@elvis1513/auto-coding-skill 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -54
- package/cli/assets/agents/browser-debugger.toml +5 -7
- package/cli/assets/agents/docs-researcher.toml +3 -5
- package/cli/assets/agents/explorer.toml +5 -10
- package/cli/assets/agents/fixer.toml +19 -17
- package/cli/assets/agents/reviewer.toml +14 -10
- package/cli/assets/skill/SKILL.md +116 -49
- package/cli/assets/skill/data/contracts/orchestration-v1.schema.json +475 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +371 -0
- package/cli/assets/skill/data/templates/ENGINEERING.md +170 -81
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +8 -4
- package/cli/assets/skill/data/templates/docs/tasks/closure-log.md +7 -6
- package/cli/assets/skill/data/templates/docs/tasks/taskbook.md +11 -4
- package/cli/assets/skill/scripts/ap.py +1389 -570
- package/cli/src/index.js +749 -51
- package/cli/tests/ap_concurrency_test.py +466 -79
- package/cli/tests/ap_profiles_test.py +339 -98
- package/cli/tests/index.test.js +499 -15
- package/package.json +3 -3
|
@@ -13,7 +13,7 @@ import yaml
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
16
|
-
SCRIPT_DIR = REPO_ROOT / "
|
|
16
|
+
SCRIPT_DIR = REPO_ROOT / "src" / "auto-coding-skill" / "scripts"
|
|
17
17
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
18
18
|
|
|
19
19
|
import ap # noqa: E402
|
|
@@ -26,9 +26,23 @@ def run(repo: Path, *args: str) -> None:
|
|
|
26
26
|
|
|
27
27
|
def base_config() -> dict:
|
|
28
28
|
return {
|
|
29
|
-
"workflow": {"mode": "dev", "profile": "auto"},
|
|
30
|
-
"concurrency": {"isolation": "
|
|
29
|
+
"workflow": {"mode": "dev", "profile": "auto", "completion": "push"},
|
|
30
|
+
"concurrency": {"isolation": "worktree"},
|
|
31
31
|
"project": {"name": "profile-test"},
|
|
32
|
+
"access": {
|
|
33
|
+
"project": {
|
|
34
|
+
"frontend": {"url": "https://project-front.test", "username": "front", "password": "front-pass"},
|
|
35
|
+
"backend": {"url": "https://project-back.test", "username": "back", "password": "back-pass"},
|
|
36
|
+
},
|
|
37
|
+
"jenkins": {
|
|
38
|
+
"frontend": {"url": "https://jenkins-front.test", "username": "front", "password": "front-pass"},
|
|
39
|
+
"backend": {"url": "https://jenkins-back.test", "username": "back", "password": "back-pass"},
|
|
40
|
+
},
|
|
41
|
+
"gitlab": {"url": "https://gitlab.test", "username": "git", "password": "git-pass"},
|
|
42
|
+
"nexus": {
|
|
43
|
+
"frontend": {"url": "https://nexus.test", "username": "nexus", "password": "nexus-pass"},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
32
46
|
"commands": {
|
|
33
47
|
"gate_changed": "true",
|
|
34
48
|
"gate_standard": "true",
|
|
@@ -54,6 +68,30 @@ def base_config() -> dict:
|
|
|
54
68
|
|
|
55
69
|
|
|
56
70
|
class AutoCodingProfileTests(unittest.TestCase):
|
|
71
|
+
@staticmethod
|
|
72
|
+
def workflow_policy(*, fragments: list[dict] | None = None) -> dict:
|
|
73
|
+
return {
|
|
74
|
+
"schema_version": 1,
|
|
75
|
+
"managed_versions": {"agents": "3.0.2", "engineering": "3.0.2"},
|
|
76
|
+
"known_official_engineering_body_sha256": [],
|
|
77
|
+
"known_official_fragments": fragments or [],
|
|
78
|
+
"conflict_rules": [
|
|
79
|
+
{
|
|
80
|
+
"id": "mandatory-full",
|
|
81
|
+
"paths": ["AGENTS.md", "docs/ENGINEERING.md"],
|
|
82
|
+
"pattern": r"^.*must run the full gate.*$",
|
|
83
|
+
"flags": "im",
|
|
84
|
+
"message": "full gate is not automatic",
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"dependency_recovery": {
|
|
88
|
+
"allowed_gate": "gate_changed",
|
|
89
|
+
"requires_locked_dependency": True,
|
|
90
|
+
"retry_same_gate_only": True,
|
|
91
|
+
"forbid_full_gate_recovery": True,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
57
95
|
def make_repo(self, change_path: str | None = None, config: dict | None = None) -> tuple[Path, dict]:
|
|
58
96
|
temp = tempfile.TemporaryDirectory(prefix="autocoding-profile-")
|
|
59
97
|
self.addCleanup(temp.cleanup)
|
|
@@ -155,6 +193,12 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
155
193
|
fix_commit=None,
|
|
156
194
|
)
|
|
157
195
|
|
|
196
|
+
@staticmethod
|
|
197
|
+
def record_closure(repo: Path, args: argparse.Namespace) -> Path:
|
|
198
|
+
with mock.patch.object(ap, "_require_task_context", return_value={"task_id": args.task_id}):
|
|
199
|
+
ap.cmd_record_closure(args)
|
|
200
|
+
return repo / "docs" / "tasks" / "closures" / f"{args.task_id}.md"
|
|
201
|
+
|
|
158
202
|
def test_docs_only_resolves_micro(self) -> None:
|
|
159
203
|
repo, cfg = self.make_repo("docs/security-auth-notes.md")
|
|
160
204
|
plan = self.plan(repo, cfg)
|
|
@@ -162,15 +206,69 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
162
206
|
self.assertEqual("changed", plan["selected_scope"])
|
|
163
207
|
self.assertEqual("dev", plan["effective_mode"])
|
|
164
208
|
self.assertEqual([], plan["recommended_agents"])
|
|
209
|
+
self.assertEqual("main-only", plan["agent_plan"]["strategy"])
|
|
210
|
+
self.assertEqual(1, plan["contract_version"])
|
|
211
|
+
self.assertEqual("data/contracts/orchestration-v1.schema.json", plan["contract_schema"])
|
|
212
|
+
for field in [
|
|
213
|
+
"contract_version",
|
|
214
|
+
"contract_schema",
|
|
215
|
+
"policies",
|
|
216
|
+
"assignment_contract",
|
|
217
|
+
"result_contract",
|
|
218
|
+
"stages",
|
|
219
|
+
"constraints",
|
|
220
|
+
]:
|
|
221
|
+
self.assertIn(field, plan["agent_plan"])
|
|
222
|
+
|
|
223
|
+
def test_planned_files_and_intent_drive_classification_without_polluting_changed_files(self) -> None:
|
|
224
|
+
repo, cfg = self.make_repo()
|
|
225
|
+
plan = self.plan(
|
|
226
|
+
repo,
|
|
227
|
+
cfg,
|
|
228
|
+
planned_paths=["src/frontend/LoginPage.tsx"],
|
|
229
|
+
intent="新增登录鉴权页面并发布",
|
|
230
|
+
)
|
|
231
|
+
self.assertEqual([], plan["changed_files"])
|
|
232
|
+
self.assertEqual(["src/frontend/LoginPage.tsx"], plan["planned_files"])
|
|
233
|
+
self.assertEqual(["src/frontend/LoginPage.tsx"], plan["classification_files"])
|
|
234
|
+
self.assertTrue(plan["intent_provided"])
|
|
235
|
+
self.assertEqual(["auth", "release_or_tooling", "ui"], plan["intent_categories"])
|
|
236
|
+
self.assertIn("browser_debugger", plan["recommended_agents"])
|
|
237
|
+
self.assertNotIn("新增登录鉴权页面并发布", str(plan))
|
|
165
238
|
|
|
166
239
|
def test_ordinary_code_resolves_standard(self) -> None:
|
|
167
240
|
repo, cfg = self.make_repo("src/widget.py")
|
|
168
241
|
(repo / "docs" / "tasks" / "evidence.jsonl").write_text("{}\n", encoding="utf-8")
|
|
169
242
|
plan = self.plan(repo, cfg)
|
|
170
243
|
self.assertEqual("standard", plan["profile"])
|
|
171
|
-
self.assertEqual("
|
|
244
|
+
self.assertEqual("changed", plan["selected_scope"])
|
|
172
245
|
self.assertEqual("dev", plan["effective_mode"])
|
|
173
|
-
self.assertEqual(["explorer", "fixer"], plan["recommended_agents"])
|
|
246
|
+
self.assertEqual(["explorer", "fixer", "reviewer"], plan["recommended_agents"])
|
|
247
|
+
agent_plan = plan["agent_plan"]
|
|
248
|
+
self.assertEqual("orchestrated-subagents", agent_plan["strategy"])
|
|
249
|
+
self.assertEqual(
|
|
250
|
+
["decomposition", "discovery", "design", "delivery", "closure"],
|
|
251
|
+
[stage["id"] for stage in agent_plan["stages"]],
|
|
252
|
+
)
|
|
253
|
+
self.assertTrue(agent_plan["policies"]["one_writer_per_worktree"])
|
|
254
|
+
self.assertEqual("explicit-non-overlapping", agent_plan["policies"]["path_ownership"])
|
|
255
|
+
self.assertEqual(
|
|
256
|
+
"integrate-before-dependent-start",
|
|
257
|
+
agent_plan["policies"]["dependency_policy"],
|
|
258
|
+
)
|
|
259
|
+
self.assertEqual("owning-fixer", agent_plan["policies"]["review_feedback_owner"])
|
|
260
|
+
self.assertEqual("diff-fingerprint", agent_plan["policies"]["review_binding"])
|
|
261
|
+
self.assertEqual("main", agent_plan["policies"]["lifecycle_owner"])
|
|
262
|
+
self.assertIn("owned_paths", agent_plan["assignment_contract"]["writer"])
|
|
263
|
+
self.assertIn("diff_fingerprint", agent_plan["assignment_contract"]["reviewer"])
|
|
264
|
+
self.assertIn("diff_fingerprint", agent_plan["result_contract"])
|
|
265
|
+
delivery = next(stage for stage in agent_plan["stages"] if stage["id"] == "delivery")
|
|
266
|
+
self.assertEqual("dependency-waves", delivery["mode"])
|
|
267
|
+
self.assertEqual(
|
|
268
|
+
["implementation", "review", "gate-integrate"],
|
|
269
|
+
[phase["id"] for phase in delivery["wave_phases"]],
|
|
270
|
+
)
|
|
271
|
+
self.assertIn("integrated", delivery["next_wave"])
|
|
174
272
|
|
|
175
273
|
def test_test_only_change_resolves_micro(self) -> None:
|
|
176
274
|
repo, cfg = self.make_repo("tests/widget_test.py")
|
|
@@ -188,43 +286,59 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
188
286
|
self.assertEqual("changed", plan["selected_scope"])
|
|
189
287
|
self.assertEqual("dev", plan["effective_mode"])
|
|
190
288
|
|
|
191
|
-
def
|
|
289
|
+
def test_high_risk_changes_keep_fast_dev_gate(self) -> None:
|
|
192
290
|
repo, cfg = self.make_repo("migrations/001.sql")
|
|
193
291
|
plan = self.plan(repo, cfg, requested_profile="micro", requested_mode="dev")
|
|
194
292
|
self.assertEqual("high-risk", plan["profile"])
|
|
195
|
-
self.assertEqual("
|
|
196
|
-
self.assertEqual("
|
|
293
|
+
self.assertEqual("changed", plan["selected_scope"])
|
|
294
|
+
self.assertEqual("dev", plan["effective_mode"])
|
|
197
295
|
self.assertTrue(plan["needs_dd"])
|
|
198
296
|
self.assertIn("reviewer", plan["recommended_agents"])
|
|
297
|
+
self.assertFalse(plan["needs_jenkins"])
|
|
298
|
+
self.assertFalse(plan["needs_target"])
|
|
299
|
+
|
|
300
|
+
def test_ui_api_discovery_roles_run_in_one_parallel_stage(self) -> None:
|
|
301
|
+
repo, cfg = self.make_repo("src/api/settings-page.tsx")
|
|
302
|
+
plan = self.plan(repo, cfg)
|
|
303
|
+
discovery = next(stage for stage in plan["agent_plan"]["stages"] if stage["id"] == "discovery")
|
|
304
|
+
self.assertEqual("parallel", discovery["mode"])
|
|
305
|
+
self.assertEqual(
|
|
306
|
+
["explorer", "docs_researcher", "browser_debugger"],
|
|
307
|
+
discovery["roles"],
|
|
308
|
+
)
|
|
309
|
+
flattened = [
|
|
310
|
+
role
|
|
311
|
+
for stage in plan["agent_plan"]["stages"]
|
|
312
|
+
for role in stage["roles"]
|
|
313
|
+
if role != "main"
|
|
314
|
+
]
|
|
315
|
+
self.assertEqual(list(dict.fromkeys(flattened)), plan["recommended_agents"])
|
|
199
316
|
|
|
200
|
-
def
|
|
317
|
+
def test_requested_verify_mode_is_rejected(self) -> None:
|
|
201
318
|
repo, cfg = self.make_repo("src/widget.py")
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
self.assertEqual("full", plan["selected_scope"])
|
|
205
|
-
self.assertEqual("verify", plan["effective_mode"])
|
|
319
|
+
with self.assertRaises(APError):
|
|
320
|
+
self.plan(repo, cfg, requested_mode="verify")
|
|
206
321
|
|
|
207
322
|
def test_configured_high_risk_profile_cannot_be_downgraded_by_cli(self) -> None:
|
|
208
323
|
cfg = base_config()
|
|
209
|
-
cfg["workflow"] = {"mode": "dev", "profile": "high-risk"}
|
|
324
|
+
cfg["workflow"] = {"mode": "dev", "profile": "high-risk", "completion": "push"}
|
|
210
325
|
repo, cfg = self.make_repo("src/widget.py", cfg)
|
|
211
326
|
plan = self.plan(repo, cfg, requested_profile="micro", requested_mode="dev")
|
|
212
327
|
self.assertEqual("high-risk", plan["profile"])
|
|
213
|
-
self.assertEqual("
|
|
214
|
-
self.assertEqual("
|
|
328
|
+
self.assertEqual("changed", plan["selected_scope"])
|
|
329
|
+
self.assertEqual("dev", plan["effective_mode"])
|
|
215
330
|
|
|
216
|
-
def
|
|
331
|
+
def test_doctor_rejects_configured_verify_mode(self) -> None:
|
|
217
332
|
cfg = base_config()
|
|
218
|
-
cfg["workflow"] = {"mode": "verify", "profile": "auto"}
|
|
219
|
-
repo,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
self.
|
|
223
|
-
self.assertEqual("verify", plan["effective_mode"])
|
|
333
|
+
cfg["workflow"] = {"mode": "verify", "profile": "auto", "completion": "push"}
|
|
334
|
+
repo, _ = self.make_repo("src/widget.py", cfg)
|
|
335
|
+
with self.assertRaises(APError) as context:
|
|
336
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
337
|
+
self.assertIn("workflow.mode", str(context.exception))
|
|
224
338
|
|
|
225
339
|
def test_configured_micro_profile_applies_to_ordinary_code(self) -> None:
|
|
226
340
|
cfg = base_config()
|
|
227
|
-
cfg["workflow"] = {"mode": "dev", "profile": "micro"}
|
|
341
|
+
cfg["workflow"] = {"mode": "dev", "profile": "micro", "completion": "push"}
|
|
228
342
|
repo, cfg = self.make_repo("src/widget.py", cfg)
|
|
229
343
|
plan = self.plan(repo, cfg)
|
|
230
344
|
self.assertEqual("micro", plan["profile"])
|
|
@@ -239,23 +353,77 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
239
353
|
self.assertEqual("high-risk", plan["profile"])
|
|
240
354
|
self.assertIn("matched gate rule with profile=high-risk", plan["profile_reasons"])
|
|
241
355
|
|
|
242
|
-
def
|
|
356
|
+
def test_full_scope_rule_does_not_expand_local_gate(self) -> None:
|
|
243
357
|
cfg = base_config()
|
|
244
358
|
cfg["gate"]["rules"] = [{"name": "sensitive", "paths": ["src/sensitive/**"], "scope": "full"}]
|
|
245
359
|
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
246
360
|
plan = self.plan(repo, cfg, requested_scope="changed", requested_profile="micro", requested_mode="dev")
|
|
247
|
-
self.assertEqual("
|
|
248
|
-
self.assertEqual("
|
|
249
|
-
self.assertEqual("
|
|
361
|
+
self.assertEqual("micro", plan["profile"])
|
|
362
|
+
self.assertEqual("changed", plan["selected_scope"])
|
|
363
|
+
self.assertEqual("dev", plan["effective_mode"])
|
|
250
364
|
|
|
251
|
-
def
|
|
365
|
+
def test_legacy_rule_commands_never_run_in_automatic_gate(self) -> None:
|
|
366
|
+
cfg = base_config()
|
|
367
|
+
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
368
|
+
quick_marker = repo / "quick-ran"
|
|
369
|
+
full_marker = repo / "full-ran"
|
|
370
|
+
build_marker = repo / "build-ran"
|
|
371
|
+
cfg["commands"] = {
|
|
372
|
+
"gate_changed": f"touch {quick_marker}",
|
|
373
|
+
"gate_full": f"touch {full_marker}",
|
|
374
|
+
"build": f"touch {build_marker}",
|
|
375
|
+
}
|
|
376
|
+
cfg["gate"]["rules"] = [
|
|
377
|
+
{
|
|
378
|
+
"name": "legacy-heavy-rule",
|
|
379
|
+
"paths": ["src/sensitive/**"],
|
|
380
|
+
"scope": "full",
|
|
381
|
+
"commands": ["gate_full", "build"],
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
self.write_config(repo, cfg)
|
|
385
|
+
|
|
386
|
+
ap.cmd_light_gate(
|
|
387
|
+
argparse.Namespace(
|
|
388
|
+
repo=str(repo),
|
|
389
|
+
scope="changed",
|
|
390
|
+
profile="",
|
|
391
|
+
mode="dev",
|
|
392
|
+
base="",
|
|
393
|
+
explain=False,
|
|
394
|
+
)
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
self.assertTrue(quick_marker.exists())
|
|
398
|
+
self.assertFalse(full_marker.exists())
|
|
399
|
+
self.assertFalse(build_marker.exists())
|
|
400
|
+
|
|
401
|
+
def test_classify_never_recommends_a_second_gate_or_structure_scan(self) -> None:
|
|
402
|
+
repo, _ = self.make_repo("src/widget.py")
|
|
403
|
+
with mock.patch.object(ap, "_record_evidence"):
|
|
404
|
+
with mock.patch("builtins.print") as printed:
|
|
405
|
+
ap.cmd_classify(
|
|
406
|
+
argparse.Namespace(
|
|
407
|
+
repo=str(repo),
|
|
408
|
+
scope="auto",
|
|
409
|
+
profile="",
|
|
410
|
+
mode="dev",
|
|
411
|
+
base="",
|
|
412
|
+
json=False,
|
|
413
|
+
)
|
|
414
|
+
)
|
|
415
|
+
rendered = "\n".join(" ".join(map(str, call.args)) for call in printed.call_args_list)
|
|
416
|
+
self.assertNotIn("light-gate", rendered)
|
|
417
|
+
self.assertNotIn("structure-check", rendered)
|
|
418
|
+
|
|
419
|
+
def test_custom_full_on_path_does_not_expand_local_gate(self) -> None:
|
|
252
420
|
cfg = base_config()
|
|
253
421
|
cfg["gate"]["full_on"] = {"paths": ["src/sensitive/**"]}
|
|
254
422
|
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
255
423
|
plan = self.plan(repo, cfg, requested_scope="changed", requested_profile="micro", requested_mode="dev")
|
|
256
|
-
self.assertEqual("
|
|
257
|
-
self.assertEqual("
|
|
258
|
-
self.assertEqual("
|
|
424
|
+
self.assertEqual("micro", plan["profile"])
|
|
425
|
+
self.assertEqual("changed", plan["selected_scope"])
|
|
426
|
+
self.assertEqual("dev", plan["effective_mode"])
|
|
259
427
|
|
|
260
428
|
def test_full_gate_never_falls_back_to_light(self) -> None:
|
|
261
429
|
repo, _ = self.make_repo()
|
|
@@ -309,32 +477,135 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
309
477
|
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
310
478
|
self.assertIn("gate.rules[0].scope", str(context.exception))
|
|
311
479
|
|
|
312
|
-
def
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
480
|
+
def test_upgrade_migrates_legacy_yaml_and_known_policy_fragments(self) -> None:
|
|
481
|
+
cfg = base_config()
|
|
482
|
+
cfg["gate"]["full_on"] = {"paths": ["src/**"]}
|
|
483
|
+
cfg["gate"]["rules"] = [
|
|
484
|
+
{
|
|
485
|
+
"name": "legacy",
|
|
486
|
+
"paths": ["src/**"],
|
|
487
|
+
"profile": "high-risk",
|
|
488
|
+
"scope": "full",
|
|
489
|
+
"commands": ["gate_full"],
|
|
490
|
+
}
|
|
317
491
|
]
|
|
318
|
-
|
|
492
|
+
repo, _ = self.make_repo(config=cfg)
|
|
493
|
+
engineering = repo / "docs" / "ENGINEERING.md"
|
|
494
|
+
engineering.write_text(
|
|
495
|
+
engineering.read_text(encoding="utf-8") + "High-risk work must run the full gate.\n",
|
|
496
|
+
encoding="utf-8",
|
|
497
|
+
)
|
|
498
|
+
policy = self.workflow_policy(
|
|
499
|
+
fragments=[
|
|
500
|
+
{
|
|
501
|
+
"id": "official-high-risk-full",
|
|
502
|
+
"paths": ["docs/ENGINEERING.md"],
|
|
503
|
+
"match": "exact-line",
|
|
504
|
+
"text": "High-risk work must run the full gate.",
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
)
|
|
508
|
+
args = argparse.Namespace(repo=str(repo), write=True, dry_run=False, json=False)
|
|
509
|
+
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
510
|
+
ap.cmd_upgrade(args)
|
|
511
|
+
|
|
512
|
+
migrated, body = ap._read_frontmatter_markdown(engineering)
|
|
513
|
+
self.assertNotIn("full_on", migrated["gate"])
|
|
514
|
+
self.assertNotIn("scope", migrated["gate"]["rules"][0])
|
|
515
|
+
self.assertNotIn("commands", migrated["gate"]["rules"][0])
|
|
516
|
+
self.assertEqual("true", migrated["commands"]["gate_full"])
|
|
517
|
+
self.assertNotIn("must run the full gate", body)
|
|
518
|
+
|
|
519
|
+
def test_upgrade_unknown_policy_conflict_fails_before_any_write(self) -> None:
|
|
520
|
+
repo, _ = self.make_repo()
|
|
521
|
+
agents = repo / "AGENTS.md"
|
|
522
|
+
agents.write_text("# Rules\nHigh-risk work must run the full gate.\n", encoding="utf-8")
|
|
523
|
+
before = agents.read_text(encoding="utf-8")
|
|
524
|
+
args = argparse.Namespace(repo=str(repo), write=True, dry_run=False, json=False)
|
|
525
|
+
with mock.patch.object(
|
|
526
|
+
ap,
|
|
527
|
+
"_load_workflow_migration_policy",
|
|
528
|
+
return_value=self.workflow_policy(),
|
|
529
|
+
):
|
|
530
|
+
with self.assertRaises(APError) as context:
|
|
531
|
+
ap.cmd_upgrade(args)
|
|
532
|
+
self.assertIn("AGENTS.md:2", str(context.exception))
|
|
533
|
+
self.assertEqual(before, agents.read_text(encoding="utf-8"))
|
|
534
|
+
self.assertFalse((repo / ".agents").exists())
|
|
535
|
+
|
|
536
|
+
def test_doctor_ignores_managed_blocks_but_rejects_unknown_external_rule(self) -> None:
|
|
537
|
+
repo, _ = self.make_repo()
|
|
538
|
+
agents = repo / "AGENTS.md"
|
|
539
|
+
agents.write_text(
|
|
540
|
+
"<!-- auto-coding-skill:managed-agents:start version=3.0.2 -->\n"
|
|
541
|
+
"High-risk work must run the full gate.\n"
|
|
542
|
+
"<!-- auto-coding-skill:managed-agents:end -->\n",
|
|
543
|
+
encoding="utf-8",
|
|
544
|
+
)
|
|
545
|
+
policy = self.workflow_policy()
|
|
546
|
+
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
547
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
548
|
+
agents.write_text(agents.read_text(encoding="utf-8") + "High-risk work must run the full gate.\n", encoding="utf-8")
|
|
549
|
+
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
550
|
+
with self.assertRaises(APError) as context:
|
|
551
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
552
|
+
self.assertIn("AGENTS.md:4", str(context.exception))
|
|
553
|
+
|
|
554
|
+
def test_doctor_rejects_legacy_isolation(self) -> None:
|
|
555
|
+
cfg = base_config()
|
|
556
|
+
cfg["concurrency"]["isolation"] = "legacy"
|
|
557
|
+
repo, _ = self.make_repo(config=cfg)
|
|
558
|
+
with self.assertRaises(APError) as context:
|
|
559
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
560
|
+
self.assertIn("must be worktree", str(context.exception))
|
|
561
|
+
|
|
562
|
+
def test_doctor_requires_one_fast_gate_for_every_profile(self) -> None:
|
|
563
|
+
for profile in ["micro", "standard", "high-risk", "auto"]:
|
|
319
564
|
with self.subTest(profile=profile):
|
|
320
565
|
cfg = base_config()
|
|
321
566
|
cfg["workflow"]["profile"] = profile
|
|
322
|
-
cfg["commands"] =
|
|
323
|
-
|
|
324
|
-
repo, _ = self.make_repo(change_path, config=cfg)
|
|
567
|
+
cfg["commands"] = {"gate_standard": "true", "gate_full": "true"}
|
|
568
|
+
repo, _ = self.make_repo(config=cfg)
|
|
325
569
|
with self.assertRaises(APError) as context:
|
|
326
570
|
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
327
|
-
self.assertIn(
|
|
571
|
+
self.assertIn("fast gate command", str(context.exception))
|
|
328
572
|
|
|
329
|
-
def
|
|
573
|
+
def test_doctor_requires_direct_access_password_even_with_env_reference(self) -> None:
|
|
330
574
|
cfg = base_config()
|
|
331
|
-
cfg["
|
|
332
|
-
cfg["
|
|
333
|
-
"health_base_url": "https://example.test",
|
|
334
|
-
"health_path": "/health",
|
|
335
|
-
}
|
|
575
|
+
cfg["access"]["gitlab"]["password"] = ""
|
|
576
|
+
cfg["access"]["gitlab"]["password_env"] = "GITLAB_PASSWORD"
|
|
336
577
|
repo, _ = self.make_repo(config=cfg)
|
|
337
|
-
|
|
578
|
+
with self.assertRaises(APError) as context:
|
|
579
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
580
|
+
self.assertIn("access.gitlab.password", str(context.exception))
|
|
581
|
+
|
|
582
|
+
def test_doctor_rejects_quoted_nullish_access_placeholders(self) -> None:
|
|
583
|
+
for placeholder in ["NULL", "~"]:
|
|
584
|
+
with self.subTest(placeholder=placeholder):
|
|
585
|
+
cfg = base_config()
|
|
586
|
+
cfg["access"]["gitlab"]["password"] = placeholder
|
|
587
|
+
repo, _ = self.make_repo(config=cfg)
|
|
588
|
+
with self.assertRaises(APError) as context:
|
|
589
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
590
|
+
self.assertIn("access.gitlab.password", str(context.exception))
|
|
591
|
+
|
|
592
|
+
def test_doctor_rejects_non_string_access_values(self) -> None:
|
|
593
|
+
for value in [False, 0]:
|
|
594
|
+
with self.subTest(value=value):
|
|
595
|
+
cfg = base_config()
|
|
596
|
+
cfg["access"]["gitlab"]["password"] = value
|
|
597
|
+
repo, _ = self.make_repo(config=cfg)
|
|
598
|
+
with self.assertRaises(APError) as context:
|
|
599
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
600
|
+
self.assertIn("access.gitlab.password", str(context.exception))
|
|
601
|
+
|
|
602
|
+
def test_doctor_validates_access_url_shape_without_network(self) -> None:
|
|
603
|
+
cfg = base_config()
|
|
604
|
+
cfg["access"]["nexus"]["frontend"]["url"] = "nexus.local"
|
|
605
|
+
repo, _ = self.make_repo(config=cfg)
|
|
606
|
+
with self.assertRaises(APError) as context:
|
|
607
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
608
|
+
self.assertIn("valid http/https URL", str(context.exception))
|
|
338
609
|
|
|
339
610
|
def test_api_docs_required_false_is_an_authoritative_opt_out(self) -> None:
|
|
340
611
|
cfg = base_config()
|
|
@@ -352,76 +623,46 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
352
623
|
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
353
624
|
ap.cmd_verify_api_docs(argparse.Namespace(repo=str(repo)))
|
|
354
625
|
|
|
355
|
-
def
|
|
356
|
-
|
|
357
|
-
("
|
|
358
|
-
("high-risk", "verify", "DEV-CLOSED"),
|
|
359
|
-
]
|
|
360
|
-
for profile, mode, result in cases:
|
|
361
|
-
with self.subTest(profile=profile, mode=mode, result=result):
|
|
362
|
-
repo, cfg = self.make_repo("src/widget.py")
|
|
363
|
-
plan = {
|
|
364
|
-
"profile": profile,
|
|
365
|
-
"effective_mode": mode,
|
|
366
|
-
"selected_scope": "full" if mode == "verify" else "changed",
|
|
367
|
-
}
|
|
368
|
-
fake_run_result = subprocess.CompletedProcess([], 0, stdout="changed\n", stderr="")
|
|
369
|
-
with (
|
|
370
|
-
mock.patch.object(ap, "ensure_git_repo"),
|
|
371
|
-
mock.patch.object(ap, "cmd_doctor"),
|
|
372
|
-
mock.patch.object(ap, "_load_cfg", return_value=cfg),
|
|
373
|
-
mock.patch.object(ap, "_resolve_execution_plan", return_value=plan),
|
|
374
|
-
mock.patch.object(ap, "cmd_light_gate"),
|
|
375
|
-
mock.patch.object(ap, "_cleanup_generated_noise"),
|
|
376
|
-
mock.patch.object(ap, "run", return_value=fake_run_result),
|
|
377
|
-
):
|
|
378
|
-
with self.assertRaises(APError):
|
|
379
|
-
ap.cmd_commit_push(
|
|
380
|
-
self.commit_args(repo, profile=profile, mode=mode, result=result)
|
|
381
|
-
)
|
|
626
|
+
def test_dev_closure_rejects_owner_acceptance_pass(self) -> None:
|
|
627
|
+
with self.assertRaises(APError):
|
|
628
|
+
ap._validate_closure_result("dev", "PASS")
|
|
382
629
|
|
|
383
630
|
def test_manual_closure_infers_one_of_the_three_effective_profiles(self) -> None:
|
|
384
631
|
repo, _ = self.make_repo("src/widget.py")
|
|
385
|
-
|
|
386
|
-
closure =
|
|
632
|
+
closure_path = self.record_closure(repo, self.closure_args(repo, result="DEV-CLOSED"))
|
|
633
|
+
closure = closure_path.read_text(encoding="utf-8")
|
|
387
634
|
self.assertIn("- Effective Profile: standard", closure)
|
|
388
635
|
self.assertNotIn("(not recorded)", closure)
|
|
389
636
|
|
|
390
|
-
def
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
for path, result in cases:
|
|
396
|
-
with self.subTest(path=path, result=result):
|
|
397
|
-
repo, _ = self.make_repo(path)
|
|
398
|
-
with self.assertRaises(APError):
|
|
399
|
-
ap.cmd_record_closure(self.closure_args(repo, result=result))
|
|
637
|
+
def test_manual_closure_uses_dev_closed_for_high_risk_work(self) -> None:
|
|
638
|
+
repo, _ = self.make_repo("migrations/001.sql")
|
|
639
|
+
closure_path = self.record_closure(repo, self.closure_args(repo, result="DEV-CLOSED"))
|
|
640
|
+
closure = closure_path.read_text(encoding="utf-8")
|
|
641
|
+
self.assertIn("- Effective Profile: high-risk", closure)
|
|
400
642
|
|
|
401
|
-
def
|
|
643
|
+
def test_manual_pass_is_outside_automatic_coding_closure(self) -> None:
|
|
402
644
|
repo, _ = self.make_repo("src/widget.py")
|
|
403
645
|
with self.assertRaises(APError) as context:
|
|
404
|
-
|
|
646
|
+
self.record_closure(
|
|
647
|
+
repo,
|
|
405
648
|
self.closure_args(repo, result="PASS", profile="high-risk", verification=[])
|
|
406
649
|
)
|
|
407
|
-
self.assertIn("
|
|
650
|
+
self.assertIn("owner acceptance", str(context.exception))
|
|
408
651
|
|
|
409
652
|
def test_manual_closure_uses_commit_diff_after_high_risk_change_is_committed(self) -> None:
|
|
410
653
|
repo, _ = self.make_repo("migrations/001.sql")
|
|
411
654
|
run(repo, "git", "add", "-A")
|
|
412
655
|
run(repo, "git", "commit", "-qm", "database migration")
|
|
413
656
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
ap.cmd_record_closure(
|
|
657
|
+
closure_path = self.record_closure(
|
|
658
|
+
repo,
|
|
418
659
|
self.closure_args(
|
|
419
660
|
repo,
|
|
420
|
-
result="
|
|
421
|
-
verification=["
|
|
661
|
+
result="DEV-CLOSED",
|
|
662
|
+
verification=["fast changed gate passed"],
|
|
422
663
|
)
|
|
423
664
|
)
|
|
424
|
-
closure =
|
|
665
|
+
closure = closure_path.read_text(encoding="utf-8")
|
|
425
666
|
self.assertIn("- Effective Profile: high-risk", closure)
|
|
426
667
|
|
|
427
668
|
|