@elvis1513/auto-coding-skill 4.3.7 → 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 -761
- package/cli/assets/managed-install.json +38 -1
- package/cli/assets/skill/SKILL.md +15 -100
- 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 -145
- 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 -17791
- 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 -3602
- package/cli/tests/ap_profiles_test.py +0 -3272
- package/cli/tests/core_shell_test.py +0 -345
- package/cli/tests/index.test.js +0 -2967
|
@@ -1,3272 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import argparse
|
|
5
|
-
import base64
|
|
6
|
-
import contextlib
|
|
7
|
-
import hashlib
|
|
8
|
-
import io
|
|
9
|
-
import json
|
|
10
|
-
import os
|
|
11
|
-
import re
|
|
12
|
-
import shlex
|
|
13
|
-
import signal
|
|
14
|
-
import subprocess
|
|
15
|
-
import sys
|
|
16
|
-
import tempfile
|
|
17
|
-
import threading
|
|
18
|
-
import time
|
|
19
|
-
import tomllib
|
|
20
|
-
import unittest
|
|
21
|
-
from pathlib import Path
|
|
22
|
-
from unittest import mock
|
|
23
|
-
|
|
24
|
-
import yaml
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
28
|
-
SCRIPT_DIR = REPO_ROOT / "src" / "auto-coding-skill" / "scripts"
|
|
29
|
-
sys.path.insert(0, str(SCRIPT_DIR))
|
|
30
|
-
|
|
31
|
-
import ap # noqa: E402
|
|
32
|
-
from core import APError # noqa: E402
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def run(repo: Path, *args: str) -> None:
|
|
36
|
-
subprocess.run(list(args), cwd=repo, check=True, text=True, capture_output=True)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def base_config() -> dict:
|
|
40
|
-
return {
|
|
41
|
-
"workflow": {"mode": "dev", "profile": "auto", "completion": "push"},
|
|
42
|
-
"concurrency": {"isolation": "adaptive"},
|
|
43
|
-
"project": {"name": "profile-test"},
|
|
44
|
-
"access": {
|
|
45
|
-
"project": {
|
|
46
|
-
"frontend": {"url": "https://project-front.test", "username": "front", "password": "front-pass"},
|
|
47
|
-
"backend": {"url": "https://project-back.test", "username": "back", "password": "back-pass"},
|
|
48
|
-
},
|
|
49
|
-
"jenkins": {
|
|
50
|
-
"frontend": {"url": "https://jenkins-front.test", "username": "front", "password": "front-pass"},
|
|
51
|
-
"backend": {"url": "https://jenkins-back.test", "username": "back", "password": "back-pass"},
|
|
52
|
-
},
|
|
53
|
-
"gitlab": {"url": "https://gitlab.test", "username": "git", "password": "git-pass"},
|
|
54
|
-
"nexus": {
|
|
55
|
-
"frontend": {"url": "https://nexus.test", "username": "nexus", "password": "nexus-pass"},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
"commands": {
|
|
59
|
-
"gate_changed": "true",
|
|
60
|
-
"gate_standard": "true",
|
|
61
|
-
"gate_full": "true",
|
|
62
|
-
},
|
|
63
|
-
"gate": {
|
|
64
|
-
"default_scope": "auto",
|
|
65
|
-
"fallback_scope": "changed",
|
|
66
|
-
"full_on_unknown": False,
|
|
67
|
-
"no_change_scope": "changed",
|
|
68
|
-
"rules": [],
|
|
69
|
-
},
|
|
70
|
-
"structure": {"enabled": False, "enforcement": "advisory"},
|
|
71
|
-
"verification": {"target_env_required": False, "jenkins_required": False},
|
|
72
|
-
"docs": {
|
|
73
|
-
"taskbook": "docs/tasks/taskbook.md",
|
|
74
|
-
"closure_log": "docs/tasks/closure-log.md",
|
|
75
|
-
"evidence_log": "docs/tasks/evidence.jsonl",
|
|
76
|
-
"design_dir": "docs/design",
|
|
77
|
-
"ledger_check_enabled": True,
|
|
78
|
-
},
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
class AutoCodingProfileTests(unittest.TestCase):
|
|
83
|
-
@staticmethod
|
|
84
|
-
def workflow_policy(*, fragments: list[dict] | None = None) -> dict:
|
|
85
|
-
return {
|
|
86
|
-
"schema_version": 1,
|
|
87
|
-
"managed_versions": {"agents": "3.0.2", "engineering": "3.0.2"},
|
|
88
|
-
"known_official_engineering_body_sha256": [],
|
|
89
|
-
"known_official_fragments": fragments or [],
|
|
90
|
-
"conflict_rules": [
|
|
91
|
-
{
|
|
92
|
-
"id": "mandatory-full",
|
|
93
|
-
"paths": ["AGENTS.md", "docs/ENGINEERING.md"],
|
|
94
|
-
"pattern": r"^.*must run the full gate.*$",
|
|
95
|
-
"flags": "im",
|
|
96
|
-
"message": "full gate is not automatic",
|
|
97
|
-
}
|
|
98
|
-
],
|
|
99
|
-
"dependency_recovery": {
|
|
100
|
-
"allowed_gate": "gate_changed",
|
|
101
|
-
"requires_locked_dependency": True,
|
|
102
|
-
"retry_same_gate_only": True,
|
|
103
|
-
"forbid_full_gate_recovery": True,
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@staticmethod
|
|
108
|
-
def reviewer_assignment(**overrides: object) -> dict:
|
|
109
|
-
assignment = {
|
|
110
|
-
"contract_version": 1,
|
|
111
|
-
"node_id": "reviewer-1",
|
|
112
|
-
"task_id": "T001",
|
|
113
|
-
"role": "reviewer",
|
|
114
|
-
"base_sha": "HEAD",
|
|
115
|
-
"scope": "review owned diff",
|
|
116
|
-
"depends_on": ["fixer-1"],
|
|
117
|
-
"acceptance": ["review current fingerprint"],
|
|
118
|
-
"diff_base": "HEAD~1",
|
|
119
|
-
"diff_head": "HEAD",
|
|
120
|
-
"diff_fingerprint": "a" * 64,
|
|
121
|
-
"diff_artifact_path": "/tmp/review.patch",
|
|
122
|
-
"diff_artifact_sha256": "b" * 64,
|
|
123
|
-
"diff_artifact_format": "git-binary-patch-v1",
|
|
124
|
-
"owning_fixer": "fixer-1",
|
|
125
|
-
}
|
|
126
|
-
assignment.update(overrides)
|
|
127
|
-
return assignment
|
|
128
|
-
|
|
129
|
-
def make_repo(self, change_path: str | None = None, config: dict | None = None) -> tuple[Path, dict]:
|
|
130
|
-
temp = tempfile.TemporaryDirectory(prefix="autocoding-profile-")
|
|
131
|
-
self.addCleanup(temp.cleanup)
|
|
132
|
-
repo = Path(temp.name)
|
|
133
|
-
cfg = config or base_config()
|
|
134
|
-
run(repo, "git", "init", "-q")
|
|
135
|
-
run(repo, "git", "config", "user.email", "test@example.com")
|
|
136
|
-
run(repo, "git", "config", "user.name", "Auto Coding Test")
|
|
137
|
-
self.write_config(repo, cfg)
|
|
138
|
-
(repo / "docs" / "tasks").mkdir(parents=True, exist_ok=True)
|
|
139
|
-
(repo / "docs" / "tasks" / "taskbook.md").write_text("# Taskbook\n", encoding="utf-8")
|
|
140
|
-
(repo / "docs" / "tasks" / "closure-log.md").write_text("# Closure Log\n", encoding="utf-8")
|
|
141
|
-
run(repo, "git", "add", "-A")
|
|
142
|
-
run(repo, "git", "commit", "-qm", "baseline")
|
|
143
|
-
if change_path:
|
|
144
|
-
target = repo / change_path
|
|
145
|
-
target.parent.mkdir(parents=True, exist_ok=True)
|
|
146
|
-
target.write_text("change\n", encoding="utf-8")
|
|
147
|
-
return repo, cfg
|
|
148
|
-
|
|
149
|
-
def test_direct_cleanup_restores_active_state_when_registry_removal_fails(self) -> None:
|
|
150
|
-
repo, _ = self.make_repo()
|
|
151
|
-
manifest = {
|
|
152
|
-
"task_id": "DIRECT-CLEANUP-RETRY",
|
|
153
|
-
"task_uuid": "direct-cleanup-uuid",
|
|
154
|
-
"worktree_path": str(repo),
|
|
155
|
-
}
|
|
156
|
-
active_path = ap._worktree_manifest_path(repo)
|
|
157
|
-
ap._write_json_object(active_path, manifest)
|
|
158
|
-
|
|
159
|
-
with mock.patch.object(
|
|
160
|
-
ap,
|
|
161
|
-
"_delete_task_manifest",
|
|
162
|
-
side_effect=APError("simulated registry failure"),
|
|
163
|
-
):
|
|
164
|
-
with self.assertRaisesRegex(APError, "simulated registry failure"):
|
|
165
|
-
ap._clear_direct_task(repo, manifest)
|
|
166
|
-
|
|
167
|
-
restored = ap._read_json_object(active_path)
|
|
168
|
-
self.assertIsNotNone(restored)
|
|
169
|
-
self.assertEqual(manifest["task_uuid"], restored["task_uuid"])
|
|
170
|
-
|
|
171
|
-
def test_registry_failure_preserves_review_evidence_for_retry(self) -> None:
|
|
172
|
-
repo, _ = self.make_repo()
|
|
173
|
-
manifest = {
|
|
174
|
-
"task_id": "CLEANUP-EVIDENCE",
|
|
175
|
-
"task_uuid": "cleanup-evidence-uuid",
|
|
176
|
-
"worktree_path": str(repo),
|
|
177
|
-
}
|
|
178
|
-
registry_path = ap._task_registry_path(repo, manifest["task_id"])
|
|
179
|
-
ap._write_json_object(registry_path, manifest)
|
|
180
|
-
review_dir = ap._task_review_dir(repo, manifest["task_id"], create=True)
|
|
181
|
-
evidence_path = review_dir / "evidence.patch"
|
|
182
|
-
ap._write_private_bytes(evidence_path, b"immutable evidence\n")
|
|
183
|
-
original_unlink = Path.unlink
|
|
184
|
-
|
|
185
|
-
def fail_registry_unlink(path: Path, *args: object, **kwargs: object) -> None:
|
|
186
|
-
if path == registry_path:
|
|
187
|
-
raise PermissionError("simulated registry permission failure")
|
|
188
|
-
original_unlink(path, *args, **kwargs)
|
|
189
|
-
|
|
190
|
-
with mock.patch.object(Path, "unlink", new=fail_registry_unlink):
|
|
191
|
-
with self.assertRaisesRegex(APError, "Cannot remove task registry state"):
|
|
192
|
-
ap._delete_task_manifest(repo, manifest)
|
|
193
|
-
|
|
194
|
-
self.assertTrue(registry_path.exists())
|
|
195
|
-
self.assertEqual(b"immutable evidence\n", evidence_path.read_bytes())
|
|
196
|
-
|
|
197
|
-
def test_review_directory_read_validation_is_mutation_free(self) -> None:
|
|
198
|
-
repo, _ = self.make_repo()
|
|
199
|
-
review_dir = ap._task_review_dir(repo, "READ-ONLY-GUARD", create=True)
|
|
200
|
-
common_dir = ap._git_common_dir(repo).resolve()
|
|
201
|
-
|
|
202
|
-
with mock.patch.object(Path, "chmod", side_effect=PermissionError("read-only sandbox")):
|
|
203
|
-
ap._guard_review_directory(review_dir, common_dir, create=False)
|
|
204
|
-
|
|
205
|
-
os.chmod(review_dir, 0o755)
|
|
206
|
-
with self.assertRaisesRegex(APError, "must use mode 0700"):
|
|
207
|
-
ap._guard_review_directory(review_dir, common_dir, create=False)
|
|
208
|
-
|
|
209
|
-
@staticmethod
|
|
210
|
-
def write_config(repo: Path, cfg: dict) -> None:
|
|
211
|
-
path = repo / "docs" / "ENGINEERING.md"
|
|
212
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
213
|
-
path.write_text(
|
|
214
|
-
"---\n" + yaml.safe_dump(cfg, allow_unicode=True, sort_keys=False) + "---\n# Engineering\n",
|
|
215
|
-
encoding="utf-8",
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
def plan(self, repo: Path, cfg: dict, **kwargs: str) -> dict:
|
|
219
|
-
return ap._resolve_execution_plan(cfg, repo, **kwargs)
|
|
220
|
-
|
|
221
|
-
@staticmethod
|
|
222
|
-
def commit_args(
|
|
223
|
-
repo: Path,
|
|
224
|
-
*,
|
|
225
|
-
profile: str,
|
|
226
|
-
mode: str,
|
|
227
|
-
result: str,
|
|
228
|
-
) -> argparse.Namespace:
|
|
229
|
-
return argparse.Namespace(
|
|
230
|
-
repo=str(repo),
|
|
231
|
-
task_id="T001",
|
|
232
|
-
title="profile closure",
|
|
233
|
-
msg="T001: profile closure",
|
|
234
|
-
mode=mode,
|
|
235
|
-
profile=profile,
|
|
236
|
-
require_light_gate=False,
|
|
237
|
-
require_runtime_health=False,
|
|
238
|
-
require_jenkins=False,
|
|
239
|
-
require_matrix=False,
|
|
240
|
-
record_closure=False,
|
|
241
|
-
job_name=None,
|
|
242
|
-
job_url=None,
|
|
243
|
-
multibranch_root_job=None,
|
|
244
|
-
branch_name=None,
|
|
245
|
-
build_number=None,
|
|
246
|
-
max_builds=20,
|
|
247
|
-
timeout_sec=1,
|
|
248
|
-
poll_sec=1,
|
|
249
|
-
allow_no_deploy=False,
|
|
250
|
-
backend_path=None,
|
|
251
|
-
frontend_path=None,
|
|
252
|
-
backend_basic_auth=False,
|
|
253
|
-
frontend_basic_auth=False,
|
|
254
|
-
jenkins_build=None,
|
|
255
|
-
target_env=None,
|
|
256
|
-
verification=None,
|
|
257
|
-
structure_check=None,
|
|
258
|
-
result=result,
|
|
259
|
-
follow_up=None,
|
|
260
|
-
initial_commit=None,
|
|
261
|
-
jenkins_failure=None,
|
|
262
|
-
fix_commit=None,
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
@staticmethod
|
|
266
|
-
def closure_args(
|
|
267
|
-
repo: Path,
|
|
268
|
-
*,
|
|
269
|
-
result: str,
|
|
270
|
-
profile: str = "",
|
|
271
|
-
verification: list[str] | None = None,
|
|
272
|
-
) -> argparse.Namespace:
|
|
273
|
-
return argparse.Namespace(
|
|
274
|
-
repo=str(repo),
|
|
275
|
-
task_id="T001",
|
|
276
|
-
title="manual closure",
|
|
277
|
-
commit="HEAD",
|
|
278
|
-
jenkins=None,
|
|
279
|
-
target_env=None,
|
|
280
|
-
verification=["manual evidence"] if verification is None else verification,
|
|
281
|
-
profile=profile,
|
|
282
|
-
structure_check="passed",
|
|
283
|
-
result=result,
|
|
284
|
-
follow_up=None,
|
|
285
|
-
initial_commit=None,
|
|
286
|
-
jenkins_failure=None,
|
|
287
|
-
fix_commit=None,
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
@staticmethod
|
|
291
|
-
def record_closure(repo: Path, args: argparse.Namespace) -> Path:
|
|
292
|
-
with mock.patch.object(ap, "_require_task_context", return_value={"task_id": args.task_id}):
|
|
293
|
-
ap.cmd_record_closure(args)
|
|
294
|
-
return repo / "docs" / "tasks" / "closures" / f"{args.task_id}.md"
|
|
295
|
-
|
|
296
|
-
def test_docs_only_resolves_micro(self) -> None:
|
|
297
|
-
repo, cfg = self.make_repo("docs/security-auth-notes.md")
|
|
298
|
-
plan = self.plan(repo, cfg)
|
|
299
|
-
self.assertEqual("micro", plan["profile"])
|
|
300
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
301
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
302
|
-
self.assertEqual([], plan["recommended_agents"])
|
|
303
|
-
self.assertEqual("main-only", plan["agent_plan"]["strategy"])
|
|
304
|
-
self.assertEqual(1, plan["contract_version"])
|
|
305
|
-
self.assertEqual("data/contracts/orchestration-v1.schema.json", plan["contract_schema"])
|
|
306
|
-
for field in [
|
|
307
|
-
"contract_version",
|
|
308
|
-
"contract_schema",
|
|
309
|
-
"policies",
|
|
310
|
-
"assignment_contract",
|
|
311
|
-
"result_contract",
|
|
312
|
-
"stages",
|
|
313
|
-
"constraints",
|
|
314
|
-
"optional_roles",
|
|
315
|
-
]:
|
|
316
|
-
self.assertIn(field, plan["agent_plan"])
|
|
317
|
-
|
|
318
|
-
def test_planned_files_and_intent_drive_classification_without_polluting_changed_files(self) -> None:
|
|
319
|
-
repo, cfg = self.make_repo()
|
|
320
|
-
plan = self.plan(
|
|
321
|
-
repo,
|
|
322
|
-
cfg,
|
|
323
|
-
planned_paths=["src/frontend/LoginPage.tsx"],
|
|
324
|
-
intent="新增登录鉴权页面并发布",
|
|
325
|
-
)
|
|
326
|
-
self.assertEqual([], plan["changed_files"])
|
|
327
|
-
self.assertEqual(["src/frontend/LoginPage.tsx"], plan["planned_files"])
|
|
328
|
-
self.assertEqual(["src/frontend/LoginPage.tsx"], plan["classification_files"])
|
|
329
|
-
self.assertTrue(plan["intent_provided"])
|
|
330
|
-
self.assertEqual(["auth", "release_or_tooling", "ui"], plan["intent_categories"])
|
|
331
|
-
self.assertEqual(["auth", "release_or_tooling"], plan["intent_risk_candidates"])
|
|
332
|
-
self.assertTrue(plan["needs_browser"])
|
|
333
|
-
self.assertEqual("standard", plan["profile"])
|
|
334
|
-
self.assertFalse(plan["review_required"])
|
|
335
|
-
self.assertEqual([], plan["recommended_agents"])
|
|
336
|
-
self.assertEqual([], plan["optional_agents"])
|
|
337
|
-
self.assertNotIn("browser_debugger", plan["recommended_agents"])
|
|
338
|
-
self.assertNotIn("docs_researcher", plan["recommended_agents"])
|
|
339
|
-
self.assertNotIn("新增登录鉴权页面并发布", str(plan))
|
|
340
|
-
|
|
341
|
-
def test_ordinary_code_resolves_standard(self) -> None:
|
|
342
|
-
repo, cfg = self.make_repo()
|
|
343
|
-
plan = self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
344
|
-
self.assertEqual("standard", plan["profile"])
|
|
345
|
-
self.assertEqual("change", plan["task_kind"])
|
|
346
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
347
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
348
|
-
self.assertEqual([], plan["recommended_agents"])
|
|
349
|
-
agent_plan = plan["agent_plan"]
|
|
350
|
-
self.assertEqual("main-only", agent_plan["strategy"])
|
|
351
|
-
self.assertEqual(["delivery"], [stage["id"] for stage in agent_plan["stages"]])
|
|
352
|
-
self.assertTrue(agent_plan["policies"]["one_writer_per_worktree"])
|
|
353
|
-
self.assertEqual("explicit-only-for-isolated-or-delegated-work", agent_plan["policies"]["path_ownership"])
|
|
354
|
-
self.assertEqual(
|
|
355
|
-
"integrate-before-dependent-start",
|
|
356
|
-
agent_plan["policies"]["dependency_policy"],
|
|
357
|
-
)
|
|
358
|
-
self.assertEqual("main", agent_plan["policies"]["review_feedback_owner"])
|
|
359
|
-
self.assertEqual("diff-fingerprint-when-required", agent_plan["policies"]["review_binding"])
|
|
360
|
-
self.assertEqual("main", agent_plan["policies"]["lifecycle_owner"])
|
|
361
|
-
self.assertIn("owned_paths", agent_plan["assignment_contract"]["writer"])
|
|
362
|
-
self.assertIn("diff_fingerprint", agent_plan["assignment_contract"]["reviewer"])
|
|
363
|
-
self.assertIn("diff_fingerprint", agent_plan["result_contract"])
|
|
364
|
-
delivery = next(stage for stage in agent_plan["stages"] if stage["id"] == "delivery")
|
|
365
|
-
self.assertEqual("serial", delivery["mode"])
|
|
366
|
-
self.assertFalse(plan["review_required"])
|
|
367
|
-
self.assertEqual(
|
|
368
|
-
["analysis", "final_changed_scope_gate", "commit_push"],
|
|
369
|
-
plan["mechanism_plan"]["required"],
|
|
370
|
-
)
|
|
371
|
-
self.assertFalse(plan["mechanism_plan"]["lifecycle_required"])
|
|
372
|
-
self.assertIn("read_only_subagents", plan["mechanism_plan"]["optional_when_beneficial"])
|
|
373
|
-
self.assertNotIn("parallel_fixers", plan["mechanism_plan"]["optional_when_beneficial"])
|
|
374
|
-
self.assertIn("task_lifecycle", plan["mechanism_plan"]["forbidden"])
|
|
375
|
-
self.assertIn("parallel_fixers", plan["mechanism_plan"]["forbidden"])
|
|
376
|
-
|
|
377
|
-
def test_intent_only_classifies_read_only_change_and_terminal_work(self) -> None:
|
|
378
|
-
repo, cfg = self.make_repo()
|
|
379
|
-
read_only = self.plan(repo, cfg, intent="Explain how authentication currently works")
|
|
380
|
-
self.assertEqual("read_only", read_only["task_kind"])
|
|
381
|
-
self.assertEqual("none", read_only["execution_mode"])
|
|
382
|
-
self.assertEqual(["analysis"], read_only["mechanism_plan"]["required"])
|
|
383
|
-
self.assertIn(
|
|
384
|
-
"read_only_subagents",
|
|
385
|
-
read_only["mechanism_plan"]["optional_when_beneficial"],
|
|
386
|
-
)
|
|
387
|
-
self.assertIn("commit_push", read_only["mechanism_plan"]["forbidden"])
|
|
388
|
-
|
|
389
|
-
change = self.plan(repo, cfg, intent="Fix the login redirect bug")
|
|
390
|
-
self.assertEqual("change", change["task_kind"])
|
|
391
|
-
self.assertEqual("direct", change["execution_mode"])
|
|
392
|
-
self.assertIn("commit_push", change["mechanism_plan"]["required"])
|
|
393
|
-
|
|
394
|
-
chinese_change = self.plan(repo, cfg, intent="请解决并优化登录跳转问题")
|
|
395
|
-
self.assertEqual("change", chinese_change["task_kind"])
|
|
396
|
-
|
|
397
|
-
forced_read_only = self.plan(
|
|
398
|
-
repo,
|
|
399
|
-
cfg,
|
|
400
|
-
intent="Fix wording in the explanation",
|
|
401
|
-
requested_task_kind="read_only",
|
|
402
|
-
)
|
|
403
|
-
self.assertEqual("read_only", forced_read_only["task_kind"])
|
|
404
|
-
|
|
405
|
-
terminal = self.plan(
|
|
406
|
-
repo,
|
|
407
|
-
cfg,
|
|
408
|
-
intent="reconcile the completed task ledger",
|
|
409
|
-
)
|
|
410
|
-
self.assertEqual("terminal_maintenance", terminal["task_kind"])
|
|
411
|
-
self.assertEqual(
|
|
412
|
-
["analysis", "targeted_consistency_check", "commit_push"],
|
|
413
|
-
terminal["mechanism_plan"]["required"],
|
|
414
|
-
)
|
|
415
|
-
self.assertIn("task_lifecycle", terminal["mechanism_plan"]["forbidden"])
|
|
416
|
-
|
|
417
|
-
with self.assertRaises(APError):
|
|
418
|
-
self.plan(
|
|
419
|
-
repo,
|
|
420
|
-
cfg,
|
|
421
|
-
planned_paths=["src/payment/service.py"],
|
|
422
|
-
requested_task_kind="terminal_maintenance",
|
|
423
|
-
)
|
|
424
|
-
with self.assertRaises(APError):
|
|
425
|
-
self.plan(
|
|
426
|
-
repo,
|
|
427
|
-
cfg,
|
|
428
|
-
planned_paths=["src/widget.py"],
|
|
429
|
-
requested_task_kind="none",
|
|
430
|
-
)
|
|
431
|
-
|
|
432
|
-
def test_execution_mode_is_none_direct_isolated_or_parallel(self) -> None:
|
|
433
|
-
repo, cfg = self.make_repo()
|
|
434
|
-
self.assertEqual("none", self.plan(repo, cfg)["execution_mode"])
|
|
435
|
-
direct = self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
436
|
-
self.assertEqual("direct", direct["execution_mode"])
|
|
437
|
-
dirty = repo / "existing.txt"
|
|
438
|
-
dirty.write_text("user change\n", encoding="utf-8")
|
|
439
|
-
isolated = self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
440
|
-
self.assertEqual("isolated", isolated["execution_mode"])
|
|
441
|
-
self.assertTrue(isolated["mechanism_plan"]["lifecycle_required"])
|
|
442
|
-
self.assertIn("worktree", isolated["mechanism_plan"]["required"])
|
|
443
|
-
dirty.unlink()
|
|
444
|
-
parallel = self.plan(
|
|
445
|
-
repo,
|
|
446
|
-
cfg,
|
|
447
|
-
planned_paths=["src/widget.py"],
|
|
448
|
-
parallel_writers=2,
|
|
449
|
-
)
|
|
450
|
-
self.assertEqual("isolated", parallel["execution_mode"])
|
|
451
|
-
self.assertTrue(parallel["review_required"])
|
|
452
|
-
self.assertIn("fixer", parallel["recommended_agents"])
|
|
453
|
-
self.assertIn("parallel_fixers", parallel["mechanism_plan"]["required"])
|
|
454
|
-
self.assertEqual("orchestrated-subagents", parallel["agent_plan"]["strategy"])
|
|
455
|
-
|
|
456
|
-
def test_working_tree_snapshot_covers_clean_unstaged_staged_and_untracked_paths(self) -> None:
|
|
457
|
-
repo, _ = self.make_repo()
|
|
458
|
-
unstaged = repo / "tracked unstaged.txt"
|
|
459
|
-
staged = repo / "tracked-staged.txt"
|
|
460
|
-
unstaged.write_text("baseline\n", encoding="utf-8")
|
|
461
|
-
staged.write_text("baseline\n", encoding="utf-8")
|
|
462
|
-
run(repo, "git", "add", "tracked unstaged.txt", "tracked-staged.txt")
|
|
463
|
-
run(repo, "git", "commit", "-qm", "add status fixtures")
|
|
464
|
-
|
|
465
|
-
self.assertEqual([], ap._working_tree_paths(repo))
|
|
466
|
-
|
|
467
|
-
unstaged.write_text("unstaged change\n", encoding="utf-8")
|
|
468
|
-
staged.write_text("staged change\n", encoding="utf-8")
|
|
469
|
-
run(repo, "git", "add", "tracked-staged.txt")
|
|
470
|
-
(repo / "untracked path.txt").write_text("untracked\n", encoding="utf-8")
|
|
471
|
-
(repo / "untracked\nline.txt").write_text("untracked newline\n", encoding="utf-8")
|
|
472
|
-
|
|
473
|
-
self.assertEqual(
|
|
474
|
-
[
|
|
475
|
-
"tracked unstaged.txt",
|
|
476
|
-
"tracked-staged.txt",
|
|
477
|
-
"untracked\nline.txt",
|
|
478
|
-
"untracked path.txt",
|
|
479
|
-
],
|
|
480
|
-
ap._working_tree_paths(repo),
|
|
481
|
-
)
|
|
482
|
-
|
|
483
|
-
def test_working_tree_snapshot_includes_both_staged_rename_endpoints(self) -> None:
|
|
484
|
-
repo, _ = self.make_repo()
|
|
485
|
-
source = repo / "old name.txt"
|
|
486
|
-
source.write_text("stable\n", encoding="utf-8")
|
|
487
|
-
run(repo, "git", "add", "old name.txt")
|
|
488
|
-
run(repo, "git", "commit", "-qm", "add rename fixture")
|
|
489
|
-
|
|
490
|
-
run(repo, "git", "mv", "old name.txt", "new name.txt")
|
|
491
|
-
|
|
492
|
-
self.assertEqual(
|
|
493
|
-
["new name.txt", "old name.txt"],
|
|
494
|
-
ap._working_tree_paths(repo),
|
|
495
|
-
)
|
|
496
|
-
|
|
497
|
-
def test_working_tree_snapshot_fails_closed_on_git_error_or_malformed_output(self) -> None:
|
|
498
|
-
repo, _ = self.make_repo()
|
|
499
|
-
failed = subprocess.CompletedProcess(
|
|
500
|
-
args=["git", "status"],
|
|
501
|
-
returncode=128,
|
|
502
|
-
stdout="",
|
|
503
|
-
stderr="fatal: status unavailable",
|
|
504
|
-
)
|
|
505
|
-
with mock.patch.object(ap, "run", return_value=failed):
|
|
506
|
-
with self.assertRaises(APError) as context:
|
|
507
|
-
ap._working_tree_paths(repo)
|
|
508
|
-
self.assertIn("refusing a direct execution plan", str(context.exception))
|
|
509
|
-
self.assertIn("status unavailable", str(context.exception))
|
|
510
|
-
|
|
511
|
-
malformed = subprocess.CompletedProcess(
|
|
512
|
-
args=["git", "status"],
|
|
513
|
-
returncode=0,
|
|
514
|
-
stdout="1 malformed\0",
|
|
515
|
-
stderr="",
|
|
516
|
-
)
|
|
517
|
-
with mock.patch.object(ap, "run", return_value=malformed):
|
|
518
|
-
with self.assertRaises(APError) as context:
|
|
519
|
-
ap._working_tree_paths(repo)
|
|
520
|
-
self.assertIn("Cannot parse Git working tree status", str(context.exception))
|
|
521
|
-
|
|
522
|
-
def test_writer_registries_fail_closed_when_json_is_corrupt(self) -> None:
|
|
523
|
-
repo, cfg = self.make_repo()
|
|
524
|
-
task_registry = ap._task_state_root(repo) / "tasks" / "T001.json"
|
|
525
|
-
task_registry.parent.mkdir(parents=True, exist_ok=True)
|
|
526
|
-
task_registry.write_text("{broken", encoding="utf-8")
|
|
527
|
-
with self.assertRaises(APError) as context:
|
|
528
|
-
self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
529
|
-
self.assertIn("Task registry is unreadable", str(context.exception))
|
|
530
|
-
|
|
531
|
-
task_registry.unlink()
|
|
532
|
-
claim_registry = (
|
|
533
|
-
ap._task_state_root(repo) / "direct-claims" / ("a" * 32 + ".json")
|
|
534
|
-
)
|
|
535
|
-
claim_registry.parent.mkdir(parents=True, exist_ok=True)
|
|
536
|
-
claim_registry.write_text("{broken", encoding="utf-8")
|
|
537
|
-
with self.assertRaises(APError) as context:
|
|
538
|
-
self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
539
|
-
self.assertIn("Direct claim registry is unreadable", str(context.exception))
|
|
540
|
-
|
|
541
|
-
def test_same_owner_direct_claim_is_rejected_and_not_implicitly_exempted(self) -> None:
|
|
542
|
-
repo, cfg = self.make_repo()
|
|
543
|
-
claim = ap._create_direct_claim(repo, cfg, ["src/widget.py"], "same-owner")
|
|
544
|
-
claim_path = ap._direct_claim_path(repo, claim["claim_id"])
|
|
545
|
-
|
|
546
|
-
plan = self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
547
|
-
self.assertTrue(plan["active_writer"])
|
|
548
|
-
self.assertEqual("isolated", plan["execution_mode"])
|
|
549
|
-
self.assertTrue(claim_path.exists())
|
|
550
|
-
self.assertEqual(claim["claim_id"], json.loads(claim_path.read_text())["claim_id"])
|
|
551
|
-
|
|
552
|
-
with self.assertRaises(APError) as context:
|
|
553
|
-
ap._create_direct_claim(repo, cfg, ["src/widget.py"], "same-owner")
|
|
554
|
-
self.assertIn(claim["claim_id"], str(context.exception))
|
|
555
|
-
self.assertTrue(claim_path.exists())
|
|
556
|
-
|
|
557
|
-
def test_continue_direct_accepts_only_declared_current_task_dirt(self) -> None:
|
|
558
|
-
repo, cfg = self.make_repo()
|
|
559
|
-
claim = ap._create_direct_claim(
|
|
560
|
-
repo,
|
|
561
|
-
cfg,
|
|
562
|
-
["src/widget.py"],
|
|
563
|
-
os.environ.get("CODEX_THREAD_ID") or "profile-test-owner",
|
|
564
|
-
)
|
|
565
|
-
target = repo / "src" / "widget.py"
|
|
566
|
-
target.parent.mkdir(parents=True, exist_ok=True)
|
|
567
|
-
target.write_text("task change\n", encoding="utf-8")
|
|
568
|
-
|
|
569
|
-
default = self.plan(repo, cfg, planned_paths=["src/widget.py"])
|
|
570
|
-
self.assertEqual("isolated", default["execution_mode"])
|
|
571
|
-
continued = self.plan(
|
|
572
|
-
repo,
|
|
573
|
-
cfg,
|
|
574
|
-
planned_paths=["src/widget.py"],
|
|
575
|
-
continue_direct=True,
|
|
576
|
-
direct_claim_id=claim["claim_id"],
|
|
577
|
-
)
|
|
578
|
-
self.assertEqual("direct", continued["execution_mode"])
|
|
579
|
-
self.assertTrue(continued["continued_direct"])
|
|
580
|
-
self.assertEqual([], continued["dirty_outside_plan"])
|
|
581
|
-
|
|
582
|
-
(repo / "unrelated.txt").write_text("other writer\n", encoding="utf-8")
|
|
583
|
-
with self.assertRaises(APError) as context:
|
|
584
|
-
self.plan(
|
|
585
|
-
repo,
|
|
586
|
-
cfg,
|
|
587
|
-
planned_paths=["src/widget.py"],
|
|
588
|
-
continue_direct=True,
|
|
589
|
-
direct_claim_id=claim["claim_id"],
|
|
590
|
-
)
|
|
591
|
-
self.assertIn("outside the clean direct claim", str(context.exception))
|
|
592
|
-
|
|
593
|
-
def test_continue_direct_requires_a_clean_pre_write_claim(self) -> None:
|
|
594
|
-
repo, cfg = self.make_repo()
|
|
595
|
-
(repo / "unknown.txt").write_text("pre-existing user change\n", encoding="utf-8")
|
|
596
|
-
with self.assertRaises(APError) as context:
|
|
597
|
-
ap._create_direct_claim(repo, cfg, ["."], "profile-test-owner")
|
|
598
|
-
self.assertIn("before the first write", str(context.exception))
|
|
599
|
-
with self.assertRaises(APError) as context:
|
|
600
|
-
self.plan(repo, cfg, planned_paths=["."], continue_direct=True)
|
|
601
|
-
self.assertIn("requires --direct-claim", str(context.exception))
|
|
602
|
-
|
|
603
|
-
def test_risk_intent_is_candidate_while_paths_and_rules_control_escalation(self) -> None:
|
|
604
|
-
repo, cfg = self.make_repo()
|
|
605
|
-
ui = self.plan(
|
|
606
|
-
repo,
|
|
607
|
-
cfg,
|
|
608
|
-
planned_paths=["frontend/src/LoginPage.tsx"],
|
|
609
|
-
intent="修复登录跳转问题",
|
|
610
|
-
)
|
|
611
|
-
self.assertEqual("standard", ui["profile"])
|
|
612
|
-
self.assertFalse(ui["review_required"])
|
|
613
|
-
self.assertEqual(["auth"], ui["intent_risk_candidates"])
|
|
614
|
-
self.assertEqual(["browser_debugger"], ui["optional_agents"])
|
|
615
|
-
|
|
616
|
-
backend = self.plan(repo, cfg, planned_paths=["backend/auth/service.py"])
|
|
617
|
-
self.assertEqual("high-risk", backend["profile"])
|
|
618
|
-
self.assertTrue(backend["review_required"])
|
|
619
|
-
self.assertEqual(["explorer"], backend["optional_agents"])
|
|
620
|
-
|
|
621
|
-
cfg["risk"] = {
|
|
622
|
-
"rules": [
|
|
623
|
-
{
|
|
624
|
-
"name": "sensitive-login-ui",
|
|
625
|
-
"paths": ["frontend/src/LoginPage.tsx"],
|
|
626
|
-
"profile": "high-risk",
|
|
627
|
-
}
|
|
628
|
-
]
|
|
629
|
-
}
|
|
630
|
-
configured = self.plan(repo, cfg, planned_paths=["frontend/src/LoginPage.tsx"])
|
|
631
|
-
self.assertEqual("high-risk", configured["profile"])
|
|
632
|
-
|
|
633
|
-
order = self.plan(repo, cfg, planned_paths=["backend/orders/sort_order.py"])
|
|
634
|
-
self.assertNotIn("payment", order["categories"])
|
|
635
|
-
|
|
636
|
-
def test_high_confidence_intent_and_backend_login_escalate_without_ui_false_positive(self) -> None:
|
|
637
|
-
repo, cfg = self.make_repo()
|
|
638
|
-
for intent, category in [
|
|
639
|
-
("修改数据库迁移", "db"),
|
|
640
|
-
("修改后端鉴权权限", "auth"),
|
|
641
|
-
("修改支付结算逻辑", "payment"),
|
|
642
|
-
("修改生产网关配置", "gateway"),
|
|
643
|
-
]:
|
|
644
|
-
with self.subTest(intent=intent):
|
|
645
|
-
plan = self.plan(repo, cfg, intent=intent)
|
|
646
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
647
|
-
self.assertTrue(plan["review_required"])
|
|
648
|
-
self.assertIn(category, plan["high_confidence_intent_categories"])
|
|
649
|
-
|
|
650
|
-
backend_login = self.plan(
|
|
651
|
-
repo,
|
|
652
|
-
cfg,
|
|
653
|
-
planned_paths=["backend/login_handler.go"],
|
|
654
|
-
intent="修复登录处理",
|
|
655
|
-
)
|
|
656
|
-
self.assertEqual("high-risk", backend_login["profile"])
|
|
657
|
-
self.assertTrue(backend_login["review_required"])
|
|
658
|
-
|
|
659
|
-
login_ui = self.plan(
|
|
660
|
-
repo,
|
|
661
|
-
cfg,
|
|
662
|
-
planned_paths=["frontend/LoginPage.tsx"],
|
|
663
|
-
intent="修复登录页面跳转",
|
|
664
|
-
)
|
|
665
|
-
self.assertEqual("standard", login_ui["profile"])
|
|
666
|
-
self.assertFalse(login_ui["review_required"])
|
|
667
|
-
|
|
668
|
-
def test_generated_agent_strategies_match_contract_schema(self) -> None:
|
|
669
|
-
schema = json.loads(
|
|
670
|
-
(REPO_ROOT / "src" / "auto-coding-skill" / "data" / "contracts" / "orchestration-v1.schema.json")
|
|
671
|
-
.read_text(encoding="utf-8")
|
|
672
|
-
)
|
|
673
|
-
allowed = set(schema["$defs"]["agentPlan"]["properties"]["strategy"]["enum"])
|
|
674
|
-
repo, cfg = self.make_repo()
|
|
675
|
-
for kwargs in [
|
|
676
|
-
{"planned_paths": ["src/widget.py"]},
|
|
677
|
-
{"planned_paths": ["backend/auth/service.py"]},
|
|
678
|
-
{"planned_paths": ["src/widget.py"], "parallel_writers": 2},
|
|
679
|
-
]:
|
|
680
|
-
with self.subTest(kwargs=kwargs):
|
|
681
|
-
plan = self.plan(repo, cfg, **kwargs)
|
|
682
|
-
self.assertIn(plan["agent_plan"]["strategy"], allowed)
|
|
683
|
-
ap._validate_orchestration_contract("classify", plan)
|
|
684
|
-
|
|
685
|
-
def test_agent_assignment_and_result_contracts_are_machine_enforced(self) -> None:
|
|
686
|
-
fingerprint = "a" * 64
|
|
687
|
-
assignment = {
|
|
688
|
-
"contract_version": 1,
|
|
689
|
-
"node_id": "reviewer-1",
|
|
690
|
-
"task_id": "T001",
|
|
691
|
-
"role": "reviewer",
|
|
692
|
-
"base_sha": "HEAD",
|
|
693
|
-
"scope": "review owned diff",
|
|
694
|
-
"depends_on": [],
|
|
695
|
-
"acceptance": ["review current fingerprint"],
|
|
696
|
-
"diff_base": "HEAD~1",
|
|
697
|
-
"diff_head": "HEAD",
|
|
698
|
-
"diff_fingerprint": fingerprint,
|
|
699
|
-
"diff_artifact_path": "/tmp/review.patch",
|
|
700
|
-
"diff_artifact_sha256": "b" * 64,
|
|
701
|
-
"diff_artifact_format": "git-binary-patch-v1",
|
|
702
|
-
"owning_fixer": "fixer-1",
|
|
703
|
-
}
|
|
704
|
-
ap._validate_orchestration_contract("assignment", assignment)
|
|
705
|
-
self_review = dict(assignment, node_id="fixer-1")
|
|
706
|
-
with self.assertRaises(APError):
|
|
707
|
-
ap._validate_orchestration_contract("assignment", self_review)
|
|
708
|
-
|
|
709
|
-
result = {
|
|
710
|
-
"contract_version": 1,
|
|
711
|
-
"node_id": "reviewer-1",
|
|
712
|
-
"role": "reviewer",
|
|
713
|
-
"task_id": "T001",
|
|
714
|
-
"base_sha": "HEAD~1",
|
|
715
|
-
"status": "completed",
|
|
716
|
-
"summary": "reviewed",
|
|
717
|
-
"depends_on": [],
|
|
718
|
-
"owned_paths": [],
|
|
719
|
-
"changed_paths": [],
|
|
720
|
-
"diff_fingerprint": fingerprint,
|
|
721
|
-
"evidence": ["diff reviewed"],
|
|
722
|
-
"findings": [],
|
|
723
|
-
"verdict": "approved",
|
|
724
|
-
"risks": [],
|
|
725
|
-
"next_owner": "main",
|
|
726
|
-
}
|
|
727
|
-
ap._validate_orchestration_contract("result", result)
|
|
728
|
-
with self.assertRaises(APError):
|
|
729
|
-
ap._validate_orchestration_contract("result", dict(result, diff_fingerprint=""))
|
|
730
|
-
|
|
731
|
-
def test_reviewer_result_template_has_complete_contract_and_verdict_mappings(self) -> None:
|
|
732
|
-
assignment = self.reviewer_assignment()
|
|
733
|
-
required_fields = {
|
|
734
|
-
"contract_version",
|
|
735
|
-
"node_id",
|
|
736
|
-
"role",
|
|
737
|
-
"task_id",
|
|
738
|
-
"base_sha",
|
|
739
|
-
"status",
|
|
740
|
-
"summary",
|
|
741
|
-
"depends_on",
|
|
742
|
-
"owned_paths",
|
|
743
|
-
"changed_paths",
|
|
744
|
-
"diff_fingerprint",
|
|
745
|
-
"evidence",
|
|
746
|
-
"findings",
|
|
747
|
-
"verdict",
|
|
748
|
-
"risks",
|
|
749
|
-
"next_owner",
|
|
750
|
-
}
|
|
751
|
-
for verdict, status, next_owner in [
|
|
752
|
-
("approved", "completed", "main"),
|
|
753
|
-
("changes-requested", "completed", "fixer-1"),
|
|
754
|
-
("blocked", "blocked", "main"),
|
|
755
|
-
]:
|
|
756
|
-
with self.subTest(verdict=verdict):
|
|
757
|
-
result = ap._reviewer_result_template(assignment, verdict)
|
|
758
|
-
self.assertEqual(required_fields, set(result))
|
|
759
|
-
self.assertEqual("reviewer", result["role"])
|
|
760
|
-
self.assertEqual("reviewer-1", result["node_id"])
|
|
761
|
-
self.assertEqual("T001", result["task_id"])
|
|
762
|
-
self.assertEqual("HEAD", result["base_sha"])
|
|
763
|
-
self.assertEqual(["fixer-1"], result["depends_on"])
|
|
764
|
-
self.assertEqual([], result["owned_paths"])
|
|
765
|
-
self.assertEqual([], result["changed_paths"])
|
|
766
|
-
self.assertEqual("a" * 64, result["diff_fingerprint"])
|
|
767
|
-
self.assertEqual(verdict, result["verdict"])
|
|
768
|
-
self.assertEqual(status, result["status"])
|
|
769
|
-
self.assertEqual(next_owner, result["next_owner"])
|
|
770
|
-
ap._validate_orchestration_contract("result", result)
|
|
771
|
-
|
|
772
|
-
def test_reviewer_runtime_normalizes_presentation_fields_but_binds_identity(self) -> None:
|
|
773
|
-
assignment = self.reviewer_assignment()
|
|
774
|
-
result = ap._normalize_reviewer_runtime_result(
|
|
775
|
-
assignment,
|
|
776
|
-
{
|
|
777
|
-
"verdict": "approved",
|
|
778
|
-
"summary": "focused review complete",
|
|
779
|
-
"evidence": ["diff inspected"],
|
|
780
|
-
},
|
|
781
|
-
)
|
|
782
|
-
self.assertEqual("reviewer-1", result["node_id"])
|
|
783
|
-
self.assertEqual("a" * 64, result["diff_fingerprint"])
|
|
784
|
-
self.assertEqual(["fixer-1"], result["depends_on"])
|
|
785
|
-
self.assertEqual("focused review complete", result["summary"])
|
|
786
|
-
|
|
787
|
-
with self.assertRaisesRegex(APError, "does not match its assignment"):
|
|
788
|
-
ap._normalize_reviewer_runtime_result(
|
|
789
|
-
assignment,
|
|
790
|
-
{
|
|
791
|
-
"verdict": "approved",
|
|
792
|
-
"diff_fingerprint": "b" * 64,
|
|
793
|
-
},
|
|
794
|
-
)
|
|
795
|
-
|
|
796
|
-
def test_codex_reviewer_command_is_ephemeral_read_only_and_uses_managed_instructions(self) -> None:
|
|
797
|
-
repo, _ = self.make_repo()
|
|
798
|
-
assignment_path = repo / "assignment.json"
|
|
799
|
-
result_path = repo / "result.json"
|
|
800
|
-
reviewer_config = repo / ".agents" / "agents" / "reviewer.toml"
|
|
801
|
-
reviewer_config.parent.mkdir(parents=True)
|
|
802
|
-
reviewer_config.write_text(
|
|
803
|
-
'name = "reviewer"\n'
|
|
804
|
-
'model = "vendor/reviewer-model"\n'
|
|
805
|
-
'developer_instructions = "review only the immutable artifact"\n',
|
|
806
|
-
encoding="utf-8",
|
|
807
|
-
)
|
|
808
|
-
runtime_python_path = repo / "Python Runtime" / "bin" / "python3"
|
|
809
|
-
runtime_python_path.parent.mkdir(parents=True)
|
|
810
|
-
runtime_python_path.symlink_to(Path(sys.executable))
|
|
811
|
-
runtime_python = str(runtime_python_path)
|
|
812
|
-
with (
|
|
813
|
-
mock.patch.object(ap.shutil, "which", return_value="/usr/local/bin/codex"),
|
|
814
|
-
mock.patch.object(ap.sys, "executable", runtime_python),
|
|
815
|
-
):
|
|
816
|
-
focused = ap._codex_reviewer_command(
|
|
817
|
-
repo,
|
|
818
|
-
assignment_path,
|
|
819
|
-
result_path,
|
|
820
|
-
review_depth="focused",
|
|
821
|
-
effective_deadline=ap._dt.datetime(
|
|
822
|
-
2026,
|
|
823
|
-
7,
|
|
824
|
-
19,
|
|
825
|
-
9,
|
|
826
|
-
45,
|
|
827
|
-
tzinfo=ap._dt.timezone.utc,
|
|
828
|
-
),
|
|
829
|
-
)
|
|
830
|
-
deep = ap._codex_reviewer_command(
|
|
831
|
-
repo,
|
|
832
|
-
assignment_path,
|
|
833
|
-
result_path,
|
|
834
|
-
review_depth="deep",
|
|
835
|
-
)
|
|
836
|
-
|
|
837
|
-
self.assertEqual("/usr/local/bin/codex", focused[0])
|
|
838
|
-
self.assertIn("--json", focused)
|
|
839
|
-
self.assertIn("--ephemeral", focused)
|
|
840
|
-
self.assertIn("--ignore-user-config", focused)
|
|
841
|
-
self.assertIn("read-only", focused)
|
|
842
|
-
self.assertIn('model_reasoning_effort="high"', focused)
|
|
843
|
-
self.assertIn('model_reasoning_effort="xhigh"', deep)
|
|
844
|
-
self.assertEqual("vendor/reviewer-model", focused[focused.index("--model") + 1])
|
|
845
|
-
prompt = focused[-1]
|
|
846
|
-
runtime_python = os.path.abspath(runtime_python)
|
|
847
|
-
self.assertTrue(Path(runtime_python).is_symlink())
|
|
848
|
-
runtime_script = str(Path(ap.__file__).resolve())
|
|
849
|
-
artifact_match = re.search(r"Before analysis, run `([^`]+)`;", prompt)
|
|
850
|
-
self.assertIsNotNone(artifact_match)
|
|
851
|
-
self.assertEqual(
|
|
852
|
-
[runtime_python, runtime_script, "review-artifact", "--file", str(assignment_path)],
|
|
853
|
-
shlex.split(artifact_match.group(1)),
|
|
854
|
-
)
|
|
855
|
-
template_match = re.search(r"Use `([^`]+)` when useful", prompt)
|
|
856
|
-
self.assertIsNotNone(template_match)
|
|
857
|
-
self.assertEqual(
|
|
858
|
-
[
|
|
859
|
-
runtime_python,
|
|
860
|
-
runtime_script,
|
|
861
|
-
"agent-result-template",
|
|
862
|
-
"--file",
|
|
863
|
-
str(assignment_path),
|
|
864
|
-
"--verdict",
|
|
865
|
-
"approved",
|
|
866
|
-
],
|
|
867
|
-
shlex.split(template_match.group(1)),
|
|
868
|
-
)
|
|
869
|
-
self.assertNotIn("docs/tools/autopipeline/ap.py", prompt)
|
|
870
|
-
self.assertIn("diff_artifact_sha256", prompt)
|
|
871
|
-
self.assertIn("never substitute a live git diff", prompt)
|
|
872
|
-
self.assertIn("2026-07-19T09:45:00+00:00", prompt)
|
|
873
|
-
self.assertIn("AUTOCODING_REVIEW_DEADLINE", prompt)
|
|
874
|
-
self.assertIn("supersedes the immutable assignment deadline_at", prompt)
|
|
875
|
-
developer_override = next(
|
|
876
|
-
item for item in focused if item.startswith("developer_instructions=")
|
|
877
|
-
)
|
|
878
|
-
tomllib.loads(developer_override)
|
|
879
|
-
self.assertEqual(str(result_path), focused[focused.index("-o") + 1])
|
|
880
|
-
|
|
881
|
-
def test_reviewer_process_timeout_terminates_its_process_group(self) -> None:
|
|
882
|
-
repo, _ = self.make_repo()
|
|
883
|
-
runner = repo / "slow-reviewer.py"
|
|
884
|
-
runner.write_text(
|
|
885
|
-
"import json, sys, time\n"
|
|
886
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
887
|
-
"print('Bearer secret-token password=hunter2', file=sys.stderr, flush=True)\n"
|
|
888
|
-
"time.sleep(30)\n",
|
|
889
|
-
encoding="utf-8",
|
|
890
|
-
)
|
|
891
|
-
started = time.monotonic()
|
|
892
|
-
with self.assertRaises(ap._ReviewerRuntimeTimeout) as raised:
|
|
893
|
-
ap._run_supervised_reviewer_process(
|
|
894
|
-
[sys.executable, str(runner)],
|
|
895
|
-
cwd=repo,
|
|
896
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
897
|
-
timeout_seconds=0.3,
|
|
898
|
-
startup_timeout_seconds=0.2,
|
|
899
|
-
)
|
|
900
|
-
self.assertLess(time.monotonic() - started, 3.0)
|
|
901
|
-
self.assertEqual(1, raised.exception.diagnostics["event_count"])
|
|
902
|
-
safe = ap._safe_reviewer_attempt(raised.exception.diagnostics, 1, "analysis-timeout")
|
|
903
|
-
self.assertNotIn("secret-token", json.dumps(safe))
|
|
904
|
-
self.assertNotIn("hunter2", json.dumps(safe))
|
|
905
|
-
|
|
906
|
-
@unittest.skipUnless(os.name == "posix", "POSIX process-group behavior")
|
|
907
|
-
def test_reviewer_timeout_kills_group_after_leader_exits(self) -> None:
|
|
908
|
-
repo, _ = self.make_repo()
|
|
909
|
-
child_pid_path = repo / "reviewer-grandchild.pid"
|
|
910
|
-
runner = repo / "leader-exits-reviewer.py"
|
|
911
|
-
runner.write_text(
|
|
912
|
-
"import json, subprocess, sys\n"
|
|
913
|
-
"from pathlib import Path\n"
|
|
914
|
-
"child = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'])\n"
|
|
915
|
-
f"Path({str(child_pid_path)!r}).write_text(str(child.pid))\n"
|
|
916
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n",
|
|
917
|
-
encoding="utf-8",
|
|
918
|
-
)
|
|
919
|
-
started = time.monotonic()
|
|
920
|
-
with self.assertRaises(ap._ReviewerRuntimeTimeout):
|
|
921
|
-
ap._run_supervised_reviewer_process(
|
|
922
|
-
[sys.executable, str(runner)],
|
|
923
|
-
cwd=repo,
|
|
924
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
925
|
-
timeout_seconds=0.3,
|
|
926
|
-
startup_timeout_seconds=0.2,
|
|
927
|
-
)
|
|
928
|
-
self.assertLess(time.monotonic() - started, 3.0)
|
|
929
|
-
child_pid = int(child_pid_path.read_text())
|
|
930
|
-
child_gone = False
|
|
931
|
-
for _ in range(20):
|
|
932
|
-
try:
|
|
933
|
-
os.kill(child_pid, 0)
|
|
934
|
-
except ProcessLookupError:
|
|
935
|
-
child_gone = True
|
|
936
|
-
break
|
|
937
|
-
time.sleep(0.05)
|
|
938
|
-
self.assertTrue(child_gone, "Reviewer grandchild survived process-group cleanup")
|
|
939
|
-
|
|
940
|
-
@unittest.skipUnless(os.name == "posix", "POSIX detached-process behavior")
|
|
941
|
-
def test_detached_pipe_holder_cannot_extend_reviewer_deadline(self) -> None:
|
|
942
|
-
repo, _ = self.make_repo()
|
|
943
|
-
child_pid_path = repo / "detached-reviewer-child.pid"
|
|
944
|
-
runner = repo / "detached-child-reviewer.py"
|
|
945
|
-
runner.write_text(
|
|
946
|
-
"import json, subprocess, sys\n"
|
|
947
|
-
"from pathlib import Path\n"
|
|
948
|
-
"child = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'], start_new_session=True)\n"
|
|
949
|
-
f"Path({str(child_pid_path)!r}).write_text(str(child.pid))\n"
|
|
950
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n",
|
|
951
|
-
encoding="utf-8",
|
|
952
|
-
)
|
|
953
|
-
started = time.monotonic()
|
|
954
|
-
child_pid = 0
|
|
955
|
-
try:
|
|
956
|
-
with self.assertRaises(ap._ReviewerRuntimeTimeout):
|
|
957
|
-
ap._run_supervised_reviewer_process(
|
|
958
|
-
[sys.executable, str(runner)],
|
|
959
|
-
cwd=repo,
|
|
960
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
961
|
-
timeout_seconds=0.3,
|
|
962
|
-
startup_timeout_seconds=0.2,
|
|
963
|
-
)
|
|
964
|
-
child_pid = int(child_pid_path.read_text())
|
|
965
|
-
finally:
|
|
966
|
-
if not child_pid and child_pid_path.exists():
|
|
967
|
-
child_pid = int(child_pid_path.read_text())
|
|
968
|
-
if child_pid:
|
|
969
|
-
try:
|
|
970
|
-
os.kill(child_pid, signal.SIGKILL)
|
|
971
|
-
except ProcessLookupError:
|
|
972
|
-
pass
|
|
973
|
-
self.assertLess(time.monotonic() - started, 3.0)
|
|
974
|
-
self.assertFalse(
|
|
975
|
-
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
976
|
-
)
|
|
977
|
-
|
|
978
|
-
def test_reviewer_process_without_first_event_is_runtime_unavailable(self) -> None:
|
|
979
|
-
repo, _ = self.make_repo()
|
|
980
|
-
runner = repo / "silent-reviewer.py"
|
|
981
|
-
runner.write_text("import time\ntime.sleep(30)\n", encoding="utf-8")
|
|
982
|
-
with self.assertRaises(ap._ReviewerRuntimeUnavailable) as raised:
|
|
983
|
-
ap._run_supervised_reviewer_process(
|
|
984
|
-
[sys.executable, str(runner)],
|
|
985
|
-
cwd=repo,
|
|
986
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
987
|
-
timeout_seconds=1,
|
|
988
|
-
startup_timeout_seconds=0.1,
|
|
989
|
-
)
|
|
990
|
-
self.assertEqual(0, raised.exception.diagnostics["event_count"])
|
|
991
|
-
|
|
992
|
-
def test_reviewer_process_clean_exit_without_semantic_event_is_unavailable(self) -> None:
|
|
993
|
-
repo, _ = self.make_repo()
|
|
994
|
-
runner = repo / "empty-reviewer.py"
|
|
995
|
-
runner.write_text("pass\n", encoding="utf-8")
|
|
996
|
-
with self.assertRaises(ap._ReviewerRuntimeUnavailable):
|
|
997
|
-
ap._run_supervised_reviewer_process(
|
|
998
|
-
[sys.executable, str(runner)],
|
|
999
|
-
cwd=repo,
|
|
1000
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
1001
|
-
timeout_seconds=1,
|
|
1002
|
-
startup_timeout_seconds=0.2,
|
|
1003
|
-
)
|
|
1004
|
-
|
|
1005
|
-
def test_reviewer_event_writer_failure_stops_process_and_reader_threads(self) -> None:
|
|
1006
|
-
repo, _ = self.make_repo()
|
|
1007
|
-
runner = repo / "writer-failure-reviewer.py"
|
|
1008
|
-
runner.write_text(
|
|
1009
|
-
"import json, time\n"
|
|
1010
|
-
"print(json.dumps({'type': 'turn.started'}), flush=True)\n"
|
|
1011
|
-
"time.sleep(30)\n",
|
|
1012
|
-
encoding="utf-8",
|
|
1013
|
-
)
|
|
1014
|
-
|
|
1015
|
-
class FailingWriter:
|
|
1016
|
-
def write(self, _: str) -> None:
|
|
1017
|
-
raise OSError("event log unavailable")
|
|
1018
|
-
|
|
1019
|
-
def flush(self) -> None:
|
|
1020
|
-
pass
|
|
1021
|
-
|
|
1022
|
-
started = time.monotonic()
|
|
1023
|
-
with mock.patch.object(
|
|
1024
|
-
ap,
|
|
1025
|
-
"_terminate_reviewer_process",
|
|
1026
|
-
wraps=ap._terminate_reviewer_process,
|
|
1027
|
-
) as terminate:
|
|
1028
|
-
with self.assertRaises(ap._ReviewerRuntimeInternalError):
|
|
1029
|
-
ap._run_supervised_reviewer_process(
|
|
1030
|
-
[sys.executable, str(runner)],
|
|
1031
|
-
cwd=repo,
|
|
1032
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
1033
|
-
timeout_seconds=3,
|
|
1034
|
-
startup_timeout_seconds=1,
|
|
1035
|
-
event_writer=FailingWriter(),
|
|
1036
|
-
)
|
|
1037
|
-
self.assertLess(time.monotonic() - started, 3.0)
|
|
1038
|
-
terminate.assert_called_once()
|
|
1039
|
-
self.assertFalse(
|
|
1040
|
-
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
1041
|
-
)
|
|
1042
|
-
|
|
1043
|
-
def test_reviewer_output_flood_is_bounded_and_cleans_reader_threads(self) -> None:
|
|
1044
|
-
repo, _ = self.make_repo()
|
|
1045
|
-
runner = repo / "flood-reviewer.py"
|
|
1046
|
-
runner.write_text(
|
|
1047
|
-
"import json\n"
|
|
1048
|
-
"for index in range(10000):\n"
|
|
1049
|
-
" print(json.dumps({'type': 'item.completed', 'item': {'type': 'note'}, 'i': index}), flush=True)\n",
|
|
1050
|
-
encoding="utf-8",
|
|
1051
|
-
)
|
|
1052
|
-
started = time.monotonic()
|
|
1053
|
-
with mock.patch.object(ap, "_REVIEW_OUTPUT_MAX_BYTES", 2048):
|
|
1054
|
-
with self.assertRaises(ap._ReviewerRuntimeOutputLimit):
|
|
1055
|
-
ap._run_supervised_reviewer_process(
|
|
1056
|
-
[sys.executable, str(runner)],
|
|
1057
|
-
cwd=repo,
|
|
1058
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
1059
|
-
timeout_seconds=3,
|
|
1060
|
-
startup_timeout_seconds=1,
|
|
1061
|
-
)
|
|
1062
|
-
self.assertLess(time.monotonic() - started, 3.0)
|
|
1063
|
-
self.assertFalse(
|
|
1064
|
-
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
1065
|
-
)
|
|
1066
|
-
|
|
1067
|
-
def test_reviewer_single_unterminated_line_is_bounded(self) -> None:
|
|
1068
|
-
repo, _ = self.make_repo()
|
|
1069
|
-
runner = repo / "long-line-reviewer.py"
|
|
1070
|
-
runner.write_text(
|
|
1071
|
-
"import sys, time\n"
|
|
1072
|
-
"sys.stdout.write('x' * 10000)\n"
|
|
1073
|
-
"sys.stdout.flush()\n"
|
|
1074
|
-
"time.sleep(30)\n",
|
|
1075
|
-
encoding="utf-8",
|
|
1076
|
-
)
|
|
1077
|
-
with mock.patch.object(ap, "_REVIEW_OUTPUT_MAX_BYTES", 2048):
|
|
1078
|
-
with self.assertRaises(ap._ReviewerRuntimeOutputLimit):
|
|
1079
|
-
ap._run_supervised_reviewer_process(
|
|
1080
|
-
[sys.executable, str(runner)],
|
|
1081
|
-
cwd=repo,
|
|
1082
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
1083
|
-
timeout_seconds=3,
|
|
1084
|
-
startup_timeout_seconds=1,
|
|
1085
|
-
)
|
|
1086
|
-
self.assertFalse(
|
|
1087
|
-
any(thread.name.startswith("reviewer-stream-") for thread in threading.enumerate())
|
|
1088
|
-
)
|
|
1089
|
-
|
|
1090
|
-
def test_reviewer_event_metadata_does_not_persist_model_or_patch_content(self) -> None:
|
|
1091
|
-
record, semantic = ap._reviewer_event_metadata(
|
|
1092
|
-
"stdout",
|
|
1093
|
-
json.dumps(
|
|
1094
|
-
{
|
|
1095
|
-
"type": "item.completed",
|
|
1096
|
-
"item": {
|
|
1097
|
-
"type": "command_execution",
|
|
1098
|
-
"text": "PATCH_SECRET_TOKEN",
|
|
1099
|
-
"output": "Bearer private-token",
|
|
1100
|
-
},
|
|
1101
|
-
}
|
|
1102
|
-
),
|
|
1103
|
-
"2026-07-17T00:00:00+00:00",
|
|
1104
|
-
)
|
|
1105
|
-
serialized = json.dumps(record)
|
|
1106
|
-
self.assertTrue(semantic)
|
|
1107
|
-
self.assertEqual("item.completed", record["event_type"])
|
|
1108
|
-
self.assertEqual("command_execution", record["item_type"])
|
|
1109
|
-
self.assertNotIn("PATCH_SECRET_TOKEN", serialized)
|
|
1110
|
-
self.assertNotIn("private-token", serialized)
|
|
1111
|
-
|
|
1112
|
-
def test_substantive_agent_message_is_not_erased_by_later_approved_message(self) -> None:
|
|
1113
|
-
assignment = self.reviewer_assignment(
|
|
1114
|
-
review_depth="focused",
|
|
1115
|
-
timeout_seconds=150,
|
|
1116
|
-
issued_at="2026-07-17T00:00:00+00:00",
|
|
1117
|
-
deadline_at="2026-07-17T00:02:30+00:00",
|
|
1118
|
-
)
|
|
1119
|
-
stdout = "\n".join(
|
|
1120
|
-
json.dumps(
|
|
1121
|
-
{
|
|
1122
|
-
"type": "item.completed",
|
|
1123
|
-
"item": {"type": "agent_message", "text": json.dumps({"verdict": verdict})},
|
|
1124
|
-
}
|
|
1125
|
-
)
|
|
1126
|
-
for verdict in ("blocked", "approved")
|
|
1127
|
-
)
|
|
1128
|
-
result = ap._substantive_reviewer_event_result(stdout, assignment)
|
|
1129
|
-
self.assertIsNotNone(result)
|
|
1130
|
-
self.assertEqual("blocked", result["verdict"])
|
|
1131
|
-
|
|
1132
|
-
def test_reviewer_spawn_failure_is_runtime_unavailable_with_safe_diagnostics(self) -> None:
|
|
1133
|
-
repo, _ = self.make_repo()
|
|
1134
|
-
with mock.patch.object(
|
|
1135
|
-
ap.subprocess,
|
|
1136
|
-
"Popen",
|
|
1137
|
-
side_effect=OSError("permission denied token=private-value"),
|
|
1138
|
-
):
|
|
1139
|
-
with self.assertRaises(ap._ReviewerRuntimeUnavailable) as raised:
|
|
1140
|
-
ap._run_supervised_reviewer_process(
|
|
1141
|
-
["missing-reviewer"],
|
|
1142
|
-
cwd=repo,
|
|
1143
|
-
env={"PATH": os.environ.get("PATH", "")},
|
|
1144
|
-
timeout_seconds=1,
|
|
1145
|
-
)
|
|
1146
|
-
safe = ap._safe_reviewer_attempt(raised.exception.diagnostics, 1, "runtime-unavailable")
|
|
1147
|
-
self.assertEqual("spawn-failed", safe["phase"])
|
|
1148
|
-
self.assertNotIn("private-value", json.dumps(safe))
|
|
1149
|
-
|
|
1150
|
-
def test_reviewer_attempt_receipt_never_persists_raw_stderr(self) -> None:
|
|
1151
|
-
diagnostics = ap._reviewer_attempt_diagnostics(
|
|
1152
|
-
started_at="2026-07-17T00:00:00+00:00",
|
|
1153
|
-
finished_at="2026-07-17T00:00:01+00:00",
|
|
1154
|
-
stdout="",
|
|
1155
|
-
stderr="PATCH_SECRET_TOKEN\n-----BEGIN OPENSSH PRIVATE KEY-----\nprivate-material",
|
|
1156
|
-
first_event_at="",
|
|
1157
|
-
last_event_at="",
|
|
1158
|
-
last_event_type="",
|
|
1159
|
-
event_count=0,
|
|
1160
|
-
phase="spawn-failed",
|
|
1161
|
-
exit_code=None,
|
|
1162
|
-
)
|
|
1163
|
-
serialized = json.dumps(
|
|
1164
|
-
ap._safe_reviewer_attempt(diagnostics, 1, "runtime-unavailable")
|
|
1165
|
-
)
|
|
1166
|
-
self.assertNotIn("stderr_tail", serialized)
|
|
1167
|
-
self.assertNotIn("PATCH_SECRET_TOKEN", serialized)
|
|
1168
|
-
self.assertNotIn("PRIVATE KEY", serialized)
|
|
1169
|
-
self.assertIn(hashlib.sha256(diagnostics["stderr"].encode()).hexdigest(), serialized)
|
|
1170
|
-
|
|
1171
|
-
def test_reviewer_assignment_timing_contract_and_fixed_budgets(self) -> None:
|
|
1172
|
-
issued_at = "2026-07-16T00:00:00+00:00"
|
|
1173
|
-
assignment = self.reviewer_assignment(
|
|
1174
|
-
review_depth="focused",
|
|
1175
|
-
timeout_seconds=150,
|
|
1176
|
-
issued_at=issued_at,
|
|
1177
|
-
deadline_at="2026-07-16T00:02:30+00:00",
|
|
1178
|
-
scope_revision=1,
|
|
1179
|
-
)
|
|
1180
|
-
self.assertEqual(
|
|
1181
|
-
assignment,
|
|
1182
|
-
ap._validate_orchestration_contract("assignment", assignment),
|
|
1183
|
-
)
|
|
1184
|
-
self.assertEqual(("focused", 150), ap._normalized_task_review_policy(True))
|
|
1185
|
-
self.assertEqual(
|
|
1186
|
-
("deep", 360),
|
|
1187
|
-
ap._normalized_task_review_policy(True, "focused", "deep"),
|
|
1188
|
-
)
|
|
1189
|
-
self.assertEqual(("none", 0), ap._normalized_task_review_policy(False, "deep"))
|
|
1190
|
-
|
|
1191
|
-
invalid_contracts = [
|
|
1192
|
-
self.reviewer_assignment(
|
|
1193
|
-
review_depth="focused",
|
|
1194
|
-
timeout_seconds=0,
|
|
1195
|
-
issued_at=issued_at,
|
|
1196
|
-
deadline_at="2026-07-16T00:02:30+00:00",
|
|
1197
|
-
),
|
|
1198
|
-
self.reviewer_assignment(
|
|
1199
|
-
review_depth="focused",
|
|
1200
|
-
timeout_seconds=150,
|
|
1201
|
-
issued_at="2026-07-16T00:00:00",
|
|
1202
|
-
deadline_at="2026-07-16T00:02:30",
|
|
1203
|
-
),
|
|
1204
|
-
self.reviewer_assignment(
|
|
1205
|
-
review_depth="focused",
|
|
1206
|
-
timeout_seconds=150,
|
|
1207
|
-
issued_at=issued_at,
|
|
1208
|
-
deadline_at="2026-07-16T00:01:00+00:00",
|
|
1209
|
-
),
|
|
1210
|
-
]
|
|
1211
|
-
for payload in invalid_contracts:
|
|
1212
|
-
with self.subTest(payload=payload):
|
|
1213
|
-
with self.assertRaises(APError):
|
|
1214
|
-
ap._validate_orchestration_contract("assignment", payload)
|
|
1215
|
-
|
|
1216
|
-
def test_reviewer_result_template_rejects_wrong_role_self_review_and_empty_fingerprint(self) -> None:
|
|
1217
|
-
invalid_assignments = [
|
|
1218
|
-
self.reviewer_assignment(role="explorer"),
|
|
1219
|
-
self.reviewer_assignment(node_id="fixer-1"),
|
|
1220
|
-
self.reviewer_assignment(diff_fingerprint=""),
|
|
1221
|
-
]
|
|
1222
|
-
for assignment in invalid_assignments:
|
|
1223
|
-
with self.subTest(assignment=assignment):
|
|
1224
|
-
with self.assertRaises(APError):
|
|
1225
|
-
ap._reviewer_result_template(assignment, "approved")
|
|
1226
|
-
|
|
1227
|
-
def test_agent_result_template_command_reads_assignment_and_prints_json(self) -> None:
|
|
1228
|
-
repo, _ = self.make_repo()
|
|
1229
|
-
assignment_path = repo / "reviewer-assignment.json"
|
|
1230
|
-
assignment_path.write_text(
|
|
1231
|
-
json.dumps(self.reviewer_assignment()),
|
|
1232
|
-
encoding="utf-8",
|
|
1233
|
-
)
|
|
1234
|
-
output = io.StringIO()
|
|
1235
|
-
with contextlib.redirect_stdout(output):
|
|
1236
|
-
ap.cmd_agent_result_template(
|
|
1237
|
-
argparse.Namespace(
|
|
1238
|
-
repo=str(repo),
|
|
1239
|
-
file=str(assignment_path),
|
|
1240
|
-
payload="",
|
|
1241
|
-
verdict="changes-requested",
|
|
1242
|
-
)
|
|
1243
|
-
)
|
|
1244
|
-
|
|
1245
|
-
result = json.loads(output.getvalue())
|
|
1246
|
-
self.assertEqual("reviewer", result["role"])
|
|
1247
|
-
self.assertEqual("changes-requested", result["verdict"])
|
|
1248
|
-
self.assertEqual("completed", result["status"])
|
|
1249
|
-
self.assertEqual("fixer-1", result["next_owner"])
|
|
1250
|
-
self.assertEqual(16, len(result))
|
|
1251
|
-
|
|
1252
|
-
def test_contract_validation_collects_missing_unexpected_type_pattern_and_conditionals(self) -> None:
|
|
1253
|
-
result = ap._reviewer_result_template(self.reviewer_assignment(), "approved")
|
|
1254
|
-
result.pop("next_owner")
|
|
1255
|
-
result.update(
|
|
1256
|
-
{
|
|
1257
|
-
"node_id": [],
|
|
1258
|
-
"changed_paths": ["src/unauthorized.py"],
|
|
1259
|
-
"diff_fingerprint": "not-a-fingerprint",
|
|
1260
|
-
"verdict": "ready-for-review",
|
|
1261
|
-
"unexpected_field": True,
|
|
1262
|
-
}
|
|
1263
|
-
)
|
|
1264
|
-
|
|
1265
|
-
with self.assertRaises(APError) as context:
|
|
1266
|
-
ap._validate_orchestration_contract("result", result)
|
|
1267
|
-
|
|
1268
|
-
message = str(context.exception)
|
|
1269
|
-
self.assertIn("missing next_owner", message)
|
|
1270
|
-
self.assertIn("unexpected unexpected_field", message)
|
|
1271
|
-
self.assertIn("$.node_id: expected type", message)
|
|
1272
|
-
self.assertIn("$.diff_fingerprint: string does not match", message)
|
|
1273
|
-
self.assertIn("$.changed_paths: too many array items", message)
|
|
1274
|
-
self.assertIn("$.verdict: value is outside the allowed enum", message)
|
|
1275
|
-
|
|
1276
|
-
def test_contract_if_branches_do_not_apply_other_role_requirements(self) -> None:
|
|
1277
|
-
fixer_assignment = {
|
|
1278
|
-
"contract_version": 1,
|
|
1279
|
-
"node_id": "fixer-1",
|
|
1280
|
-
"task_id": "T001",
|
|
1281
|
-
"role": "fixer",
|
|
1282
|
-
"base_sha": "HEAD",
|
|
1283
|
-
"scope": "implement one change",
|
|
1284
|
-
"depends_on": [],
|
|
1285
|
-
"acceptance": ["tests pass"],
|
|
1286
|
-
"execution_mode": "isolated",
|
|
1287
|
-
"owned_paths": ["src/**"],
|
|
1288
|
-
}
|
|
1289
|
-
with self.assertRaises(APError) as context:
|
|
1290
|
-
ap._validate_orchestration_contract("assignment", fixer_assignment)
|
|
1291
|
-
|
|
1292
|
-
message = str(context.exception)
|
|
1293
|
-
self.assertIn("task_branch", message)
|
|
1294
|
-
self.assertIn("worktree_path", message)
|
|
1295
|
-
self.assertNotIn("diff_base", message)
|
|
1296
|
-
self.assertNotIn("diff_head", message)
|
|
1297
|
-
self.assertNotIn("diff_fingerprint", message)
|
|
1298
|
-
self.assertNotIn("owning_fixer", message)
|
|
1299
|
-
|
|
1300
|
-
def test_validation_routes_collect_all_commands_and_reject_unmapped_code(self) -> None:
|
|
1301
|
-
repo, cfg = self.make_repo()
|
|
1302
|
-
cfg["commands"] = {"one": "true", "two": "true"}
|
|
1303
|
-
cfg["validation"] = {
|
|
1304
|
-
"on_unmapped": "error",
|
|
1305
|
-
"routes": [
|
|
1306
|
-
{"name": "all-src", "paths": ["src/**"], "commands": ["one", "two"]},
|
|
1307
|
-
{"name": "python", "paths": ["**/*.py"], "commands": ["two"]},
|
|
1308
|
-
],
|
|
1309
|
-
}
|
|
1310
|
-
plan = ap._validation_plan(cfg, ["src/widget.py"])
|
|
1311
|
-
self.assertEqual(["one", "two"], plan["commands"])
|
|
1312
|
-
self.assertEqual(["all-src", "python"], plan["matched_routes"])
|
|
1313
|
-
ap._validate_validation_plan(cfg, plan)
|
|
1314
|
-
with self.assertRaises(APError) as context:
|
|
1315
|
-
ap._validate_validation_plan(cfg, ap._validation_plan(cfg, ["contracts/api.yaml"]))
|
|
1316
|
-
self.assertIn("no validation route", str(context.exception))
|
|
1317
|
-
|
|
1318
|
-
def test_final_gate_budget_is_configurable_and_times_out(self) -> None:
|
|
1319
|
-
cfg = base_config()
|
|
1320
|
-
cfg["validation"] = {
|
|
1321
|
-
"on_unmapped": "error",
|
|
1322
|
-
"max_command_seconds": 0.05,
|
|
1323
|
-
"max_total_seconds": 0.1,
|
|
1324
|
-
"routes": [{"name": "slow", "paths": ["src/**"], "commands": ["slow"]}],
|
|
1325
|
-
}
|
|
1326
|
-
cfg["commands"]["slow"] = f'{sys.executable} -c "import time; time.sleep(1)"'
|
|
1327
|
-
repo, cfg = self.make_repo("src/widget.py", cfg)
|
|
1328
|
-
with self.assertRaises(APError) as context:
|
|
1329
|
-
ap.cmd_light_gate(
|
|
1330
|
-
argparse.Namespace(
|
|
1331
|
-
repo=str(repo),
|
|
1332
|
-
scope="changed",
|
|
1333
|
-
profile="",
|
|
1334
|
-
mode="dev",
|
|
1335
|
-
base="",
|
|
1336
|
-
explain=False,
|
|
1337
|
-
)
|
|
1338
|
-
)
|
|
1339
|
-
self.assertIn("timed out", str(context.exception))
|
|
1340
|
-
|
|
1341
|
-
cfg["validation"]["max_command_seconds"] = 240
|
|
1342
|
-
cfg["validation"]["max_total_seconds"] = 300
|
|
1343
|
-
self.assertEqual(
|
|
1344
|
-
{"command_seconds": 240.0, "total_seconds": 300.0},
|
|
1345
|
-
ap._final_gate_budget(cfg),
|
|
1346
|
-
)
|
|
1347
|
-
|
|
1348
|
-
cfg["validation"]["max_total_seconds"] = 200
|
|
1349
|
-
with self.assertRaises(APError) as context:
|
|
1350
|
-
ap._final_gate_budget(cfg)
|
|
1351
|
-
self.assertIn("cannot exceed validation.max_total_seconds", str(context.exception))
|
|
1352
|
-
|
|
1353
|
-
def test_final_changed_scope_gate_runs_blocking_structure_check(self) -> None:
|
|
1354
|
-
cfg = base_config()
|
|
1355
|
-
cfg["structure"] = {
|
|
1356
|
-
"enabled": True,
|
|
1357
|
-
"enforcement": "blocking",
|
|
1358
|
-
"max_file_lines_warn": 0,
|
|
1359
|
-
"max_file_lines_block": 1,
|
|
1360
|
-
"max_function_lines_warn": 0,
|
|
1361
|
-
"layer_rules": {"enabled": False},
|
|
1362
|
-
}
|
|
1363
|
-
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1364
|
-
repo, _ = self.make_repo("src/too-large.py", cfg)
|
|
1365
|
-
(repo / "src" / "too-large.py").write_text("one\ntwo\n", encoding="utf-8")
|
|
1366
|
-
|
|
1367
|
-
with self.assertRaisesRegex(APError, "structure-check failed"):
|
|
1368
|
-
ap.cmd_light_gate(
|
|
1369
|
-
argparse.Namespace(
|
|
1370
|
-
repo=str(repo),
|
|
1371
|
-
scope="changed",
|
|
1372
|
-
profile="",
|
|
1373
|
-
mode="dev",
|
|
1374
|
-
base="",
|
|
1375
|
-
explain=False,
|
|
1376
|
-
)
|
|
1377
|
-
)
|
|
1378
|
-
|
|
1379
|
-
def test_route_timeout_uses_smallest_matching_budget(self) -> None:
|
|
1380
|
-
cfg = base_config()
|
|
1381
|
-
cfg["commands"] = {"one": "true", "two": "true"}
|
|
1382
|
-
cfg["validation"] = {
|
|
1383
|
-
"on_unmapped": "error",
|
|
1384
|
-
"max_command_seconds": 120,
|
|
1385
|
-
"max_total_seconds": 180,
|
|
1386
|
-
"routes": [
|
|
1387
|
-
{
|
|
1388
|
-
"name": "all-src",
|
|
1389
|
-
"paths": ["src/**"],
|
|
1390
|
-
"commands": ["one", "two"],
|
|
1391
|
-
"timeout_seconds": 90,
|
|
1392
|
-
},
|
|
1393
|
-
{
|
|
1394
|
-
"name": "python",
|
|
1395
|
-
"paths": ["**/*.py"],
|
|
1396
|
-
"commands": ["two"],
|
|
1397
|
-
"timeout_seconds": 30,
|
|
1398
|
-
},
|
|
1399
|
-
],
|
|
1400
|
-
}
|
|
1401
|
-
plan = ap._validation_plan(cfg, ["src/widget.py"])
|
|
1402
|
-
self.assertEqual({"one": 90.0, "two": 30.0}, plan["command_timeouts"])
|
|
1403
|
-
|
|
1404
|
-
def test_test_only_change_resolves_micro(self) -> None:
|
|
1405
|
-
repo, cfg = self.make_repo("tests/widget_test.py")
|
|
1406
|
-
(repo / "docs" / "tasks" / "evidence.jsonl").write_text("{}\n", encoding="utf-8")
|
|
1407
|
-
plan = self.plan(repo, cfg)
|
|
1408
|
-
self.assertEqual("micro", plan["profile"])
|
|
1409
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
1410
|
-
|
|
1411
|
-
def test_sensitive_named_test_only_changes_stay_micro(self) -> None:
|
|
1412
|
-
for path in ["tests/auth_test.py", "tests/payment_spec.ts", "tests/upload_test.py"]:
|
|
1413
|
-
with self.subTest(path=path):
|
|
1414
|
-
repo, cfg = self.make_repo(path)
|
|
1415
|
-
plan = self.plan(repo, cfg)
|
|
1416
|
-
self.assertEqual("micro", plan["profile"])
|
|
1417
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
1418
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
1419
|
-
|
|
1420
|
-
def test_high_risk_changes_keep_fast_dev_gate(self) -> None:
|
|
1421
|
-
repo, cfg = self.make_repo("migrations/001.sql")
|
|
1422
|
-
plan = self.plan(repo, cfg, requested_profile="micro", requested_mode="dev")
|
|
1423
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
1424
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
1425
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
1426
|
-
self.assertFalse(plan["needs_dd"])
|
|
1427
|
-
self.assertTrue(plan["review_required"])
|
|
1428
|
-
self.assertIn("reviewer", plan["recommended_agents"])
|
|
1429
|
-
self.assertFalse(plan["needs_jenkins"])
|
|
1430
|
-
self.assertFalse(plan["needs_target"])
|
|
1431
|
-
|
|
1432
|
-
def test_focused_and_deep_review_policies_share_reviewer_with_bounded_attempt(self) -> None:
|
|
1433
|
-
cfg = base_config()
|
|
1434
|
-
cfg["risk"] = {
|
|
1435
|
-
"rules": [
|
|
1436
|
-
{
|
|
1437
|
-
"name": "focused-sensitive-change",
|
|
1438
|
-
"paths": ["src/sensitive/**"],
|
|
1439
|
-
"profile": "high-risk",
|
|
1440
|
-
}
|
|
1441
|
-
]
|
|
1442
|
-
}
|
|
1443
|
-
repo, cfg = self.make_repo(config=cfg)
|
|
1444
|
-
focused = self.plan(repo, cfg, planned_paths=["src/sensitive/value.py"])
|
|
1445
|
-
deep = self.plan(repo, cfg, planned_paths=["backend/auth/service.py"])
|
|
1446
|
-
|
|
1447
|
-
for plan, depth, timeout in [
|
|
1448
|
-
(focused, "focused", 150),
|
|
1449
|
-
(deep, "deep", 360),
|
|
1450
|
-
]:
|
|
1451
|
-
with self.subTest(depth=depth):
|
|
1452
|
-
self.assertTrue(plan["review_required"])
|
|
1453
|
-
self.assertEqual(depth, plan["review_depth"])
|
|
1454
|
-
self.assertEqual("reviewer", plan["review_agent"])
|
|
1455
|
-
self.assertEqual(timeout, plan["review_timeout_seconds"])
|
|
1456
|
-
self.assertEqual(1, plan["review_analysis_attempt_limit"])
|
|
1457
|
-
self.assertEqual("reviewer", plan["agent_plan"]["policies"]["review_agent"])
|
|
1458
|
-
self.assertEqual(
|
|
1459
|
-
timeout,
|
|
1460
|
-
plan["agent_plan"]["policies"]["review_timeout_seconds"],
|
|
1461
|
-
)
|
|
1462
|
-
self.assertEqual(
|
|
1463
|
-
1,
|
|
1464
|
-
plan["agent_plan"]["policies"]["review_analysis_attempt_limit"],
|
|
1465
|
-
)
|
|
1466
|
-
constraints = " ".join(plan["agent_plan"]["constraints"]).lower()
|
|
1467
|
-
self.assertIn("timeout is blocked", constraints)
|
|
1468
|
-
self.assertIn("reuse the same analysis", constraints)
|
|
1469
|
-
|
|
1470
|
-
def test_ui_api_reports_capabilities_without_auto_dispatch(self) -> None:
|
|
1471
|
-
repo, cfg = self.make_repo("src/api/settings-page.tsx")
|
|
1472
|
-
plan = self.plan(repo, cfg)
|
|
1473
|
-
self.assertTrue(plan["needs_browser"])
|
|
1474
|
-
self.assertEqual([], plan["recommended_agents"])
|
|
1475
|
-
self.assertEqual("main-only", plan["agent_plan"]["strategy"])
|
|
1476
|
-
self.assertEqual(["main"], plan["agent_plan"]["stages"][0]["roles"])
|
|
1477
|
-
|
|
1478
|
-
def test_ui_classification_uses_segments_and_extensions_not_substrings(self) -> None:
|
|
1479
|
-
for path in [
|
|
1480
|
-
".env.components",
|
|
1481
|
-
"docker-compose.components.yml",
|
|
1482
|
-
"config/component-overrides.yml",
|
|
1483
|
-
"backend/component_service.go",
|
|
1484
|
-
]:
|
|
1485
|
-
with self.subTest(path=path):
|
|
1486
|
-
self.assertNotIn("ui", ap._classify_paths([path])["categories"])
|
|
1487
|
-
|
|
1488
|
-
for path in [
|
|
1489
|
-
"frontend/src/app.ts",
|
|
1490
|
-
"src/components/Button.ts",
|
|
1491
|
-
"src/views/Home.js",
|
|
1492
|
-
"src/Button.tsx",
|
|
1493
|
-
"miniapp/pages/home/index.ts",
|
|
1494
|
-
]:
|
|
1495
|
-
with self.subTest(path=path):
|
|
1496
|
-
self.assertIn("ui", ap._classify_paths([path])["categories"])
|
|
1497
|
-
|
|
1498
|
-
repo, cfg = self.make_repo()
|
|
1499
|
-
plan = self.plan(repo, cfg, planned_paths=[".env.components"])
|
|
1500
|
-
self.assertFalse(plan["needs_browser"])
|
|
1501
|
-
|
|
1502
|
-
def test_exact_cross_module_high_risk_rename_is_mechanical_but_reviewed(self) -> None:
|
|
1503
|
-
repo, cfg = self.make_repo()
|
|
1504
|
-
source = repo / "backend" / "auth" / "policy.py"
|
|
1505
|
-
source.parent.mkdir(parents=True)
|
|
1506
|
-
source.write_text("POLICY = 'stable'\n", encoding="utf-8")
|
|
1507
|
-
run(repo, "git", "add", str(source.relative_to(repo)))
|
|
1508
|
-
run(repo, "git", "commit", "-qm", "add auth policy")
|
|
1509
|
-
destination = repo / "account" / "auth" / "policy.py"
|
|
1510
|
-
destination.parent.mkdir(parents=True)
|
|
1511
|
-
run(repo, "git", "mv", str(source.relative_to(repo)), str(destination.relative_to(repo)))
|
|
1512
|
-
|
|
1513
|
-
plan = self.plan(repo, cfg)
|
|
1514
|
-
|
|
1515
|
-
self.assertEqual(
|
|
1516
|
-
["account/auth/policy.py", "backend/auth/policy.py"],
|
|
1517
|
-
plan["changed_files"],
|
|
1518
|
-
)
|
|
1519
|
-
self.assertTrue(plan["cross_module"])
|
|
1520
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
1521
|
-
self.assertEqual("mechanical", plan["change_nature"])
|
|
1522
|
-
self.assertTrue(plan["review_required"])
|
|
1523
|
-
self.assertFalse(plan["design_required"])
|
|
1524
|
-
|
|
1525
|
-
extra = repo / "account" / "auth" / "new_policy.py"
|
|
1526
|
-
extra.write_text("POLICY = 'new'\n", encoding="utf-8")
|
|
1527
|
-
mixed = self.plan(repo, cfg)
|
|
1528
|
-
self.assertEqual("unknown", mixed["change_nature"])
|
|
1529
|
-
self.assertTrue(mixed["design_required"])
|
|
1530
|
-
|
|
1531
|
-
def test_semantic_or_unknown_cross_module_high_risk_change_keeps_design(self) -> None:
|
|
1532
|
-
repo, cfg = self.make_repo()
|
|
1533
|
-
source = repo / "backend" / "auth" / "policy.py"
|
|
1534
|
-
source.parent.mkdir(parents=True)
|
|
1535
|
-
source.write_text("POLICY = 'stable'\n", encoding="utf-8")
|
|
1536
|
-
run(repo, "git", "add", str(source.relative_to(repo)))
|
|
1537
|
-
run(repo, "git", "commit", "-qm", "add auth policy")
|
|
1538
|
-
destination = repo / "account" / "auth" / "policy.py"
|
|
1539
|
-
destination.parent.mkdir(parents=True)
|
|
1540
|
-
run(repo, "git", "mv", str(source.relative_to(repo)), str(destination.relative_to(repo)))
|
|
1541
|
-
destination.write_text("POLICY = 'changed'\n", encoding="utf-8")
|
|
1542
|
-
|
|
1543
|
-
semantic = self.plan(repo, cfg, intent="改变鉴权策略行为和模块职责")
|
|
1544
|
-
self.assertEqual("semantic", semantic["change_nature"])
|
|
1545
|
-
self.assertTrue(semantic["review_required"])
|
|
1546
|
-
self.assertTrue(semantic["design_required"])
|
|
1547
|
-
|
|
1548
|
-
clean_repo, clean_cfg = self.make_repo()
|
|
1549
|
-
unknown = self.plan(
|
|
1550
|
-
clean_repo,
|
|
1551
|
-
clean_cfg,
|
|
1552
|
-
planned_paths=["backend/auth/policy.py", "account/auth/policy.py"],
|
|
1553
|
-
)
|
|
1554
|
-
self.assertEqual("unknown", unknown["change_nature"])
|
|
1555
|
-
self.assertTrue(unknown["review_required"])
|
|
1556
|
-
self.assertTrue(unknown["design_required"])
|
|
1557
|
-
|
|
1558
|
-
def test_failed_git_rename_probe_stays_conservative(self) -> None:
|
|
1559
|
-
repo, _ = self.make_repo()
|
|
1560
|
-
failed = subprocess.CompletedProcess(
|
|
1561
|
-
args=["git", "diff"],
|
|
1562
|
-
returncode=128,
|
|
1563
|
-
stdout="",
|
|
1564
|
-
stderr="fatal: diff unavailable",
|
|
1565
|
-
)
|
|
1566
|
-
with (
|
|
1567
|
-
mock.patch.object(ap, "_effective_change_base", return_value=""),
|
|
1568
|
-
mock.patch.object(ap, "run", return_value=failed),
|
|
1569
|
-
):
|
|
1570
|
-
self.assertFalse(
|
|
1571
|
-
ap._pure_exact_git_rename(
|
|
1572
|
-
repo,
|
|
1573
|
-
"",
|
|
1574
|
-
["backend/auth/policy.py", "account/auth/policy.py"],
|
|
1575
|
-
)
|
|
1576
|
-
)
|
|
1577
|
-
|
|
1578
|
-
def test_explicit_design_rule_wins_over_mechanical_change(self) -> None:
|
|
1579
|
-
cfg = base_config()
|
|
1580
|
-
cfg["risk"] = {
|
|
1581
|
-
"rules": [
|
|
1582
|
-
{
|
|
1583
|
-
"name": "auth-design",
|
|
1584
|
-
"paths": ["**/auth/**"],
|
|
1585
|
-
"profile": "high-risk",
|
|
1586
|
-
"design": "required",
|
|
1587
|
-
}
|
|
1588
|
-
]
|
|
1589
|
-
}
|
|
1590
|
-
repo, cfg = self.make_repo(config=cfg)
|
|
1591
|
-
plan = self.plan(
|
|
1592
|
-
repo,
|
|
1593
|
-
cfg,
|
|
1594
|
-
planned_paths=["backend/auth/policy.py", "account/auth/policy.py"],
|
|
1595
|
-
intent="机械同步,不改变行为",
|
|
1596
|
-
)
|
|
1597
|
-
self.assertEqual("mechanical", plan["change_nature"])
|
|
1598
|
-
self.assertTrue(plan["review_required"])
|
|
1599
|
-
self.assertTrue(plan["design_required"])
|
|
1600
|
-
|
|
1601
|
-
def test_semantic_or_negated_intent_overrides_mechanical_words(self) -> None:
|
|
1602
|
-
repo, cfg = self.make_repo()
|
|
1603
|
-
paths = ["backend/auth/policy.py", "account/auth/policy.py"]
|
|
1604
|
-
for intent in [
|
|
1605
|
-
"mechanical sync that changes behavior",
|
|
1606
|
-
"rename only while changing the API contract",
|
|
1607
|
-
"机械同步但修改鉴权契约",
|
|
1608
|
-
]:
|
|
1609
|
-
with self.subTest(intent=intent):
|
|
1610
|
-
plan = self.plan(repo, cfg, planned_paths=paths, intent=intent)
|
|
1611
|
-
self.assertEqual("semantic", plan["change_nature"])
|
|
1612
|
-
self.assertTrue(plan["design_required"])
|
|
1613
|
-
|
|
1614
|
-
for intent in ["not mechanical", "不是机械变更"]:
|
|
1615
|
-
with self.subTest(intent=intent):
|
|
1616
|
-
plan = self.plan(repo, cfg, planned_paths=paths, intent=intent)
|
|
1617
|
-
self.assertEqual("unknown", plan["change_nature"])
|
|
1618
|
-
self.assertTrue(plan["design_required"])
|
|
1619
|
-
|
|
1620
|
-
def test_terminal_ledger_maintenance_creates_no_lifecycle_plan(self) -> None:
|
|
1621
|
-
repo, cfg = self.make_repo()
|
|
1622
|
-
plan = self.plan(repo, cfg, planned_paths=["docs/tasks/closure-log.md"])
|
|
1623
|
-
self.assertTrue(plan["terminal_maintenance"])
|
|
1624
|
-
self.assertEqual("none", plan["execution_mode"])
|
|
1625
|
-
self.assertFalse(plan["review_required"])
|
|
1626
|
-
self.assertFalse(plan["design_required"])
|
|
1627
|
-
self.assertEqual([], plan["recommended_agents"])
|
|
1628
|
-
|
|
1629
|
-
def test_requested_verify_mode_is_rejected(self) -> None:
|
|
1630
|
-
repo, cfg = self.make_repo("src/widget.py")
|
|
1631
|
-
with self.assertRaises(APError):
|
|
1632
|
-
self.plan(repo, cfg, requested_mode="verify")
|
|
1633
|
-
|
|
1634
|
-
def test_configured_high_risk_profile_cannot_be_downgraded_by_cli(self) -> None:
|
|
1635
|
-
cfg = base_config()
|
|
1636
|
-
cfg["workflow"] = {"mode": "dev", "profile": "high-risk", "completion": "push"}
|
|
1637
|
-
repo, cfg = self.make_repo("src/widget.py", cfg)
|
|
1638
|
-
plan = self.plan(repo, cfg, requested_profile="micro", requested_mode="dev")
|
|
1639
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
1640
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
1641
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
1642
|
-
|
|
1643
|
-
def test_doctor_rejects_configured_verify_mode(self) -> None:
|
|
1644
|
-
cfg = base_config()
|
|
1645
|
-
cfg["workflow"] = {"mode": "verify", "profile": "auto", "completion": "push"}
|
|
1646
|
-
repo, _ = self.make_repo("src/widget.py", cfg)
|
|
1647
|
-
with self.assertRaises(APError) as context:
|
|
1648
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
1649
|
-
self.assertIn("workflow.mode", str(context.exception))
|
|
1650
|
-
|
|
1651
|
-
def test_configured_micro_profile_applies_to_ordinary_code(self) -> None:
|
|
1652
|
-
cfg = base_config()
|
|
1653
|
-
cfg["workflow"] = {"mode": "dev", "profile": "micro", "completion": "push"}
|
|
1654
|
-
repo, cfg = self.make_repo("src/widget.py", cfg)
|
|
1655
|
-
plan = self.plan(repo, cfg)
|
|
1656
|
-
self.assertEqual("micro", plan["profile"])
|
|
1657
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
1658
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
1659
|
-
|
|
1660
|
-
def test_rule_can_raise_profile(self) -> None:
|
|
1661
|
-
cfg = base_config()
|
|
1662
|
-
cfg["gate"]["rules"] = [{"name": "sensitive", "paths": ["src/special/**"], "profile": "high-risk"}]
|
|
1663
|
-
repo, cfg = self.make_repo("src/special/value.py", cfg)
|
|
1664
|
-
plan = self.plan(repo, cfg)
|
|
1665
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
1666
|
-
self.assertIn("matched gate rule with profile=high-risk", plan["profile_reasons"])
|
|
1667
|
-
|
|
1668
|
-
def test_legacy_full_scope_rule_fails_closed_during_planning(self) -> None:
|
|
1669
|
-
cfg = base_config()
|
|
1670
|
-
cfg["gate"]["rules"] = [{"name": "sensitive", "paths": ["src/sensitive/**"], "scope": "full"}]
|
|
1671
|
-
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1672
|
-
with self.assertRaisesRegex(APError, "legacy automatic gate escalation"):
|
|
1673
|
-
self.plan(
|
|
1674
|
-
repo,
|
|
1675
|
-
cfg,
|
|
1676
|
-
requested_scope="changed",
|
|
1677
|
-
requested_profile="micro",
|
|
1678
|
-
requested_mode="dev",
|
|
1679
|
-
)
|
|
1680
|
-
|
|
1681
|
-
def test_legacy_rule_commands_fail_closed_and_never_run(self) -> None:
|
|
1682
|
-
cfg = base_config()
|
|
1683
|
-
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1684
|
-
marker_dir = repo / ".test-markers"
|
|
1685
|
-
marker_dir.mkdir()
|
|
1686
|
-
quick_marker = marker_dir / "quick-ran"
|
|
1687
|
-
full_marker = marker_dir / "full-ran"
|
|
1688
|
-
build_marker = marker_dir / "build-ran"
|
|
1689
|
-
cfg["commands"] = {
|
|
1690
|
-
"gate_changed": f"touch {quick_marker}",
|
|
1691
|
-
"gate_full": f"touch {full_marker}",
|
|
1692
|
-
"build": f"touch {build_marker}",
|
|
1693
|
-
}
|
|
1694
|
-
cfg["gate"]["rules"] = [
|
|
1695
|
-
{
|
|
1696
|
-
"name": "legacy-heavy-rule",
|
|
1697
|
-
"paths": ["src/sensitive/**"],
|
|
1698
|
-
"scope": "full",
|
|
1699
|
-
"commands": ["gate_full", "build"],
|
|
1700
|
-
}
|
|
1701
|
-
]
|
|
1702
|
-
self.write_config(repo, cfg)
|
|
1703
|
-
|
|
1704
|
-
with self.assertRaises(APError) as context:
|
|
1705
|
-
ap.cmd_light_gate(
|
|
1706
|
-
argparse.Namespace(
|
|
1707
|
-
repo=str(repo),
|
|
1708
|
-
scope="changed",
|
|
1709
|
-
profile="",
|
|
1710
|
-
mode="dev",
|
|
1711
|
-
base="",
|
|
1712
|
-
explain=False,
|
|
1713
|
-
)
|
|
1714
|
-
)
|
|
1715
|
-
|
|
1716
|
-
self.assertIn("legacy automatic gate escalation", str(context.exception))
|
|
1717
|
-
self.assertFalse(quick_marker.exists())
|
|
1718
|
-
self.assertFalse(full_marker.exists())
|
|
1719
|
-
self.assertFalse(build_marker.exists())
|
|
1720
|
-
|
|
1721
|
-
def test_classify_never_recommends_a_second_gate_or_structure_scan(self) -> None:
|
|
1722
|
-
repo, _ = self.make_repo("src/widget.py")
|
|
1723
|
-
with mock.patch.object(ap, "_record_evidence"):
|
|
1724
|
-
with mock.patch("builtins.print") as printed:
|
|
1725
|
-
ap.cmd_classify(
|
|
1726
|
-
argparse.Namespace(
|
|
1727
|
-
repo=str(repo),
|
|
1728
|
-
scope="auto",
|
|
1729
|
-
profile="",
|
|
1730
|
-
mode="dev",
|
|
1731
|
-
base="",
|
|
1732
|
-
json=False,
|
|
1733
|
-
)
|
|
1734
|
-
)
|
|
1735
|
-
rendered = "\n".join(" ".join(map(str, call.args)) for call in printed.call_args_list)
|
|
1736
|
-
self.assertNotIn("light-gate", rendered)
|
|
1737
|
-
self.assertNotIn("structure-check", rendered)
|
|
1738
|
-
|
|
1739
|
-
def test_classify_text_output_exposes_workspace_and_writer_snapshot(self) -> None:
|
|
1740
|
-
repo, _ = self.make_repo("path with spaces.txt")
|
|
1741
|
-
output = io.StringIO()
|
|
1742
|
-
args = argparse.Namespace(
|
|
1743
|
-
repo=str(repo),
|
|
1744
|
-
scope="auto",
|
|
1745
|
-
profile="",
|
|
1746
|
-
mode="dev",
|
|
1747
|
-
base="",
|
|
1748
|
-
planned_path=[],
|
|
1749
|
-
intent="",
|
|
1750
|
-
intent_file="",
|
|
1751
|
-
task_kind="auto",
|
|
1752
|
-
claim_direct=False,
|
|
1753
|
-
claim_owner="",
|
|
1754
|
-
continue_direct=False,
|
|
1755
|
-
direct_claim="",
|
|
1756
|
-
writers=1,
|
|
1757
|
-
json=False,
|
|
1758
|
-
)
|
|
1759
|
-
with mock.patch.object(ap, "_record_evidence"):
|
|
1760
|
-
with contextlib.redirect_stdout(output):
|
|
1761
|
-
ap.cmd_classify(args)
|
|
1762
|
-
|
|
1763
|
-
rendered = output.getvalue()
|
|
1764
|
-
self.assertIn(f"[classify] repo={repo.resolve()}", rendered)
|
|
1765
|
-
self.assertIn("[classify] workspace_dirty=true", rendered)
|
|
1766
|
-
self.assertIn('[classify] dirty_paths=["path with spaces.txt"]', rendered)
|
|
1767
|
-
self.assertIn("[classify] active_writer=false", rendered)
|
|
1768
|
-
self.assertIn("[classify] review_analysis_attempt_limit=0", rendered)
|
|
1769
|
-
|
|
1770
|
-
def test_custom_full_on_path_does_not_expand_local_gate(self) -> None:
|
|
1771
|
-
cfg = base_config()
|
|
1772
|
-
cfg["gate"]["full_on"] = {"paths": ["src/sensitive/**"]}
|
|
1773
|
-
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1774
|
-
plan = self.plan(repo, cfg, requested_scope="changed", requested_profile="micro", requested_mode="dev")
|
|
1775
|
-
self.assertEqual("micro", plan["profile"])
|
|
1776
|
-
self.assertEqual("changed", plan["selected_scope"])
|
|
1777
|
-
self.assertEqual("dev", plan["effective_mode"])
|
|
1778
|
-
|
|
1779
|
-
def test_full_gate_never_falls_back_to_light(self) -> None:
|
|
1780
|
-
repo, _ = self.make_repo()
|
|
1781
|
-
marker = repo / "light-ran"
|
|
1782
|
-
cfg = {"commands": {"light_gate": f"touch {marker}"}}
|
|
1783
|
-
with self.assertRaises(APError):
|
|
1784
|
-
ap._run_full_gate(repo, cfg)
|
|
1785
|
-
self.assertFalse(marker.exists())
|
|
1786
|
-
|
|
1787
|
-
cfg = {"commands": {"gate_full": f"touch {marker}"}}
|
|
1788
|
-
self.assertEqual(["gate_full"], ap._run_full_gate(repo, cfg))
|
|
1789
|
-
self.assertTrue(marker.exists())
|
|
1790
|
-
|
|
1791
|
-
def test_structure_defaults_to_advisory_until_explicitly_blocking(self) -> None:
|
|
1792
|
-
cfg = base_config()
|
|
1793
|
-
cfg["structure"] = {
|
|
1794
|
-
"enabled": True,
|
|
1795
|
-
"max_file_lines_warn": 3,
|
|
1796
|
-
"max_file_lines_block": 5,
|
|
1797
|
-
"max_function_lines_warn": 0,
|
|
1798
|
-
"max_added_lines_to_large_file": 2,
|
|
1799
|
-
"layer_rules": {"enabled": False},
|
|
1800
|
-
}
|
|
1801
|
-
repo, cfg = self.make_repo("src/large.py", cfg)
|
|
1802
|
-
(repo / "src" / "large.py").write_text("\n".join(f"line {i}" for i in range(10)), encoding="utf-8")
|
|
1803
|
-
args = argparse.Namespace(repo=str(repo), scope="changed", base="", json=False)
|
|
1804
|
-
ap.cmd_structure_check(args)
|
|
1805
|
-
|
|
1806
|
-
cfg["structure"]["enforcement"] = "blocking"
|
|
1807
|
-
self.write_config(repo, cfg)
|
|
1808
|
-
with self.assertRaises(APError):
|
|
1809
|
-
ap.cmd_structure_check(args)
|
|
1810
|
-
|
|
1811
|
-
def test_structure_block_warnings_matrix(self) -> None:
|
|
1812
|
-
cases = [
|
|
1813
|
-
("blocking", True, True),
|
|
1814
|
-
("blocking", False, False),
|
|
1815
|
-
("advisory", True, False),
|
|
1816
|
-
]
|
|
1817
|
-
for enforcement, configured_block_warnings, should_block in cases:
|
|
1818
|
-
with self.subTest(
|
|
1819
|
-
enforcement=enforcement,
|
|
1820
|
-
block_warnings=configured_block_warnings,
|
|
1821
|
-
):
|
|
1822
|
-
cfg = base_config()
|
|
1823
|
-
cfg["structure"] = {
|
|
1824
|
-
"enabled": True,
|
|
1825
|
-
"enforcement": enforcement,
|
|
1826
|
-
"block_warnings": configured_block_warnings,
|
|
1827
|
-
"max_file_lines_warn": 4,
|
|
1828
|
-
"max_file_lines_block": 50,
|
|
1829
|
-
"max_function_lines_warn": 4,
|
|
1830
|
-
"max_added_lines_to_large_file": 50,
|
|
1831
|
-
"layer_rules": {"enabled": False},
|
|
1832
|
-
}
|
|
1833
|
-
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1834
|
-
repo, _ = self.make_repo("src/large.py", cfg)
|
|
1835
|
-
(repo / "src" / "large.py").write_text(
|
|
1836
|
-
"def oversized():\n"
|
|
1837
|
-
" value = 1\n"
|
|
1838
|
-
" value += 1\n"
|
|
1839
|
-
" value += 1\n"
|
|
1840
|
-
" return value\n"
|
|
1841
|
-
"tail = 1\n",
|
|
1842
|
-
encoding="utf-8",
|
|
1843
|
-
)
|
|
1844
|
-
output = io.StringIO()
|
|
1845
|
-
args = argparse.Namespace(
|
|
1846
|
-
repo=str(repo), scope="changed", base="", json=True
|
|
1847
|
-
)
|
|
1848
|
-
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
1849
|
-
if should_block:
|
|
1850
|
-
with self.assertRaisesRegex(APError, "2 blocking issue"):
|
|
1851
|
-
ap.cmd_structure_check(args)
|
|
1852
|
-
else:
|
|
1853
|
-
ap.cmd_structure_check(args)
|
|
1854
|
-
|
|
1855
|
-
result = json.loads(output.getvalue())
|
|
1856
|
-
self.assertIs(should_block, result["block_warnings"])
|
|
1857
|
-
if should_block:
|
|
1858
|
-
self.assertEqual(2, len(result["blocking"]))
|
|
1859
|
-
else:
|
|
1860
|
-
self.assertEqual([], result["blocking"])
|
|
1861
|
-
self.assertEqual(2, len(result["warnings"]))
|
|
1862
|
-
|
|
1863
|
-
def test_structure_block_warnings_keeps_accepted_debt_size_findings_advisory(self) -> None:
|
|
1864
|
-
cfg = base_config()
|
|
1865
|
-
cfg["structure"] = {
|
|
1866
|
-
"enabled": True,
|
|
1867
|
-
"enforcement": "blocking",
|
|
1868
|
-
"block_warnings": True,
|
|
1869
|
-
"max_file_lines_warn": 4,
|
|
1870
|
-
"max_file_lines_block": 50,
|
|
1871
|
-
"max_function_lines_warn": 4,
|
|
1872
|
-
"max_added_lines_to_large_file": 50,
|
|
1873
|
-
"accepted_debt_paths": ["src/accepted.py"],
|
|
1874
|
-
"layer_rules": {"enabled": False},
|
|
1875
|
-
}
|
|
1876
|
-
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1877
|
-
repo, _ = self.make_repo("src/accepted.py", cfg)
|
|
1878
|
-
(repo / "src" / "accepted.py").write_text(
|
|
1879
|
-
"def accepted_debt():\n"
|
|
1880
|
-
" value = 1\n"
|
|
1881
|
-
" value += 1\n"
|
|
1882
|
-
" value += 1\n"
|
|
1883
|
-
" return value\n"
|
|
1884
|
-
"tail = 1\n",
|
|
1885
|
-
encoding="utf-8",
|
|
1886
|
-
)
|
|
1887
|
-
output = io.StringIO()
|
|
1888
|
-
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
1889
|
-
ap.cmd_structure_check(
|
|
1890
|
-
argparse.Namespace(
|
|
1891
|
-
repo=str(repo), scope="changed", base="", json=True
|
|
1892
|
-
)
|
|
1893
|
-
)
|
|
1894
|
-
|
|
1895
|
-
result = json.loads(output.getvalue())
|
|
1896
|
-
self.assertIs(True, result["block_warnings"])
|
|
1897
|
-
self.assertEqual([], result["blocking"])
|
|
1898
|
-
self.assertEqual(2, len(result["warnings"]))
|
|
1899
|
-
|
|
1900
|
-
def test_changed_scope_light_gate_blocks_promoted_structure_warnings(self) -> None:
|
|
1901
|
-
cfg = base_config()
|
|
1902
|
-
cfg["structure"] = {
|
|
1903
|
-
"enabled": True,
|
|
1904
|
-
"enforcement": "blocking",
|
|
1905
|
-
"block_warnings": True,
|
|
1906
|
-
"max_file_lines_warn": 3,
|
|
1907
|
-
"max_file_lines_block": 50,
|
|
1908
|
-
"max_function_lines_warn": 0,
|
|
1909
|
-
"max_added_lines_to_large_file": 50,
|
|
1910
|
-
"layer_rules": {"enabled": False},
|
|
1911
|
-
}
|
|
1912
|
-
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1913
|
-
repo, _ = self.make_repo("src/warn-only.py", cfg)
|
|
1914
|
-
(repo / "src" / "warn-only.py").write_text(
|
|
1915
|
-
"one\ntwo\nthree\nfour\n",
|
|
1916
|
-
encoding="utf-8",
|
|
1917
|
-
)
|
|
1918
|
-
|
|
1919
|
-
with mock.patch.object(ap, "_record_evidence"):
|
|
1920
|
-
with self.assertRaisesRegex(APError, "structure-check failed"):
|
|
1921
|
-
ap.cmd_light_gate(
|
|
1922
|
-
argparse.Namespace(
|
|
1923
|
-
repo=str(repo),
|
|
1924
|
-
scope="changed",
|
|
1925
|
-
profile="",
|
|
1926
|
-
mode="dev",
|
|
1927
|
-
base="",
|
|
1928
|
-
explain=False,
|
|
1929
|
-
)
|
|
1930
|
-
)
|
|
1931
|
-
|
|
1932
|
-
def test_doctor_validates_structure_block_warnings_type_and_advises_on_no_effect(self) -> None:
|
|
1933
|
-
cfg = base_config()
|
|
1934
|
-
cfg["structure"] = {
|
|
1935
|
-
"enabled": True,
|
|
1936
|
-
"enforcement": "blocking",
|
|
1937
|
-
"block_warnings": "true",
|
|
1938
|
-
}
|
|
1939
|
-
repo, _ = self.make_repo(config=cfg)
|
|
1940
|
-
with self.assertRaisesRegex(
|
|
1941
|
-
APError,
|
|
1942
|
-
"structure.block_warnings must be a boolean",
|
|
1943
|
-
):
|
|
1944
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
1945
|
-
|
|
1946
|
-
cfg = base_config()
|
|
1947
|
-
cfg["structure"] = {
|
|
1948
|
-
"enabled": True,
|
|
1949
|
-
"enforcement": "advisory",
|
|
1950
|
-
"block_warnings": True,
|
|
1951
|
-
}
|
|
1952
|
-
repo, _ = self.make_repo(config=cfg)
|
|
1953
|
-
output = io.StringIO()
|
|
1954
|
-
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
1955
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
1956
|
-
self.assertIn(
|
|
1957
|
-
"structure.block_warnings has no effect unless structure.enforcement=blocking",
|
|
1958
|
-
output.getvalue(),
|
|
1959
|
-
)
|
|
1960
|
-
self.assertIn("[doctor] OK", output.getvalue())
|
|
1961
|
-
|
|
1962
|
-
def test_java_and_kotlin_semicolon_imports_trigger_layer_rules(self) -> None:
|
|
1963
|
-
structure_cfg = {
|
|
1964
|
-
"layer_rules": {
|
|
1965
|
-
"enabled": True,
|
|
1966
|
-
"block": True,
|
|
1967
|
-
"rules": [
|
|
1968
|
-
{
|
|
1969
|
-
"name": "domain",
|
|
1970
|
-
"paths": ["src/domain/**"],
|
|
1971
|
-
"forbidden_imports": ["**/infrastructure/**"],
|
|
1972
|
-
}
|
|
1973
|
-
],
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
for suffix in ["java", "kt"]:
|
|
1977
|
-
for import_line in [
|
|
1978
|
-
"import com.example.infrastructure.SecretStore;",
|
|
1979
|
-
"import com.example.infrastructure.SecretStore; // boundary",
|
|
1980
|
-
"import com.example.infrastructure.SecretStore; /* boundary */",
|
|
1981
|
-
"import com.example.infrastructure.SecretStore; /* boundary",
|
|
1982
|
-
"import com.example.infrastructure.SecretStore; /* boundary */ // trailing",
|
|
1983
|
-
]:
|
|
1984
|
-
with self.subTest(suffix=suffix, import_line=import_line):
|
|
1985
|
-
path = f"src/domain/Order.{suffix}"
|
|
1986
|
-
issues = ap._structure_boundary_issues(
|
|
1987
|
-
path,
|
|
1988
|
-
[
|
|
1989
|
-
"package com.example.domain;",
|
|
1990
|
-
import_line,
|
|
1991
|
-
"",
|
|
1992
|
-
"class Order {}",
|
|
1993
|
-
],
|
|
1994
|
-
structure_cfg,
|
|
1995
|
-
)
|
|
1996
|
-
self.assertEqual(1, len(issues))
|
|
1997
|
-
self.assertIn("layer 'domain'", issues[0])
|
|
1998
|
-
self.assertIn("com.example.infrastructure.SecretStore", issues[0])
|
|
1999
|
-
|
|
2000
|
-
def test_function_ranges_follow_language_syntax(self) -> None:
|
|
2001
|
-
fixtures = [
|
|
2002
|
-
(
|
|
2003
|
-
"repository.go",
|
|
2004
|
-
[
|
|
2005
|
-
"package sample",
|
|
2006
|
-
"",
|
|
2007
|
-
"func (r *Repository) Find() error {",
|
|
2008
|
-
" if r == nil {",
|
|
2009
|
-
" return nil",
|
|
2010
|
-
" }",
|
|
2011
|
-
" return nil",
|
|
2012
|
-
"}",
|
|
2013
|
-
"",
|
|
2014
|
-
"var after = 1",
|
|
2015
|
-
],
|
|
2016
|
-
3,
|
|
2017
|
-
6,
|
|
2018
|
-
),
|
|
2019
|
-
(
|
|
2020
|
-
"normalize.py",
|
|
2021
|
-
[
|
|
2022
|
-
"def normalize(value):",
|
|
2023
|
-
" if value:",
|
|
2024
|
-
" return value",
|
|
2025
|
-
" return None",
|
|
2026
|
-
"after = 1",
|
|
2027
|
-
],
|
|
2028
|
-
1,
|
|
2029
|
-
4,
|
|
2030
|
-
),
|
|
2031
|
-
(
|
|
2032
|
-
"block-arrow.ts",
|
|
2033
|
-
[
|
|
2034
|
-
"const block = () => {",
|
|
2035
|
-
' const literal = "}";',
|
|
2036
|
-
" // } inside a comment is not the function end",
|
|
2037
|
-
" if (literal) {",
|
|
2038
|
-
" return literal;",
|
|
2039
|
-
" }",
|
|
2040
|
-
' return "";',
|
|
2041
|
-
"};",
|
|
2042
|
-
"const after = 1;",
|
|
2043
|
-
],
|
|
2044
|
-
1,
|
|
2045
|
-
8,
|
|
2046
|
-
),
|
|
2047
|
-
(
|
|
2048
|
-
"expression-arrow.ts",
|
|
2049
|
-
[
|
|
2050
|
-
"const expression = value =>",
|
|
2051
|
-
" value",
|
|
2052
|
-
" .trim()",
|
|
2053
|
-
" .toLowerCase();",
|
|
2054
|
-
"const after = 1;",
|
|
2055
|
-
],
|
|
2056
|
-
1,
|
|
2057
|
-
4,
|
|
2058
|
-
),
|
|
2059
|
-
(
|
|
2060
|
-
"parenthesized-arrow.ts",
|
|
2061
|
-
[
|
|
2062
|
-
"const expression = value => (",
|
|
2063
|
-
" value",
|
|
2064
|
-
" .trim()",
|
|
2065
|
-
" .toLowerCase()",
|
|
2066
|
-
");",
|
|
2067
|
-
"const after = 1;",
|
|
2068
|
-
],
|
|
2069
|
-
1,
|
|
2070
|
-
5,
|
|
2071
|
-
),
|
|
2072
|
-
(
|
|
2073
|
-
"conditional-arrow.ts",
|
|
2074
|
-
[
|
|
2075
|
-
"const choose = value => value ?",
|
|
2076
|
-
" first :",
|
|
2077
|
-
" second;",
|
|
2078
|
-
"const after = 1;",
|
|
2079
|
-
],
|
|
2080
|
-
1,
|
|
2081
|
-
3,
|
|
2082
|
-
),
|
|
2083
|
-
(
|
|
2084
|
-
"view-arrow.tsx",
|
|
2085
|
-
[
|
|
2086
|
-
"const View = () => <section>",
|
|
2087
|
-
" <span>value</span>",
|
|
2088
|
-
"</section>;",
|
|
2089
|
-
"const after = 1;",
|
|
2090
|
-
],
|
|
2091
|
-
1,
|
|
2092
|
-
3,
|
|
2093
|
-
),
|
|
2094
|
-
(
|
|
2095
|
-
"multiline-params.ts",
|
|
2096
|
-
[
|
|
2097
|
-
"const multi = (",
|
|
2098
|
-
" value: string,",
|
|
2099
|
-
" count: number,",
|
|
2100
|
-
") => {",
|
|
2101
|
-
" return value.repeat(count);",
|
|
2102
|
-
"};",
|
|
2103
|
-
"const after = 1;",
|
|
2104
|
-
],
|
|
2105
|
-
1,
|
|
2106
|
-
6,
|
|
2107
|
-
),
|
|
2108
|
-
(
|
|
2109
|
-
"typed-arrow-factory.ts",
|
|
2110
|
-
[
|
|
2111
|
-
"const factory = (): (x: string) => { value: string } => {",
|
|
2112
|
-
" const build = (value: string) => ({ value });",
|
|
2113
|
-
" return build;",
|
|
2114
|
-
"};",
|
|
2115
|
-
"const after = 1;",
|
|
2116
|
-
],
|
|
2117
|
-
1,
|
|
2118
|
-
4,
|
|
2119
|
-
),
|
|
2120
|
-
(
|
|
2121
|
-
"typed-generic-arrow-factory.ts",
|
|
2122
|
-
[
|
|
2123
|
-
"const factory = (): <T>(x: T) => { value: T } => {",
|
|
2124
|
-
" const build = <T>(value: T) => ({ value });",
|
|
2125
|
-
" return build;",
|
|
2126
|
-
"};",
|
|
2127
|
-
"const after = 1;",
|
|
2128
|
-
],
|
|
2129
|
-
1,
|
|
2130
|
-
4,
|
|
2131
|
-
),
|
|
2132
|
-
(
|
|
2133
|
-
"typed-constrained-generic-arrow.ts",
|
|
2134
|
-
[
|
|
2135
|
-
"const factory = <T extends (x: string) => { value: string }>(cb: T): void => {",
|
|
2136
|
-
" void cb;",
|
|
2137
|
-
" return;",
|
|
2138
|
-
"};",
|
|
2139
|
-
"const after = 1;",
|
|
2140
|
-
],
|
|
2141
|
-
1,
|
|
2142
|
-
4,
|
|
2143
|
-
),
|
|
2144
|
-
(
|
|
2145
|
-
"typed-defaulted-generic-arrow.ts",
|
|
2146
|
-
[
|
|
2147
|
-
"const factory = <T = () => { value: string }>(cb?: T): void => {",
|
|
2148
|
-
" void cb;",
|
|
2149
|
-
" return;",
|
|
2150
|
-
"};",
|
|
2151
|
-
"const after = 1;",
|
|
2152
|
-
],
|
|
2153
|
-
1,
|
|
2154
|
-
4,
|
|
2155
|
-
),
|
|
2156
|
-
(
|
|
2157
|
-
"typed-function.ts",
|
|
2158
|
-
[
|
|
2159
|
-
"export async function listBudgetRanges(",
|
|
2160
|
-
" scope: string,",
|
|
2161
|
-
"): Promise<BudgetRange[]> {",
|
|
2162
|
-
" return request(scope);",
|
|
2163
|
-
"}",
|
|
2164
|
-
"const after = 1;",
|
|
2165
|
-
],
|
|
2166
|
-
1,
|
|
2167
|
-
5,
|
|
2168
|
-
),
|
|
2169
|
-
(
|
|
2170
|
-
"typed-literal-function.ts",
|
|
2171
|
-
[
|
|
2172
|
-
"export function buildValue(): {",
|
|
2173
|
-
" value: string;",
|
|
2174
|
-
"} {",
|
|
2175
|
-
" return { value: 'ready' };",
|
|
2176
|
-
"}",
|
|
2177
|
-
"const after = 1;",
|
|
2178
|
-
],
|
|
2179
|
-
1,
|
|
2180
|
-
5,
|
|
2181
|
-
),
|
|
2182
|
-
(
|
|
2183
|
-
"typed-generic-constraint.ts",
|
|
2184
|
-
[
|
|
2185
|
-
"export function constrained<T extends { kind: string }>(",
|
|
2186
|
-
" value: T,",
|
|
2187
|
-
"): T {",
|
|
2188
|
-
" return value;",
|
|
2189
|
-
"}",
|
|
2190
|
-
"const after = 1;",
|
|
2191
|
-
],
|
|
2192
|
-
1,
|
|
2193
|
-
5,
|
|
2194
|
-
),
|
|
2195
|
-
(
|
|
2196
|
-
"typed-function-return.ts",
|
|
2197
|
-
[
|
|
2198
|
-
"export function makeFactory(): (x: string) => { value: string } {",
|
|
2199
|
-
" return value => ({ value });",
|
|
2200
|
-
"}",
|
|
2201
|
-
"const after = 1;",
|
|
2202
|
-
],
|
|
2203
|
-
1,
|
|
2204
|
-
3,
|
|
2205
|
-
),
|
|
2206
|
-
(
|
|
2207
|
-
"typed-generic-function-return.ts",
|
|
2208
|
-
[
|
|
2209
|
-
"export function makeGenericFactory(): <T>(x: T) => { value: T } {",
|
|
2210
|
-
" return value => ({ value });",
|
|
2211
|
-
"}",
|
|
2212
|
-
"const after = 1;",
|
|
2213
|
-
],
|
|
2214
|
-
1,
|
|
2215
|
-
3,
|
|
2216
|
-
),
|
|
2217
|
-
(
|
|
2218
|
-
"typed-conditional-return.ts",
|
|
2219
|
-
[
|
|
2220
|
-
"export function choose<T>(",
|
|
2221
|
-
" value: T,",
|
|
2222
|
-
"): T extends { kind: string } ? { matched: T } : { matched: never } {",
|
|
2223
|
-
" return { matched: value } as never;",
|
|
2224
|
-
"}",
|
|
2225
|
-
"const after = 1;",
|
|
2226
|
-
],
|
|
2227
|
-
1,
|
|
2228
|
-
5,
|
|
2229
|
-
),
|
|
2230
|
-
(
|
|
2231
|
-
"typed-keyof-return.ts",
|
|
2232
|
-
[
|
|
2233
|
-
"export function key(): keyof { ready: boolean } {",
|
|
2234
|
-
" return 'ready';",
|
|
2235
|
-
"}",
|
|
2236
|
-
"const after = 1;",
|
|
2237
|
-
],
|
|
2238
|
-
1,
|
|
2239
|
-
3,
|
|
2240
|
-
),
|
|
2241
|
-
(
|
|
2242
|
-
"typed-predicate-return.ts",
|
|
2243
|
-
[
|
|
2244
|
-
"export function isReady(value: unknown): value is { ready: true } {",
|
|
2245
|
-
" return Boolean(value);",
|
|
2246
|
-
"}",
|
|
2247
|
-
"const after = 1;",
|
|
2248
|
-
],
|
|
2249
|
-
1,
|
|
2250
|
-
3,
|
|
2251
|
-
),
|
|
2252
|
-
(
|
|
2253
|
-
"typed-multiline-generic-return.ts",
|
|
2254
|
-
[
|
|
2255
|
-
"export function load(): Promise<",
|
|
2256
|
-
" { value: string }",
|
|
2257
|
-
"> {",
|
|
2258
|
-
" return Promise.resolve({ value: 'ready' });",
|
|
2259
|
-
"}",
|
|
2260
|
-
"const after = 1;",
|
|
2261
|
-
],
|
|
2262
|
-
1,
|
|
2263
|
-
5,
|
|
2264
|
-
),
|
|
2265
|
-
(
|
|
2266
|
-
"typed-multiline-union-return.ts",
|
|
2267
|
-
[
|
|
2268
|
-
"export function union():",
|
|
2269
|
-
" | { kind: 'a' }",
|
|
2270
|
-
" | { kind: 'b' }",
|
|
2271
|
-
"{",
|
|
2272
|
-
" return { kind: 'a' };",
|
|
2273
|
-
"}",
|
|
2274
|
-
"const after = 1;",
|
|
2275
|
-
],
|
|
2276
|
-
1,
|
|
2277
|
-
6,
|
|
2278
|
-
),
|
|
2279
|
-
(
|
|
2280
|
-
"typed-commented-return.ts",
|
|
2281
|
-
[
|
|
2282
|
-
"export function commented(): /* result */ { value: string } {",
|
|
2283
|
-
" return { value: 'ready' };",
|
|
2284
|
-
"}",
|
|
2285
|
-
"const after = 1;",
|
|
2286
|
-
],
|
|
2287
|
-
1,
|
|
2288
|
-
3,
|
|
2289
|
-
),
|
|
2290
|
-
(
|
|
2291
|
-
"same-indent-plus.ts",
|
|
2292
|
-
[
|
|
2293
|
-
"const sum = value => value",
|
|
2294
|
-
"+ increment",
|
|
2295
|
-
"+ extra;",
|
|
2296
|
-
"const after = 1;",
|
|
2297
|
-
],
|
|
2298
|
-
1,
|
|
2299
|
-
3,
|
|
2300
|
-
),
|
|
2301
|
-
(
|
|
2302
|
-
"same-indent-chain.ts",
|
|
2303
|
-
[
|
|
2304
|
-
"const normalized = value => value",
|
|
2305
|
-
".trim()",
|
|
2306
|
-
".toLowerCase();",
|
|
2307
|
-
"const after = 1;",
|
|
2308
|
-
],
|
|
2309
|
-
1,
|
|
2310
|
-
3,
|
|
2311
|
-
),
|
|
2312
|
-
(
|
|
2313
|
-
"conditional-jsx.tsx",
|
|
2314
|
-
[
|
|
2315
|
-
"const Choice = value => (",
|
|
2316
|
-
" value ?",
|
|
2317
|
-
" <Accept /> :",
|
|
2318
|
-
" <Reject />",
|
|
2319
|
-
");",
|
|
2320
|
-
"const after = 1;",
|
|
2321
|
-
],
|
|
2322
|
-
1,
|
|
2323
|
-
5,
|
|
2324
|
-
),
|
|
2325
|
-
(
|
|
2326
|
-
"self-closing-jsx.tsx",
|
|
2327
|
-
[
|
|
2328
|
-
"function CompactView({ value }: { value: string }) {",
|
|
2329
|
-
" return (",
|
|
2330
|
-
" <section>",
|
|
2331
|
-
" <Widget",
|
|
2332
|
-
" value={value}",
|
|
2333
|
-
" />",
|
|
2334
|
-
' <span title="login/payment">{value}</span>',
|
|
2335
|
-
" </section>",
|
|
2336
|
-
" );",
|
|
2337
|
-
"}",
|
|
2338
|
-
"const after = 1;",
|
|
2339
|
-
],
|
|
2340
|
-
1,
|
|
2341
|
-
10,
|
|
2342
|
-
),
|
|
2343
|
-
(
|
|
2344
|
-
"self-closing-expression-jsx.tsx",
|
|
2345
|
-
[
|
|
2346
|
-
"const CompactIcon = () => (",
|
|
2347
|
-
" <svg>",
|
|
2348
|
-
" <path",
|
|
2349
|
-
" d=\"M0 0\"",
|
|
2350
|
-
" />",
|
|
2351
|
-
' <text aria-label="login/payment">ok</text>',
|
|
2352
|
-
" </svg>",
|
|
2353
|
-
");",
|
|
2354
|
-
"const after = 1;",
|
|
2355
|
-
],
|
|
2356
|
-
1,
|
|
2357
|
-
8,
|
|
2358
|
-
),
|
|
2359
|
-
(
|
|
2360
|
-
"conditional-self-closing-jsx.tsx",
|
|
2361
|
-
[
|
|
2362
|
-
"function ConditionalView({ show }: { show: boolean }) {",
|
|
2363
|
-
" return (",
|
|
2364
|
-
" <section>",
|
|
2365
|
-
" {show && <Widget",
|
|
2366
|
-
' value="ready"',
|
|
2367
|
-
" />}",
|
|
2368
|
-
" </section>",
|
|
2369
|
-
" );",
|
|
2370
|
-
"}",
|
|
2371
|
-
"const after = 1;",
|
|
2372
|
-
],
|
|
2373
|
-
1,
|
|
2374
|
-
9,
|
|
2375
|
-
),
|
|
2376
|
-
(
|
|
2377
|
-
"conditional-self-closing-expression.tsx",
|
|
2378
|
-
[
|
|
2379
|
-
"const ConditionalView = ({ show }: { show: boolean }) => (",
|
|
2380
|
-
" <section>",
|
|
2381
|
-
" {show && <Widget",
|
|
2382
|
-
' value="ready"',
|
|
2383
|
-
" />}",
|
|
2384
|
-
" </section>",
|
|
2385
|
-
");",
|
|
2386
|
-
"const after = 1;",
|
|
2387
|
-
],
|
|
2388
|
-
1,
|
|
2389
|
-
7,
|
|
2390
|
-
),
|
|
2391
|
-
]
|
|
2392
|
-
trailing_top_level_lines = [f"top_level_{index} = {index}" for index in range(20)]
|
|
2393
|
-
for path, lines, start_line, expected_size in fixtures:
|
|
2394
|
-
with self.subTest(path=path):
|
|
2395
|
-
warnings = ap._function_size_warnings(
|
|
2396
|
-
path,
|
|
2397
|
-
lines + trailing_top_level_lines,
|
|
2398
|
-
expected_size - 1,
|
|
2399
|
-
)
|
|
2400
|
-
self.assertEqual(1, len(warnings))
|
|
2401
|
-
self.assertIn(f"{path}:{start_line}", warnings[0])
|
|
2402
|
-
self.assertIn(f"has {expected_size} lines", warnings[0])
|
|
2403
|
-
|
|
2404
|
-
def test_python_inline_suite_does_not_absorb_top_level_code(self) -> None:
|
|
2405
|
-
lines = ["def ready(): return True"] + [f"top_level_{index} = {index}" for index in range(200)]
|
|
2406
|
-
self.assertEqual([], ap._function_size_warnings("inline.py", lines, 120))
|
|
2407
|
-
|
|
2408
|
-
def test_multiline_arrow_declaration_has_one_size_finding(self) -> None:
|
|
2409
|
-
lines = [
|
|
2410
|
-
"const multi = (",
|
|
2411
|
-
" value: string,",
|
|
2412
|
-
") => {",
|
|
2413
|
-
*[f" const value_{index} = value;" for index in range(10)],
|
|
2414
|
-
"};",
|
|
2415
|
-
]
|
|
2416
|
-
warnings = ap._function_size_warnings("multi.ts", lines, 5)
|
|
2417
|
-
self.assertEqual(1, len(warnings), warnings)
|
|
2418
|
-
self.assertIn("multi.ts:1", warnings[0])
|
|
2419
|
-
|
|
2420
|
-
def test_same_line_fallback_uses_longest_callback(self) -> None:
|
|
2421
|
-
lines = [
|
|
2422
|
-
"consume(first => {}, second => {",
|
|
2423
|
-
*[f" const value_{index} = second;" for index in range(10)],
|
|
2424
|
-
"});",
|
|
2425
|
-
]
|
|
2426
|
-
warnings = ap._function_size_warnings("callbacks.ts", lines, 5)
|
|
2427
|
-
self.assertEqual(1, len(warnings), warnings)
|
|
2428
|
-
self.assertIn("callbacks.ts:1", warnings[0])
|
|
2429
|
-
|
|
2430
|
-
def test_function_ranges_ignore_type_braces_regex_literals_and_prior_assignments(self) -> None:
|
|
2431
|
-
long_body = [f" value_{index} := {index}" for index in range(130)]
|
|
2432
|
-
go_lines = [
|
|
2433
|
-
"package sample",
|
|
2434
|
-
"func build() struct {",
|
|
2435
|
-
" Value string",
|
|
2436
|
-
"} {",
|
|
2437
|
-
*long_body,
|
|
2438
|
-
" return struct { Value string }{}",
|
|
2439
|
-
"}",
|
|
2440
|
-
]
|
|
2441
|
-
self.assertEqual(1, len(ap._function_size_warnings("builder.go", go_lines, 120)))
|
|
2442
|
-
|
|
2443
|
-
js_lines = [
|
|
2444
|
-
"const block = () => {",
|
|
2445
|
-
" const matcher = /}/;",
|
|
2446
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2447
|
-
"};",
|
|
2448
|
-
]
|
|
2449
|
-
self.assertEqual(1, len(ap._function_size_warnings("regex.js", js_lines, 120)))
|
|
2450
|
-
|
|
2451
|
-
regex_gt_lines = [
|
|
2452
|
-
"function block() {",
|
|
2453
|
-
" const matcher = />}/;",
|
|
2454
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2455
|
-
"}",
|
|
2456
|
-
]
|
|
2457
|
-
self.assertEqual(1, len(ap._function_size_warnings("regex-gt.js", regex_gt_lines, 120)))
|
|
2458
|
-
closing_tag_regex_lines = [
|
|
2459
|
-
"function block() {",
|
|
2460
|
-
" const matcher = /section>}/;",
|
|
2461
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2462
|
-
"}",
|
|
2463
|
-
]
|
|
2464
|
-
self.assertEqual(
|
|
2465
|
-
1,
|
|
2466
|
-
len(ap._function_size_warnings("closing-tag-regex.js", closing_tag_regex_lines, 120)),
|
|
2467
|
-
)
|
|
2468
|
-
comparison_regex_lines = [
|
|
2469
|
-
"function block() {",
|
|
2470
|
-
' const matched = value</section>}/.test("section>}");',
|
|
2471
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2472
|
-
"}",
|
|
2473
|
-
]
|
|
2474
|
-
self.assertEqual(
|
|
2475
|
-
1,
|
|
2476
|
-
len(ap._function_size_warnings("comparison-regex.js", comparison_regex_lines, 120)),
|
|
2477
|
-
)
|
|
2478
|
-
semicolon_regex_lines = [
|
|
2479
|
-
"function block() {",
|
|
2480
|
-
r' const matched = value</section>;\}/.test("section>;} ");',
|
|
2481
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2482
|
-
"}",
|
|
2483
|
-
]
|
|
2484
|
-
self.assertEqual(
|
|
2485
|
-
1,
|
|
2486
|
-
len(ap._function_size_warnings("semicolon-regex.js", semicolon_regex_lines, 120)),
|
|
2487
|
-
)
|
|
2488
|
-
for suffix_expression in ["/}/ as RegExp", "/}/ satisfies RegExp"]:
|
|
2489
|
-
ts_regex_lines = [
|
|
2490
|
-
"function block() {",
|
|
2491
|
-
f" const matcher = {suffix_expression};",
|
|
2492
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2493
|
-
"}",
|
|
2494
|
-
]
|
|
2495
|
-
with self.subTest(suffix_expression=suffix_expression):
|
|
2496
|
-
self.assertEqual(
|
|
2497
|
-
1,
|
|
2498
|
-
len(ap._function_size_warnings("regex-suffix.ts", ts_regex_lines, 120)),
|
|
2499
|
-
)
|
|
2500
|
-
for prefix_expression in [
|
|
2501
|
-
'const html = "<Tag>";',
|
|
2502
|
-
"const pattern = /<Tag>/;",
|
|
2503
|
-
"foo<Tag>();",
|
|
2504
|
-
"const typed: Box<Tag> | null = null;",
|
|
2505
|
-
"const cast = box as Box<Tag>;",
|
|
2506
|
-
"const first = <A></A>; const second = <B></B>;",
|
|
2507
|
-
]:
|
|
2508
|
-
prefixed_regex_lines = [
|
|
2509
|
-
"function block() {",
|
|
2510
|
-
f" {prefix_expression} const matched = value</section>}}/.test(text);",
|
|
2511
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2512
|
-
"}",
|
|
2513
|
-
]
|
|
2514
|
-
with self.subTest(prefix_expression=prefix_expression):
|
|
2515
|
-
self.assertEqual(
|
|
2516
|
-
1,
|
|
2517
|
-
len(ap._function_size_warnings("prefixed-regex.ts", prefixed_regex_lines, 120)),
|
|
2518
|
-
)
|
|
2519
|
-
for generic_comparison in [
|
|
2520
|
-
" const matched = (box as Box<Tag>).value</section>}/.test(text);",
|
|
2521
|
-
" const matched: boolean | Box<Tag> = value</section>}/.test(text);",
|
|
2522
|
-
" const matched = (<Outer>{foo<Tag>()}</Outer>) && value</section>}/.test(text);",
|
|
2523
|
-
" const matched = (<Outer>{(box as Box<Tag>).value}</Outer>) && value</section>}/.test(text);",
|
|
2524
|
-
" const matched = (<Outer>{show && <Tag>hello</Tag>}</Outer>) && value</section>}/.test(text);",
|
|
2525
|
-
" const matched = (<Outer>hello<Tag>world</Tag></Outer>) && value</section>}/.test(text);",
|
|
2526
|
-
]:
|
|
2527
|
-
generic_regex_lines = [
|
|
2528
|
-
"function block() {",
|
|
2529
|
-
generic_comparison,
|
|
2530
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2531
|
-
"}",
|
|
2532
|
-
]
|
|
2533
|
-
with self.subTest(generic_comparison=generic_comparison):
|
|
2534
|
-
self.assertEqual(
|
|
2535
|
-
1,
|
|
2536
|
-
len(ap._function_size_warnings("generic-regex.ts", generic_regex_lines, 120)),
|
|
2537
|
-
)
|
|
2538
|
-
comparison = "const matched = value</>}/.test(text);"
|
|
2539
|
-
self.assertTrue(ap._looks_like_regex_start(comparison, comparison.index("/")))
|
|
2540
|
-
named_comparison = "const matched = value</section>}/.test(text);"
|
|
2541
|
-
self.assertTrue(ap._looks_like_regex_start(named_comparison, named_comparison.index("/")))
|
|
2542
|
-
assigned = "const matcher = /section>}/;"
|
|
2543
|
-
self.assertTrue(ap._looks_like_regex_start(assigned, assigned.index("/")))
|
|
2544
|
-
returned = "return /foo>/;"
|
|
2545
|
-
self.assertTrue(ap._looks_like_regex_start(returned, returned.index("/")))
|
|
2546
|
-
self.assertFalse(ap._looks_like_regex_start(" />", 4))
|
|
2547
|
-
self.assertFalse(ap._looks_like_regex_start(" </section>", 5))
|
|
2548
|
-
self.assertFalse(ap._looks_like_regex_start(" </_Private>", 5))
|
|
2549
|
-
self.assertFalse(ap._looks_like_regex_start(" </$Component>", 5))
|
|
2550
|
-
self.assertFalse(ap._looks_like_regex_start(" />}", 4))
|
|
2551
|
-
self.assertFalse(ap._looks_like_regex_start(" /> : null}", 4))
|
|
2552
|
-
jsx_close_same_line = " />}</section>;"
|
|
2553
|
-
self.assertFalse(ap._looks_like_regex_start(jsx_close_same_line, 4))
|
|
2554
|
-
|
|
2555
|
-
jsx_block = [
|
|
2556
|
-
"function F() {",
|
|
2557
|
-
" return <section>",
|
|
2558
|
-
" {show && <Widget",
|
|
2559
|
-
" x={1}",
|
|
2560
|
-
" />}</section>;",
|
|
2561
|
-
*[f" const value_{index} = {index};" for index in range(130)],
|
|
2562
|
-
"}",
|
|
2563
|
-
]
|
|
2564
|
-
self.assertEqual(1, len(ap._function_size_warnings("jsx-block.tsx", jsx_block, 120)))
|
|
2565
|
-
|
|
2566
|
-
jsx_expression = [
|
|
2567
|
-
"const F = () => (",
|
|
2568
|
-
" <section>",
|
|
2569
|
-
" {show && <Widget",
|
|
2570
|
-
" x={1}",
|
|
2571
|
-
" />}</section>",
|
|
2572
|
-
");",
|
|
2573
|
-
"const after = 1;",
|
|
2574
|
-
]
|
|
2575
|
-
arrow_location = ap._find_arrow_locations(jsx_expression, 0, None)[0]
|
|
2576
|
-
self.assertEqual(
|
|
2577
|
-
(6, False),
|
|
2578
|
-
ap._expression_arrow_end(jsx_expression, 0, arrow_location, 6, None, ".tsx"),
|
|
2579
|
-
)
|
|
2580
|
-
self.assertEqual([], ap._function_size_warnings("jsx-expression.tsx", jsx_expression, 6))
|
|
2581
|
-
|
|
2582
|
-
trailing_jsx_expressions = [
|
|
2583
|
-
["const F = () => <Tag></Tag>; // comment", "const after = 1;"],
|
|
2584
|
-
["const F = () => <Tag></Tag>; /* comment */", "const after = 1;"],
|
|
2585
|
-
["const F = () => <Tag></Tag> / divisor;", "const after = 1;"],
|
|
2586
|
-
["const F = () => <Tag>hello</Tag>/(divisor);", "const after = 1;"],
|
|
2587
|
-
["const F = () => <></>; // comment", "const after = 1;"],
|
|
2588
|
-
[
|
|
2589
|
-
"const F = () => (",
|
|
2590
|
-
" <Widget",
|
|
2591
|
-
" value={1}",
|
|
2592
|
-
" />); // comment",
|
|
2593
|
-
"const after = 1;",
|
|
2594
|
-
],
|
|
2595
|
-
]
|
|
2596
|
-
for expression in trailing_jsx_expressions:
|
|
2597
|
-
with self.subTest(expression=expression):
|
|
2598
|
-
arrow_location = ap._find_arrow_locations(expression, 0, None)[0]
|
|
2599
|
-
expected_end = len(expression) - 1
|
|
2600
|
-
self.assertEqual(
|
|
2601
|
-
(expected_end, False),
|
|
2602
|
-
ap._expression_arrow_end(
|
|
2603
|
-
expression, 0, arrow_location, expected_end, None, ".tsx"
|
|
2604
|
-
),
|
|
2605
|
-
)
|
|
2606
|
-
self.assertEqual(
|
|
2607
|
-
[],
|
|
2608
|
-
ap._function_size_warnings("trailing-jsx.tsx", expression, expected_end),
|
|
2609
|
-
)
|
|
2610
|
-
|
|
2611
|
-
multiline_jsx_text = [
|
|
2612
|
-
"const F = () => (",
|
|
2613
|
-
" <Tag>",
|
|
2614
|
-
" hello</Tag>/(divisor)",
|
|
2615
|
-
");",
|
|
2616
|
-
"const after = 1;",
|
|
2617
|
-
]
|
|
2618
|
-
arrow_location = ap._find_arrow_locations(multiline_jsx_text, 0, None)[0]
|
|
2619
|
-
self.assertEqual(
|
|
2620
|
-
(4, False),
|
|
2621
|
-
ap._expression_arrow_end(multiline_jsx_text, 0, arrow_location, 4, None, ".tsx"),
|
|
2622
|
-
)
|
|
2623
|
-
self.assertEqual([], ap._function_size_warnings("multiline-jsx.tsx", multiline_jsx_text, 4))
|
|
2624
|
-
|
|
2625
|
-
for jsx_expression_body in [
|
|
2626
|
-
' {value</section>}/.test(text) ? "yes" : "no"}',
|
|
2627
|
-
' {/>}/.test(text) ? "yes" : "no"}',
|
|
2628
|
-
]:
|
|
2629
|
-
jsx_regex_expression = [
|
|
2630
|
-
"const F = () => <Tag>",
|
|
2631
|
-
jsx_expression_body,
|
|
2632
|
-
"</Tag>;",
|
|
2633
|
-
"const after = 1;",
|
|
2634
|
-
]
|
|
2635
|
-
with self.subTest(jsx_expression_body=jsx_expression_body):
|
|
2636
|
-
arrow_location = ap._find_arrow_locations(jsx_regex_expression, 0, None)[0]
|
|
2637
|
-
self.assertEqual(
|
|
2638
|
-
(3, False),
|
|
2639
|
-
ap._expression_arrow_end(
|
|
2640
|
-
jsx_regex_expression, 0, arrow_location, 3, None, ".tsx"
|
|
2641
|
-
),
|
|
2642
|
-
)
|
|
2643
|
-
self.assertEqual(
|
|
2644
|
-
1,
|
|
2645
|
-
len(
|
|
2646
|
-
ap._function_size_warnings(
|
|
2647
|
-
"jsx-regex-expression.tsx", jsx_regex_expression, 2
|
|
2648
|
-
)
|
|
2649
|
-
),
|
|
2650
|
-
)
|
|
2651
|
-
|
|
2652
|
-
separate_declarations = [
|
|
2653
|
-
'const label = "ready"',
|
|
2654
|
-
"const block = () => {",
|
|
2655
|
-
" return label;",
|
|
2656
|
-
"};",
|
|
2657
|
-
]
|
|
2658
|
-
self.assertEqual([], ap._function_size_warnings("separate.ts", separate_declarations, 3))
|
|
2659
|
-
|
|
2660
|
-
def test_function_range_scan_is_bounded_and_gate_deadline_is_enforced(self) -> None:
|
|
2661
|
-
depth = 4000
|
|
2662
|
-
lines = [f"function nested_{index}() {{" for index in range(depth)]
|
|
2663
|
-
lines.extend("}" for _ in range(depth))
|
|
2664
|
-
started = time.perf_counter()
|
|
2665
|
-
warnings = ap._function_size_warnings("nested.js", lines, 10)
|
|
2666
|
-
elapsed = time.perf_counter() - started
|
|
2667
|
-
self.assertEqual(depth - 5, len(warnings))
|
|
2668
|
-
self.assertLess(elapsed, 3.0, f"function scan must stay threshold-bounded, got {elapsed:.3f}s")
|
|
2669
|
-
|
|
2670
|
-
cfg = base_config()
|
|
2671
|
-
cfg["structure"] = {
|
|
2672
|
-
"enabled": True,
|
|
2673
|
-
"enforcement": "blocking",
|
|
2674
|
-
"max_function_lines_warn": 10,
|
|
2675
|
-
"layer_rules": {"enabled": False},
|
|
2676
|
-
}
|
|
2677
|
-
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
2678
|
-
repo, _ = self.make_repo("src/app.js", cfg)
|
|
2679
|
-
with self.assertRaisesRegex(APError, "timed out during structure check"):
|
|
2680
|
-
ap._run_structure_check_for_gate(
|
|
2681
|
-
repo,
|
|
2682
|
-
cfg,
|
|
2683
|
-
"changed",
|
|
2684
|
-
"",
|
|
2685
|
-
deadline=time.monotonic() - 1,
|
|
2686
|
-
command_timeout_s=30,
|
|
2687
|
-
)
|
|
2688
|
-
|
|
2689
|
-
def test_structure_scan_excludes_non_authoritative_agent_history_and_metadata(self) -> None:
|
|
2690
|
-
repo, _ = self.make_repo()
|
|
2691
|
-
files = {
|
|
2692
|
-
".agents/archive/old.py": "old = True\n",
|
|
2693
|
-
".agents/agents/custom.toml": "model = 'test'\n",
|
|
2694
|
-
".agents/managed-install.json": "{}\n",
|
|
2695
|
-
".agents/custom/check.py": "active = True\n",
|
|
2696
|
-
"src/app.py": "active = True\n",
|
|
2697
|
-
}
|
|
2698
|
-
for relative, content in files.items():
|
|
2699
|
-
target = repo / relative
|
|
2700
|
-
target.parent.mkdir(parents=True, exist_ok=True)
|
|
2701
|
-
target.write_text(content, encoding="utf-8")
|
|
2702
|
-
run(repo, "git", "add", "-A")
|
|
2703
|
-
run(repo, "git", "commit", "-qm", "add structure fixtures")
|
|
2704
|
-
|
|
2705
|
-
candidates = ap._structure_paths_for_scope(repo, "full", "", {})
|
|
2706
|
-
|
|
2707
|
-
self.assertIn(".agents/custom/check.py", candidates)
|
|
2708
|
-
self.assertIn("src/app.py", candidates)
|
|
2709
|
-
self.assertNotIn(".agents/archive/old.py", candidates)
|
|
2710
|
-
self.assertNotIn(".agents/agents/custom.toml", candidates)
|
|
2711
|
-
self.assertNotIn(".agents/managed-install.json", candidates)
|
|
2712
|
-
|
|
2713
|
-
def test_doctor_validates_profile_values(self) -> None:
|
|
2714
|
-
cfg = base_config()
|
|
2715
|
-
cfg["workflow"]["profile"] = "extreme"
|
|
2716
|
-
cfg["gate"]["rules"] = [{"paths": ["src/**"], "profile": "unsafe"}]
|
|
2717
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2718
|
-
with self.assertRaises(APError) as context:
|
|
2719
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2720
|
-
message = str(context.exception)
|
|
2721
|
-
self.assertIn("workflow.profile", message)
|
|
2722
|
-
self.assertIn("gate.rules[0].profile", message)
|
|
2723
|
-
|
|
2724
|
-
def test_doctor_rejects_invalid_rule_scope(self) -> None:
|
|
2725
|
-
cfg = base_config()
|
|
2726
|
-
cfg["docs"]["ledger_check_enabled"] = False
|
|
2727
|
-
cfg["gate"]["rules"] = [{"paths": ["src/**"], "scope": "ful"}]
|
|
2728
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2729
|
-
with self.assertRaises(APError) as context:
|
|
2730
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2731
|
-
self.assertIn("gate.rules[0].scope", str(context.exception))
|
|
2732
|
-
|
|
2733
|
-
def test_project_overlay_render_rejects_its_own_oversized_output(self) -> None:
|
|
2734
|
-
with self.assertRaisesRegex(APError, "exceeds its size limit"):
|
|
2735
|
-
ap._render_project_overlay({"project": {"oversized": "x" * 200_000}})
|
|
2736
|
-
|
|
2737
|
-
def test_project_config_prepare_never_replaces_a_concurrent_overlay(self) -> None:
|
|
2738
|
-
repo, _ = self.make_repo()
|
|
2739
|
-
overlay = repo / "docs" / "project" / "auto-coding-skill.yaml"
|
|
2740
|
-
overlay.parent.mkdir(parents=True, exist_ok=True)
|
|
2741
|
-
concurrent = ap._render_project_overlay({"project": {"name": "concurrent-owner"}})
|
|
2742
|
-
planned = ap._render_project_overlay({"project": {"name": "planned-owner"}})
|
|
2743
|
-
overlay.write_bytes(concurrent)
|
|
2744
|
-
engineering_before = (repo / "docs" / "ENGINEERING.md").read_bytes()
|
|
2745
|
-
convergence = {
|
|
2746
|
-
"engineering_current": "",
|
|
2747
|
-
"engineering_output": engineering_before.decode("utf-8"),
|
|
2748
|
-
"overlay_current": None,
|
|
2749
|
-
"overlay_output": planned,
|
|
2750
|
-
"migrated_paths": ["project.name"],
|
|
2751
|
-
}
|
|
2752
|
-
args = argparse.Namespace(repo=str(repo), write=True, json=False)
|
|
2753
|
-
|
|
2754
|
-
with mock.patch.object(ap, "_project_config_convergence_plan", return_value=convergence):
|
|
2755
|
-
with self.assertRaisesRegex(APError, "create-only publish"):
|
|
2756
|
-
ap.cmd_project_config_prepare(args)
|
|
2757
|
-
|
|
2758
|
-
self.assertEqual(concurrent, overlay.read_bytes())
|
|
2759
|
-
self.assertEqual(engineering_before, (repo / "docs" / "ENGINEERING.md").read_bytes())
|
|
2760
|
-
|
|
2761
|
-
def test_upgrade_write_is_retired_before_any_migration(self) -> None:
|
|
2762
|
-
cfg = base_config()
|
|
2763
|
-
cfg["gate"]["full_on"] = {"paths": ["src/**"]}
|
|
2764
|
-
cfg["gate"]["rules"] = [
|
|
2765
|
-
{
|
|
2766
|
-
"name": "legacy",
|
|
2767
|
-
"paths": ["src/**"],
|
|
2768
|
-
"profile": "high-risk",
|
|
2769
|
-
"scope": "full",
|
|
2770
|
-
"commands": ["gate_full"],
|
|
2771
|
-
}
|
|
2772
|
-
]
|
|
2773
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2774
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
2775
|
-
engineering.write_text(
|
|
2776
|
-
engineering.read_text(encoding="utf-8") + "High-risk work must run the full gate.\n",
|
|
2777
|
-
encoding="utf-8",
|
|
2778
|
-
)
|
|
2779
|
-
policy = self.workflow_policy(
|
|
2780
|
-
fragments=[
|
|
2781
|
-
{
|
|
2782
|
-
"id": "official-high-risk-full",
|
|
2783
|
-
"paths": ["docs/ENGINEERING.md"],
|
|
2784
|
-
"match": "exact-line",
|
|
2785
|
-
"text": "High-risk work must run the full gate.",
|
|
2786
|
-
}
|
|
2787
|
-
]
|
|
2788
|
-
)
|
|
2789
|
-
before = engineering.read_bytes()
|
|
2790
|
-
args = argparse.Namespace(repo=str(repo), write=True, dry_run=False, json=False)
|
|
2791
|
-
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
2792
|
-
with self.assertRaises(APError) as context:
|
|
2793
|
-
ap.cmd_upgrade(args)
|
|
2794
|
-
|
|
2795
|
-
self.assertIn("transactional installer", str(context.exception))
|
|
2796
|
-
self.assertEqual(before, engineering.read_bytes())
|
|
2797
|
-
self.assertFalse((repo / ".agents").exists())
|
|
2798
|
-
|
|
2799
|
-
def test_upgrade_unknown_policy_conflict_fails_before_any_write(self) -> None:
|
|
2800
|
-
repo, _ = self.make_repo()
|
|
2801
|
-
engineering = repo / "docs" / "ENGINEERING.md"
|
|
2802
|
-
engineering.write_text(
|
|
2803
|
-
engineering.read_text(encoding="utf-8")
|
|
2804
|
-
+ "High-risk work must run the full gate.\n",
|
|
2805
|
-
encoding="utf-8",
|
|
2806
|
-
)
|
|
2807
|
-
before = engineering.read_text(encoding="utf-8")
|
|
2808
|
-
args = argparse.Namespace(repo=str(repo), write=False, dry_run=True, json=False)
|
|
2809
|
-
with mock.patch.object(
|
|
2810
|
-
ap,
|
|
2811
|
-
"_project_config_convergence_plan",
|
|
2812
|
-
return_value={},
|
|
2813
|
-
):
|
|
2814
|
-
with mock.patch.object(
|
|
2815
|
-
ap,
|
|
2816
|
-
"_load_workflow_migration_policy",
|
|
2817
|
-
return_value=self.workflow_policy(),
|
|
2818
|
-
):
|
|
2819
|
-
with self.assertRaises(APError) as context:
|
|
2820
|
-
ap.cmd_upgrade(args)
|
|
2821
|
-
self.assertIn("docs/ENGINEERING.md", str(context.exception))
|
|
2822
|
-
self.assertEqual(before, engineering.read_text(encoding="utf-8"))
|
|
2823
|
-
self.assertFalse((repo / ".agents").exists())
|
|
2824
|
-
|
|
2825
|
-
def test_doctor_ignores_managed_blocks_but_rejects_unknown_external_rule(self) -> None:
|
|
2826
|
-
repo, _ = self.make_repo()
|
|
2827
|
-
agents = repo / "AGENTS.md"
|
|
2828
|
-
agents.write_text(
|
|
2829
|
-
"<!-- auto-coding-skill:managed-agents:start version=3.0.2 -->\n"
|
|
2830
|
-
"High-risk work must run the full gate.\n"
|
|
2831
|
-
"<!-- auto-coding-skill:managed-agents:end -->\n",
|
|
2832
|
-
encoding="utf-8",
|
|
2833
|
-
)
|
|
2834
|
-
policy = self.workflow_policy()
|
|
2835
|
-
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
2836
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2837
|
-
agents.write_text(agents.read_text(encoding="utf-8") + "High-risk work must run the full gate.\n", encoding="utf-8")
|
|
2838
|
-
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
2839
|
-
with self.assertRaises(APError) as context:
|
|
2840
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2841
|
-
self.assertIn("AGENTS.md:4", str(context.exception))
|
|
2842
|
-
|
|
2843
|
-
def test_doctor_rejects_legacy_isolation(self) -> None:
|
|
2844
|
-
cfg = base_config()
|
|
2845
|
-
cfg["concurrency"]["isolation"] = "legacy"
|
|
2846
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2847
|
-
with self.assertRaises(APError) as context:
|
|
2848
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2849
|
-
self.assertIn("must be adaptive or worktree", str(context.exception))
|
|
2850
|
-
|
|
2851
|
-
def test_doctor_requires_one_fast_gate_for_every_profile(self) -> None:
|
|
2852
|
-
for profile in ["micro", "standard", "high-risk", "auto"]:
|
|
2853
|
-
with self.subTest(profile=profile):
|
|
2854
|
-
cfg = base_config()
|
|
2855
|
-
cfg["workflow"]["profile"] = profile
|
|
2856
|
-
cfg["commands"] = {"gate_standard": "true", "gate_full": "true"}
|
|
2857
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2858
|
-
with self.assertRaises(APError) as context:
|
|
2859
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2860
|
-
self.assertIn("validation.routes", str(context.exception))
|
|
2861
|
-
|
|
2862
|
-
def test_doctor_requires_direct_access_password_even_with_env_reference(self) -> None:
|
|
2863
|
-
cfg = base_config()
|
|
2864
|
-
cfg["access"]["gitlab"]["password"] = ""
|
|
2865
|
-
cfg["access"]["gitlab"]["password_env"] = "GITLAB_PASSWORD"
|
|
2866
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2867
|
-
with self.assertRaises(APError) as context:
|
|
2868
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2869
|
-
self.assertIn("access.gitlab.password", str(context.exception))
|
|
2870
|
-
|
|
2871
|
-
def test_doctor_rejects_quoted_nullish_access_placeholders(self) -> None:
|
|
2872
|
-
for placeholder in ["NULL", "~"]:
|
|
2873
|
-
with self.subTest(placeholder=placeholder):
|
|
2874
|
-
cfg = base_config()
|
|
2875
|
-
cfg["access"]["gitlab"]["password"] = placeholder
|
|
2876
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2877
|
-
with self.assertRaises(APError) as context:
|
|
2878
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2879
|
-
self.assertIn("access.gitlab.password", str(context.exception))
|
|
2880
|
-
|
|
2881
|
-
def test_doctor_rejects_non_string_access_values(self) -> None:
|
|
2882
|
-
for value in [False, 0]:
|
|
2883
|
-
with self.subTest(value=value):
|
|
2884
|
-
cfg = base_config()
|
|
2885
|
-
cfg["access"]["gitlab"]["password"] = value
|
|
2886
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2887
|
-
with self.assertRaises(APError) as context:
|
|
2888
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2889
|
-
self.assertIn("access.gitlab.password", str(context.exception))
|
|
2890
|
-
|
|
2891
|
-
def test_doctor_validates_access_url_shape_without_network(self) -> None:
|
|
2892
|
-
cfg = base_config()
|
|
2893
|
-
cfg["access"]["nexus"]["frontend"]["url"] = "nexus.local"
|
|
2894
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2895
|
-
with self.assertRaises(APError) as context:
|
|
2896
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2897
|
-
self.assertIn("valid http/https URL", str(context.exception))
|
|
2898
|
-
|
|
2899
|
-
def test_api_docs_required_false_is_an_authoritative_opt_out(self) -> None:
|
|
2900
|
-
cfg = base_config()
|
|
2901
|
-
cfg["docs"].update(
|
|
2902
|
-
{
|
|
2903
|
-
"api_docs_required": False,
|
|
2904
|
-
"api_doc": "docs/interfaces/api.md",
|
|
2905
|
-
"api_change_log": "docs/interfaces/api-change-log.md",
|
|
2906
|
-
}
|
|
2907
|
-
)
|
|
2908
|
-
repo, _ = self.make_repo(config=cfg)
|
|
2909
|
-
api_doc = repo / "docs" / "interfaces" / "api.md"
|
|
2910
|
-
api_doc.parent.mkdir(parents=True, exist_ok=True)
|
|
2911
|
-
api_doc.write_text("# Existing API\n", encoding="utf-8")
|
|
2912
|
-
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2913
|
-
ap.cmd_verify_api_docs(argparse.Namespace(repo=str(repo)))
|
|
2914
|
-
|
|
2915
|
-
def test_root_and_nested_package_json_are_high_risk_and_require_review(self) -> None:
|
|
2916
|
-
repo, cfg = self.make_repo()
|
|
2917
|
-
for path in ["package.json", "frontend/admin/package.json"]:
|
|
2918
|
-
with self.subTest(path=path):
|
|
2919
|
-
plan = self.plan(
|
|
2920
|
-
repo,
|
|
2921
|
-
cfg,
|
|
2922
|
-
planned_paths=[path],
|
|
2923
|
-
requested_task_kind="change",
|
|
2924
|
-
)
|
|
2925
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
2926
|
-
self.assertTrue(plan["review_required"])
|
|
2927
|
-
self.assertIn("release_or_tooling", plan["categories"])
|
|
2928
|
-
|
|
2929
|
-
def test_root_agents_protocol_is_high_risk_release_tooling(self) -> None:
|
|
2930
|
-
repo, cfg = self.make_repo()
|
|
2931
|
-
plan = self.plan(
|
|
2932
|
-
repo,
|
|
2933
|
-
cfg,
|
|
2934
|
-
planned_paths=["AGENTS.md"],
|
|
2935
|
-
requested_task_kind="change",
|
|
2936
|
-
)
|
|
2937
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
2938
|
-
self.assertTrue(plan["review_required"])
|
|
2939
|
-
self.assertIn("release_or_tooling", plan["categories"])
|
|
2940
|
-
|
|
2941
|
-
def test_generic_migration_language_and_managed_policy_are_not_database_risk(self) -> None:
|
|
2942
|
-
repo, cfg = self.make_repo()
|
|
2943
|
-
plan = self.plan(
|
|
2944
|
-
repo,
|
|
2945
|
-
cfg,
|
|
2946
|
-
planned_paths=["docs/project/overlay-migration.md"],
|
|
2947
|
-
intent="Document project overlay migration behavior",
|
|
2948
|
-
requested_task_kind="change",
|
|
2949
|
-
)
|
|
2950
|
-
self.assertNotIn("db", plan["categories"])
|
|
2951
|
-
self.assertNotIn("db", plan["intent_categories"])
|
|
2952
|
-
self.assertNotIn("db", plan["high_confidence_intent_categories"])
|
|
2953
|
-
self.assertNotIn(
|
|
2954
|
-
"db",
|
|
2955
|
-
ap._classify_paths(
|
|
2956
|
-
[".agents/skills/auto-coding-skill/data/policies/workflow-migrations-v1.json"]
|
|
2957
|
-
)["categories"],
|
|
2958
|
-
)
|
|
2959
|
-
self.assertNotIn(
|
|
2960
|
-
"db",
|
|
2961
|
-
ap._classify_paths(
|
|
2962
|
-
["src/auto-coding-skill/data/policies/workflow-migrations-v1.json"]
|
|
2963
|
-
)["categories"],
|
|
2964
|
-
)
|
|
2965
|
-
self.assertIn("db", ap._classify_paths(["migrations/001.sql"])["categories"])
|
|
2966
|
-
|
|
2967
|
-
def test_database_named_source_files_remain_high_risk(self) -> None:
|
|
2968
|
-
repo, cfg = self.make_repo()
|
|
2969
|
-
for path in [
|
|
2970
|
-
"src/db.py",
|
|
2971
|
-
"src/database.py",
|
|
2972
|
-
"src/schema.py",
|
|
2973
|
-
"src/migrations.py",
|
|
2974
|
-
"internal/db.go",
|
|
2975
|
-
"backend/db_migrations/001.py",
|
|
2976
|
-
"backend/database-migrations/001.py",
|
|
2977
|
-
"backend/schema_migrations/001.py",
|
|
2978
|
-
"backend/db-migrations/001.py",
|
|
2979
|
-
]:
|
|
2980
|
-
with self.subTest(path=path):
|
|
2981
|
-
self.assertIn("db", ap._classify_paths([path])["categories"])
|
|
2982
|
-
plan = self.plan(
|
|
2983
|
-
repo,
|
|
2984
|
-
cfg,
|
|
2985
|
-
planned_paths=[path],
|
|
2986
|
-
requested_task_kind="change",
|
|
2987
|
-
)
|
|
2988
|
-
self.assertEqual("high-risk", plan["profile"])
|
|
2989
|
-
self.assertTrue(plan["review_required"])
|
|
2990
|
-
|
|
2991
|
-
def test_explicit_full_structure_scope_inspects_clean_tracked_files(self) -> None:
|
|
2992
|
-
cfg = base_config()
|
|
2993
|
-
cfg["structure"] = {
|
|
2994
|
-
"enabled": True,
|
|
2995
|
-
"enforcement": "advisory",
|
|
2996
|
-
"max_file_lines_warn": 0,
|
|
2997
|
-
"max_file_lines_block": 0,
|
|
2998
|
-
"max_function_lines_warn": 0,
|
|
2999
|
-
"layer_rules": {"enabled": False},
|
|
3000
|
-
}
|
|
3001
|
-
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
3002
|
-
repo, _ = self.make_repo("src/app.py", cfg)
|
|
3003
|
-
run(repo, "git", "add", "-A")
|
|
3004
|
-
run(repo, "git", "commit", "-qm", "add tracked structure fixture")
|
|
3005
|
-
|
|
3006
|
-
output = io.StringIO()
|
|
3007
|
-
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
3008
|
-
ap.cmd_structure_check(
|
|
3009
|
-
argparse.Namespace(repo=str(repo), scope="full", base="", json=True)
|
|
3010
|
-
)
|
|
3011
|
-
|
|
3012
|
-
result = json.loads(output.getvalue())
|
|
3013
|
-
self.assertEqual("full", result["scope"])
|
|
3014
|
-
self.assertGreaterEqual(result["inspected_files"], 1)
|
|
3015
|
-
|
|
3016
|
-
def test_verify_jenkins_accepts_access_schema_and_uses_selected_identity(self) -> None:
|
|
3017
|
-
repo, cfg = self.make_repo()
|
|
3018
|
-
(repo / "Jenkinsfile").write_text("pipeline {}\n", encoding="utf-8")
|
|
3019
|
-
|
|
3020
|
-
with mock.patch.object(ap, "_record_evidence"):
|
|
3021
|
-
ap.cmd_verify_jenkins(argparse.Namespace(repo=str(repo), component="all"))
|
|
3022
|
-
|
|
3023
|
-
header = ap._jenkins_basic_auth_headers(cfg, component="backend")["Authorization"]
|
|
3024
|
-
decoded = base64.b64decode(header.removeprefix("Basic ")).decode("utf-8")
|
|
3025
|
-
self.assertEqual("back:back-pass", decoded)
|
|
3026
|
-
|
|
3027
|
-
def test_jenkins_component_is_ambiguous_with_two_access_endpoints(self) -> None:
|
|
3028
|
-
cfg = base_config()
|
|
3029
|
-
with self.assertRaisesRegex(APError, "Multiple access.jenkins endpoints"):
|
|
3030
|
-
ap._resolve_jenkins_component(cfg)
|
|
3031
|
-
|
|
3032
|
-
cfg["access"]["jenkins"]["backend"] = dict(cfg["access"]["jenkins"]["frontend"])
|
|
3033
|
-
self.assertEqual("frontend", ap._resolve_jenkins_component(cfg))
|
|
3034
|
-
|
|
3035
|
-
def test_verify_jenkins_build_uses_one_selected_access_component(self) -> None:
|
|
3036
|
-
repo, _ = self.make_repo()
|
|
3037
|
-
args = argparse.Namespace(
|
|
3038
|
-
repo=str(repo),
|
|
3039
|
-
component="backend",
|
|
3040
|
-
git_ref="HEAD",
|
|
3041
|
-
job_name=None,
|
|
3042
|
-
job_url=None,
|
|
3043
|
-
multibranch_root_job=None,
|
|
3044
|
-
branch_name=None,
|
|
3045
|
-
build_number=7,
|
|
3046
|
-
max_builds=20,
|
|
3047
|
-
timeout_sec=1,
|
|
3048
|
-
poll_sec=1,
|
|
3049
|
-
allow_no_deploy=True,
|
|
3050
|
-
)
|
|
3051
|
-
payload = {
|
|
3052
|
-
"number": 7,
|
|
3053
|
-
"result": "SUCCESS",
|
|
3054
|
-
"building": False,
|
|
3055
|
-
"description": "deployed",
|
|
3056
|
-
"url": "https://jenkins-back.test/7/",
|
|
3057
|
-
}
|
|
3058
|
-
with (
|
|
3059
|
-
mock.patch.object(ap, "_jenkins_api_get_json", return_value=payload) as api_get,
|
|
3060
|
-
mock.patch.object(ap, "_record_evidence"),
|
|
3061
|
-
):
|
|
3062
|
-
ap.cmd_verify_jenkins_build(args)
|
|
3063
|
-
|
|
3064
|
-
self.assertEqual("backend", api_get.call_args.kwargs["component"])
|
|
3065
|
-
self.assertIn("https://jenkins-back.test/7/api/json", api_get.call_args.args[0])
|
|
3066
|
-
|
|
3067
|
-
def test_verify_jenkins_preserves_legacy_configuration(self) -> None:
|
|
3068
|
-
cfg = base_config()
|
|
3069
|
-
cfg["access"]["jenkins"] = {}
|
|
3070
|
-
cfg["jenkins"] = {
|
|
3071
|
-
"base_url": "https://legacy-jenkins.test",
|
|
3072
|
-
"job_url": "https://legacy-jenkins.test/job/backend",
|
|
3073
|
-
"trigger_branch": "dev",
|
|
3074
|
-
"image_repository": "registry.test/project/backend",
|
|
3075
|
-
"image_tag_strategy": "commit",
|
|
3076
|
-
"deploy_env": "production",
|
|
3077
|
-
"api_user": "legacy-user",
|
|
3078
|
-
"api_password": "legacy-pass",
|
|
3079
|
-
}
|
|
3080
|
-
cfg["target_env"] = {
|
|
3081
|
-
"health_base_url": "https://legacy-target.test",
|
|
3082
|
-
"health_path": "/healthz",
|
|
3083
|
-
}
|
|
3084
|
-
repo, _ = self.make_repo(config=cfg)
|
|
3085
|
-
(repo / "Jenkinsfile").write_text("pipeline {}\n", encoding="utf-8")
|
|
3086
|
-
|
|
3087
|
-
with mock.patch.object(ap, "_record_evidence"):
|
|
3088
|
-
ap.cmd_verify_jenkins(argparse.Namespace(repo=str(repo), component="all"))
|
|
3089
|
-
|
|
3090
|
-
self.assertEqual("", ap._resolve_jenkins_component(cfg))
|
|
3091
|
-
header = ap._jenkins_basic_auth_headers(cfg)["Authorization"]
|
|
3092
|
-
decoded = base64.b64decode(header.removeprefix("Basic ")).decode("utf-8")
|
|
3093
|
-
self.assertEqual("legacy-user:legacy-pass", decoded)
|
|
3094
|
-
|
|
3095
|
-
def test_jenkins_crumb_cache_is_scoped_by_identity(self) -> None:
|
|
3096
|
-
cfg = base_config()
|
|
3097
|
-
cfg["access"]["jenkins"]["frontend"].update(
|
|
3098
|
-
{"url": "https://jenkins.test/job/frontend", "username": "front-user"}
|
|
3099
|
-
)
|
|
3100
|
-
cfg["access"]["jenkins"]["backend"].update(
|
|
3101
|
-
{"url": "https://jenkins.test/job/backend", "username": "back-user"}
|
|
3102
|
-
)
|
|
3103
|
-
|
|
3104
|
-
def response(crumb: str) -> mock.MagicMock:
|
|
3105
|
-
value = mock.MagicMock()
|
|
3106
|
-
value.__enter__.return_value.read.return_value = json.dumps(
|
|
3107
|
-
{"crumbRequestField": "Jenkins-Crumb", "crumb": crumb}
|
|
3108
|
-
).encode("utf-8")
|
|
3109
|
-
return value
|
|
3110
|
-
|
|
3111
|
-
ap._JENKINS_CRUMB_CACHE.clear()
|
|
3112
|
-
self.addCleanup(ap._JENKINS_CRUMB_CACHE.clear)
|
|
3113
|
-
with mock.patch.object(
|
|
3114
|
-
ap.urllib.request,
|
|
3115
|
-
"urlopen",
|
|
3116
|
-
side_effect=[response("crumb-front"), response("crumb-back")],
|
|
3117
|
-
) as urlopen:
|
|
3118
|
-
frontend = ap._jenkins_crumb_headers(cfg, component="frontend")
|
|
3119
|
-
backend = ap._jenkins_crumb_headers(cfg, component="backend")
|
|
3120
|
-
|
|
3121
|
-
self.assertEqual({"Jenkins-Crumb": "crumb-front"}, frontend)
|
|
3122
|
-
self.assertEqual({"Jenkins-Crumb": "crumb-back"}, backend)
|
|
3123
|
-
self.assertEqual(2, urlopen.call_count)
|
|
3124
|
-
self.assertEqual(2, len(ap._JENKINS_CRUMB_CACHE))
|
|
3125
|
-
|
|
3126
|
-
def test_verify_target_uses_access_project_urls_without_legacy_wait(self) -> None:
|
|
3127
|
-
repo, _ = self.make_repo()
|
|
3128
|
-
args = argparse.Namespace(
|
|
3129
|
-
repo=str(repo),
|
|
3130
|
-
backend_path=["/healthz"],
|
|
3131
|
-
frontend_path=["/"],
|
|
3132
|
-
backend_basic_auth=False,
|
|
3133
|
-
frontend_basic_auth=False,
|
|
3134
|
-
)
|
|
3135
|
-
with (
|
|
3136
|
-
mock.patch.object(ap, "_http_get", return_value=(200, "ok")) as http_get,
|
|
3137
|
-
mock.patch.object(ap, "_wait_for_health_url") as wait_health,
|
|
3138
|
-
mock.patch.object(ap, "_record_evidence"),
|
|
3139
|
-
):
|
|
3140
|
-
ap.cmd_verify_target(args)
|
|
3141
|
-
|
|
3142
|
-
self.assertEqual(
|
|
3143
|
-
["https://project-back.test/healthz", "https://project-front.test/"],
|
|
3144
|
-
[call.args[0] for call in http_get.call_args_list],
|
|
3145
|
-
)
|
|
3146
|
-
wait_health.assert_not_called()
|
|
3147
|
-
|
|
3148
|
-
def test_verify_target_missing_access_url_fails_before_network(self) -> None:
|
|
3149
|
-
cfg = base_config()
|
|
3150
|
-
cfg["access"]["project"]["backend"]["url"] = ""
|
|
3151
|
-
repo, _ = self.make_repo(config=cfg)
|
|
3152
|
-
args = argparse.Namespace(
|
|
3153
|
-
repo=str(repo),
|
|
3154
|
-
backend_path=["/healthz"],
|
|
3155
|
-
frontend_path=None,
|
|
3156
|
-
backend_basic_auth=False,
|
|
3157
|
-
frontend_basic_auth=False,
|
|
3158
|
-
)
|
|
3159
|
-
with (
|
|
3160
|
-
mock.patch.object(ap, "_http_get") as http_get,
|
|
3161
|
-
mock.patch.object(ap, "http_get_status") as get_status,
|
|
3162
|
-
mock.patch.object(ap.time, "sleep") as sleep,
|
|
3163
|
-
):
|
|
3164
|
-
with self.assertRaisesRegex(APError, "access.project.backend.url"):
|
|
3165
|
-
ap.cmd_verify_target(args)
|
|
3166
|
-
|
|
3167
|
-
http_get.assert_not_called()
|
|
3168
|
-
get_status.assert_not_called()
|
|
3169
|
-
sleep.assert_not_called()
|
|
3170
|
-
|
|
3171
|
-
def test_verify_target_preserves_legacy_endpoint_and_health_preflight(self) -> None:
|
|
3172
|
-
cfg = base_config()
|
|
3173
|
-
cfg["access"]["project"] = {}
|
|
3174
|
-
cfg["jenkins"] = {"deploy_timeout_sec": 7}
|
|
3175
|
-
cfg["target_env"] = {
|
|
3176
|
-
"backend_base_url": "https://legacy-target.test/api",
|
|
3177
|
-
"backend_username": "legacy-user",
|
|
3178
|
-
"backend_password": "legacy-pass",
|
|
3179
|
-
"health_base_url": "https://legacy-target.test",
|
|
3180
|
-
"health_path": "/healthz",
|
|
3181
|
-
}
|
|
3182
|
-
repo, _ = self.make_repo(config=cfg)
|
|
3183
|
-
args = argparse.Namespace(
|
|
3184
|
-
repo=str(repo),
|
|
3185
|
-
backend_path=["/ready"],
|
|
3186
|
-
frontend_path=None,
|
|
3187
|
-
backend_basic_auth=False,
|
|
3188
|
-
frontend_basic_auth=False,
|
|
3189
|
-
)
|
|
3190
|
-
with (
|
|
3191
|
-
mock.patch.object(ap, "_wait_for_health_url") as wait_health,
|
|
3192
|
-
mock.patch.object(ap, "_http_get", return_value=(200, "ok")) as http_get,
|
|
3193
|
-
mock.patch.object(ap, "_record_evidence"),
|
|
3194
|
-
):
|
|
3195
|
-
ap.cmd_verify_target(args)
|
|
3196
|
-
|
|
3197
|
-
wait_health.assert_called_once_with(
|
|
3198
|
-
"target", "https://legacy-target.test/healthz", 7
|
|
3199
|
-
)
|
|
3200
|
-
self.assertEqual("https://legacy-target.test/api/ready", http_get.call_args.args[0])
|
|
3201
|
-
|
|
3202
|
-
def test_dev_closure_rejects_owner_acceptance_pass(self) -> None:
|
|
3203
|
-
with self.assertRaises(APError):
|
|
3204
|
-
ap._validate_closure_result("dev", "PASS")
|
|
3205
|
-
|
|
3206
|
-
def test_manual_closure_infers_one_of_the_three_effective_profiles(self) -> None:
|
|
3207
|
-
repo, _ = self.make_repo("src/widget.py")
|
|
3208
|
-
closure_path = self.record_closure(repo, self.closure_args(repo, result="DEV-CLOSED"))
|
|
3209
|
-
closure = closure_path.read_text(encoding="utf-8")
|
|
3210
|
-
self.assertIn("- Effective Profile: standard", closure)
|
|
3211
|
-
self.assertNotIn("(not recorded)", closure)
|
|
3212
|
-
|
|
3213
|
-
def test_manual_closure_uses_dev_closed_for_high_risk_work(self) -> None:
|
|
3214
|
-
repo, _ = self.make_repo("migrations/001.sql")
|
|
3215
|
-
closure_path = self.record_closure(repo, self.closure_args(repo, result="DEV-CLOSED"))
|
|
3216
|
-
closure = closure_path.read_text(encoding="utf-8")
|
|
3217
|
-
self.assertIn("- Effective Profile: high-risk", closure)
|
|
3218
|
-
|
|
3219
|
-
def test_manual_pass_is_outside_automatic_coding_closure(self) -> None:
|
|
3220
|
-
repo, _ = self.make_repo("src/widget.py")
|
|
3221
|
-
with self.assertRaises(APError) as context:
|
|
3222
|
-
self.record_closure(
|
|
3223
|
-
repo,
|
|
3224
|
-
self.closure_args(repo, result="PASS", profile="high-risk", verification=[])
|
|
3225
|
-
)
|
|
3226
|
-
self.assertIn("owner acceptance", str(context.exception))
|
|
3227
|
-
|
|
3228
|
-
def test_manual_closure_uses_commit_diff_after_high_risk_change_is_committed(self) -> None:
|
|
3229
|
-
repo, _ = self.make_repo("migrations/001.sql")
|
|
3230
|
-
run(repo, "git", "add", "-A")
|
|
3231
|
-
run(repo, "git", "commit", "-qm", "database migration")
|
|
3232
|
-
|
|
3233
|
-
closure_path = self.record_closure(
|
|
3234
|
-
repo,
|
|
3235
|
-
self.closure_args(
|
|
3236
|
-
repo,
|
|
3237
|
-
result="DEV-CLOSED",
|
|
3238
|
-
verification=["fast changed gate passed"],
|
|
3239
|
-
)
|
|
3240
|
-
)
|
|
3241
|
-
closure = closure_path.read_text(encoding="utf-8")
|
|
3242
|
-
self.assertIn("- Effective Profile: high-risk", closure)
|
|
3243
|
-
|
|
3244
|
-
def test_feedback_lifecycle_tracks_upgrade_verification_regression_and_closure(self) -> None:
|
|
3245
|
-
signature = "sha256:" + "a" * 64
|
|
3246
|
-
catalog = {
|
|
3247
|
-
signature: {
|
|
3248
|
-
"signature": signature,
|
|
3249
|
-
"disposition": "fixed",
|
|
3250
|
-
"effective_skill_version": "4.3.1",
|
|
3251
|
-
}
|
|
3252
|
-
}
|
|
3253
|
-
report = {
|
|
3254
|
-
"status": "open",
|
|
3255
|
-
"signature": signature,
|
|
3256
|
-
"last_verified_skill_version": "4.3.0",
|
|
3257
|
-
}
|
|
3258
|
-
self.assertEqual("upgrade-due", ap._feedback_lifecycle(report, "4.3.0", catalog)[0])
|
|
3259
|
-
self.assertEqual("verification-due", ap._feedback_lifecycle(report, "4.3.1", catalog)[0])
|
|
3260
|
-
report["last_verified_skill_version"] = "4.3.1"
|
|
3261
|
-
self.assertEqual("regression-current", ap._feedback_lifecycle(report, "4.3.1", catalog)[0])
|
|
3262
|
-
self.assertEqual("recheck-due", ap._feedback_lifecycle(report, "4.3.2", catalog)[0])
|
|
3263
|
-
report["last_verified_skill_version"] = "4.3.2"
|
|
3264
|
-
self.assertEqual("recheck-due", ap._feedback_lifecycle(report, "4.3.1", catalog)[0])
|
|
3265
|
-
report["last_verified_skill_version"] = "4.3.1"
|
|
3266
|
-
self.assertEqual("recheck-due", ap._feedback_lifecycle(report, "4.3.2", {})[0])
|
|
3267
|
-
report["status"] = "resolved"
|
|
3268
|
-
self.assertEqual("closed", ap._feedback_lifecycle(report, "4.3.2", catalog)[0])
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
if __name__ == "__main__":
|
|
3272
|
-
unittest.main()
|