@elvis1513/auto-coding-skill 3.0.0 → 3.0.2
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 +126 -54
- package/cli/assets/agents/browser-debugger.toml +5 -7
- package/cli/assets/agents/docs-researcher.toml +3 -5
- package/cli/assets/agents/explorer.toml +5 -10
- package/cli/assets/agents/fixer.toml +19 -17
- package/cli/assets/agents/reviewer.toml +14 -10
- package/cli/assets/skill/SKILL.md +116 -49
- package/cli/assets/skill/data/contracts/orchestration-v1.schema.json +475 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +371 -0
- package/cli/assets/skill/data/templates/ENGINEERING.md +170 -81
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +8 -4
- package/cli/assets/skill/data/templates/docs/tasks/closure-log.md +7 -6
- package/cli/assets/skill/data/templates/docs/tasks/taskbook.md +11 -4
- package/cli/assets/skill/scripts/ap.py +1389 -570
- package/cli/src/index.js +749 -51
- package/cli/tests/ap_concurrency_test.py +466 -79
- package/cli/tests/ap_profiles_test.py +339 -98
- package/cli/tests/index.test.js +499 -15
- package/package.json +3 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
4
|
import json
|
|
5
|
+
import os
|
|
5
6
|
import subprocess
|
|
6
7
|
import sys
|
|
7
8
|
import tempfile
|
|
@@ -13,7 +14,7 @@ import yaml
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
16
|
-
AP_SCRIPT = REPO_ROOT / "
|
|
17
|
+
AP_SCRIPT = REPO_ROOT / "src" / "auto-coding-skill" / "scripts" / "ap.py"
|
|
17
18
|
_MISSING = object()
|
|
18
19
|
|
|
19
20
|
|
|
@@ -50,18 +51,32 @@ def git_output(cwd: Path, *args: str) -> str:
|
|
|
50
51
|
|
|
51
52
|
def base_config(isolation: str | object = "worktree") -> dict:
|
|
52
53
|
config = {
|
|
53
|
-
"workflow": {"mode": "dev", "profile": "auto"},
|
|
54
|
+
"workflow": {"mode": "dev", "profile": "auto", "completion": "push"},
|
|
54
55
|
"project": {"name": "concurrency-test"},
|
|
56
|
+
"access": {
|
|
57
|
+
"project": {
|
|
58
|
+
"frontend": {"url": "https://project-front.test", "username": "front", "password": "front-pass"},
|
|
59
|
+
"backend": {"url": "https://project-back.test", "username": "back", "password": "back-pass"},
|
|
60
|
+
},
|
|
61
|
+
"jenkins": {
|
|
62
|
+
"frontend": {"url": "https://jenkins-front.test", "username": "front", "password": "front-pass"},
|
|
63
|
+
"backend": {"url": "https://jenkins-back.test", "username": "back", "password": "back-pass"},
|
|
64
|
+
},
|
|
65
|
+
"gitlab": {"url": "https://gitlab.test", "username": "git", "password": "git-pass"},
|
|
66
|
+
"nexus": {
|
|
67
|
+
"frontend": {"url": "https://nexus.test", "username": "nexus", "password": "nexus-pass"},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
55
70
|
"commands": {
|
|
56
71
|
"gate_changed": "true",
|
|
57
72
|
"gate_standard": "true",
|
|
58
73
|
"gate_full": "true",
|
|
59
74
|
},
|
|
60
75
|
"gate": {
|
|
61
|
-
"default_scope": "
|
|
62
|
-
"fallback_scope": "
|
|
63
|
-
"full_on_unknown":
|
|
64
|
-
"no_change_scope": "
|
|
76
|
+
"default_scope": "changed",
|
|
77
|
+
"fallback_scope": "changed",
|
|
78
|
+
"full_on_unknown": False,
|
|
79
|
+
"no_change_scope": "changed",
|
|
65
80
|
"rules": [],
|
|
66
81
|
},
|
|
67
82
|
"structure": {"enabled": False, "enforcement": "advisory"},
|
|
@@ -148,6 +163,26 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
148
163
|
check=check,
|
|
149
164
|
)
|
|
150
165
|
|
|
166
|
+
def approve_task(self, repo: Path, task_id: str) -> str:
|
|
167
|
+
status = self.ap(repo, "task-status", task_id, "--json")
|
|
168
|
+
fingerprint = json.loads(status.stdout)["tasks"][0]["current_diff_fingerprint"]
|
|
169
|
+
self.ap(
|
|
170
|
+
repo,
|
|
171
|
+
"task-review",
|
|
172
|
+
task_id,
|
|
173
|
+
"--verdict",
|
|
174
|
+
"approved",
|
|
175
|
+
"--diff-fingerprint",
|
|
176
|
+
fingerprint,
|
|
177
|
+
"--reviewer",
|
|
178
|
+
"test-reviewer",
|
|
179
|
+
)
|
|
180
|
+
return fingerprint
|
|
181
|
+
|
|
182
|
+
def commit_push(self, repo: Path, task_id: str, message: str) -> subprocess.CompletedProcess[str]:
|
|
183
|
+
self.approve_task(repo, task_id)
|
|
184
|
+
return self.ap(repo, "commit-push", task_id, "--msg", message)
|
|
185
|
+
|
|
151
186
|
def task_worktree(self, repo: Path, task_id: str) -> Path:
|
|
152
187
|
wanted = f"refs/heads/codex/{task_id}"
|
|
153
188
|
current_path: Path | None = None
|
|
@@ -159,7 +194,15 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
159
194
|
self.fail(f"no worktree registered for {wanted}")
|
|
160
195
|
|
|
161
196
|
def start_task(self, repo: Path, task_id: str) -> Path:
|
|
162
|
-
result = self.ap(
|
|
197
|
+
result = self.ap(
|
|
198
|
+
repo,
|
|
199
|
+
"task-start",
|
|
200
|
+
task_id,
|
|
201
|
+
"--base",
|
|
202
|
+
"origin/dev",
|
|
203
|
+
"--owned-path",
|
|
204
|
+
".",
|
|
205
|
+
)
|
|
163
206
|
worktree = self.task_worktree(repo, task_id)
|
|
164
207
|
self.assertIn(task_id, result.stdout + result.stderr)
|
|
165
208
|
self.assertTrue(worktree.is_dir())
|
|
@@ -199,6 +242,72 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
199
242
|
)
|
|
200
243
|
return result
|
|
201
244
|
|
|
245
|
+
def test_task_start_rejects_unknown_full_gate_policy_before_creating_branch(self) -> None:
|
|
246
|
+
_, repo, _ = self.make_repo()
|
|
247
|
+
(repo / "AGENTS.md").write_text(
|
|
248
|
+
"# Workflow\n- High-risk work\n must run the real full gate before push.\n",
|
|
249
|
+
encoding="utf-8",
|
|
250
|
+
)
|
|
251
|
+
result = self.ap(
|
|
252
|
+
repo,
|
|
253
|
+
"task-start",
|
|
254
|
+
"POLICY-START",
|
|
255
|
+
"--base",
|
|
256
|
+
"origin/dev",
|
|
257
|
+
"--owned-path",
|
|
258
|
+
".",
|
|
259
|
+
check=False,
|
|
260
|
+
)
|
|
261
|
+
self.assertNotEqual(0, result.returncode)
|
|
262
|
+
self.assertIn("AGENTS.md:2", result.stdout + result.stderr)
|
|
263
|
+
self.assert_local_branch(repo, "codex/POLICY-START", False)
|
|
264
|
+
|
|
265
|
+
def test_task_start_rejects_legacy_gate_yaml_before_creating_branch(self) -> None:
|
|
266
|
+
_, repo, _ = self.make_repo()
|
|
267
|
+
engineering = repo / "docs" / "ENGINEERING.md"
|
|
268
|
+
text = engineering.read_text(encoding="utf-8").replace(
|
|
269
|
+
" full_on_unknown: false\n",
|
|
270
|
+
" full_on_unknown: true\n full_on:\n - prod_config\n",
|
|
271
|
+
).replace(
|
|
272
|
+
" rules: []\n",
|
|
273
|
+
" rules:\n - match:\n - Jenkinsfile\n scope: full\n commands:\n - gate_full\n",
|
|
274
|
+
)
|
|
275
|
+
engineering.write_text(text, encoding="utf-8")
|
|
276
|
+
result = self.ap(
|
|
277
|
+
repo,
|
|
278
|
+
"task-start",
|
|
279
|
+
"POLICY-YAML",
|
|
280
|
+
"--base",
|
|
281
|
+
"origin/dev",
|
|
282
|
+
"--owned-path",
|
|
283
|
+
".",
|
|
284
|
+
check=False,
|
|
285
|
+
)
|
|
286
|
+
self.assertNotEqual(0, result.returncode)
|
|
287
|
+
self.assertIn("gate.full_on", result.stdout + result.stderr)
|
|
288
|
+
self.assertIn("gate.rules[0].scope", result.stdout + result.stderr)
|
|
289
|
+
self.assert_local_branch(repo, "codex/POLICY-YAML", False)
|
|
290
|
+
|
|
291
|
+
def test_commit_push_rejects_policy_added_after_task_start(self) -> None:
|
|
292
|
+
_, repo, _ = self.make_repo()
|
|
293
|
+
worktree = self.start_task(repo, "POLICY-PUSH")
|
|
294
|
+
(worktree / "AGENTS.md").write_text(
|
|
295
|
+
"# Workflow\nRuntime changes require the full gate.\n",
|
|
296
|
+
encoding="utf-8",
|
|
297
|
+
)
|
|
298
|
+
self.approve_task(worktree, "POLICY-PUSH")
|
|
299
|
+
result = self.ap(
|
|
300
|
+
worktree,
|
|
301
|
+
"commit-push",
|
|
302
|
+
"POLICY-PUSH",
|
|
303
|
+
"--msg",
|
|
304
|
+
"POLICY-PUSH: blocked",
|
|
305
|
+
check=False,
|
|
306
|
+
)
|
|
307
|
+
self.assertNotEqual(0, result.returncode)
|
|
308
|
+
self.assertIn("AGENTS.md:2", result.stdout + result.stderr)
|
|
309
|
+
self.assertEqual("", git_output(worktree, "diff", "--cached", "--name-only"))
|
|
310
|
+
|
|
202
311
|
def manifest_payloads(self, repo: Path) -> list[dict]:
|
|
203
312
|
common_dir_raw = git_output(repo, "rev-parse", "--git-common-dir")
|
|
204
313
|
common_dir = Path(common_dir_raw)
|
|
@@ -249,6 +358,272 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
249
358
|
),
|
|
250
359
|
"task-start must persist a task manifest in the Git common directory",
|
|
251
360
|
)
|
|
361
|
+
active_task = (worktree / "docs" / "tasks" / "active" / "START-1.md").read_text(
|
|
362
|
+
encoding="utf-8"
|
|
363
|
+
)
|
|
364
|
+
for field in [
|
|
365
|
+
"Worktree:",
|
|
366
|
+
"Orchestrator:",
|
|
367
|
+
"Owning fixer:",
|
|
368
|
+
"Owned paths:",
|
|
369
|
+
"Depends on integrated tasks:",
|
|
370
|
+
"Reviewer / stable diff:",
|
|
371
|
+
"Review verdict:",
|
|
372
|
+
]:
|
|
373
|
+
self.assertIn(field, active_task)
|
|
374
|
+
|
|
375
|
+
def test_schema_one_task_status_fails_closed_with_migration_recovery(self) -> None:
|
|
376
|
+
_, repo, _ = self.make_repo()
|
|
377
|
+
self.start_task(repo, "LEGACY-SCHEMA")
|
|
378
|
+
registry = self.registry_manifest_path(repo, "LEGACY-SCHEMA")
|
|
379
|
+
payload = json.loads(registry.read_text(encoding="utf-8"))
|
|
380
|
+
payload["schema"] = 1
|
|
381
|
+
for field in [
|
|
382
|
+
"owned_paths",
|
|
383
|
+
"depends_on",
|
|
384
|
+
"prerequisite_shas",
|
|
385
|
+
"writer_lease",
|
|
386
|
+
"review",
|
|
387
|
+
]:
|
|
388
|
+
payload.pop(field, None)
|
|
389
|
+
registry.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
390
|
+
|
|
391
|
+
result = self.ap(repo, "task-status", "LEGACY-SCHEMA", check=False)
|
|
392
|
+
rendered = result.stdout + result.stderr
|
|
393
|
+
self.assertNotEqual(0, result.returncode)
|
|
394
|
+
self.assertIn("legacy schema-1 task", rendered)
|
|
395
|
+
self.assertIn("cannot safely infer or claim owned_paths", rendered)
|
|
396
|
+
self.assertIn("previously installed runtime", rendered)
|
|
397
|
+
self.assertIn("restore the 3.0.0 runtime", rendered)
|
|
398
|
+
|
|
399
|
+
def test_owned_paths_are_required_and_unowned_changes_are_rejected(self) -> None:
|
|
400
|
+
_, repo, remote = self.make_repo()
|
|
401
|
+
missing = self.ap(
|
|
402
|
+
repo,
|
|
403
|
+
"task-start",
|
|
404
|
+
"NO-OWNED",
|
|
405
|
+
"--base",
|
|
406
|
+
"origin/dev",
|
|
407
|
+
check=False,
|
|
408
|
+
)
|
|
409
|
+
self.assertNotEqual(0, missing.returncode)
|
|
410
|
+
self.assertIn("owned-path", (missing.stdout + missing.stderr).lower())
|
|
411
|
+
self.assert_remote_branch(remote, "codex/NO-OWNED", False)
|
|
412
|
+
|
|
413
|
+
self.ap(
|
|
414
|
+
repo,
|
|
415
|
+
"task-start",
|
|
416
|
+
"OWNED-ONLY",
|
|
417
|
+
"--base",
|
|
418
|
+
"origin/dev",
|
|
419
|
+
"--owned-path",
|
|
420
|
+
"src/owned",
|
|
421
|
+
)
|
|
422
|
+
worktree = self.task_worktree(repo, "OWNED-ONLY")
|
|
423
|
+
outside = worktree / "src" / "outside.txt"
|
|
424
|
+
outside.parent.mkdir(parents=True)
|
|
425
|
+
outside.write_text("outside\n", encoding="utf-8")
|
|
426
|
+
status = self.ap(worktree, "task-status", "OWNED-ONLY", "--json")
|
|
427
|
+
fingerprint = json.loads(status.stdout)["tasks"][0]["current_diff_fingerprint"]
|
|
428
|
+
review = self.ap(
|
|
429
|
+
worktree,
|
|
430
|
+
"task-review",
|
|
431
|
+
"OWNED-ONLY",
|
|
432
|
+
"--verdict",
|
|
433
|
+
"approved",
|
|
434
|
+
"--diff-fingerprint",
|
|
435
|
+
fingerprint,
|
|
436
|
+
check=False,
|
|
437
|
+
)
|
|
438
|
+
self.assertNotEqual(0, review.returncode)
|
|
439
|
+
self.assertIn("outside task owned_paths", review.stdout + review.stderr)
|
|
440
|
+
|
|
441
|
+
def test_approved_fingerprint_expires_when_owned_diff_changes(self) -> None:
|
|
442
|
+
_, repo, remote = self.make_repo()
|
|
443
|
+
worktree = self.start_task(repo, "STALE-REVIEW")
|
|
444
|
+
payload = worktree / "payload.txt"
|
|
445
|
+
payload.write_text("reviewed\n", encoding="utf-8")
|
|
446
|
+
registry = self.registry_manifest_path(repo, "STALE-REVIEW")
|
|
447
|
+
manifest = json.loads(registry.read_text(encoding="utf-8"))
|
|
448
|
+
owner = manifest["owner"]
|
|
449
|
+
manifest["owner"] = "another-lifecycle-owner"
|
|
450
|
+
registry.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
451
|
+
status = self.ap(worktree, "task-status", "STALE-REVIEW", "--json")
|
|
452
|
+
fingerprint = json.loads(status.stdout)["tasks"][0]["current_diff_fingerprint"]
|
|
453
|
+
non_owner_review = self.ap(
|
|
454
|
+
worktree,
|
|
455
|
+
"task-review",
|
|
456
|
+
"STALE-REVIEW",
|
|
457
|
+
"--verdict",
|
|
458
|
+
"approved",
|
|
459
|
+
"--diff-fingerprint",
|
|
460
|
+
fingerprint,
|
|
461
|
+
check=False,
|
|
462
|
+
)
|
|
463
|
+
self.assertNotEqual(0, non_owner_review.returncode)
|
|
464
|
+
self.assertIn("lifecycle owner", non_owner_review.stdout + non_owner_review.stderr)
|
|
465
|
+
manifest["owner"] = owner
|
|
466
|
+
registry.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
467
|
+
self.approve_task(worktree, "STALE-REVIEW")
|
|
468
|
+
payload.write_text("changed after review\n", encoding="utf-8")
|
|
469
|
+
|
|
470
|
+
result = self.ap(
|
|
471
|
+
worktree,
|
|
472
|
+
"commit-push",
|
|
473
|
+
"STALE-REVIEW",
|
|
474
|
+
"--msg",
|
|
475
|
+
"STALE-REVIEW: must fail",
|
|
476
|
+
check=False,
|
|
477
|
+
)
|
|
478
|
+
self.assertNotEqual(0, result.returncode)
|
|
479
|
+
self.assertIn("fingerprint is stale", result.stdout + result.stderr)
|
|
480
|
+
self.assert_remote_branch(remote, "codex/STALE-REVIEW", False)
|
|
481
|
+
|
|
482
|
+
def test_writer_lease_requires_match_and_owner_handoff_uses_generation_cas(self) -> None:
|
|
483
|
+
_, repo, _ = self.make_repo()
|
|
484
|
+
owner = os.environ["CODEX_THREAD_ID"]
|
|
485
|
+
self.ap(
|
|
486
|
+
repo,
|
|
487
|
+
"task-start",
|
|
488
|
+
"LEASE-1",
|
|
489
|
+
"--base",
|
|
490
|
+
"origin/dev",
|
|
491
|
+
"--owned-path",
|
|
492
|
+
".",
|
|
493
|
+
"--writer",
|
|
494
|
+
"fixer-label",
|
|
495
|
+
)
|
|
496
|
+
worktree = self.task_worktree(repo, "LEASE-1")
|
|
497
|
+
(worktree / "lease.txt").write_text("ready\n", encoding="utf-8")
|
|
498
|
+
self.approve_task(worktree, "LEASE-1")
|
|
499
|
+
|
|
500
|
+
mismatch = self.ap(
|
|
501
|
+
worktree,
|
|
502
|
+
"commit-push",
|
|
503
|
+
"LEASE-1",
|
|
504
|
+
"--msg",
|
|
505
|
+
"LEASE-1: wrong writer",
|
|
506
|
+
check=False,
|
|
507
|
+
)
|
|
508
|
+
self.assertNotEqual(0, mismatch.returncode)
|
|
509
|
+
self.assertIn("writer lease mismatch", (mismatch.stdout + mismatch.stderr).lower())
|
|
510
|
+
|
|
511
|
+
spoofed = self.ap(
|
|
512
|
+
worktree,
|
|
513
|
+
"commit-push",
|
|
514
|
+
"LEASE-1",
|
|
515
|
+
"--msg",
|
|
516
|
+
"LEASE-1: spoofed writer",
|
|
517
|
+
"--writer",
|
|
518
|
+
"fixer-label",
|
|
519
|
+
check=False,
|
|
520
|
+
)
|
|
521
|
+
self.assertNotEqual(0, spoofed.returncode)
|
|
522
|
+
self.assertIn("actor identity cannot be overridden", spoofed.stdout + spoofed.stderr)
|
|
523
|
+
|
|
524
|
+
self.ap(
|
|
525
|
+
repo,
|
|
526
|
+
"task-handoff",
|
|
527
|
+
"LEASE-1",
|
|
528
|
+
"--from",
|
|
529
|
+
"fixer-label",
|
|
530
|
+
"--to",
|
|
531
|
+
owner,
|
|
532
|
+
"--generation",
|
|
533
|
+
"1",
|
|
534
|
+
)
|
|
535
|
+
stale = self.ap(
|
|
536
|
+
repo,
|
|
537
|
+
"task-handoff",
|
|
538
|
+
"LEASE-1",
|
|
539
|
+
"--from",
|
|
540
|
+
owner,
|
|
541
|
+
"--to",
|
|
542
|
+
"next-writer",
|
|
543
|
+
"--generation",
|
|
544
|
+
"1",
|
|
545
|
+
check=False,
|
|
546
|
+
)
|
|
547
|
+
self.assertNotEqual(0, stale.returncode)
|
|
548
|
+
self.assertIn("generation changed", stale.stdout + stale.stderr)
|
|
549
|
+
manifest = json.loads(self.registry_manifest_path(repo, "LEASE-1").read_text(encoding="utf-8"))
|
|
550
|
+
self.assertEqual(owner, manifest["writer_lease"]["holder"])
|
|
551
|
+
self.assertEqual(2, manifest["writer_lease"]["generation"])
|
|
552
|
+
|
|
553
|
+
def test_dependency_sha_must_already_be_in_task_base(self) -> None:
|
|
554
|
+
_, repo, _ = self.make_repo()
|
|
555
|
+
tree = git_output(repo, "rev-parse", "HEAD^{tree}")
|
|
556
|
+
orphan = git_output(repo, "commit-tree", tree, "-m", "unintegrated prerequisite")
|
|
557
|
+
result = self.ap(
|
|
558
|
+
repo,
|
|
559
|
+
"task-start",
|
|
560
|
+
"DEPENDENT-1",
|
|
561
|
+
"--base",
|
|
562
|
+
"origin/dev",
|
|
563
|
+
"--owned-path",
|
|
564
|
+
".",
|
|
565
|
+
"--depends-on",
|
|
566
|
+
f"UPSTREAM-1={orphan}",
|
|
567
|
+
check=False,
|
|
568
|
+
)
|
|
569
|
+
self.assertNotEqual(0, result.returncode)
|
|
570
|
+
self.assertIn("not integrated", result.stdout + result.stderr)
|
|
571
|
+
|
|
572
|
+
def test_target_advance_rebases_then_requires_review_before_integration(self) -> None:
|
|
573
|
+
_, repo, remote = self.make_repo()
|
|
574
|
+
worktree = self.start_task(repo, "REBASE-REVIEW")
|
|
575
|
+
(worktree / "task.txt").write_text("task\n", encoding="utf-8")
|
|
576
|
+
self.commit_push(worktree, "REBASE-REVIEW", "REBASE-REVIEW: ready")
|
|
577
|
+
|
|
578
|
+
(repo / "upstream.txt").write_text("upstream\n", encoding="utf-8")
|
|
579
|
+
git(repo, "add", "upstream.txt")
|
|
580
|
+
git(repo, "commit", "-qm", "advance target")
|
|
581
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
582
|
+
|
|
583
|
+
rebased = self.ap(repo, "task-integrate", "REBASE-REVIEW", check=False)
|
|
584
|
+
self.assertNotEqual(0, rebased.returncode)
|
|
585
|
+
self.assertIn("review again", rebased.stdout + rebased.stderr)
|
|
586
|
+
manifest = json.loads(self.registry_manifest_path(repo, "REBASE-REVIEW").read_text(encoding="utf-8"))
|
|
587
|
+
self.assertEqual("pushed", manifest["state"])
|
|
588
|
+
self.assertEqual("pending", manifest["review"]["verdict"])
|
|
589
|
+
self.assertNotEqual(
|
|
590
|
+
0,
|
|
591
|
+
git(remote, "cat-file", "-e", "refs/heads/dev:task.txt", check=False).returncode,
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
self.approve_task(worktree, "REBASE-REVIEW")
|
|
595
|
+
self.ap(repo, "task-integrate", "REBASE-REVIEW")
|
|
596
|
+
self.assertEqual("task", git_output(remote, "show", "refs/heads/dev:task.txt"))
|
|
597
|
+
|
|
598
|
+
def test_rebase_conflict_can_resume_only_then_requires_fresh_review(self) -> None:
|
|
599
|
+
_, repo, remote = self.make_repo()
|
|
600
|
+
worktree = self.start_task(repo, "RESUME-1")
|
|
601
|
+
(worktree / "shared.txt").write_text("task side\n", encoding="utf-8")
|
|
602
|
+
self.commit_push(worktree, "RESUME-1", "RESUME-1: ready")
|
|
603
|
+
|
|
604
|
+
(repo / "shared.txt").write_text("target side\n", encoding="utf-8")
|
|
605
|
+
git(repo, "add", "shared.txt")
|
|
606
|
+
git(repo, "commit", "-qm", "conflicting target change")
|
|
607
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
608
|
+
|
|
609
|
+
conflict = self.ap(repo, "task-integrate", "RESUME-1", check=False)
|
|
610
|
+
self.assertNotEqual(0, conflict.returncode)
|
|
611
|
+
self.assertIn("rebase conflicted", conflict.stdout + conflict.stderr)
|
|
612
|
+
manifest = json.loads(self.registry_manifest_path(repo, "RESUME-1").read_text(encoding="utf-8"))
|
|
613
|
+
self.assertEqual("conflicted", manifest["state"])
|
|
614
|
+
self.assertEqual("pending", manifest["review"]["verdict"])
|
|
615
|
+
|
|
616
|
+
(worktree / "shared.txt").write_text("resolved\n", encoding="utf-8")
|
|
617
|
+
git(worktree, "add", "shared.txt")
|
|
618
|
+
git(worktree, "-c", "core.editor=true", "rebase", "--continue")
|
|
619
|
+
self.ap(repo, "task-resume", "RESUME-1")
|
|
620
|
+
manifest = json.loads(self.registry_manifest_path(repo, "RESUME-1").read_text(encoding="utf-8"))
|
|
621
|
+
self.assertEqual("pushed", manifest["state"])
|
|
622
|
+
self.assertEqual("pending", manifest["review"]["verdict"])
|
|
623
|
+
|
|
624
|
+
self.approve_task(worktree, "RESUME-1")
|
|
625
|
+
self.ap(repo, "task-integrate", "RESUME-1")
|
|
626
|
+
self.assertEqual("resolved", git_output(remote, "show", "refs/heads/dev:shared.txt"))
|
|
252
627
|
|
|
253
628
|
def test_task_start_rolls_back_checkout_hook_side_effects(self) -> None:
|
|
254
629
|
hook_bodies = {
|
|
@@ -269,7 +644,16 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
269
644
|
self.install_hook(repo, "post-checkout", body)
|
|
270
645
|
task_id = f"HOOK-{label.upper()}"
|
|
271
646
|
|
|
272
|
-
result = self.ap(
|
|
647
|
+
result = self.ap(
|
|
648
|
+
repo,
|
|
649
|
+
"task-start",
|
|
650
|
+
task_id,
|
|
651
|
+
"--base",
|
|
652
|
+
"origin/dev",
|
|
653
|
+
"--owned-path",
|
|
654
|
+
".",
|
|
655
|
+
check=False,
|
|
656
|
+
)
|
|
273
657
|
|
|
274
658
|
self.assertNotEqual(0, result.returncode)
|
|
275
659
|
self.assertIn("hook", (result.stdout + result.stderr).lower())
|
|
@@ -317,8 +701,8 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
317
701
|
}
|
|
318
702
|
self.assertEqual(before, after)
|
|
319
703
|
|
|
320
|
-
def
|
|
321
|
-
_, repo, remote = self.make_repo("
|
|
704
|
+
def test_missing_task_manifest_is_rejected_in_linked_worktree(self) -> None:
|
|
705
|
+
_, repo, remote = self.make_repo("worktree")
|
|
322
706
|
worktree = self.start_task(repo, "NO-MANIFEST")
|
|
323
707
|
git_dir = Path(git_output(worktree, "rev-parse", "--git-dir"))
|
|
324
708
|
if not git_dir.is_absolute():
|
|
@@ -398,6 +782,8 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
398
782
|
second_status = git(second_worktree, "status", "--short").stdout
|
|
399
783
|
self.assertIn("?? docs/tasks/active/", second_status)
|
|
400
784
|
self.assertIn("?? second-task-only.txt", second_status)
|
|
785
|
+
self.approve_task(worktree, "ISOLATED-1")
|
|
786
|
+
self.approve_task(second_worktree, "ISOLATED-2")
|
|
401
787
|
with ThreadPoolExecutor(max_workers=2) as pool:
|
|
402
788
|
first_commit = pool.submit(
|
|
403
789
|
self.ap,
|
|
@@ -448,15 +834,32 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
448
834
|
)
|
|
449
835
|
|
|
450
836
|
def test_task_integrate_from_primary_pushes_target_and_cleans_task_refs(self) -> None:
|
|
451
|
-
|
|
837
|
+
root, repo, remote = self.make_repo()
|
|
838
|
+
gate_marker = root / "gate-invocations"
|
|
839
|
+
commit_hook_marker = root / "commit-hook-invocations"
|
|
840
|
+
push_hook_marker = root / "push-hook-invocations"
|
|
841
|
+
engineering = repo / "docs" / "ENGINEERING.md"
|
|
842
|
+
original = engineering.read_text(encoding="utf-8")
|
|
843
|
+
configured = original.replace(
|
|
844
|
+
"gate_changed: 'true'",
|
|
845
|
+
f"gate_changed: 'printf x >> {gate_marker}'",
|
|
846
|
+
)
|
|
847
|
+
self.assertNotEqual(original, configured)
|
|
848
|
+
engineering.write_text(configured, encoding="utf-8")
|
|
849
|
+
git(repo, "add", "docs/ENGINEERING.md")
|
|
850
|
+
git(repo, "commit", "-qm", "configure observable fast gate")
|
|
851
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
852
|
+
self.install_hook(repo, "pre-commit", f"printf c >> '{commit_hook_marker}'\n")
|
|
853
|
+
self.install_hook(repo, "pre-push", f"printf p >> '{push_hook_marker}'\n")
|
|
854
|
+
|
|
452
855
|
worktree = self.start_task(repo, "INTEGRATE-1")
|
|
453
856
|
(worktree / "integrated.txt").write_text("integrated\n", encoding="utf-8")
|
|
454
|
-
self.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
"
|
|
857
|
+
self.commit_push(worktree, "INTEGRATE-1", "INTEGRATE-1: ready")
|
|
858
|
+
task_commit = git_output(worktree, "rev-parse", "HEAD")
|
|
859
|
+
self.assertEqual("c", commit_hook_marker.read_text(encoding="utf-8"))
|
|
860
|
+
self.assertFalse(
|
|
861
|
+
push_hook_marker.exists(),
|
|
862
|
+
"the internal backup push must not duplicate the final pre-push hook",
|
|
460
863
|
)
|
|
461
864
|
|
|
462
865
|
rejected = self.ap(worktree, "task-integrate", "INTEGRATE-1", check=False)
|
|
@@ -475,18 +878,36 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
475
878
|
self.assertFalse(worktree.exists())
|
|
476
879
|
self.assert_local_branch(repo, "codex/INTEGRATE-1", False)
|
|
477
880
|
self.assert_remote_branch(remote, "codex/INTEGRATE-1", False)
|
|
881
|
+
self.assertEqual("x", gate_marker.read_text(encoding="utf-8"), "push flow must run the fast gate exactly once")
|
|
882
|
+
self.assertEqual("c", commit_hook_marker.read_text(encoding="utf-8"), "push flow must create exactly one hook-visible commit")
|
|
883
|
+
self.assertEqual("p", push_hook_marker.read_text(encoding="utf-8"), "the final target push hook must run exactly once")
|
|
884
|
+
self.assertEqual(task_commit, git_output(remote, "rev-parse", "refs/heads/dev"), "integration must not create a second evidence commit")
|
|
885
|
+
|
|
886
|
+
def test_task_integrate_rejects_legacy_gate_failed_state(self) -> None:
|
|
887
|
+
_, repo, remote = self.make_repo()
|
|
888
|
+
worktree = self.start_task(repo, "FAILED-GATE")
|
|
889
|
+
(worktree / "must-not-integrate.txt").write_text("blocked\n", encoding="utf-8")
|
|
890
|
+
self.commit_push(worktree, "FAILED-GATE", "FAILED-GATE: staged task")
|
|
891
|
+
registry = self.registry_manifest_path(repo, "FAILED-GATE")
|
|
892
|
+
payload = json.loads(registry.read_text(encoding="utf-8"))
|
|
893
|
+
payload["state"] = "gate-failed"
|
|
894
|
+
registry.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
895
|
+
|
|
896
|
+
result = self.ap(repo, "task-integrate", "FAILED-GATE", check=False)
|
|
897
|
+
|
|
898
|
+
self.assertNotEqual(0, result.returncode)
|
|
899
|
+
self.assertIn("committed and pushed", (result.stdout + result.stderr).lower())
|
|
900
|
+
self.assertTrue(worktree.exists())
|
|
901
|
+
self.assertNotEqual(
|
|
902
|
+
0,
|
|
903
|
+
git(remote, "cat-file", "-e", "refs/heads/dev:must-not-integrate.txt", check=False).returncode,
|
|
904
|
+
)
|
|
478
905
|
|
|
479
906
|
def test_task_finish_keep_remote_reports_retained_branch(self) -> None:
|
|
480
907
|
_, repo, remote = self.make_repo()
|
|
481
908
|
worktree = self.start_task(repo, "KEEP-REMOTE")
|
|
482
909
|
(worktree / "kept.txt").write_text("kept remotely\n", encoding="utf-8")
|
|
483
|
-
self.
|
|
484
|
-
worktree,
|
|
485
|
-
"commit-push",
|
|
486
|
-
"KEEP-REMOTE",
|
|
487
|
-
"--msg",
|
|
488
|
-
"KEEP-REMOTE: ready",
|
|
489
|
-
)
|
|
910
|
+
self.commit_push(worktree, "KEEP-REMOTE", "KEEP-REMOTE: ready")
|
|
490
911
|
self.ap(repo, "task-integrate", "KEEP-REMOTE", "--keep-worktree")
|
|
491
912
|
|
|
492
913
|
finish = self.ap(repo, "task-finish", "KEEP-REMOTE", "--keep-remote")
|
|
@@ -504,13 +925,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
504
925
|
(deleting / "shared.txt").unlink()
|
|
505
926
|
(observer / "observer.txt").write_text("observer\n", encoding="utf-8")
|
|
506
927
|
|
|
507
|
-
self.
|
|
508
|
-
deleting,
|
|
509
|
-
"commit-push",
|
|
510
|
-
"DELETE-1",
|
|
511
|
-
"--msg",
|
|
512
|
-
"DELETE-1: delete shared file",
|
|
513
|
-
)
|
|
928
|
+
self.commit_push(deleting, "DELETE-1", "DELETE-1: delete shared file")
|
|
514
929
|
|
|
515
930
|
deleted_ref = "refs/heads/codex/DELETE-1"
|
|
516
931
|
self.assertNotEqual(
|
|
@@ -571,13 +986,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
571
986
|
_, repo, remote = self.make_repo()
|
|
572
987
|
worktree = self.start_task(repo, "PRUNE-REGISTERED")
|
|
573
988
|
(worktree / "registered.txt").write_text("registered\n", encoding="utf-8")
|
|
574
|
-
self.
|
|
575
|
-
worktree,
|
|
576
|
-
"commit-push",
|
|
577
|
-
"PRUNE-REGISTERED",
|
|
578
|
-
"--msg",
|
|
579
|
-
"PRUNE-REGISTERED: ready",
|
|
580
|
-
)
|
|
989
|
+
self.commit_push(worktree, "PRUNE-REGISTERED", "PRUNE-REGISTERED: ready")
|
|
581
990
|
self.ap(
|
|
582
991
|
repo,
|
|
583
992
|
"task-integrate",
|
|
@@ -602,13 +1011,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
602
1011
|
|
|
603
1012
|
worktree = self.start_task(repo, "IGNORED-1")
|
|
604
1013
|
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
605
|
-
self.
|
|
606
|
-
worktree,
|
|
607
|
-
"commit-push",
|
|
608
|
-
"IGNORED-1",
|
|
609
|
-
"--msg",
|
|
610
|
-
"IGNORED-1: ready",
|
|
611
|
-
)
|
|
1014
|
+
self.commit_push(worktree, "IGNORED-1", "IGNORED-1: ready")
|
|
612
1015
|
self.ap(repo, "task-integrate", "IGNORED-1", "--keep-worktree")
|
|
613
1016
|
|
|
614
1017
|
(worktree / ".env").write_text("must survive\n", encoding="utf-8")
|
|
@@ -674,13 +1077,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
674
1077
|
"--recursive",
|
|
675
1078
|
)
|
|
676
1079
|
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
677
|
-
self.
|
|
678
|
-
worktree,
|
|
679
|
-
"commit-push",
|
|
680
|
-
"SUBMODULE-1",
|
|
681
|
-
"--msg",
|
|
682
|
-
"SUBMODULE-1: ready",
|
|
683
|
-
)
|
|
1080
|
+
self.commit_push(worktree, "SUBMODULE-1", "SUBMODULE-1: ready")
|
|
684
1081
|
self.ap(repo, "task-integrate", "SUBMODULE-1", "--keep-worktree")
|
|
685
1082
|
|
|
686
1083
|
task_module = worktree / "vendor" / "module"
|
|
@@ -909,13 +1306,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
909
1306
|
git(repo, "config", "--local", "--get", "submodule.vendor/module.active", check=False).returncode,
|
|
910
1307
|
)
|
|
911
1308
|
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
912
|
-
self.
|
|
913
|
-
worktree,
|
|
914
|
-
"commit-push",
|
|
915
|
-
"SUBMODULE-CONFIG",
|
|
916
|
-
"--msg",
|
|
917
|
-
"SUBMODULE-CONFIG: ready",
|
|
918
|
-
)
|
|
1309
|
+
self.commit_push(worktree, "SUBMODULE-CONFIG", "SUBMODULE-CONFIG: ready")
|
|
919
1310
|
self.ap(repo, "task-integrate", "SUBMODULE-CONFIG")
|
|
920
1311
|
|
|
921
1312
|
self.assertEqual(before_status, git_output(repo, "submodule", "status", "--", "vendor/module"))
|
|
@@ -990,6 +1381,8 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
990
1381
|
"alternate",
|
|
991
1382
|
"--remote",
|
|
992
1383
|
"upstream",
|
|
1384
|
+
"--owned-path",
|
|
1385
|
+
".",
|
|
993
1386
|
)
|
|
994
1387
|
worktree = self.task_worktree(repo, "RELATIVE-BASE")
|
|
995
1388
|
self.assertIn("../module-b.git", (worktree / ".gitmodules").read_text(encoding="utf-8"))
|
|
@@ -1060,13 +1453,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1060
1453
|
"--recursive",
|
|
1061
1454
|
)
|
|
1062
1455
|
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
1063
|
-
self.
|
|
1064
|
-
worktree,
|
|
1065
|
-
"commit-push",
|
|
1066
|
-
"SUBMODULE-RESIDUAL",
|
|
1067
|
-
"--msg",
|
|
1068
|
-
"SUBMODULE-RESIDUAL: ready",
|
|
1069
|
-
)
|
|
1456
|
+
self.commit_push(worktree, "SUBMODULE-RESIDUAL", "SUBMODULE-RESIDUAL: ready")
|
|
1070
1457
|
self.ap(repo, "task-integrate", "SUBMODULE-RESIDUAL", "--keep-worktree")
|
|
1071
1458
|
|
|
1072
1459
|
module_b = worktree / "vendor" / "b"
|
|
@@ -1127,13 +1514,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1127
1514
|
root, repo, remote = self.make_repo()
|
|
1128
1515
|
worktree = self.start_task(repo, "REMOTE-RACE")
|
|
1129
1516
|
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
1130
|
-
self.
|
|
1131
|
-
worktree,
|
|
1132
|
-
"commit-push",
|
|
1133
|
-
"REMOTE-RACE",
|
|
1134
|
-
"--msg",
|
|
1135
|
-
"REMOTE-RACE: ready",
|
|
1136
|
-
)
|
|
1517
|
+
self.commit_push(worktree, "REMOTE-RACE", "REMOTE-RACE: ready")
|
|
1137
1518
|
self.ap(repo, "task-integrate", "REMOTE-RACE", "--keep-worktree")
|
|
1138
1519
|
|
|
1139
1520
|
attacker = root / "attacker"
|
|
@@ -1174,13 +1555,13 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1174
1555
|
worktree = self.start_task(repo, "MUTATE-1")
|
|
1175
1556
|
engineering = worktree / "docs" / "ENGINEERING.md"
|
|
1176
1557
|
text = engineering.read_text(encoding="utf-8")
|
|
1177
|
-
text = text.replace("
|
|
1178
|
-
text = text.replace("gate_full: 'true'", "gate_full: 'printf gate-change >> shared.txt'")
|
|
1558
|
+
text = text.replace("gate_changed: 'true'", "gate_changed: 'printf gate-change >> shared.txt'")
|
|
1179
1559
|
engineering.write_text(text, encoding="utf-8")
|
|
1180
1560
|
git(worktree, "add", "docs/ENGINEERING.md")
|
|
1181
1561
|
git(worktree, "commit", "-qm", "configure mutating gate")
|
|
1182
1562
|
before = git_output(worktree, "rev-parse", "HEAD")
|
|
1183
1563
|
(worktree / "task.txt").write_text("task\n", encoding="utf-8")
|
|
1564
|
+
self.approve_task(worktree, "MUTATE-1")
|
|
1184
1565
|
|
|
1185
1566
|
result = self.ap(
|
|
1186
1567
|
worktree,
|
|
@@ -1208,6 +1589,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1208
1589
|
)
|
|
1209
1590
|
before = git_output(worktree, "rev-parse", "HEAD")
|
|
1210
1591
|
(worktree / "payload.txt").write_text("payload\n", encoding="utf-8")
|
|
1592
|
+
self.approve_task(worktree, "COMMIT-HOOK")
|
|
1211
1593
|
|
|
1212
1594
|
result = self.ap(
|
|
1213
1595
|
worktree,
|
|
@@ -1224,7 +1606,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1224
1606
|
self.assertEqual("hook mutation\n", (worktree / "hook-after.txt").read_text(encoding="utf-8"))
|
|
1225
1607
|
self.assert_remote_branch(remote, "codex/COMMIT-HOOK", False)
|
|
1226
1608
|
|
|
1227
|
-
def
|
|
1609
|
+
def test_missing_config_defaults_to_worktree_and_legacy_is_rejected(self) -> None:
|
|
1228
1610
|
_, default_repo, _ = self.make_repo(_MISSING)
|
|
1229
1611
|
(default_repo / "shared.txt").write_text("must stay isolated\n", encoding="utf-8")
|
|
1230
1612
|
default_commit = self.assert_rejected_without_mutation(
|
|
@@ -1239,16 +1621,21 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1239
1621
|
self.start_task(default_repo, "DEFAULT-1")
|
|
1240
1622
|
|
|
1241
1623
|
_, legacy_repo, legacy_remote = self.make_repo("legacy")
|
|
1624
|
+
before = git_output(legacy_repo, "rev-parse", "HEAD")
|
|
1242
1625
|
(legacy_repo / "shared.txt").write_text("legacy shared checkout\n", encoding="utf-8")
|
|
1243
|
-
self.ap(
|
|
1626
|
+
result = self.ap(
|
|
1244
1627
|
legacy_repo,
|
|
1245
1628
|
"commit-push",
|
|
1246
1629
|
"LEGACY-1",
|
|
1247
1630
|
"--msg",
|
|
1248
|
-
"LEGACY-1:
|
|
1631
|
+
"LEGACY-1: must be rejected",
|
|
1632
|
+
check=False,
|
|
1249
1633
|
)
|
|
1634
|
+
self.assertNotEqual(0, result.returncode)
|
|
1635
|
+
self.assertIn("must be worktree", result.stdout + result.stderr)
|
|
1636
|
+
self.assertEqual(before, git_output(legacy_repo, "rev-parse", "HEAD"))
|
|
1250
1637
|
self.assertEqual(
|
|
1251
|
-
"
|
|
1638
|
+
"baseline",
|
|
1252
1639
|
git_output(legacy_remote, "show", "refs/heads/dev:shared.txt"),
|
|
1253
1640
|
)
|
|
1254
1641
|
|