@elvis1513/auto-coding-skill 4.2.8 → 4.3.1
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 +110 -7
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +7 -7
- package/cli/assets/skill/data/policies/feedback-resolutions-v1.json +15 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +17 -12
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +14 -8
- package/cli/assets/skill/scripts/ap.py +3094 -641
- package/cli/assets/skill/scripts/core.py +363 -1
- package/cli/assets/skill/scripts/install_integrity.py +12 -10
- package/cli/assets/skill/scripts/scaffold_templates.py +146 -0
- package/cli/src/index.js +1188 -317
- package/cli/tests/ap_concurrency_test.py +1 -1
- package/cli/tests/ap_profiles_test.py +98 -33
- package/cli/tests/core_shell_test.py +261 -0
- package/cli/tests/index.test.js +1694 -180
- package/package.json +1 -1
|
@@ -817,7 +817,7 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
|
|
|
817
817
|
_, repo, _ = self.make_repo("adaptive", require_review=False)
|
|
818
818
|
engineering = repo / "docs" / "ENGINEERING.md"
|
|
819
819
|
text = engineering.read_text(encoding="utf-8")
|
|
820
|
-
engineering.write_text(text.replace("front-pass", "", 1), encoding="utf-8")
|
|
820
|
+
engineering.write_text(text.replace("front-pass", "CHANGE_ME", 1), encoding="utf-8")
|
|
821
821
|
git(repo, "add", "docs/ENGINEERING.md")
|
|
822
822
|
git(repo, "commit", "-qm", "invalidate access for preflight test")
|
|
823
823
|
git(repo, "push", "-q", "origin", "dev")
|
|
@@ -1610,21 +1610,27 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
1610
1610
|
self.assertEqual("high-risk", plan["profile"])
|
|
1611
1611
|
self.assertIn("matched gate rule with profile=high-risk", plan["profile_reasons"])
|
|
1612
1612
|
|
|
1613
|
-
def
|
|
1613
|
+
def test_legacy_full_scope_rule_fails_closed_during_planning(self) -> None:
|
|
1614
1614
|
cfg = base_config()
|
|
1615
1615
|
cfg["gate"]["rules"] = [{"name": "sensitive", "paths": ["src/sensitive/**"], "scope": "full"}]
|
|
1616
1616
|
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1617
|
+
with self.assertRaisesRegex(APError, "legacy automatic gate escalation"):
|
|
1618
|
+
self.plan(
|
|
1619
|
+
repo,
|
|
1620
|
+
cfg,
|
|
1621
|
+
requested_scope="changed",
|
|
1622
|
+
requested_profile="micro",
|
|
1623
|
+
requested_mode="dev",
|
|
1624
|
+
)
|
|
1621
1625
|
|
|
1622
|
-
def
|
|
1626
|
+
def test_legacy_rule_commands_fail_closed_and_never_run(self) -> None:
|
|
1623
1627
|
cfg = base_config()
|
|
1624
1628
|
repo, cfg = self.make_repo("src/sensitive/value.py", cfg)
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1629
|
+
marker_dir = repo / ".test-markers"
|
|
1630
|
+
marker_dir.mkdir()
|
|
1631
|
+
quick_marker = marker_dir / "quick-ran"
|
|
1632
|
+
full_marker = marker_dir / "full-ran"
|
|
1633
|
+
build_marker = marker_dir / "build-ran"
|
|
1628
1634
|
cfg["commands"] = {
|
|
1629
1635
|
"gate_changed": f"touch {quick_marker}",
|
|
1630
1636
|
"gate_full": f"touch {full_marker}",
|
|
@@ -1640,18 +1646,20 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
1640
1646
|
]
|
|
1641
1647
|
self.write_config(repo, cfg)
|
|
1642
1648
|
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1649
|
+
with self.assertRaises(APError) as context:
|
|
1650
|
+
ap.cmd_light_gate(
|
|
1651
|
+
argparse.Namespace(
|
|
1652
|
+
repo=str(repo),
|
|
1653
|
+
scope="changed",
|
|
1654
|
+
profile="",
|
|
1655
|
+
mode="dev",
|
|
1656
|
+
base="",
|
|
1657
|
+
explain=False,
|
|
1658
|
+
)
|
|
1651
1659
|
)
|
|
1652
|
-
)
|
|
1653
1660
|
|
|
1654
|
-
self.
|
|
1661
|
+
self.assertIn("legacy automatic gate escalation", str(context.exception))
|
|
1662
|
+
self.assertFalse(quick_marker.exists())
|
|
1655
1663
|
self.assertFalse(full_marker.exists())
|
|
1656
1664
|
self.assertFalse(build_marker.exists())
|
|
1657
1665
|
|
|
@@ -2667,7 +2675,35 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
2667
2675
|
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
2668
2676
|
self.assertIn("gate.rules[0].scope", str(context.exception))
|
|
2669
2677
|
|
|
2670
|
-
def
|
|
2678
|
+
def test_project_overlay_render_rejects_its_own_oversized_output(self) -> None:
|
|
2679
|
+
with self.assertRaisesRegex(APError, "exceeds its size limit"):
|
|
2680
|
+
ap._render_project_overlay({"project": {"oversized": "x" * 200_000}})
|
|
2681
|
+
|
|
2682
|
+
def test_project_config_prepare_never_replaces_a_concurrent_overlay(self) -> None:
|
|
2683
|
+
repo, _ = self.make_repo()
|
|
2684
|
+
overlay = repo / "docs" / "project" / "auto-coding-skill.yaml"
|
|
2685
|
+
overlay.parent.mkdir(parents=True, exist_ok=True)
|
|
2686
|
+
concurrent = ap._render_project_overlay({"project": {"name": "concurrent-owner"}})
|
|
2687
|
+
planned = ap._render_project_overlay({"project": {"name": "planned-owner"}})
|
|
2688
|
+
overlay.write_bytes(concurrent)
|
|
2689
|
+
engineering_before = (repo / "docs" / "ENGINEERING.md").read_bytes()
|
|
2690
|
+
convergence = {
|
|
2691
|
+
"engineering_current": "",
|
|
2692
|
+
"engineering_output": engineering_before.decode("utf-8"),
|
|
2693
|
+
"overlay_current": None,
|
|
2694
|
+
"overlay_output": planned,
|
|
2695
|
+
"migrated_paths": ["project.name"],
|
|
2696
|
+
}
|
|
2697
|
+
args = argparse.Namespace(repo=str(repo), write=True, json=False)
|
|
2698
|
+
|
|
2699
|
+
with mock.patch.object(ap, "_project_config_convergence_plan", return_value=convergence):
|
|
2700
|
+
with self.assertRaisesRegex(APError, "create-only publish"):
|
|
2701
|
+
ap.cmd_project_config_prepare(args)
|
|
2702
|
+
|
|
2703
|
+
self.assertEqual(concurrent, overlay.read_bytes())
|
|
2704
|
+
self.assertEqual(engineering_before, (repo / "docs" / "ENGINEERING.md").read_bytes())
|
|
2705
|
+
|
|
2706
|
+
def test_upgrade_write_is_retired_before_any_migration(self) -> None:
|
|
2671
2707
|
cfg = base_config()
|
|
2672
2708
|
cfg["gate"]["full_on"] = {"paths": ["src/**"]}
|
|
2673
2709
|
cfg["gate"]["rules"] = [
|
|
@@ -2695,17 +2731,15 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
2695
2731
|
}
|
|
2696
2732
|
]
|
|
2697
2733
|
)
|
|
2734
|
+
before = engineering.read_bytes()
|
|
2698
2735
|
args = argparse.Namespace(repo=str(repo), write=True, dry_run=False, json=False)
|
|
2699
2736
|
with mock.patch.object(ap, "_load_workflow_migration_policy", return_value=policy):
|
|
2700
|
-
|
|
2737
|
+
with self.assertRaises(APError) as context:
|
|
2738
|
+
ap.cmd_upgrade(args)
|
|
2701
2739
|
|
|
2702
|
-
|
|
2703
|
-
self.
|
|
2704
|
-
self.
|
|
2705
|
-
self.assertEqual("high-risk", migrated["risk"]["rules"][0]["profile"])
|
|
2706
|
-
self.assertEqual(["gate_full"], migrated["validation"]["routes"][-1]["commands"])
|
|
2707
|
-
self.assertEqual("true", migrated["commands"]["gate_full"])
|
|
2708
|
-
self.assertNotIn("must run the full gate", body)
|
|
2740
|
+
self.assertIn("transactional installer", str(context.exception))
|
|
2741
|
+
self.assertEqual(before, engineering.read_bytes())
|
|
2742
|
+
self.assertFalse((repo / ".agents").exists())
|
|
2709
2743
|
|
|
2710
2744
|
def test_upgrade_unknown_policy_conflict_fails_before_any_write(self) -> None:
|
|
2711
2745
|
repo, _ = self.make_repo()
|
|
@@ -2716,14 +2750,19 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
2716
2750
|
encoding="utf-8",
|
|
2717
2751
|
)
|
|
2718
2752
|
before = engineering.read_text(encoding="utf-8")
|
|
2719
|
-
args = argparse.Namespace(repo=str(repo), write=
|
|
2753
|
+
args = argparse.Namespace(repo=str(repo), write=False, dry_run=True, json=False)
|
|
2720
2754
|
with mock.patch.object(
|
|
2721
2755
|
ap,
|
|
2722
|
-
"
|
|
2723
|
-
return_value=
|
|
2756
|
+
"_project_config_convergence_plan",
|
|
2757
|
+
return_value={},
|
|
2724
2758
|
):
|
|
2725
|
-
with
|
|
2726
|
-
ap
|
|
2759
|
+
with mock.patch.object(
|
|
2760
|
+
ap,
|
|
2761
|
+
"_load_workflow_migration_policy",
|
|
2762
|
+
return_value=self.workflow_policy(),
|
|
2763
|
+
):
|
|
2764
|
+
with self.assertRaises(APError) as context:
|
|
2765
|
+
ap.cmd_upgrade(args)
|
|
2727
2766
|
self.assertIn("docs/ENGINEERING.md", str(context.exception))
|
|
2728
2767
|
self.assertEqual(before, engineering.read_text(encoding="utf-8"))
|
|
2729
2768
|
self.assertFalse((repo / ".agents").exists())
|
|
@@ -3085,6 +3124,32 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
3085
3124
|
closure = closure_path.read_text(encoding="utf-8")
|
|
3086
3125
|
self.assertIn("- Effective Profile: high-risk", closure)
|
|
3087
3126
|
|
|
3127
|
+
def test_feedback_lifecycle_tracks_upgrade_verification_regression_and_closure(self) -> None:
|
|
3128
|
+
signature = "sha256:" + "a" * 64
|
|
3129
|
+
catalog = {
|
|
3130
|
+
signature: {
|
|
3131
|
+
"signature": signature,
|
|
3132
|
+
"disposition": "fixed",
|
|
3133
|
+
"effective_skill_version": "4.3.1",
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
report = {
|
|
3137
|
+
"status": "open",
|
|
3138
|
+
"signature": signature,
|
|
3139
|
+
"last_verified_skill_version": "4.3.0",
|
|
3140
|
+
}
|
|
3141
|
+
self.assertEqual("upgrade-due", ap._feedback_lifecycle(report, "4.3.0", catalog)[0])
|
|
3142
|
+
self.assertEqual("verification-due", ap._feedback_lifecycle(report, "4.3.1", catalog)[0])
|
|
3143
|
+
report["last_verified_skill_version"] = "4.3.1"
|
|
3144
|
+
self.assertEqual("regression-current", ap._feedback_lifecycle(report, "4.3.1", catalog)[0])
|
|
3145
|
+
self.assertEqual("recheck-due", ap._feedback_lifecycle(report, "4.3.2", catalog)[0])
|
|
3146
|
+
report["last_verified_skill_version"] = "4.3.2"
|
|
3147
|
+
self.assertEqual("recheck-due", ap._feedback_lifecycle(report, "4.3.1", catalog)[0])
|
|
3148
|
+
report["last_verified_skill_version"] = "4.3.1"
|
|
3149
|
+
self.assertEqual("recheck-due", ap._feedback_lifecycle(report, "4.3.2", {})[0])
|
|
3150
|
+
report["status"] = "resolved"
|
|
3151
|
+
self.assertEqual("closed", ap._feedback_lifecycle(report, "4.3.2", catalog)[0])
|
|
3152
|
+
|
|
3088
3153
|
|
|
3089
3154
|
if __name__ == "__main__":
|
|
3090
3155
|
unittest.main()
|
|
@@ -80,5 +80,266 @@ class RunShellTests(unittest.TestCase):
|
|
|
80
80
|
self.assertEqual(3, process.wait.call_count)
|
|
81
81
|
|
|
82
82
|
|
|
83
|
+
class ProjectConfigResolverTests(unittest.TestCase):
|
|
84
|
+
def setUp(self) -> None:
|
|
85
|
+
self.temporary = tempfile.TemporaryDirectory(prefix="autocoding-config-")
|
|
86
|
+
self.repo = Path(self.temporary.name)
|
|
87
|
+
(self.repo / "docs" / "project").mkdir(parents=True)
|
|
88
|
+
self.write_managed(
|
|
89
|
+
"""workflow:
|
|
90
|
+
skill_version: "4.3.1"
|
|
91
|
+
mode: dev
|
|
92
|
+
profile: auto
|
|
93
|
+
completion: push
|
|
94
|
+
project:
|
|
95
|
+
name: sample
|
|
96
|
+
commands:
|
|
97
|
+
project_fast: npm test
|
|
98
|
+
validation:
|
|
99
|
+
enabled: true
|
|
100
|
+
retries: 3
|
|
101
|
+
routes:
|
|
102
|
+
- paths: [src/**]
|
|
103
|
+
access:
|
|
104
|
+
project:
|
|
105
|
+
password: managed-secret
|
|
106
|
+
"""
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def tearDown(self) -> None:
|
|
110
|
+
self.temporary.cleanup()
|
|
111
|
+
|
|
112
|
+
def write_managed(self, frontmatter: str, body: str = "# Managed\n") -> None:
|
|
113
|
+
(self.repo / core.MANAGED_CONFIG_RELATIVE_PATH).write_text(
|
|
114
|
+
f"---\n{frontmatter.rstrip()}\n---\n{body}",
|
|
115
|
+
encoding="utf-8",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
def write_overlay(self, overrides: str, schema: str = core.PROJECT_CONFIG_SCHEMA) -> None:
|
|
119
|
+
(self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH).write_text(
|
|
120
|
+
f"schema: {schema}\noverrides:\n{overrides}",
|
|
121
|
+
encoding="utf-8",
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def assert_overlay_error(self, expected: str) -> None:
|
|
125
|
+
with self.assertRaises(core.APError) as context:
|
|
126
|
+
core.load_effective_config(self.repo)
|
|
127
|
+
self.assertIn(expected, str(context.exception))
|
|
128
|
+
|
|
129
|
+
def test_missing_overlay_keeps_managed_config_and_find_config_compatibility(self) -> None:
|
|
130
|
+
effective = core.load_effective_config(self.repo)
|
|
131
|
+
|
|
132
|
+
self.assertEqual("sample", effective["project"]["name"])
|
|
133
|
+
self.assertEqual("4.3.1", effective["workflow"]["skill_version"])
|
|
134
|
+
self.assertEqual(self.repo / "docs" / "ENGINEERING.md", core.find_config(self.repo))
|
|
135
|
+
self.assertEqual({}, core.load_project_overrides(self.repo))
|
|
136
|
+
|
|
137
|
+
def test_recursive_merge_treats_falsy_scalars_and_empty_lists_as_authoritative(self) -> None:
|
|
138
|
+
self.write_overlay(
|
|
139
|
+
""" workflow:
|
|
140
|
+
profile: project-profile
|
|
141
|
+
project:
|
|
142
|
+
name: project-owned
|
|
143
|
+
commands:
|
|
144
|
+
project_fast: ''
|
|
145
|
+
validation:
|
|
146
|
+
enabled: false
|
|
147
|
+
retries: 0
|
|
148
|
+
routes: []
|
|
149
|
+
added:
|
|
150
|
+
nested: value
|
|
151
|
+
"""
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
effective = core.load_effective_config(self.repo)
|
|
155
|
+
|
|
156
|
+
self.assertEqual("4.3.1", effective["workflow"]["skill_version"])
|
|
157
|
+
self.assertEqual("dev", effective["workflow"]["mode"])
|
|
158
|
+
self.assertEqual("project-profile", effective["workflow"]["profile"])
|
|
159
|
+
self.assertEqual("push", effective["workflow"]["completion"])
|
|
160
|
+
self.assertEqual("project-owned", effective["project"]["name"])
|
|
161
|
+
self.assertEqual("", effective["commands"]["project_fast"])
|
|
162
|
+
self.assertIs(effective["validation"]["enabled"], False)
|
|
163
|
+
self.assertEqual(0, effective["validation"]["retries"])
|
|
164
|
+
self.assertEqual([], effective["validation"]["routes"])
|
|
165
|
+
self.assertEqual({"nested": "value"}, effective["added"])
|
|
166
|
+
|
|
167
|
+
def test_overlay_payload_parser_matches_file_loader(self) -> None:
|
|
168
|
+
self.write_overlay(" project:\n name: project-owned\n validation:\n routes: []\n")
|
|
169
|
+
payload = (self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH).read_bytes()
|
|
170
|
+
|
|
171
|
+
self.assertEqual(
|
|
172
|
+
core.load_project_overrides(self.repo),
|
|
173
|
+
core.parse_project_overrides_payload(payload),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
def test_overlay_payload_parser_and_loader_both_reject_invalid_wrapper(self) -> None:
|
|
177
|
+
payload = (
|
|
178
|
+
f"schema: {core.PROJECT_CONFIG_SCHEMA}\n"
|
|
179
|
+
"overrides: {}\n"
|
|
180
|
+
"project: {}\n"
|
|
181
|
+
).encode("utf-8")
|
|
182
|
+
(self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH).write_bytes(payload)
|
|
183
|
+
|
|
184
|
+
for label, load in (
|
|
185
|
+
("payload", lambda: core.parse_project_overrides_payload(payload)),
|
|
186
|
+
("file", lambda: core.load_project_overrides(self.repo)),
|
|
187
|
+
):
|
|
188
|
+
with self.subTest(source=label):
|
|
189
|
+
with self.assertRaisesRegex(core.APError, "unsupported top-level wrapper"):
|
|
190
|
+
load()
|
|
191
|
+
|
|
192
|
+
def test_merge_does_not_mutate_either_layer(self) -> None:
|
|
193
|
+
defaults = {"nested": {"managed": True}, "items": ["managed"]}
|
|
194
|
+
overrides = {"nested": {"project": True}, "items": []}
|
|
195
|
+
|
|
196
|
+
effective = core.merge_project_config(defaults, overrides)
|
|
197
|
+
effective["nested"]["managed"] = False
|
|
198
|
+
|
|
199
|
+
self.assertEqual({"nested": {"managed": True}, "items": ["managed"]}, defaults)
|
|
200
|
+
self.assertEqual({"nested": {"project": True}, "items": []}, overrides)
|
|
201
|
+
|
|
202
|
+
def test_rejects_null_values_in_both_layers(self) -> None:
|
|
203
|
+
self.write_overlay(" commands:\n project_fast:\n")
|
|
204
|
+
self.assert_overlay_error("must not contain null")
|
|
205
|
+
|
|
206
|
+
(self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH).unlink()
|
|
207
|
+
self.write_managed("workflow:\n skill_version:\n")
|
|
208
|
+
self.assert_overlay_error("must not contain null")
|
|
209
|
+
|
|
210
|
+
def test_rejects_duplicate_keys_in_both_layers(self) -> None:
|
|
211
|
+
self.write_overlay(" project:\n name: one\n name: two\n")
|
|
212
|
+
self.assert_overlay_error("duplicate YAML keys")
|
|
213
|
+
|
|
214
|
+
(self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH).unlink()
|
|
215
|
+
self.write_managed("project:\n name: one\n name: two\n")
|
|
216
|
+
self.assert_overlay_error("duplicate YAML keys")
|
|
217
|
+
|
|
218
|
+
def test_rejects_yaml_anchors_aliases_and_merge_keys(self) -> None:
|
|
219
|
+
self.write_overlay(" project: &project\n name: sample\n copy: *project\n")
|
|
220
|
+
self.assert_overlay_error("anchors or aliases")
|
|
221
|
+
|
|
222
|
+
self.write_overlay(" project:\n <<: {name: sample}\n")
|
|
223
|
+
self.assert_overlay_error("merge keys")
|
|
224
|
+
|
|
225
|
+
def test_rejects_unknown_wrapper_or_schema(self) -> None:
|
|
226
|
+
overlay = self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH
|
|
227
|
+
overlay.write_text(
|
|
228
|
+
f"schema: {core.PROJECT_CONFIG_SCHEMA}\noverrides: {{}}\nproject: {{}}\n",
|
|
229
|
+
encoding="utf-8",
|
|
230
|
+
)
|
|
231
|
+
self.assert_overlay_error("unsupported top-level wrapper")
|
|
232
|
+
|
|
233
|
+
self.write_overlay(" project: {}\n", schema="unexpected/v1")
|
|
234
|
+
self.assert_overlay_error("schema is unsupported")
|
|
235
|
+
|
|
236
|
+
def test_rejects_managed_workflow_fields_and_whole_workflow_replacement(self) -> None:
|
|
237
|
+
for field, value in (
|
|
238
|
+
("skill_version", '"99.0.0"'),
|
|
239
|
+
("mode", "custom"),
|
|
240
|
+
("completion", "local-only"),
|
|
241
|
+
):
|
|
242
|
+
with self.subTest(field=field):
|
|
243
|
+
self.write_overlay(f" workflow:\n {field}: {value}\n")
|
|
244
|
+
self.assert_overlay_error("cannot override managed workflow fields")
|
|
245
|
+
|
|
246
|
+
self.write_overlay(" workflow: disabled\n")
|
|
247
|
+
self.assert_overlay_error("cannot override managed workflow fields")
|
|
248
|
+
|
|
249
|
+
@unittest.skipIf(os.name == "nt", "symlink setup is platform-dependent")
|
|
250
|
+
def test_rejects_overlay_file_and_parent_symlinks(self) -> None:
|
|
251
|
+
overlay = self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH
|
|
252
|
+
outside = self.repo / "outside.yaml"
|
|
253
|
+
outside.write_text(
|
|
254
|
+
f"schema: {core.PROJECT_CONFIG_SCHEMA}\noverrides: {{}}\n",
|
|
255
|
+
encoding="utf-8",
|
|
256
|
+
)
|
|
257
|
+
overlay.symlink_to(outside)
|
|
258
|
+
self.assert_overlay_error("regular non-symlink file")
|
|
259
|
+
|
|
260
|
+
overlay.unlink()
|
|
261
|
+
project_dir = self.repo / "docs" / "project"
|
|
262
|
+
project_dir.rmdir()
|
|
263
|
+
outside_dir = self.repo / "outside-project"
|
|
264
|
+
outside_dir.mkdir()
|
|
265
|
+
(outside_dir / "auto-coding-skill.yaml").write_text(
|
|
266
|
+
f"schema: {core.PROJECT_CONFIG_SCHEMA}\noverrides: {{}}\n",
|
|
267
|
+
encoding="utf-8",
|
|
268
|
+
)
|
|
269
|
+
project_dir.symlink_to(outside_dir, target_is_directory=True)
|
|
270
|
+
self.assert_overlay_error("parent must be a real directory")
|
|
271
|
+
|
|
272
|
+
def test_bounds_overlay_and_frontmatter_reads(self) -> None:
|
|
273
|
+
overlay = self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH
|
|
274
|
+
overlay.write_bytes(b"x" * (core.PROJECT_CONFIG_OVERLAY_MAX_BYTES + 1))
|
|
275
|
+
self.assert_overlay_error("exceeds its size limit")
|
|
276
|
+
|
|
277
|
+
overlay.unlink()
|
|
278
|
+
huge = "x" * core.MANAGED_CONFIG_FRONTMATTER_MAX_BYTES
|
|
279
|
+
self.write_managed(f"project:\n name: {huge}\n")
|
|
280
|
+
self.assert_overlay_error("bounded YAML frontmatter")
|
|
281
|
+
|
|
282
|
+
def test_rejects_excessive_yaml_nesting(self) -> None:
|
|
283
|
+
indent = " "
|
|
284
|
+
lines = []
|
|
285
|
+
for index in range(core.PROJECT_CONFIG_MAX_YAML_DEPTH + 1):
|
|
286
|
+
lines.append(f"{indent}level{index}:")
|
|
287
|
+
indent += " "
|
|
288
|
+
lines.append(f"{indent}value: bounded")
|
|
289
|
+
self.write_overlay("\n".join(lines) + "\n")
|
|
290
|
+
|
|
291
|
+
self.assert_overlay_error("YAML complexity limit")
|
|
292
|
+
|
|
293
|
+
def test_large_managed_body_is_not_part_of_frontmatter_bound(self) -> None:
|
|
294
|
+
self.write_managed(
|
|
295
|
+
'workflow:\n skill_version: "4.3.1"\n',
|
|
296
|
+
body="x" * (core.MANAGED_CONFIG_FRONTMATTER_MAX_BYTES + 1),
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
self.assertEqual("4.3.1", core.load_effective_config(self.repo)["workflow"]["skill_version"])
|
|
300
|
+
|
|
301
|
+
def test_yaml_failure_does_not_echo_content_or_absolute_path(self) -> None:
|
|
302
|
+
secret = "NEVER_ECHO_THIS_SECRET"
|
|
303
|
+
overlay = self.repo / core.PROJECT_CONFIG_OVERLAY_RELATIVE_PATH
|
|
304
|
+
overlay.write_text(
|
|
305
|
+
f"schema: {core.PROJECT_CONFIG_SCHEMA}\noverrides:\n access: [{secret}\n",
|
|
306
|
+
encoding="utf-8",
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
with self.assertRaises(core.APError) as context:
|
|
310
|
+
core.load_effective_config(self.repo)
|
|
311
|
+
|
|
312
|
+
message = str(context.exception)
|
|
313
|
+
self.assertNotIn(secret, message)
|
|
314
|
+
self.assertNotIn(str(self.repo), message)
|
|
315
|
+
|
|
316
|
+
def test_yaml_constructor_failures_are_sanitized_as_aperror(self) -> None:
|
|
317
|
+
cases = (
|
|
318
|
+
("bool", "!!bool BOOL_SECRET_SENTINEL", "BOOL_SECRET_SENTINEL"),
|
|
319
|
+
("int", "!!int INT_SECRET_SENTINEL", "INT_SECRET_SENTINEL"),
|
|
320
|
+
("huge-int", "9" * 5000, "9" * 64),
|
|
321
|
+
)
|
|
322
|
+
for label, value, forbidden in cases:
|
|
323
|
+
with self.subTest(case=label):
|
|
324
|
+
self.write_overlay(f" value: {value}\n")
|
|
325
|
+
with self.assertRaises(core.APError) as context:
|
|
326
|
+
core.load_effective_config(self.repo)
|
|
327
|
+
|
|
328
|
+
message = str(context.exception)
|
|
329
|
+
self.assertIn("contains invalid YAML", message)
|
|
330
|
+
self.assertNotIn(forbidden, message)
|
|
331
|
+
|
|
332
|
+
def test_rejects_surrogate_nul_and_escape_strings(self) -> None:
|
|
333
|
+
cases = (
|
|
334
|
+
("surrogate", '"\\uD800"', "invalid Unicode string"),
|
|
335
|
+
("nul", '"\\0"', "unsupported control character"),
|
|
336
|
+
("escape", '"\\u001b[31m"', "unsupported control character"),
|
|
337
|
+
)
|
|
338
|
+
for label, value, expected in cases:
|
|
339
|
+
with self.subTest(case=label):
|
|
340
|
+
self.write_overlay(f" value: {value}\n")
|
|
341
|
+
self.assert_overlay_error(expected)
|
|
342
|
+
|
|
343
|
+
|
|
83
344
|
if __name__ == "__main__":
|
|
84
345
|
unittest.main()
|