-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathsetup_git_diff_e2e_fixture.py
More file actions
152 lines (125 loc) · 4.8 KB
/
setup_git_diff_e2e_fixture.py
File metadata and controls
152 lines (125 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from __future__ import annotations
import argparse
import json
from pathlib import Path
from deepscientist.artifact import ArtifactService
from deepscientist.config import ConfigManager
from deepscientist.gitops import checkpoint_repo
from deepscientist.home import ensure_home_layout, repo_root
from deepscientist.quest import QuestService
from deepscientist.shared import run_command, write_text
from deepscientist.skills import SkillInstaller
FIXTURE_QUEST_ID = "e2e-git-diff"
FIXTURE_RUN_ID = "e2e-run-001"
FIXTURE_HEADING = "Historical Diff Fixture"
DIFF_HEADING = "Notes Diff Fixture"
OLD_PATH = "docs/old-name.md"
NEW_PATH = "docs/new-name.md"
DIFF_PATH = "docs/notes.md"
BASE_CONTENT = """# Historical Diff Fixture
Model summary: baseline stable today.
Remove this legacy note.
Shared conclusion line.
- Old bullet
"""
UPDATED_CONTENT = """# Historical Diff Fixture
Model summary: refined stable today.
Shared conclusion line.
- New bullet
Added follow-up observation.
"""
BASE_DIFF_CONTENT = """# Notes Diff Fixture
Model summary: baseline stable today.
Remove this legacy note.
Shared conclusion line.
"""
UPDATED_DIFF_CONTENT = """# Notes Diff Fixture
Model summary: refined stable today.
Shared conclusion line.
Added follow-up observation.
"""
def confirm_local_baseline(artifact: ArtifactService, quest_root: Path, baseline_id: str = "baseline-e2e") -> None:
baseline_root = quest_root / "baselines" / "local" / baseline_id
baseline_root.mkdir(parents=True, exist_ok=True)
write_text(baseline_root / "README.md", "# Baseline\n")
artifact.confirm_baseline(
quest_root,
baseline_path=str(baseline_root),
baseline_id=baseline_id,
summary=f"Confirmed {baseline_id}",
metrics_summary={"acc": 0.8},
primary_metric={"name": "acc", "value": 0.8},
metric_contract={
"primary_metric_id": "acc",
"metrics": [{"metric_id": "acc", "direction": "higher"}],
},
)
def build_fixture(home: Path) -> dict[str, object]:
ensure_home_layout(home)
config_manager = ConfigManager(home)
config_manager.ensure_files()
installer = SkillInstaller(repo_root(), home)
quest_service = QuestService(home, skill_installer=installer)
quest = quest_service.create("Git diff viewer E2E fixture", quest_id=FIXTURE_QUEST_ID)
quest_root = Path(quest["quest_root"])
artifact = ArtifactService(home)
base_ref = run_command(
["git", "branch", "--show-current"],
cwd=quest_root,
check=True,
).stdout.strip() or "main"
confirm_local_baseline(artifact, quest_root)
old_file = quest_root / OLD_PATH
old_file.parent.mkdir(parents=True, exist_ok=True)
write_text(old_file, BASE_CONTENT)
write_text(quest_root / DIFF_PATH, BASE_DIFF_CONTENT)
checkpoint_repo(quest_root, "seed git diff e2e fixture", allow_empty=False)
branch = artifact.prepare_branch(
quest_root,
run_id=FIXTURE_RUN_ID,
branch_kind="run",
create_worktree_flag=False,
)
branch_ref = str(branch["branch"])
run_command(["git", "checkout", branch_ref], cwd=quest_root, check=True)
run_command(["git", "mv", OLD_PATH, NEW_PATH], cwd=quest_root, check=True)
write_text(quest_root / NEW_PATH, UPDATED_CONTENT)
write_text(quest_root / DIFF_PATH, UPDATED_DIFF_CONTENT)
checkpoint_repo(quest_root, "rename markdown fixture and update lines", allow_empty=False)
artifact.record(
quest_root,
{
"kind": "run",
"run_id": FIXTURE_RUN_ID,
"run_kind": "experiment",
"summary": "Exercise rename-aware diff rendering for the git viewer.",
"metrics_summary": {"acc": 0.91},
},
)
return {
"quest_id": quest["quest_id"],
"quest_root": str(quest_root),
"branch_ref": branch_ref,
"base_ref": base_ref,
"run_id": FIXTURE_RUN_ID,
"old_path": OLD_PATH,
"new_path": NEW_PATH,
"document_heading": FIXTURE_HEADING,
"diff_path": DIFF_PATH,
"diff_heading": DIFF_HEADING,
"home": str(home),
}
def main() -> int:
parser = argparse.ArgumentParser(description="Create an isolated git diff E2E fixture quest.")
parser.add_argument("--home", required=True, help="DeepScientist home for the temporary fixture runtime.")
parser.add_argument("--output", required=True, help="Path to write the fixture JSON.")
args = parser.parse_args()
home = Path(args.home).expanduser().resolve()
output = Path(args.output).expanduser().resolve()
output.parent.mkdir(parents=True, exist_ok=True)
fixture = build_fixture(home)
output.write_text(json.dumps(fixture, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps(fixture, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())