@elvis1513/auto-coding-skill 4.2.7 → 4.3.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 +121 -14
- package/cli/assets/agents/reviewer.toml +2 -2
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +13 -14
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +17 -12
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +24 -23
- package/cli/assets/skill/scripts/ap.py +4063 -698
- package/cli/assets/skill/scripts/core.py +363 -1
- package/cli/assets/skill/scripts/install_integrity.py +6 -4
- package/cli/assets/skill/scripts/scaffold_templates.py +99 -0
- package/cli/src/index.js +1128 -322
- package/cli/tests/ap_concurrency_test.py +322 -34
- package/cli/tests/ap_profiles_test.py +398 -69
- package/cli/tests/core_shell_test.py +261 -0
- package/cli/tests/index.test.js +1580 -182
- package/package.json +1 -1
|
@@ -4,12 +4,15 @@ from __future__ import annotations
|
|
|
4
4
|
import argparse
|
|
5
5
|
import base64
|
|
6
6
|
import contextlib
|
|
7
|
+
import hashlib
|
|
7
8
|
import io
|
|
8
9
|
import json
|
|
9
10
|
import os
|
|
11
|
+
import signal
|
|
10
12
|
import subprocess
|
|
11
13
|
import sys
|
|
12
14
|
import tempfile
|
|
15
|
+
import threading
|
|
13
16
|
import time
|
|
14
17
|
import tomllib
|
|
15
18
|
import unittest
|
|
@@ -780,65 +783,352 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
780
783
|
repo, _ = self.make_repo()
|
|
781
784
|
assignment_path = repo / "assignment.json"
|
|
782
785
|
result_path = repo / "result.json"
|
|
786
|
+
reviewer_config = repo / ".agents" / "agents" / "reviewer.toml"
|
|
787
|
+
reviewer_config.parent.mkdir(parents=True)
|
|
788
|
+
reviewer_config.write_text(
|
|
789
|
+
'name = "reviewer"\n'
|
|
790
|
+
'model = "vendor/reviewer-model"\n'
|
|
791
|
+
'developer_instructions = "review only the immutable artifact"\n',
|
|
792
|
+
encoding="utf-8",
|
|
793
|
+
)
|
|
783
794
|
with mock.patch.object(ap.shutil, "which", return_value="/usr/local/bin/codex"):
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
795
|
+
focused = ap._codex_reviewer_command(
|
|
796
|
+
repo,
|
|
797
|
+
assignment_path,
|
|
798
|
+
result_path,
|
|
799
|
+
review_depth="focused",
|
|
800
|
+
)
|
|
801
|
+
deep = ap._codex_reviewer_command(
|
|
802
|
+
repo,
|
|
803
|
+
assignment_path,
|
|
804
|
+
result_path,
|
|
805
|
+
review_depth="deep",
|
|
806
|
+
)
|
|
807
|
+
|
|
808
|
+
self.assertEqual("/usr/local/bin/codex", focused[0])
|
|
809
|
+
self.assertIn("--json", focused)
|
|
810
|
+
self.assertIn("--ephemeral", focused)
|
|
811
|
+
self.assertIn("--ignore-user-config", focused)
|
|
812
|
+
self.assertIn("read-only", focused)
|
|
813
|
+
self.assertIn('model_reasoning_effort="high"', focused)
|
|
814
|
+
self.assertIn('model_reasoning_effort="xhigh"', deep)
|
|
815
|
+
self.assertEqual("vendor/reviewer-model", focused[focused.index("--model") + 1])
|
|
816
|
+
prompt = focused[-1]
|
|
792
817
|
self.assertIn("docs/tools/autopipeline/ap.py review-artifact --file", prompt)
|
|
793
818
|
self.assertIn("diff_artifact_sha256", prompt)
|
|
794
819
|
self.assertIn("never substitute a live git diff", prompt)
|
|
795
820
|
developer_override = next(
|
|
796
|
-
item for item in
|
|
821
|
+
item for item in focused if item.startswith("developer_instructions=")
|
|
797
822
|
)
|
|
798
823
|
tomllib.loads(developer_override)
|
|
799
|
-
self.assertEqual(str(result_path),
|
|
824
|
+
self.assertEqual(str(result_path), focused[focused.index("-o") + 1])
|
|
800
825
|
|
|
801
826
|
def test_reviewer_process_timeout_terminates_its_process_group(self) -> None:
|
|
802
827
|
repo, _ = self.make_repo()
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
("
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
828
|
+
runner = repo / "slow-reviewer.py"
|
|
829
|
+
runner.write_text(
|
|
830
|
+
"import json, sys, time\n"
|
|
831
|
+
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
832
|
+
"print('Bearer secret-token password=hunter2', file=sys.stderr, flush=True)\n"
|
|
833
|
+
"time.sleep(30)\n",
|
|
834
|
+
encoding="utf-8",
|
|
835
|
+
)
|
|
836
|
+
started = time.monotonic()
|
|
837
|
+
with self.assertRaises(ap._ReviewerRuntimeTimeout) as raised:
|
|
838
|
+
ap._run_supervised_reviewer_process(
|
|
839
|
+
[sys.executable, str(runner)],
|
|
840
|
+
cwd=repo,
|
|
841
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
842
|
+
timeout_seconds=0.3,
|
|
843
|
+
startup_timeout_seconds=0.2,
|
|
844
|
+
)
|
|
845
|
+
self.assertLess(time.monotonic() - started, 3.0)
|
|
846
|
+
self.assertEqual(1, raised.exception.diagnostics["event_count"])
|
|
847
|
+
safe = ap._safe_reviewer_attempt(raised.exception.diagnostics, 1, "analysis-timeout")
|
|
848
|
+
self.assertNotIn("secret-token", json.dumps(safe))
|
|
849
|
+
self.assertNotIn("hunter2", json.dumps(safe))
|
|
850
|
+
|
|
851
|
+
@unittest.skipUnless(os.name == "posix", "POSIX process-group behavior")
|
|
852
|
+
def test_reviewer_timeout_kills_group_after_leader_exits(self) -> None:
|
|
853
|
+
repo, _ = self.make_repo()
|
|
854
|
+
child_pid_path = repo / "reviewer-grandchild.pid"
|
|
855
|
+
runner = repo / "leader-exits-reviewer.py"
|
|
856
|
+
runner.write_text(
|
|
857
|
+
"import json, subprocess, sys\n"
|
|
858
|
+
"from pathlib import Path\n"
|
|
859
|
+
"child = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'])\n"
|
|
860
|
+
f"Path({str(child_pid_path)!r}).write_text(str(child.pid))\n"
|
|
861
|
+
"print(json.dumps({'type': 'turn.started'}), flush=True)\n",
|
|
862
|
+
encoding="utf-8",
|
|
863
|
+
)
|
|
864
|
+
started = time.monotonic()
|
|
865
|
+
with self.assertRaises(ap._ReviewerRuntimeTimeout):
|
|
866
|
+
ap._run_supervised_reviewer_process(
|
|
867
|
+
[sys.executable, str(runner)],
|
|
868
|
+
cwd=repo,
|
|
869
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
870
|
+
timeout_seconds=0.3,
|
|
871
|
+
startup_timeout_seconds=0.2,
|
|
872
|
+
)
|
|
873
|
+
self.assertLess(time.monotonic() - started, 3.0)
|
|
874
|
+
child_pid = int(child_pid_path.read_text())
|
|
875
|
+
child_gone = False
|
|
876
|
+
for _ in range(20):
|
|
877
|
+
try:
|
|
878
|
+
os.kill(child_pid, 0)
|
|
879
|
+
except ProcessLookupError:
|
|
880
|
+
child_gone = True
|
|
881
|
+
break
|
|
882
|
+
time.sleep(0.05)
|
|
883
|
+
self.assertTrue(child_gone, "Reviewer grandchild survived process-group cleanup")
|
|
884
|
+
|
|
885
|
+
@unittest.skipUnless(os.name == "posix", "POSIX detached-process behavior")
|
|
886
|
+
def test_detached_pipe_holder_cannot_extend_reviewer_deadline(self) -> None:
|
|
887
|
+
repo, _ = self.make_repo()
|
|
888
|
+
child_pid_path = repo / "detached-reviewer-child.pid"
|
|
889
|
+
runner = repo / "detached-child-reviewer.py"
|
|
890
|
+
runner.write_text(
|
|
891
|
+
"import json, subprocess, sys\n"
|
|
892
|
+
"from pathlib import Path\n"
|
|
893
|
+
"child = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'], start_new_session=True)\n"
|
|
894
|
+
f"Path({str(child_pid_path)!r}).write_text(str(child.pid))\n"
|
|
895
|
+
"print(json.dumps({'type': 'turn.started'}), flush=True)\n",
|
|
896
|
+
encoding="utf-8",
|
|
897
|
+
)
|
|
898
|
+
started = time.monotonic()
|
|
899
|
+
child_pid = 0
|
|
900
|
+
try:
|
|
814
901
|
with self.assertRaises(ap._ReviewerRuntimeTimeout):
|
|
815
902
|
ap._run_supervised_reviewer_process(
|
|
816
|
-
[
|
|
903
|
+
[sys.executable, str(runner)],
|
|
904
|
+
cwd=repo,
|
|
905
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
906
|
+
timeout_seconds=0.3,
|
|
907
|
+
startup_timeout_seconds=0.2,
|
|
908
|
+
)
|
|
909
|
+
child_pid = int(child_pid_path.read_text())
|
|
910
|
+
finally:
|
|
911
|
+
if not child_pid and child_pid_path.exists():
|
|
912
|
+
child_pid = int(child_pid_path.read_text())
|
|
913
|
+
if child_pid:
|
|
914
|
+
try:
|
|
915
|
+
os.kill(child_pid, signal.SIGKILL)
|
|
916
|
+
except ProcessLookupError:
|
|
917
|
+
pass
|
|
918
|
+
self.assertLess(time.monotonic() - started, 3.0)
|
|
919
|
+
self.assertFalse(
|
|
920
|
+
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
921
|
+
)
|
|
922
|
+
|
|
923
|
+
def test_reviewer_process_without_first_event_is_runtime_unavailable(self) -> None:
|
|
924
|
+
repo, _ = self.make_repo()
|
|
925
|
+
runner = repo / "silent-reviewer.py"
|
|
926
|
+
runner.write_text("import time\ntime.sleep(30)\n", encoding="utf-8")
|
|
927
|
+
with self.assertRaises(ap._ReviewerRuntimeUnavailable) as raised:
|
|
928
|
+
ap._run_supervised_reviewer_process(
|
|
929
|
+
[sys.executable, str(runner)],
|
|
930
|
+
cwd=repo,
|
|
931
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
932
|
+
timeout_seconds=1,
|
|
933
|
+
startup_timeout_seconds=0.1,
|
|
934
|
+
)
|
|
935
|
+
self.assertEqual(0, raised.exception.diagnostics["event_count"])
|
|
936
|
+
|
|
937
|
+
def test_reviewer_process_clean_exit_without_semantic_event_is_unavailable(self) -> None:
|
|
938
|
+
repo, _ = self.make_repo()
|
|
939
|
+
runner = repo / "empty-reviewer.py"
|
|
940
|
+
runner.write_text("pass\n", encoding="utf-8")
|
|
941
|
+
with self.assertRaises(ap._ReviewerRuntimeUnavailable):
|
|
942
|
+
ap._run_supervised_reviewer_process(
|
|
943
|
+
[sys.executable, str(runner)],
|
|
944
|
+
cwd=repo,
|
|
945
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
946
|
+
timeout_seconds=1,
|
|
947
|
+
startup_timeout_seconds=0.2,
|
|
948
|
+
)
|
|
949
|
+
|
|
950
|
+
def test_reviewer_event_writer_failure_stops_process_and_reader_threads(self) -> None:
|
|
951
|
+
repo, _ = self.make_repo()
|
|
952
|
+
runner = repo / "writer-failure-reviewer.py"
|
|
953
|
+
runner.write_text(
|
|
954
|
+
"import json, time\n"
|
|
955
|
+
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
956
|
+
"time.sleep(30)\n",
|
|
957
|
+
encoding="utf-8",
|
|
958
|
+
)
|
|
959
|
+
|
|
960
|
+
class FailingWriter:
|
|
961
|
+
def write(self, _: str) -> None:
|
|
962
|
+
raise OSError("event log unavailable")
|
|
963
|
+
|
|
964
|
+
def flush(self) -> None:
|
|
965
|
+
pass
|
|
966
|
+
|
|
967
|
+
started = time.monotonic()
|
|
968
|
+
with mock.patch.object(
|
|
969
|
+
ap,
|
|
970
|
+
"_terminate_reviewer_process",
|
|
971
|
+
wraps=ap._terminate_reviewer_process,
|
|
972
|
+
) as terminate:
|
|
973
|
+
with self.assertRaises(ap._ReviewerRuntimeInternalError):
|
|
974
|
+
ap._run_supervised_reviewer_process(
|
|
975
|
+
[sys.executable, str(runner)],
|
|
817
976
|
cwd=repo,
|
|
818
977
|
env={"PATH": os.environ.get("PATH", "")},
|
|
819
|
-
timeout_seconds=
|
|
978
|
+
timeout_seconds=3,
|
|
979
|
+
startup_timeout_seconds=1,
|
|
980
|
+
event_writer=FailingWriter(),
|
|
820
981
|
)
|
|
982
|
+
self.assertLess(time.monotonic() - started, 3.0)
|
|
983
|
+
terminate.assert_called_once()
|
|
984
|
+
self.assertFalse(
|
|
985
|
+
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
986
|
+
)
|
|
821
987
|
|
|
822
|
-
|
|
823
|
-
self.
|
|
824
|
-
|
|
988
|
+
def test_reviewer_output_flood_is_bounded_and_cleans_reader_threads(self) -> None:
|
|
989
|
+
repo, _ = self.make_repo()
|
|
990
|
+
runner = repo / "flood-reviewer.py"
|
|
991
|
+
runner.write_text(
|
|
992
|
+
"import json\n"
|
|
993
|
+
"for index in range(10000):\n"
|
|
994
|
+
" print(json.dumps({'type': 'item.completed', 'item': {'type': 'note'}, 'i': index}), flush=True)\n",
|
|
995
|
+
encoding="utf-8",
|
|
996
|
+
)
|
|
997
|
+
started = time.monotonic()
|
|
998
|
+
with mock.patch.object(ap, "_REVIEW_OUTPUT_MAX_BYTES", 2048):
|
|
999
|
+
with self.assertRaises(ap._ReviewerRuntimeOutputLimit):
|
|
1000
|
+
ap._run_supervised_reviewer_process(
|
|
1001
|
+
[sys.executable, str(runner)],
|
|
1002
|
+
cwd=repo,
|
|
1003
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
1004
|
+
timeout_seconds=3,
|
|
1005
|
+
startup_timeout_seconds=1,
|
|
1006
|
+
)
|
|
1007
|
+
self.assertLess(time.monotonic() - started, 3.0)
|
|
1008
|
+
self.assertFalse(
|
|
1009
|
+
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
def test_reviewer_single_unterminated_line_is_bounded(self) -> None:
|
|
1013
|
+
repo, _ = self.make_repo()
|
|
1014
|
+
runner = repo / "long-line-reviewer.py"
|
|
1015
|
+
runner.write_text(
|
|
1016
|
+
"import sys, time\n"
|
|
1017
|
+
"sys.stdout.write('x' * 10000)\n"
|
|
1018
|
+
"sys.stdout.flush()\n"
|
|
1019
|
+
"time.sleep(30)\n",
|
|
1020
|
+
encoding="utf-8",
|
|
1021
|
+
)
|
|
1022
|
+
with mock.patch.object(ap, "_REVIEW_OUTPUT_MAX_BYTES", 2048):
|
|
1023
|
+
with self.assertRaises(ap._ReviewerRuntimeOutputLimit):
|
|
1024
|
+
ap._run_supervised_reviewer_process(
|
|
1025
|
+
[sys.executable, str(runner)],
|
|
1026
|
+
cwd=repo,
|
|
1027
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
1028
|
+
timeout_seconds=3,
|
|
1029
|
+
startup_timeout_seconds=1,
|
|
1030
|
+
)
|
|
1031
|
+
self.assertFalse(
|
|
1032
|
+
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
def test_reviewer_event_metadata_does_not_persist_model_or_patch_content(self) -> None:
|
|
1036
|
+
record, semantic = ap._reviewer_event_metadata(
|
|
1037
|
+
"stdout",
|
|
1038
|
+
json.dumps(
|
|
1039
|
+
{
|
|
1040
|
+
"type": "item.completed",
|
|
1041
|
+
"item": {
|
|
1042
|
+
"type": "command_execution",
|
|
1043
|
+
"text": "PATCH_SECRET_TOKEN",
|
|
1044
|
+
"output": "Bearer private-token",
|
|
1045
|
+
},
|
|
1046
|
+
}
|
|
1047
|
+
),
|
|
1048
|
+
"2026-07-17T00:00:00+00:00",
|
|
1049
|
+
)
|
|
1050
|
+
serialized = json.dumps(record)
|
|
1051
|
+
self.assertTrue(semantic)
|
|
1052
|
+
self.assertEqual("item.completed", record["event_type"])
|
|
1053
|
+
self.assertEqual("command_execution", record["item_type"])
|
|
1054
|
+
self.assertNotIn("PATCH_SECRET_TOKEN", serialized)
|
|
1055
|
+
self.assertNotIn("private-token", serialized)
|
|
1056
|
+
|
|
1057
|
+
def test_substantive_agent_message_is_not_erased_by_later_approved_message(self) -> None:
|
|
1058
|
+
assignment = self.reviewer_assignment(
|
|
1059
|
+
review_depth="focused",
|
|
1060
|
+
timeout_seconds=150,
|
|
1061
|
+
issued_at="2026-07-17T00:00:00+00:00",
|
|
1062
|
+
deadline_at="2026-07-17T00:02:30+00:00",
|
|
1063
|
+
)
|
|
1064
|
+
stdout = "\n".join(
|
|
1065
|
+
json.dumps(
|
|
1066
|
+
{
|
|
1067
|
+
"type": "item.completed",
|
|
1068
|
+
"item": {"type": "agent_message", "text": json.dumps({"verdict": verdict})},
|
|
1069
|
+
}
|
|
1070
|
+
)
|
|
1071
|
+
for verdict in ("blocked", "approved")
|
|
1072
|
+
)
|
|
1073
|
+
result = ap._substantive_reviewer_event_result(stdout, assignment)
|
|
1074
|
+
self.assertIsNotNone(result)
|
|
1075
|
+
self.assertEqual("blocked", result["verdict"])
|
|
1076
|
+
|
|
1077
|
+
def test_reviewer_spawn_failure_is_runtime_unavailable_with_safe_diagnostics(self) -> None:
|
|
1078
|
+
repo, _ = self.make_repo()
|
|
1079
|
+
with mock.patch.object(
|
|
1080
|
+
ap.subprocess,
|
|
1081
|
+
"Popen",
|
|
1082
|
+
side_effect=OSError("permission denied token=private-value"),
|
|
1083
|
+
):
|
|
1084
|
+
with self.assertRaises(ap._ReviewerRuntimeUnavailable) as raised:
|
|
1085
|
+
ap._run_supervised_reviewer_process(
|
|
1086
|
+
["missing-reviewer"],
|
|
1087
|
+
cwd=repo,
|
|
1088
|
+
env={"PATH": os.environ.get("PATH", "")},
|
|
1089
|
+
timeout_seconds=1,
|
|
1090
|
+
)
|
|
1091
|
+
safe = ap._safe_reviewer_attempt(raised.exception.diagnostics, 1, "runtime-unavailable")
|
|
1092
|
+
self.assertEqual("spawn-failed", safe["phase"])
|
|
1093
|
+
self.assertNotIn("private-value", json.dumps(safe))
|
|
1094
|
+
|
|
1095
|
+
def test_reviewer_attempt_receipt_never_persists_raw_stderr(self) -> None:
|
|
1096
|
+
diagnostics = ap._reviewer_attempt_diagnostics(
|
|
1097
|
+
started_at="2026-07-17T00:00:00+00:00",
|
|
1098
|
+
finished_at="2026-07-17T00:00:01+00:00",
|
|
1099
|
+
stdout="",
|
|
1100
|
+
stderr="PATCH_SECRET_TOKEN\n-----BEGIN OPENSSH PRIVATE KEY-----\nprivate-material",
|
|
1101
|
+
first_event_at="",
|
|
1102
|
+
last_event_at="",
|
|
1103
|
+
last_event_type="",
|
|
1104
|
+
event_count=0,
|
|
1105
|
+
phase="spawn-failed",
|
|
1106
|
+
exit_code=None,
|
|
1107
|
+
)
|
|
1108
|
+
serialized = json.dumps(
|
|
1109
|
+
ap._safe_reviewer_attempt(diagnostics, 1, "runtime-unavailable")
|
|
1110
|
+
)
|
|
1111
|
+
self.assertNotIn("stderr_tail", serialized)
|
|
1112
|
+
self.assertNotIn("PATCH_SECRET_TOKEN", serialized)
|
|
1113
|
+
self.assertNotIn("PRIVATE KEY", serialized)
|
|
1114
|
+
self.assertIn(hashlib.sha256(diagnostics["stderr"].encode()).hexdigest(), serialized)
|
|
825
1115
|
|
|
826
1116
|
def test_reviewer_assignment_timing_contract_and_fixed_budgets(self) -> None:
|
|
827
1117
|
issued_at = "2026-07-16T00:00:00+00:00"
|
|
828
1118
|
assignment = self.reviewer_assignment(
|
|
829
1119
|
review_depth="focused",
|
|
830
|
-
timeout_seconds=
|
|
1120
|
+
timeout_seconds=150,
|
|
831
1121
|
issued_at=issued_at,
|
|
832
|
-
deadline_at="2026-07-16T00:
|
|
1122
|
+
deadline_at="2026-07-16T00:02:30+00:00",
|
|
833
1123
|
scope_revision=1,
|
|
834
1124
|
)
|
|
835
1125
|
self.assertEqual(
|
|
836
1126
|
assignment,
|
|
837
1127
|
ap._validate_orchestration_contract("assignment", assignment),
|
|
838
1128
|
)
|
|
839
|
-
self.assertEqual(("focused",
|
|
1129
|
+
self.assertEqual(("focused", 150), ap._normalized_task_review_policy(True))
|
|
840
1130
|
self.assertEqual(
|
|
841
|
-
("deep",
|
|
1131
|
+
("deep", 360),
|
|
842
1132
|
ap._normalized_task_review_policy(True, "focused", "deep"),
|
|
843
1133
|
)
|
|
844
1134
|
self.assertEqual(("none", 0), ap._normalized_task_review_policy(False, "deep"))
|
|
@@ -848,17 +1138,17 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
848
1138
|
review_depth="focused",
|
|
849
1139
|
timeout_seconds=0,
|
|
850
1140
|
issued_at=issued_at,
|
|
851
|
-
deadline_at="2026-07-16T00:
|
|
1141
|
+
deadline_at="2026-07-16T00:02:30+00:00",
|
|
852
1142
|
),
|
|
853
1143
|
self.reviewer_assignment(
|
|
854
1144
|
review_depth="focused",
|
|
855
|
-
timeout_seconds=
|
|
1145
|
+
timeout_seconds=150,
|
|
856
1146
|
issued_at="2026-07-16T00:00:00",
|
|
857
|
-
deadline_at="2026-07-16T00:
|
|
1147
|
+
deadline_at="2026-07-16T00:02:30",
|
|
858
1148
|
),
|
|
859
1149
|
self.reviewer_assignment(
|
|
860
1150
|
review_depth="focused",
|
|
861
|
-
timeout_seconds=
|
|
1151
|
+
timeout_seconds=150,
|
|
862
1152
|
issued_at=issued_at,
|
|
863
1153
|
deadline_at="2026-07-16T00:01:00+00:00",
|
|
864
1154
|
),
|
|
@@ -1100,8 +1390,8 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
1100
1390
|
deep = self.plan(repo, cfg, planned_paths=["backend/auth/service.py"])
|
|
1101
1391
|
|
|
1102
1392
|
for plan, depth, timeout in [
|
|
1103
|
-
(focused, "focused",
|
|
1104
|
-
(deep, "deep",
|
|
1393
|
+
(focused, "focused", 150),
|
|
1394
|
+
(deep, "deep", 360),
|
|
1105
1395
|
]:
|
|
1106
1396
|
with self.subTest(depth=depth):
|
|
1107
1397
|
self.assertTrue(plan["review_required"])
|
|
@@ -1320,21 +1610,27 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
1320
1610
|
self.assertEqual("high-risk", plan["profile"])
|
|
1321
1611
|
self.assertIn("matched gate rule with profile=high-risk", plan["profile_reasons"])
|
|
1322
1612
|
|
|
1323
|
-
def
|
|
1613
|
+
def test_legacy_full_scope_rule_fails_closed_during_planning(self) -> None:
|
|
1324
1614
|
cfg = base_config()
|
|
1325
1615
|
cfg["gate"]["rules"] = [{"name": "sensitive", "paths": ["src/sensitive/**"], "scope": "full"}]
|
|
1326
1616
|
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1617
|
+
with self.assertRaisesRegex(APError, "legacy automatic gate escalation"):
|
|
1618
|
+
self.plan(
|
|
1619
|
+
repo,
|
|
1620
|
+
cfg,
|
|
1621
|
+
requested_scope="changed",
|
|
1622
|
+
requested_profile="micro",
|
|
1623
|
+
requested_mode="dev",
|
|
1624
|
+
)
|
|
1331
1625
|
|
|
1332
|
-
def
|
|
1626
|
+
def test_legacy_rule_commands_fail_closed_and_never_run(self) -> None:
|
|
1333
1627
|
cfg = base_config()
|
|
1334
1628
|
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1629
|
+
marker_dir = repo / ".test-markers"
|
|
1630
|
+
marker_dir.mkdir()
|
|
1631
|
+
quick_marker = marker_dir / "quick-ran"
|
|
1632
|
+
full_marker = marker_dir / "full-ran"
|
|
1633
|
+
build_marker = marker_dir / "build-ran"
|
|
1338
1634
|
cfg["commands"] = {
|
|
1339
1635
|
"gate_changed": f"touch {quick_marker}",
|
|
1340
1636
|
"gate_full": f"touch {full_marker}",
|
|
@@ -1350,18 +1646,20 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
1350
1646
|
]
|
|
1351
1647
|
self.write_config(repo, cfg)
|
|
1352
1648
|
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1649
|
+
with self.assertRaises(APError) as context:
|
|
1650
|
+
ap.cmd_light_gate(
|
|
1651
|
+
argparse.Namespace(
|
|
1652
|
+
repo=str(repo),
|
|
1653
|
+
scope="changed",
|
|
1654
|
+
profile="",
|
|
1655
|
+
mode="dev",
|
|
1656
|
+
base="",
|
|
1657
|
+
explain=False,
|
|
1658
|
+
)
|
|
1361
1659
|
)
|
|
1362
|
-
)
|
|
1363
1660
|
|
|
1364
|
-
self.
|
|
1661
|
+
self.assertIn("legacy automatic gate escalation", str(context.exception))
|
|
1662
|
+
self.assertFalse(quick_marker.exists())
|
|
1365
1663
|
self.assertFalse(full_marker.exists())
|
|
1366
1664
|
self.assertFalse(build_marker.exists())
|
|
1367
1665
|
|
|
@@ -2377,7 +2675,35 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
2377
2675
|
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2378
2676
|
self.assertIn("gate.rules[0].scope", str(context.exception))
|
|
2379
2677
|
|
|
2380
|
-
def
|
|
2678
|
+
def test_project_overlay_render_rejects_its_own_oversized_output(self) -> None:
|
|
2679
|
+
with self.assertRaisesRegex(APError, "exceeds its size limit"):
|
|
2680
|
+
ap._render_project_overlay({"project": {"oversized": "x" * 200_000}})
|
|
2681
|
+
|
|
2682
|
+
def test_project_config_prepare_never_replaces_a_concurrent_overlay(self) -> None:
|
|
2683
|
+
repo, _ = self.make_repo()
|
|
2684
|
+
overlay = repo / "docs" / "project" / "auto-coding-skill.yaml"
|
|
2685
|
+
overlay.parent.mkdir(parents=True, exist_ok=True)
|
|
2686
|
+
concurrent = ap._render_project_overlay({"project": {"name": "concurrent-owner"}})
|
|
2687
|
+
planned = ap._render_project_overlay({"project": {"name": "planned-owner"}})
|
|
2688
|
+
overlay.write_bytes(concurrent)
|
|
2689
|
+
engineering_before = (repo / "docs" / "ENGINEERING.md").read_bytes()
|
|
2690
|
+
convergence = {
|
|
2691
|
+
"engineering_current": "",
|
|
2692
|
+
"engineering_output": engineering_before.decode("utf-8"),
|
|
2693
|
+
"overlay_current": None,
|
|
2694
|
+
"overlay_output": planned,
|
|
2695
|
+
"migrated_paths": ["project.name"],
|
|
2696
|
+
}
|
|
2697
|
+
args = argparse.Namespace(repo=str(repo), write=True, json=False)
|
|
2698
|
+
|
|
2699
|
+
with mock.patch.object(ap, "_project_config_convergence_plan", return_value=convergence):
|
|
2700
|
+
with self.assertRaisesRegex(APError, "create-only publish"):
|
|
2701
|
+
ap.cmd_project_config_prepare(args)
|
|
2702
|
+
|
|
2703
|
+
self.assertEqual(concurrent, overlay.read_bytes())
|
|
2704
|
+
self.assertEqual(engineering_before, (repo / "docs" / "ENGINEERING.md").read_bytes())
|
|
2705
|
+
|
|
2706
|
+
def test_upgrade_write_is_retired_before_any_migration(self) -> None:
|
|
2381
2707
|
cfg = base_config()
|
|
2382
2708
|
cfg["gate"]["full_on"] = {"paths": ["src/**"]}
|
|
2383
2709
|
cfg["gate"]["rules"] = [
|
|
@@ -2405,17 +2731,15 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
2405
2731
|
}
|
|
2406
2732
|
]
|
|
2407
2733
|
)
|
|
2734
|
+
before = engineering.read_bytes()
|
|
2408
2735
|
args = argparse.Namespace(repo=str(repo), write=True, dry_run=False, json=False)
|
|
2409
2736
|
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
2410
|
-
|
|
2737
|
+
with self.assertRaises(APError) as context:
|
|
2738
|
+
ap.cmd_upgrade(args)
|
|
2411
2739
|
|
|
2412
|
-
|
|
2413
|
-
self.
|
|
2414
|
-
self.
|
|
2415
|
-
self.assertEqual("high-risk", migrated["risk"]["rules"][0]["profile"])
|
|
2416
|
-
self.assertEqual(["gate_full"], migrated["validation"]["routes"][-1]["commands"])
|
|
2417
|
-
self.assertEqual("true", migrated["commands"]["gate_full"])
|
|
2418
|
-
self.assertNotIn("must run the full gate", body)
|
|
2740
|
+
self.assertIn("transactional installer", str(context.exception))
|
|
2741
|
+
self.assertEqual(before, engineering.read_bytes())
|
|
2742
|
+
self.assertFalse((repo / ".agents").exists())
|
|
2419
2743
|
|
|
2420
2744
|
def test_upgrade_unknown_policy_conflict_fails_before_any_write(self) -> None:
|
|
2421
2745
|
repo, _ = self.make_repo()
|
|
@@ -2426,14 +2750,19 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
2426
2750
|
encoding="utf-8",
|
|
2427
2751
|
)
|
|
2428
2752
|
before = engineering.read_text(encoding="utf-8")
|
|
2429
|
-
args = argparse.Namespace(repo=str(repo), write=
|
|
2753
|
+
args = argparse.Namespace(repo=str(repo), write=False, dry_run=True, json=False)
|
|
2430
2754
|
with mock.patch.object(
|
|
2431
2755
|
ap,
|
|
2432
|
-
"
|
|
2433
|
-
return_value=
|
|
2756
|
+
"_project_config_convergence_plan",
|
|
2757
|
+
return_value={},
|
|
2434
2758
|
):
|
|
2435
|
-
with
|
|
2436
|
-
ap
|
|
2759
|
+
with mock.patch.object(
|
|
2760
|
+
ap,
|
|
2761
|
+
"_load_workflow_migration_policy",
|
|
2762
|
+
return_value=self.workflow_policy(),
|
|
2763
|
+
):
|
|
2764
|
+
with self.assertRaises(APError) as context:
|
|
2765
|
+
ap.cmd_upgrade(args)
|
|
2437
2766
|
self.assertIn("docs/ENGINEERING.md", str(context.exception))
|
|
2438
2767
|
self.assertEqual(before, engineering.read_text(encoding="utf-8"))
|
|
2439
2768
|
self.assertFalse((repo / ".agents").exists())
|