@elvis1513/auto-coding-skill 4.2.6 → 4.2.7
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 +33 -4
- package/cli/assets/agents/reviewer.toml +4 -4
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +4 -4
- package/cli/assets/skill/data/contracts/orchestration-v1.schema.json +17 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +2 -2
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +4 -4
- package/cli/assets/skill/scripts/ap.py +829 -58
- package/cli/tests/ap_concurrency_test.py +315 -17
- package/cli/tests/ap_profiles_test.py +58 -0
- package/cli/tests/index.test.js +21 -20
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
import hashlib
|
|
4
5
|
import json
|
|
5
6
|
import os
|
|
6
7
|
import subprocess
|
|
@@ -214,6 +215,41 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
214
215
|
self.approve_task(repo, task_id)
|
|
215
216
|
return self.ap(repo, "commit-push", task_id, "--msg", message)
|
|
216
217
|
|
|
218
|
+
def artifact_reviewer_runner(self, root: Path, *tokens: str) -> str:
|
|
219
|
+
fake_reviewer = root / "fake-artifact-reviewer.py"
|
|
220
|
+
fake_reviewer.write_text(
|
|
221
|
+
"import hashlib, json, os, pathlib, subprocess, sys\n"
|
|
222
|
+
"if os.environ.get('CODEX_THREAD_ID'):\n"
|
|
223
|
+
" raise SystemExit(9)\n"
|
|
224
|
+
"assignment_path = pathlib.Path(os.environ['AUTOCODING_REVIEW_ASSIGNMENT'])\n"
|
|
225
|
+
"assignment_bytes = assignment_path.read_bytes()\n"
|
|
226
|
+
"if hashlib.sha256(assignment_bytes).hexdigest() != os.environ['AUTOCODING_REVIEW_ASSIGNMENT_SHA256']:\n"
|
|
227
|
+
" raise SystemExit(10)\n"
|
|
228
|
+
"assignment = json.loads(assignment_bytes)\n"
|
|
229
|
+
"artifact_path = pathlib.Path(assignment['diff_artifact_path'])\n"
|
|
230
|
+
"emitted = subprocess.run([sys.executable, sys.argv[1], '--repo', str(pathlib.Path.cwd()), "
|
|
231
|
+
"'review-artifact', '--file', str(assignment_path)], capture_output=True, check=False)\n"
|
|
232
|
+
"if emitted.returncode != 0:\n"
|
|
233
|
+
" raise SystemExit(11)\n"
|
|
234
|
+
"payload = emitted.stdout\n"
|
|
235
|
+
"actual = hashlib.sha256(payload).hexdigest()\n"
|
|
236
|
+
"if actual != assignment['diff_artifact_sha256']:\n"
|
|
237
|
+
" raise SystemExit(12)\n"
|
|
238
|
+
"if os.environ.get('AUTOCODING_REVIEW_DIFF_ARTIFACT') != str(artifact_path):\n"
|
|
239
|
+
" raise SystemExit(13)\n"
|
|
240
|
+
"if os.environ.get('AUTOCODING_REVIEW_DIFF_ARTIFACT_SHA256') != actual:\n"
|
|
241
|
+
" raise SystemExit(14)\n"
|
|
242
|
+
"if int(os.environ['AUTOCODING_REVIEW_TIMEOUT_SECONDS']) not in (90, 300):\n"
|
|
243
|
+
" raise SystemExit(15)\n"
|
|
244
|
+
"for token in sys.argv[2:]:\n"
|
|
245
|
+
" if token.encode('utf-8') not in payload:\n"
|
|
246
|
+
" raise SystemExit(16)\n"
|
|
247
|
+
"print(json.dumps({'verdict': 'approved', 'summary': 'artifact reviewed', "
|
|
248
|
+
"'evidence': ['diff_artifact_sha256=' + actual]}))\n",
|
|
249
|
+
encoding="utf-8",
|
|
250
|
+
)
|
|
251
|
+
return json.dumps([sys.executable, str(fake_reviewer), str(AP_SCRIPT), *tokens])
|
|
252
|
+
|
|
217
253
|
def task_worktree(self, repo: Path, task_id: str) -> Path:
|
|
218
254
|
wanted = f"refs/heads/codex/{task_id}"
|
|
219
255
|
current_path: Path | None = None
|
|
@@ -779,7 +815,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
779
815
|
self.assertNotIn("initialization is incomplete", output)
|
|
780
816
|
|
|
781
817
|
def test_continue_direct_can_adopt_owned_changes_for_new_review_lifecycle(self) -> None:
|
|
782
|
-
|
|
818
|
+
root, repo, remote = self.make_repo("adaptive", require_review=False)
|
|
783
819
|
claim = self.claim_direct(repo, "shared.txt")
|
|
784
820
|
(repo / "shared.txt").write_text("continued direct\n", encoding="utf-8")
|
|
785
821
|
started = self.ap(
|
|
@@ -810,9 +846,35 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
810
846
|
)
|
|
811
847
|
self.assertNotEqual(0, missing_reviewer.returncode)
|
|
812
848
|
self.assertIn("explicit --reviewer", missing_reviewer.stdout + missing_reviewer.stderr)
|
|
813
|
-
|
|
849
|
+
runner = self.artifact_reviewer_runner(root, "continued direct")
|
|
850
|
+
reviewed = json.loads(
|
|
851
|
+
self.ap(
|
|
852
|
+
repo,
|
|
853
|
+
"review-run",
|
|
854
|
+
"DIRECT-CONTINUE",
|
|
855
|
+
"--reviewer",
|
|
856
|
+
"direct-reviewer",
|
|
857
|
+
"--runner-command-json",
|
|
858
|
+
runner,
|
|
859
|
+
"--json",
|
|
860
|
+
).stdout
|
|
861
|
+
)
|
|
862
|
+
self.assertEqual("approved", reviewed["verdict"])
|
|
863
|
+
assignment_path = Path(
|
|
864
|
+
json.loads(
|
|
865
|
+
self.registry_manifest_path(repo, "DIRECT-CONTINUE").read_text(encoding="utf-8")
|
|
866
|
+
)["review"]["assignment_path"]
|
|
867
|
+
)
|
|
868
|
+
pushed = self.ap(
|
|
869
|
+
repo,
|
|
870
|
+
"commit-push",
|
|
871
|
+
"DIRECT-CONTINUE",
|
|
872
|
+
"--msg",
|
|
873
|
+
"DIRECT-CONTINUE: update",
|
|
874
|
+
)
|
|
814
875
|
self.assertIn("execution_mode=direct", pushed.stdout)
|
|
815
876
|
self.assertEqual("continued direct", git_output(remote, "show", "refs/heads/dev:shared.txt"))
|
|
877
|
+
self.assertFalse(assignment_path.parent.exists())
|
|
816
878
|
|
|
817
879
|
claim = self.claim_direct(repo, "shared.txt")
|
|
818
880
|
(repo / "shared.txt").write_text("owned again\n", encoding="utf-8")
|
|
@@ -901,28 +963,219 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
901
963
|
self.assertEqual(90, assignment["timeout_seconds"])
|
|
902
964
|
self.assertEqual(1, assignment["scope_revision"])
|
|
903
965
|
self.assertTrue(Path(first["assignment_path"]).is_file())
|
|
966
|
+
assignment_path = Path(first["assignment_path"])
|
|
967
|
+
artifact_path = Path(assignment["diff_artifact_path"])
|
|
968
|
+
artifact = artifact_path.read_bytes()
|
|
969
|
+
self.assertEqual(assignment_path.parent, artifact_path.parent)
|
|
970
|
+
self.assertEqual(0o600, assignment_path.stat().st_mode & 0o777)
|
|
971
|
+
self.assertEqual(0o600, artifact_path.stat().st_mode & 0o777)
|
|
972
|
+
self.assertEqual(hashlib.sha256(artifact).hexdigest(), assignment["diff_artifact_sha256"])
|
|
973
|
+
self.assertEqual("git-binary-patch-v1", assignment["diff_artifact_format"])
|
|
974
|
+
self.assertIn(b"review me", artifact)
|
|
975
|
+
emitted = self.ap(
|
|
976
|
+
worktree,
|
|
977
|
+
"review-artifact",
|
|
978
|
+
"--file",
|
|
979
|
+
str(assignment_path),
|
|
980
|
+
)
|
|
981
|
+
self.assertEqual(artifact, emitted.stdout.encode("utf-8"))
|
|
904
982
|
issued = datetime.fromisoformat(assignment["issued_at"])
|
|
905
983
|
deadline = datetime.fromisoformat(assignment["deadline_at"])
|
|
906
984
|
self.assertEqual(90, int((deadline - issued).total_seconds()))
|
|
907
985
|
|
|
986
|
+
artifact_path.write_bytes(artifact + b"tampered\n")
|
|
987
|
+
tampered = self.ap(
|
|
988
|
+
worktree,
|
|
989
|
+
"review-assignment",
|
|
990
|
+
"REVIEW-DEADLINE",
|
|
991
|
+
"--reviewer",
|
|
992
|
+
"reviewer-1",
|
|
993
|
+
check=False,
|
|
994
|
+
)
|
|
995
|
+
self.assertNotEqual(0, tampered.returncode)
|
|
996
|
+
self.assertIn("SHA-256 mismatch", tampered.stdout + tampered.stderr)
|
|
997
|
+
|
|
998
|
+
def test_review_assignment_hash_binding_rejects_assignment_file_tampering(self) -> None:
|
|
999
|
+
_, repo, _ = self.make_repo()
|
|
1000
|
+
worktree = self.start_task(repo, "REVIEW-ASSIGNMENT-HASH", "shared.txt")
|
|
1001
|
+
(worktree / "shared.txt").write_text("hash-bound review\n", encoding="utf-8")
|
|
1002
|
+
issued = json.loads(
|
|
1003
|
+
self.ap(
|
|
1004
|
+
worktree,
|
|
1005
|
+
"review-assignment",
|
|
1006
|
+
"REVIEW-ASSIGNMENT-HASH",
|
|
1007
|
+
"--reviewer",
|
|
1008
|
+
"reviewer-hash",
|
|
1009
|
+
"--json",
|
|
1010
|
+
).stdout
|
|
1011
|
+
)
|
|
1012
|
+
assignment_path = Path(issued["assignment_path"])
|
|
1013
|
+
original = assignment_path.read_bytes()
|
|
1014
|
+
manifest = json.loads(
|
|
1015
|
+
self.registry_manifest_path(repo, "REVIEW-ASSIGNMENT-HASH").read_text(
|
|
1016
|
+
encoding="utf-8"
|
|
1017
|
+
)
|
|
1018
|
+
)
|
|
1019
|
+
self.assertEqual(
|
|
1020
|
+
hashlib.sha256(original).hexdigest(),
|
|
1021
|
+
manifest["review"]["assignment_sha256"],
|
|
1022
|
+
)
|
|
1023
|
+
|
|
1024
|
+
assignment_path.write_bytes(original + b" \n")
|
|
1025
|
+
rejected = self.ap(
|
|
1026
|
+
worktree,
|
|
1027
|
+
"review-assignment",
|
|
1028
|
+
"REVIEW-ASSIGNMENT-HASH",
|
|
1029
|
+
"--reviewer",
|
|
1030
|
+
"reviewer-hash",
|
|
1031
|
+
check=False,
|
|
1032
|
+
)
|
|
1033
|
+
self.assertNotEqual(0, rejected.returncode)
|
|
1034
|
+
self.assertIn("assignment SHA-256 mismatch", rejected.stdout + rejected.stderr)
|
|
1035
|
+
|
|
1036
|
+
def test_review_assignment_rejects_symlinked_review_root(self) -> None:
|
|
1037
|
+
root, repo, _ = self.make_repo()
|
|
1038
|
+
worktree = self.start_task(repo, "REVIEW-SYMLINK", "shared.txt")
|
|
1039
|
+
(worktree / "shared.txt").write_text("must stay git local\n", encoding="utf-8")
|
|
1040
|
+
review_root = self.registry_manifest_path(repo, "REVIEW-SYMLINK").parent.parent / "reviews"
|
|
1041
|
+
task_review_dir = review_root / "REVIEW-SYMLINK"
|
|
1042
|
+
if task_review_dir.exists():
|
|
1043
|
+
task_review_dir.rmdir()
|
|
1044
|
+
if review_root.exists():
|
|
1045
|
+
review_root.rmdir()
|
|
1046
|
+
outside = root / "outside-reviews"
|
|
1047
|
+
outside.mkdir()
|
|
1048
|
+
review_root.symlink_to(outside, target_is_directory=True)
|
|
1049
|
+
|
|
1050
|
+
rejected = self.ap(
|
|
1051
|
+
worktree,
|
|
1052
|
+
"review-assignment",
|
|
1053
|
+
"REVIEW-SYMLINK",
|
|
1054
|
+
"--reviewer",
|
|
1055
|
+
"reviewer-symlink",
|
|
1056
|
+
check=False,
|
|
1057
|
+
)
|
|
1058
|
+
self.assertNotEqual(0, rejected.returncode)
|
|
1059
|
+
self.assertIn("symlinked Git-local review storage", rejected.stdout + rejected.stderr)
|
|
1060
|
+
self.assertFalse((outside / "REVIEW-SYMLINK").exists())
|
|
1061
|
+
|
|
1062
|
+
def test_review_snapshot_covers_git_states_without_mutating_main_index_or_objects(self) -> None:
|
|
1063
|
+
_, repo, _ = self.make_repo()
|
|
1064
|
+
(repo / "delete-me.txt").write_text("delete me\n", encoding="utf-8")
|
|
1065
|
+
git(repo, "add", "delete-me.txt")
|
|
1066
|
+
git(repo, "commit", "-qm", "add deletion fixture")
|
|
1067
|
+
git(repo, "push", "-q", "origin", "dev")
|
|
1068
|
+
worktree = self.start_task(repo, "REVIEW-GIT-STATES", ".")
|
|
1069
|
+
(worktree / "delete-me.txt").unlink()
|
|
1070
|
+
shared = worktree / "shared.txt"
|
|
1071
|
+
shared.write_text("executable review\n", encoding="utf-8")
|
|
1072
|
+
shared.chmod(shared.stat().st_mode | 0o111)
|
|
1073
|
+
(worktree / "binary-review.bin").write_bytes(b"\x00\x01binary-review\xff" * 32)
|
|
1074
|
+
(worktree / "review-link").symlink_to("shared.txt")
|
|
1075
|
+
index_path = Path(git_output(worktree, "rev-parse", "--git-path", "index"))
|
|
1076
|
+
if not index_path.is_absolute():
|
|
1077
|
+
index_path = (worktree / index_path).resolve()
|
|
1078
|
+
index_before = index_path.read_bytes()
|
|
1079
|
+
objects_before = git_output(worktree, "count-objects", "-v")
|
|
1080
|
+
|
|
1081
|
+
issued = json.loads(
|
|
1082
|
+
self.ap(
|
|
1083
|
+
worktree,
|
|
1084
|
+
"review-assignment",
|
|
1085
|
+
"REVIEW-GIT-STATES",
|
|
1086
|
+
"--reviewer",
|
|
1087
|
+
"reviewer-git-states",
|
|
1088
|
+
"--json",
|
|
1089
|
+
).stdout
|
|
1090
|
+
)
|
|
1091
|
+
patch = Path(issued["assignment"]["diff_artifact_path"]).read_bytes()
|
|
1092
|
+
self.assertIn(b"deleted file mode 100644", patch)
|
|
1093
|
+
self.assertIn(b"old mode 100644", patch)
|
|
1094
|
+
self.assertIn(b"new mode 100755", patch)
|
|
1095
|
+
self.assertIn(b"new file mode 120000", patch)
|
|
1096
|
+
self.assertIn(b"GIT binary patch", patch)
|
|
1097
|
+
self.assertEqual(index_before, index_path.read_bytes())
|
|
1098
|
+
self.assertEqual(objects_before, git_output(worktree, "count-objects", "-v"))
|
|
1099
|
+
self.assertFalse(list(Path(issued["assignment_path"]).parent.glob(".snapshot-*")))
|
|
1100
|
+
|
|
1101
|
+
def test_review_snapshot_stops_and_cleans_when_stream_limit_is_exceeded(self) -> None:
|
|
1102
|
+
_, repo, _ = self.make_repo()
|
|
1103
|
+
worktree = self.start_task(repo, "REVIEW-SIZE-LIMIT", "shared.txt")
|
|
1104
|
+
# The input itself stays below the test limit while the Git patch
|
|
1105
|
+
# headers plus body exceed it, exercising the streaming PIPE cutoff.
|
|
1106
|
+
(worktree / "shared.txt").write_text("small\n", encoding="utf-8")
|
|
1107
|
+
previous = os.environ.get("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES")
|
|
1108
|
+
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = "128"
|
|
1109
|
+
try:
|
|
1110
|
+
rejected = self.ap(
|
|
1111
|
+
worktree,
|
|
1112
|
+
"review-assignment",
|
|
1113
|
+
"REVIEW-SIZE-LIMIT",
|
|
1114
|
+
"--reviewer",
|
|
1115
|
+
"reviewer-size",
|
|
1116
|
+
check=False,
|
|
1117
|
+
)
|
|
1118
|
+
finally:
|
|
1119
|
+
if previous is None:
|
|
1120
|
+
os.environ.pop("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES", None)
|
|
1121
|
+
else:
|
|
1122
|
+
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = previous
|
|
1123
|
+
self.assertNotEqual(0, rejected.returncode)
|
|
1124
|
+
self.assertIn("safety limit", rejected.stdout + rejected.stderr)
|
|
1125
|
+
review_dir = (
|
|
1126
|
+
self.registry_manifest_path(repo, "REVIEW-SIZE-LIMIT").parent.parent
|
|
1127
|
+
/ "reviews"
|
|
1128
|
+
/ "REVIEW-SIZE-LIMIT"
|
|
1129
|
+
)
|
|
1130
|
+
self.assertFalse(list(review_dir.glob(".snapshot-*")))
|
|
1131
|
+
self.assertFalse(list(review_dir.glob("*.assignment.json")))
|
|
1132
|
+
self.assertFalse(list(review_dir.glob("*.patch")))
|
|
1133
|
+
|
|
1134
|
+
def test_review_snapshot_rejects_oversized_input_before_creating_temp_objects(self) -> None:
|
|
1135
|
+
_, repo, _ = self.make_repo()
|
|
1136
|
+
worktree = self.start_task(repo, "REVIEW-INPUT-LIMIT", "shared.txt")
|
|
1137
|
+
(worktree / "shared.txt").write_text("x" * 4096 + "\n", encoding="utf-8")
|
|
1138
|
+
objects_before = git_output(worktree, "count-objects", "-v")
|
|
1139
|
+
previous = os.environ.get("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES")
|
|
1140
|
+
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = "128"
|
|
1141
|
+
try:
|
|
1142
|
+
rejected = self.ap(
|
|
1143
|
+
worktree,
|
|
1144
|
+
"review-assignment",
|
|
1145
|
+
"REVIEW-INPUT-LIMIT",
|
|
1146
|
+
"--reviewer",
|
|
1147
|
+
"reviewer-input-size",
|
|
1148
|
+
check=False,
|
|
1149
|
+
)
|
|
1150
|
+
finally:
|
|
1151
|
+
if previous is None:
|
|
1152
|
+
os.environ.pop("AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES", None)
|
|
1153
|
+
else:
|
|
1154
|
+
os.environ["AUTOCODING_REVIEW_ARTIFACT_MAX_BYTES"] = previous
|
|
1155
|
+
self.assertNotEqual(0, rejected.returncode)
|
|
1156
|
+
self.assertIn("snapshot input exceeds", rejected.stdout + rejected.stderr)
|
|
1157
|
+
review_dir = (
|
|
1158
|
+
self.registry_manifest_path(repo, "REVIEW-INPUT-LIMIT").parent.parent
|
|
1159
|
+
/ "reviews"
|
|
1160
|
+
/ "REVIEW-INPUT-LIMIT"
|
|
1161
|
+
)
|
|
1162
|
+
self.assertFalse(review_dir.exists())
|
|
1163
|
+
self.assertEqual(objects_before, git_output(worktree, "count-objects", "-v"))
|
|
1164
|
+
|
|
908
1165
|
def test_review_run_supervises_separate_process_and_records_result_once(self) -> None:
|
|
909
1166
|
root, repo, _ = self.make_repo()
|
|
910
|
-
worktree = self.start_task(repo, "REVIEW-RUN", "
|
|
911
|
-
(worktree / "shared.txt").write_text("review
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
"
|
|
915
|
-
"if os.environ.get('CODEX_THREAD_ID'):\n"
|
|
916
|
-
" raise SystemExit(9)\n"
|
|
917
|
-
"assignment_path = pathlib.Path(os.environ['AUTOCODING_REVIEW_ASSIGNMENT'])\n"
|
|
918
|
-
"assignment = json.loads(assignment_path.read_text(encoding='utf-8'))\n"
|
|
919
|
-
"if int(os.environ['AUTOCODING_REVIEW_TIMEOUT_SECONDS']) not in (90, 300):\n"
|
|
920
|
-
" raise SystemExit(10)\n"
|
|
921
|
-
"print(json.dumps({'verdict': 'approved', 'summary': 'runtime reviewed', "
|
|
922
|
-
"'evidence': ['assignment=' + assignment['task_id']]}))\n",
|
|
1167
|
+
worktree = self.start_task(repo, "REVIEW-RUN", ".")
|
|
1168
|
+
(worktree / "shared.txt").write_text("staged tracked review token\n", encoding="utf-8")
|
|
1169
|
+
git(worktree, "add", "shared.txt")
|
|
1170
|
+
(worktree / "untracked-review.txt").write_text(
|
|
1171
|
+
"untracked review token\n",
|
|
923
1172
|
encoding="utf-8",
|
|
924
1173
|
)
|
|
925
|
-
runner =
|
|
1174
|
+
runner = self.artifact_reviewer_runner(
|
|
1175
|
+
root,
|
|
1176
|
+
"staged tracked review token",
|
|
1177
|
+
"untracked review token",
|
|
1178
|
+
)
|
|
926
1179
|
completed = self.ap(
|
|
927
1180
|
worktree,
|
|
928
1181
|
"review-run",
|
|
@@ -935,7 +1188,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
935
1188
|
)
|
|
936
1189
|
result = json.loads(completed.stdout)
|
|
937
1190
|
self.assertEqual("approved", result["verdict"])
|
|
938
|
-
self.assertEqual("
|
|
1191
|
+
self.assertEqual("artifact reviewed", result["summary"])
|
|
939
1192
|
|
|
940
1193
|
status = json.loads(
|
|
941
1194
|
self.ap(worktree, "task-status", "REVIEW-RUN", "--json").stdout
|
|
@@ -1062,6 +1315,9 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1062
1315
|
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
1063
1316
|
manifest["review"]["issued_at"] = assignment["issued_at"]
|
|
1064
1317
|
manifest["review"]["deadline_at"] = assignment["deadline_at"]
|
|
1318
|
+
manifest["review"]["assignment_sha256"] = hashlib.sha256(
|
|
1319
|
+
assignment_path.read_bytes()
|
|
1320
|
+
).hexdigest()
|
|
1065
1321
|
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
1066
1322
|
|
|
1067
1323
|
slow_reviewer = root / "slow-reviewer.py"
|
|
@@ -1163,6 +1419,9 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1163
1419
|
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
1164
1420
|
manifest["review"]["issued_at"] = assignment["issued_at"]
|
|
1165
1421
|
manifest["review"]["deadline_at"] = assignment["deadline_at"]
|
|
1422
|
+
manifest["review"]["assignment_sha256"] = hashlib.sha256(
|
|
1423
|
+
assignment_path.read_bytes()
|
|
1424
|
+
).hexdigest()
|
|
1166
1425
|
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
1167
1426
|
|
|
1168
1427
|
renewed = self.ap(
|
|
@@ -1724,6 +1983,12 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1724
1983
|
worktree = self.start_task(repo, "INTEGRATE-1")
|
|
1725
1984
|
(worktree / "integrated.txt").write_text("integrated\n", encoding="utf-8")
|
|
1726
1985
|
self.commit_push(worktree, "INTEGRATE-1", "INTEGRATE-1: ready")
|
|
1986
|
+
review_dir = Path(
|
|
1987
|
+
json.loads(
|
|
1988
|
+
self.registry_manifest_path(repo, "INTEGRATE-1").read_text(encoding="utf-8")
|
|
1989
|
+
)["review"]["assignment_path"]
|
|
1990
|
+
).parent
|
|
1991
|
+
self.assertTrue(review_dir.is_dir())
|
|
1727
1992
|
task_commit = git_output(worktree, "rev-parse", "HEAD")
|
|
1728
1993
|
self.assertEqual("c", commit_hook_marker.read_text(encoding="utf-8"))
|
|
1729
1994
|
self.assertFalse(
|
|
@@ -1747,6 +2012,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1747
2012
|
self.assertFalse(worktree.exists())
|
|
1748
2013
|
self.assert_local_branch(repo, "codex/INTEGRATE-1", False)
|
|
1749
2014
|
self.assert_remote_branch(remote, "codex/INTEGRATE-1", False)
|
|
2015
|
+
self.assertFalse(review_dir.exists())
|
|
1750
2016
|
self.assertEqual("x", gate_marker.read_text(encoding="utf-8"), "push flow must run the fast gate exactly once")
|
|
1751
2017
|
self.assertEqual("c", commit_hook_marker.read_text(encoding="utf-8"), "push flow must create exactly one hook-visible commit")
|
|
1752
2018
|
self.assertEqual("p", push_hook_marker.read_text(encoding="utf-8"), "the final target push hook must run exactly once")
|
|
@@ -1871,6 +2137,31 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
1871
2137
|
self.assert_local_branch(repo, "codex/PRUNE-REGISTERED", False)
|
|
1872
2138
|
self.assert_remote_branch(remote, "codex/PRUNE-REGISTERED", False)
|
|
1873
2139
|
|
|
2140
|
+
def test_task_prune_removes_orphan_git_local_review_artifacts(self) -> None:
|
|
2141
|
+
_, repo, _ = self.make_repo()
|
|
2142
|
+
worktree = self.start_task(repo, "PRUNE-REVIEW-ORPHAN", "shared.txt")
|
|
2143
|
+
(worktree / "shared.txt").write_text("orphan review\n", encoding="utf-8")
|
|
2144
|
+
issued = json.loads(
|
|
2145
|
+
self.ap(
|
|
2146
|
+
worktree,
|
|
2147
|
+
"review-assignment",
|
|
2148
|
+
"PRUNE-REVIEW-ORPHAN",
|
|
2149
|
+
"--reviewer",
|
|
2150
|
+
"reviewer-orphan",
|
|
2151
|
+
"--json",
|
|
2152
|
+
).stdout
|
|
2153
|
+
)
|
|
2154
|
+
review_dir = Path(issued["assignment_path"]).parent
|
|
2155
|
+
self.assertTrue(review_dir.is_dir())
|
|
2156
|
+
git(repo, "worktree", "unlock", str(worktree))
|
|
2157
|
+
git(repo, "worktree", "remove", "--force", str(worktree))
|
|
2158
|
+
self.registry_manifest_path(repo, "PRUNE-REVIEW-ORPHAN").unlink()
|
|
2159
|
+
|
|
2160
|
+
self.ap(repo, "task-prune")
|
|
2161
|
+
|
|
2162
|
+
self.assertFalse(review_dir.exists())
|
|
2163
|
+
self.assert_local_branch(repo, "codex/PRUNE-REVIEW-ORPHAN", False)
|
|
2164
|
+
|
|
1874
2165
|
def test_cleanup_blocks_unknown_ignored_data_but_allows_runtime_evidence(self) -> None:
|
|
1875
2166
|
_, repo, remote = self.make_repo()
|
|
1876
2167
|
(repo / ".gitignore").write_text(".env\n.local/\n", encoding="utf-8")
|
|
@@ -2388,6 +2679,11 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
2388
2679
|
worktree = self.start_task(repo, "REMOTE-RACE")
|
|
2389
2680
|
(worktree / "payload.txt").write_text("ready\n", encoding="utf-8")
|
|
2390
2681
|
self.commit_push(worktree, "REMOTE-RACE", "REMOTE-RACE: ready")
|
|
2682
|
+
review_dir = Path(
|
|
2683
|
+
json.loads(
|
|
2684
|
+
self.registry_manifest_path(repo, "REMOTE-RACE").read_text(encoding="utf-8")
|
|
2685
|
+
)["review"]["assignment_path"]
|
|
2686
|
+
).parent
|
|
2391
2687
|
self.ap(repo, "task-integrate", "REMOTE-RACE", "--keep-worktree")
|
|
2392
2688
|
|
|
2393
2689
|
attacker = root / "attacker"
|
|
@@ -2412,6 +2708,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
2412
2708
|
manifest_path = self.registry_manifest_path(repo, "REMOTE-RACE")
|
|
2413
2709
|
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
2414
2710
|
self.assertEqual("cleanup-pending", manifest["state"])
|
|
2711
|
+
self.assertTrue(review_dir.is_dir())
|
|
2415
2712
|
|
|
2416
2713
|
prune = self.ap(repo, "task-prune")
|
|
2417
2714
|
self.assertIn("remote cleanup pending", prune.stdout + prune.stderr)
|
|
@@ -2421,6 +2718,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
2421
2718
|
git(remote, "update-ref", "-d", "refs/heads/codex/REMOTE-RACE", changed_remote_tip)
|
|
2422
2719
|
self.ap(repo, "task-prune")
|
|
2423
2720
|
self.assertFalse(manifest_path.exists())
|
|
2721
|
+
self.assertFalse(review_dir.exists())
|
|
2424
2722
|
self.assert_remote_branch(remote, "codex/REMOTE-RACE", False)
|
|
2425
2723
|
|
|
2426
2724
|
def test_gate_mutation_aborts_before_staging_or_commit(self) -> None:
|
|
@@ -113,6 +113,9 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
113
113
|
"diff_base": "HEAD~1",
|
|
114
114
|
"diff_head": "HEAD",
|
|
115
115
|
"diff_fingerprint": "a" * 64,
|
|
116
|
+
"diff_artifact_path": "/tmp/review.patch",
|
|
117
|
+
"diff_artifact_sha256": "b" * 64,
|
|
118
|
+
"diff_artifact_format": "git-binary-patch-v1",
|
|
116
119
|
"owning_fixer": "fixer-1",
|
|
117
120
|
}
|
|
118
121
|
assignment.update(overrides)
|
|
@@ -138,6 +141,54 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
138
141
|
target.write_text("change\n", encoding="utf-8")
|
|
139
142
|
return repo, cfg
|
|
140
143
|
|
|
144
|
+
def test_direct_cleanup_restores_active_state_when_registry_removal_fails(self) -> None:
|
|
145
|
+
repo, _ = self.make_repo()
|
|
146
|
+
manifest = {
|
|
147
|
+
"task_id": "DIRECT-CLEANUP-RETRY",
|
|
148
|
+
"task_uuid": "direct-cleanup-uuid",
|
|
149
|
+
"worktree_path": str(repo),
|
|
150
|
+
}
|
|
151
|
+
active_path = ap._worktree_manifest_path(repo)
|
|
152
|
+
ap._write_json_object(active_path, manifest)
|
|
153
|
+
|
|
154
|
+
with mock.patch.object(
|
|
155
|
+
ap,
|
|
156
|
+
"_delete_task_manifest",
|
|
157
|
+
side_effect=APError("simulated registry failure"),
|
|
158
|
+
):
|
|
159
|
+
with self.assertRaisesRegex(APError, "simulated registry failure"):
|
|
160
|
+
ap._clear_direct_task(repo, manifest)
|
|
161
|
+
|
|
162
|
+
restored = ap._read_json_object(active_path)
|
|
163
|
+
self.assertIsNotNone(restored)
|
|
164
|
+
self.assertEqual(manifest["task_uuid"], restored["task_uuid"])
|
|
165
|
+
|
|
166
|
+
def test_registry_failure_preserves_review_evidence_for_retry(self) -> None:
|
|
167
|
+
repo, _ = self.make_repo()
|
|
168
|
+
manifest = {
|
|
169
|
+
"task_id": "CLEANUP-EVIDENCE",
|
|
170
|
+
"task_uuid": "cleanup-evidence-uuid",
|
|
171
|
+
"worktree_path": str(repo),
|
|
172
|
+
}
|
|
173
|
+
registry_path = ap._task_registry_path(repo, manifest["task_id"])
|
|
174
|
+
ap._write_json_object(registry_path, manifest)
|
|
175
|
+
review_dir = ap._task_review_dir(repo, manifest["task_id"], create=True)
|
|
176
|
+
evidence_path = review_dir / "evidence.patch"
|
|
177
|
+
ap._write_private_bytes(evidence_path, b"immutable evidence\n")
|
|
178
|
+
original_unlink = Path.unlink
|
|
179
|
+
|
|
180
|
+
def fail_registry_unlink(path: Path, *args: object, **kwargs: object) -> None:
|
|
181
|
+
if path == registry_path:
|
|
182
|
+
raise PermissionError("simulated registry permission failure")
|
|
183
|
+
original_unlink(path, *args, **kwargs)
|
|
184
|
+
|
|
185
|
+
with mock.patch.object(Path, "unlink", new=fail_registry_unlink):
|
|
186
|
+
with self.assertRaisesRegex(APError, "Cannot remove task registry state"):
|
|
187
|
+
ap._delete_task_manifest(repo, manifest)
|
|
188
|
+
|
|
189
|
+
self.assertTrue(registry_path.exists())
|
|
190
|
+
self.assertEqual(b"immutable evidence\n", evidence_path.read_bytes())
|
|
191
|
+
|
|
141
192
|
@staticmethod
|
|
142
193
|
def write_config(repo: Path, cfg: dict) -> None:
|
|
143
194
|
path = repo / "docs" / "ENGINEERING.md"
|
|
@@ -628,6 +679,9 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
628
679
|
"diff_base": "HEAD~1",
|
|
629
680
|
"diff_head": "HEAD",
|
|
630
681
|
"diff_fingerprint": fingerprint,
|
|
682
|
+
"diff_artifact_path": "/tmp/review.patch",
|
|
683
|
+
"diff_artifact_sha256": "b" * 64,
|
|
684
|
+
"diff_artifact_format": "git-binary-patch-v1",
|
|
631
685
|
"owning_fixer": "fixer-1",
|
|
632
686
|
}
|
|
633
687
|
ap._validate_orchestration_contract("assignment", assignment)
|
|
@@ -734,6 +788,10 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
734
788
|
self.assertIn("--ignore-user-config", command)
|
|
735
789
|
self.assertIn("read-only", command)
|
|
736
790
|
self.assertIn('model_reasoning_effort="xhigh"', command)
|
|
791
|
+
prompt = command[-1]
|
|
792
|
+
self.assertIn("docs/tools/autopipeline/ap.py review-artifact --file", prompt)
|
|
793
|
+
self.assertIn("diff_artifact_sha256", prompt)
|
|
794
|
+
self.assertIn("never substitute a live git diff", prompt)
|
|
737
795
|
developer_override = next(
|
|
738
796
|
item for item in command if item.startswith("developer_instructions=")
|
|
739
797
|
)
|