feat: validator L3 (contract satisfaction) + L6 (waste detection) + deterministic query CLI#2
Merged
Conversation
…on + query CLI Implements the two previously-planned validator levels and a deterministic query interface, completing the 6-level TDD cascade. Level 3 — Contract satisfaction (errors): - Each declared L0 constraint_contracts / commitment_contracts must be satisfied: its validated_by provider file must exist, every satisfies_constraint / satisfies_commitment reference must resolve to a declared contract of the matching kind (constraint vs commitment), and no declared contract may be left uncovered (no provider and no referencing spec). Mirrors the binding semantics of Level 2. Level 6 — Waste detection (warnings): - Orphaned organization.yaml roles never referenced in any process spec - Unconsumed products (no signal implemented_by, no other reference) - Empty contracts (missing/empty requires obligations) - Duplicate implemented_by allocation within a single signal - Conservative definitions to avoid false positives. Deterministic query CLI (orgschema-query): - Plain deterministic interface over L3/L6 (NO natural-language / LLM layer); OrgSchema's constraint space is boolean, so a deterministic query is the correct interface rather than a grounded NL->DSL pipeline. - --schema FILE [--check contracts|waste|all] [--level 3|6] [--format text|json] - Re-uses the validator level functions so results never diverge. - console_scripts entry point added in pyproject.toml. Tests: positive + negative cases for L3 and L6, plus CLI smoke tests (16 tests). pytest pythonpath configured so the source tree imports. Verified against orgschema-demo: all 6 levels pass, 0 false positives. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes the 6-level OrgSchema TDD-cascade validator by implementing the two previously-planned levels (the README noted L3/L6 as "planned for future releases") plus a deterministic query CLI.
Level 3 — Contract Satisfaction (errors)
L0 defines
constraint_contracts(L0_con_*) andcommitment_contracts(L0_com_*), and specs reference them viasatisfies_constraint/satisfies_commitment. L3 enforces, deterministically:validated_byfile is present on disk (the parenthetical note formpath (note)is handled). A contract pointing at a missing provider is an unmet contract.satisfies_constraint/satisfies_commitmentannotation resolves to a declared contract of the matching kind (a commitment id undersatisfies_constraintis a type mismatch).Contracts are binding (regulatory / self-imposed), so violations are errors, mirroring Level 2.
Level 6 — Waste Detection (warnings)
Surfaces declared units that are never consumed (advisory, like L4/L5):
organization.yaml: rolesreferenced by no process spec (substring match across structured + prose fields, conservative to avoid singular/plural false positives).products/*.yamlthat no signal lists inimplemented_byand no other spec references by path or id.requires.implemented_by.Definitions are deliberately conservative (declared-here-consumed-nowhere) to keep noise low.
Deterministic Query CLI —
orgschema-queryA plain deterministic query interface over L3/L6 — no natural-language / LLM layer. OrgSchema's constraint space is boolean (satisfied or not; consumed or not), so a deterministic query is the right interface, not a grounded NL→DSL pipeline. It re-uses the validator level functions, so query and validator never disagree.
Exit
1when an error-severity check (contracts) reports a violation, else0. Added as aconsole_scriptsentry point.Quality
uv run black --check .,flake8 --select=E9,F63,F7,F82,mypy, and fullpytestall green. Fleet pre-commit hook passed (black/flake8/mypy/trivy).orgschema-demo: all 6 levels pass with 0 false positives.Spec ambiguity resolved
The README named L3/L6 but did not give field-level definitions. Definitions were derived faithfully from the existing data model (the L0
validated_by/requirescontract fields andsatisfies_constraint/satisfies_commitmentreferences already present in the demo) and documented in the function docstrings and README.🤖 Generated with Claude Code