Skip to content

test(parser): pin error recovery after a column-0 tag with a stray quote - #2800

Merged
robcohen merged 1 commit into
mainfrom
fix/tag-quote-error-recovery
Oct 29, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/tag-quote-error-recovery

Conversation

@robcohen

Copy link
Copy Markdown
Member

What changed

Test only. Adds test_parse_tag_line_with_a_stray_quote_keeps_the_following_directives to crates/rustledger-parser/tests/unterminated_quote.rs. No parser code changes.

Why

#2781 was filed before #2788 ("end an unterminated quote at its own line") merged. #2788 fixes it: the stray " after a column-0 #TODO tag now ends at its own line, so error recovery resyncs at the next line, as beancount does. Nothing pinned the tag shape, so this adds a regression test for it and its variants. Each case asserts the exact error span, the exact surviving directives, and the lossless + green/red agreement invariants (assert_invariants: lossless tokenize, CST round-trip, parse vs parse_red_only directives and errors).

Evidence

Repro from the issue:

#TODO buy 27" monitor
2024-01-02 open Assets:B
2024-01-03 open Assets:C
Case rledger before #2788 rledger on main (336ddce) bean-check 3.2.3
issue repro 1 error, bytes 0..72 (to EOF), 0 opens 1 error on line 1 (0..22), opens B, C errors on line 1, opens B, C
repro with CRLF (not run) 1 error on line 1 (0..23), opens B, C errors on line 1, opens B, C
#TODO "x then an open (not run) 1 error on line 1, open B errors on line 1, open B
#TODO 2024-01-01 open Assets:A "x then two opens (not run) 1 error on line 1, opens B, C errors on line 1, opens B, C
#TODO "x as the last line, no newline (not run) 1 error on line 2, open A errors on line 2, open A
repro plus a later note ... "hello" and open Assets:D (not run) 1 error on lines 1 to 4 (the string closes on line 4), open D only errors on lines 1 and 4, open D only

The last case is expected: a terminated string may span lines in beancount, so the " on line 1 pairs with the first " on line 4 and both sides lose lines 2 to 4.

The new test fails with logos_lexer.rs reverted to its pre-#2788 version (left: [("parse error: unexpected input", 0, 72)], right: [(..., 0, 22)]) and passes on main.

bean-check results come from beancount 3.2.3 in the dev-shell compat container (parser.parse_file, listing error line numbers and surviving entries).

Baseline impact

None: no parser code changes. The local strict corpus_baseline and cst_baseline gates pass (STRICT_BASELINE=1).

How to test

cargo test -p rustledger-parser --test unterminated_quote

Also ran: cargo test -p rustledger-parser --all-features, cargo test -p rustledger-loader (56 test result: ok, 0 failed), clippy -D warnings --all-targets on rustledger-parser, cargo fmt --check, RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser --no-deps.

Draft so it lands after the #2758 baseline regeneration.

Closes #2781

🤖 Generated with Claude Code

#2788 (end an unterminated quote at its own line) already fixed #2781:
`#TODO buy 27" monitor` followed by two opens now reports one error on
line 1 and keeps both opens, as beancount 3.2.3 does. Before #2788 the
error ran to the end of the file and both opens were lost.

Add a parse-level regression test for the tag shape and its variants
(CRLF, a bare `#TODO "x`, a directive-looking tag line, the last line,
and a later quote that closes the string across lines). Each case
matches beancount 3.2.3's error line and surviving directives, and goes
through the lossless and green/red agreement invariants.

Closes #2781

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen marked this pull request as ready for review October 29, 2026 04:29
@robcohen
robcohen requested a review from a team as a code owner October 29, 2026 04:29
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 45.3ms ± 0.9ms 806.0ms ± 4.9ms 17.8x 34.6 MB / 51.1 MB
investment 68.4ms ± 1.2ms 2944.9ms ± 33.0ms 43.1x 44.5 MB / 59.0 MB
fifo 66.6ms ± 1.1ms 14631.7ms ± 77.7ms 219.8x 40.4 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 44.4ms ± 0.4ms 45.3ms ± 0.9ms +1.9% ✅ within noise 34.6 MB → 34.6 MB (-0.2%)
investment 68.2ms ± 1.0ms 68.4ms ± 1.2ms +0.2% ✅ within noise 44.4 MB → 44.5 MB (+0.1%)
fifo 66.2ms ± 1.0ms 66.6ms ± 1.1ms +0.5% ✅ within noise 40.6 MB → 40.4 MB (-0.4%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.4ms, investment 0.7ms, fifo 0.7ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 821
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 310261c into main Oct 29, 2026
60 of 61 checks passed
@robcohen
robcohen deleted the fix/tag-quote-error-recovery branch October 29, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(parser): error recovery after a column-0 #tag with a quote loses the following directives

1 participant