{"record":{"id":"d1ca70d207bd8414","repo":"Hmbown/CodeWhale","slug":"bounded-fragment-module-must-define-trait-contextf","errorCode":null,"errorMessage":"bounded fragment module must define trait ContextFragment with matches_text","messagePattern":"bounded fragment module must define trait ContextFragment with matches_text","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":576,"sourceCode":"        \".cursorrules\",\n        \".clinerules\",\n        \".windsurf/rules\",\n        \".gemini\",\n        \".github/copilot-instructions.md\",\n    ]\n    for candidate in required_candidates:\n        if candidate not in text:\n            raise RuntimeContractError(\n                f\"PROJECT_INSTRUCTION_CANDIDATES missing required entry {candidate!r}\"\n            )\n\n    # matches_text recognizer must exist on the fragment trait\n    if \"fn matches_text\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must define a matches_text recognizer on the fragment trait\"\n        )\n    if \"trait ContextFragment\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must define trait ContextFragment with matches_text\"\n        )\n\n    # No unbounded fragment — enforce that creation clamps to MAX_FRAGMENT_BYTES\n    if \"MAX_FRAGMENT_BYTES\" not in text or \"enforce_byte_cap\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must enforce byte caps via enforce_byte_cap and MAX_FRAGMENT_BYTES\"\n        )\n\n    # TUI must be unified with the core boundary (shared crates/core module)\n    tui_fragment = REPO_ROOT / \"crates\" / \"tui\" / \"src\" / \"model_context\" / \"fragment.rs\"\n    try:\n        tui_text = tui_fragment.read_text(encoding=\"utf-8\")\n    except FileNotFoundError as error:\n        raise RuntimeContractError(\n            f\"missing TUI fragment module: {tui_fragment} ({error})\"\n        ) from error\n    if \"codewhale_core::fragments\" not in tui_text:","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L558-L594","documentation":"The gate requires the literal text 'trait ContextFragment' in crates/core/src/fragments.rs - the shared trait all bounded context fragments implement. It fails when the trait is renamed, or when fragments.rs is split so the trait definition lives in a submodule the gate (which reads only fragments.rs) cannot see.","triggerScenarios":"Renaming ContextFragment to Fragment/ContextSection; converting fragments.rs into a fragments/ directory with the trait in a sub-file while the gate still reads the old single file.","commonSituations":"Module-growth refactors splitting the 600+ line fragments.rs; trait renames during API cleanup.","solutions":["Keep 'pub trait ContextFragment' declared inside crates/core/src/fragments.rs","If splitting the module, update FRAGMENT_MODULE in scripts/check-runtime-contract-budget.py:428 to point at the file that now holds the trait, in the same commit","Verify: 'grep -n \"trait ContextFragment\" crates/core/src/fragments.rs'"],"exampleFix":"# before: trait moved to crates/core/src/fragment_trait.rs, fragments.rs only re-exports\n# (gate still reads fragments.rs -> fails)\npub use crate::fragment_trait::ContextFragment;\n\n# after: keep the trait definition in fragments.rs (or update FRAGMENT_MODULE)\npub trait ContextFragment { /* ... */ }","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\ntext = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\nassert \"trait ContextFragment\" in text, \"ContextFragment trait not declared in fragments.rs\"","typeGuard":"def is_runtime_contract_error(exc: BaseException) -> bool:\n    return isinstance(exc, ValueError) and type(exc).__name__ == \"RuntimeContractError\"","tryCatchPattern":"try:\n    check_fragment_caps()\nexcept RuntimeContractError as error:\n    print(f\"[gate] {error}\", file=sys.stderr)\n    raise SystemExit(2)","preventionTips":["Keep 'pub trait ContextFragment' defined in crates/core/src/fragments.rs itself","When splitting the module, update FRAGMENT_MODULE in the checker to the file holding the trait","Run the checker as part of any module-restructure PR"],"tags":["python","ci","static-analysis","rust","trait","module-structure"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}