@elvis1513/auto-coding-skill 3.0.1 → 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 +16 -1
- package/cli/assets/skill/SKILL.md +5 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +371 -0
- package/cli/assets/skill/data/templates/ENGINEERING.md +8 -1
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +4 -0
- package/cli/assets/skill/scripts/ap.py +390 -8
- package/cli/src/index.js +387 -37
- package/cli/tests/ap_concurrency_test.py +70 -4
- package/cli/tests/ap_profiles_test.py +98 -0
- package/cli/tests/index.test.js +98 -8
- package/package.json +1 -1
|
@@ -68,6 +68,30 @@ def base_config() -> dict:
|
|
|
68
68
|
|
|
69
69
|
|
|
70
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
|
+
|
|
71
95
|
def make_repo(self, change_path: str | None = None, config: dict | None = None) -> tuple[Path, dict]:
|
|
72
96
|
temp = tempfile.TemporaryDirectory(prefix="autocoding-profile-")
|
|
73
97
|
self.addCleanup(temp.cleanup)
|
|
@@ -453,6 +477,80 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
453
477
|
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
454
478
|
self.assertIn("gate.rules[0].scope", str(context.exception))
|
|
455
479
|
|
|
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
|
+
}
|
|
491
|
+
]
|
|
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
|
+
|
|
456
554
|
def test_doctor_rejects_legacy_isolation(self) -> None:
|
|
457
555
|
cfg = base_config()
|
|
458
556
|
cfg["concurrency"]["isolation"] = "legacy"
|
package/cli/tests/index.test.js
CHANGED
|
@@ -206,8 +206,8 @@ function testMinimalSyncConvergesWithinBudget() {
|
|
|
206
206
|
|
|
207
207
|
const files = listProjectFiles(repo);
|
|
208
208
|
const lines = files.reduce((total, file) => total + fs.readFileSync(file, "utf8").split(/\r?\n/).length, 0);
|
|
209
|
-
assert(files.length <=
|
|
210
|
-
assert(lines <=
|
|
209
|
+
assert(files.length <= 23, `minimal scaffold file budget exceeded: ${files.length}`);
|
|
210
|
+
assert(lines <= 10000, `minimal scaffold line budget exceeded: ${lines}`);
|
|
211
211
|
const engineering = fs.readFileSync(path.join(repo, "docs", "ENGINEERING.md"), "utf8");
|
|
212
212
|
assert(engineering.includes("profile: \"auto\""), "engineering should enable adaptive profiles");
|
|
213
213
|
assert(engineering.includes("isolation: \"worktree\""), "engineering should require task worktree isolation");
|
|
@@ -271,6 +271,24 @@ function testStatusRejectsLegacyIsolation() {
|
|
|
271
271
|
assert(parsed.next.includes("upgrade --write"), "status should direct legacy projects through upgrade");
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
function testStatusRejectsLegacyGateEscalation() {
|
|
275
|
+
const repo = tmpdir("legacy-gate-status");
|
|
276
|
+
run("node", [cli, "init"], { cwd: repo });
|
|
277
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
278
|
+
const engineeringPath = path.join(repo, "docs", "ENGINEERING.md");
|
|
279
|
+
const engineering = fs.readFileSync(engineeringPath, "utf8").replace(
|
|
280
|
+
' full_on_unknown: false\n no_change_scope: "changed"\n profile_log:',
|
|
281
|
+
' full_on_unknown: true\n full_on: ["prod_config"]\n no_change_scope: "changed"\n rules:\n - match: ["Jenkinsfile"]\n scope: "full"\n commands: ["gate_full"]\n profile_log:',
|
|
282
|
+
);
|
|
283
|
+
fs.writeFileSync(engineeringPath, engineering);
|
|
284
|
+
const status = run("node", [cli, "status", "--projects", repo, "--json"], { check: false });
|
|
285
|
+
assert(status.status === 2, "legacy automatic gate escalation must make status non-zero");
|
|
286
|
+
const invalid = JSON.parse(status.stdout).results[0].invalidConfigTokens;
|
|
287
|
+
for (const expected of ["gate.full_on", "gate.full_on_unknown", "gate.rules[].scope", "gate.rules[].commands"]) {
|
|
288
|
+
assert(invalid.some(item => item.includes(expected)), `status should report ${expected}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
274
292
|
function testOrdinaryNodeTestIsNotPromotedToAutomaticGate() {
|
|
275
293
|
const repo = tmpdir("node-gate-inference");
|
|
276
294
|
writeFile(path.join(repo, "package.json"), JSON.stringify({ scripts: { test: "node --test" } }, null, 2) + "\n");
|
|
@@ -701,7 +719,7 @@ function testManagedEngineeringSyncIsControlledAndIdempotent() {
|
|
|
701
719
|
|
|
702
720
|
const engineering = path.join(repo, "docs", "ENGINEERING.md");
|
|
703
721
|
const initial = fs.readFileSync(engineering, "utf8");
|
|
704
|
-
const startPattern = /<!-- auto-coding-skill:managed-workflow:start version=3\.0\.
|
|
722
|
+
const startPattern = /<!-- auto-coding-skill:managed-workflow:start version=3\.0\.2 -->/;
|
|
705
723
|
const endMarker = "<!-- auto-coding-skill:managed-workflow:end -->";
|
|
706
724
|
assert(startPattern.test(initial), "new projects should include a versioned managed workflow marker");
|
|
707
725
|
assert(initial.includes(endMarker), "new projects should include the managed workflow end marker");
|
|
@@ -720,7 +738,7 @@ function testManagedEngineeringSyncIsControlledAndIdempotent() {
|
|
|
720
738
|
const dryRun = run("node", [cli, "sync", "--projects", repo, "--dry-run", "--json"]);
|
|
721
739
|
const dryResult = JSON.parse(dryRun.stdout).results[0];
|
|
722
740
|
assert(dryResult.managedWorkflow.state === "stale", `dry-run should expose stale workflow state: ${dryRun.stdout}`);
|
|
723
|
-
assert(dryResult.managedWorkflow.version === "3.0.
|
|
741
|
+
assert(dryResult.managedWorkflow.version === "3.0.2", "dry-run should expose the target workflow version");
|
|
724
742
|
assert(dryResult.actions.some(item => item.action === "would-update" && item.path === "docs/ENGINEERING.md"), "dry-run should plan the managed body update");
|
|
725
743
|
assert(fs.readFileSync(engineering, "utf8") === customized, "dry-run must not write ENGINEERING.md");
|
|
726
744
|
|
|
@@ -730,14 +748,14 @@ function testManagedEngineeringSyncIsControlledAndIdempotent() {
|
|
|
730
748
|
const updatedEnd = updated.indexOf(endMarker) + endMarker.length;
|
|
731
749
|
assert(updated.slice(0, updatedStart) === outsideBefore, "sync must preserve frontmatter and content before the managed block byte-for-byte");
|
|
732
750
|
assert(updated.slice(updatedEnd) === outsideAfter, "sync must preserve content after the managed block byte-for-byte");
|
|
733
|
-
assert(updated.includes("version=3.0.
|
|
751
|
+
assert(updated.includes("version=3.0.2"), "sync should install the current managed workflow version");
|
|
734
752
|
assert(updated.includes("## Execution profiles"), "sync should refresh stale managed workflow content");
|
|
735
753
|
|
|
736
754
|
fillRequiredAccess(repo);
|
|
737
755
|
const status = run("node", [cli, "status", "--projects", repo, "--json"]);
|
|
738
756
|
const statusResult = JSON.parse(status.stdout).results[0];
|
|
739
757
|
assert(statusResult.managedWorkflow.state === "current", `status should expose current managed workflow state: ${status.stdout}`);
|
|
740
|
-
assert(statusResult.managedWorkflow.version === "3.0.
|
|
758
|
+
assert(statusResult.managedWorkflow.version === "3.0.2", "status should expose the installed managed workflow version");
|
|
741
759
|
|
|
742
760
|
const beforeSecondSync = fs.readFileSync(engineering, "utf8");
|
|
743
761
|
const second = run("node", [cli, "sync", "--projects", repo, "--json"]);
|
|
@@ -765,7 +783,7 @@ function testLegacyEngineeringMigrationPreservesExistingBody() {
|
|
|
765
783
|
assert(dryResult.actions.find(item => item.path === "docs/ENGINEERING.md")?.detail.includes("preserved-custom"), "custom legacy action should be labeled preserved-custom");
|
|
766
784
|
run("node", [cli, "sync", "--projects", repo]);
|
|
767
785
|
const migrated = fs.readFileSync(engineering, "utf8");
|
|
768
|
-
assert(migrated.includes("version=3.0.
|
|
786
|
+
assert(migrated.includes("version=3.0.2"), "legacy migration should insert the current managed workflow");
|
|
769
787
|
assert(migrated.includes(legacyNote), "legacy migration must preserve the complete existing body");
|
|
770
788
|
const migratedStart = migrated.indexOf("<!-- auto-coding-skill:managed-workflow:start");
|
|
771
789
|
const migratedEnd = migrated.indexOf(endMarker) + endMarker.length;
|
|
@@ -824,7 +842,7 @@ function testMalformedManagedMarkersFailClosed() {
|
|
|
824
842
|
const before = fs.readFileSync(engineering, "utf8");
|
|
825
843
|
|
|
826
844
|
const result = run("node", [cli, "sync", "--projects", repo], { check: false });
|
|
827
|
-
assert(result.status !== 0 && result.stderr.includes("refusing
|
|
845
|
+
assert(result.status !== 0 && result.stderr.includes("refusing"), `${name}: malformed markers should reject sync`);
|
|
828
846
|
assert(fs.readFileSync(engineering, "utf8") === before, `${name}: rejected sync must not touch ENGINEERING.md`);
|
|
829
847
|
assert(fs.readFileSync(skill, "utf8") === `user-sentinel-${name}\n`, `${name}: preflight must reject before writing the skill`);
|
|
830
848
|
}
|
|
@@ -891,11 +909,80 @@ function testLegacyTaskPreflightRejectsWholeBatchAtomically() {
|
|
|
891
909
|
assert(fs.readFileSync(secondAgent).equals(secondAgentBefore), "batch preflight must not write the project containing the legacy task");
|
|
892
910
|
}
|
|
893
911
|
|
|
912
|
+
function testManagedAgentsMigrationPreservesCustomRules() {
|
|
913
|
+
const repo = tmpdir("managed-agents-document");
|
|
914
|
+
run("node", [cli, "init"], { cwd: repo });
|
|
915
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
916
|
+
const agents = path.join(repo, "AGENTS.md");
|
|
917
|
+
const initial = fs.readFileSync(agents, "utf8");
|
|
918
|
+
assert(initial.includes("managed-agents:start version=3.0.2"), "new projects should receive the versioned root AGENTS block");
|
|
919
|
+
|
|
920
|
+
const custom = [
|
|
921
|
+
"# Project rules",
|
|
922
|
+
"",
|
|
923
|
+
"- Preserve this repository-specific rule exactly.",
|
|
924
|
+
"- `high-risk` cannot be downgraded and must execute `commands.gate_full`; changed or standard fallbacks do not count. Use `PASS / FAIL / PARTIAL` only from the required executed evidence.",
|
|
925
|
+
"",
|
|
926
|
+
].join("\n");
|
|
927
|
+
writeFile(agents, custom);
|
|
928
|
+
const dryRun = run("node", [cli, "sync", "--projects", repo, "--dry-run", "--json"]);
|
|
929
|
+
const plan = JSON.parse(dryRun.stdout).results[0].managedAgentsDocument;
|
|
930
|
+
assert(plan.state === "legacy-custom", `unmarked custom AGENTS should be migrated: ${dryRun.stdout}`);
|
|
931
|
+
assert(plan.migrations.includes("agents-v22-govchain-full"), "known official full-gate rule should be selected by exact migration id");
|
|
932
|
+
|
|
933
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
934
|
+
const migrated = fs.readFileSync(agents, "utf8");
|
|
935
|
+
assert(migrated.includes("managed-agents:start version=3.0.2"), "AGENTS migration should install the current managed block");
|
|
936
|
+
assert(migrated.includes("Preserve this repository-specific rule exactly."), "AGENTS migration must preserve unrelated custom rules");
|
|
937
|
+
assert(!migrated.includes("must execute `commands.gate_full`"), "known official conflicting rule should be removed");
|
|
938
|
+
const stable = fs.readFileSync(agents);
|
|
939
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
940
|
+
assert(fs.readFileSync(agents).equals(stable), "managed AGENTS sync should be idempotent");
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function testUnknownWorkflowConflictFailsWholeBatchBeforeWrites() {
|
|
944
|
+
const first = tmpdir("workflow-conflict-first");
|
|
945
|
+
const second = tmpdir("workflow-conflict-second");
|
|
946
|
+
for (const repo of [first, second]) {
|
|
947
|
+
run("git", ["init", "-q"], { cwd: repo });
|
|
948
|
+
run("node", [cli, "init"], { cwd: repo });
|
|
949
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
950
|
+
}
|
|
951
|
+
const firstSkill = path.join(first, ".agents", "skills", "auto-coding-skill", "SKILL.md");
|
|
952
|
+
writeFile(firstSkill, "batch-sentinel\n");
|
|
953
|
+
const secondAgents = path.join(second, "AGENTS.md");
|
|
954
|
+
fs.appendFileSync(secondAgents, "\n- High-risk changes\n must run the real full gate before push.\n");
|
|
955
|
+
|
|
956
|
+
const status = run("node", [cli, "status", "--projects", second, "--json"], { check: false });
|
|
957
|
+
assert(status.status !== 0, "status must be non-ok for an unknown conflicting workflow rule");
|
|
958
|
+
const statusPlan = JSON.parse(status.stdout).results[0].managedAgentsDocument;
|
|
959
|
+
assert(statusPlan.state === "conflict", `status should expose the document conflict: ${status.stdout}`);
|
|
960
|
+
assert(statusPlan.conflicts[0].file === "AGENTS.md" && statusPlan.conflicts[0].line > 0, "status conflict should include file and line");
|
|
961
|
+
|
|
962
|
+
const sync = run("node", [cli, "sync", "--projects", `${first},${second}`], { check: false });
|
|
963
|
+
assert(sync.status !== 0 && sync.stderr.includes("entire sync batch before writes"), "one unknown conflict must reject the complete batch");
|
|
964
|
+
assert(fs.readFileSync(firstSkill, "utf8") === "batch-sentinel\n", "batch conflict preflight must run before an earlier project's skill write");
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function testEngineeringMarkerBoundaryIsNormalized() {
|
|
968
|
+
const repo = tmpdir("engineering-marker-boundary");
|
|
969
|
+
run("node", [cli, "init"], { cwd: repo });
|
|
970
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
971
|
+
const engineering = path.join(repo, "docs", "ENGINEERING.md");
|
|
972
|
+
const marker = "<!-- auto-coding-skill:managed-workflow:end -->";
|
|
973
|
+
const current = fs.readFileSync(engineering, "utf8");
|
|
974
|
+
writeFile(engineering, current.replace(`${marker}\n`, `${marker}# Project-specific workflow\n`));
|
|
975
|
+
run("node", [cli, "sync", "--projects", repo]);
|
|
976
|
+
const normalized = fs.readFileSync(engineering, "utf8");
|
|
977
|
+
assert(normalized.includes(`${marker}\n# Project-specific workflow\n`), "sync should normalize a heading glued to the managed end marker");
|
|
978
|
+
}
|
|
979
|
+
|
|
894
980
|
testPreflightAvoidsPartialInstall();
|
|
895
981
|
testDestVariants();
|
|
896
982
|
testLauncherFallsBackToGlobalRuntime();
|
|
897
983
|
testMinimalSyncConvergesWithinBudget();
|
|
898
984
|
testStatusRejectsLegacyIsolation();
|
|
985
|
+
testStatusRejectsLegacyGateEscalation();
|
|
899
986
|
testOrdinaryNodeTestIsNotPromotedToAutomaticGate();
|
|
900
987
|
testAccessPasswordsAreRequiredButNeverPrintedByStatus();
|
|
901
988
|
testManagedAgentModelsInheritAndOverridesSurvive();
|
|
@@ -922,5 +1009,8 @@ testOfficialLegacyEngineeringBodyIsReplacedWithoutDuplication();
|
|
|
922
1009
|
testMalformedManagedMarkersFailClosed();
|
|
923
1010
|
testSkillOnlySyncTouchesOnlySkill();
|
|
924
1011
|
testLegacyTaskPreflightRejectsWholeBatchAtomically();
|
|
1012
|
+
testManagedAgentsMigrationPreservesCustomRules();
|
|
1013
|
+
testUnknownWorkflowConflictFailsWholeBatchBeforeWrites();
|
|
1014
|
+
testEngineeringMarkerBoundaryIsNormalized();
|
|
925
1015
|
|
|
926
1016
|
console.log("cli-installer-regression-ok");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elvis1513/auto-coding-skill",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "CLI installer for an isolated .agents engineering workflow with parallel Git worktrees, fast local gates, push-based completion, and safe cleanup.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|