Repository navigation
feat(tooling): add ptadiff, format-generic differential parse testing - #73
Merged
Merged
Conversation
A Python package under tooling/differential that compares a parser's errors
with a reference implementation's and turns the mismatches into named
categories:
- oracle adapters: beancount via its public Python API (parse_string,
lex_iter_string) in forked workers with timeouts and crash capture; CLI
oracle stubs for ledger and hledger
- a JSON-lines protocol for the implementation under test:
{id, text} in, {id, errors: [{line, code, msg}]} out
- per-format plugins: normalizers, a registry of category keys (beancount:
`shape` from lex_iter_string token names, and `coarse`), generators
- the seeded G1-G3(b) beancount generators: fixed seeds, no hardcoded
paths, deterministic sorted output (digests pinned in the tests), drawing
G3 windows from a bundled seed corpus
- shared stages: a key-preserving minimizer (lines, tokens, characters),
a clusterer, and deterministic JSON + markdown reports
- a CLI (`python -m ptadiff generate|run|minimize`), tests, a README, and a
CI job running them on Python 3.10 and 3.12 against beancount 3.2.3
Nothing is derived from beancount's grammar, lexer rules or parser tables;
a key built from a clean-room grammar's parser states plugs into the key
registry once those tables exist.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
to rustledger/rustledger
that referenced
this pull request
Nov 27, 2026
…dards#73) The tooling/differential tree is identical to the feature-branch commit it replaces, so no count changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
to rustledger/rustledger
that referenced
this pull request
Nov 27, 2026
…diff (#3056) * feat(parity): name parse-error mismatches by category key through ptadiff The parse-error parity harness now runs through pta-standards' differential package (ptadiff, tooling/differential), pinned by commit in the manifest (`#@ptadiff-rev`), and names every mismatch with ptadiff's beancount `shape` category key: which side reports more on the first line the two disagree on, that side's error kinds, the line's kind, and the line's token shape from beancount's black-box lexer (lex_iter_string). - parse_error_lines gains `--jsonl`, ptadiff's JSON-lines protocol; the harness talks to rledger through it, and runs beancount in ptadiff's forked workers (same crash capture as before) - a new `gen` input source: 12000 inputs from ptadiff's seeded G1-G3(b) generators, pinned like the fuzz and matrix inputs (`#@generators`, `#@inputs gen`, per-input pins), identical across runs, worker counts and Python versions - the manifest pins each category key's count over the fixed sources (`@ categories`, next to the symptom buckets); a changed count is a stale pin, and a different ptadiff revision, key or generator sample is a coverage error. Every existing pin is unchanged - the report adds the category table, with the ten largest categories' examples minimized by ptadiff's key-preserving minimizer (`--minimize`); `--categories-json` writes it for the CI artifact - a token-level drift test (`cst::bc_lexer_drift`) compares BcLexer with beancount 3.2.3's lex_iter_string, token name and byte span, over the tracked ledgers, fuzz regressions, pinned fuzz corpus, stray-character matrix and generator sample (123833 inputs, all agree), run in the python-gated-cargo-tests job with skips turned into failures Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(compat): pin ptadiff to pta-standards main (rustledger/pta-standards#73) The tooling/differential tree is identical to the feature-branch commit it replaces, so no count changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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
tooling/differential/, a Python package (ptadiff). It compares a parser's errors with a reference implementation's and turns the mismatches into named categories that CI can count and pin.It is format-generic. Each format supplies a plugin: an oracle adapter, normalizers, a registry of category keys, generators, and shrink units. Comparing, minimizing, clustering and reporting are shared.
parse_string,lex_iter_string). Each call runs in a forked worker (ptadiff.pool.run_forked) with a timeout. A segfault, exception or hang loses only that input, which is recorded as a crash.parse_outputis left to write.{id, text}in,{id, errors: [{line, code, msg}]}out.coarse:side|who:kinds|line-kind, using the error kinds of the side that reports more on that line.shape(the default):coarseplus the divergent line's token shape, taken fromlex_iter_stringtoken names. That is the token just before the first invalid token (^at the start of the line), or the line's first two tokens when it has none.ptadiff-report/1) plus a markdown table.python -m ptadiff generate | run | minimize.Why
This is phase 1 of the parser plan: reproducible differential infrastructure that turns parse mismatches into named categories. rustledger's parse-error parity gate consumes it, pinned to a commit of this branch, in a companion PR.
License boundary
beancount is GPL-2.0-only. Nothing here is derived from its
grammar.y,lexer.l,parser.c,tokens.cor tables generated from them. The oracle only calls beancount's public Python API, and token names come from whatlex_iter_stringreturns at run time.How to test
The new
differential-toolingjob inci.ymlruns the tests on Python 3.10 and 3.12 against beancount 3.2.3, with skips turned into failures. It also installs the package from its subdirectory, which is how consumers install it.ruff format --check .andruff check .(0.16.4) are clean.Example output
These are the top categories of rustledger against beancount 3.2.3 over 123,304 inputs, with the examples minimized:
impl-fewer|oracle:lex:token+syn:INDENT|indented|INDENT error"\t\ufeff"impl-more|impl:P0012|top|^ error"\^A\r2"impl-more|impl:P0012|top|DATE error"2229-1-7B\r!"🤖 Generated with Claude Code