spec 110 US-A: cacp-python reference parser (v0.1.0)#6
Merged
Conversation
New cacp-python/ subdirectory implementing the canonical Python parser for CACP per the spec in ../README.md. Parser (~145 LOC incl. docstrings; core logic ~80 LOC) covers: - 9 STATUS values: ok|fail|partial|needs_decision|no_changes| decomposed|rejected|retry|fixture_gap - 3 TESTS/BUILD values: pass|fail|skip (+ optional :N count for TESTS) - Whitespace tolerance (space, multiple spaces, tab) via [ \t]* — not \s*, which would swallow newlines and cross field boundaries - Case-insensitive field names; STATUS/TESTS/BUILD values normalized to lowercase Zero runtime dependencies (pure stdlib + dataclass model). A dataclass keeps the dep tree empty; callers wanting Pydantic-style validation can wrap the returned record. Tests (42 passing) cover: 9-value parametrized STATUS, the 6-line tolerance vector from README.md verbatim, README response example round-trip, dispatch-example negative (no STATUS field -> parse returns None), case-insensitive field names across the full grid, and whitespace tolerance for TESTS/BUILD. Spec 110 US-A of the switchyard project — this package becomes the canonical reference impl that downstream (switchyard v5.4.x, zendev) consumes as `cacp>=0.1.0`. Other language implementations should port tests/test_conformance.py against the same vector. Co-Authored-By: Claude Opus 4.7 (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.
What
Adds a new
cacp-python/subdirectory containing the canonical Pythonreference parser for CACP. The parser lives alongside the spec so the
two can evolve together.
Why
Spec 110 US-A of the switchyard
project. The goal is to have the canonical Python implementation
colocated with the canonical spec, rather than letting each downstream
consumer ship its own slightly-different parser (which is how we got
bugs like switchyard #941 — a parser that rejected output the spec said
was valid).
Size
What's in it
src/cacp/parser.py—parse(text) -> CACPResponse | None. Sevencompiled per-field regexes, each with
[ \t]*(deliberately NOT\s*— that would let a blank line swallow the following field) andre.IGNORECASE | re.MULTILINE. STATUS alternates over the 9canonical values; TESTS/BUILD over the 3 canonical values.
src/cacp/models.py—CACPResponsedataclass + the two canonicaltuples (
CANONICAL_STATUS_VALUES,CANONICAL_TESTS_BUILD_VALUES).tests/test_conformance.py— the 6-line tolerance vector from thespec verbatim, plus parametrized coverage of all 9 STATUS values and
all 3 TESTS/BUILD values under every whitespace shape.
tests/test_roundtrip.py— feeds the literal response example andliteral dispatch example from
../README.mdthrough the parser;response round-trips, dispatch correctly returns
None(strict — noSTATUS field means not a response).
Test summary
All 42 tests pass under Python 3.12. Test breakdown:
Design notes
@dataclassto keep the dep tree empty. Callers that want runtime validation
can wrap it. The tradeoff was discussed inline in the README.md.
FIELD:valuesplitter. Thislets each field enforce its own grammar (STATUS restricted to the
9 values, TESTS allows optional
:N, FILES_* captures to EOL).[ \t]*not\s*after the colon —\smatches newline, so alazy
\s*would let one field's blank line get consumed into thenext field's value. This is the same class of bug switchyard #941
hit in v5.2.0 and the spec's "Why these rules exist" section calls
out.
Next steps (out of scope for this PR)
cacp>=0.1.0as a real dependency anddelete its in-tree parser copy.
tests/test_conformance.pyagainst the same vector.Reviewer ask
Please confirm the STATUS vocabulary and tolerance test vector match
the spec's intent. Everything in
tests/test_conformance.pyderivesfrom the canonical README.md in this repo — if any row there is wrong,
either the test is wrong or the spec is wrong, and I'd rather catch
that now than after downstream consumers pin the version.
Guardrails honored
README.mdat the repo root — that'sthe authoritative spec.
main.🤖 Generated with Claude Code