@elvis1513/auto-coding-skill 2.2.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/cli/assets/skill/SKILL.md +60 -7
- package/cli/assets/skill/data/templates/ENGINEERING.md +75 -5
- package/cli/assets/skill/scripts/ap.py +2413 -99
- package/cli/src/index.js +12 -0
- package/cli/tests/ap_concurrency_test.py +1257 -0
- package/cli/tests/ap_profiles_test.py +1 -0
- package/cli/tests/index.test.js +2 -1
- package/package.json +3 -3
|
@@ -0,0 +1,1257 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
import unittest
|
|
9
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import yaml
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
16
|
+
AP_SCRIPT = REPO_ROOT / "cli" / "assets" / "skill" / "scripts" / "ap.py"
|
|
17
|
+
_MISSING = object()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def command(
|
|
21
|
+
cwd: Path,
|
|
22
|
+
*args: str,
|
|
23
|
+
check: bool = True,
|
|
24
|
+
input_text: str | None = None,
|
|
25
|
+
) -> subprocess.CompletedProcess[str]:
|
|
26
|
+
result = subprocess.run(
|
|
27
|
+
list(args),
|
|
28
|
+
cwd=cwd,
|
|
29
|
+
check=False,
|
|
30
|
+
text=True,
|
|
31
|
+
input=input_text,
|
|
32
|
+
capture_output=True,
|
|
33
|
+
timeout=30,
|
|
34
|
+
)
|
|
35
|
+
if check and result.returncode != 0:
|
|
36
|
+
raise AssertionError(
|
|
37
|
+
f"command failed ({result.returncode}): {' '.join(args)}\n"
|
|
38
|
+
f"stdout:\n{result.stdout}\nstderr:\n{result.stderr}"
|
|
39
|
+
)
|
|
40
|
+
return result
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def git(cwd: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess[str]:
|
|
44
|
+
return command(cwd, "git", *args, check=check)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def git_output(cwd: Path, *args: str) -> str:
|
|
48
|
+
return git(cwd, *args).stdout.strip()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def base_config(isolation: str | object = "worktree") -> dict:
|
|
52
|
+
config = {
|
|
53
|
+
"workflow": {"mode": "dev", "profile": "auto"},
|
|
54
|
+
"project": {"name": "concurrency-test"},
|
|
55
|
+
"commands": {
|
|
56
|
+
"gate_changed": "true",
|
|
57
|
+
"gate_standard": "true",
|
|
58
|
+
"gate_full": "true",
|
|
59
|
+
},
|
|
60
|
+
"gate": {
|
|
61
|
+
"default_scope": "auto",
|
|
62
|
+
"fallback_scope": "standard",
|
|
63
|
+
"full_on_unknown": True,
|
|
64
|
+
"no_change_scope": "standard",
|
|
65
|
+
"rules": [],
|
|
66
|
+
},
|
|
67
|
+
"structure": {"enabled": False, "enforcement": "advisory"},
|
|
68
|
+
"verification": {
|
|
69
|
+
"target_env_required": False,
|
|
70
|
+
"jenkins_required": False,
|
|
71
|
+
},
|
|
72
|
+
"docs": {
|
|
73
|
+
"taskbook": "docs/tasks/taskbook.md",
|
|
74
|
+
"closure_log": "docs/tasks/closure-log.md",
|
|
75
|
+
"evidence_log": "docs/tasks/evidence.jsonl",
|
|
76
|
+
"design_dir": "docs/design",
|
|
77
|
+
"ledger_check_enabled": False,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
if isolation is not _MISSING:
|
|
81
|
+
config["concurrency"] = {
|
|
82
|
+
"isolation": isolation,
|
|
83
|
+
"base_ref": "origin/dev",
|
|
84
|
+
"target_branch": "dev",
|
|
85
|
+
"branch_prefix": "codex/",
|
|
86
|
+
# Tests replace this with an absolute path outside the primary checkout.
|
|
87
|
+
"worktree_root": "",
|
|
88
|
+
"cleanup_merged": True,
|
|
89
|
+
"delete_remote_branch": True,
|
|
90
|
+
}
|
|
91
|
+
return config
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
95
|
+
def make_repo(
|
|
96
|
+
self,
|
|
97
|
+
isolation: str | object = "worktree",
|
|
98
|
+
) -> tuple[Path, Path, Path]:
|
|
99
|
+
temp = tempfile.TemporaryDirectory(prefix="autocoding-concurrency-")
|
|
100
|
+
self.addCleanup(temp.cleanup)
|
|
101
|
+
root = Path(temp.name)
|
|
102
|
+
repo = root / "project"
|
|
103
|
+
remote = root / "origin.git"
|
|
104
|
+
worktrees = root / "worktrees"
|
|
105
|
+
repo.mkdir()
|
|
106
|
+
|
|
107
|
+
git(root, "init", "--bare", "-q", str(remote))
|
|
108
|
+
git(repo, "init", "-q", "-b", "dev")
|
|
109
|
+
git(repo, "config", "user.email", "test@example.com")
|
|
110
|
+
git(repo, "config", "user.name", "Auto Coding Test")
|
|
111
|
+
|
|
112
|
+
config = base_config(isolation)
|
|
113
|
+
if "concurrency" in config:
|
|
114
|
+
config["concurrency"]["worktree_root"] = str(worktrees)
|
|
115
|
+
engineering = repo / "docs" / "ENGINEERING.md"
|
|
116
|
+
engineering.parent.mkdir(parents=True)
|
|
117
|
+
engineering.write_text(
|
|
118
|
+
"---\n"
|
|
119
|
+
+ yaml.safe_dump(config, allow_unicode=True, sort_keys=False)
|
|
120
|
+
+ "---\n# Engineering\n",
|
|
121
|
+
encoding="utf-8",
|
|
122
|
+
)
|
|
123
|
+
tasks = repo / "docs" / "tasks"
|
|
124
|
+
tasks.mkdir(parents=True)
|
|
125
|
+
(tasks / "taskbook.md").write_text("# Taskbook\n", encoding="utf-8")
|
|
126
|
+
(tasks / "closure-log.md").write_text("# Closure Log\n", encoding="utf-8")
|
|
127
|
+
(repo / "shared.txt").write_text("baseline\n", encoding="utf-8")
|
|
128
|
+
git(repo, "add", "-A")
|
|
129
|
+
git(repo, "commit", "-qm", "baseline")
|
|
130
|
+
git(repo, "remote", "add", "origin", str(remote))
|
|
131
|
+
git(repo, "push", "-qu", "origin", "dev")
|
|
132
|
+
git(remote, "symbolic-ref", "HEAD", "refs/heads/dev")
|
|
133
|
+
return root, repo, remote
|
|
134
|
+
|
|
135
|
+
def ap(
|
|
136
|
+
self,
|
|
137
|
+
repo: Path,
|
|
138
|
+
*args: str,
|
|
139
|
+
check: bool = True,
|
|
140
|
+
) -> subprocess.CompletedProcess[str]:
|
|
141
|
+
return command(
|
|
142
|
+
repo,
|
|
143
|
+
sys.executable,
|
|
144
|
+
str(AP_SCRIPT),
|
|
145
|
+
"--repo",
|
|
146
|
+
str(repo),
|
|
147
|
+
*args,
|
|
148
|
+
check=check,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def task_worktree(self, repo: Path, task_id: str) -> Path:
|
|
152
|
+
wanted = f"refs/heads/codex/{task_id}"
|
|
153
|
+
current_path: Path | None = None
|
|
154
|
+
for line in git_output(repo, "worktree", "list", "--porcelain").splitlines():
|
|
155
|
+
if line.startswith("worktree "):
|
|
156
|
+
current_path = Path(line.removeprefix("worktree "))
|
|
157
|
+
elif line == f"branch {wanted}" and current_path is not None:
|
|
158
|
+
return current_path
|
|
159
|
+
self.fail(f"no worktree registered for {wanted}")
|
|
160
|
+
|
|
161
|
+
def start_task(self, repo: Path, task_id: str) -> Path:
|
|
162
|
+
result = self.ap(repo, "task-start", task_id, "--base", "origin/dev")
|
|
163
|
+
worktree = self.task_worktree(repo, task_id)
|
|
164
|
+
self.assertIn(task_id, result.stdout + result.stderr)
|
|
165
|
+
self.assertTrue(worktree.is_dir())
|
|
166
|
+
self.assertNotEqual(repo.resolve(), worktree.resolve())
|
|
167
|
+
self.assertNotIn(repo.resolve(), worktree.resolve().parents)
|
|
168
|
+
self.assertEqual(f"codex/{task_id}", git_output(worktree, "branch", "--show-current"))
|
|
169
|
+
return worktree
|
|
170
|
+
|
|
171
|
+
def assert_local_branch(self, repo: Path, branch: str, exists: bool) -> None:
|
|
172
|
+
result = git(repo, "show-ref", "--verify", "--quiet", f"refs/heads/{branch}", check=False)
|
|
173
|
+
self.assertEqual(exists, result.returncode == 0, branch)
|
|
174
|
+
|
|
175
|
+
def assert_remote_branch(self, remote: Path, branch: str, exists: bool) -> None:
|
|
176
|
+
result = git(
|
|
177
|
+
remote,
|
|
178
|
+
"show-ref",
|
|
179
|
+
"--verify",
|
|
180
|
+
"--quiet",
|
|
181
|
+
f"refs/heads/{branch}",
|
|
182
|
+
check=False,
|
|
183
|
+
)
|
|
184
|
+
self.assertEqual(exists, result.returncode == 0, branch)
|
|
185
|
+
|
|
186
|
+
def assert_rejected_without_mutation(
|
|
187
|
+
self,
|
|
188
|
+
repo: Path,
|
|
189
|
+
*args: str,
|
|
190
|
+
) -> subprocess.CompletedProcess[str]:
|
|
191
|
+
before_head = git_output(repo, "rev-parse", "HEAD")
|
|
192
|
+
before_status = git_output(repo, "status", "--porcelain=v1", "--untracked-files=all")
|
|
193
|
+
result = self.ap(repo, *args, check=False)
|
|
194
|
+
self.assertNotEqual(0, result.returncode, result.stdout + result.stderr)
|
|
195
|
+
self.assertEqual(before_head, git_output(repo, "rev-parse", "HEAD"))
|
|
196
|
+
self.assertEqual(
|
|
197
|
+
before_status,
|
|
198
|
+
git_output(repo, "status", "--porcelain=v1", "--untracked-files=all"),
|
|
199
|
+
)
|
|
200
|
+
return result
|
|
201
|
+
|
|
202
|
+
def manifest_payloads(self, repo: Path) -> list[dict]:
|
|
203
|
+
common_dir_raw = git_output(repo, "rev-parse", "--git-common-dir")
|
|
204
|
+
common_dir = Path(common_dir_raw)
|
|
205
|
+
if not common_dir.is_absolute():
|
|
206
|
+
common_dir = (repo / common_dir).resolve()
|
|
207
|
+
payloads: list[dict] = []
|
|
208
|
+
for candidate in common_dir.rglob("*.json"):
|
|
209
|
+
try:
|
|
210
|
+
payload = json.loads(candidate.read_text(encoding="utf-8"))
|
|
211
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
|
212
|
+
continue
|
|
213
|
+
if isinstance(payload, dict):
|
|
214
|
+
payloads.append(payload)
|
|
215
|
+
return payloads
|
|
216
|
+
|
|
217
|
+
def registry_manifest_path(self, repo: Path, task_id: str) -> Path:
|
|
218
|
+
common_dir = Path(git_output(repo, "rev-parse", "--git-common-dir"))
|
|
219
|
+
if not common_dir.is_absolute():
|
|
220
|
+
common_dir = (repo / common_dir).resolve()
|
|
221
|
+
return common_dir / "auto-coding-skill" / "tasks" / f"{task_id}.json"
|
|
222
|
+
|
|
223
|
+
def install_hook(self, repo: Path, name: str, body: str) -> Path:
|
|
224
|
+
common_dir = Path(git_output(repo, "rev-parse", "--git-common-dir"))
|
|
225
|
+
if not common_dir.is_absolute():
|
|
226
|
+
common_dir = (repo / common_dir).resolve()
|
|
227
|
+
hook = common_dir / "hooks" / name
|
|
228
|
+
hook.write_text("#!/bin/sh\nset -eu\n" + body, encoding="utf-8")
|
|
229
|
+
hook.chmod(0o755)
|
|
230
|
+
return hook
|
|
231
|
+
|
|
232
|
+
def test_task_start_creates_external_worktree_manifest_and_status(self) -> None:
|
|
233
|
+
_, repo, _ = self.make_repo()
|
|
234
|
+
worktree = self.start_task(repo, "START-1")
|
|
235
|
+
|
|
236
|
+
status = self.ap(repo, "task-status", "START-1")
|
|
237
|
+
rendered_status = status.stdout + status.stderr
|
|
238
|
+
self.assertIn("START-1", rendered_status)
|
|
239
|
+
self.assertIn("codex/START-1", rendered_status)
|
|
240
|
+
self.assertIn(str(worktree), rendered_status)
|
|
241
|
+
|
|
242
|
+
serialized_payloads = [json.dumps(item, sort_keys=True) for item in self.manifest_payloads(repo)]
|
|
243
|
+
self.assertTrue(
|
|
244
|
+
any(
|
|
245
|
+
"START-1" in payload
|
|
246
|
+
and "codex/START-1" in payload
|
|
247
|
+
and str(worktree) in payload
|
|
248
|
+
for payload in serialized_payloads
|
|
249
|
+
),
|
|
250
|
+
"task-start must persist a task manifest in the Git common directory",
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
def test_task_start_rolls_back_checkout_hook_side_effects(self) -> None:
|
|
254
|
+
hook_bodies = {
|
|
255
|
+
"untracked": (
|
|
256
|
+
'root="$(git rev-parse --show-toplevel)"\n'
|
|
257
|
+
'printf "hook data\\n" > "$root/hook-created.txt"\n'
|
|
258
|
+
),
|
|
259
|
+
"clean-commit": (
|
|
260
|
+
'root="$(git rev-parse --show-toplevel)"\n'
|
|
261
|
+
'printf "hook commit\\n" > "$root/hook-created.txt"\n'
|
|
262
|
+
'git -C "$root" add hook-created.txt\n'
|
|
263
|
+
'git -C "$root" commit --no-verify -qm "checkout hook commit"\n'
|
|
264
|
+
),
|
|
265
|
+
}
|
|
266
|
+
for label, body in hook_bodies.items():
|
|
267
|
+
with self.subTest(label=label):
|
|
268
|
+
root, repo, _ = self.make_repo()
|
|
269
|
+
self.install_hook(repo, "post-checkout", body)
|
|
270
|
+
task_id = f"HOOK-{label.upper()}"
|
|
271
|
+
|
|
272
|
+
result = self.ap(repo, "task-start", task_id, "--base", "origin/dev", check=False)
|
|
273
|
+
|
|
274
|
+
self.assertNotEqual(0, result.returncode)
|
|
275
|
+
self.assertIn("hook", (result.stdout + result.stderr).lower())
|
|
276
|
+
self.assert_local_branch(repo, f"codex/{task_id}", False)
|
|
277
|
+
self.assertFalse(self.registry_manifest_path(repo, task_id).exists())
|
|
278
|
+
self.assertNotIn(
|
|
279
|
+
f"refs/heads/codex/{task_id}",
|
|
280
|
+
git_output(repo, "worktree", "list", "--porcelain"),
|
|
281
|
+
)
|
|
282
|
+
self.assertFalse((root / "worktrees" / repo.name / task_id).exists())
|
|
283
|
+
|
|
284
|
+
def test_control_commands_are_rejected_from_another_task_worktree(self) -> None:
|
|
285
|
+
_, repo, _ = self.make_repo()
|
|
286
|
+
first = self.start_task(repo, "CROSS-1")
|
|
287
|
+
second = self.start_task(repo, "CROSS-2")
|
|
288
|
+
|
|
289
|
+
commands = [
|
|
290
|
+
("task-integrate", "CROSS-1"),
|
|
291
|
+
("task-finish", "CROSS-1"),
|
|
292
|
+
("task-prune",),
|
|
293
|
+
("task-start", "CROSS-3"),
|
|
294
|
+
]
|
|
295
|
+
for args in commands:
|
|
296
|
+
with self.subTest(command=args[0]):
|
|
297
|
+
before = {
|
|
298
|
+
"control_head": git_output(repo, "rev-parse", "HEAD"),
|
|
299
|
+
"control_status": git_output(repo, "status", "--porcelain=v1"),
|
|
300
|
+
"first_head": git_output(first, "rev-parse", "HEAD"),
|
|
301
|
+
"first_status": git_output(first, "status", "--porcelain=v1"),
|
|
302
|
+
"second_head": git_output(second, "rev-parse", "HEAD"),
|
|
303
|
+
"second_status": git_output(second, "status", "--porcelain=v1"),
|
|
304
|
+
"worktrees": git_output(repo, "worktree", "list", "--porcelain"),
|
|
305
|
+
}
|
|
306
|
+
result = self.ap(second, *args, check=False)
|
|
307
|
+
self.assertNotEqual(0, result.returncode)
|
|
308
|
+
self.assertIn("control", (result.stdout + result.stderr).lower())
|
|
309
|
+
after = {
|
|
310
|
+
"control_head": git_output(repo, "rev-parse", "HEAD"),
|
|
311
|
+
"control_status": git_output(repo, "status", "--porcelain=v1"),
|
|
312
|
+
"first_head": git_output(first, "rev-parse", "HEAD"),
|
|
313
|
+
"first_status": git_output(first, "status", "--porcelain=v1"),
|
|
314
|
+
"second_head": git_output(second, "rev-parse", "HEAD"),
|
|
315
|
+
"second_status": git_output(second, "status", "--porcelain=v1"),
|
|
316
|
+
"worktrees": git_output(repo, "worktree", "list", "--porcelain"),
|
|
317
|
+
}
|
|
318
|
+
self.assertEqual(before, after)
|
|
319
|
+
|
|
320
|
+
def test_missing_task_manifest_cannot_fall_back_to_legacy_in_linked_worktree(self) -> None:
|
|
321
|
+
_, repo, remote = self.make_repo("legacy")
|
|
322
|
+
worktree = self.start_task(repo, "NO-MANIFEST")
|
|
323
|
+
git_dir = Path(git_output(worktree, "rev-parse", "--git-dir"))
|
|
324
|
+
if not git_dir.is_absolute():
|
|
325
|
+
git_dir = (worktree / git_dir).resolve()
|
|
326
|
+
(git_dir / "auto-coding-skill-task.json").unlink()
|
|
327
|
+
before = git_output(worktree, "rev-parse", "HEAD")
|
|
328
|
+
(worktree / "payload.txt").write_text("must not publish\n", encoding="utf-8")
|
|
329
|
+
|
|
330
|
+
result = self.ap(
|
|
331
|
+
worktree,
|
|
332
|
+
"commit-push",
|
|
333
|
+
"NO-MANIFEST",
|
|
334
|
+
"--msg",
|
|
335
|
+
"NO-MANIFEST: must fail",
|
|
336
|
+
check=False,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
self.assertNotEqual(0, result.returncode)
|
|
340
|
+
self.assertIn("manifest", (result.stdout + result.stderr).lower())
|
|
341
|
+
self.assertEqual(before, git_output(worktree, "rev-parse", "HEAD"))
|
|
342
|
+
self.assert_remote_branch(remote, "codex/NO-MANIFEST", False)
|
|
343
|
+
|
|
344
|
+
def test_corrupt_manifest_cannot_redirect_cleanup_to_control_branch(self) -> None:
|
|
345
|
+
_, repo, remote = self.make_repo()
|
|
346
|
+
worktree = self.start_task(repo, "CORRUPT-1")
|
|
347
|
+
registry = self.registry_manifest_path(repo, "CORRUPT-1")
|
|
348
|
+
worktree_git_dir = Path(git_output(worktree, "rev-parse", "--git-dir"))
|
|
349
|
+
if not worktree_git_dir.is_absolute():
|
|
350
|
+
worktree_git_dir = (worktree / worktree_git_dir).resolve()
|
|
351
|
+
worktree_manifest = worktree_git_dir / "auto-coding-skill-task.json"
|
|
352
|
+
payload = json.loads(registry.read_text(encoding="utf-8"))
|
|
353
|
+
payload["task_branch"] = "dev"
|
|
354
|
+
rendered = json.dumps(payload, indent=2, sort_keys=True) + "\n"
|
|
355
|
+
registry.write_text(rendered, encoding="utf-8")
|
|
356
|
+
worktree_manifest.write_text(rendered, encoding="utf-8")
|
|
357
|
+
local_dev = git_output(repo, "rev-parse", "refs/heads/dev")
|
|
358
|
+
remote_dev = git_output(remote, "rev-parse", "refs/heads/dev")
|
|
359
|
+
|
|
360
|
+
result = self.ap(repo, "task-finish", "CORRUPT-1", check=False)
|
|
361
|
+
|
|
362
|
+
self.assertNotEqual(0, result.returncode)
|
|
363
|
+
self.assertIn("invalid task branch", (result.stdout + result.stderr).lower())
|
|
364
|
+
self.assertEqual(local_dev, git_output(repo, "rev-parse", "refs/heads/dev"))
|
|
365
|
+
self.assertEqual(remote_dev, git_output(remote, "rev-parse", "refs/heads/dev"))
|
|
366
|
+
self.assertTrue(worktree.exists())
|
|
367
|
+
self.assert_local_branch(repo, "codex/CORRUPT-1", True)
|
|
368
|
+
|
|
369
|
+
def test_commit_push_requires_matching_manifest_and_isolated_worktree(self) -> None:
|
|
370
|
+
_, repo, remote = self.make_repo()
|
|
371
|
+
worktree = self.start_task(repo, "ISOLATED-1")
|
|
372
|
+
second_worktree = self.start_task(repo, "ISOLATED-2")
|
|
373
|
+
(worktree / "task-only.txt").write_text("task change\n", encoding="utf-8")
|
|
374
|
+
(second_worktree / "second-task-only.txt").write_text(
|
|
375
|
+
"second task change\n",
|
|
376
|
+
encoding="utf-8",
|
|
377
|
+
)
|
|
378
|
+
(repo / "shared.txt").write_text("primary checkout change\n", encoding="utf-8")
|
|
379
|
+
|
|
380
|
+
mismatch = self.assert_rejected_without_mutation(
|
|
381
|
+
worktree,
|
|
382
|
+
"commit-push",
|
|
383
|
+
"ANOTHER-TASK",
|
|
384
|
+
"--msg",
|
|
385
|
+
"ANOTHER-TASK: must fail",
|
|
386
|
+
)
|
|
387
|
+
self.assertIn("task", (mismatch.stdout + mismatch.stderr).lower())
|
|
388
|
+
|
|
389
|
+
primary = self.assert_rejected_without_mutation(
|
|
390
|
+
repo,
|
|
391
|
+
"commit-push",
|
|
392
|
+
"ISOLATED-1",
|
|
393
|
+
"--msg",
|
|
394
|
+
"ISOLATED-1: must fail from primary checkout",
|
|
395
|
+
)
|
|
396
|
+
self.assertIn("worktree", (primary.stdout + primary.stderr).lower())
|
|
397
|
+
|
|
398
|
+
second_status = git(second_worktree, "status", "--short").stdout
|
|
399
|
+
self.assertIn("?? docs/tasks/active/", second_status)
|
|
400
|
+
self.assertIn("?? second-task-only.txt", second_status)
|
|
401
|
+
with ThreadPoolExecutor(max_workers=2) as pool:
|
|
402
|
+
first_commit = pool.submit(
|
|
403
|
+
self.ap,
|
|
404
|
+
worktree,
|
|
405
|
+
"commit-push",
|
|
406
|
+
"ISOLATED-1",
|
|
407
|
+
"--msg",
|
|
408
|
+
"ISOLATED-1: isolated change",
|
|
409
|
+
)
|
|
410
|
+
second_commit = pool.submit(
|
|
411
|
+
self.ap,
|
|
412
|
+
second_worktree,
|
|
413
|
+
"commit-push",
|
|
414
|
+
"ISOLATED-2",
|
|
415
|
+
"--msg",
|
|
416
|
+
"ISOLATED-2: independent change",
|
|
417
|
+
)
|
|
418
|
+
first_commit.result()
|
|
419
|
+
second_commit.result()
|
|
420
|
+
|
|
421
|
+
self.assert_remote_branch(remote, "codex/ISOLATED-1", True)
|
|
422
|
+
task_ref = "refs/heads/codex/ISOLATED-1"
|
|
423
|
+
self.assertEqual(
|
|
424
|
+
"task change",
|
|
425
|
+
git_output(remote, "show", f"{task_ref}:task-only.txt"),
|
|
426
|
+
)
|
|
427
|
+
self.assertEqual("baseline", git_output(remote, "show", f"{task_ref}:shared.txt"))
|
|
428
|
+
self.assertNotEqual(
|
|
429
|
+
0,
|
|
430
|
+
git(
|
|
431
|
+
remote,
|
|
432
|
+
"cat-file",
|
|
433
|
+
"-e",
|
|
434
|
+
f"{task_ref}:second-task-only.txt",
|
|
435
|
+
check=False,
|
|
436
|
+
).returncode,
|
|
437
|
+
)
|
|
438
|
+
self.assertEqual("primary checkout change\n", (repo / "shared.txt").read_text(encoding="utf-8"))
|
|
439
|
+
self.assertEqual(" M shared.txt\n", git(repo, "status", "--short").stdout)
|
|
440
|
+
second_ref = "refs/heads/codex/ISOLATED-2"
|
|
441
|
+
self.assertEqual(
|
|
442
|
+
"second task change",
|
|
443
|
+
git_output(remote, "show", f"{second_ref}:second-task-only.txt"),
|
|
444
|
+
)
|
|
445
|
+
self.assertNotEqual(
|
|
446
|
+
0,
|
|
447
|
+
git(remote, "cat-file", "-e", f"{second_ref}:task-only.txt", check=False).returncode,
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
def test_task_integrate_from_primary_pushes_target_and_cleans_task_refs(self) -> None:
|
|
451
|
+
_, repo, remote = self.make_repo()
|
|
452
|
+
worktree = self.start_task(repo, "INTEGRATE-1")
|
|
453
|
+
(worktree / "integrated.txt").write_text("integrated\n", encoding="utf-8")
|
|
454
|
+
self.ap(
|
|
455
|
+
worktree,
|
|
456
|
+
"commit-push",
|
|
457
|
+
"INTEGRATE-1",
|
|
458
|
+
"--msg",
|
|
459
|
+
"INTEGRATE-1: ready",
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
rejected = self.ap(worktree, "task-integrate", "INTEGRATE-1", check=False)
|
|
463
|
+
self.assertNotEqual(0, rejected.returncode)
|
|
464
|
+
self.assertTrue(worktree.exists())
|
|
465
|
+
self.assert_remote_branch(remote, "codex/INTEGRATE-1", True)
|
|
466
|
+
|
|
467
|
+
(repo / "shared.txt").write_text("primary work stays untouched\n", encoding="utf-8")
|
|
468
|
+
self.ap(repo, "task-integrate", "INTEGRATE-1")
|
|
469
|
+
|
|
470
|
+
self.assertEqual("integrated", git_output(remote, "show", "refs/heads/dev:integrated.txt"))
|
|
471
|
+
self.assertEqual(
|
|
472
|
+
"primary work stays untouched\n",
|
|
473
|
+
(repo / "shared.txt").read_text(encoding="utf-8"),
|
|
474
|
+
)
|
|
475
|
+
self.assertFalse(worktree.exists())
|
|
476
|
+
self.assert_local_branch(repo, "codex/INTEGRATE-1", False)
|
|
477
|
+
self.assert_remote_branch(remote, "codex/INTEGRATE-1", False)
|
|
478
|
+
|
|
479
|
+
def test_task_finish_keep_remote_reports_retained_branch(self) -> None:
|
|
480
|
+
_, repo, remote = self.make_repo()
|
|
481
|
+
worktree = self.start_task(repo, "KEEP-REMOTE")
|
|
482
|
+
(worktree / "kept.txt").write_text("kept remotely\n", encoding="utf-8")
|
|
483
|
+
self.ap(
|
|
484
|
+
worktree,
|
|
485
|
+
"commit-push",
|
|
486
|
+
"KEEP-REMOTE",
|
|
487
|
+
"--msg",
|
|
488
|
+
"KEEP-REMOTE: ready",
|
|
489
|
+
)
|
|
490
|
+
self.ap(repo, "task-integrate", "KEEP-REMOTE", "--keep-worktree")
|
|
491
|
+
|
|
492
|
+
finish = self.ap(repo, "task-finish", "KEEP-REMOTE", "--keep-remote")
|
|
493
|
+
|
|
494
|
+
self.assertIn("remote_branch_deleted=false", finish.stdout + finish.stderr)
|
|
495
|
+
self.assertFalse(worktree.exists())
|
|
496
|
+
self.assert_local_branch(repo, "codex/KEEP-REMOTE", False)
|
|
497
|
+
self.assert_remote_branch(remote, "codex/KEEP-REMOTE", True)
|
|
498
|
+
self.assertFalse(self.registry_manifest_path(repo, "KEEP-REMOTE").exists())
|
|
499
|
+
|
|
500
|
+
def test_task_deletion_is_isolated_and_committed_only_on_its_task_branch(self) -> None:
|
|
501
|
+
_, repo, remote = self.make_repo()
|
|
502
|
+
deleting = self.start_task(repo, "DELETE-1")
|
|
503
|
+
observer = self.start_task(repo, "DELETE-2")
|
|
504
|
+
(deleting / "shared.txt").unlink()
|
|
505
|
+
(observer / "observer.txt").write_text("observer\n", encoding="utf-8")
|
|
506
|
+
|
|
507
|
+
self.ap(
|
|
508
|
+
deleting,
|
|
509
|
+
"commit-push",
|
|
510
|
+
"DELETE-1",
|
|
511
|
+
"--msg",
|
|
512
|
+
"DELETE-1: delete shared file",
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
deleted_ref = "refs/heads/codex/DELETE-1"
|
|
516
|
+
self.assertNotEqual(
|
|
517
|
+
0,
|
|
518
|
+
git(remote, "cat-file", "-e", f"{deleted_ref}:shared.txt", check=False).returncode,
|
|
519
|
+
)
|
|
520
|
+
self.assertEqual("baseline\n", (repo / "shared.txt").read_text(encoding="utf-8"))
|
|
521
|
+
self.assertEqual("baseline\n", (observer / "shared.txt").read_text(encoding="utf-8"))
|
|
522
|
+
self.assertTrue((observer / "observer.txt").exists())
|
|
523
|
+
|
|
524
|
+
def test_task_finish_refuses_dirty_or_unmerged_tasks(self) -> None:
|
|
525
|
+
_, repo, _ = self.make_repo()
|
|
526
|
+
|
|
527
|
+
dirty_worktree = self.start_task(repo, "DIRTY-1")
|
|
528
|
+
(dirty_worktree / "dirty.txt").write_text("not committed\n", encoding="utf-8")
|
|
529
|
+
dirty = self.ap(repo, "task-finish", "DIRTY-1", check=False)
|
|
530
|
+
self.assertNotEqual(0, dirty.returncode)
|
|
531
|
+
self.assertTrue(dirty_worktree.exists())
|
|
532
|
+
self.assert_local_branch(repo, "codex/DIRTY-1", True)
|
|
533
|
+
self.assertTrue((dirty_worktree / "dirty.txt").exists())
|
|
534
|
+
|
|
535
|
+
unmerged_worktree = self.start_task(repo, "UNMERGED-1")
|
|
536
|
+
(unmerged_worktree / "unmerged.txt").write_text("committed only on task\n", encoding="utf-8")
|
|
537
|
+
git(unmerged_worktree, "add", "unmerged.txt")
|
|
538
|
+
git(unmerged_worktree, "commit", "-qm", "unmerged task commit")
|
|
539
|
+
unmerged = self.ap(repo, "task-finish", "UNMERGED-1", check=False)
|
|
540
|
+
self.assertNotEqual(0, unmerged.returncode)
|
|
541
|
+
self.assertTrue(unmerged_worktree.exists())
|
|
542
|
+
self.assert_local_branch(repo, "codex/UNMERGED-1", True)
|
|
543
|
+
self.assertEqual("unmerged task commit", git_output(unmerged_worktree, "log", "-1", "--format=%s"))
|
|
544
|
+
|
|
545
|
+
def test_task_prune_only_removes_merged_unoccupied_codex_branches(self) -> None:
|
|
546
|
+
root, repo, _ = self.make_repo()
|
|
547
|
+
git(repo, "branch", "codex/merged-free", "dev")
|
|
548
|
+
git(repo, "branch", "feature/merged-free", "dev")
|
|
549
|
+
|
|
550
|
+
git(repo, "branch", "codex/unmerged-free", "dev")
|
|
551
|
+
unmerged_path = root / "unmerged-worktree"
|
|
552
|
+
git(repo, "worktree", "add", "-q", str(unmerged_path), "codex/unmerged-free")
|
|
553
|
+
(unmerged_path / "unique.txt").write_text("unique\n", encoding="utf-8")
|
|
554
|
+
git(unmerged_path, "add", "unique.txt")
|
|
555
|
+
git(unmerged_path, "commit", "-qm", "unique unmerged commit")
|
|
556
|
+
git(repo, "worktree", "remove", str(unmerged_path))
|
|
557
|
+
|
|
558
|
+
git(repo, "branch", "codex/merged-occupied", "dev")
|
|
559
|
+
occupied_path = root / "occupied-worktree"
|
|
560
|
+
git(repo, "worktree", "add", "-q", str(occupied_path), "codex/merged-occupied")
|
|
561
|
+
|
|
562
|
+
self.ap(repo, "task-prune")
|
|
563
|
+
|
|
564
|
+
self.assert_local_branch(repo, "codex/merged-free", False)
|
|
565
|
+
self.assert_local_branch(repo, "codex/unmerged-free", True)
|
|
566
|
+
self.assert_local_branch(repo, "codex/merged-occupied", True)
|
|
567
|
+
self.assert_local_branch(repo, "feature/merged-free", True)
|
|
568
|
+
self.assertTrue(occupied_path.exists())
|
|
569
|
+
|
|
570
|
+
def test_task_prune_finishes_registered_integrated_worktree(self) -> None:
|
|
571
|
+
_, repo, remote = self.make_repo()
|
|
572
|
+
worktree = self.start_task(repo, "PRUNE-REGISTERED")
|
|
573
|
+
(worktree / "registered.txt").write_text("registered\n", encoding="utf-8")
|
|
574
|
+
self.ap(
|
|
575
|
+
worktree,
|
|
576
|
+
"commit-push",
|
|
577
|
+
"PRUNE-REGISTERED",
|
|
578
|
+
"--msg",
|
|
579
|
+
"PRUNE-REGISTERED: ready",
|
|
580
|
+
)
|
|
581
|
+
self.ap(
|
|
582
|
+
repo,
|
|
583
|
+
"task-integrate",
|
|
584
|
+
"PRUNE-REGISTERED",
|
|
585
|
+
"--keep-worktree",
|
|
586
|
+
)
|
|
587
|
+
self.assertTrue(worktree.exists())
|
|
588
|
+
self.assert_local_branch(repo, "codex/PRUNE-REGISTERED", True)
|
|
589
|
+
|
|
590
|
+
self.ap(repo, "task-prune")
|
|
591
|
+
|
|
592
|
+
self.assertFalse(worktree.exists())
|
|
593
|
+
self.assert_local_branch(repo, "codex/PRUNE-REGISTERED", False)
|
|
594
|
+
self.assert_remote_branch(remote, "codex/PRUNE-REGISTERED", False)
|
|
595
|
+
|
|
596
|
+
def test_cleanup_blocks_unknown_ignored_data_but_allows_runtime_evidence(self) -> None:
|
|
597
|
+
_, repo, remote = self.make_repo()
|
|
598
|
+
(repo / ".gitignore").write_text(".env\n.local/\n", encoding="utf-8")
|
|
599
|
+
git(repo, "add", ".gitignore")
|
|
600
|
+
git(repo, "commit", "-qm", "ignore local runtime files")
|
|
601
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
602
|
+
|
|
603
|
+
worktree = self.start_task(repo, "IGNORED-1")
|
|
604
|
+
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
605
|
+
self.ap(
|
|
606
|
+
worktree,
|
|
607
|
+
"commit-push",
|
|
608
|
+
"IGNORED-1",
|
|
609
|
+
"--msg",
|
|
610
|
+
"IGNORED-1: ready",
|
|
611
|
+
)
|
|
612
|
+
self.ap(repo, "task-integrate", "IGNORED-1", "--keep-worktree")
|
|
613
|
+
|
|
614
|
+
(worktree / ".env").write_text("must survive\n", encoding="utf-8")
|
|
615
|
+
blocked = self.ap(repo, "task-finish", "IGNORED-1", check=False)
|
|
616
|
+
self.assertNotEqual(0, blocked.returncode)
|
|
617
|
+
self.assertIn(".env", blocked.stdout + blocked.stderr)
|
|
618
|
+
self.assertTrue(worktree.exists())
|
|
619
|
+
self.assertEqual("must survive\n", (worktree / ".env").read_text(encoding="utf-8"))
|
|
620
|
+
|
|
621
|
+
(worktree / ".env").unlink()
|
|
622
|
+
runtime_evidence = worktree / ".local" / "auto-coding-skill" / "gate.jsonl"
|
|
623
|
+
runtime_evidence.parent.mkdir(parents=True, exist_ok=True)
|
|
624
|
+
runtime_evidence.write_text("runtime evidence\n", encoding="utf-8")
|
|
625
|
+
self.ap(repo, "task-finish", "IGNORED-1")
|
|
626
|
+
|
|
627
|
+
self.assertFalse(worktree.exists())
|
|
628
|
+
self.assert_local_branch(repo, "codex/IGNORED-1", False)
|
|
629
|
+
self.assert_remote_branch(remote, "codex/IGNORED-1", False)
|
|
630
|
+
self.assertFalse(self.registry_manifest_path(repo, "IGNORED-1").exists())
|
|
631
|
+
|
|
632
|
+
def test_cleanup_safely_deinitializes_submodules_and_preserves_unknown_data(self) -> None:
|
|
633
|
+
root, repo, remote = self.make_repo()
|
|
634
|
+
module = root / "module-source"
|
|
635
|
+
module.mkdir()
|
|
636
|
+
git(module, "init", "-q", "-b", "main")
|
|
637
|
+
git(module, "config", "user.email", "module@example.com")
|
|
638
|
+
git(module, "config", "user.name", "Module Author")
|
|
639
|
+
(module / ".gitignore").write_text(".secret\n.local/\n", encoding="utf-8")
|
|
640
|
+
(module / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
641
|
+
git(module, "add", "-A")
|
|
642
|
+
git(module, "commit", "-qm", "module baseline")
|
|
643
|
+
|
|
644
|
+
git(
|
|
645
|
+
repo,
|
|
646
|
+
"-c",
|
|
647
|
+
"protocol.file.allow=always",
|
|
648
|
+
"submodule",
|
|
649
|
+
"add",
|
|
650
|
+
"-q",
|
|
651
|
+
str(module),
|
|
652
|
+
"vendor/module",
|
|
653
|
+
)
|
|
654
|
+
git(repo, "commit", "-qam", "add submodule")
|
|
655
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
656
|
+
primary_submodule_status = git_output(
|
|
657
|
+
repo,
|
|
658
|
+
"submodule",
|
|
659
|
+
"status",
|
|
660
|
+
"--",
|
|
661
|
+
"vendor/module",
|
|
662
|
+
)
|
|
663
|
+
primary_submodule_url = git_output(repo, "config", "--get", "submodule.vendor/module.url")
|
|
664
|
+
self.assertFalse(primary_submodule_status.startswith("-"))
|
|
665
|
+
|
|
666
|
+
worktree = self.start_task(repo, "SUBMODULE-1")
|
|
667
|
+
git(
|
|
668
|
+
worktree,
|
|
669
|
+
"-c",
|
|
670
|
+
"protocol.file.allow=always",
|
|
671
|
+
"submodule",
|
|
672
|
+
"update",
|
|
673
|
+
"--init",
|
|
674
|
+
"--recursive",
|
|
675
|
+
)
|
|
676
|
+
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
677
|
+
self.ap(
|
|
678
|
+
worktree,
|
|
679
|
+
"commit-push",
|
|
680
|
+
"SUBMODULE-1",
|
|
681
|
+
"--msg",
|
|
682
|
+
"SUBMODULE-1: ready",
|
|
683
|
+
)
|
|
684
|
+
self.ap(repo, "task-integrate", "SUBMODULE-1", "--keep-worktree")
|
|
685
|
+
|
|
686
|
+
task_module = worktree / "vendor" / "module"
|
|
687
|
+
baseline = git_output(task_module, "rev-parse", "HEAD")
|
|
688
|
+
|
|
689
|
+
extra_worktree = root / "submodule-extra-worktree"
|
|
690
|
+
git(
|
|
691
|
+
task_module,
|
|
692
|
+
"worktree",
|
|
693
|
+
"add",
|
|
694
|
+
"-q",
|
|
695
|
+
"-b",
|
|
696
|
+
"extra-check",
|
|
697
|
+
str(extra_worktree),
|
|
698
|
+
baseline,
|
|
699
|
+
)
|
|
700
|
+
(extra_worktree / "module.txt").write_text("external dirty data\n", encoding="utf-8")
|
|
701
|
+
extra_blocked = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
702
|
+
self.assertNotEqual(0, extra_blocked.returncode)
|
|
703
|
+
self.assertIn("additional linked worktrees", extra_blocked.stdout + extra_blocked.stderr)
|
|
704
|
+
self.assertEqual(
|
|
705
|
+
"external dirty data\n",
|
|
706
|
+
(extra_worktree / "module.txt").read_text(encoding="utf-8"),
|
|
707
|
+
)
|
|
708
|
+
self.assertEqual("M module.txt", git_output(extra_worktree, "status", "--short"))
|
|
709
|
+
self.assertTrue(worktree.exists())
|
|
710
|
+
self.assert_local_branch(repo, "codex/SUBMODULE-1", True)
|
|
711
|
+
|
|
712
|
+
(extra_worktree / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
713
|
+
git(task_module, "worktree", "remove", str(extra_worktree))
|
|
714
|
+
extra_tip = git_output(task_module, "rev-parse", "refs/heads/extra-check")
|
|
715
|
+
git(task_module, "update-ref", "-d", "refs/heads/extra-check", extra_tip)
|
|
716
|
+
|
|
717
|
+
git(task_module, "checkout", "-qb", "hidden")
|
|
718
|
+
(task_module / "hidden.txt").write_text("local-only history\n", encoding="utf-8")
|
|
719
|
+
git(task_module, "add", "hidden.txt")
|
|
720
|
+
git(task_module, "commit", "-qm", "hidden local commit")
|
|
721
|
+
hidden_commit = git_output(task_module, "rev-parse", "HEAD")
|
|
722
|
+
git(task_module, "checkout", "-q", "--detach", baseline)
|
|
723
|
+
self.assertEqual("", git_output(worktree, "status", "--porcelain=v1"))
|
|
724
|
+
self.assertEqual("", git_output(task_module, "status", "--porcelain=v1"))
|
|
725
|
+
|
|
726
|
+
hidden = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
727
|
+
self.assertNotEqual(0, hidden.returncode)
|
|
728
|
+
self.assertIn("local refs/reflogs", hidden.stdout + hidden.stderr)
|
|
729
|
+
self.assertEqual(hidden_commit, git_output(task_module, "rev-parse", "refs/heads/hidden"))
|
|
730
|
+
self.assertTrue(worktree.exists())
|
|
731
|
+
self.assert_local_branch(repo, "codex/SUBMODULE-1", True)
|
|
732
|
+
|
|
733
|
+
git(task_module, "push", "-q", "origin", "refs/heads/hidden:refs/heads/hidden")
|
|
734
|
+
git(
|
|
735
|
+
task_module,
|
|
736
|
+
"fetch",
|
|
737
|
+
"-q",
|
|
738
|
+
"origin",
|
|
739
|
+
"refs/heads/hidden:refs/remotes/origin/hidden",
|
|
740
|
+
)
|
|
741
|
+
|
|
742
|
+
git(module, "update-ref", "-d", "refs/heads/hidden", hidden_commit)
|
|
743
|
+
git(module, "reflog", "expire", "--expire=now", "--all")
|
|
744
|
+
git(module, "gc", "--prune=now")
|
|
745
|
+
stale = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
746
|
+
self.assertNotEqual(0, stale.returncode)
|
|
747
|
+
self.assertIn("local refs/reflogs", stale.stdout + stale.stderr)
|
|
748
|
+
self.assertEqual(hidden_commit, git_output(task_module, "rev-parse", "refs/heads/hidden"))
|
|
749
|
+
self.assertTrue(worktree.exists())
|
|
750
|
+
|
|
751
|
+
git(task_module, "push", "-q", "origin", "refs/heads/hidden:refs/heads/hidden")
|
|
752
|
+
git(
|
|
753
|
+
task_module,
|
|
754
|
+
"fetch",
|
|
755
|
+
"-q",
|
|
756
|
+
"origin",
|
|
757
|
+
"refs/heads/hidden:refs/remotes/origin/hidden",
|
|
758
|
+
)
|
|
759
|
+
|
|
760
|
+
secret = task_module / ".secret"
|
|
761
|
+
secret.write_text("must survive\n", encoding="utf-8")
|
|
762
|
+
blocked = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
763
|
+
self.assertNotEqual(0, blocked.returncode)
|
|
764
|
+
self.assertIn("vendor/module/.secret", blocked.stdout + blocked.stderr)
|
|
765
|
+
self.assertEqual("must survive\n", secret.read_text(encoding="utf-8"))
|
|
766
|
+
self.assertTrue(worktree.exists())
|
|
767
|
+
self.assert_local_branch(repo, "codex/SUBMODULE-1", True)
|
|
768
|
+
|
|
769
|
+
secret.unlink()
|
|
770
|
+
runtime_evidence = (
|
|
771
|
+
worktree / "vendor" / "module" / ".local" / "auto-coding-skill" / "gate.jsonl"
|
|
772
|
+
)
|
|
773
|
+
runtime_evidence.parent.mkdir(parents=True, exist_ok=True)
|
|
774
|
+
runtime_evidence.write_text("disposable runtime data\n", encoding="utf-8")
|
|
775
|
+
self.ap(repo, "task-finish", "SUBMODULE-1")
|
|
776
|
+
|
|
777
|
+
self.assertFalse(worktree.exists())
|
|
778
|
+
self.assert_local_branch(repo, "codex/SUBMODULE-1", False)
|
|
779
|
+
self.assert_remote_branch(remote, "codex/SUBMODULE-1", False)
|
|
780
|
+
self.assertFalse(self.registry_manifest_path(repo, "SUBMODULE-1").exists())
|
|
781
|
+
self.assertEqual("module baseline\n", (module / "module.txt").read_text(encoding="utf-8"))
|
|
782
|
+
self.assertEqual(
|
|
783
|
+
primary_submodule_status,
|
|
784
|
+
git_output(repo, "submodule", "status", "--", "vendor/module"),
|
|
785
|
+
)
|
|
786
|
+
self.assertEqual(
|
|
787
|
+
primary_submodule_url,
|
|
788
|
+
git_output(repo, "config", "--get", "submodule.vendor/module.url"),
|
|
789
|
+
)
|
|
790
|
+
self.assertEqual("", git_output(repo / "vendor" / "module", "status", "--porcelain=v1"))
|
|
791
|
+
|
|
792
|
+
git(module, "update-ref", "-d", "refs/heads/hidden", hidden_commit)
|
|
793
|
+
git(module, "reflog", "expire", "--expire=now", "--all")
|
|
794
|
+
git(module, "gc", "--prune=now")
|
|
795
|
+
self.assertNotEqual(
|
|
796
|
+
0,
|
|
797
|
+
git(module, "cat-file", "-e", f"{hidden_commit}^{{commit}}", check=False).returncode,
|
|
798
|
+
)
|
|
799
|
+
recovery_root = (
|
|
800
|
+
self.registry_manifest_path(repo, "SUBMODULE-1").parents[1]
|
|
801
|
+
/ "submodule-recovery"
|
|
802
|
+
)
|
|
803
|
+
recovery_repos = sorted((recovery_root / "repos").glob("*.git"))
|
|
804
|
+
self.assertTrue(recovery_repos)
|
|
805
|
+
self.assertTrue(
|
|
806
|
+
any(
|
|
807
|
+
command(
|
|
808
|
+
repo,
|
|
809
|
+
"git",
|
|
810
|
+
f"--git-dir={candidate}",
|
|
811
|
+
"cat-file",
|
|
812
|
+
"-e",
|
|
813
|
+
f"{hidden_commit}^{{commit}}",
|
|
814
|
+
check=False,
|
|
815
|
+
).returncode
|
|
816
|
+
== 0
|
|
817
|
+
for candidate in recovery_repos
|
|
818
|
+
),
|
|
819
|
+
"durable recovery storage must retain submodule commits after remote deletion",
|
|
820
|
+
)
|
|
821
|
+
self.assertTrue(list((recovery_root / "snapshots").rglob("*.json")))
|
|
822
|
+
|
|
823
|
+
def test_submodule_urls_are_worktree_local_and_common_changes_are_not_overwritten(self) -> None:
|
|
824
|
+
root, repo, _ = self.make_repo()
|
|
825
|
+
module = root / "config-module-source"
|
|
826
|
+
module.mkdir()
|
|
827
|
+
git(module, "init", "-q", "-b", "main")
|
|
828
|
+
git(module, "config", "user.email", "module@example.com")
|
|
829
|
+
git(module, "config", "user.name", "Module Author")
|
|
830
|
+
(module / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
831
|
+
git(module, "add", "module.txt")
|
|
832
|
+
git(module, "commit", "-qm", "module baseline")
|
|
833
|
+
module_b = root / "config-module-source-b"
|
|
834
|
+
git(root, "clone", "-q", str(module), str(module_b))
|
|
835
|
+
git(
|
|
836
|
+
repo,
|
|
837
|
+
"-c",
|
|
838
|
+
"protocol.file.allow=always",
|
|
839
|
+
"submodule",
|
|
840
|
+
"add",
|
|
841
|
+
"-q",
|
|
842
|
+
str(module),
|
|
843
|
+
"vendor/module",
|
|
844
|
+
)
|
|
845
|
+
git(repo, "commit", "-qam", "add initially uninitialized submodule")
|
|
846
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
847
|
+
git(repo, "submodule", "-q", "deinit", "-f", "--", "vendor/module")
|
|
848
|
+
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.url", check=False)
|
|
849
|
+
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.active", check=False)
|
|
850
|
+
before_status = git_output(repo, "submodule", "status", "--", "vendor/module")
|
|
851
|
+
self.assertTrue(before_status.startswith("-"))
|
|
852
|
+
|
|
853
|
+
worktree = self.start_task(repo, "SUBMODULE-CONFIG")
|
|
854
|
+
self.assertEqual(
|
|
855
|
+
str(module),
|
|
856
|
+
git_output(worktree, "config", "--worktree", "--get", "submodule.vendor/module.url"),
|
|
857
|
+
)
|
|
858
|
+
gitmodules = worktree / ".gitmodules"
|
|
859
|
+
gitmodules.write_text(
|
|
860
|
+
gitmodules.read_text(encoding="utf-8").replace(str(module), str(module_b)),
|
|
861
|
+
encoding="utf-8",
|
|
862
|
+
)
|
|
863
|
+
git(
|
|
864
|
+
worktree,
|
|
865
|
+
"config",
|
|
866
|
+
"--local",
|
|
867
|
+
"submodule.vendor/module.url",
|
|
868
|
+
str(module_b),
|
|
869
|
+
)
|
|
870
|
+
git(worktree, "config", "--local", "submodule.vendor/module.active", "true")
|
|
871
|
+
conflict = self.ap(worktree, "task-submodule-sync", "SUBMODULE-CONFIG", check=False)
|
|
872
|
+
self.assertNotEqual(0, conflict.returncode)
|
|
873
|
+
self.assertIn("shared submodule config changed", (conflict.stdout + conflict.stderr).lower())
|
|
874
|
+
self.assertEqual(
|
|
875
|
+
str(module_b),
|
|
876
|
+
git_output(repo, "config", "--local", "--get", "submodule.vendor/module.url"),
|
|
877
|
+
)
|
|
878
|
+
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.url")
|
|
879
|
+
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.active")
|
|
880
|
+
self.ap(worktree, "task-submodule-sync", "SUBMODULE-CONFIG")
|
|
881
|
+
self.assertEqual(
|
|
882
|
+
str(module_b),
|
|
883
|
+
git_output(worktree, "config", "--worktree", "--get", "submodule.vendor/module.url"),
|
|
884
|
+
)
|
|
885
|
+
self.assertNotEqual(
|
|
886
|
+
0,
|
|
887
|
+
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
888
|
+
)
|
|
889
|
+
|
|
890
|
+
git(
|
|
891
|
+
worktree,
|
|
892
|
+
"-c",
|
|
893
|
+
"protocol.file.allow=always",
|
|
894
|
+
"submodule",
|
|
895
|
+
"update",
|
|
896
|
+
"--init",
|
|
897
|
+
"--recursive",
|
|
898
|
+
)
|
|
899
|
+
self.assertEqual(
|
|
900
|
+
str(module_b),
|
|
901
|
+
git_output(worktree / "vendor" / "module", "remote", "get-url", "origin"),
|
|
902
|
+
)
|
|
903
|
+
self.assertNotEqual(
|
|
904
|
+
0,
|
|
905
|
+
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
906
|
+
)
|
|
907
|
+
self.assertNotEqual(
|
|
908
|
+
0,
|
|
909
|
+
git(repo, "config", "--local", "--get", "submodule.vendor/module.active", check=False).returncode,
|
|
910
|
+
)
|
|
911
|
+
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
912
|
+
self.ap(
|
|
913
|
+
worktree,
|
|
914
|
+
"commit-push",
|
|
915
|
+
"SUBMODULE-CONFIG",
|
|
916
|
+
"--msg",
|
|
917
|
+
"SUBMODULE-CONFIG: ready",
|
|
918
|
+
)
|
|
919
|
+
self.ap(repo, "task-integrate", "SUBMODULE-CONFIG")
|
|
920
|
+
|
|
921
|
+
self.assertEqual(before_status, git_output(repo, "submodule", "status", "--", "vendor/module"))
|
|
922
|
+
self.assertNotEqual(
|
|
923
|
+
0,
|
|
924
|
+
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
925
|
+
)
|
|
926
|
+
|
|
927
|
+
def test_relative_submodule_url_uses_task_base_instead_of_control_checkout(self) -> None:
|
|
928
|
+
root, repo, super_remote = self.make_repo()
|
|
929
|
+
module_source = root / "relative-module-source"
|
|
930
|
+
module_source.mkdir()
|
|
931
|
+
git(module_source, "init", "-q", "-b", "main")
|
|
932
|
+
git(module_source, "config", "user.email", "module@example.com")
|
|
933
|
+
git(module_source, "config", "user.name", "Module Author")
|
|
934
|
+
(module_source / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
935
|
+
git(module_source, "add", "module.txt")
|
|
936
|
+
git(module_source, "commit", "-qm", "module baseline")
|
|
937
|
+
module_a = root / "module-a.git"
|
|
938
|
+
module_b = root / "module-b.git"
|
|
939
|
+
git(root, "clone", "-q", "--bare", str(module_source), str(module_a))
|
|
940
|
+
git(root, "clone", "-q", "--bare", str(module_source), str(module_b))
|
|
941
|
+
|
|
942
|
+
git(
|
|
943
|
+
repo,
|
|
944
|
+
"-c",
|
|
945
|
+
"protocol.file.allow=always",
|
|
946
|
+
"submodule",
|
|
947
|
+
"add",
|
|
948
|
+
"-q",
|
|
949
|
+
str(module_a),
|
|
950
|
+
"vendor/module",
|
|
951
|
+
)
|
|
952
|
+
gitmodules = repo / ".gitmodules"
|
|
953
|
+
gitmodules.write_text(
|
|
954
|
+
gitmodules.read_text(encoding="utf-8").replace(str(module_a), "../module-a.git"),
|
|
955
|
+
encoding="utf-8",
|
|
956
|
+
)
|
|
957
|
+
git(repo, "commit", "-qam", "add relative submodule URL")
|
|
958
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
959
|
+
git(repo, "submodule", "-q", "deinit", "-f", "--", "vendor/module")
|
|
960
|
+
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.url", check=False)
|
|
961
|
+
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.active", check=False)
|
|
962
|
+
|
|
963
|
+
git(repo, "branch", "alternate", "dev")
|
|
964
|
+
alternate = root / "alternate-base"
|
|
965
|
+
git(repo, "worktree", "add", "-q", str(alternate), "alternate")
|
|
966
|
+
alternate_gitmodules = alternate / ".gitmodules"
|
|
967
|
+
alternate_gitmodules.write_text(
|
|
968
|
+
alternate_gitmodules.read_text(encoding="utf-8").replace(
|
|
969
|
+
"../module-a.git",
|
|
970
|
+
"../module-b.git",
|
|
971
|
+
),
|
|
972
|
+
encoding="utf-8",
|
|
973
|
+
)
|
|
974
|
+
git(alternate, "commit", "-qam", "use alternate relative submodule URL")
|
|
975
|
+
git(alternate, "push", "-q", "origin", "alternate")
|
|
976
|
+
git(repo, "worktree", "remove", str(alternate))
|
|
977
|
+
upstream_root = root / "upstream"
|
|
978
|
+
upstream_root.mkdir()
|
|
979
|
+
upstream_super = upstream_root / "super.git"
|
|
980
|
+
git(root, "clone", "-q", "--bare", str(super_remote), str(upstream_super))
|
|
981
|
+
git(repo, "remote", "add", "upstream", str(upstream_super))
|
|
982
|
+
|
|
983
|
+
self.ap(
|
|
984
|
+
repo,
|
|
985
|
+
"task-start",
|
|
986
|
+
"RELATIVE-BASE",
|
|
987
|
+
"--base",
|
|
988
|
+
"upstream/alternate",
|
|
989
|
+
"--target-branch",
|
|
990
|
+
"alternate",
|
|
991
|
+
"--remote",
|
|
992
|
+
"upstream",
|
|
993
|
+
)
|
|
994
|
+
worktree = self.task_worktree(repo, "RELATIVE-BASE")
|
|
995
|
+
self.assertIn("../module-b.git", (worktree / ".gitmodules").read_text(encoding="utf-8"))
|
|
996
|
+
self.assertEqual(
|
|
997
|
+
module_b.resolve(),
|
|
998
|
+
Path(
|
|
999
|
+
git_output(
|
|
1000
|
+
worktree,
|
|
1001
|
+
"config",
|
|
1002
|
+
"--worktree",
|
|
1003
|
+
"--get",
|
|
1004
|
+
"submodule.vendor/module.url",
|
|
1005
|
+
)
|
|
1006
|
+
).resolve(),
|
|
1007
|
+
)
|
|
1008
|
+
git(
|
|
1009
|
+
worktree,
|
|
1010
|
+
"-c",
|
|
1011
|
+
"protocol.file.allow=always",
|
|
1012
|
+
"submodule",
|
|
1013
|
+
"update",
|
|
1014
|
+
"--init",
|
|
1015
|
+
"--recursive",
|
|
1016
|
+
)
|
|
1017
|
+
self.assertEqual(
|
|
1018
|
+
module_b.resolve(),
|
|
1019
|
+
Path(
|
|
1020
|
+
git_output(worktree / "vendor" / "module", "remote", "get-url", "origin")
|
|
1021
|
+
).resolve(),
|
|
1022
|
+
)
|
|
1023
|
+
self.assertNotEqual(
|
|
1024
|
+
0,
|
|
1025
|
+
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
1026
|
+
)
|
|
1027
|
+
|
|
1028
|
+
def test_cleanup_blocks_deinitialized_residual_submodule_git_history(self) -> None:
|
|
1029
|
+
root, repo, remote = self.make_repo()
|
|
1030
|
+
for name in ("a", "b"):
|
|
1031
|
+
module = root / f"residual-module-{name}"
|
|
1032
|
+
module.mkdir()
|
|
1033
|
+
git(module, "init", "-q", "-b", "main")
|
|
1034
|
+
git(module, "config", "user.email", f"{name}@example.com")
|
|
1035
|
+
git(module, "config", "user.name", f"Module {name.upper()}")
|
|
1036
|
+
(module / "module.txt").write_text(f"module {name}\n", encoding="utf-8")
|
|
1037
|
+
git(module, "add", "module.txt")
|
|
1038
|
+
git(module, "commit", "-qm", f"module {name} baseline")
|
|
1039
|
+
git(
|
|
1040
|
+
repo,
|
|
1041
|
+
"-c",
|
|
1042
|
+
"protocol.file.allow=always",
|
|
1043
|
+
"submodule",
|
|
1044
|
+
"add",
|
|
1045
|
+
"-q",
|
|
1046
|
+
str(module),
|
|
1047
|
+
f"vendor/{name}",
|
|
1048
|
+
)
|
|
1049
|
+
git(repo, "commit", "-qam", "add residual-state submodules")
|
|
1050
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
1051
|
+
|
|
1052
|
+
worktree = self.start_task(repo, "SUBMODULE-RESIDUAL")
|
|
1053
|
+
git(
|
|
1054
|
+
worktree,
|
|
1055
|
+
"-c",
|
|
1056
|
+
"protocol.file.allow=always",
|
|
1057
|
+
"submodule",
|
|
1058
|
+
"update",
|
|
1059
|
+
"--init",
|
|
1060
|
+
"--recursive",
|
|
1061
|
+
)
|
|
1062
|
+
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
1063
|
+
self.ap(
|
|
1064
|
+
worktree,
|
|
1065
|
+
"commit-push",
|
|
1066
|
+
"SUBMODULE-RESIDUAL",
|
|
1067
|
+
"--msg",
|
|
1068
|
+
"SUBMODULE-RESIDUAL: ready",
|
|
1069
|
+
)
|
|
1070
|
+
self.ap(repo, "task-integrate", "SUBMODULE-RESIDUAL", "--keep-worktree")
|
|
1071
|
+
|
|
1072
|
+
module_b = worktree / "vendor" / "b"
|
|
1073
|
+
baseline = git_output(module_b, "rev-parse", "HEAD")
|
|
1074
|
+
git(module_b, "checkout", "-qb", "hidden")
|
|
1075
|
+
(module_b / "hidden.txt").write_text("local-only residual history\n", encoding="utf-8")
|
|
1076
|
+
git(module_b, "add", "hidden.txt")
|
|
1077
|
+
git(module_b, "commit", "-qm", "hidden residual commit")
|
|
1078
|
+
hidden_commit = git_output(module_b, "rev-parse", "HEAD")
|
|
1079
|
+
module_b_git_dir = Path(git_output(module_b, "rev-parse", "--git-dir"))
|
|
1080
|
+
if not module_b_git_dir.is_absolute():
|
|
1081
|
+
module_b_git_dir = (module_b / module_b_git_dir).resolve()
|
|
1082
|
+
git(module_b, "checkout", "-q", "--detach", baseline)
|
|
1083
|
+
git(worktree, "submodule", "-q", "deinit", "-f", "--", "vendor/b")
|
|
1084
|
+
module_b_url = git_output(
|
|
1085
|
+
repo,
|
|
1086
|
+
"config",
|
|
1087
|
+
"--file",
|
|
1088
|
+
str(repo / ".gitmodules"),
|
|
1089
|
+
"--get",
|
|
1090
|
+
"submodule.vendor/b.url",
|
|
1091
|
+
)
|
|
1092
|
+
git(repo, "config", "--local", "submodule.vendor/b.url", module_b_url)
|
|
1093
|
+
git(repo, "config", "--local", "submodule.vendor/b.active", "true")
|
|
1094
|
+
self.assertFalse((worktree / "vendor" / "b" / ".git").exists())
|
|
1095
|
+
self.assertEqual(
|
|
1096
|
+
hidden_commit,
|
|
1097
|
+
command(
|
|
1098
|
+
repo,
|
|
1099
|
+
"git",
|
|
1100
|
+
f"--git-dir={module_b_git_dir}",
|
|
1101
|
+
"rev-parse",
|
|
1102
|
+
"refs/heads/hidden",
|
|
1103
|
+
).stdout.strip(),
|
|
1104
|
+
)
|
|
1105
|
+
|
|
1106
|
+
blocked = self.ap(repo, "task-finish", "SUBMODULE-RESIDUAL", check=False)
|
|
1107
|
+
self.assertNotEqual(0, blocked.returncode)
|
|
1108
|
+
self.assertIn("residual module Git directory", blocked.stdout + blocked.stderr)
|
|
1109
|
+
self.assertTrue(worktree.exists())
|
|
1110
|
+
self.assertTrue(module_b_git_dir.exists())
|
|
1111
|
+
self.assertEqual(
|
|
1112
|
+
hidden_commit,
|
|
1113
|
+
command(
|
|
1114
|
+
repo,
|
|
1115
|
+
"git",
|
|
1116
|
+
f"--git-dir={module_b_git_dir}",
|
|
1117
|
+
"rev-parse",
|
|
1118
|
+
"refs/heads/hidden",
|
|
1119
|
+
).stdout.strip(),
|
|
1120
|
+
)
|
|
1121
|
+
self.assert_local_branch(repo, "codex/SUBMODULE-RESIDUAL", True)
|
|
1122
|
+
self.assert_remote_branch(remote, "codex/SUBMODULE-RESIDUAL", True)
|
|
1123
|
+
self.assertTrue(self.registry_manifest_path(repo, "SUBMODULE-RESIDUAL").exists())
|
|
1124
|
+
self.assertTrue((worktree / "vendor" / "a" / ".git").exists())
|
|
1125
|
+
|
|
1126
|
+
def test_changed_remote_task_branch_stays_cleanup_pending_until_safe_retry(self) -> None:
|
|
1127
|
+
root, repo, remote = self.make_repo()
|
|
1128
|
+
worktree = self.start_task(repo, "REMOTE-RACE")
|
|
1129
|
+
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
1130
|
+
self.ap(
|
|
1131
|
+
worktree,
|
|
1132
|
+
"commit-push",
|
|
1133
|
+
"REMOTE-RACE",
|
|
1134
|
+
"--msg",
|
|
1135
|
+
"REMOTE-RACE: ready",
|
|
1136
|
+
)
|
|
1137
|
+
self.ap(repo, "task-integrate", "REMOTE-RACE", "--keep-worktree")
|
|
1138
|
+
|
|
1139
|
+
attacker = root / "attacker"
|
|
1140
|
+
git(root, "clone", "-q", str(remote), str(attacker))
|
|
1141
|
+
git(attacker, "config", "user.email", "other@example.com")
|
|
1142
|
+
git(attacker, "config", "user.name", "Other Writer")
|
|
1143
|
+
git(attacker, "checkout", "-qb", "remote-race", "origin/codex/REMOTE-RACE")
|
|
1144
|
+
(attacker / "other.txt").write_text("other writer\n", encoding="utf-8")
|
|
1145
|
+
git(attacker, "add", "other.txt")
|
|
1146
|
+
git(attacker, "commit", "-qm", "other writer advances task branch")
|
|
1147
|
+
git(attacker, "push", "-q", "origin", "HEAD:refs/heads/codex/REMOTE-RACE")
|
|
1148
|
+
changed_remote_tip = git_output(remote, "rev-parse", "refs/heads/codex/REMOTE-RACE")
|
|
1149
|
+
|
|
1150
|
+
finish = self.ap(repo, "task-finish", "REMOTE-RACE")
|
|
1151
|
+
self.assertIn("remote_branch_deleted=false", finish.stdout + finish.stderr)
|
|
1152
|
+
self.assertFalse(worktree.exists())
|
|
1153
|
+
self.assert_local_branch(repo, "codex/REMOTE-RACE", False)
|
|
1154
|
+
self.assertEqual(
|
|
1155
|
+
changed_remote_tip,
|
|
1156
|
+
git_output(remote, "rev-parse", "refs/heads/codex/REMOTE-RACE"),
|
|
1157
|
+
)
|
|
1158
|
+
manifest_path = self.registry_manifest_path(repo, "REMOTE-RACE")
|
|
1159
|
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
1160
|
+
self.assertEqual("cleanup-pending", manifest["state"])
|
|
1161
|
+
|
|
1162
|
+
prune = self.ap(repo, "task-prune")
|
|
1163
|
+
self.assertIn("remote cleanup pending", prune.stdout + prune.stderr)
|
|
1164
|
+
self.assertTrue(manifest_path.exists())
|
|
1165
|
+
self.assert_remote_branch(remote, "codex/REMOTE-RACE", True)
|
|
1166
|
+
|
|
1167
|
+
git(remote, "update-ref", "-d", "refs/heads/codex/REMOTE-RACE", changed_remote_tip)
|
|
1168
|
+
self.ap(repo, "task-prune")
|
|
1169
|
+
self.assertFalse(manifest_path.exists())
|
|
1170
|
+
self.assert_remote_branch(remote, "codex/REMOTE-RACE", False)
|
|
1171
|
+
|
|
1172
|
+
def test_gate_mutation_aborts_before_staging_or_commit(self) -> None:
|
|
1173
|
+
_, repo, remote = self.make_repo()
|
|
1174
|
+
worktree = self.start_task(repo, "MUTATE-1")
|
|
1175
|
+
engineering = worktree / "docs" / "ENGINEERING.md"
|
|
1176
|
+
text = engineering.read_text(encoding="utf-8")
|
|
1177
|
+
text = text.replace("gate_standard: 'true'", "gate_standard: 'printf gate-change >> shared.txt'")
|
|
1178
|
+
text = text.replace("gate_full: 'true'", "gate_full: 'printf gate-change >> shared.txt'")
|
|
1179
|
+
engineering.write_text(text, encoding="utf-8")
|
|
1180
|
+
git(worktree, "add", "docs/ENGINEERING.md")
|
|
1181
|
+
git(worktree, "commit", "-qm", "configure mutating gate")
|
|
1182
|
+
before = git_output(worktree, "rev-parse", "HEAD")
|
|
1183
|
+
(worktree / "task.txt").write_text("task\n", encoding="utf-8")
|
|
1184
|
+
|
|
1185
|
+
result = self.ap(
|
|
1186
|
+
worktree,
|
|
1187
|
+
"commit-push",
|
|
1188
|
+
"MUTATE-1",
|
|
1189
|
+
"--msg",
|
|
1190
|
+
"MUTATE-1: must abort",
|
|
1191
|
+
check=False,
|
|
1192
|
+
)
|
|
1193
|
+
|
|
1194
|
+
self.assertNotEqual(0, result.returncode)
|
|
1195
|
+
self.assertIn("gate changed", (result.stdout + result.stderr).lower())
|
|
1196
|
+
self.assertEqual(before, git_output(worktree, "rev-parse", "HEAD"))
|
|
1197
|
+
self.assertEqual("", git_output(worktree, "diff", "--cached", "--name-only"))
|
|
1198
|
+
self.assert_remote_branch(remote, "codex/MUTATE-1", False)
|
|
1199
|
+
|
|
1200
|
+
def test_post_commit_hook_mutation_prevents_push(self) -> None:
|
|
1201
|
+
_, repo, remote = self.make_repo()
|
|
1202
|
+
worktree = self.start_task(repo, "COMMIT-HOOK")
|
|
1203
|
+
self.install_hook(
|
|
1204
|
+
repo,
|
|
1205
|
+
"post-commit",
|
|
1206
|
+
'root="$(git rev-parse --show-toplevel)"\n'
|
|
1207
|
+
'printf "hook mutation\\n" > "$root/hook-after.txt"\n',
|
|
1208
|
+
)
|
|
1209
|
+
before = git_output(worktree, "rev-parse", "HEAD")
|
|
1210
|
+
(worktree / "payload.txt").write_text("payload\n", encoding="utf-8")
|
|
1211
|
+
|
|
1212
|
+
result = self.ap(
|
|
1213
|
+
worktree,
|
|
1214
|
+
"commit-push",
|
|
1215
|
+
"COMMIT-HOOK",
|
|
1216
|
+
"--msg",
|
|
1217
|
+
"COMMIT-HOOK: must stay local",
|
|
1218
|
+
check=False,
|
|
1219
|
+
)
|
|
1220
|
+
|
|
1221
|
+
self.assertNotEqual(0, result.returncode)
|
|
1222
|
+
self.assertIn("not pushed", (result.stdout + result.stderr).lower())
|
|
1223
|
+
self.assertNotEqual(before, git_output(worktree, "rev-parse", "HEAD"))
|
|
1224
|
+
self.assertEqual("hook mutation\n", (worktree / "hook-after.txt").read_text(encoding="utf-8"))
|
|
1225
|
+
self.assert_remote_branch(remote, "codex/COMMIT-HOOK", False)
|
|
1226
|
+
|
|
1227
|
+
def test_missing_config_defaults_to_worktree_and_legacy_is_explicit(self) -> None:
|
|
1228
|
+
_, default_repo, _ = self.make_repo(_MISSING)
|
|
1229
|
+
(default_repo / "shared.txt").write_text("must stay isolated\n", encoding="utf-8")
|
|
1230
|
+
default_commit = self.assert_rejected_without_mutation(
|
|
1231
|
+
default_repo,
|
|
1232
|
+
"commit-push",
|
|
1233
|
+
"DEFAULT-1",
|
|
1234
|
+
"--msg",
|
|
1235
|
+
"DEFAULT-1: must start first",
|
|
1236
|
+
)
|
|
1237
|
+
self.assertIn("task-start", (default_commit.stdout + default_commit.stderr).lower())
|
|
1238
|
+
default_repo.joinpath("shared.txt").write_text("baseline\n", encoding="utf-8")
|
|
1239
|
+
self.start_task(default_repo, "DEFAULT-1")
|
|
1240
|
+
|
|
1241
|
+
_, legacy_repo, legacy_remote = self.make_repo("legacy")
|
|
1242
|
+
(legacy_repo / "shared.txt").write_text("legacy shared checkout\n", encoding="utf-8")
|
|
1243
|
+
self.ap(
|
|
1244
|
+
legacy_repo,
|
|
1245
|
+
"commit-push",
|
|
1246
|
+
"LEGACY-1",
|
|
1247
|
+
"--msg",
|
|
1248
|
+
"LEGACY-1: legacy compatibility",
|
|
1249
|
+
)
|
|
1250
|
+
self.assertEqual(
|
|
1251
|
+
"legacy shared checkout",
|
|
1252
|
+
git_output(legacy_remote, "show", "refs/heads/dev:shared.txt"),
|
|
1253
|
+
)
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
if __name__ == "__main__":
|
|
1257
|
+
unittest.main()
|