refactor(cdsl_engine): sink atomic runtime capability flags into schema contracts

Phase 4 of the decoupling refactor (behavior-preserving):
- profile_schema.json: every operation contract now carries
  runtime_capability {body_mutating, requires_active_body,
  replayable, requires_selector, open_profile_ok} (single source of truth)
- operation_contracts.py: validates and forwards the flags
- capabilities.py: the five data-classification frozensets are now
  derived from the schema at import time; dispatch-logic sets
  (_HOLE_ATOMICS, _PATTERN_ATOMICS, extent constants) stay in code
- test_profile_schema.py: completeness + structural invariants test

Equivalence proven by flag counts (27/13/25/6/2) matching the previous
hand-written sets and by the unchanged test-baseline failure set.
This commit is contained in:
2026-09-09 13:41:38 +08:00
parent 5ffb106f36
commit beac59fc8b
4 changed files with 101 additions and 66 deletions
+22
View File
@@ -60,6 +60,28 @@ class ProfileSchemaTests(unittest.TestCase):
)
self.assertEqual(set(self.schema["profiles"]), set(self.schema["runtime_supported_profiles"]))
def test_runtime_capability_flags_are_complete_and_structurally_sound(self) -> None:
contracts = self.schema["operation_contracts"]
flags = ("body_mutating", "requires_active_body", "replayable", "requires_selector", "open_profile_ok")
for atomic_id, contract in contracts.items():
capability = contract.get("runtime_capability")
self.assertIsInstance(capability, dict, atomic_id)
for flag in flags:
self.assertIsInstance(capability.get(flag), bool, f"{atomic_id}.{flag}")
for atomic_id, contract in contracts.items():
capability = contract["runtime_capability"]
if capability["replayable"]:
# Only body-mutating features (or pattern replay itself) can be
# the source of another pattern replay.
self.assertTrue(
capability["body_mutating"] or atomic_id.startswith("pattern_"),
atomic_id,
)
if capability["requires_active_body"]:
self.assertTrue(capability["body_mutating"], atomic_id)
if capability["open_profile_ok"]:
self.assertTrue(atomic_id.startswith("extrude_cut"), atomic_id)
def test_rejects_unsupported_atomic_operation_before_rebuild(self) -> None:
cdsl = {
"schema": "cad.cdsl.llm.v1",