Contracts

built-in-location-authority.md

Contract — Built-In Location Authority & Anti-Regression Ratchet

Behavioural contract for the seam (built_in_dir) and the CI gate. Written as assertions the implementation and its tests must satisfy.

C1 — built_in_dir(kind) resolution

#GivenWhenThen
C1.1any shipped built-in kind K (≠ carve-out)built_in_dir(K)returns resolve_pack_root("built-in") / K.plural, a path inside packs/built-in/<plural>/
C1.2the pack root is locatablebuilt_in_dir(K) then loadloads the same artefacts production loads today (graph identity unchanged)
C1.3the pack root cannot be locatedresolve_pack_root("built-in")raises PackRootNotFound — no empty-set substitute
C1.4K ∈ the derived complement {MISSION_STEP_CONTRACT, TEMPLATE, ANTI_PATTERN} (the kinds with NO packs/built-in/<plural>/ content dir)built_in_dir(K)raises a named error (no silent path to a non-existent dir); the set is DERIVED from "has a content dir", not hand-listed
C1.5a test needs a synthetic tierset SPEC_KITTY_PACKS_ROOT=<tmp>resolve_pack_root("built-in") resolves under <tmp>; no nested-path param needed
C1.6a caller needs the built-in ROOT (not a kind dir) — DRG loader/extractor, reference-pointer walk, doctrine regenerate-graphbuilt_in_root()returns resolve_pack_root("built-in"); these route through the seam, not a bare resolve_pack_root call scattered across modules

C2 — DoctrineService (fail-open removal)

#GivenWhenThen
C2.1DoctrineService(...) constructioninspect its APIthere is no built_in_root parameter and no nested _built_in_dir
C2.2any production callerbuild the service, access a reporepos self-resolve via built_in_dir(kind); behaviour unchanged
C2.3(regression) org pack shadows a built-in styleguideload styleguidesDoctrineLayerCollisionWarning fires (the collision test, resolved at the real root)

C3 — Anti-regression architectural ratchet (tests/architectural/)

#GivenWhenThen
C3.1the src/ treeAST scan (joins only)only the two pack_paths.py authorities construct a built-in path join — a resolve_pack_root("built-in") / … BinOp, its variable-indirected form (x = resolve_pack_root("built-in"); x / …), or a <path> / "built-in" filesystem join; any other join site fails the gate, named
C3.1ba bare resolve_pack_root("built-in") root call (via built_in_root()) OR a bare "built-in" string used as a layer/provenance marker (~20 legitimate sites)AST scanis PERMITTED (not flagged) — the gate is join-only, not a constant-scan
C3.2every kind WITH a content dir (the 9)resolve via authoritylands in an existing packs/built-in/<plural>/, asserted through resolve_pack_root(...) (not a raw repo-relative .exists(), cf. #3036); the derived complement {mission_step_contract, template, anti_pattern} is the #3091-marked exemption
C3.3the shipped agent_profiles setcountis non-empty (anti-vacuity — a stale/empty root fails the gate instead of passing vacuously)
C3.4existing forbidden-pattern guards + the new ratchetrunthe ratchet lives in its OWN file (not folded into test_no_dead_doctrine_paths.py, cf. #3039); existing guards' old-path literals are NOT repointed

C4 — Activation-vocabulary derivation

#GivenWhenThen
C4.1charter_yaml_io._ACTIVATION_KEYS and the finalize migration ACTIVATION_KEYScompare to YAML_KEY_MAPboth are set-equal to the derived authority (guard test)
C4.2a project with an activated glossary packrun the finalize migrationactivated_glossary_packs is carried onto charter.yaml (no silent drop)