@elvis1513/auto-coding-skill 4.3.6 → 5.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 +26 -748
- package/cli/assets/managed-install.json +38 -1
- package/cli/assets/skill/SKILL.md +15 -98
- package/cli/assets/skill/data/templates/ENVIRONMENT.md +30 -0
- package/cli/assets/skill/data/templates/architecture/.gitkeep +1 -0
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +39 -143
- package/cli/assets/skill/data/templates/deployment/.gitkeep +1 -0
- package/cli/assets/skill/data/templates/design/.gitkeep +1 -0
- package/cli/assets/skill/data/templates/interfaces/.gitkeep +1 -0
- package/cli/assets/skill/data/templates/product/.gitkeep +1 -0
- package/cli/src/index.js +127 -2589
- package/cli/src/sync-assets.js +38 -95
- package/package.json +9 -17
- package/cli/assets/agents/browser-debugger.toml +0 -27
- package/cli/assets/agents/docs-researcher.toml +0 -18
- package/cli/assets/agents/explorer.toml +0 -26
- package/cli/assets/agents/fixer.toml +0 -29
- package/cli/assets/agents/reviewer.toml +0 -50
- package/cli/assets/skill/data/contracts/orchestration-v1.schema.json +0 -567
- package/cli/assets/skill/data/policies/feedback-resolutions-v1.json +0 -68
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +0 -657
- package/cli/assets/skill/data/templates/ENGINEERING.md +0 -115
- package/cli/assets/skill/data/templates/tools/ap.py +0 -16
- package/cli/assets/skill/requirements.txt +0 -1
- package/cli/assets/skill/scripts/ap.py +0 -17630
- package/cli/assets/skill/scripts/core.py +0 -510
- package/cli/assets/skill/scripts/http_checks.py +0 -92
- package/cli/assets/skill/scripts/install_integrity.py +0 -427
- package/cli/assets/skill/scripts/scaffold_templates.py +0 -325
- package/cli/tests/ap_concurrency_test.py +0 -3520
- package/cli/tests/ap_profiles_test.py +0 -3261
- package/cli/tests/core_shell_test.py +0 -345
- package/cli/tests/index.test.js +0 -2967
|
@@ -1,3520 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import hashlib
|
|
5
|
-
import json
|
|
6
|
-
import os
|
|
7
|
-
import shutil
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
import tempfile
|
|
11
|
-
import time
|
|
12
|
-
import unittest
|
|
13
|
-
from datetime import datetime, timedelta, timezone
|
|
14
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
|
|
17
|
-
import yaml
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
21
|
-
AP_SCRIPT = REPO_ROOT / "src" / "auto-coding-skill" / "scripts" / "ap.py"
|
|
22
|
-
_MISSING = object()
|
|
23
|
-
_TEST_OWNER = os.environ.get("CODEX_THREAD_ID") or "concurrency-test-owner"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def command(
|
|
27
|
-
cwd: Path,
|
|
28
|
-
*args: str,
|
|
29
|
-
check: bool = True,
|
|
30
|
-
input_text: str | None = None,
|
|
31
|
-
) -> subprocess.CompletedProcess[str]:
|
|
32
|
-
env = os.environ.copy()
|
|
33
|
-
env.setdefault("CODEX_THREAD_ID", _TEST_OWNER)
|
|
34
|
-
env.setdefault("AUTOCODING_TEST_RUNNER_OVERRIDE", "1")
|
|
35
|
-
result = subprocess.run(
|
|
36
|
-
list(args),
|
|
37
|
-
cwd=cwd,
|
|
38
|
-
check=False,
|
|
39
|
-
text=True,
|
|
40
|
-
input=input_text,
|
|
41
|
-
capture_output=True,
|
|
42
|
-
timeout=30,
|
|
43
|
-
env=env,
|
|
44
|
-
)
|
|
45
|
-
if check and result.returncode != 0:
|
|
46
|
-
raise AssertionError(
|
|
47
|
-
f"command failed ({result.returncode}): {' '.join(args)}\n"
|
|
48
|
-
f"stdout:\n{result.stdout}\nstderr:\n{result.stderr}"
|
|
49
|
-
)
|
|
50
|
-
return result
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def git(cwd: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess[str]:
|
|
54
|
-
return command(cwd, "git", *args, check=check)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def git_output(cwd: Path, *args: str) -> str:
|
|
58
|
-
return git(cwd, *args).stdout.strip()
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def base_config(isolation: str | object = "adaptive") -> dict:
|
|
62
|
-
config = {
|
|
63
|
-
"workflow": {"mode": "dev", "profile": "auto", "completion": "push"},
|
|
64
|
-
"project": {"name": "concurrency-test"},
|
|
65
|
-
"access": {
|
|
66
|
-
"project": {
|
|
67
|
-
"frontend": {"url": "https://project-front.test", "username": "front", "password": "front-pass"},
|
|
68
|
-
"backend": {"url": "https://project-back.test", "username": "back", "password": "back-pass"},
|
|
69
|
-
},
|
|
70
|
-
"jenkins": {
|
|
71
|
-
"frontend": {"url": "https://jenkins-front.test", "username": "front", "password": "front-pass"},
|
|
72
|
-
"backend": {"url": "https://jenkins-back.test", "username": "back", "password": "back-pass"},
|
|
73
|
-
},
|
|
74
|
-
"gitlab": {"url": "https://gitlab.test", "username": "git", "password": "git-pass"},
|
|
75
|
-
"nexus": {
|
|
76
|
-
"frontend": {"url": "https://nexus.test", "username": "nexus", "password": "nexus-pass"},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
"commands": {
|
|
80
|
-
"gate_changed": "true",
|
|
81
|
-
"gate_standard": "true",
|
|
82
|
-
"gate_full": "true",
|
|
83
|
-
},
|
|
84
|
-
"gate": {
|
|
85
|
-
"default_scope": "changed",
|
|
86
|
-
"fallback_scope": "changed",
|
|
87
|
-
"full_on_unknown": False,
|
|
88
|
-
"no_change_scope": "changed",
|
|
89
|
-
"rules": [],
|
|
90
|
-
},
|
|
91
|
-
"risk": {
|
|
92
|
-
"rules": [
|
|
93
|
-
{"name": "test-review", "paths": ["**"], "review": "required"},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
"structure": {"enabled": False, "enforcement": "advisory"},
|
|
97
|
-
"verification": {
|
|
98
|
-
"target_env_required": False,
|
|
99
|
-
"jenkins_required": False,
|
|
100
|
-
},
|
|
101
|
-
"docs": {
|
|
102
|
-
"taskbook": "docs/tasks/taskbook.md",
|
|
103
|
-
"closure_log": "docs/tasks/closure-log.md",
|
|
104
|
-
"evidence_log": "docs/tasks/evidence.jsonl",
|
|
105
|
-
"design_dir": "docs/design",
|
|
106
|
-
"ledger_check_enabled": False,
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
if isolation is not _MISSING:
|
|
110
|
-
config["concurrency"] = {
|
|
111
|
-
"isolation": isolation,
|
|
112
|
-
"base_ref": "origin/dev",
|
|
113
|
-
"target_branch": "dev",
|
|
114
|
-
"branch_prefix": "codex/",
|
|
115
|
-
# Tests replace this with an absolute path outside the primary checkout.
|
|
116
|
-
"worktree_root": "",
|
|
117
|
-
"cleanup_merged": True,
|
|
118
|
-
"delete_remote_branch": True,
|
|
119
|
-
}
|
|
120
|
-
return config
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
124
|
-
def make_repo(
|
|
125
|
-
self,
|
|
126
|
-
isolation: str | object = "worktree",
|
|
127
|
-
*,
|
|
128
|
-
require_review: bool = True,
|
|
129
|
-
) -> tuple[Path, Path, Path]:
|
|
130
|
-
temp = tempfile.TemporaryDirectory(prefix="autocoding-concurrency-")
|
|
131
|
-
self.addCleanup(temp.cleanup)
|
|
132
|
-
root = Path(temp.name)
|
|
133
|
-
repo = root / "project"
|
|
134
|
-
remote = root / "origin.git"
|
|
135
|
-
worktrees = root / "worktrees"
|
|
136
|
-
repo.mkdir()
|
|
137
|
-
|
|
138
|
-
git(root, "init", "--bare", "-q", str(remote))
|
|
139
|
-
git(repo, "init", "-q", "-b", "dev")
|
|
140
|
-
git(repo, "config", "user.email", "test@example.com")
|
|
141
|
-
git(repo, "config", "user.name", "Auto Coding Test")
|
|
142
|
-
|
|
143
|
-
config = base_config(isolation)
|
|
144
|
-
if not require_review:
|
|
145
|
-
config["risk"]["rules"] = []
|
|
146
|
-
if "concurrency" in config:
|
|
147
|
-
config["concurrency"]["worktree_root"] = str(worktrees)
|
|
148
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
149
|
-
engineering.parent.mkdir(parents=True)
|
|
150
|
-
engineering.write_text(
|
|
151
|
-
"---\n"
|
|
152
|
-
+ yaml.safe_dump(config, allow_unicode=True, sort_keys=False)
|
|
153
|
-
+ "---\n# Engineering\n",
|
|
154
|
-
encoding="utf-8",
|
|
155
|
-
)
|
|
156
|
-
tasks = repo / "docs" / "tasks"
|
|
157
|
-
tasks.mkdir(parents=True)
|
|
158
|
-
(tasks / "taskbook.md").write_text("# Taskbook\n", encoding="utf-8")
|
|
159
|
-
(tasks / "closure-log.md").write_text("# Closure Log\n", encoding="utf-8")
|
|
160
|
-
(repo / "shared.txt").write_text("baseline\n", encoding="utf-8")
|
|
161
|
-
git(repo, "add", "-A")
|
|
162
|
-
git(repo, "commit", "-qm", "baseline")
|
|
163
|
-
git(repo, "remote", "add", "origin", str(remote))
|
|
164
|
-
git(repo, "push", "-qu", "origin", "dev")
|
|
165
|
-
git(remote, "symbolic-ref", "HEAD", "refs/heads/dev")
|
|
166
|
-
return root, repo, remote
|
|
167
|
-
|
|
168
|
-
def ap(
|
|
169
|
-
self,
|
|
170
|
-
repo: Path,
|
|
171
|
-
*args: str,
|
|
172
|
-
check: bool = True,
|
|
173
|
-
) -> subprocess.CompletedProcess[str]:
|
|
174
|
-
return command(
|
|
175
|
-
repo,
|
|
176
|
-
sys.executable,
|
|
177
|
-
str(AP_SCRIPT),
|
|
178
|
-
"--repo",
|
|
179
|
-
str(repo),
|
|
180
|
-
*args,
|
|
181
|
-
check=check,
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
def ap_script(
|
|
185
|
-
self,
|
|
186
|
-
repo: Path,
|
|
187
|
-
script: Path,
|
|
188
|
-
*args: str,
|
|
189
|
-
check: bool = True,
|
|
190
|
-
) -> subprocess.CompletedProcess[str]:
|
|
191
|
-
return command(
|
|
192
|
-
repo,
|
|
193
|
-
sys.executable,
|
|
194
|
-
str(script),
|
|
195
|
-
"--repo",
|
|
196
|
-
str(repo),
|
|
197
|
-
*args,
|
|
198
|
-
check=check,
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
def managed_runtime(self, root: Path, version: str = "4.3.6") -> Path:
|
|
202
|
-
install_root = root / "managed-runtime"
|
|
203
|
-
skill = install_root / ".agents" / "skills" / "auto-coding-skill"
|
|
204
|
-
shutil.copytree(REPO_ROOT / "src" / "auto-coding-skill", skill)
|
|
205
|
-
script = skill / "scripts" / "ap.py"
|
|
206
|
-
relative = ".agents/skills/auto-coding-skill/scripts/ap.py"
|
|
207
|
-
manifest = {
|
|
208
|
-
"schema_version": 1,
|
|
209
|
-
"skill_version": version,
|
|
210
|
-
"manifest_path": ".agents/managed-install.json",
|
|
211
|
-
"entries": [
|
|
212
|
-
{
|
|
213
|
-
"path": relative,
|
|
214
|
-
"source": "skill/scripts/ap.py",
|
|
215
|
-
"ownership": "exact",
|
|
216
|
-
"sha256": hashlib.sha256(script.read_bytes()).hexdigest(),
|
|
217
|
-
"executable": bool(script.stat().st_mode & 0o111),
|
|
218
|
-
"scope": "shared",
|
|
219
|
-
"version": version,
|
|
220
|
-
}
|
|
221
|
-
],
|
|
222
|
-
"managed_namespaces": [],
|
|
223
|
-
"preserved": [],
|
|
224
|
-
}
|
|
225
|
-
manifest_path = install_root / ".agents" / "managed-install.json"
|
|
226
|
-
manifest_path.parent.mkdir(parents=True, exist_ok=True)
|
|
227
|
-
manifest_path.write_text(json.dumps(manifest) + "\n", encoding="utf-8")
|
|
228
|
-
return script
|
|
229
|
-
|
|
230
|
-
def approve_task(self, repo: Path, task_id: str) -> str:
|
|
231
|
-
issued = json.loads(
|
|
232
|
-
self.ap(
|
|
233
|
-
repo,
|
|
234
|
-
"review-assignment",
|
|
235
|
-
task_id,
|
|
236
|
-
"--reviewer",
|
|
237
|
-
"test-reviewer",
|
|
238
|
-
"--json",
|
|
239
|
-
).stdout
|
|
240
|
-
)
|
|
241
|
-
fingerprint = issued["assignment"]["diff_fingerprint"]
|
|
242
|
-
self.ap(
|
|
243
|
-
repo,
|
|
244
|
-
"task-review",
|
|
245
|
-
task_id,
|
|
246
|
-
"--verdict",
|
|
247
|
-
"approved",
|
|
248
|
-
"--diff-fingerprint",
|
|
249
|
-
fingerprint,
|
|
250
|
-
"--reviewer",
|
|
251
|
-
"test-reviewer",
|
|
252
|
-
)
|
|
253
|
-
return fingerprint
|
|
254
|
-
|
|
255
|
-
def claim_direct(self, repo: Path, *owned_paths: str) -> str:
|
|
256
|
-
args: list[str] = ["classify", "--task-kind", "change", "--claim-direct", "--json"]
|
|
257
|
-
for path in owned_paths:
|
|
258
|
-
args.extend(["--planned-path", path])
|
|
259
|
-
payload = json.loads(self.ap(repo, *args).stdout)
|
|
260
|
-
return payload["direct_claim"]["id"]
|
|
261
|
-
|
|
262
|
-
def commit_push(self, repo: Path, task_id: str, message: str) -> subprocess.CompletedProcess[str]:
|
|
263
|
-
self.approve_task(repo, task_id)
|
|
264
|
-
return self.ap(repo, "commit-push", task_id, "--msg", message)
|
|
265
|
-
|
|
266
|
-
def artifact_reviewer_runner(
|
|
267
|
-
self,
|
|
268
|
-
root: Path,
|
|
269
|
-
*tokens: str,
|
|
270
|
-
runtime_script: Path = AP_SCRIPT,
|
|
271
|
-
) -> str:
|
|
272
|
-
fake_reviewer = root / "fake-artifact-reviewer.py"
|
|
273
|
-
fake_reviewer.write_text(
|
|
274
|
-
"import hashlib, json, os, pathlib, subprocess, sys\n"
|
|
275
|
-
"if os.environ.get('CODEX_THREAD_ID'):\n"
|
|
276
|
-
" raise SystemExit(9)\n"
|
|
277
|
-
"assignment_path = pathlib.Path(os.environ['AUTOCODING_REVIEW_ASSIGNMENT'])\n"
|
|
278
|
-
"assignment_bytes = assignment_path.read_bytes()\n"
|
|
279
|
-
"if hashlib.sha256(assignment_bytes).hexdigest() != os.environ['AUTOCODING_REVIEW_ASSIGNMENT_SHA256']:\n"
|
|
280
|
-
" raise SystemExit(10)\n"
|
|
281
|
-
"assignment = json.loads(assignment_bytes)\n"
|
|
282
|
-
"artifact_path = pathlib.Path(assignment['diff_artifact_path'])\n"
|
|
283
|
-
"emitted = subprocess.run([sys.executable, sys.argv[1], '--repo', str(pathlib.Path.cwd()), "
|
|
284
|
-
"'review-artifact', '--file', str(assignment_path)], capture_output=True, check=False)\n"
|
|
285
|
-
"if emitted.returncode != 0:\n"
|
|
286
|
-
" raise SystemExit(11)\n"
|
|
287
|
-
"payload = emitted.stdout\n"
|
|
288
|
-
"actual = hashlib.sha256(payload).hexdigest()\n"
|
|
289
|
-
"if actual != assignment['diff_artifact_sha256']:\n"
|
|
290
|
-
" raise SystemExit(12)\n"
|
|
291
|
-
"if os.environ.get('AUTOCODING_REVIEW_DIFF_ARTIFACT') != str(artifact_path):\n"
|
|
292
|
-
" raise SystemExit(13)\n"
|
|
293
|
-
"if os.environ.get('AUTOCODING_REVIEW_DIFF_ARTIFACT_SHA256') != actual:\n"
|
|
294
|
-
" raise SystemExit(14)\n"
|
|
295
|
-
"if int(os.environ['AUTOCODING_REVIEW_TIMEOUT_SECONDS']) not in (150, 360):\n"
|
|
296
|
-
" raise SystemExit(15)\n"
|
|
297
|
-
"for token in sys.argv[2:]:\n"
|
|
298
|
-
" if token.encode('utf-8') not in payload:\n"
|
|
299
|
-
" raise SystemExit(16)\n"
|
|
300
|
-
"print(json.dumps({'verdict': 'approved', 'summary': 'artifact reviewed', "
|
|
301
|
-
"'evidence': ['diff_artifact_sha256=' + actual]}))\n",
|
|
302
|
-
encoding="utf-8",
|
|
303
|
-
)
|
|
304
|
-
return json.dumps([sys.executable, str(fake_reviewer), str(runtime_script), *tokens])
|
|
305
|
-
|
|
306
|
-
def task_worktree(self, repo: Path, task_id: str) -> Path:
|
|
307
|
-
wanted = f"refs/heads/codex/{task_id}"
|
|
308
|
-
current_path: Path | None = None
|
|
309
|
-
for line in git_output(repo, "worktree", "list", "--porcelain").splitlines():
|
|
310
|
-
if line.startswith("worktree "):
|
|
311
|
-
current_path = Path(line.removeprefix("worktree "))
|
|
312
|
-
elif line == f"branch {wanted}" and current_path is not None:
|
|
313
|
-
return current_path
|
|
314
|
-
self.fail(f"no worktree registered for {wanted}")
|
|
315
|
-
|
|
316
|
-
def start_task(self, repo: Path, task_id: str, owned_path: str = ".") -> Path:
|
|
317
|
-
result = self.ap(
|
|
318
|
-
repo,
|
|
319
|
-
"task-start",
|
|
320
|
-
task_id,
|
|
321
|
-
"--base",
|
|
322
|
-
"origin/dev",
|
|
323
|
-
"--owned-path",
|
|
324
|
-
owned_path,
|
|
325
|
-
"--isolated",
|
|
326
|
-
"--review-required",
|
|
327
|
-
)
|
|
328
|
-
worktree = self.task_worktree(repo, task_id)
|
|
329
|
-
self.assertIn(task_id, result.stdout + result.stderr)
|
|
330
|
-
self.assertTrue(worktree.is_dir())
|
|
331
|
-
self.assertNotEqual(repo.resolve(), worktree.resolve())
|
|
332
|
-
self.assertNotIn(repo.resolve(), worktree.resolve().parents)
|
|
333
|
-
self.assertEqual(f"codex/{task_id}", git_output(worktree, "branch", "--show-current"))
|
|
334
|
-
return worktree
|
|
335
|
-
|
|
336
|
-
def assert_local_branch(self, repo: Path, branch: str, exists: bool) -> None:
|
|
337
|
-
result = git(repo, "show-ref", "--verify", "--quiet", f"refs/heads/{branch}", check=False)
|
|
338
|
-
self.assertEqual(exists, result.returncode == 0, branch)
|
|
339
|
-
|
|
340
|
-
def assert_remote_branch(self, remote: Path, branch: str, exists: bool) -> None:
|
|
341
|
-
result = git(
|
|
342
|
-
remote,
|
|
343
|
-
"show-ref",
|
|
344
|
-
"--verify",
|
|
345
|
-
"--quiet",
|
|
346
|
-
f"refs/heads/{branch}",
|
|
347
|
-
check=False,
|
|
348
|
-
)
|
|
349
|
-
self.assertEqual(exists, result.returncode == 0, branch)
|
|
350
|
-
|
|
351
|
-
def assert_rejected_without_mutation(
|
|
352
|
-
self,
|
|
353
|
-
repo: Path,
|
|
354
|
-
*args: str,
|
|
355
|
-
) -> subprocess.CompletedProcess[str]:
|
|
356
|
-
before_head = git_output(repo, "rev-parse", "HEAD")
|
|
357
|
-
before_status = git_output(repo, "status", "--porcelain=v1", "--untracked-files=all")
|
|
358
|
-
result = self.ap(repo, *args, check=False)
|
|
359
|
-
self.assertNotEqual(0, result.returncode, result.stdout + result.stderr)
|
|
360
|
-
self.assertEqual(before_head, git_output(repo, "rev-parse", "HEAD"))
|
|
361
|
-
self.assertEqual(
|
|
362
|
-
before_status,
|
|
363
|
-
git_output(repo, "status", "--porcelain=v1", "--untracked-files=all"),
|
|
364
|
-
)
|
|
365
|
-
return result
|
|
366
|
-
|
|
367
|
-
def test_task_start_rejects_unknown_full_gate_policy_before_creating_branch(self) -> None:
|
|
368
|
-
_, repo, _ = self.make_repo()
|
|
369
|
-
(repo / "AGENTS.md").write_text(
|
|
370
|
-
"# Workflow\n- High-risk work\n must run the real full gate before push.\n",
|
|
371
|
-
encoding="utf-8",
|
|
372
|
-
)
|
|
373
|
-
result = self.ap(
|
|
374
|
-
repo,
|
|
375
|
-
"task-start",
|
|
376
|
-
"POLICY-START",
|
|
377
|
-
"--base",
|
|
378
|
-
"origin/dev",
|
|
379
|
-
"--owned-path",
|
|
380
|
-
".",
|
|
381
|
-
check=False,
|
|
382
|
-
)
|
|
383
|
-
self.assertNotEqual(0, result.returncode)
|
|
384
|
-
self.assertIn("AGENTS.md:2", result.stdout + result.stderr)
|
|
385
|
-
self.assert_local_branch(repo, "codex/POLICY-START", False)
|
|
386
|
-
|
|
387
|
-
def test_task_start_rejects_owner_and_writer_that_conflict_with_runtime_identity(self) -> None:
|
|
388
|
-
_, repo, _ = self.make_repo()
|
|
389
|
-
for field in ("owner", "writer"):
|
|
390
|
-
with self.subTest(field=field):
|
|
391
|
-
task_id = f"IDENTITY-{field.upper()}"
|
|
392
|
-
rejected = self.ap(
|
|
393
|
-
repo,
|
|
394
|
-
"task-start",
|
|
395
|
-
task_id,
|
|
396
|
-
"--base",
|
|
397
|
-
"origin/dev",
|
|
398
|
-
"--owned-path",
|
|
399
|
-
"shared.txt",
|
|
400
|
-
"--isolated",
|
|
401
|
-
"--review-required",
|
|
402
|
-
f"--{field}",
|
|
403
|
-
"different-runtime-actor",
|
|
404
|
-
check=False,
|
|
405
|
-
)
|
|
406
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
407
|
-
self.assertIn("does not match CODEX_THREAD_ID", rejected.stdout + rejected.stderr)
|
|
408
|
-
self.assertFalse(self.registry_manifest_path(repo, task_id).exists())
|
|
409
|
-
self.assert_local_branch(repo, f"codex/{task_id}", False)
|
|
410
|
-
|
|
411
|
-
def test_task_start_rejects_legacy_gate_yaml_before_creating_branch(self) -> None:
|
|
412
|
-
_, repo, _ = self.make_repo()
|
|
413
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
414
|
-
text = engineering.read_text(encoding="utf-8").replace(
|
|
415
|
-
" full_on_unknown: false\n",
|
|
416
|
-
" full_on_unknown: true\n full_on:\n - prod_config\n",
|
|
417
|
-
).replace(
|
|
418
|
-
" rules: []\n",
|
|
419
|
-
" rules:\n - match:\n - Jenkinsfile\n scope: full\n commands:\n - gate_full\n",
|
|
420
|
-
)
|
|
421
|
-
engineering.write_text(text, encoding="utf-8")
|
|
422
|
-
result = self.ap(
|
|
423
|
-
repo,
|
|
424
|
-
"task-start",
|
|
425
|
-
"POLICY-YAML",
|
|
426
|
-
"--base",
|
|
427
|
-
"origin/dev",
|
|
428
|
-
"--owned-path",
|
|
429
|
-
".",
|
|
430
|
-
check=False,
|
|
431
|
-
)
|
|
432
|
-
self.assertNotEqual(0, result.returncode)
|
|
433
|
-
self.assertIn("gate.full_on", result.stdout + result.stderr)
|
|
434
|
-
self.assertIn("gate.rules[0].scope", result.stdout + result.stderr)
|
|
435
|
-
self.assert_local_branch(repo, "codex/POLICY-YAML", False)
|
|
436
|
-
|
|
437
|
-
def test_commit_push_rejects_policy_added_after_task_start(self) -> None:
|
|
438
|
-
_, repo, _ = self.make_repo()
|
|
439
|
-
worktree = self.start_task(repo, "POLICY-PUSH")
|
|
440
|
-
(worktree / "AGENTS.md").write_text(
|
|
441
|
-
"# Workflow\nRuntime changes require the full gate.\n",
|
|
442
|
-
encoding="utf-8",
|
|
443
|
-
)
|
|
444
|
-
self.approve_task(worktree, "POLICY-PUSH")
|
|
445
|
-
result = self.ap(
|
|
446
|
-
worktree,
|
|
447
|
-
"commit-push",
|
|
448
|
-
"POLICY-PUSH",
|
|
449
|
-
"--msg",
|
|
450
|
-
"POLICY-PUSH: blocked",
|
|
451
|
-
check=False,
|
|
452
|
-
)
|
|
453
|
-
self.assertNotEqual(0, result.returncode)
|
|
454
|
-
self.assertIn("AGENTS.md:2", result.stdout + result.stderr)
|
|
455
|
-
self.assertEqual("", git_output(worktree, "diff", "--cached", "--name-only"))
|
|
456
|
-
|
|
457
|
-
def manifest_payloads(self, repo: Path) -> list[dict]:
|
|
458
|
-
common_dir_raw = git_output(repo, "rev-parse", "--git-common-dir")
|
|
459
|
-
common_dir = Path(common_dir_raw)
|
|
460
|
-
if not common_dir.is_absolute():
|
|
461
|
-
common_dir = (repo / common_dir).resolve()
|
|
462
|
-
payloads: list[dict] = []
|
|
463
|
-
for candidate in common_dir.rglob("*.json"):
|
|
464
|
-
try:
|
|
465
|
-
payload = json.loads(candidate.read_text(encoding="utf-8"))
|
|
466
|
-
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
|
467
|
-
continue
|
|
468
|
-
if isinstance(payload, dict):
|
|
469
|
-
payloads.append(payload)
|
|
470
|
-
return payloads
|
|
471
|
-
|
|
472
|
-
def registry_manifest_path(self, repo: Path, task_id: str) -> Path:
|
|
473
|
-
common_dir = Path(git_output(repo, "rev-parse", "--git-common-dir"))
|
|
474
|
-
if not common_dir.is_absolute():
|
|
475
|
-
common_dir = (repo / common_dir).resolve()
|
|
476
|
-
return common_dir / "auto-coding-skill" / "tasks" / f"{task_id}.json"
|
|
477
|
-
|
|
478
|
-
def shorten_review_deadline(
|
|
479
|
-
self,
|
|
480
|
-
repo: Path,
|
|
481
|
-
task_id: str,
|
|
482
|
-
issued: dict,
|
|
483
|
-
seconds: int = 2,
|
|
484
|
-
) -> None:
|
|
485
|
-
deadline = datetime.now(timezone.utc).replace(microsecond=0) + timedelta(seconds=seconds)
|
|
486
|
-
assignment = issued["assignment"]
|
|
487
|
-
assignment["deadline_at"] = deadline.isoformat()
|
|
488
|
-
assignment["issued_at"] = (deadline - timedelta(seconds=150)).isoformat()
|
|
489
|
-
assignment_path = Path(issued["assignment_path"])
|
|
490
|
-
assignment_path.write_text(json.dumps(assignment, indent=2) + "\n", encoding="utf-8")
|
|
491
|
-
manifest_path = self.registry_manifest_path(repo, task_id)
|
|
492
|
-
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
493
|
-
manifest["review"]["issued_at"] = assignment["issued_at"]
|
|
494
|
-
manifest["review"]["deadline_at"] = assignment["deadline_at"]
|
|
495
|
-
manifest["review"]["assignment_sha256"] = hashlib.sha256(
|
|
496
|
-
assignment_path.read_bytes()
|
|
497
|
-
).hexdigest()
|
|
498
|
-
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
499
|
-
|
|
500
|
-
def install_hook(self, repo: Path, name: str, body: str) -> Path:
|
|
501
|
-
common_dir = Path(git_output(repo, "rev-parse", "--git-common-dir"))
|
|
502
|
-
if not common_dir.is_absolute():
|
|
503
|
-
common_dir = (repo / common_dir).resolve()
|
|
504
|
-
hook = common_dir / "hooks" / name
|
|
505
|
-
hook.write_text("#!/bin/sh\nset -eu\n" + body, encoding="utf-8")
|
|
506
|
-
hook.chmod(0o755)
|
|
507
|
-
return hook
|
|
508
|
-
|
|
509
|
-
def update_config(self, repo: Path, update) -> None:
|
|
510
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
511
|
-
raw = engineering.read_text(encoding="utf-8")
|
|
512
|
-
_, frontmatter, body = raw.split("---", 2)
|
|
513
|
-
config = yaml.safe_load(frontmatter)
|
|
514
|
-
update(config)
|
|
515
|
-
engineering.write_text(
|
|
516
|
-
"---\n"
|
|
517
|
-
+ yaml.safe_dump(config, allow_unicode=True, sort_keys=False)
|
|
518
|
-
+ "---"
|
|
519
|
-
+ body,
|
|
520
|
-
encoding="utf-8",
|
|
521
|
-
)
|
|
522
|
-
git(repo, "add", "docs/ENGINEERING.md")
|
|
523
|
-
git(repo, "commit", "-qm", "update test workflow config")
|
|
524
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
525
|
-
|
|
526
|
-
def test_task_start_creates_external_worktree_manifest_and_status(self) -> None:
|
|
527
|
-
_, repo, _ = self.make_repo()
|
|
528
|
-
worktree = self.start_task(repo, "START-1")
|
|
529
|
-
|
|
530
|
-
status = self.ap(repo, "task-status", "START-1")
|
|
531
|
-
rendered_status = status.stdout + status.stderr
|
|
532
|
-
self.assertIn("START-1", rendered_status)
|
|
533
|
-
self.assertIn("codex/START-1", rendered_status)
|
|
534
|
-
self.assertIn(str(worktree), rendered_status)
|
|
535
|
-
status_payload = json.loads(
|
|
536
|
-
self.ap(repo, "task-status", "START-1", "--json").stdout
|
|
537
|
-
)["tasks"][0]
|
|
538
|
-
self.assertFalse(status_payload["has_task_commits"])
|
|
539
|
-
self.assertFalse(status_payload["merged_into_target"])
|
|
540
|
-
|
|
541
|
-
serialized_payloads = [json.dumps(item, sort_keys=True) for item in self.manifest_payloads(repo)]
|
|
542
|
-
self.assertTrue(
|
|
543
|
-
any(
|
|
544
|
-
"START-1" in payload
|
|
545
|
-
and "codex/START-1" in payload
|
|
546
|
-
and str(worktree) in payload
|
|
547
|
-
for payload in serialized_payloads
|
|
548
|
-
),
|
|
549
|
-
"task-start must persist a task manifest in the Git common directory",
|
|
550
|
-
)
|
|
551
|
-
self.assertFalse(
|
|
552
|
-
(worktree / "docs" / "tasks" / "active" / "START-1.md").exists(),
|
|
553
|
-
"4.0 machine state must not create tracked active-task documents",
|
|
554
|
-
)
|
|
555
|
-
|
|
556
|
-
def test_clean_serial_task_uses_direct_branch_and_no_diff_is_noop(self) -> None:
|
|
557
|
-
_, repo, remote = self.make_repo("adaptive", require_review=False)
|
|
558
|
-
worktrees_before = git_output(repo, "worktree", "list", "--porcelain")
|
|
559
|
-
unnecessary = self.ap(
|
|
560
|
-
repo,
|
|
561
|
-
"task-start",
|
|
562
|
-
"DIRECT-SKIP",
|
|
563
|
-
"--base",
|
|
564
|
-
"origin/dev",
|
|
565
|
-
"--owned-path",
|
|
566
|
-
"shared.txt",
|
|
567
|
-
check=False,
|
|
568
|
-
)
|
|
569
|
-
self.assertNotEqual(0, unnecessary.returncode)
|
|
570
|
-
self.assertIn("does not need a machine task lifecycle", unnecessary.stdout + unnecessary.stderr)
|
|
571
|
-
self.assertFalse(self.registry_manifest_path(repo, "DIRECT-SKIP").exists())
|
|
572
|
-
start = self.ap(
|
|
573
|
-
repo,
|
|
574
|
-
"task-start",
|
|
575
|
-
"DIRECT-1",
|
|
576
|
-
"--base",
|
|
577
|
-
"origin/dev",
|
|
578
|
-
"--owned-path",
|
|
579
|
-
"shared.txt",
|
|
580
|
-
"--force-lifecycle",
|
|
581
|
-
)
|
|
582
|
-
self.assertIn("execution_mode=direct", start.stdout)
|
|
583
|
-
self.assertEqual(worktrees_before, git_output(repo, "worktree", "list", "--porcelain"))
|
|
584
|
-
self.assert_local_branch(repo, "codex/DIRECT-1", False)
|
|
585
|
-
status = json.loads(self.ap(repo, "task-status", "DIRECT-1", "--json").stdout)["tasks"][0]
|
|
586
|
-
self.assertEqual("direct", status["execution_mode"])
|
|
587
|
-
self.assertFalse(status["has_task_commits"])
|
|
588
|
-
self.assertFalse(status["merged_into_target"])
|
|
589
|
-
self.assertFalse((repo / "docs" / "tasks" / "active" / "DIRECT-1.md").exists())
|
|
590
|
-
|
|
591
|
-
(repo / "shared.txt").write_text("direct\n", encoding="utf-8")
|
|
592
|
-
pushed = self.ap(repo, "commit-push", "DIRECT-1", "--msg", "DIRECT-1: update")
|
|
593
|
-
self.assertIn("execution_mode=direct", pushed.stdout)
|
|
594
|
-
self.assertEqual("direct", git_output(remote, "show", "refs/heads/dev:shared.txt"))
|
|
595
|
-
self.assertFalse(self.registry_manifest_path(repo, "DIRECT-1").exists())
|
|
596
|
-
|
|
597
|
-
before = git_output(repo, "rev-parse", "HEAD")
|
|
598
|
-
self.ap(repo, "task-start", "DIRECT-NOOP", "--owned-path", "shared.txt", "--force-lifecycle")
|
|
599
|
-
noop = self.ap(repo, "commit-push", "DIRECT-NOOP", "--msg", "DIRECT-NOOP: none")
|
|
600
|
-
self.assertIn("NOOP", noop.stdout)
|
|
601
|
-
self.assertEqual(before, git_output(repo, "rev-parse", "HEAD"))
|
|
602
|
-
self.assertFalse(self.registry_manifest_path(repo, "DIRECT-NOOP").exists())
|
|
603
|
-
|
|
604
|
-
def test_commit_push_accepts_already_staged_deletion(self) -> None:
|
|
605
|
-
_, repo, remote = self.make_repo()
|
|
606
|
-
worktree = self.start_task(repo, "STAGED-DELETE", "shared.txt")
|
|
607
|
-
(worktree / "shared.txt").unlink()
|
|
608
|
-
git(worktree, "add", "-A", "--", "shared.txt")
|
|
609
|
-
self.approve_task(worktree, "STAGED-DELETE")
|
|
610
|
-
|
|
611
|
-
result = self.ap(
|
|
612
|
-
worktree,
|
|
613
|
-
"commit-push",
|
|
614
|
-
"STAGED-DELETE",
|
|
615
|
-
"--msg",
|
|
616
|
-
"STAGED-DELETE: remove shared file",
|
|
617
|
-
)
|
|
618
|
-
|
|
619
|
-
self.assertIn("commit-push", result.stdout)
|
|
620
|
-
self.assertNotEqual(
|
|
621
|
-
0,
|
|
622
|
-
git(
|
|
623
|
-
remote,
|
|
624
|
-
"cat-file",
|
|
625
|
-
"-e",
|
|
626
|
-
"refs/heads/codex/STAGED-DELETE:shared.txt",
|
|
627
|
-
check=False,
|
|
628
|
-
).returncode,
|
|
629
|
-
)
|
|
630
|
-
self.assertEqual("", git_output(worktree, "status", "--short"))
|
|
631
|
-
|
|
632
|
-
def test_staged_rename_requires_ownership_of_both_paths(self) -> None:
|
|
633
|
-
_, repo, remote = self.make_repo()
|
|
634
|
-
worktree = self.start_task(repo, "RENAME-DENY", "renamed.txt")
|
|
635
|
-
git(worktree, "mv", "shared.txt", "renamed.txt")
|
|
636
|
-
status = json.loads(self.ap(worktree, "task-status", "RENAME-DENY", "--json").stdout)
|
|
637
|
-
fingerprint = status["tasks"][0]["current_diff_fingerprint"]
|
|
638
|
-
|
|
639
|
-
denied = self.ap(
|
|
640
|
-
worktree,
|
|
641
|
-
"task-review",
|
|
642
|
-
"RENAME-DENY",
|
|
643
|
-
"--verdict",
|
|
644
|
-
"approved",
|
|
645
|
-
"--diff-fingerprint",
|
|
646
|
-
fingerprint,
|
|
647
|
-
"--reviewer",
|
|
648
|
-
"test-reviewer",
|
|
649
|
-
check=False,
|
|
650
|
-
)
|
|
651
|
-
|
|
652
|
-
self.assertNotEqual(0, denied.returncode)
|
|
653
|
-
self.assertIn("shared.txt", denied.stdout + denied.stderr)
|
|
654
|
-
self.assert_remote_branch(remote, "codex/RENAME-DENY", False)
|
|
655
|
-
|
|
656
|
-
_, allowed_repo, allowed_remote = self.make_repo()
|
|
657
|
-
started = self.ap(
|
|
658
|
-
allowed_repo,
|
|
659
|
-
"task-start",
|
|
660
|
-
"RENAME-ALLOW",
|
|
661
|
-
"--base",
|
|
662
|
-
"origin/dev",
|
|
663
|
-
"--owned-path",
|
|
664
|
-
"shared.txt",
|
|
665
|
-
"--owned-path",
|
|
666
|
-
"renamed.txt",
|
|
667
|
-
"--isolated",
|
|
668
|
-
"--review-required",
|
|
669
|
-
)
|
|
670
|
-
self.assertIn("RENAME-ALLOW", started.stdout)
|
|
671
|
-
allowed_worktree = self.task_worktree(allowed_repo, "RENAME-ALLOW")
|
|
672
|
-
git(allowed_worktree, "mv", "shared.txt", "renamed.txt")
|
|
673
|
-
self.commit_push(allowed_worktree, "RENAME-ALLOW", "RENAME-ALLOW: rename shared file")
|
|
674
|
-
self.assertEqual(
|
|
675
|
-
"baseline",
|
|
676
|
-
git_output(allowed_remote, "show", "refs/heads/codex/RENAME-ALLOW:renamed.txt"),
|
|
677
|
-
)
|
|
678
|
-
self.assertNotEqual(
|
|
679
|
-
0,
|
|
680
|
-
git(
|
|
681
|
-
allowed_remote,
|
|
682
|
-
"cat-file",
|
|
683
|
-
"-e",
|
|
684
|
-
"refs/heads/codex/RENAME-ALLOW:shared.txt",
|
|
685
|
-
check=False,
|
|
686
|
-
).returncode,
|
|
687
|
-
)
|
|
688
|
-
|
|
689
|
-
def test_commit_push_stages_mixed_index_and_worktree_state(self) -> None:
|
|
690
|
-
_, repo, remote = self.make_repo()
|
|
691
|
-
worktree = self.start_task(repo, "MIXED-STAGE")
|
|
692
|
-
(worktree / "shared.txt").write_text("staged-v1\n", encoding="utf-8")
|
|
693
|
-
git(worktree, "add", "shared.txt")
|
|
694
|
-
(worktree / "shared.txt").write_text("worktree-v2\n", encoding="utf-8")
|
|
695
|
-
(worktree / "new-file.txt").write_text("new\n", encoding="utf-8")
|
|
696
|
-
|
|
697
|
-
self.commit_push(worktree, "MIXED-STAGE", "MIXED-STAGE: commit final task state")
|
|
698
|
-
|
|
699
|
-
ref = "refs/heads/codex/MIXED-STAGE"
|
|
700
|
-
self.assertEqual("worktree-v2", git_output(remote, "show", f"{ref}:shared.txt"))
|
|
701
|
-
self.assertEqual("new", git_output(remote, "show", f"{ref}:new-file.txt"))
|
|
702
|
-
|
|
703
|
-
def test_final_gate_receipt_reuses_manual_pass_and_commit_retry(self) -> None:
|
|
704
|
-
root, repo, remote = self.make_repo()
|
|
705
|
-
gate_count = root / "gate-count"
|
|
706
|
-
self.update_config(
|
|
707
|
-
repo,
|
|
708
|
-
lambda config: config["commands"].update(
|
|
709
|
-
{"gate_changed": f"printf x >> {gate_count}"}
|
|
710
|
-
),
|
|
711
|
-
)
|
|
712
|
-
worktree = self.start_task(repo, "GATE-REUSE", "shared.txt")
|
|
713
|
-
(worktree / "shared.txt").write_text("validated\n", encoding="utf-8")
|
|
714
|
-
self.ap(worktree, "light-gate", "--scope", "changed")
|
|
715
|
-
self.assertEqual("x", gate_count.read_text(encoding="utf-8"))
|
|
716
|
-
self.approve_task(worktree, "GATE-REUSE")
|
|
717
|
-
common_dir = Path(git_output(worktree, "rev-parse", "--git-common-dir"))
|
|
718
|
-
if not common_dir.is_absolute():
|
|
719
|
-
common_dir = (worktree / common_dir).resolve()
|
|
720
|
-
fail_once = common_dir / "precommit-failed-once"
|
|
721
|
-
self.install_hook(
|
|
722
|
-
repo,
|
|
723
|
-
"pre-commit",
|
|
724
|
-
f'if [ ! -f "{fail_once}" ]; then touch "{fail_once}"; exit 1; fi\n',
|
|
725
|
-
)
|
|
726
|
-
|
|
727
|
-
first = self.ap(
|
|
728
|
-
worktree,
|
|
729
|
-
"commit-push",
|
|
730
|
-
"GATE-REUSE",
|
|
731
|
-
"--msg",
|
|
732
|
-
"GATE-REUSE: validated change",
|
|
733
|
-
check=False,
|
|
734
|
-
)
|
|
735
|
-
self.assertNotEqual(0, first.returncode)
|
|
736
|
-
self.assertIn("REUSED", first.stdout + first.stderr)
|
|
737
|
-
second = self.ap(
|
|
738
|
-
worktree,
|
|
739
|
-
"commit-push",
|
|
740
|
-
"GATE-REUSE",
|
|
741
|
-
"--msg",
|
|
742
|
-
"GATE-REUSE: validated change",
|
|
743
|
-
)
|
|
744
|
-
self.assertIn("REUSED", second.stdout + second.stderr)
|
|
745
|
-
self.assertEqual("x", gate_count.read_text(encoding="utf-8"))
|
|
746
|
-
self.assertEqual(
|
|
747
|
-
"validated",
|
|
748
|
-
git_output(remote, "show", "refs/heads/codex/GATE-REUSE:shared.txt"),
|
|
749
|
-
)
|
|
750
|
-
|
|
751
|
-
def test_final_gate_receipt_invalidates_when_content_changes(self) -> None:
|
|
752
|
-
root, repo, _ = self.make_repo()
|
|
753
|
-
gate_count = root / "gate-count-invalidated"
|
|
754
|
-
self.update_config(
|
|
755
|
-
repo,
|
|
756
|
-
lambda config: config["commands"].update(
|
|
757
|
-
{"gate_changed": f"printf x >> {gate_count}"}
|
|
758
|
-
),
|
|
759
|
-
)
|
|
760
|
-
worktree = self.start_task(repo, "GATE-INVALIDATE", "shared.txt")
|
|
761
|
-
(worktree / "shared.txt").write_text("first\n", encoding="utf-8")
|
|
762
|
-
self.ap(worktree, "light-gate", "--scope", "changed")
|
|
763
|
-
(worktree / "shared.txt").write_text("second\n", encoding="utf-8")
|
|
764
|
-
self.approve_task(worktree, "GATE-INVALIDATE")
|
|
765
|
-
|
|
766
|
-
result = self.ap(
|
|
767
|
-
worktree,
|
|
768
|
-
"commit-push",
|
|
769
|
-
"GATE-INVALIDATE",
|
|
770
|
-
"--msg",
|
|
771
|
-
"GATE-INVALIDATE: use current content",
|
|
772
|
-
)
|
|
773
|
-
|
|
774
|
-
self.assertNotIn("REUSED", result.stdout + result.stderr)
|
|
775
|
-
self.assertEqual("xx", gate_count.read_text(encoding="utf-8"))
|
|
776
|
-
|
|
777
|
-
def test_task_scope_add_expands_direct_scope_idempotently(self) -> None:
|
|
778
|
-
_, repo, remote = self.make_repo("adaptive", require_review=False)
|
|
779
|
-
self.ap(
|
|
780
|
-
repo,
|
|
781
|
-
"task-start",
|
|
782
|
-
"SCOPE-DIRECT",
|
|
783
|
-
"--owned-path",
|
|
784
|
-
"shared.txt",
|
|
785
|
-
"--force-lifecycle",
|
|
786
|
-
)
|
|
787
|
-
expanded = self.ap(
|
|
788
|
-
repo,
|
|
789
|
-
"task-scope-add",
|
|
790
|
-
"SCOPE-DIRECT",
|
|
791
|
-
"--owned-path",
|
|
792
|
-
"future.txt",
|
|
793
|
-
"--json",
|
|
794
|
-
)
|
|
795
|
-
payload = json.loads(expanded.stdout)
|
|
796
|
-
self.assertEqual("expanded", payload["status"])
|
|
797
|
-
self.assertEqual(2, payload["scope_revision"])
|
|
798
|
-
noop = json.loads(
|
|
799
|
-
self.ap(
|
|
800
|
-
repo,
|
|
801
|
-
"task-scope-add",
|
|
802
|
-
"SCOPE-DIRECT",
|
|
803
|
-
"--owned-path",
|
|
804
|
-
"future.txt",
|
|
805
|
-
"--json",
|
|
806
|
-
).stdout
|
|
807
|
-
)
|
|
808
|
-
self.assertEqual("noop", noop["status"])
|
|
809
|
-
self.assertEqual(2, noop["scope_revision"])
|
|
810
|
-
|
|
811
|
-
(repo / "future.txt").write_text("future\n", encoding="utf-8")
|
|
812
|
-
self.ap(
|
|
813
|
-
repo,
|
|
814
|
-
"commit-push",
|
|
815
|
-
"SCOPE-DIRECT",
|
|
816
|
-
"--msg",
|
|
817
|
-
"SCOPE-DIRECT: add future file",
|
|
818
|
-
)
|
|
819
|
-
self.assertEqual("future", git_output(remote, "show", "refs/heads/dev:future.txt"))
|
|
820
|
-
|
|
821
|
-
def test_task_scope_add_invalidates_review_and_blocks_conflicts(self) -> None:
|
|
822
|
-
_, repo, _ = self.make_repo()
|
|
823
|
-
first = self.start_task(repo, "SCOPE-FIRST", "shared.txt")
|
|
824
|
-
self.start_task(repo, "SCOPE-SECOND", "second-owned.txt")
|
|
825
|
-
(first / "shared.txt").write_text("reviewed\n", encoding="utf-8")
|
|
826
|
-
old_fingerprint = self.approve_task(first, "SCOPE-FIRST")
|
|
827
|
-
|
|
828
|
-
expanded = json.loads(
|
|
829
|
-
self.ap(
|
|
830
|
-
first,
|
|
831
|
-
"task-scope-add",
|
|
832
|
-
"SCOPE-FIRST",
|
|
833
|
-
"--owned-path",
|
|
834
|
-
"future.txt",
|
|
835
|
-
"--json",
|
|
836
|
-
).stdout
|
|
837
|
-
)
|
|
838
|
-
self.assertEqual(2, expanded["scope_revision"])
|
|
839
|
-
status = json.loads(self.ap(first, "task-status", "SCOPE-FIRST", "--json").stdout)["tasks"][0]
|
|
840
|
-
self.assertEqual("pending", status["review"]["verdict"])
|
|
841
|
-
self.assertNotEqual(old_fingerprint, status["current_diff_fingerprint"])
|
|
842
|
-
stale = self.ap(
|
|
843
|
-
first,
|
|
844
|
-
"task-review",
|
|
845
|
-
"SCOPE-FIRST",
|
|
846
|
-
"--verdict",
|
|
847
|
-
"approved",
|
|
848
|
-
"--diff-fingerprint",
|
|
849
|
-
old_fingerprint,
|
|
850
|
-
"--reviewer",
|
|
851
|
-
"test-reviewer",
|
|
852
|
-
check=False,
|
|
853
|
-
)
|
|
854
|
-
self.assertNotEqual(0, stale.returncode)
|
|
855
|
-
|
|
856
|
-
conflict = self.ap(
|
|
857
|
-
first,
|
|
858
|
-
"task-scope-add",
|
|
859
|
-
"SCOPE-FIRST",
|
|
860
|
-
"--owned-path",
|
|
861
|
-
"second-owned.txt",
|
|
862
|
-
check=False,
|
|
863
|
-
)
|
|
864
|
-
self.assertNotEqual(0, conflict.returncode)
|
|
865
|
-
self.assertIn("SCOPE-SECOND", conflict.stdout + conflict.stderr)
|
|
866
|
-
|
|
867
|
-
def test_task_scope_add_escalates_risk_without_moving_worktrees(self) -> None:
|
|
868
|
-
_, repo, _ = self.make_repo("adaptive", require_review=False)
|
|
869
|
-
self.ap(
|
|
870
|
-
repo,
|
|
871
|
-
"task-start",
|
|
872
|
-
"SCOPE-RISK",
|
|
873
|
-
"--owned-path",
|
|
874
|
-
"shared.txt",
|
|
875
|
-
"--force-lifecycle",
|
|
876
|
-
)
|
|
877
|
-
before = git_output(repo, "worktree", "list", "--porcelain")
|
|
878
|
-
expanded = json.loads(
|
|
879
|
-
self.ap(
|
|
880
|
-
repo,
|
|
881
|
-
"task-scope-add",
|
|
882
|
-
"SCOPE-RISK",
|
|
883
|
-
"--owned-path",
|
|
884
|
-
"backend/auth/token.go",
|
|
885
|
-
"--json",
|
|
886
|
-
).stdout
|
|
887
|
-
)
|
|
888
|
-
self.assertEqual("high-risk", expanded["effective_profile"])
|
|
889
|
-
self.assertTrue(expanded["review_required"])
|
|
890
|
-
self.assertEqual(before, git_output(repo, "worktree", "list", "--porcelain"))
|
|
891
|
-
|
|
892
|
-
def test_unnecessary_lifecycle_rejects_before_access_or_fetch_checks(self) -> None:
|
|
893
|
-
_, repo, _ = self.make_repo("adaptive", require_review=False)
|
|
894
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
895
|
-
text = engineering.read_text(encoding="utf-8")
|
|
896
|
-
engineering.write_text(text.replace("front-pass", "CHANGE_ME", 1), encoding="utf-8")
|
|
897
|
-
git(repo, "add", "docs/ENGINEERING.md")
|
|
898
|
-
git(repo, "commit", "-qm", "invalidate access for preflight test")
|
|
899
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
900
|
-
|
|
901
|
-
result = self.ap(
|
|
902
|
-
repo,
|
|
903
|
-
"task-start",
|
|
904
|
-
"DIRECT-PREFLIGHT",
|
|
905
|
-
"--base",
|
|
906
|
-
"origin/branch-that-must-not-be-fetched",
|
|
907
|
-
"--owned-path",
|
|
908
|
-
"shared.txt",
|
|
909
|
-
check=False,
|
|
910
|
-
)
|
|
911
|
-
output = result.stdout + result.stderr
|
|
912
|
-
self.assertNotEqual(0, result.returncode)
|
|
913
|
-
self.assertIn("does not need a machine task lifecycle", output)
|
|
914
|
-
self.assertNotIn("initialization is incomplete", output)
|
|
915
|
-
|
|
916
|
-
def test_continue_direct_can_adopt_owned_changes_for_new_review_lifecycle(self) -> None:
|
|
917
|
-
root, repo, remote = self.make_repo("adaptive", require_review=False)
|
|
918
|
-
claim = self.claim_direct(repo, "shared.txt")
|
|
919
|
-
(repo / "shared.txt").write_text("continued direct\n", encoding="utf-8")
|
|
920
|
-
started = self.ap(
|
|
921
|
-
repo,
|
|
922
|
-
"task-start",
|
|
923
|
-
"DIRECT-CONTINUE",
|
|
924
|
-
"--owned-path",
|
|
925
|
-
"shared.txt",
|
|
926
|
-
"--continue-direct",
|
|
927
|
-
"--direct-claim",
|
|
928
|
-
claim,
|
|
929
|
-
"--review-required",
|
|
930
|
-
)
|
|
931
|
-
self.assertIn("execution_mode=direct", started.stdout)
|
|
932
|
-
status = json.loads(
|
|
933
|
-
self.ap(repo, "task-status", "DIRECT-CONTINUE", "--json").stdout
|
|
934
|
-
)["tasks"][0]
|
|
935
|
-
self.assertEqual("direct", status["execution_mode"])
|
|
936
|
-
missing_reviewer = self.ap(
|
|
937
|
-
repo,
|
|
938
|
-
"task-review",
|
|
939
|
-
"DIRECT-CONTINUE",
|
|
940
|
-
"--verdict",
|
|
941
|
-
"approved",
|
|
942
|
-
"--diff-fingerprint",
|
|
943
|
-
status["current_diff_fingerprint"],
|
|
944
|
-
check=False,
|
|
945
|
-
)
|
|
946
|
-
self.assertNotEqual(0, missing_reviewer.returncode)
|
|
947
|
-
self.assertIn("explicit --reviewer", missing_reviewer.stdout + missing_reviewer.stderr)
|
|
948
|
-
runner = self.artifact_reviewer_runner(root, "continued direct")
|
|
949
|
-
reviewed = json.loads(
|
|
950
|
-
self.ap(
|
|
951
|
-
repo,
|
|
952
|
-
"review-run",
|
|
953
|
-
"DIRECT-CONTINUE",
|
|
954
|
-
"--reviewer",
|
|
955
|
-
"direct-reviewer",
|
|
956
|
-
"--runner-command-json",
|
|
957
|
-
runner,
|
|
958
|
-
"--json",
|
|
959
|
-
).stdout
|
|
960
|
-
)
|
|
961
|
-
self.assertEqual("approved", reviewed["verdict"])
|
|
962
|
-
assignment_path = Path(
|
|
963
|
-
json.loads(
|
|
964
|
-
self.registry_manifest_path(repo, "DIRECT-CONTINUE").read_text(encoding="utf-8")
|
|
965
|
-
)["review"]["assignment_path"]
|
|
966
|
-
)
|
|
967
|
-
pushed = self.ap(
|
|
968
|
-
repo,
|
|
969
|
-
"commit-push",
|
|
970
|
-
"DIRECT-CONTINUE",
|
|
971
|
-
"--msg",
|
|
972
|
-
"DIRECT-CONTINUE: update",
|
|
973
|
-
)
|
|
974
|
-
self.assertIn("execution_mode=direct", pushed.stdout)
|
|
975
|
-
self.assertEqual("continued direct", git_output(remote, "show", "refs/heads/dev:shared.txt"))
|
|
976
|
-
self.assertFalse(assignment_path.parent.exists())
|
|
977
|
-
|
|
978
|
-
claim = self.claim_direct(repo, "shared.txt")
|
|
979
|
-
(repo / "shared.txt").write_text("owned again\n", encoding="utf-8")
|
|
980
|
-
(repo / "unrelated.txt").write_text("unknown\n", encoding="utf-8")
|
|
981
|
-
rejected = self.ap(
|
|
982
|
-
repo,
|
|
983
|
-
"task-start",
|
|
984
|
-
"DIRECT-CONTINUE-BLOCKED",
|
|
985
|
-
"--owned-path",
|
|
986
|
-
"shared.txt",
|
|
987
|
-
"--continue-direct",
|
|
988
|
-
"--direct-claim",
|
|
989
|
-
claim,
|
|
990
|
-
"--review-required",
|
|
991
|
-
check=False,
|
|
992
|
-
)
|
|
993
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
994
|
-
self.assertIn("unrelated.txt", rejected.stdout + rejected.stderr)
|
|
995
|
-
self.assertFalse(self.registry_manifest_path(repo, "DIRECT-CONTINUE-BLOCKED").exists())
|
|
996
|
-
|
|
997
|
-
def test_reviewer_cannot_be_current_writer(self) -> None:
|
|
998
|
-
_, repo, _ = self.make_repo()
|
|
999
|
-
self.ap(
|
|
1000
|
-
repo,
|
|
1001
|
-
"task-start",
|
|
1002
|
-
"SELF-REVIEW",
|
|
1003
|
-
"--base",
|
|
1004
|
-
"origin/dev",
|
|
1005
|
-
"--owned-path",
|
|
1006
|
-
"src",
|
|
1007
|
-
"--isolated",
|
|
1008
|
-
"--review-required",
|
|
1009
|
-
)
|
|
1010
|
-
worktree = self.task_worktree(repo, "SELF-REVIEW")
|
|
1011
|
-
payload = worktree / "src" / "payload.txt"
|
|
1012
|
-
payload.parent.mkdir(parents=True, exist_ok=True)
|
|
1013
|
-
payload.write_text("changed\n", encoding="utf-8")
|
|
1014
|
-
self.ap(
|
|
1015
|
-
repo,
|
|
1016
|
-
"task-handoff",
|
|
1017
|
-
"SELF-REVIEW",
|
|
1018
|
-
"--from",
|
|
1019
|
-
_TEST_OWNER,
|
|
1020
|
-
"--to",
|
|
1021
|
-
"self-reviewer",
|
|
1022
|
-
"--generation",
|
|
1023
|
-
"1",
|
|
1024
|
-
)
|
|
1025
|
-
status = json.loads(
|
|
1026
|
-
self.ap(worktree, "task-status", "SELF-REVIEW", "--json").stdout
|
|
1027
|
-
)["tasks"][0]
|
|
1028
|
-
rejected = self.ap(
|
|
1029
|
-
worktree,
|
|
1030
|
-
"task-review",
|
|
1031
|
-
"SELF-REVIEW",
|
|
1032
|
-
"--verdict",
|
|
1033
|
-
"approved",
|
|
1034
|
-
"--diff-fingerprint",
|
|
1035
|
-
status["current_diff_fingerprint"],
|
|
1036
|
-
"--reviewer",
|
|
1037
|
-
"self-reviewer",
|
|
1038
|
-
check=False,
|
|
1039
|
-
)
|
|
1040
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1041
|
-
self.assertIn("writer lease holder", rejected.stdout + rejected.stderr)
|
|
1042
|
-
|
|
1043
|
-
def test_review_assignment_is_deadline_bound_and_idempotent(self) -> None:
|
|
1044
|
-
_, repo, _ = self.make_repo()
|
|
1045
|
-
worktree = self.start_task(repo, "REVIEW-DEADLINE", "shared.txt")
|
|
1046
|
-
(worktree / "shared.txt").write_text("review me\n", encoding="utf-8")
|
|
1047
|
-
|
|
1048
|
-
first = json.loads(
|
|
1049
|
-
self.ap(
|
|
1050
|
-
worktree,
|
|
1051
|
-
"review-assignment",
|
|
1052
|
-
"REVIEW-DEADLINE",
|
|
1053
|
-
"--reviewer",
|
|
1054
|
-
"reviewer-1",
|
|
1055
|
-
"--json",
|
|
1056
|
-
).stdout
|
|
1057
|
-
)
|
|
1058
|
-
second = json.loads(
|
|
1059
|
-
self.ap(
|
|
1060
|
-
worktree,
|
|
1061
|
-
"review-assignment",
|
|
1062
|
-
"REVIEW-DEADLINE",
|
|
1063
|
-
"--reviewer",
|
|
1064
|
-
"reviewer-1",
|
|
1065
|
-
"--json",
|
|
1066
|
-
).stdout
|
|
1067
|
-
)
|
|
1068
|
-
self.assertEqual(first, second)
|
|
1069
|
-
assignment = first["assignment"]
|
|
1070
|
-
self.assertEqual("focused", assignment["review_depth"])
|
|
1071
|
-
self.assertEqual(150, assignment["timeout_seconds"])
|
|
1072
|
-
self.assertEqual(1, assignment["scope_revision"])
|
|
1073
|
-
self.assertTrue(Path(first["assignment_path"]).is_file())
|
|
1074
|
-
assignment_path = Path(first["assignment_path"])
|
|
1075
|
-
artifact_path = Path(assignment["diff_artifact_path"])
|
|
1076
|
-
artifact = artifact_path.read_bytes()
|
|
1077
|
-
self.assertEqual(assignment_path.parent, artifact_path.parent)
|
|
1078
|
-
self.assertEqual(0o600, assignment_path.stat().st_mode & 0o777)
|
|
1079
|
-
self.assertEqual(0o600, artifact_path.stat().st_mode & 0o777)
|
|
1080
|
-
self.assertEqual(hashlib.sha256(artifact).hexdigest(), assignment["diff_artifact_sha256"])
|
|
1081
|
-
self.assertEqual("git-binary-patch-v1", assignment["diff_artifact_format"])
|
|
1082
|
-
self.assertIn(b"review me", artifact)
|
|
1083
|
-
emitted = self.ap(
|
|
1084
|
-
worktree,
|
|
1085
|
-
"review-artifact",
|
|
1086
|
-
"--file",
|
|
1087
|
-
str(assignment_path),
|
|
1088
|
-
)
|
|
1089
|
-
self.assertEqual(artifact, emitted.stdout.encode("utf-8"))
|
|
1090
|
-
issued = datetime.fromisoformat(assignment["issued_at"])
|
|
1091
|
-
deadline = datetime.fromisoformat(assignment["deadline_at"])
|
|
1092
|
-
self.assertEqual(150, int((deadline - issued).total_seconds()))
|
|
1093
|
-
|
|
1094
|
-
artifact_path.write_bytes(artifact + b"tampered\n")
|
|
1095
|
-
tampered = self.ap(
|
|
1096
|
-
worktree,
|
|
1097
|
-
"review-assignment",
|
|
1098
|
-
"REVIEW-DEADLINE",
|
|
1099
|
-
"--reviewer",
|
|
1100
|
-
"reviewer-1",
|
|
1101
|
-
check=False,
|
|
1102
|
-
)
|
|
1103
|
-
self.assertNotEqual(0, tampered.returncode)
|
|
1104
|
-
self.assertIn("SHA-256 mismatch", tampered.stdout + tampered.stderr)
|
|
1105
|
-
|
|
1106
|
-
def test_review_assignment_hash_binding_rejects_assignment_file_tampering(self) -> None:
|
|
1107
|
-
_, repo, _ = self.make_repo()
|
|
1108
|
-
worktree = self.start_task(repo, "REVIEW-ASSIGNMENT-HASH", "shared.txt")
|
|
1109
|
-
(worktree / "shared.txt").write_text("hash-bound review\n", encoding="utf-8")
|
|
1110
|
-
issued = json.loads(
|
|
1111
|
-
self.ap(
|
|
1112
|
-
worktree,
|
|
1113
|
-
"review-assignment",
|
|
1114
|
-
"REVIEW-ASSIGNMENT-HASH",
|
|
1115
|
-
"--reviewer",
|
|
1116
|
-
"reviewer-hash",
|
|
1117
|
-
"--json",
|
|
1118
|
-
).stdout
|
|
1119
|
-
)
|
|
1120
|
-
assignment_path = Path(issued["assignment_path"])
|
|
1121
|
-
original = assignment_path.read_bytes()
|
|
1122
|
-
manifest = json.loads(
|
|
1123
|
-
self.registry_manifest_path(repo, "REVIEW-ASSIGNMENT-HASH").read_text(
|
|
1124
|
-
encoding="utf-8"
|
|
1125
|
-
)
|
|
1126
|
-
)
|
|
1127
|
-
self.assertEqual(
|
|
1128
|
-
hashlib.sha256(original).hexdigest(),
|
|
1129
|
-
manifest["review"]["assignment_sha256"],
|
|
1130
|
-
)
|
|
1131
|
-
|
|
1132
|
-
assignment_path.write_bytes(original + b" \n")
|
|
1133
|
-
rejected = self.ap(
|
|
1134
|
-
worktree,
|
|
1135
|
-
"review-assignment",
|
|
1136
|
-
"REVIEW-ASSIGNMENT-HASH",
|
|
1137
|
-
"--reviewer",
|
|
1138
|
-
"reviewer-hash",
|
|
1139
|
-
check=False,
|
|
1140
|
-
)
|
|
1141
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1142
|
-
self.assertIn("assignment SHA-256 mismatch", rejected.stdout + rejected.stderr)
|
|
1143
|
-
|
|
1144
|
-
def test_review_assignment_rejects_symlinked_review_root(self) -> None:
|
|
1145
|
-
root, repo, _ = self.make_repo()
|
|
1146
|
-
worktree = self.start_task(repo, "REVIEW-SYMLINK", "shared.txt")
|
|
1147
|
-
(worktree / "shared.txt").write_text("must stay git local\n", encoding="utf-8")
|
|
1148
|
-
review_root = self.registry_manifest_path(repo, "REVIEW-SYMLINK").parent.parent / "reviews"
|
|
1149
|
-
task_review_dir = review_root / "REVIEW-SYMLINK"
|
|
1150
|
-
if task_review_dir.exists():
|
|
1151
|
-
task_review_dir.rmdir()
|
|
1152
|
-
if review_root.exists():
|
|
1153
|
-
review_root.rmdir()
|
|
1154
|
-
outside = root / "outside-reviews"
|
|
1155
|
-
outside.mkdir()
|
|
1156
|
-
review_root.symlink_to(outside, target_is_directory=True)
|
|
1157
|
-
|
|
1158
|
-
rejected = self.ap(
|
|
1159
|
-
worktree,
|
|
1160
|
-
"review-assignment",
|
|
1161
|
-
"REVIEW-SYMLINK",
|
|
1162
|
-
"--reviewer",
|
|
1163
|
-
"reviewer-symlink",
|
|
1164
|
-
check=False,
|
|
1165
|
-
)
|
|
1166
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1167
|
-
self.assertIn("symlinked Git-local review storage", rejected.stdout + rejected.stderr)
|
|
1168
|
-
self.assertFalse((outside / "REVIEW-SYMLINK").exists())
|
|
1169
|
-
|
|
1170
|
-
def test_review_snapshot_covers_git_states_without_mutating_main_index_or_objects(self) -> None:
|
|
1171
|
-
_, repo, _ = self.make_repo()
|
|
1172
|
-
(repo / "delete-me.txt").write_text("delete me\n", encoding="utf-8")
|
|
1173
|
-
git(repo, "add", "delete-me.txt")
|
|
1174
|
-
git(repo, "commit", "-qm", "add deletion fixture")
|
|
1175
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
1176
|
-
worktree = self.start_task(repo, "REVIEW-GIT-STATES", ".")
|
|
1177
|
-
(worktree / "delete-me.txt").unlink()
|
|
1178
|
-
shared = worktree / "shared.txt"
|
|
1179
|
-
shared.write_text("executable review\n", encoding="utf-8")
|
|
1180
|
-
shared.chmod(shared.stat().st_mode | 0o111)
|
|
1181
|
-
(worktree / "binary-review.bin").write_bytes(b"\x00\x01binary-review\xff" * 32)
|
|
1182
|
-
(worktree / "review-link").symlink_to("shared.txt")
|
|
1183
|
-
index_path = Path(git_output(worktree, "rev-parse", "--git-path", "index"))
|
|
1184
|
-
if not index_path.is_absolute():
|
|
1185
|
-
index_path = (worktree / index_path).resolve()
|
|
1186
|
-
index_before = index_path.read_bytes()
|
|
1187
|
-
objects_before = git_output(worktree, "count-objects", "-v")
|
|
1188
|
-
|
|
1189
|
-
issued = json.loads(
|
|
1190
|
-
self.ap(
|
|
1191
|
-
worktree,
|
|
1192
|
-
"review-assignment",
|
|
1193
|
-
"REVIEW-GIT-STATES",
|
|
1194
|
-
"--reviewer",
|
|
1195
|
-
"reviewer-git-states",
|
|
1196
|
-
"--json",
|
|
1197
|
-
).stdout
|
|
1198
|
-
)
|
|
1199
|
-
patch = Path(issued["assignment"]["diff_artifact_path"]).read_bytes()
|
|
1200
|
-
self.assertIn(b"deleted file mode 100644", patch)
|
|
1201
|
-
self.assertIn(b"old mode 100644", patch)
|
|
1202
|
-
self.assertIn(b"new mode 100755", patch)
|
|
1203
|
-
self.assertIn(b"new file mode 120000", patch)
|
|
1204
|
-
self.assertIn(b"GIT binary patch", patch)
|
|
1205
|
-
self.assertEqual(index_before, index_path.read_bytes())
|
|
1206
|
-
self.assertEqual(objects_before, git_output(worktree, "count-objects", "-v"))
|
|
1207
|
-
self.assertFalse(list(Path(issued["assignment_path"]).parent.glob(".snapshot-*")))
|
|
1208
|
-
|
|
1209
|
-
def test_review_snapshot_stops_and_cleans_when_stream_limit_is_exceeded(self) -> None:
|
|
1210
|
-
_, repo, _ = self.make_repo()
|
|
1211
|
-
worktree = self.start_task(repo, "REVIEW-SIZE-LIMIT", "shared.txt")
|
|
1212
|
-
# The input itself stays below the test limit while the Git patch
|
|
1213
|
-
# headers plus body exceed it, exercising the streaming PIPE cutoff.
|
|
1214
|
-
(worktree / "shared.txt").write_text("small\n", encoding="utf-8")
|
|
1215
|
-
previous = os.environ.get("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES")
|
|
1216
|
-
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = "128"
|
|
1217
|
-
try:
|
|
1218
|
-
rejected = self.ap(
|
|
1219
|
-
worktree,
|
|
1220
|
-
"review-assignment",
|
|
1221
|
-
"REVIEW-SIZE-LIMIT",
|
|
1222
|
-
"--reviewer",
|
|
1223
|
-
"reviewer-size",
|
|
1224
|
-
check=False,
|
|
1225
|
-
)
|
|
1226
|
-
finally:
|
|
1227
|
-
if previous is None:
|
|
1228
|
-
os.environ.pop("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES", None)
|
|
1229
|
-
else:
|
|
1230
|
-
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = previous
|
|
1231
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1232
|
-
self.assertIn("safety limit", rejected.stdout + rejected.stderr)
|
|
1233
|
-
review_dir = (
|
|
1234
|
-
self.registry_manifest_path(repo, "REVIEW-SIZE-LIMIT").parent.parent
|
|
1235
|
-
/ "reviews"
|
|
1236
|
-
/ "REVIEW-SIZE-LIMIT"
|
|
1237
|
-
)
|
|
1238
|
-
self.assertFalse(list(review_dir.glob(".snapshot-*")))
|
|
1239
|
-
self.assertFalse(list(review_dir.glob("*.assignment.json")))
|
|
1240
|
-
self.assertFalse(list(review_dir.glob("*.patch")))
|
|
1241
|
-
|
|
1242
|
-
def test_review_snapshot_rejects_oversized_input_before_creating_temp_objects(self) -> None:
|
|
1243
|
-
_, repo, _ = self.make_repo()
|
|
1244
|
-
worktree = self.start_task(repo, "REVIEW-INPUT-LIMIT", "shared.txt")
|
|
1245
|
-
(worktree / "shared.txt").write_text("x" * 4096 + "\n", encoding="utf-8")
|
|
1246
|
-
objects_before = git_output(worktree, "count-objects", "-v")
|
|
1247
|
-
previous = os.environ.get("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES")
|
|
1248
|
-
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = "128"
|
|
1249
|
-
try:
|
|
1250
|
-
rejected = self.ap(
|
|
1251
|
-
worktree,
|
|
1252
|
-
"review-assignment",
|
|
1253
|
-
"REVIEW-INPUT-LIMIT",
|
|
1254
|
-
"--reviewer",
|
|
1255
|
-
"reviewer-input-size",
|
|
1256
|
-
check=False,
|
|
1257
|
-
)
|
|
1258
|
-
finally:
|
|
1259
|
-
if previous is None:
|
|
1260
|
-
os.environ.pop("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES", None)
|
|
1261
|
-
else:
|
|
1262
|
-
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = previous
|
|
1263
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1264
|
-
self.assertIn("snapshot input exceeds", rejected.stdout + rejected.stderr)
|
|
1265
|
-
review_dir = (
|
|
1266
|
-
self.registry_manifest_path(repo, "REVIEW-INPUT-LIMIT").parent.parent
|
|
1267
|
-
/ "reviews"
|
|
1268
|
-
/ "REVIEW-INPUT-LIMIT"
|
|
1269
|
-
)
|
|
1270
|
-
self.assertFalse(review_dir.exists())
|
|
1271
|
-
self.assertEqual(objects_before, git_output(worktree, "count-objects", "-v"))
|
|
1272
|
-
|
|
1273
|
-
def test_review_run_supervises_separate_process_and_records_result_once(self) -> None:
|
|
1274
|
-
root, repo, _ = self.make_repo()
|
|
1275
|
-
worktree = self.start_task(repo, "REVIEW-RUN", ".")
|
|
1276
|
-
(worktree / "shared.txt").write_text("staged tracked review token\n", encoding="utf-8")
|
|
1277
|
-
git(worktree, "add", "shared.txt")
|
|
1278
|
-
(worktree / "untracked-review.txt").write_text(
|
|
1279
|
-
"untracked review token\n",
|
|
1280
|
-
encoding="utf-8",
|
|
1281
|
-
)
|
|
1282
|
-
runner = self.artifact_reviewer_runner(
|
|
1283
|
-
root,
|
|
1284
|
-
"staged tracked review token",
|
|
1285
|
-
"untracked review token",
|
|
1286
|
-
)
|
|
1287
|
-
completed = self.ap(
|
|
1288
|
-
worktree,
|
|
1289
|
-
"review-run",
|
|
1290
|
-
"REVIEW-RUN",
|
|
1291
|
-
"--reviewer",
|
|
1292
|
-
"reviewer-runtime",
|
|
1293
|
-
"--runner-command-json",
|
|
1294
|
-
runner,
|
|
1295
|
-
"--json",
|
|
1296
|
-
)
|
|
1297
|
-
result = json.loads(completed.stdout)
|
|
1298
|
-
self.assertEqual("approved", result["verdict"])
|
|
1299
|
-
self.assertEqual("artifact reviewed", result["summary"])
|
|
1300
|
-
|
|
1301
|
-
status = json.loads(
|
|
1302
|
-
self.ap(worktree, "task-status", "REVIEW-RUN", "--json").stdout
|
|
1303
|
-
)["tasks"][0]
|
|
1304
|
-
review = status["review"]
|
|
1305
|
-
self.assertEqual("approved", review["verdict"])
|
|
1306
|
-
self.assertEqual("completed", review["runtime_state"])
|
|
1307
|
-
self.assertEqual("reviewer-runtime", review["reviewer"])
|
|
1308
|
-
self.assertEqual(0, review["runtime_exit_code"])
|
|
1309
|
-
result_path = Path(review["runtime_result_path"])
|
|
1310
|
-
receipt_path = Path(review["runtime_receipt_path"])
|
|
1311
|
-
self.assertEqual(0o600, result_path.stat().st_mode & 0o777)
|
|
1312
|
-
self.assertEqual(0o600, receipt_path.stat().st_mode & 0o777)
|
|
1313
|
-
receipt = json.loads(receipt_path.read_text())
|
|
1314
|
-
self.assertEqual("completed", receipt["status"])
|
|
1315
|
-
self.assertRegex(receipt["result_sha256"], r"^[0-9a-f]{64}$")
|
|
1316
|
-
|
|
1317
|
-
repeated = self.ap(
|
|
1318
|
-
worktree,
|
|
1319
|
-
"review-run",
|
|
1320
|
-
"REVIEW-RUN",
|
|
1321
|
-
"--reviewer",
|
|
1322
|
-
"reviewer-runtime",
|
|
1323
|
-
"--runner-command-json",
|
|
1324
|
-
runner,
|
|
1325
|
-
check=False,
|
|
1326
|
-
)
|
|
1327
|
-
self.assertNotEqual(0, repeated.returncode)
|
|
1328
|
-
self.assertIn("already complete", repeated.stdout + repeated.stderr)
|
|
1329
|
-
|
|
1330
|
-
tampered_payload = json.loads(result_path.read_text())
|
|
1331
|
-
tampered_payload["summary"] = "tampered after review"
|
|
1332
|
-
result_path.write_text(json.dumps(tampered_payload) + "\n", encoding="utf-8")
|
|
1333
|
-
tampered = self.ap(
|
|
1334
|
-
worktree,
|
|
1335
|
-
"task-review",
|
|
1336
|
-
"REVIEW-RUN",
|
|
1337
|
-
"--verdict",
|
|
1338
|
-
"approved",
|
|
1339
|
-
"--diff-fingerprint",
|
|
1340
|
-
status["current_diff_fingerprint"],
|
|
1341
|
-
"--reviewer",
|
|
1342
|
-
"reviewer-runtime",
|
|
1343
|
-
check=False,
|
|
1344
|
-
)
|
|
1345
|
-
self.assertNotEqual(0, tampered.returncode)
|
|
1346
|
-
self.assertIn("result changed", tampered.stdout + tampered.stderr)
|
|
1347
|
-
|
|
1348
|
-
def test_review_run_retries_clean_exit_without_event_and_rejects_approved_file(self) -> None:
|
|
1349
|
-
root, repo, _ = self.make_repo()
|
|
1350
|
-
worktree = self.start_task(repo, "REVIEW-NO-EVENT", "shared.txt")
|
|
1351
|
-
(worktree / "shared.txt").write_text("review without event\n", encoding="utf-8")
|
|
1352
|
-
counter = root / "attempt-count.txt"
|
|
1353
|
-
runner_path = root / "no-event-reviewer.py"
|
|
1354
|
-
runner_path.write_text(
|
|
1355
|
-
"import json, os\n"
|
|
1356
|
-
"from pathlib import Path\n"
|
|
1357
|
-
f"counter = Path({str(counter)!r})\n"
|
|
1358
|
-
"counter.write_text(str(int(counter.read_text() or '0') + 1) if counter.exists() else '1')\n"
|
|
1359
|
-
"Path(os.environ['AUTOCODING_REVIEW_RESULT']).write_text(json.dumps({'verdict': 'approved'}) + '\\n')\n",
|
|
1360
|
-
encoding="utf-8",
|
|
1361
|
-
)
|
|
1362
|
-
rejected = self.ap(
|
|
1363
|
-
worktree,
|
|
1364
|
-
"review-run",
|
|
1365
|
-
"REVIEW-NO-EVENT",
|
|
1366
|
-
"--reviewer",
|
|
1367
|
-
"reviewer-no-event",
|
|
1368
|
-
"--runner-command-json",
|
|
1369
|
-
json.dumps([sys.executable, str(runner_path)]),
|
|
1370
|
-
check=False,
|
|
1371
|
-
)
|
|
1372
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1373
|
-
self.assertIn("runtime-unavailable", rejected.stdout + rejected.stderr)
|
|
1374
|
-
self.assertEqual("2", counter.read_text())
|
|
1375
|
-
status = json.loads(
|
|
1376
|
-
self.ap(worktree, "task-status", "REVIEW-NO-EVENT", "--json").stdout
|
|
1377
|
-
)["tasks"][0]
|
|
1378
|
-
self.assertEqual("runtime-unavailable", status["review"]["runtime_state"])
|
|
1379
|
-
self.assertEqual("blocked", status["review"]["verdict"])
|
|
1380
|
-
|
|
1381
|
-
def test_substantive_result_written_before_timeout_cannot_be_bypassed(self) -> None:
|
|
1382
|
-
root, repo, _ = self.make_repo()
|
|
1383
|
-
worktree = self.start_task(repo, "REVIEW-SUBSTANTIVE", "shared.txt")
|
|
1384
|
-
(worktree / "shared.txt").write_text("substantive finding\n", encoding="utf-8")
|
|
1385
|
-
issued = json.loads(
|
|
1386
|
-
self.ap(
|
|
1387
|
-
worktree,
|
|
1388
|
-
"review-assignment",
|
|
1389
|
-
"REVIEW-SUBSTANTIVE",
|
|
1390
|
-
"--reviewer",
|
|
1391
|
-
"reviewer-substantive",
|
|
1392
|
-
"--json",
|
|
1393
|
-
).stdout
|
|
1394
|
-
)
|
|
1395
|
-
self.shorten_review_deadline(repo, "REVIEW-SUBSTANTIVE", issued)
|
|
1396
|
-
runner_path = root / "substantive-reviewer.py"
|
|
1397
|
-
runner_path.write_text(
|
|
1398
|
-
"import json, os, time\n"
|
|
1399
|
-
"from pathlib import Path\n"
|
|
1400
|
-
"result = Path(os.environ['AUTOCODING_REVIEW_RESULT'])\n"
|
|
1401
|
-
"result.write_text(json.dumps({'verdict': 'changes-requested', 'summary': 'real defect'}) + '\\n')\n"
|
|
1402
|
-
"result.chmod(0o600)\n"
|
|
1403
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
1404
|
-
"time.sleep(30)\n",
|
|
1405
|
-
encoding="utf-8",
|
|
1406
|
-
)
|
|
1407
|
-
timed_out = self.ap(
|
|
1408
|
-
worktree,
|
|
1409
|
-
"review-run",
|
|
1410
|
-
"REVIEW-SUBSTANTIVE",
|
|
1411
|
-
"--reviewer",
|
|
1412
|
-
"reviewer-substantive",
|
|
1413
|
-
"--runner-command-json",
|
|
1414
|
-
json.dumps([sys.executable, str(runner_path)]),
|
|
1415
|
-
check=False,
|
|
1416
|
-
)
|
|
1417
|
-
self.assertNotEqual(0, timed_out.returncode)
|
|
1418
|
-
self.assertIn("cannot be bypassed", timed_out.stdout + timed_out.stderr)
|
|
1419
|
-
status = json.loads(
|
|
1420
|
-
self.ap(worktree, "task-status", "REVIEW-SUBSTANTIVE", "--json").stdout
|
|
1421
|
-
)["tasks"][0]
|
|
1422
|
-
review = status["review"]
|
|
1423
|
-
self.assertEqual("changes-requested", review["verdict"])
|
|
1424
|
-
self.assertEqual("blocked", review["runtime_state"])
|
|
1425
|
-
receipt = json.loads(Path(review["runtime_receipt_path"]).read_text())
|
|
1426
|
-
self.assertEqual("blocked", receipt["status"])
|
|
1427
|
-
self.assertEqual("changes-requested", receipt["verdict"])
|
|
1428
|
-
self.assertEqual(1, len(receipt["attempts"]))
|
|
1429
|
-
bypass = self.ap(
|
|
1430
|
-
worktree,
|
|
1431
|
-
"review-runtime-override",
|
|
1432
|
-
"REVIEW-SUBSTANTIVE",
|
|
1433
|
-
"--diff-fingerprint",
|
|
1434
|
-
status["current_diff_fingerprint"],
|
|
1435
|
-
"--authorized-by",
|
|
1436
|
-
"product-owner",
|
|
1437
|
-
"--authorization-ref",
|
|
1438
|
-
"conversation-substantive",
|
|
1439
|
-
"--reason",
|
|
1440
|
-
"A substantive Reviewer result must remain blocking.",
|
|
1441
|
-
"--evidence",
|
|
1442
|
-
"reviewer returned changes requested",
|
|
1443
|
-
"--confirm-runtime-bypass",
|
|
1444
|
-
check=False,
|
|
1445
|
-
)
|
|
1446
|
-
self.assertNotEqual(0, bypass.returncode)
|
|
1447
|
-
self.assertIn("allowed only after", bypass.stdout + bypass.stderr)
|
|
1448
|
-
|
|
1449
|
-
def test_substantive_result_survives_nonzero_reviewer_exit(self) -> None:
|
|
1450
|
-
root, repo, _ = self.make_repo()
|
|
1451
|
-
worktree = self.start_task(repo, "REVIEW-NONZERO", "shared.txt")
|
|
1452
|
-
(worktree / "shared.txt").write_text("nonzero substantive finding\n", encoding="utf-8")
|
|
1453
|
-
runner_path = root / "nonzero-substantive-reviewer.py"
|
|
1454
|
-
runner_path.write_text(
|
|
1455
|
-
"import json, os\n"
|
|
1456
|
-
"from pathlib import Path\n"
|
|
1457
|
-
"result = Path(os.environ['AUTOCODING_REVIEW_RESULT'])\n"
|
|
1458
|
-
"result.write_text(json.dumps({'verdict': 'changes-requested', 'summary': 'specific defect'}) + '\\n')\n"
|
|
1459
|
-
"result.chmod(0o600)\n"
|
|
1460
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
1461
|
-
"raise SystemExit(7)\n",
|
|
1462
|
-
encoding="utf-8",
|
|
1463
|
-
)
|
|
1464
|
-
rejected = self.ap(
|
|
1465
|
-
worktree,
|
|
1466
|
-
"review-run",
|
|
1467
|
-
"REVIEW-NONZERO",
|
|
1468
|
-
"--reviewer",
|
|
1469
|
-
"reviewer-nonzero",
|
|
1470
|
-
"--runner-command-json",
|
|
1471
|
-
json.dumps([sys.executable, str(runner_path)]),
|
|
1472
|
-
check=False,
|
|
1473
|
-
)
|
|
1474
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1475
|
-
self.assertIn("cannot be bypassed", rejected.stdout + rejected.stderr)
|
|
1476
|
-
status = json.loads(
|
|
1477
|
-
self.ap(worktree, "task-status", "REVIEW-NONZERO", "--json").stdout
|
|
1478
|
-
)["tasks"][0]
|
|
1479
|
-
review = status["review"]
|
|
1480
|
-
self.assertEqual("changes-requested", review["verdict"])
|
|
1481
|
-
self.assertEqual("blocked", review["runtime_state"])
|
|
1482
|
-
self.assertEqual(7, review["runtime_exit_code"])
|
|
1483
|
-
result = json.loads(Path(review["runtime_result_path"]).read_text())
|
|
1484
|
-
self.assertEqual("specific defect", result["summary"])
|
|
1485
|
-
receipt = json.loads(Path(review["runtime_receipt_path"]).read_text())
|
|
1486
|
-
self.assertEqual("blocked", receipt["status"])
|
|
1487
|
-
self.assertEqual("changes-requested", receipt["verdict"])
|
|
1488
|
-
self.assertEqual(7, receipt["exit_code"])
|
|
1489
|
-
|
|
1490
|
-
def test_substantive_agent_message_before_timeout_cannot_be_bypassed(self) -> None:
|
|
1491
|
-
root, repo, _ = self.make_repo()
|
|
1492
|
-
worktree = self.start_task(repo, "REVIEW-EVENT-FINDING", "shared.txt")
|
|
1493
|
-
(worktree / "shared.txt").write_text("event finding\n", encoding="utf-8")
|
|
1494
|
-
issued = json.loads(
|
|
1495
|
-
self.ap(
|
|
1496
|
-
worktree,
|
|
1497
|
-
"review-assignment",
|
|
1498
|
-
"REVIEW-EVENT-FINDING",
|
|
1499
|
-
"--reviewer",
|
|
1500
|
-
"reviewer-event-finding",
|
|
1501
|
-
"--json",
|
|
1502
|
-
).stdout
|
|
1503
|
-
)
|
|
1504
|
-
self.shorten_review_deadline(repo, "REVIEW-EVENT-FINDING", issued)
|
|
1505
|
-
runner_path = root / "event-finding-reviewer.py"
|
|
1506
|
-
runner_path.write_text(
|
|
1507
|
-
"import json, sys, time\n"
|
|
1508
|
-
"result = json.dumps({'verdict': 'blocked', 'summary': 'event-only defect'})\n"
|
|
1509
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
1510
|
-
"sys.stdout.write(json.dumps({'type': 'item.completed', 'item': {'type': 'agent_message', 'text': result}}))\n"
|
|
1511
|
-
"sys.stdout.flush()\n"
|
|
1512
|
-
"time.sleep(30)\n",
|
|
1513
|
-
encoding="utf-8",
|
|
1514
|
-
)
|
|
1515
|
-
timed_out = self.ap(
|
|
1516
|
-
worktree,
|
|
1517
|
-
"review-run",
|
|
1518
|
-
"REVIEW-EVENT-FINDING",
|
|
1519
|
-
"--reviewer",
|
|
1520
|
-
"reviewer-event-finding",
|
|
1521
|
-
"--runner-command-json",
|
|
1522
|
-
json.dumps([sys.executable, str(runner_path)]),
|
|
1523
|
-
check=False,
|
|
1524
|
-
)
|
|
1525
|
-
self.assertNotEqual(0, timed_out.returncode)
|
|
1526
|
-
self.assertIn("cannot be bypassed", timed_out.stdout + timed_out.stderr)
|
|
1527
|
-
status = json.loads(
|
|
1528
|
-
self.ap(worktree, "task-status", "REVIEW-EVENT-FINDING", "--json").stdout
|
|
1529
|
-
)["tasks"][0]
|
|
1530
|
-
self.assertEqual("blocked", status["review"]["verdict"])
|
|
1531
|
-
self.assertEqual("blocked", status["review"]["runtime_state"])
|
|
1532
|
-
result = json.loads(Path(status["review"]["runtime_result_path"]).read_text())
|
|
1533
|
-
self.assertEqual("event-only defect", result["summary"])
|
|
1534
|
-
|
|
1535
|
-
def test_blocked_runtime_cannot_be_reassigned_or_overwritten_as_approved(self) -> None:
|
|
1536
|
-
root, repo, _ = self.make_repo()
|
|
1537
|
-
worktree = self.start_task(repo, "REVIEW-BLOCKED", "shared.txt")
|
|
1538
|
-
(worktree / "shared.txt").write_text("review is blocked\n", encoding="utf-8")
|
|
1539
|
-
blocked_reviewer = root / "blocked-reviewer.py"
|
|
1540
|
-
blocked_reviewer.write_text(
|
|
1541
|
-
"import json\n"
|
|
1542
|
-
"print(json.dumps({'verdict': 'blocked', 'summary': 'missing evidence'}))\n",
|
|
1543
|
-
encoding="utf-8",
|
|
1544
|
-
)
|
|
1545
|
-
runner = json.dumps([sys.executable, str(blocked_reviewer)])
|
|
1546
|
-
blocked = self.ap(
|
|
1547
|
-
worktree,
|
|
1548
|
-
"review-run",
|
|
1549
|
-
"REVIEW-BLOCKED",
|
|
1550
|
-
"--reviewer",
|
|
1551
|
-
"reviewer-blocked",
|
|
1552
|
-
"--runner-command-json",
|
|
1553
|
-
runner,
|
|
1554
|
-
check=False,
|
|
1555
|
-
)
|
|
1556
|
-
self.assertNotEqual(0, blocked.returncode)
|
|
1557
|
-
self.assertIn("Reviewer returned blocked", blocked.stdout + blocked.stderr)
|
|
1558
|
-
status = json.loads(
|
|
1559
|
-
self.ap(worktree, "task-status", "REVIEW-BLOCKED", "--json").stdout
|
|
1560
|
-
)["tasks"][0]
|
|
1561
|
-
self.assertEqual("blocked", status["review"]["verdict"])
|
|
1562
|
-
self.assertEqual("blocked", status["review"]["runtime_state"])
|
|
1563
|
-
|
|
1564
|
-
reassigned = self.ap(
|
|
1565
|
-
worktree,
|
|
1566
|
-
"review-assignment",
|
|
1567
|
-
"REVIEW-BLOCKED",
|
|
1568
|
-
"--reviewer",
|
|
1569
|
-
"reviewer-blocked",
|
|
1570
|
-
check=False,
|
|
1571
|
-
)
|
|
1572
|
-
self.assertNotEqual(0, reassigned.returncode)
|
|
1573
|
-
self.assertIn("already complete or consumed", reassigned.stdout + reassigned.stderr)
|
|
1574
|
-
overwritten = self.ap(
|
|
1575
|
-
worktree,
|
|
1576
|
-
"task-review",
|
|
1577
|
-
"REVIEW-BLOCKED",
|
|
1578
|
-
"--verdict",
|
|
1579
|
-
"approved",
|
|
1580
|
-
"--diff-fingerprint",
|
|
1581
|
-
status["current_diff_fingerprint"],
|
|
1582
|
-
"--reviewer",
|
|
1583
|
-
"reviewer-blocked",
|
|
1584
|
-
check=False,
|
|
1585
|
-
)
|
|
1586
|
-
self.assertNotEqual(0, overwritten.returncode)
|
|
1587
|
-
self.assertIn("runtime state=blocked", overwritten.stdout + overwritten.stderr)
|
|
1588
|
-
bypass = self.ap(
|
|
1589
|
-
worktree,
|
|
1590
|
-
"review-runtime-override",
|
|
1591
|
-
"REVIEW-BLOCKED",
|
|
1592
|
-
"--diff-fingerprint",
|
|
1593
|
-
status["current_diff_fingerprint"],
|
|
1594
|
-
"--authorized-by",
|
|
1595
|
-
"product-owner",
|
|
1596
|
-
"--authorization-ref",
|
|
1597
|
-
"conversation-blocked",
|
|
1598
|
-
"--reason",
|
|
1599
|
-
"User cannot override a substantive Reviewer blocked verdict.",
|
|
1600
|
-
"--evidence",
|
|
1601
|
-
"reviewer returned blocked",
|
|
1602
|
-
"--confirm-runtime-bypass",
|
|
1603
|
-
check=False,
|
|
1604
|
-
)
|
|
1605
|
-
self.assertNotEqual(0, bypass.returncode)
|
|
1606
|
-
self.assertIn("allowed only after", bypass.stdout + bypass.stderr)
|
|
1607
|
-
|
|
1608
|
-
def test_known_432_artifact_access_block_gets_one_immutable_managed_retry(self) -> None:
|
|
1609
|
-
root, repo, _ = self.make_repo()
|
|
1610
|
-
managed_script = self.managed_runtime(root)
|
|
1611
|
-
worktree = self.start_task(repo, "REVIEW-MANAGED-RETRY", "shared.txt")
|
|
1612
|
-
(worktree / "shared.txt").write_text("managed retry payload\n", encoding="utf-8")
|
|
1613
|
-
common_dir = Path(git_output(repo, "rev-parse", "--git-common-dir"))
|
|
1614
|
-
if not common_dir.is_absolute():
|
|
1615
|
-
common_dir = (repo / common_dir).resolve()
|
|
1616
|
-
state_root = common_dir / "auto-coding-skill"
|
|
1617
|
-
blocked_reviewer = root / "known-artifact-access-block.py"
|
|
1618
|
-
blocked_reviewer.write_text(
|
|
1619
|
-
"import json\n"
|
|
1620
|
-
f"state_root = {str(state_root)!r}\n"
|
|
1621
|
-
"print(json.dumps({"
|
|
1622
|
-
"'verdict': 'blocked', "
|
|
1623
|
-
"'summary': 'Review could not begin because review-artifact failed before emitting the immutable patch.', "
|
|
1624
|
-
"'evidence': ['review-artifact exited 2: Cannot protect Git-local review storage at ' + state_root + ': Operation not permitted.'], "
|
|
1625
|
-
"'risks': ['The immutable patch was not emitted or substantively reviewed.']}))\n",
|
|
1626
|
-
encoding="utf-8",
|
|
1627
|
-
)
|
|
1628
|
-
blocked = self.ap(
|
|
1629
|
-
worktree,
|
|
1630
|
-
"review-run",
|
|
1631
|
-
"REVIEW-MANAGED-RETRY",
|
|
1632
|
-
"--reviewer",
|
|
1633
|
-
"managed-retry-reviewer",
|
|
1634
|
-
"--runner-command-json",
|
|
1635
|
-
json.dumps([sys.executable, str(blocked_reviewer)]),
|
|
1636
|
-
check=False,
|
|
1637
|
-
)
|
|
1638
|
-
self.assertNotEqual(0, blocked.returncode)
|
|
1639
|
-
manifest_path = self.registry_manifest_path(repo, "REVIEW-MANAGED-RETRY")
|
|
1640
|
-
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
1641
|
-
manifest["skill_version"] = "4.3.2"
|
|
1642
|
-
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
1643
|
-
prior_review = manifest["review"]
|
|
1644
|
-
prior_paths = [
|
|
1645
|
-
Path(prior_review["assignment_path"]),
|
|
1646
|
-
Path(prior_review["diff_artifact_path"]),
|
|
1647
|
-
Path(prior_review["runtime_result_path"]),
|
|
1648
|
-
Path(prior_review["runtime_receipt_path"]),
|
|
1649
|
-
Path(prior_review["runtime_event_log_path"]),
|
|
1650
|
-
]
|
|
1651
|
-
prior_bytes = {path: path.read_bytes() for path in prior_paths}
|
|
1652
|
-
fingerprint = prior_review["diff_fingerprint"]
|
|
1653
|
-
|
|
1654
|
-
authorized = json.loads(
|
|
1655
|
-
self.ap_script(
|
|
1656
|
-
worktree,
|
|
1657
|
-
managed_script,
|
|
1658
|
-
"review-runtime-retry",
|
|
1659
|
-
"REVIEW-MANAGED-RETRY",
|
|
1660
|
-
"--diff-fingerprint",
|
|
1661
|
-
fingerprint,
|
|
1662
|
-
"--reason-code",
|
|
1663
|
-
"managed-review-artifact-access",
|
|
1664
|
-
"--confirm-managed-runtime-retry",
|
|
1665
|
-
"--json",
|
|
1666
|
-
).stdout
|
|
1667
|
-
)
|
|
1668
|
-
self.assertEqual("retry-authorized", authorized["status"])
|
|
1669
|
-
self.assertEqual("retry-v4.3.6", authorized["retry_token"])
|
|
1670
|
-
audit_path = Path(authorized["audit_path"])
|
|
1671
|
-
self.assertEqual(0o600, audit_path.stat().st_mode & 0o777)
|
|
1672
|
-
audit = json.loads(audit_path.read_text(encoding="utf-8"))
|
|
1673
|
-
self.assertEqual("4.3.2", audit["task_skill_version"])
|
|
1674
|
-
self.assertEqual(hashlib.sha256(prior_bytes[prior_paths[2]]).hexdigest(), audit["prior_result_sha256"])
|
|
1675
|
-
|
|
1676
|
-
runner = self.artifact_reviewer_runner(
|
|
1677
|
-
root,
|
|
1678
|
-
"managed retry payload",
|
|
1679
|
-
runtime_script=managed_script,
|
|
1680
|
-
)
|
|
1681
|
-
reviewed = json.loads(
|
|
1682
|
-
self.ap_script(
|
|
1683
|
-
worktree,
|
|
1684
|
-
managed_script,
|
|
1685
|
-
"review-run",
|
|
1686
|
-
"REVIEW-MANAGED-RETRY",
|
|
1687
|
-
"--reviewer",
|
|
1688
|
-
"managed-retry-reviewer",
|
|
1689
|
-
"--runner-command-json",
|
|
1690
|
-
runner,
|
|
1691
|
-
"--json",
|
|
1692
|
-
).stdout
|
|
1693
|
-
)
|
|
1694
|
-
self.assertEqual("approved", reviewed["verdict"])
|
|
1695
|
-
for path, original in prior_bytes.items():
|
|
1696
|
-
self.assertEqual(original, path.read_bytes(), str(path))
|
|
1697
|
-
status = json.loads(
|
|
1698
|
-
self.ap_script(
|
|
1699
|
-
worktree,
|
|
1700
|
-
managed_script,
|
|
1701
|
-
"task-status",
|
|
1702
|
-
"REVIEW-MANAGED-RETRY",
|
|
1703
|
-
"--json",
|
|
1704
|
-
).stdout
|
|
1705
|
-
)["tasks"][0]
|
|
1706
|
-
retry_review = status["review"]
|
|
1707
|
-
self.assertEqual("approved", retry_review["verdict"])
|
|
1708
|
-
self.assertIn(".retry-v4.3.6.result.json", retry_review["runtime_result_path"])
|
|
1709
|
-
retry_receipt = json.loads(Path(retry_review["runtime_receipt_path"]).read_text())
|
|
1710
|
-
self.assertEqual("retry-v4.3.6", retry_receipt["runtime_retry_token"])
|
|
1711
|
-
self.assertEqual(authorized["audit_sha256"], retry_receipt["runtime_retry_audit_sha256"])
|
|
1712
|
-
|
|
1713
|
-
repeated = self.ap_script(
|
|
1714
|
-
worktree,
|
|
1715
|
-
managed_script,
|
|
1716
|
-
"review-runtime-retry",
|
|
1717
|
-
"REVIEW-MANAGED-RETRY",
|
|
1718
|
-
"--diff-fingerprint",
|
|
1719
|
-
fingerprint,
|
|
1720
|
-
"--reason-code",
|
|
1721
|
-
"managed-review-artifact-access",
|
|
1722
|
-
"--confirm-managed-runtime-retry",
|
|
1723
|
-
check=False,
|
|
1724
|
-
)
|
|
1725
|
-
self.assertNotEqual(0, repeated.returncode)
|
|
1726
|
-
|
|
1727
|
-
def test_434_retry_artifact_access_block_gets_one_fixed_runtime_repair(self) -> None:
|
|
1728
|
-
root, repo, _ = self.make_repo()
|
|
1729
|
-
managed_434 = self.managed_runtime(root / "runtime-434", "4.3.4")
|
|
1730
|
-
managed_fixed = self.managed_runtime(root / "runtime-fixed", "4.3.6")
|
|
1731
|
-
worktree = self.start_task(repo, "REVIEW-RETRY-REPAIR", "shared.txt")
|
|
1732
|
-
(worktree / "shared.txt").write_text("repair retry payload\n", encoding="utf-8")
|
|
1733
|
-
common_dir = Path(git_output(repo, "rev-parse", "--git-common-dir"))
|
|
1734
|
-
if not common_dir.is_absolute():
|
|
1735
|
-
common_dir = (repo / common_dir).resolve()
|
|
1736
|
-
state_root = common_dir / "auto-coding-skill"
|
|
1737
|
-
blocked_reviewer = root / "repair-artifact-access-block.py"
|
|
1738
|
-
blocked_reviewer.write_text(
|
|
1739
|
-
"import json\n"
|
|
1740
|
-
f"state_root = {str(state_root)!r}\n"
|
|
1741
|
-
"print(json.dumps({"
|
|
1742
|
-
"'verdict': 'blocked', "
|
|
1743
|
-
"'summary': 'Review could not begin because review-artifact failed to verify and emit the immutable patch.', "
|
|
1744
|
-
"'evidence': ['review-artifact exited with: Cannot protect Git-local review storage: ' + state_root + ': [Errno 1] Operation not permitted'], "
|
|
1745
|
-
"'risks': ['The SHA-256-bound frozen diff was not emitted or reviewed, so no substantive correctness or security conclusion is available.']}))\n",
|
|
1746
|
-
encoding="utf-8",
|
|
1747
|
-
)
|
|
1748
|
-
blocked_runner = json.dumps([sys.executable, str(blocked_reviewer)])
|
|
1749
|
-
self.ap(
|
|
1750
|
-
worktree,
|
|
1751
|
-
"review-run",
|
|
1752
|
-
"REVIEW-RETRY-REPAIR",
|
|
1753
|
-
"--reviewer",
|
|
1754
|
-
"repair-reviewer",
|
|
1755
|
-
"--runner-command-json",
|
|
1756
|
-
blocked_runner,
|
|
1757
|
-
check=False,
|
|
1758
|
-
)
|
|
1759
|
-
manifest_path = self.registry_manifest_path(repo, "REVIEW-RETRY-REPAIR")
|
|
1760
|
-
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
1761
|
-
manifest["skill_version"] = "4.3.2"
|
|
1762
|
-
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
1763
|
-
fingerprint = manifest["review"]["diff_fingerprint"]
|
|
1764
|
-
first_retry = json.loads(
|
|
1765
|
-
self.ap_script(
|
|
1766
|
-
worktree,
|
|
1767
|
-
managed_434,
|
|
1768
|
-
"review-runtime-retry",
|
|
1769
|
-
"REVIEW-RETRY-REPAIR",
|
|
1770
|
-
"--diff-fingerprint",
|
|
1771
|
-
fingerprint,
|
|
1772
|
-
"--reason-code",
|
|
1773
|
-
"managed-review-artifact-access",
|
|
1774
|
-
"--confirm-managed-runtime-retry",
|
|
1775
|
-
"--json",
|
|
1776
|
-
).stdout
|
|
1777
|
-
)
|
|
1778
|
-
self.assertEqual("retry-v4.3.4", first_retry["retry_token"])
|
|
1779
|
-
self.ap_script(
|
|
1780
|
-
worktree,
|
|
1781
|
-
managed_434,
|
|
1782
|
-
"review-run",
|
|
1783
|
-
"REVIEW-RETRY-REPAIR",
|
|
1784
|
-
"--reviewer",
|
|
1785
|
-
"repair-reviewer",
|
|
1786
|
-
"--runner-command-json",
|
|
1787
|
-
blocked_runner,
|
|
1788
|
-
check=False,
|
|
1789
|
-
)
|
|
1790
|
-
blocked_status = json.loads(
|
|
1791
|
-
self.ap_script(
|
|
1792
|
-
worktree,
|
|
1793
|
-
managed_434,
|
|
1794
|
-
"task-status",
|
|
1795
|
-
"REVIEW-RETRY-REPAIR",
|
|
1796
|
-
"--json",
|
|
1797
|
-
).stdout
|
|
1798
|
-
)["tasks"][0]
|
|
1799
|
-
old_review = blocked_status["review"]
|
|
1800
|
-
old_evidence_paths = [
|
|
1801
|
-
Path(old_review["runtime_retry_audit_path"]),
|
|
1802
|
-
Path(old_review["runtime_result_path"]),
|
|
1803
|
-
Path(old_review["runtime_receipt_path"]),
|
|
1804
|
-
Path(old_review["runtime_event_log_path"]),
|
|
1805
|
-
]
|
|
1806
|
-
old_evidence = {path: path.read_bytes() for path in old_evidence_paths}
|
|
1807
|
-
|
|
1808
|
-
repaired = json.loads(
|
|
1809
|
-
self.ap_script(
|
|
1810
|
-
worktree,
|
|
1811
|
-
managed_fixed,
|
|
1812
|
-
"review-runtime-retry",
|
|
1813
|
-
"REVIEW-RETRY-REPAIR",
|
|
1814
|
-
"--diff-fingerprint",
|
|
1815
|
-
fingerprint,
|
|
1816
|
-
"--reason-code",
|
|
1817
|
-
"managed-review-artifact-access",
|
|
1818
|
-
"--confirm-managed-runtime-retry",
|
|
1819
|
-
"--json",
|
|
1820
|
-
).stdout
|
|
1821
|
-
)
|
|
1822
|
-
self.assertEqual("retry-v4.3.6", repaired["retry_token"])
|
|
1823
|
-
repair_audit = json.loads(Path(repaired["audit_path"]).read_text(encoding="utf-8"))
|
|
1824
|
-
self.assertEqual("retry-v4.3.4", repair_audit["superseded_retry_token"])
|
|
1825
|
-
self.assertEqual("blocked", repair_audit["superseded_retry_state"])
|
|
1826
|
-
reviewed = json.loads(
|
|
1827
|
-
self.ap_script(
|
|
1828
|
-
worktree,
|
|
1829
|
-
managed_fixed,
|
|
1830
|
-
"review-run",
|
|
1831
|
-
"REVIEW-RETRY-REPAIR",
|
|
1832
|
-
"--reviewer",
|
|
1833
|
-
"repair-reviewer",
|
|
1834
|
-
"--runner-command-json",
|
|
1835
|
-
self.artifact_reviewer_runner(
|
|
1836
|
-
root,
|
|
1837
|
-
"repair retry payload",
|
|
1838
|
-
runtime_script=managed_fixed,
|
|
1839
|
-
),
|
|
1840
|
-
"--json",
|
|
1841
|
-
).stdout
|
|
1842
|
-
)
|
|
1843
|
-
self.assertEqual("approved", reviewed["verdict"])
|
|
1844
|
-
for path, original in old_evidence.items():
|
|
1845
|
-
self.assertEqual(original, path.read_bytes(), str(path))
|
|
1846
|
-
|
|
1847
|
-
def test_managed_retry_rejects_a_substantive_blocked_result(self) -> None:
|
|
1848
|
-
root, repo, _ = self.make_repo()
|
|
1849
|
-
managed_script = self.managed_runtime(root)
|
|
1850
|
-
worktree = self.start_task(repo, "REVIEW-RETRY-FINDING", "shared.txt")
|
|
1851
|
-
(worktree / "shared.txt").write_text("substantive retry rejection\n", encoding="utf-8")
|
|
1852
|
-
reviewer = root / "substantive-block.py"
|
|
1853
|
-
reviewer.write_text(
|
|
1854
|
-
"import json\n"
|
|
1855
|
-
"print(json.dumps({'verdict': 'blocked', 'summary': 'real correctness defect', "
|
|
1856
|
-
"'findings': ['P1: incorrect authorization check'], "
|
|
1857
|
-
"'risks': ['Production authorization can be bypassed.']}))\n",
|
|
1858
|
-
encoding="utf-8",
|
|
1859
|
-
)
|
|
1860
|
-
self.ap(
|
|
1861
|
-
worktree,
|
|
1862
|
-
"review-run",
|
|
1863
|
-
"REVIEW-RETRY-FINDING",
|
|
1864
|
-
"--reviewer",
|
|
1865
|
-
"finding-reviewer",
|
|
1866
|
-
"--runner-command-json",
|
|
1867
|
-
json.dumps([sys.executable, str(reviewer)]),
|
|
1868
|
-
check=False,
|
|
1869
|
-
)
|
|
1870
|
-
manifest_path = self.registry_manifest_path(repo, "REVIEW-RETRY-FINDING")
|
|
1871
|
-
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
1872
|
-
manifest["skill_version"] = "4.3.2"
|
|
1873
|
-
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
1874
|
-
rejected = self.ap_script(
|
|
1875
|
-
worktree,
|
|
1876
|
-
managed_script,
|
|
1877
|
-
"review-runtime-retry",
|
|
1878
|
-
"REVIEW-RETRY-FINDING",
|
|
1879
|
-
"--diff-fingerprint",
|
|
1880
|
-
manifest["review"]["diff_fingerprint"],
|
|
1881
|
-
"--reason-code",
|
|
1882
|
-
"managed-review-artifact-access",
|
|
1883
|
-
"--confirm-managed-runtime-retry",
|
|
1884
|
-
check=False,
|
|
1885
|
-
)
|
|
1886
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
1887
|
-
self.assertIn("not the exact non-substantive", rejected.stdout + rejected.stderr)
|
|
1888
|
-
|
|
1889
|
-
def test_review_run_retries_runtime_unavailable_and_allows_bound_user_override(self) -> None:
|
|
1890
|
-
root, repo, _ = self.make_repo()
|
|
1891
|
-
worktree = self.start_task(repo, "REVIEW-TIMEOUT", "shared.txt")
|
|
1892
|
-
(worktree / "shared.txt").write_text("review me slowly\n", encoding="utf-8")
|
|
1893
|
-
issued = json.loads(
|
|
1894
|
-
self.ap(
|
|
1895
|
-
worktree,
|
|
1896
|
-
"review-assignment",
|
|
1897
|
-
"REVIEW-TIMEOUT",
|
|
1898
|
-
"--reviewer",
|
|
1899
|
-
"reviewer-timeout",
|
|
1900
|
-
"--json",
|
|
1901
|
-
).stdout
|
|
1902
|
-
)
|
|
1903
|
-
self.shorten_review_deadline(repo, "REVIEW-TIMEOUT", issued, seconds=5)
|
|
1904
|
-
|
|
1905
|
-
slow_reviewer = root / "slow-reviewer.py"
|
|
1906
|
-
slow_reviewer.write_text("import time\ntime.sleep(30)\n", encoding="utf-8")
|
|
1907
|
-
started = time.monotonic()
|
|
1908
|
-
previous_startup_timeout = os.environ.get("AUTOCODING_REVIEW_STARTUP_TIMEOUT_SECONDS")
|
|
1909
|
-
os.environ["AUTOCODING_REVIEW_STARTUP_TIMEOUT_SECONDS"] = "0.1"
|
|
1910
|
-
try:
|
|
1911
|
-
timed_out = self.ap(
|
|
1912
|
-
worktree,
|
|
1913
|
-
"review-run",
|
|
1914
|
-
"REVIEW-TIMEOUT",
|
|
1915
|
-
"--reviewer",
|
|
1916
|
-
"reviewer-timeout",
|
|
1917
|
-
"--runner-command-json",
|
|
1918
|
-
json.dumps([sys.executable, str(slow_reviewer)]),
|
|
1919
|
-
check=False,
|
|
1920
|
-
)
|
|
1921
|
-
finally:
|
|
1922
|
-
if previous_startup_timeout is None:
|
|
1923
|
-
os.environ.pop("AUTOCODING_REVIEW_STARTUP_TIMEOUT_SECONDS", None)
|
|
1924
|
-
else:
|
|
1925
|
-
os.environ["AUTOCODING_REVIEW_STARTUP_TIMEOUT_SECONDS"] = previous_startup_timeout
|
|
1926
|
-
elapsed = time.monotonic() - started
|
|
1927
|
-
self.assertNotEqual(0, timed_out.returncode)
|
|
1928
|
-
self.assertLess(elapsed, 6.0)
|
|
1929
|
-
self.assertIn("runtime-unavailable", timed_out.stdout + timed_out.stderr)
|
|
1930
|
-
status = json.loads(
|
|
1931
|
-
self.ap(worktree, "task-status", "REVIEW-TIMEOUT", "--json").stdout
|
|
1932
|
-
)["tasks"][0]
|
|
1933
|
-
self.assertEqual("blocked", status["review"]["verdict"])
|
|
1934
|
-
self.assertEqual("runtime-unavailable", status["review"]["runtime_state"])
|
|
1935
|
-
receipt = json.loads(Path(status["review"]["runtime_receipt_path"]).read_text())
|
|
1936
|
-
self.assertEqual(2, receipt["schema"])
|
|
1937
|
-
self.assertEqual("runtime-unavailable", receipt["status"])
|
|
1938
|
-
self.assertEqual(2, len(receipt["attempts"]))
|
|
1939
|
-
self.assertRegex(receipt["event_log_sha256"], r"^[0-9a-f]{64}$")
|
|
1940
|
-
|
|
1941
|
-
receipt_path = Path(status["review"]["runtime_receipt_path"])
|
|
1942
|
-
original_receipt = receipt_path.read_bytes()
|
|
1943
|
-
tampered_receipt = json.loads(original_receipt)
|
|
1944
|
-
tampered_receipt["failure_kind"] = "tampered-before-override"
|
|
1945
|
-
receipt_path.write_text(json.dumps(tampered_receipt) + "\n", encoding="utf-8")
|
|
1946
|
-
rejected_receipt = self.ap(
|
|
1947
|
-
worktree,
|
|
1948
|
-
"review-runtime-override",
|
|
1949
|
-
"REVIEW-TIMEOUT",
|
|
1950
|
-
"--diff-fingerprint",
|
|
1951
|
-
status["current_diff_fingerprint"],
|
|
1952
|
-
"--authorized-by",
|
|
1953
|
-
"product-owner",
|
|
1954
|
-
"--authorization-ref",
|
|
1955
|
-
"conversation-pre-tamper",
|
|
1956
|
-
"--reason",
|
|
1957
|
-
"Tampered pre-override evidence must be rejected.",
|
|
1958
|
-
"--evidence",
|
|
1959
|
-
"targeted tests passed",
|
|
1960
|
-
"--confirm-runtime-bypass",
|
|
1961
|
-
check=False,
|
|
1962
|
-
)
|
|
1963
|
-
self.assertNotEqual(0, rejected_receipt.returncode)
|
|
1964
|
-
self.assertIn("changed after failure finalization", rejected_receipt.stdout + rejected_receipt.stderr)
|
|
1965
|
-
receipt_path.write_bytes(original_receipt)
|
|
1966
|
-
|
|
1967
|
-
event_log_path = Path(status["review"]["runtime_event_log_path"])
|
|
1968
|
-
original_event_log = event_log_path.read_bytes()
|
|
1969
|
-
event_log_path.write_bytes(original_event_log + b'{"event_type":"tampered"}\n')
|
|
1970
|
-
rejected_event = self.ap(
|
|
1971
|
-
worktree,
|
|
1972
|
-
"review-runtime-override",
|
|
1973
|
-
"REVIEW-TIMEOUT",
|
|
1974
|
-
"--diff-fingerprint",
|
|
1975
|
-
status["current_diff_fingerprint"],
|
|
1976
|
-
"--authorized-by",
|
|
1977
|
-
"product-owner",
|
|
1978
|
-
"--authorization-ref",
|
|
1979
|
-
"conversation-event-tamper",
|
|
1980
|
-
"--reason",
|
|
1981
|
-
"Tampered event evidence must be rejected before override.",
|
|
1982
|
-
"--evidence",
|
|
1983
|
-
"targeted tests passed",
|
|
1984
|
-
"--confirm-runtime-bypass",
|
|
1985
|
-
check=False,
|
|
1986
|
-
)
|
|
1987
|
-
self.assertNotEqual(0, rejected_event.returncode)
|
|
1988
|
-
self.assertIn("event log changed", rejected_event.stdout + rejected_event.stderr)
|
|
1989
|
-
event_log_path.write_bytes(original_event_log)
|
|
1990
|
-
|
|
1991
|
-
override = json.loads(
|
|
1992
|
-
self.ap(
|
|
1993
|
-
worktree,
|
|
1994
|
-
"review-runtime-override",
|
|
1995
|
-
"REVIEW-TIMEOUT",
|
|
1996
|
-
"--diff-fingerprint",
|
|
1997
|
-
status["current_diff_fingerprint"],
|
|
1998
|
-
"--authorized-by",
|
|
1999
|
-
"product-owner",
|
|
2000
|
-
"--authorization-ref",
|
|
2001
|
-
"conversation-2026-07-17",
|
|
2002
|
-
"--reason",
|
|
2003
|
-
"User accepted the exhausted Reviewer runtime failure.",
|
|
2004
|
-
"--evidence",
|
|
2005
|
-
"targeted tests passed",
|
|
2006
|
-
"--confirm-runtime-bypass",
|
|
2007
|
-
"--json",
|
|
2008
|
-
).stdout
|
|
2009
|
-
)
|
|
2010
|
-
self.assertEqual("runtime-bypassed", override["verdict"])
|
|
2011
|
-
bypassed_status = json.loads(
|
|
2012
|
-
self.ap(worktree, "task-status", "REVIEW-TIMEOUT", "--json").stdout
|
|
2013
|
-
)["tasks"][0]
|
|
2014
|
-
self.assertEqual("runtime-bypassed", bypassed_status["review"]["verdict"])
|
|
2015
|
-
self.assertEqual("runtime-bypassed", bypassed_status["review"]["runtime_state"])
|
|
2016
|
-
|
|
2017
|
-
receipt_path = Path(bypassed_status["review"]["runtime_receipt_path"])
|
|
2018
|
-
original_receipt = receipt_path.read_bytes()
|
|
2019
|
-
tampered_receipt = json.loads(original_receipt)
|
|
2020
|
-
tampered_receipt["failure_kind"] = "tampered"
|
|
2021
|
-
receipt_path.write_text(json.dumps(tampered_receipt) + "\n", encoding="utf-8")
|
|
2022
|
-
rejected_tamper = self.ap(
|
|
2023
|
-
worktree,
|
|
2024
|
-
"commit-push",
|
|
2025
|
-
"REVIEW-TIMEOUT",
|
|
2026
|
-
"--msg",
|
|
2027
|
-
"test: reject tampered runtime bypass",
|
|
2028
|
-
check=False,
|
|
2029
|
-
)
|
|
2030
|
-
self.assertNotEqual(0, rejected_tamper.returncode)
|
|
2031
|
-
self.assertIn("receipt SHA-256", rejected_tamper.stdout + rejected_tamper.stderr)
|
|
2032
|
-
receipt_path.write_bytes(original_receipt)
|
|
2033
|
-
|
|
2034
|
-
pushed = self.ap(
|
|
2035
|
-
worktree,
|
|
2036
|
-
"commit-push",
|
|
2037
|
-
"REVIEW-TIMEOUT",
|
|
2038
|
-
"--msg",
|
|
2039
|
-
"test: allow bound runtime bypass",
|
|
2040
|
-
)
|
|
2041
|
-
self.assertIn("commit-push", pushed.stdout + pushed.stderr)
|
|
2042
|
-
|
|
2043
|
-
def test_task_review_requires_assignment_and_exact_head(self) -> None:
|
|
2044
|
-
_, repo, _ = self.make_repo()
|
|
2045
|
-
worktree = self.start_task(repo, "REVIEW-HEAD", "shared.txt")
|
|
2046
|
-
(worktree / "shared.txt").write_text("review me\n", encoding="utf-8")
|
|
2047
|
-
status = json.loads(
|
|
2048
|
-
self.ap(worktree, "task-status", "REVIEW-HEAD", "--json").stdout
|
|
2049
|
-
)["tasks"][0]
|
|
2050
|
-
missing = self.ap(
|
|
2051
|
-
worktree,
|
|
2052
|
-
"task-review",
|
|
2053
|
-
"REVIEW-HEAD",
|
|
2054
|
-
"--verdict",
|
|
2055
|
-
"approved",
|
|
2056
|
-
"--diff-fingerprint",
|
|
2057
|
-
status["current_diff_fingerprint"],
|
|
2058
|
-
"--reviewer",
|
|
2059
|
-
"reviewer-1",
|
|
2060
|
-
check=False,
|
|
2061
|
-
)
|
|
2062
|
-
self.assertNotEqual(0, missing.returncode)
|
|
2063
|
-
self.assertIn("must use review-assignment", missing.stdout + missing.stderr)
|
|
2064
|
-
|
|
2065
|
-
issued = json.loads(
|
|
2066
|
-
self.ap(
|
|
2067
|
-
worktree,
|
|
2068
|
-
"review-assignment",
|
|
2069
|
-
"REVIEW-HEAD",
|
|
2070
|
-
"--reviewer",
|
|
2071
|
-
"reviewer-1",
|
|
2072
|
-
"--json",
|
|
2073
|
-
).stdout
|
|
2074
|
-
)["assignment"]
|
|
2075
|
-
git(worktree, "add", "shared.txt")
|
|
2076
|
-
git(worktree, "commit", "-qm", "manual task commit")
|
|
2077
|
-
stale = self.ap(
|
|
2078
|
-
worktree,
|
|
2079
|
-
"task-review",
|
|
2080
|
-
"REVIEW-HEAD",
|
|
2081
|
-
"--verdict",
|
|
2082
|
-
"approved",
|
|
2083
|
-
"--diff-fingerprint",
|
|
2084
|
-
issued["diff_fingerprint"],
|
|
2085
|
-
"--reviewer",
|
|
2086
|
-
"reviewer-1",
|
|
2087
|
-
check=False,
|
|
2088
|
-
)
|
|
2089
|
-
self.assertNotEqual(0, stale.returncode)
|
|
2090
|
-
self.assertIn("HEAD is stale", stale.stdout + stale.stderr)
|
|
2091
|
-
|
|
2092
|
-
def test_expired_review_assignment_cannot_be_renewed_or_approved(self) -> None:
|
|
2093
|
-
_, repo, _ = self.make_repo()
|
|
2094
|
-
worktree = self.start_task(repo, "REVIEW-EXPIRED", "shared.txt")
|
|
2095
|
-
(worktree / "shared.txt").write_text("review me\n", encoding="utf-8")
|
|
2096
|
-
issued = json.loads(
|
|
2097
|
-
self.ap(
|
|
2098
|
-
worktree,
|
|
2099
|
-
"review-assignment",
|
|
2100
|
-
"REVIEW-EXPIRED",
|
|
2101
|
-
"--reviewer",
|
|
2102
|
-
"reviewer-1",
|
|
2103
|
-
"--json",
|
|
2104
|
-
).stdout
|
|
2105
|
-
)
|
|
2106
|
-
assignment_path = Path(issued["assignment_path"])
|
|
2107
|
-
assignment = issued["assignment"]
|
|
2108
|
-
past_deadline = datetime.now(timezone.utc).replace(microsecond=0) - timedelta(seconds=1)
|
|
2109
|
-
assignment["deadline_at"] = past_deadline.isoformat()
|
|
2110
|
-
assignment["issued_at"] = (past_deadline - timedelta(seconds=150)).isoformat()
|
|
2111
|
-
assignment_path.write_text(json.dumps(assignment, indent=2) + "\n", encoding="utf-8")
|
|
2112
|
-
|
|
2113
|
-
manifest_path = self.registry_manifest_path(repo, "REVIEW-EXPIRED")
|
|
2114
|
-
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
2115
|
-
manifest["review"]["issued_at"] = assignment["issued_at"]
|
|
2116
|
-
manifest["review"]["deadline_at"] = assignment["deadline_at"]
|
|
2117
|
-
manifest["review"]["assignment_sha256"] = hashlib.sha256(
|
|
2118
|
-
assignment_path.read_bytes()
|
|
2119
|
-
).hexdigest()
|
|
2120
|
-
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
2121
|
-
|
|
2122
|
-
renewed = self.ap(
|
|
2123
|
-
worktree,
|
|
2124
|
-
"review-assignment",
|
|
2125
|
-
"REVIEW-EXPIRED",
|
|
2126
|
-
"--reviewer",
|
|
2127
|
-
"reviewer-1",
|
|
2128
|
-
check=False,
|
|
2129
|
-
)
|
|
2130
|
-
self.assertNotEqual(0, renewed.returncode)
|
|
2131
|
-
self.assertIn("timed out", renewed.stdout + renewed.stderr)
|
|
2132
|
-
approved = self.ap(
|
|
2133
|
-
worktree,
|
|
2134
|
-
"task-review",
|
|
2135
|
-
"REVIEW-EXPIRED",
|
|
2136
|
-
"--verdict",
|
|
2137
|
-
"approved",
|
|
2138
|
-
"--diff-fingerprint",
|
|
2139
|
-
assignment["diff_fingerprint"],
|
|
2140
|
-
"--reviewer",
|
|
2141
|
-
"reviewer-1",
|
|
2142
|
-
check=False,
|
|
2143
|
-
)
|
|
2144
|
-
self.assertNotEqual(0, approved.returncode)
|
|
2145
|
-
self.assertIn("deadline expired", approved.stdout + approved.stderr)
|
|
2146
|
-
|
|
2147
|
-
def test_schema_one_task_status_fails_closed_with_migration_recovery(self) -> None:
|
|
2148
|
-
_, repo, _ = self.make_repo()
|
|
2149
|
-
self.start_task(repo, "LEGACY-SCHEMA")
|
|
2150
|
-
registry = self.registry_manifest_path(repo, "LEGACY-SCHEMA")
|
|
2151
|
-
payload = json.loads(registry.read_text(encoding="utf-8"))
|
|
2152
|
-
payload["schema"] = 1
|
|
2153
|
-
for field in [
|
|
2154
|
-
"owned_paths",
|
|
2155
|
-
"depends_on",
|
|
2156
|
-
"prerequisite_shas",
|
|
2157
|
-
"writer_lease",
|
|
2158
|
-
"review",
|
|
2159
|
-
]:
|
|
2160
|
-
payload.pop(field, None)
|
|
2161
|
-
registry.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
2162
|
-
|
|
2163
|
-
result = self.ap(repo, "task-status", "LEGACY-SCHEMA", check=False)
|
|
2164
|
-
rendered = result.stdout + result.stderr
|
|
2165
|
-
self.assertNotEqual(0, result.returncode)
|
|
2166
|
-
self.assertIn("legacy schema-1 task", rendered)
|
|
2167
|
-
self.assertIn("cannot safely infer or claim owned_paths", rendered)
|
|
2168
|
-
self.assertIn("previously installed runtime", rendered)
|
|
2169
|
-
self.assertIn("restore the 3.0.0 runtime", rendered)
|
|
2170
|
-
|
|
2171
|
-
def test_owned_paths_are_required_and_unowned_changes_are_rejected(self) -> None:
|
|
2172
|
-
_, repo, remote = self.make_repo()
|
|
2173
|
-
missing = self.ap(
|
|
2174
|
-
repo,
|
|
2175
|
-
"task-start",
|
|
2176
|
-
"NO-OWNED",
|
|
2177
|
-
"--base",
|
|
2178
|
-
"origin/dev",
|
|
2179
|
-
check=False,
|
|
2180
|
-
)
|
|
2181
|
-
self.assertNotEqual(0, missing.returncode)
|
|
2182
|
-
self.assertIn("owned-path", (missing.stdout + missing.stderr).lower())
|
|
2183
|
-
self.assert_remote_branch(remote, "codex/NO-OWNED", False)
|
|
2184
|
-
|
|
2185
|
-
self.ap(
|
|
2186
|
-
repo,
|
|
2187
|
-
"task-start",
|
|
2188
|
-
"OWNED-ONLY",
|
|
2189
|
-
"--base",
|
|
2190
|
-
"origin/dev",
|
|
2191
|
-
"--owned-path",
|
|
2192
|
-
"src/owned",
|
|
2193
|
-
)
|
|
2194
|
-
worktree = self.task_worktree(repo, "OWNED-ONLY")
|
|
2195
|
-
outside = worktree / "src" / "outside.txt"
|
|
2196
|
-
outside.parent.mkdir(parents=True)
|
|
2197
|
-
outside.write_text("outside\n", encoding="utf-8")
|
|
2198
|
-
status = self.ap(worktree, "task-status", "OWNED-ONLY", "--json")
|
|
2199
|
-
fingerprint = json.loads(status.stdout)["tasks"][0]["current_diff_fingerprint"]
|
|
2200
|
-
review = self.ap(
|
|
2201
|
-
worktree,
|
|
2202
|
-
"task-review",
|
|
2203
|
-
"OWNED-ONLY",
|
|
2204
|
-
"--verdict",
|
|
2205
|
-
"approved",
|
|
2206
|
-
"--diff-fingerprint",
|
|
2207
|
-
fingerprint,
|
|
2208
|
-
check=False,
|
|
2209
|
-
)
|
|
2210
|
-
self.assertNotEqual(0, review.returncode)
|
|
2211
|
-
self.assertIn("outside task owned_paths", review.stdout + review.stderr)
|
|
2212
|
-
|
|
2213
|
-
def test_approved_fingerprint_expires_when_owned_diff_changes(self) -> None:
|
|
2214
|
-
_, repo, remote = self.make_repo()
|
|
2215
|
-
worktree = self.start_task(repo, "STALE-REVIEW")
|
|
2216
|
-
payload = worktree / "payload.txt"
|
|
2217
|
-
payload.write_text("reviewed\n", encoding="utf-8")
|
|
2218
|
-
registry = self.registry_manifest_path(repo, "STALE-REVIEW")
|
|
2219
|
-
manifest = json.loads(registry.read_text(encoding="utf-8"))
|
|
2220
|
-
owner = manifest["owner"]
|
|
2221
|
-
manifest["owner"] = "another-lifecycle-owner"
|
|
2222
|
-
registry.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
2223
|
-
status = self.ap(worktree, "task-status", "STALE-REVIEW", "--json")
|
|
2224
|
-
fingerprint = json.loads(status.stdout)["tasks"][0]["current_diff_fingerprint"]
|
|
2225
|
-
non_owner_review = self.ap(
|
|
2226
|
-
worktree,
|
|
2227
|
-
"task-review",
|
|
2228
|
-
"STALE-REVIEW",
|
|
2229
|
-
"--verdict",
|
|
2230
|
-
"approved",
|
|
2231
|
-
"--diff-fingerprint",
|
|
2232
|
-
fingerprint,
|
|
2233
|
-
check=False,
|
|
2234
|
-
)
|
|
2235
|
-
self.assertNotEqual(0, non_owner_review.returncode)
|
|
2236
|
-
self.assertIn("lifecycle owner", non_owner_review.stdout + non_owner_review.stderr)
|
|
2237
|
-
manifest["owner"] = owner
|
|
2238
|
-
registry.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
2239
|
-
self.approve_task(worktree, "STALE-REVIEW")
|
|
2240
|
-
payload.write_text("changed after review\n", encoding="utf-8")
|
|
2241
|
-
|
|
2242
|
-
result = self.ap(
|
|
2243
|
-
worktree,
|
|
2244
|
-
"commit-push",
|
|
2245
|
-
"STALE-REVIEW",
|
|
2246
|
-
"--msg",
|
|
2247
|
-
"STALE-REVIEW: must fail",
|
|
2248
|
-
check=False,
|
|
2249
|
-
)
|
|
2250
|
-
self.assertNotEqual(0, result.returncode)
|
|
2251
|
-
self.assertIn("fingerprint is stale", result.stdout + result.stderr)
|
|
2252
|
-
self.assert_remote_branch(remote, "codex/STALE-REVIEW", False)
|
|
2253
|
-
|
|
2254
|
-
def test_writer_lease_requires_match_and_owner_handoff_uses_generation_cas(self) -> None:
|
|
2255
|
-
_, repo, _ = self.make_repo()
|
|
2256
|
-
owner = _TEST_OWNER
|
|
2257
|
-
self.ap(
|
|
2258
|
-
repo,
|
|
2259
|
-
"task-start",
|
|
2260
|
-
"LEASE-1",
|
|
2261
|
-
"--base",
|
|
2262
|
-
"origin/dev",
|
|
2263
|
-
"--owned-path",
|
|
2264
|
-
".",
|
|
2265
|
-
)
|
|
2266
|
-
worktree = self.task_worktree(repo, "LEASE-1")
|
|
2267
|
-
(worktree / "lease.txt").write_text("ready\n", encoding="utf-8")
|
|
2268
|
-
self.approve_task(worktree, "LEASE-1")
|
|
2269
|
-
|
|
2270
|
-
self.ap(
|
|
2271
|
-
repo,
|
|
2272
|
-
"task-handoff",
|
|
2273
|
-
"LEASE-1",
|
|
2274
|
-
"--from",
|
|
2275
|
-
owner,
|
|
2276
|
-
"--to",
|
|
2277
|
-
"fixer-label",
|
|
2278
|
-
"--generation",
|
|
2279
|
-
"1",
|
|
2280
|
-
)
|
|
2281
|
-
|
|
2282
|
-
mismatch = self.ap(
|
|
2283
|
-
worktree,
|
|
2284
|
-
"commit-push",
|
|
2285
|
-
"LEASE-1",
|
|
2286
|
-
"--msg",
|
|
2287
|
-
"LEASE-1: wrong writer",
|
|
2288
|
-
check=False,
|
|
2289
|
-
)
|
|
2290
|
-
self.assertNotEqual(0, mismatch.returncode)
|
|
2291
|
-
self.assertIn("writer lease mismatch", (mismatch.stdout + mismatch.stderr).lower())
|
|
2292
|
-
|
|
2293
|
-
spoofed = self.ap(
|
|
2294
|
-
worktree,
|
|
2295
|
-
"commit-push",
|
|
2296
|
-
"LEASE-1",
|
|
2297
|
-
"--msg",
|
|
2298
|
-
"LEASE-1: spoofed writer",
|
|
2299
|
-
"--writer",
|
|
2300
|
-
"fixer-label",
|
|
2301
|
-
check=False,
|
|
2302
|
-
)
|
|
2303
|
-
self.assertNotEqual(0, spoofed.returncode)
|
|
2304
|
-
self.assertIn("actor identity cannot be overridden", spoofed.stdout + spoofed.stderr)
|
|
2305
|
-
|
|
2306
|
-
self.ap(
|
|
2307
|
-
repo,
|
|
2308
|
-
"task-handoff",
|
|
2309
|
-
"LEASE-1",
|
|
2310
|
-
"--from",
|
|
2311
|
-
"fixer-label",
|
|
2312
|
-
"--to",
|
|
2313
|
-
owner,
|
|
2314
|
-
"--generation",
|
|
2315
|
-
"2",
|
|
2316
|
-
)
|
|
2317
|
-
stale = self.ap(
|
|
2318
|
-
repo,
|
|
2319
|
-
"task-handoff",
|
|
2320
|
-
"LEASE-1",
|
|
2321
|
-
"--from",
|
|
2322
|
-
owner,
|
|
2323
|
-
"--to",
|
|
2324
|
-
"next-writer",
|
|
2325
|
-
"--generation",
|
|
2326
|
-
"2",
|
|
2327
|
-
check=False,
|
|
2328
|
-
)
|
|
2329
|
-
self.assertNotEqual(0, stale.returncode)
|
|
2330
|
-
self.assertIn("generation changed", stale.stdout + stale.stderr)
|
|
2331
|
-
manifest = json.loads(self.registry_manifest_path(repo, "LEASE-1").read_text(encoding="utf-8"))
|
|
2332
|
-
self.assertEqual(owner, manifest["writer_lease"]["holder"])
|
|
2333
|
-
self.assertEqual(3, manifest["writer_lease"]["generation"])
|
|
2334
|
-
|
|
2335
|
-
def test_dependency_sha_must_already_be_in_task_base(self) -> None:
|
|
2336
|
-
_, repo, _ = self.make_repo()
|
|
2337
|
-
tree = git_output(repo, "rev-parse", "HEAD^{tree}")
|
|
2338
|
-
orphan = git_output(repo, "commit-tree", tree, "-m", "unintegrated prerequisite")
|
|
2339
|
-
result = self.ap(
|
|
2340
|
-
repo,
|
|
2341
|
-
"task-start",
|
|
2342
|
-
"DEPENDENT-1",
|
|
2343
|
-
"--base",
|
|
2344
|
-
"origin/dev",
|
|
2345
|
-
"--owned-path",
|
|
2346
|
-
".",
|
|
2347
|
-
"--depends-on",
|
|
2348
|
-
f"UPSTREAM-1={orphan}",
|
|
2349
|
-
check=False,
|
|
2350
|
-
)
|
|
2351
|
-
self.assertNotEqual(0, result.returncode)
|
|
2352
|
-
self.assertIn("not integrated", result.stdout + result.stderr)
|
|
2353
|
-
|
|
2354
|
-
def test_target_advance_rebases_then_requires_review_before_integration(self) -> None:
|
|
2355
|
-
_, repo, remote = self.make_repo()
|
|
2356
|
-
worktree = self.start_task(repo, "REBASE-REVIEW")
|
|
2357
|
-
(worktree / "task.txt").write_text("task\n", encoding="utf-8")
|
|
2358
|
-
self.commit_push(worktree, "REBASE-REVIEW", "REBASE-REVIEW: ready")
|
|
2359
|
-
|
|
2360
|
-
(repo / "upstream.txt").write_text("upstream\n", encoding="utf-8")
|
|
2361
|
-
git(repo, "add", "upstream.txt")
|
|
2362
|
-
git(repo, "commit", "-qm", "advance target")
|
|
2363
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
2364
|
-
|
|
2365
|
-
rebased = self.ap(repo, "task-integrate", "REBASE-REVIEW", check=False)
|
|
2366
|
-
self.assertNotEqual(0, rebased.returncode)
|
|
2367
|
-
self.assertIn("review again", rebased.stdout + rebased.stderr)
|
|
2368
|
-
manifest = json.loads(self.registry_manifest_path(repo, "REBASE-REVIEW").read_text(encoding="utf-8"))
|
|
2369
|
-
self.assertEqual("pushed", manifest["state"])
|
|
2370
|
-
self.assertEqual("pending", manifest["review"]["verdict"])
|
|
2371
|
-
self.assertNotEqual(
|
|
2372
|
-
0,
|
|
2373
|
-
git(remote, "cat-file", "-e", "refs/heads/dev:task.txt", check=False).returncode,
|
|
2374
|
-
)
|
|
2375
|
-
|
|
2376
|
-
self.approve_task(worktree, "REBASE-REVIEW")
|
|
2377
|
-
self.ap(repo, "task-integrate", "REBASE-REVIEW")
|
|
2378
|
-
self.assertEqual("task", git_output(remote, "show", "refs/heads/dev:task.txt"))
|
|
2379
|
-
|
|
2380
|
-
def test_rebase_conflict_can_resume_only_then_requires_fresh_review(self) -> None:
|
|
2381
|
-
_, repo, remote = self.make_repo()
|
|
2382
|
-
worktree = self.start_task(repo, "RESUME-1")
|
|
2383
|
-
(worktree / "shared.txt").write_text("task side\n", encoding="utf-8")
|
|
2384
|
-
self.commit_push(worktree, "RESUME-1", "RESUME-1: ready")
|
|
2385
|
-
|
|
2386
|
-
(repo / "shared.txt").write_text("target side\n", encoding="utf-8")
|
|
2387
|
-
git(repo, "add", "shared.txt")
|
|
2388
|
-
git(repo, "commit", "-qm", "conflicting target change")
|
|
2389
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
2390
|
-
|
|
2391
|
-
conflict = self.ap(repo, "task-integrate", "RESUME-1", check=False)
|
|
2392
|
-
self.assertNotEqual(0, conflict.returncode)
|
|
2393
|
-
self.assertIn("rebase conflicted", conflict.stdout + conflict.stderr)
|
|
2394
|
-
manifest = json.loads(self.registry_manifest_path(repo, "RESUME-1").read_text(encoding="utf-8"))
|
|
2395
|
-
self.assertEqual("conflicted", manifest["state"])
|
|
2396
|
-
self.assertEqual("pending", manifest["review"]["verdict"])
|
|
2397
|
-
|
|
2398
|
-
(worktree / "shared.txt").write_text("resolved\n", encoding="utf-8")
|
|
2399
|
-
git(worktree, "add", "shared.txt")
|
|
2400
|
-
git(worktree, "-c", "core.editor=true", "rebase", "--continue")
|
|
2401
|
-
self.ap(repo, "task-resume", "RESUME-1")
|
|
2402
|
-
manifest = json.loads(self.registry_manifest_path(repo, "RESUME-1").read_text(encoding="utf-8"))
|
|
2403
|
-
self.assertEqual("pushed", manifest["state"])
|
|
2404
|
-
self.assertEqual("pending", manifest["review"]["verdict"])
|
|
2405
|
-
|
|
2406
|
-
self.approve_task(worktree, "RESUME-1")
|
|
2407
|
-
self.ap(repo, "task-integrate", "RESUME-1")
|
|
2408
|
-
self.assertEqual("resolved", git_output(remote, "show", "refs/heads/dev:shared.txt"))
|
|
2409
|
-
|
|
2410
|
-
def test_task_start_rolls_back_checkout_hook_side_effects(self) -> None:
|
|
2411
|
-
hook_bodies = {
|
|
2412
|
-
"untracked": (
|
|
2413
|
-
'root="$(git rev-parse --show-toplevel)"\n'
|
|
2414
|
-
'printf "hook data\\n" > "$root/hook-created.txt"\n'
|
|
2415
|
-
),
|
|
2416
|
-
"clean-commit": (
|
|
2417
|
-
'root="$(git rev-parse --show-toplevel)"\n'
|
|
2418
|
-
'printf "hook commit\\n" > "$root/hook-created.txt"\n'
|
|
2419
|
-
'git -C "$root" add hook-created.txt\n'
|
|
2420
|
-
'git -C "$root" commit --no-verify -qm "checkout hook commit"\n'
|
|
2421
|
-
),
|
|
2422
|
-
}
|
|
2423
|
-
for label, body in hook_bodies.items():
|
|
2424
|
-
with self.subTest(label=label):
|
|
2425
|
-
root, repo, _ = self.make_repo()
|
|
2426
|
-
self.install_hook(repo, "post-checkout", body)
|
|
2427
|
-
task_id = f"HOOK-{label.upper()}"
|
|
2428
|
-
|
|
2429
|
-
result = self.ap(
|
|
2430
|
-
repo,
|
|
2431
|
-
"task-start",
|
|
2432
|
-
task_id,
|
|
2433
|
-
"--base",
|
|
2434
|
-
"origin/dev",
|
|
2435
|
-
"--owned-path",
|
|
2436
|
-
".",
|
|
2437
|
-
check=False,
|
|
2438
|
-
)
|
|
2439
|
-
|
|
2440
|
-
self.assertNotEqual(0, result.returncode)
|
|
2441
|
-
self.assertIn("hook", (result.stdout + result.stderr).lower())
|
|
2442
|
-
self.assert_local_branch(repo, f"codex/{task_id}", False)
|
|
2443
|
-
self.assertFalse(self.registry_manifest_path(repo, task_id).exists())
|
|
2444
|
-
self.assertNotIn(
|
|
2445
|
-
f"refs/heads/codex/{task_id}",
|
|
2446
|
-
git_output(repo, "worktree", "list", "--porcelain"),
|
|
2447
|
-
)
|
|
2448
|
-
self.assertFalse((root / "worktrees" / repo.name / task_id).exists())
|
|
2449
|
-
|
|
2450
|
-
def test_control_commands_are_rejected_from_another_task_worktree(self) -> None:
|
|
2451
|
-
_, repo, _ = self.make_repo()
|
|
2452
|
-
first = self.start_task(repo, "CROSS-1", "cross/one")
|
|
2453
|
-
second = self.start_task(repo, "CROSS-2", "cross/two")
|
|
2454
|
-
|
|
2455
|
-
commands = [
|
|
2456
|
-
("task-integrate", "CROSS-1"),
|
|
2457
|
-
("task-finish", "CROSS-1"),
|
|
2458
|
-
("task-prune",),
|
|
2459
|
-
("task-start", "CROSS-3"),
|
|
2460
|
-
]
|
|
2461
|
-
for args in commands:
|
|
2462
|
-
with self.subTest(command=args[0]):
|
|
2463
|
-
before = {
|
|
2464
|
-
"control_head": git_output(repo, "rev-parse", "HEAD"),
|
|
2465
|
-
"control_status": git_output(repo, "status", "--porcelain=v1"),
|
|
2466
|
-
"first_head": git_output(first, "rev-parse", "HEAD"),
|
|
2467
|
-
"first_status": git_output(first, "status", "--porcelain=v1"),
|
|
2468
|
-
"second_head": git_output(second, "rev-parse", "HEAD"),
|
|
2469
|
-
"second_status": git_output(second, "status", "--porcelain=v1"),
|
|
2470
|
-
"worktrees": git_output(repo, "worktree", "list", "--porcelain"),
|
|
2471
|
-
}
|
|
2472
|
-
result = self.ap(second, *args, check=False)
|
|
2473
|
-
self.assertNotEqual(0, result.returncode)
|
|
2474
|
-
self.assertIn("control", (result.stdout + result.stderr).lower())
|
|
2475
|
-
after = {
|
|
2476
|
-
"control_head": git_output(repo, "rev-parse", "HEAD"),
|
|
2477
|
-
"control_status": git_output(repo, "status", "--porcelain=v1"),
|
|
2478
|
-
"first_head": git_output(first, "rev-parse", "HEAD"),
|
|
2479
|
-
"first_status": git_output(first, "status", "--porcelain=v1"),
|
|
2480
|
-
"second_head": git_output(second, "rev-parse", "HEAD"),
|
|
2481
|
-
"second_status": git_output(second, "status", "--porcelain=v1"),
|
|
2482
|
-
"worktrees": git_output(repo, "worktree", "list", "--porcelain"),
|
|
2483
|
-
}
|
|
2484
|
-
self.assertEqual(before, after)
|
|
2485
|
-
|
|
2486
|
-
def test_task_start_rejects_overlapping_active_owned_paths(self) -> None:
|
|
2487
|
-
_, repo, _ = self.make_repo()
|
|
2488
|
-
first = self.start_task(repo, "OWNER-1", "backend")
|
|
2489
|
-
result = self.ap(
|
|
2490
|
-
repo,
|
|
2491
|
-
"task-start",
|
|
2492
|
-
"OWNER-2",
|
|
2493
|
-
"--base",
|
|
2494
|
-
"origin/dev",
|
|
2495
|
-
"--owned-path",
|
|
2496
|
-
"backend/api",
|
|
2497
|
-
"--isolated",
|
|
2498
|
-
check=False,
|
|
2499
|
-
)
|
|
2500
|
-
self.assertNotEqual(0, result.returncode)
|
|
2501
|
-
self.assertIn("overlap active task OWNER-1", result.stdout + result.stderr)
|
|
2502
|
-
self.assertTrue(first.exists())
|
|
2503
|
-
self.assertFalse(self.registry_manifest_path(repo, "OWNER-2").exists())
|
|
2504
|
-
self.assert_local_branch(repo, "codex/OWNER-2", False)
|
|
2505
|
-
|
|
2506
|
-
def test_task_start_rejects_terminal_ledger_lifecycle_and_multi_writer(self) -> None:
|
|
2507
|
-
_, repo, _ = self.make_repo()
|
|
2508
|
-
terminal = self.ap(
|
|
2509
|
-
repo,
|
|
2510
|
-
"task-start",
|
|
2511
|
-
"LEDGER-END",
|
|
2512
|
-
"--base",
|
|
2513
|
-
"origin/dev",
|
|
2514
|
-
"--owned-path",
|
|
2515
|
-
"docs/tasks/closure-log.md",
|
|
2516
|
-
check=False,
|
|
2517
|
-
)
|
|
2518
|
-
self.assertNotEqual(0, terminal.returncode)
|
|
2519
|
-
self.assertIn("terminal maintenance", terminal.stdout + terminal.stderr)
|
|
2520
|
-
self.assertFalse(self.registry_manifest_path(repo, "LEDGER-END").exists())
|
|
2521
|
-
|
|
2522
|
-
multi = self.ap(
|
|
2523
|
-
repo,
|
|
2524
|
-
"task-start",
|
|
2525
|
-
"MULTI-1",
|
|
2526
|
-
"--base",
|
|
2527
|
-
"origin/dev",
|
|
2528
|
-
"--owned-path",
|
|
2529
|
-
"frontend",
|
|
2530
|
-
"--writers",
|
|
2531
|
-
"2",
|
|
2532
|
-
check=False,
|
|
2533
|
-
)
|
|
2534
|
-
self.assertNotEqual(0, multi.returncode)
|
|
2535
|
-
self.assertIn("exactly one writer lease", multi.stdout + multi.stderr)
|
|
2536
|
-
self.assertFalse(self.registry_manifest_path(repo, "MULTI-1").exists())
|
|
2537
|
-
|
|
2538
|
-
def test_missing_task_manifest_is_rejected_in_linked_worktree(self) -> None:
|
|
2539
|
-
_, repo, remote = self.make_repo("worktree")
|
|
2540
|
-
worktree = self.start_task(repo, "NO-MANIFEST")
|
|
2541
|
-
git_dir = Path(git_output(worktree, "rev-parse", "--git-dir"))
|
|
2542
|
-
if not git_dir.is_absolute():
|
|
2543
|
-
git_dir = (worktree / git_dir).resolve()
|
|
2544
|
-
(git_dir / "auto-coding-skill-task.json").unlink()
|
|
2545
|
-
before = git_output(worktree, "rev-parse", "HEAD")
|
|
2546
|
-
(worktree / "payload.txt").write_text("must not publish\n", encoding="utf-8")
|
|
2547
|
-
|
|
2548
|
-
result = self.ap(
|
|
2549
|
-
worktree,
|
|
2550
|
-
"commit-push",
|
|
2551
|
-
"NO-MANIFEST",
|
|
2552
|
-
"--msg",
|
|
2553
|
-
"NO-MANIFEST: must fail",
|
|
2554
|
-
check=False,
|
|
2555
|
-
)
|
|
2556
|
-
|
|
2557
|
-
self.assertNotEqual(0, result.returncode)
|
|
2558
|
-
self.assertIn("manifest", (result.stdout + result.stderr).lower())
|
|
2559
|
-
self.assertEqual(before, git_output(worktree, "rev-parse", "HEAD"))
|
|
2560
|
-
self.assert_remote_branch(remote, "codex/NO-MANIFEST", False)
|
|
2561
|
-
|
|
2562
|
-
def test_corrupt_manifest_cannot_redirect_cleanup_to_control_branch(self) -> None:
|
|
2563
|
-
_, repo, remote = self.make_repo()
|
|
2564
|
-
worktree = self.start_task(repo, "CORRUPT-1")
|
|
2565
|
-
registry = self.registry_manifest_path(repo, "CORRUPT-1")
|
|
2566
|
-
worktree_git_dir = Path(git_output(worktree, "rev-parse", "--git-dir"))
|
|
2567
|
-
if not worktree_git_dir.is_absolute():
|
|
2568
|
-
worktree_git_dir = (worktree / worktree_git_dir).resolve()
|
|
2569
|
-
worktree_manifest = worktree_git_dir / "auto-coding-skill-task.json"
|
|
2570
|
-
payload = json.loads(registry.read_text(encoding="utf-8"))
|
|
2571
|
-
payload["task_branch"] = "dev"
|
|
2572
|
-
rendered = json.dumps(payload, indent=2, sort_keys=True) + "\n"
|
|
2573
|
-
registry.write_text(rendered, encoding="utf-8")
|
|
2574
|
-
worktree_manifest.write_text(rendered, encoding="utf-8")
|
|
2575
|
-
local_dev = git_output(repo, "rev-parse", "refs/heads/dev")
|
|
2576
|
-
remote_dev = git_output(remote, "rev-parse", "refs/heads/dev")
|
|
2577
|
-
|
|
2578
|
-
result = self.ap(repo, "task-finish", "CORRUPT-1", check=False)
|
|
2579
|
-
|
|
2580
|
-
self.assertNotEqual(0, result.returncode)
|
|
2581
|
-
self.assertIn("invalid task branch", (result.stdout + result.stderr).lower())
|
|
2582
|
-
self.assertEqual(local_dev, git_output(repo, "rev-parse", "refs/heads/dev"))
|
|
2583
|
-
self.assertEqual(remote_dev, git_output(remote, "rev-parse", "refs/heads/dev"))
|
|
2584
|
-
self.assertTrue(worktree.exists())
|
|
2585
|
-
self.assert_local_branch(repo, "codex/CORRUPT-1", True)
|
|
2586
|
-
|
|
2587
|
-
def test_commit_push_requires_matching_manifest_and_isolated_worktree(self) -> None:
|
|
2588
|
-
_, repo, remote = self.make_repo()
|
|
2589
|
-
worktree = self.start_task(repo, "ISOLATED-1", "task-only.txt")
|
|
2590
|
-
second_worktree = self.start_task(repo, "ISOLATED-2", "second-task-only.txt")
|
|
2591
|
-
(worktree / "task-only.txt").write_text("task change\n", encoding="utf-8")
|
|
2592
|
-
(second_worktree / "second-task-only.txt").write_text(
|
|
2593
|
-
"second task change\n",
|
|
2594
|
-
encoding="utf-8",
|
|
2595
|
-
)
|
|
2596
|
-
(repo / "shared.txt").write_text("primary checkout change\n", encoding="utf-8")
|
|
2597
|
-
|
|
2598
|
-
mismatch = self.assert_rejected_without_mutation(
|
|
2599
|
-
worktree,
|
|
2600
|
-
"commit-push",
|
|
2601
|
-
"ANOTHER-TASK",
|
|
2602
|
-
"--msg",
|
|
2603
|
-
"ANOTHER-TASK: must fail",
|
|
2604
|
-
)
|
|
2605
|
-
self.assertIn("task", (mismatch.stdout + mismatch.stderr).lower())
|
|
2606
|
-
|
|
2607
|
-
primary = self.assert_rejected_without_mutation(
|
|
2608
|
-
repo,
|
|
2609
|
-
"commit-push",
|
|
2610
|
-
"ISOLATED-1",
|
|
2611
|
-
"--msg",
|
|
2612
|
-
"ISOLATED-1: must fail from primary checkout",
|
|
2613
|
-
)
|
|
2614
|
-
self.assertIn("worktree", (primary.stdout + primary.stderr).lower())
|
|
2615
|
-
|
|
2616
|
-
second_status = git(second_worktree, "status", "--short").stdout
|
|
2617
|
-
self.assertIn("?? second-task-only.txt", second_status)
|
|
2618
|
-
self.approve_task(worktree, "ISOLATED-1")
|
|
2619
|
-
self.approve_task(second_worktree, "ISOLATED-2")
|
|
2620
|
-
with ThreadPoolExecutor(max_workers=2) as pool:
|
|
2621
|
-
first_commit = pool.submit(
|
|
2622
|
-
self.ap,
|
|
2623
|
-
worktree,
|
|
2624
|
-
"commit-push",
|
|
2625
|
-
"ISOLATED-1",
|
|
2626
|
-
"--msg",
|
|
2627
|
-
"ISOLATED-1: isolated change",
|
|
2628
|
-
)
|
|
2629
|
-
second_commit = pool.submit(
|
|
2630
|
-
self.ap,
|
|
2631
|
-
second_worktree,
|
|
2632
|
-
"commit-push",
|
|
2633
|
-
"ISOLATED-2",
|
|
2634
|
-
"--msg",
|
|
2635
|
-
"ISOLATED-2: independent change",
|
|
2636
|
-
)
|
|
2637
|
-
first_commit.result()
|
|
2638
|
-
second_commit.result()
|
|
2639
|
-
|
|
2640
|
-
self.assert_remote_branch(remote, "codex/ISOLATED-1", True)
|
|
2641
|
-
task_ref = "refs/heads/codex/ISOLATED-1"
|
|
2642
|
-
self.assertEqual(
|
|
2643
|
-
"task change",
|
|
2644
|
-
git_output(remote, "show", f"{task_ref}:task-only.txt"),
|
|
2645
|
-
)
|
|
2646
|
-
self.assertEqual("baseline", git_output(remote, "show", f"{task_ref}:shared.txt"))
|
|
2647
|
-
self.assertNotEqual(
|
|
2648
|
-
0,
|
|
2649
|
-
git(
|
|
2650
|
-
remote,
|
|
2651
|
-
"cat-file",
|
|
2652
|
-
"-e",
|
|
2653
|
-
f"{task_ref}:second-task-only.txt",
|
|
2654
|
-
check=False,
|
|
2655
|
-
).returncode,
|
|
2656
|
-
)
|
|
2657
|
-
self.assertEqual("primary checkout change\n", (repo / "shared.txt").read_text(encoding="utf-8"))
|
|
2658
|
-
self.assertEqual(" M shared.txt\n", git(repo, "status", "--short").stdout)
|
|
2659
|
-
second_ref = "refs/heads/codex/ISOLATED-2"
|
|
2660
|
-
self.assertEqual(
|
|
2661
|
-
"second task change",
|
|
2662
|
-
git_output(remote, "show", f"{second_ref}:second-task-only.txt"),
|
|
2663
|
-
)
|
|
2664
|
-
self.assertNotEqual(
|
|
2665
|
-
0,
|
|
2666
|
-
git(remote, "cat-file", "-e", f"{second_ref}:task-only.txt", check=False).returncode,
|
|
2667
|
-
)
|
|
2668
|
-
|
|
2669
|
-
def test_task_integrate_from_primary_pushes_target_and_cleans_task_refs(self) -> None:
|
|
2670
|
-
root, repo, remote = self.make_repo()
|
|
2671
|
-
gate_marker = root / "gate-invocations"
|
|
2672
|
-
commit_hook_marker = root / "commit-hook-invocations"
|
|
2673
|
-
push_hook_marker = root / "push-hook-invocations"
|
|
2674
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
2675
|
-
original = engineering.read_text(encoding="utf-8")
|
|
2676
|
-
configured = original.replace(
|
|
2677
|
-
"gate_changed: 'true'",
|
|
2678
|
-
f"gate_changed: 'printf x >> {gate_marker}'",
|
|
2679
|
-
)
|
|
2680
|
-
self.assertNotEqual(original, configured)
|
|
2681
|
-
engineering.write_text(configured, encoding="utf-8")
|
|
2682
|
-
git(repo, "add", "docs/ENGINEERING.md")
|
|
2683
|
-
git(repo, "commit", "-qm", "configure observable fast gate")
|
|
2684
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
2685
|
-
self.install_hook(repo, "pre-commit", f"printf c >> '{commit_hook_marker}'\n")
|
|
2686
|
-
self.install_hook(repo, "pre-push", f"printf p >> '{push_hook_marker}'\n")
|
|
2687
|
-
|
|
2688
|
-
worktree = self.start_task(repo, "INTEGRATE-1")
|
|
2689
|
-
(worktree / "integrated.txt").write_text("integrated\n", encoding="utf-8")
|
|
2690
|
-
self.commit_push(worktree, "INTEGRATE-1", "INTEGRATE-1: ready")
|
|
2691
|
-
review_dir = Path(
|
|
2692
|
-
json.loads(
|
|
2693
|
-
self.registry_manifest_path(repo, "INTEGRATE-1").read_text(encoding="utf-8")
|
|
2694
|
-
)["review"]["assignment_path"]
|
|
2695
|
-
).parent
|
|
2696
|
-
self.assertTrue(review_dir.is_dir())
|
|
2697
|
-
task_commit = git_output(worktree, "rev-parse", "HEAD")
|
|
2698
|
-
self.assertEqual("c", commit_hook_marker.read_text(encoding="utf-8"))
|
|
2699
|
-
self.assertFalse(
|
|
2700
|
-
push_hook_marker.exists(),
|
|
2701
|
-
"the internal backup push must not duplicate the final pre-push hook",
|
|
2702
|
-
)
|
|
2703
|
-
|
|
2704
|
-
rejected = self.ap(worktree, "task-integrate", "INTEGRATE-1", check=False)
|
|
2705
|
-
self.assertNotEqual(0, rejected.returncode)
|
|
2706
|
-
self.assertTrue(worktree.exists())
|
|
2707
|
-
self.assert_remote_branch(remote, "codex/INTEGRATE-1", True)
|
|
2708
|
-
|
|
2709
|
-
(repo / "shared.txt").write_text("primary work stays untouched\n", encoding="utf-8")
|
|
2710
|
-
self.ap(repo, "task-integrate", "INTEGRATE-1")
|
|
2711
|
-
|
|
2712
|
-
self.assertEqual("integrated", git_output(remote, "show", "refs/heads/dev:integrated.txt"))
|
|
2713
|
-
self.assertEqual(
|
|
2714
|
-
"primary work stays untouched\n",
|
|
2715
|
-
(repo / "shared.txt").read_text(encoding="utf-8"),
|
|
2716
|
-
)
|
|
2717
|
-
self.assertFalse(worktree.exists())
|
|
2718
|
-
self.assert_local_branch(repo, "codex/INTEGRATE-1", False)
|
|
2719
|
-
self.assert_remote_branch(remote, "codex/INTEGRATE-1", False)
|
|
2720
|
-
self.assertFalse(review_dir.exists())
|
|
2721
|
-
self.assertEqual("x", gate_marker.read_text(encoding="utf-8"), "push flow must run the fast gate exactly once")
|
|
2722
|
-
self.assertEqual("c", commit_hook_marker.read_text(encoding="utf-8"), "push flow must create exactly one hook-visible commit")
|
|
2723
|
-
self.assertEqual("p", push_hook_marker.read_text(encoding="utf-8"), "the final target push hook must run exactly once")
|
|
2724
|
-
self.assertEqual(task_commit, git_output(remote, "rev-parse", "refs/heads/dev"), "integration must not create a second evidence commit")
|
|
2725
|
-
|
|
2726
|
-
def test_task_integrate_rejects_legacy_gate_failed_state(self) -> None:
|
|
2727
|
-
_, repo, remote = self.make_repo()
|
|
2728
|
-
worktree = self.start_task(repo, "FAILED-GATE")
|
|
2729
|
-
(worktree / "must-not-integrate.txt").write_text("blocked\n", encoding="utf-8")
|
|
2730
|
-
self.commit_push(worktree, "FAILED-GATE", "FAILED-GATE: staged task")
|
|
2731
|
-
registry = self.registry_manifest_path(repo, "FAILED-GATE")
|
|
2732
|
-
payload = json.loads(registry.read_text(encoding="utf-8"))
|
|
2733
|
-
payload["state"] = "gate-failed"
|
|
2734
|
-
registry.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
2735
|
-
|
|
2736
|
-
result = self.ap(repo, "task-integrate", "FAILED-GATE", check=False)
|
|
2737
|
-
|
|
2738
|
-
self.assertNotEqual(0, result.returncode)
|
|
2739
|
-
self.assertIn("committed and pushed", (result.stdout + result.stderr).lower())
|
|
2740
|
-
self.assertTrue(worktree.exists())
|
|
2741
|
-
self.assertNotEqual(
|
|
2742
|
-
0,
|
|
2743
|
-
git(remote, "cat-file", "-e", "refs/heads/dev:must-not-integrate.txt", check=False).returncode,
|
|
2744
|
-
)
|
|
2745
|
-
|
|
2746
|
-
def test_task_finish_keep_remote_reports_retained_branch(self) -> None:
|
|
2747
|
-
_, repo, remote = self.make_repo()
|
|
2748
|
-
worktree = self.start_task(repo, "KEEP-REMOTE")
|
|
2749
|
-
(worktree / "kept.txt").write_text("kept remotely\n", encoding="utf-8")
|
|
2750
|
-
self.commit_push(worktree, "KEEP-REMOTE", "KEEP-REMOTE: ready")
|
|
2751
|
-
self.ap(repo, "task-integrate", "KEEP-REMOTE", "--keep-worktree")
|
|
2752
|
-
|
|
2753
|
-
finish = self.ap(repo, "task-finish", "KEEP-REMOTE", "--keep-remote")
|
|
2754
|
-
|
|
2755
|
-
self.assertIn("remote_branch_deleted=false", finish.stdout + finish.stderr)
|
|
2756
|
-
self.assertFalse(worktree.exists())
|
|
2757
|
-
self.assert_local_branch(repo, "codex/KEEP-REMOTE", False)
|
|
2758
|
-
self.assert_remote_branch(remote, "codex/KEEP-REMOTE", True)
|
|
2759
|
-
self.assertFalse(self.registry_manifest_path(repo, "KEEP-REMOTE").exists())
|
|
2760
|
-
|
|
2761
|
-
def test_task_deletion_is_isolated_and_committed_only_on_its_task_branch(self) -> None:
|
|
2762
|
-
_, repo, remote = self.make_repo()
|
|
2763
|
-
deleting = self.start_task(repo, "DELETE-1", "shared.txt")
|
|
2764
|
-
observer = self.start_task(repo, "DELETE-2", "observer.txt")
|
|
2765
|
-
(deleting / "shared.txt").unlink()
|
|
2766
|
-
(observer / "observer.txt").write_text("observer\n", encoding="utf-8")
|
|
2767
|
-
|
|
2768
|
-
self.commit_push(deleting, "DELETE-1", "DELETE-1: delete shared file")
|
|
2769
|
-
|
|
2770
|
-
deleted_ref = "refs/heads/codex/DELETE-1"
|
|
2771
|
-
self.assertNotEqual(
|
|
2772
|
-
0,
|
|
2773
|
-
git(remote, "cat-file", "-e", f"{deleted_ref}:shared.txt", check=False).returncode,
|
|
2774
|
-
)
|
|
2775
|
-
self.assertEqual("baseline\n", (repo / "shared.txt").read_text(encoding="utf-8"))
|
|
2776
|
-
self.assertEqual("baseline\n", (observer / "shared.txt").read_text(encoding="utf-8"))
|
|
2777
|
-
self.assertTrue((observer / "observer.txt").exists())
|
|
2778
|
-
|
|
2779
|
-
def test_task_finish_refuses_dirty_or_unmerged_tasks(self) -> None:
|
|
2780
|
-
_, repo, _ = self.make_repo()
|
|
2781
|
-
|
|
2782
|
-
dirty_worktree = self.start_task(repo, "DIRTY-1", "dirty.txt")
|
|
2783
|
-
(dirty_worktree / "dirty.txt").write_text("not committed\n", encoding="utf-8")
|
|
2784
|
-
dirty = self.ap(repo, "task-finish", "DIRTY-1", check=False)
|
|
2785
|
-
self.assertNotEqual(0, dirty.returncode)
|
|
2786
|
-
self.assertTrue(dirty_worktree.exists())
|
|
2787
|
-
self.assert_local_branch(repo, "codex/DIRTY-1", True)
|
|
2788
|
-
self.assertTrue((dirty_worktree / "dirty.txt").exists())
|
|
2789
|
-
|
|
2790
|
-
unmerged_worktree = self.start_task(repo, "UNMERGED-1", "unmerged.txt")
|
|
2791
|
-
(unmerged_worktree / "unmerged.txt").write_text("committed only on task\n", encoding="utf-8")
|
|
2792
|
-
git(unmerged_worktree, "add", "unmerged.txt")
|
|
2793
|
-
git(unmerged_worktree, "commit", "-qm", "unmerged task commit")
|
|
2794
|
-
unmerged = self.ap(repo, "task-finish", "UNMERGED-1", check=False)
|
|
2795
|
-
self.assertNotEqual(0, unmerged.returncode)
|
|
2796
|
-
self.assertTrue(unmerged_worktree.exists())
|
|
2797
|
-
self.assert_local_branch(repo, "codex/UNMERGED-1", True)
|
|
2798
|
-
self.assertEqual("unmerged task commit", git_output(unmerged_worktree, "log", "-1", "--format=%s"))
|
|
2799
|
-
|
|
2800
|
-
def test_task_prune_only_removes_merged_unoccupied_codex_branches(self) -> None:
|
|
2801
|
-
root, repo, _ = self.make_repo()
|
|
2802
|
-
git(repo, "branch", "codex/merged-free", "dev")
|
|
2803
|
-
git(repo, "branch", "feature/merged-free", "dev")
|
|
2804
|
-
|
|
2805
|
-
git(repo, "branch", "codex/unmerged-free", "dev")
|
|
2806
|
-
unmerged_path = root / "unmerged-worktree"
|
|
2807
|
-
git(repo, "worktree", "add", "-q", str(unmerged_path), "codex/unmerged-free")
|
|
2808
|
-
(unmerged_path / "unique.txt").write_text("unique\n", encoding="utf-8")
|
|
2809
|
-
git(unmerged_path, "add", "unique.txt")
|
|
2810
|
-
git(unmerged_path, "commit", "-qm", "unique unmerged commit")
|
|
2811
|
-
git(repo, "worktree", "remove", str(unmerged_path))
|
|
2812
|
-
|
|
2813
|
-
git(repo, "branch", "codex/merged-occupied", "dev")
|
|
2814
|
-
occupied_path = root / "occupied-worktree"
|
|
2815
|
-
git(repo, "worktree", "add", "-q", str(occupied_path), "codex/merged-occupied")
|
|
2816
|
-
|
|
2817
|
-
self.ap(repo, "task-prune")
|
|
2818
|
-
|
|
2819
|
-
self.assert_local_branch(repo, "codex/merged-free", False)
|
|
2820
|
-
self.assert_local_branch(repo, "codex/unmerged-free", True)
|
|
2821
|
-
self.assert_local_branch(repo, "codex/merged-occupied", True)
|
|
2822
|
-
self.assert_local_branch(repo, "feature/merged-free", True)
|
|
2823
|
-
self.assertTrue(occupied_path.exists())
|
|
2824
|
-
|
|
2825
|
-
def test_task_prune_finishes_registered_integrated_worktree(self) -> None:
|
|
2826
|
-
_, repo, remote = self.make_repo()
|
|
2827
|
-
worktree = self.start_task(repo, "PRUNE-REGISTERED")
|
|
2828
|
-
(worktree / "registered.txt").write_text("registered\n", encoding="utf-8")
|
|
2829
|
-
self.commit_push(worktree, "PRUNE-REGISTERED", "PRUNE-REGISTERED: ready")
|
|
2830
|
-
self.ap(
|
|
2831
|
-
repo,
|
|
2832
|
-
"task-integrate",
|
|
2833
|
-
"PRUNE-REGISTERED",
|
|
2834
|
-
"--keep-worktree",
|
|
2835
|
-
)
|
|
2836
|
-
self.assertTrue(worktree.exists())
|
|
2837
|
-
self.assert_local_branch(repo, "codex/PRUNE-REGISTERED", True)
|
|
2838
|
-
|
|
2839
|
-
self.ap(repo, "task-prune")
|
|
2840
|
-
|
|
2841
|
-
self.assertFalse(worktree.exists())
|
|
2842
|
-
self.assert_local_branch(repo, "codex/PRUNE-REGISTERED", False)
|
|
2843
|
-
self.assert_remote_branch(remote, "codex/PRUNE-REGISTERED", False)
|
|
2844
|
-
|
|
2845
|
-
def test_task_prune_removes_orphan_git_local_review_artifacts(self) -> None:
|
|
2846
|
-
_, repo, _ = self.make_repo()
|
|
2847
|
-
worktree = self.start_task(repo, "PRUNE-REVIEW-ORPHAN", "shared.txt")
|
|
2848
|
-
(worktree / "shared.txt").write_text("orphan review\n", encoding="utf-8")
|
|
2849
|
-
issued = json.loads(
|
|
2850
|
-
self.ap(
|
|
2851
|
-
worktree,
|
|
2852
|
-
"review-assignment",
|
|
2853
|
-
"PRUNE-REVIEW-ORPHAN",
|
|
2854
|
-
"--reviewer",
|
|
2855
|
-
"reviewer-orphan",
|
|
2856
|
-
"--json",
|
|
2857
|
-
).stdout
|
|
2858
|
-
)
|
|
2859
|
-
review_dir = Path(issued["assignment_path"]).parent
|
|
2860
|
-
self.assertTrue(review_dir.is_dir())
|
|
2861
|
-
git(repo, "worktree", "unlock", str(worktree))
|
|
2862
|
-
git(repo, "worktree", "remove", "--force", str(worktree))
|
|
2863
|
-
self.registry_manifest_path(repo, "PRUNE-REVIEW-ORPHAN").unlink()
|
|
2864
|
-
|
|
2865
|
-
self.ap(repo, "task-prune")
|
|
2866
|
-
|
|
2867
|
-
self.assertFalse(review_dir.exists())
|
|
2868
|
-
self.assert_local_branch(repo, "codex/PRUNE-REVIEW-ORPHAN", False)
|
|
2869
|
-
|
|
2870
|
-
def test_cleanup_blocks_unknown_ignored_data_but_allows_runtime_evidence(self) -> None:
|
|
2871
|
-
_, repo, remote = self.make_repo()
|
|
2872
|
-
(repo / ".gitignore").write_text(".env\n.local/\n", encoding="utf-8")
|
|
2873
|
-
git(repo, "add", ".gitignore")
|
|
2874
|
-
git(repo, "commit", "-qm", "ignore local runtime files")
|
|
2875
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
2876
|
-
|
|
2877
|
-
worktree = self.start_task(repo, "IGNORED-1")
|
|
2878
|
-
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
2879
|
-
self.commit_push(worktree, "IGNORED-1", "IGNORED-1: ready")
|
|
2880
|
-
self.ap(repo, "task-integrate", "IGNORED-1", "--keep-worktree")
|
|
2881
|
-
|
|
2882
|
-
(worktree / ".env").write_text("must survive\n", encoding="utf-8")
|
|
2883
|
-
blocked = self.ap(repo, "task-finish", "IGNORED-1", check=False)
|
|
2884
|
-
self.assertNotEqual(0, blocked.returncode)
|
|
2885
|
-
self.assertIn(".env", blocked.stdout + blocked.stderr)
|
|
2886
|
-
self.assertTrue(worktree.exists())
|
|
2887
|
-
self.assertEqual("must survive\n", (worktree / ".env").read_text(encoding="utf-8"))
|
|
2888
|
-
|
|
2889
|
-
(worktree / ".env").unlink()
|
|
2890
|
-
runtime_evidence = worktree / ".local" / "auto-coding-skill" / "gate.jsonl"
|
|
2891
|
-
runtime_evidence.parent.mkdir(parents=True, exist_ok=True)
|
|
2892
|
-
runtime_evidence.write_text("runtime evidence\n", encoding="utf-8")
|
|
2893
|
-
self.ap(repo, "task-finish", "IGNORED-1")
|
|
2894
|
-
|
|
2895
|
-
self.assertFalse(worktree.exists())
|
|
2896
|
-
self.assert_local_branch(repo, "codex/IGNORED-1", False)
|
|
2897
|
-
self.assert_remote_branch(remote, "codex/IGNORED-1", False)
|
|
2898
|
-
self.assertFalse(self.registry_manifest_path(repo, "IGNORED-1").exists())
|
|
2899
|
-
|
|
2900
|
-
def test_cleanup_safely_deinitializes_submodules_and_preserves_unknown_data(self) -> None:
|
|
2901
|
-
root, repo, remote = self.make_repo()
|
|
2902
|
-
module = root / "module-source"
|
|
2903
|
-
module.mkdir()
|
|
2904
|
-
git(module, "init", "-q", "-b", "main")
|
|
2905
|
-
git(module, "config", "user.email", "module@example.com")
|
|
2906
|
-
git(module, "config", "user.name", "Module Author")
|
|
2907
|
-
(module / ".gitignore").write_text(".secret\n.local/\n", encoding="utf-8")
|
|
2908
|
-
(module / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
2909
|
-
git(module, "add", "-A")
|
|
2910
|
-
git(module, "commit", "-qm", "module baseline")
|
|
2911
|
-
|
|
2912
|
-
git(
|
|
2913
|
-
repo,
|
|
2914
|
-
"-c",
|
|
2915
|
-
"protocol.file.allow=always",
|
|
2916
|
-
"submodule",
|
|
2917
|
-
"add",
|
|
2918
|
-
"-q",
|
|
2919
|
-
str(module),
|
|
2920
|
-
"vendor/module",
|
|
2921
|
-
)
|
|
2922
|
-
git(repo, "commit", "-qam", "add submodule")
|
|
2923
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
2924
|
-
primary_submodule_status = git_output(
|
|
2925
|
-
repo,
|
|
2926
|
-
"submodule",
|
|
2927
|
-
"status",
|
|
2928
|
-
"--",
|
|
2929
|
-
"vendor/module",
|
|
2930
|
-
)
|
|
2931
|
-
primary_submodule_url = git_output(repo, "config", "--get", "submodule.vendor/module.url")
|
|
2932
|
-
self.assertFalse(primary_submodule_status.startswith("-"))
|
|
2933
|
-
|
|
2934
|
-
worktree = self.start_task(repo, "SUBMODULE-1")
|
|
2935
|
-
git(
|
|
2936
|
-
worktree,
|
|
2937
|
-
"-c",
|
|
2938
|
-
"protocol.file.allow=always",
|
|
2939
|
-
"submodule",
|
|
2940
|
-
"update",
|
|
2941
|
-
"--init",
|
|
2942
|
-
"--recursive",
|
|
2943
|
-
)
|
|
2944
|
-
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
2945
|
-
self.commit_push(worktree, "SUBMODULE-1", "SUBMODULE-1: ready")
|
|
2946
|
-
self.ap(repo, "task-integrate", "SUBMODULE-1", "--keep-worktree")
|
|
2947
|
-
|
|
2948
|
-
task_module = worktree / "vendor" / "module"
|
|
2949
|
-
baseline = git_output(task_module, "rev-parse", "HEAD")
|
|
2950
|
-
|
|
2951
|
-
extra_worktree = root / "submodule-extra-worktree"
|
|
2952
|
-
git(
|
|
2953
|
-
task_module,
|
|
2954
|
-
"worktree",
|
|
2955
|
-
"add",
|
|
2956
|
-
"-q",
|
|
2957
|
-
"-b",
|
|
2958
|
-
"extra-check",
|
|
2959
|
-
str(extra_worktree),
|
|
2960
|
-
baseline,
|
|
2961
|
-
)
|
|
2962
|
-
(extra_worktree / "module.txt").write_text("external dirty data\n", encoding="utf-8")
|
|
2963
|
-
extra_blocked = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
2964
|
-
self.assertNotEqual(0, extra_blocked.returncode)
|
|
2965
|
-
self.assertIn("additional linked worktrees", extra_blocked.stdout + extra_blocked.stderr)
|
|
2966
|
-
self.assertEqual(
|
|
2967
|
-
"external dirty data\n",
|
|
2968
|
-
(extra_worktree / "module.txt").read_text(encoding="utf-8"),
|
|
2969
|
-
)
|
|
2970
|
-
self.assertEqual("M module.txt", git_output(extra_worktree, "status", "--short"))
|
|
2971
|
-
self.assertTrue(worktree.exists())
|
|
2972
|
-
self.assert_local_branch(repo, "codex/SUBMODULE-1", True)
|
|
2973
|
-
|
|
2974
|
-
(extra_worktree / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
2975
|
-
git(task_module, "worktree", "remove", str(extra_worktree))
|
|
2976
|
-
extra_tip = git_output(task_module, "rev-parse", "refs/heads/extra-check")
|
|
2977
|
-
git(task_module, "update-ref", "-d", "refs/heads/extra-check", extra_tip)
|
|
2978
|
-
|
|
2979
|
-
git(task_module, "checkout", "-qb", "hidden")
|
|
2980
|
-
git(task_module, "config", "user.email", "test@example.com")
|
|
2981
|
-
git(task_module, "config", "user.name", "Auto Coding Test")
|
|
2982
|
-
(task_module / "hidden.txt").write_text("local-only history\n", encoding="utf-8")
|
|
2983
|
-
git(task_module, "add", "hidden.txt")
|
|
2984
|
-
git(task_module, "commit", "-qm", "hidden local commit")
|
|
2985
|
-
hidden_commit = git_output(task_module, "rev-parse", "HEAD")
|
|
2986
|
-
git(task_module, "checkout", "-q", "--detach", baseline)
|
|
2987
|
-
self.assertEqual("", git_output(worktree, "status", "--porcelain=v1"))
|
|
2988
|
-
self.assertEqual("", git_output(task_module, "status", "--porcelain=v1"))
|
|
2989
|
-
|
|
2990
|
-
hidden = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
2991
|
-
self.assertNotEqual(0, hidden.returncode)
|
|
2992
|
-
self.assertIn("local refs/reflogs", hidden.stdout + hidden.stderr)
|
|
2993
|
-
self.assertEqual(hidden_commit, git_output(task_module, "rev-parse", "refs/heads/hidden"))
|
|
2994
|
-
self.assertTrue(worktree.exists())
|
|
2995
|
-
self.assert_local_branch(repo, "codex/SUBMODULE-1", True)
|
|
2996
|
-
|
|
2997
|
-
git(task_module, "push", "-q", "origin", "refs/heads/hidden:refs/heads/hidden")
|
|
2998
|
-
git(
|
|
2999
|
-
task_module,
|
|
3000
|
-
"fetch",
|
|
3001
|
-
"-q",
|
|
3002
|
-
"origin",
|
|
3003
|
-
"refs/heads/hidden:refs/remotes/origin/hidden",
|
|
3004
|
-
)
|
|
3005
|
-
|
|
3006
|
-
git(module, "update-ref", "-d", "refs/heads/hidden", hidden_commit)
|
|
3007
|
-
git(module, "reflog", "expire", "--expire=now", "--all")
|
|
3008
|
-
git(module, "gc", "--prune=now")
|
|
3009
|
-
stale = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
3010
|
-
self.assertNotEqual(0, stale.returncode)
|
|
3011
|
-
self.assertIn("local refs/reflogs", stale.stdout + stale.stderr)
|
|
3012
|
-
self.assertEqual(hidden_commit, git_output(task_module, "rev-parse", "refs/heads/hidden"))
|
|
3013
|
-
self.assertTrue(worktree.exists())
|
|
3014
|
-
|
|
3015
|
-
git(task_module, "push", "-q", "origin", "refs/heads/hidden:refs/heads/hidden")
|
|
3016
|
-
git(
|
|
3017
|
-
task_module,
|
|
3018
|
-
"fetch",
|
|
3019
|
-
"-q",
|
|
3020
|
-
"origin",
|
|
3021
|
-
"refs/heads/hidden:refs/remotes/origin/hidden",
|
|
3022
|
-
)
|
|
3023
|
-
|
|
3024
|
-
secret = task_module / ".secret"
|
|
3025
|
-
secret.write_text("must survive\n", encoding="utf-8")
|
|
3026
|
-
blocked = self.ap(repo, "task-finish", "SUBMODULE-1", check=False)
|
|
3027
|
-
self.assertNotEqual(0, blocked.returncode)
|
|
3028
|
-
self.assertIn("vendor/module/.secret", blocked.stdout + blocked.stderr)
|
|
3029
|
-
self.assertEqual("must survive\n", secret.read_text(encoding="utf-8"))
|
|
3030
|
-
self.assertTrue(worktree.exists())
|
|
3031
|
-
self.assert_local_branch(repo, "codex/SUBMODULE-1", True)
|
|
3032
|
-
|
|
3033
|
-
secret.unlink()
|
|
3034
|
-
runtime_evidence = (
|
|
3035
|
-
worktree / "vendor" / "module" / ".local" / "auto-coding-skill" / "gate.jsonl"
|
|
3036
|
-
)
|
|
3037
|
-
runtime_evidence.parent.mkdir(parents=True, exist_ok=True)
|
|
3038
|
-
runtime_evidence.write_text("disposable runtime data\n", encoding="utf-8")
|
|
3039
|
-
self.ap(repo, "task-finish", "SUBMODULE-1")
|
|
3040
|
-
|
|
3041
|
-
self.assertFalse(worktree.exists())
|
|
3042
|
-
self.assert_local_branch(repo, "codex/SUBMODULE-1", False)
|
|
3043
|
-
self.assert_remote_branch(remote, "codex/SUBMODULE-1", False)
|
|
3044
|
-
self.assertFalse(self.registry_manifest_path(repo, "SUBMODULE-1").exists())
|
|
3045
|
-
self.assertEqual("module baseline\n", (module / "module.txt").read_text(encoding="utf-8"))
|
|
3046
|
-
self.assertEqual(
|
|
3047
|
-
primary_submodule_status,
|
|
3048
|
-
git_output(repo, "submodule", "status", "--", "vendor/module"),
|
|
3049
|
-
)
|
|
3050
|
-
self.assertEqual(
|
|
3051
|
-
primary_submodule_url,
|
|
3052
|
-
git_output(repo, "config", "--get", "submodule.vendor/module.url"),
|
|
3053
|
-
)
|
|
3054
|
-
self.assertEqual("", git_output(repo / "vendor" / "module", "status", "--porcelain=v1"))
|
|
3055
|
-
|
|
3056
|
-
git(module, "update-ref", "-d", "refs/heads/hidden", hidden_commit)
|
|
3057
|
-
git(module, "reflog", "expire", "--expire=now", "--all")
|
|
3058
|
-
git(module, "gc", "--prune=now")
|
|
3059
|
-
self.assertNotEqual(
|
|
3060
|
-
0,
|
|
3061
|
-
git(module, "cat-file", "-e", f"{hidden_commit}^{{commit}}", check=False).returncode,
|
|
3062
|
-
)
|
|
3063
|
-
recovery_root = (
|
|
3064
|
-
self.registry_manifest_path(repo, "SUBMODULE-1").parents[1]
|
|
3065
|
-
/ "submodule-recovery"
|
|
3066
|
-
)
|
|
3067
|
-
recovery_repos = sorted((recovery_root / "repos").glob("*.git"))
|
|
3068
|
-
self.assertTrue(recovery_repos)
|
|
3069
|
-
self.assertTrue(
|
|
3070
|
-
any(
|
|
3071
|
-
command(
|
|
3072
|
-
repo,
|
|
3073
|
-
"git",
|
|
3074
|
-
f"--git-dir={candidate}",
|
|
3075
|
-
"cat-file",
|
|
3076
|
-
"-e",
|
|
3077
|
-
f"{hidden_commit}^{{commit}}",
|
|
3078
|
-
check=False,
|
|
3079
|
-
).returncode
|
|
3080
|
-
== 0
|
|
3081
|
-
for candidate in recovery_repos
|
|
3082
|
-
),
|
|
3083
|
-
"durable recovery storage must retain submodule commits after remote deletion",
|
|
3084
|
-
)
|
|
3085
|
-
self.assertTrue(list((recovery_root / "snapshots").rglob("*.json")))
|
|
3086
|
-
|
|
3087
|
-
def test_submodule_urls_are_worktree_local_and_common_changes_are_not_overwritten(self) -> None:
|
|
3088
|
-
root, repo, _ = self.make_repo()
|
|
3089
|
-
module = root / "config-module-source"
|
|
3090
|
-
module.mkdir()
|
|
3091
|
-
git(module, "init", "-q", "-b", "main")
|
|
3092
|
-
git(module, "config", "user.email", "module@example.com")
|
|
3093
|
-
git(module, "config", "user.name", "Module Author")
|
|
3094
|
-
(module / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
3095
|
-
git(module, "add", "module.txt")
|
|
3096
|
-
git(module, "commit", "-qm", "module baseline")
|
|
3097
|
-
module_b = root / "config-module-source-b"
|
|
3098
|
-
git(root, "clone", "-q", str(module), str(module_b))
|
|
3099
|
-
git(
|
|
3100
|
-
repo,
|
|
3101
|
-
"-c",
|
|
3102
|
-
"protocol.file.allow=always",
|
|
3103
|
-
"submodule",
|
|
3104
|
-
"add",
|
|
3105
|
-
"-q",
|
|
3106
|
-
str(module),
|
|
3107
|
-
"vendor/module",
|
|
3108
|
-
)
|
|
3109
|
-
git(repo, "commit", "-qam", "add initially uninitialized submodule")
|
|
3110
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
3111
|
-
git(repo, "submodule", "-q", "deinit", "-f", "--", "vendor/module")
|
|
3112
|
-
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.url", check=False)
|
|
3113
|
-
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.active", check=False)
|
|
3114
|
-
before_status = git_output(repo, "submodule", "status", "--", "vendor/module")
|
|
3115
|
-
self.assertTrue(before_status.startswith("-"))
|
|
3116
|
-
|
|
3117
|
-
worktree = self.start_task(repo, "SUBMODULE-CONFIG")
|
|
3118
|
-
self.assertEqual(
|
|
3119
|
-
str(module),
|
|
3120
|
-
git_output(worktree, "config", "--worktree", "--get", "submodule.vendor/module.url"),
|
|
3121
|
-
)
|
|
3122
|
-
gitmodules = worktree / ".gitmodules"
|
|
3123
|
-
gitmodules.write_text(
|
|
3124
|
-
gitmodules.read_text(encoding="utf-8").replace(str(module), str(module_b)),
|
|
3125
|
-
encoding="utf-8",
|
|
3126
|
-
)
|
|
3127
|
-
git(
|
|
3128
|
-
worktree,
|
|
3129
|
-
"config",
|
|
3130
|
-
"--local",
|
|
3131
|
-
"submodule.vendor/module.url",
|
|
3132
|
-
str(module_b),
|
|
3133
|
-
)
|
|
3134
|
-
git(worktree, "config", "--local", "submodule.vendor/module.active", "true")
|
|
3135
|
-
conflict = self.ap(worktree, "task-submodule-sync", "SUBMODULE-CONFIG", check=False)
|
|
3136
|
-
self.assertNotEqual(0, conflict.returncode)
|
|
3137
|
-
self.assertIn("shared submodule config changed", (conflict.stdout + conflict.stderr).lower())
|
|
3138
|
-
self.assertEqual(
|
|
3139
|
-
str(module_b),
|
|
3140
|
-
git_output(repo, "config", "--local", "--get", "submodule.vendor/module.url"),
|
|
3141
|
-
)
|
|
3142
|
-
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.url")
|
|
3143
|
-
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.active")
|
|
3144
|
-
self.ap(worktree, "task-submodule-sync", "SUBMODULE-CONFIG")
|
|
3145
|
-
self.assertEqual(
|
|
3146
|
-
str(module_b),
|
|
3147
|
-
git_output(worktree, "config", "--worktree", "--get", "submodule.vendor/module.url"),
|
|
3148
|
-
)
|
|
3149
|
-
self.assertNotEqual(
|
|
3150
|
-
0,
|
|
3151
|
-
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
3152
|
-
)
|
|
3153
|
-
|
|
3154
|
-
git(
|
|
3155
|
-
worktree,
|
|
3156
|
-
"-c",
|
|
3157
|
-
"protocol.file.allow=always",
|
|
3158
|
-
"submodule",
|
|
3159
|
-
"update",
|
|
3160
|
-
"--init",
|
|
3161
|
-
"--recursive",
|
|
3162
|
-
)
|
|
3163
|
-
self.assertEqual(
|
|
3164
|
-
str(module_b),
|
|
3165
|
-
git_output(worktree / "vendor" / "module", "remote", "get-url", "origin"),
|
|
3166
|
-
)
|
|
3167
|
-
self.assertNotEqual(
|
|
3168
|
-
0,
|
|
3169
|
-
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
3170
|
-
)
|
|
3171
|
-
self.assertNotEqual(
|
|
3172
|
-
0,
|
|
3173
|
-
git(repo, "config", "--local", "--get", "submodule.vendor/module.active", check=False).returncode,
|
|
3174
|
-
)
|
|
3175
|
-
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
3176
|
-
self.commit_push(worktree, "SUBMODULE-CONFIG", "SUBMODULE-CONFIG: ready")
|
|
3177
|
-
self.ap(repo, "task-integrate", "SUBMODULE-CONFIG")
|
|
3178
|
-
|
|
3179
|
-
self.assertEqual(before_status, git_output(repo, "submodule", "status", "--", "vendor/module"))
|
|
3180
|
-
self.assertNotEqual(
|
|
3181
|
-
0,
|
|
3182
|
-
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
3183
|
-
)
|
|
3184
|
-
|
|
3185
|
-
def test_relative_submodule_url_uses_task_base_instead_of_control_checkout(self) -> None:
|
|
3186
|
-
root, repo, super_remote = self.make_repo()
|
|
3187
|
-
module_source = root / "relative-module-source"
|
|
3188
|
-
module_source.mkdir()
|
|
3189
|
-
git(module_source, "init", "-q", "-b", "main")
|
|
3190
|
-
git(module_source, "config", "user.email", "module@example.com")
|
|
3191
|
-
git(module_source, "config", "user.name", "Module Author")
|
|
3192
|
-
(module_source / "module.txt").write_text("module baseline\n", encoding="utf-8")
|
|
3193
|
-
git(module_source, "add", "module.txt")
|
|
3194
|
-
git(module_source, "commit", "-qm", "module baseline")
|
|
3195
|
-
module_a = root / "module-a.git"
|
|
3196
|
-
module_b = root / "module-b.git"
|
|
3197
|
-
git(root, "clone", "-q", "--bare", str(module_source), str(module_a))
|
|
3198
|
-
git(root, "clone", "-q", "--bare", str(module_source), str(module_b))
|
|
3199
|
-
|
|
3200
|
-
git(
|
|
3201
|
-
repo,
|
|
3202
|
-
"-c",
|
|
3203
|
-
"protocol.file.allow=always",
|
|
3204
|
-
"submodule",
|
|
3205
|
-
"add",
|
|
3206
|
-
"-q",
|
|
3207
|
-
str(module_a),
|
|
3208
|
-
"vendor/module",
|
|
3209
|
-
)
|
|
3210
|
-
gitmodules = repo / ".gitmodules"
|
|
3211
|
-
gitmodules.write_text(
|
|
3212
|
-
gitmodules.read_text(encoding="utf-8").replace(str(module_a), "../module-a.git"),
|
|
3213
|
-
encoding="utf-8",
|
|
3214
|
-
)
|
|
3215
|
-
git(repo, "commit", "-qam", "add relative submodule URL")
|
|
3216
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
3217
|
-
git(repo, "submodule", "-q", "deinit", "-f", "--", "vendor/module")
|
|
3218
|
-
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.url", check=False)
|
|
3219
|
-
git(repo, "config", "--local", "--unset-all", "submodule.vendor/module.active", check=False)
|
|
3220
|
-
|
|
3221
|
-
git(repo, "branch", "alternate", "dev")
|
|
3222
|
-
alternate = root / "alternate-base"
|
|
3223
|
-
git(repo, "worktree", "add", "-q", str(alternate), "alternate")
|
|
3224
|
-
alternate_gitmodules = alternate / ".gitmodules"
|
|
3225
|
-
alternate_gitmodules.write_text(
|
|
3226
|
-
alternate_gitmodules.read_text(encoding="utf-8").replace(
|
|
3227
|
-
"../module-a.git",
|
|
3228
|
-
"../module-b.git",
|
|
3229
|
-
),
|
|
3230
|
-
encoding="utf-8",
|
|
3231
|
-
)
|
|
3232
|
-
git(alternate, "commit", "-qam", "use alternate relative submodule URL")
|
|
3233
|
-
git(alternate, "push", "-q", "origin", "alternate")
|
|
3234
|
-
git(repo, "worktree", "remove", str(alternate))
|
|
3235
|
-
upstream_root = root / "upstream"
|
|
3236
|
-
upstream_root.mkdir()
|
|
3237
|
-
upstream_super = upstream_root / "super.git"
|
|
3238
|
-
git(root, "clone", "-q", "--bare", str(super_remote), str(upstream_super))
|
|
3239
|
-
git(repo, "remote", "add", "upstream", str(upstream_super))
|
|
3240
|
-
|
|
3241
|
-
self.ap(
|
|
3242
|
-
repo,
|
|
3243
|
-
"task-start",
|
|
3244
|
-
"RELATIVE-BASE",
|
|
3245
|
-
"--base",
|
|
3246
|
-
"upstream/alternate",
|
|
3247
|
-
"--target-branch",
|
|
3248
|
-
"alternate",
|
|
3249
|
-
"--remote",
|
|
3250
|
-
"upstream",
|
|
3251
|
-
"--owned-path",
|
|
3252
|
-
".",
|
|
3253
|
-
)
|
|
3254
|
-
worktree = self.task_worktree(repo, "RELATIVE-BASE")
|
|
3255
|
-
self.assertIn("../module-b.git", (worktree / ".gitmodules").read_text(encoding="utf-8"))
|
|
3256
|
-
self.assertEqual(
|
|
3257
|
-
module_b.resolve(),
|
|
3258
|
-
Path(
|
|
3259
|
-
git_output(
|
|
3260
|
-
worktree,
|
|
3261
|
-
"config",
|
|
3262
|
-
"--worktree",
|
|
3263
|
-
"--get",
|
|
3264
|
-
"submodule.vendor/module.url",
|
|
3265
|
-
)
|
|
3266
|
-
).resolve(),
|
|
3267
|
-
)
|
|
3268
|
-
git(
|
|
3269
|
-
worktree,
|
|
3270
|
-
"-c",
|
|
3271
|
-
"protocol.file.allow=always",
|
|
3272
|
-
"submodule",
|
|
3273
|
-
"update",
|
|
3274
|
-
"--init",
|
|
3275
|
-
"--recursive",
|
|
3276
|
-
)
|
|
3277
|
-
self.assertEqual(
|
|
3278
|
-
module_b.resolve(),
|
|
3279
|
-
Path(
|
|
3280
|
-
git_output(worktree / "vendor" / "module", "remote", "get-url", "origin")
|
|
3281
|
-
).resolve(),
|
|
3282
|
-
)
|
|
3283
|
-
self.assertNotEqual(
|
|
3284
|
-
0,
|
|
3285
|
-
git(repo, "config", "--local", "--get", "submodule.vendor/module.url", check=False).returncode,
|
|
3286
|
-
)
|
|
3287
|
-
|
|
3288
|
-
def test_cleanup_blocks_deinitialized_residual_submodule_git_history(self) -> None:
|
|
3289
|
-
root, repo, remote = self.make_repo()
|
|
3290
|
-
for name in ("a", "b"):
|
|
3291
|
-
module = root / f"residual-module-{name}"
|
|
3292
|
-
module.mkdir()
|
|
3293
|
-
git(module, "init", "-q", "-b", "main")
|
|
3294
|
-
git(module, "config", "user.email", f"{name}@example.com")
|
|
3295
|
-
git(module, "config", "user.name", f"Module {name.upper()}")
|
|
3296
|
-
(module / "module.txt").write_text(f"module {name}\n", encoding="utf-8")
|
|
3297
|
-
git(module, "add", "module.txt")
|
|
3298
|
-
git(module, "commit", "-qm", f"module {name} baseline")
|
|
3299
|
-
git(
|
|
3300
|
-
repo,
|
|
3301
|
-
"-c",
|
|
3302
|
-
"protocol.file.allow=always",
|
|
3303
|
-
"submodule",
|
|
3304
|
-
"add",
|
|
3305
|
-
"-q",
|
|
3306
|
-
str(module),
|
|
3307
|
-
f"vendor/{name}",
|
|
3308
|
-
)
|
|
3309
|
-
git(repo, "commit", "-qam", "add residual-state submodules")
|
|
3310
|
-
git(repo, "push", "-q", "origin", "dev")
|
|
3311
|
-
|
|
3312
|
-
worktree = self.start_task(repo, "SUBMODULE-RESIDUAL")
|
|
3313
|
-
git(
|
|
3314
|
-
worktree,
|
|
3315
|
-
"-c",
|
|
3316
|
-
"protocol.file.allow=always",
|
|
3317
|
-
"submodule",
|
|
3318
|
-
"update",
|
|
3319
|
-
"--init",
|
|
3320
|
-
"--recursive",
|
|
3321
|
-
)
|
|
3322
|
-
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
3323
|
-
self.commit_push(worktree, "SUBMODULE-RESIDUAL", "SUBMODULE-RESIDUAL: ready")
|
|
3324
|
-
self.ap(repo, "task-integrate", "SUBMODULE-RESIDUAL", "--keep-worktree")
|
|
3325
|
-
|
|
3326
|
-
module_b = worktree / "vendor" / "b"
|
|
3327
|
-
baseline = git_output(module_b, "rev-parse", "HEAD")
|
|
3328
|
-
git(module_b, "config", "user.email", "test@example.com")
|
|
3329
|
-
git(module_b, "config", "user.name", "Auto Coding Test")
|
|
3330
|
-
git(module_b, "checkout", "-qb", "hidden")
|
|
3331
|
-
(module_b / "hidden.txt").write_text("local-only residual history\n", encoding="utf-8")
|
|
3332
|
-
git(module_b, "add", "hidden.txt")
|
|
3333
|
-
git(module_b, "commit", "-qm", "hidden residual commit")
|
|
3334
|
-
hidden_commit = git_output(module_b, "rev-parse", "HEAD")
|
|
3335
|
-
module_b_git_dir = Path(git_output(module_b, "rev-parse", "--git-dir"))
|
|
3336
|
-
if not module_b_git_dir.is_absolute():
|
|
3337
|
-
module_b_git_dir = (module_b / module_b_git_dir).resolve()
|
|
3338
|
-
git(module_b, "checkout", "-q", "--detach", baseline)
|
|
3339
|
-
git(worktree, "submodule", "-q", "deinit", "-f", "--", "vendor/b")
|
|
3340
|
-
module_b_url = git_output(
|
|
3341
|
-
repo,
|
|
3342
|
-
"config",
|
|
3343
|
-
"--file",
|
|
3344
|
-
str(repo / ".gitmodules"),
|
|
3345
|
-
"--get",
|
|
3346
|
-
"submodule.vendor/b.url",
|
|
3347
|
-
)
|
|
3348
|
-
git(repo, "config", "--local", "submodule.vendor/b.url", module_b_url)
|
|
3349
|
-
git(repo, "config", "--local", "submodule.vendor/b.active", "true")
|
|
3350
|
-
self.assertFalse((worktree / "vendor" / "b" / ".git").exists())
|
|
3351
|
-
self.assertEqual(
|
|
3352
|
-
hidden_commit,
|
|
3353
|
-
command(
|
|
3354
|
-
repo,
|
|
3355
|
-
"git",
|
|
3356
|
-
f"--git-dir={module_b_git_dir}",
|
|
3357
|
-
"rev-parse",
|
|
3358
|
-
"refs/heads/hidden",
|
|
3359
|
-
).stdout.strip(),
|
|
3360
|
-
)
|
|
3361
|
-
|
|
3362
|
-
blocked = self.ap(repo, "task-finish", "SUBMODULE-RESIDUAL", check=False)
|
|
3363
|
-
self.assertNotEqual(0, blocked.returncode)
|
|
3364
|
-
self.assertIn("residual module Git directory", blocked.stdout + blocked.stderr)
|
|
3365
|
-
self.assertTrue(worktree.exists())
|
|
3366
|
-
self.assertTrue(module_b_git_dir.exists())
|
|
3367
|
-
self.assertEqual(
|
|
3368
|
-
hidden_commit,
|
|
3369
|
-
command(
|
|
3370
|
-
repo,
|
|
3371
|
-
"git",
|
|
3372
|
-
f"--git-dir={module_b_git_dir}",
|
|
3373
|
-
"rev-parse",
|
|
3374
|
-
"refs/heads/hidden",
|
|
3375
|
-
).stdout.strip(),
|
|
3376
|
-
)
|
|
3377
|
-
self.assert_local_branch(repo, "codex/SUBMODULE-RESIDUAL", True)
|
|
3378
|
-
self.assert_remote_branch(remote, "codex/SUBMODULE-RESIDUAL", True)
|
|
3379
|
-
self.assertTrue(self.registry_manifest_path(repo, "SUBMODULE-RESIDUAL").exists())
|
|
3380
|
-
self.assertTrue((worktree / "vendor" / "a" / ".git").exists())
|
|
3381
|
-
|
|
3382
|
-
def test_changed_remote_task_branch_stays_cleanup_pending_until_safe_retry(self) -> None:
|
|
3383
|
-
root, repo, remote = self.make_repo()
|
|
3384
|
-
worktree = self.start_task(repo, "REMOTE-RACE")
|
|
3385
|
-
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
3386
|
-
self.commit_push(worktree, "REMOTE-RACE", "REMOTE-RACE: ready")
|
|
3387
|
-
review_dir = Path(
|
|
3388
|
-
json.loads(
|
|
3389
|
-
self.registry_manifest_path(repo, "REMOTE-RACE").read_text(encoding="utf-8")
|
|
3390
|
-
)["review"]["assignment_path"]
|
|
3391
|
-
).parent
|
|
3392
|
-
self.ap(repo, "task-integrate", "REMOTE-RACE", "--keep-worktree")
|
|
3393
|
-
|
|
3394
|
-
attacker = root / "attacker"
|
|
3395
|
-
git(root, "clone", "-q", str(remote), str(attacker))
|
|
3396
|
-
git(attacker, "config", "user.email", "other@example.com")
|
|
3397
|
-
git(attacker, "config", "user.name", "Other Writer")
|
|
3398
|
-
git(attacker, "checkout", "-qb", "remote-race", "origin/codex/REMOTE-RACE")
|
|
3399
|
-
(attacker / "other.txt").write_text("other writer\n", encoding="utf-8")
|
|
3400
|
-
git(attacker, "add", "other.txt")
|
|
3401
|
-
git(attacker, "commit", "-qm", "other writer advances task branch")
|
|
3402
|
-
git(attacker, "push", "-q", "origin", "HEAD:refs/heads/codex/REMOTE-RACE")
|
|
3403
|
-
changed_remote_tip = git_output(remote, "rev-parse", "refs/heads/codex/REMOTE-RACE")
|
|
3404
|
-
|
|
3405
|
-
finish = self.ap(repo, "task-finish", "REMOTE-RACE")
|
|
3406
|
-
self.assertIn("remote_branch_deleted=false", finish.stdout + finish.stderr)
|
|
3407
|
-
self.assertFalse(worktree.exists())
|
|
3408
|
-
self.assert_local_branch(repo, "codex/REMOTE-RACE", False)
|
|
3409
|
-
self.assertEqual(
|
|
3410
|
-
changed_remote_tip,
|
|
3411
|
-
git_output(remote, "rev-parse", "refs/heads/codex/REMOTE-RACE"),
|
|
3412
|
-
)
|
|
3413
|
-
manifest_path = self.registry_manifest_path(repo, "REMOTE-RACE")
|
|
3414
|
-
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
3415
|
-
self.assertEqual("cleanup-pending", manifest["state"])
|
|
3416
|
-
self.assertTrue(review_dir.is_dir())
|
|
3417
|
-
|
|
3418
|
-
prune = self.ap(repo, "task-prune")
|
|
3419
|
-
self.assertIn("remote cleanup pending", prune.stdout + prune.stderr)
|
|
3420
|
-
self.assertTrue(manifest_path.exists())
|
|
3421
|
-
self.assert_remote_branch(remote, "codex/REMOTE-RACE", True)
|
|
3422
|
-
|
|
3423
|
-
git(remote, "update-ref", "-d", "refs/heads/codex/REMOTE-RACE", changed_remote_tip)
|
|
3424
|
-
self.ap(repo, "task-prune")
|
|
3425
|
-
self.assertFalse(manifest_path.exists())
|
|
3426
|
-
self.assertFalse(review_dir.exists())
|
|
3427
|
-
self.assert_remote_branch(remote, "codex/REMOTE-RACE", False)
|
|
3428
|
-
|
|
3429
|
-
def test_gate_mutation_aborts_before_staging_or_commit(self) -> None:
|
|
3430
|
-
_, repo, remote = self.make_repo()
|
|
3431
|
-
self.update_config(
|
|
3432
|
-
repo,
|
|
3433
|
-
lambda config: config["commands"].update(
|
|
3434
|
-
{"gate_changed": "printf gate-change >> shared.txt"}
|
|
3435
|
-
),
|
|
3436
|
-
)
|
|
3437
|
-
worktree = self.start_task(repo, "MUTATE-1")
|
|
3438
|
-
before = git_output(worktree, "rev-parse", "HEAD")
|
|
3439
|
-
(worktree / "task.txt").write_text("task\n", encoding="utf-8")
|
|
3440
|
-
self.approve_task(worktree, "MUTATE-1")
|
|
3441
|
-
|
|
3442
|
-
result = self.ap(
|
|
3443
|
-
worktree,
|
|
3444
|
-
"commit-push",
|
|
3445
|
-
"MUTATE-1",
|
|
3446
|
-
"--msg",
|
|
3447
|
-
"MUTATE-1: must abort",
|
|
3448
|
-
check=False,
|
|
3449
|
-
)
|
|
3450
|
-
|
|
3451
|
-
self.assertNotEqual(0, result.returncode)
|
|
3452
|
-
self.assertIn("gate changed", (result.stdout + result.stderr).lower())
|
|
3453
|
-
self.assertEqual(before, git_output(worktree, "rev-parse", "HEAD"))
|
|
3454
|
-
self.assertEqual("", git_output(worktree, "diff", "--cached", "--name-only"))
|
|
3455
|
-
self.assert_remote_branch(remote, "codex/MUTATE-1", False)
|
|
3456
|
-
|
|
3457
|
-
def test_post_commit_hook_mutation_prevents_push(self) -> None:
|
|
3458
|
-
_, repo, remote = self.make_repo()
|
|
3459
|
-
worktree = self.start_task(repo, "COMMIT-HOOK")
|
|
3460
|
-
self.install_hook(
|
|
3461
|
-
repo,
|
|
3462
|
-
"post-commit",
|
|
3463
|
-
'root="$(git rev-parse --show-toplevel)"\n'
|
|
3464
|
-
'printf "hook mutation\\n" > "$root/hook-after.txt"\n',
|
|
3465
|
-
)
|
|
3466
|
-
before = git_output(worktree, "rev-parse", "HEAD")
|
|
3467
|
-
(worktree / "payload.txt").write_text("payload\n", encoding="utf-8")
|
|
3468
|
-
self.approve_task(worktree, "COMMIT-HOOK")
|
|
3469
|
-
|
|
3470
|
-
result = self.ap(
|
|
3471
|
-
worktree,
|
|
3472
|
-
"commit-push",
|
|
3473
|
-
"COMMIT-HOOK",
|
|
3474
|
-
"--msg",
|
|
3475
|
-
"COMMIT-HOOK: must stay local",
|
|
3476
|
-
check=False,
|
|
3477
|
-
)
|
|
3478
|
-
|
|
3479
|
-
self.assertNotEqual(0, result.returncode)
|
|
3480
|
-
self.assertIn("not pushed", (result.stdout + result.stderr).lower())
|
|
3481
|
-
self.assertNotEqual(before, git_output(worktree, "rev-parse", "HEAD"))
|
|
3482
|
-
self.assertEqual("hook mutation\n", (worktree / "hook-after.txt").read_text(encoding="utf-8"))
|
|
3483
|
-
self.assert_remote_branch(remote, "codex/COMMIT-HOOK", False)
|
|
3484
|
-
|
|
3485
|
-
def test_missing_config_defaults_to_worktree_and_legacy_is_rejected(self) -> None:
|
|
3486
|
-
_, default_repo, _ = self.make_repo(_MISSING)
|
|
3487
|
-
(default_repo / "shared.txt").write_text("must stay isolated\n", encoding="utf-8")
|
|
3488
|
-
default_commit = self.assert_rejected_without_mutation(
|
|
3489
|
-
default_repo,
|
|
3490
|
-
"commit-push",
|
|
3491
|
-
"DEFAULT-1",
|
|
3492
|
-
"--msg",
|
|
3493
|
-
"DEFAULT-1: must start first",
|
|
3494
|
-
)
|
|
3495
|
-
self.assertIn("task-start", (default_commit.stdout + default_commit.stderr).lower())
|
|
3496
|
-
default_repo.joinpath("shared.txt").write_text("baseline\n", encoding="utf-8")
|
|
3497
|
-
self.start_task(default_repo, "DEFAULT-1")
|
|
3498
|
-
|
|
3499
|
-
_, legacy_repo, legacy_remote = self.make_repo("legacy")
|
|
3500
|
-
before = git_output(legacy_repo, "rev-parse", "HEAD")
|
|
3501
|
-
(legacy_repo / "shared.txt").write_text("legacy shared checkout\n", encoding="utf-8")
|
|
3502
|
-
result = self.ap(
|
|
3503
|
-
legacy_repo,
|
|
3504
|
-
"commit-push",
|
|
3505
|
-
"LEGACY-1",
|
|
3506
|
-
"--msg",
|
|
3507
|
-
"LEGACY-1: must be rejected",
|
|
3508
|
-
check=False,
|
|
3509
|
-
)
|
|
3510
|
-
self.assertNotEqual(0, result.returncode)
|
|
3511
|
-
self.assertIn("must be adaptive or worktree", result.stdout + result.stderr)
|
|
3512
|
-
self.assertEqual(before, git_output(legacy_repo, "rev-parse", "HEAD"))
|
|
3513
|
-
self.assertEqual(
|
|
3514
|
-
"baseline",
|
|
3515
|
-
git_output(legacy_remote, "show", "refs/heads/dev:shared.txt"),
|
|
3516
|
-
)
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
if __name__ == "__main__":
|
|
3520
|
-
unittest.main()
|