Skip to content

test(parser): #1262 phase 4.2 — format-compat suite with 30 destructive-formatting fixtures - #1292

Merged
robcohen merged 4 commits into
mainfrom
feat/cst-phase-4-2-format-compat
Jun 9, 2026
Merged

robcohen merged 4 commits into
mainfrom
feat/cst-phase-4-2-format-compat

Conversation

@robcohen

@robcohen robcohen commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

Phase 4.2 of the CST migration (#1262) — the format-compat regression suite that pins the formatter's promise on every historical destructive-formatting bug class with file-pair golden fixtures.

  • 30 fixtures across crates/rustledger-parser/tests/format_compat/cases/, each a (input.bean, expected.bean) pair the harness validates byte-for-byte.
  • Runtime-walking harness in tests/format_compat.rs asserts three properties per fixture: format_source(input) == expected, idempotence (format_source(expected) == expected), and parseability (parse(expected).errors.is_empty()).
  • MIN_FIXTURES = 24 coverage floor — a contributor deleting cases by accident fails CI instead of silently dropping the regression net.
  • Bootstrap example (examples/bootstrap_format_compat.rs) authors expected.bean from format_source(input.bean); refuses to overwrite without BOOTSTRAP_OVERWRITE=1 so a stray re-run can't silently re-baseline a fixture whose expected output was hand-edited to pin a deliberate canonical-form choice.

The file-pair shape complements the inline IDEMPOTENCE_MATRIX in cst::format::tests:

  • IDEMPOTENCE_MATRIX pins per-rule canonical-form behavior via property-style tests. Hand-edited in code review.
  • tests/format_compat/cases/ is the user-facing contract surface — browse the directory to see what rledger format promises on a given input. Reviewers can read input/expected side by side without running the test runner.

Coverage

Bug classes covered:

Class Fixtures
#1252 destructive-formatting reproducer issue_1252_destructive_repro
Trailing-comment preservation (round-7 / Copilot #1) trailing_comment_on_directive_header, trailing_comment_eof_no_newline, posting_trailing_comment
Sign preservation in BALANCE / PRICE (round-7 / Copilot #2) balance_leading_unary_minus_preserves_sign, balance_leading_parenthesized_expression, price_leading_unary_minus_preserves_sign, posting_arithmetic_with_parens
{# ... } marker preservation (Copilot #3 false-alarm) cost_spec_per_unit_plus_total_marker
Cost-spec interior canonical form cost_spec_with_negative_amount, cost_spec_with_comma_and_date
Pragma directive round-trip pushtag_poptag_pair_preserved, pushmeta_popmeta_pair_preserved
Tag/link source-order rule transaction_tags_and_links_source_order
Unicode + multi-line string interior multiline_note_string_preserved, non_latin_account_names
Inter-directive comment positioning section_header_comments_tight, comment_with_unbalanced_quote
Metadata value canonical form metadata_unary_minus_value, metadata_arithmetic_value
File-level whitespace canonicalization multiple_trailing_blank_lines_collapsed, missing_final_newline_added, bom_dropped
CRLF / line-ending rule crlf_outside_strings_folded, crlf_inside_strings_preserved
Per-directive shape pins balance_assertion_with_metadata, transaction_with_pending_flag, custom_directive_with_date_value, document_with_tags_and_links, options_includes_plugins_block

Test plan

  • cargo test -p rustledger-parser — 230+ tests pass including the new format_compat integration test
  • cargo clippy -p rustledger-parser --all-features --all-targets -- -D warnings — clean
  • RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser --no-deps — clean
  • cargo fmt --all -- --check — clean
  • CI green across the workspace

Refs #1262.

🤖 Generated with Claude Code

…ve-formatting fixtures

Phase 4.2 of the CST migration: pin the formatter's promise on every
historical destructive-formatting bug class with file-pair golden
fixtures (input.bean / expected.bean) and a runtime-walking harness.

The file-pair shape complements the inline IDEMPOTENCE_MATRIX in
crates/rustledger-parser/src/cst/format.rs::tests:

- IDEMPOTENCE_MATRIX pins per-rule canonical-form behavior via
  property-style tests (idempotence, lexer agreement, round-trip
  through canonicalize_directives). Hand-edited in code review.

- tests/format_compat/cases/ is the user-facing contract surface.
  Browse the directory to see what rledger format promises on a
  given input. Reviewers can read input.bean and expected.bean side
  by side without running the test runner.

Both layers are load-bearing. The file-pair layer is the one
external users will read when they want to understand what the
formatter will do to their file.

## Coverage

30 fixtures across the bug classes that have caused destructive
formatting historically:

- issue_1252_destructive_repro — full reproducer from lutzky's
  issue. Pins the trailing-comment, pushtag/poptag, and
  cross-directive-tag-migration fixes from PR #1284.
- trailing_comment_on_directive_header, trailing_comment_eof_no_newline,
  posting_trailing_comment — the trailing-comment preservation
  rule from PR #1284 round-7 (Copilot #1).
- balance_leading_unary_minus_preserves_sign,
  balance_leading_parenthesized_expression,
  price_leading_unary_minus_preserves_sign,
  posting_arithmetic_with_parens — the sign-preservation rule
  from PR #1284 round-7 (Copilot #2).
- cost_spec_per_unit_plus_total_marker — pins the {# ... } marker
  preservation (Copilot #3 false-alarm).
- cost_spec_with_negative_amount, cost_spec_with_comma_and_date —
  cost-spec interior canonical form.
- pushtag_poptag_pair_preserved, pushmeta_popmeta_pair_preserved —
  pragma directives survive a round-trip.
- transaction_tags_and_links_source_order — source-order rule on
  transaction headers.
- multiline_note_string_preserved, non_latin_account_names —
  Unicode and multi-line string interior preservation.
- section_header_comments_tight, comment_with_unbalanced_quote —
  inter-directive comment positioning and state-machine
  agreement on stray quotes.
- metadata_unary_minus_value, metadata_arithmetic_value —
  metadata value canonical form.
- multiple_trailing_blank_lines_collapsed, missing_final_newline_added,
  bom_dropped — file-level whitespace canonicalization.
- crlf_outside_strings_folded, crlf_inside_strings_preserved —
  CRLF line-ending rule.
- balance_assertion_with_metadata, transaction_with_pending_flag,
  custom_directive_with_date_value, document_with_tags_and_links,
  options_includes_plugins_block — per-directive shape pins.

## Harness

tests/format_compat.rs walks tests/format_compat/cases/ at runtime
and asserts three properties per fixture:

1. format_source(input) == expected — the byte-exact contract.
2. format_source(expected) == expected — idempotence: re-formatting
   canonical text is a no-op.
3. parse(expected).errors is empty — the canonical output is itself
   parseable.

Asserts MIN_FIXTURES = 24 as a coverage floor so a future
contributor deleting cases by accident fails CI instead of
silently dropping the regression net.

## Authoring

A new fixture is two files: input.bean (what the user typed) and
expected.bean (what the formatter promises). The
bootstrap_format_compat example reads input.bean for every case
and writes expected.bean by running format_source on it. After
the initial bootstrap, expected.bean is the golden contract; the
example refuses to overwrite unless BOOTSTRAP_OVERWRITE=1 is set,
which keeps a stray re-run from silently re-baselining a fixture
whose expected output was hand-edited to pin a deliberate
canonical-form choice.

## Verified

- cargo test -p rustledger-parser — all 230+ tests pass including
  the new format_compat test
- cargo clippy -p rustledger-parser --all-features --all-targets
  -- -D warnings — clean
- RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser --no-deps
  — clean

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner June 9, 2026 18:09
Copilot AI review requested due to automatic review settings June 9, 2026 18:09
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 33.1ms ± 1.9ms 25.3 MB
beancount 879.7ms ± 11.7ms 50.3 MB
Comparison 26.6x faster 2.0x less

vs main branch (2026-06-09)

Metric main this PR Change
Time 37.6ms 33.1ms -12.0% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “format-compat” regression suite in rustledger-parser to lock in formatter behavior across historically destructive-formatting cases as part of the CST migration (#1262), using file-pair golden fixtures that are easy to review and hard to accidentally delete without CI noticing.

Changes:

  • Introduces an integration test harness (tests/format_compat.rs) that discovers fixtures and asserts output match, idempotence, and parseability, with a minimum fixture-count floor.
  • Adds a bootstrap example (examples/bootstrap_format_compat.rs) to generate expected.bean from input.bean, with overwrite protection via BOOTSTRAP_OVERWRITE=1.
  • Adds 30 fixture directories under tests/format_compat/cases/, each containing input.bean / expected.bean, plus a README describing conventions.

Reviewed changes

Copilot reviewed 63 out of 63 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rustledger-parser/tests/format_compat/README.md Documents the format-compat fixture layout and contribution workflow.
crates/rustledger-parser/tests/format_compat.rs Integration test harness that walks fixtures and enforces formatting/idempotence/parseability invariants.
crates/rustledger-parser/examples/bootstrap_format_compat.rs One-shot bootstrap tool to generate/update expected.bean golden files.
crates/rustledger-parser/tests/format_compat/cases/balance_assertion_with_metadata/input.bean Golden fixture input for balance assertion metadata formatting.
crates/rustledger-parser/tests/format_compat/cases/balance_assertion_with_metadata/expected.bean Golden fixture expected output for balance assertion metadata formatting.
crates/rustledger-parser/tests/format_compat/cases/balance_leading_parenthesized_expression/input.bean Golden fixture input for balance parenthesized expression preservation.
crates/rustledger-parser/tests/format_compat/cases/balance_leading_parenthesized_expression/expected.bean Golden fixture expected output for balance parenthesized expression preservation.
crates/rustledger-parser/tests/format_compat/cases/balance_leading_unary_minus_preserves_sign/input.bean Golden fixture input for unary minus sign preservation in balance.
crates/rustledger-parser/tests/format_compat/cases/balance_leading_unary_minus_preserves_sign/expected.bean Golden fixture expected output for unary minus sign preservation in balance.
crates/rustledger-parser/tests/format_compat/cases/bom_dropped/input.bean Golden fixture input for BOM handling.
crates/rustledger-parser/tests/format_compat/cases/bom_dropped/expected.bean Golden fixture expected output for BOM stripping.
crates/rustledger-parser/tests/format_compat/cases/comment_with_unbalanced_quote/input.bean Golden fixture input for comment parsing/spacing with stray quotes.
crates/rustledger-parser/tests/format_compat/cases/comment_with_unbalanced_quote/expected.bean Golden fixture expected output for comment parsing/spacing with stray quotes.
crates/rustledger-parser/tests/format_compat/cases/cost_spec_per_unit_plus_total_marker/input.bean Golden fixture input for {# ... } cost marker preservation.
crates/rustledger-parser/tests/format_compat/cases/cost_spec_per_unit_plus_total_marker/expected.bean Golden fixture expected output for {# ... } cost marker preservation.
crates/rustledger-parser/tests/format_compat/cases/cost_spec_with_comma_and_date/input.bean Golden fixture input for cost spec comma/date canonicalization.
crates/rustledger-parser/tests/format_compat/cases/cost_spec_with_comma_and_date/expected.bean Golden fixture expected output for cost spec comma/date canonicalization.
crates/rustledger-parser/tests/format_compat/cases/cost_spec_with_negative_amount/input.bean Golden fixture input for negative cost-spec amount spacing.
crates/rustledger-parser/tests/format_compat/cases/cost_spec_with_negative_amount/expected.bean Golden fixture expected output for negative cost-spec amount spacing.
crates/rustledger-parser/tests/format_compat/cases/crlf_inside_strings_preserved/input.bean Golden fixture input for CRLF preservation inside strings.
crates/rustledger-parser/tests/format_compat/cases/crlf_inside_strings_preserved/expected.bean Golden fixture expected output for CRLF preservation inside strings.
crates/rustledger-parser/tests/format_compat/cases/crlf_outside_strings_folded/input.bean Golden fixture input for CRLF folding outside strings.
crates/rustledger-parser/tests/format_compat/cases/crlf_outside_strings_folded/expected.bean Golden fixture expected output for CRLF folding outside strings.
crates/rustledger-parser/tests/format_compat/cases/custom_directive_with_date_value/input.bean Golden fixture input for custom directive date-typed value retention.
crates/rustledger-parser/tests/format_compat/cases/custom_directive_with_date_value/expected.bean Golden fixture expected output for custom directive date-typed value retention.
crates/rustledger-parser/tests/format_compat/cases/document_with_tags_and_links/input.bean Golden fixture input for document directive tag/link handling.
crates/rustledger-parser/tests/format_compat/cases/document_with_tags_and_links/expected.bean Golden fixture expected output for document directive tag/link handling.
crates/rustledger-parser/tests/format_compat/cases/issue_1252_destructive_repro/input.bean Golden fixture input reproducing destructive-formatting behaviors from #1252.
crates/rustledger-parser/tests/format_compat/cases/issue_1252_destructive_repro/expected.bean Golden fixture expected output for #1252 reproducer canonical form.
crates/rustledger-parser/tests/format_compat/cases/metadata_arithmetic_value/input.bean Golden fixture input for metadata arithmetic value formatting.
crates/rustledger-parser/tests/format_compat/cases/metadata_arithmetic_value/expected.bean Golden fixture expected output for metadata arithmetic value formatting.
crates/rustledger-parser/tests/format_compat/cases/metadata_unary_minus_value/input.bean Golden fixture input for metadata unary minus formatting.
crates/rustledger-parser/tests/format_compat/cases/metadata_unary_minus_value/expected.bean Golden fixture expected output for metadata unary minus formatting.
crates/rustledger-parser/tests/format_compat/cases/missing_final_newline_added/input.bean Golden fixture input for missing-final-newline behavior.
crates/rustledger-parser/tests/format_compat/cases/missing_final_newline_added/expected.bean Golden fixture expected output for missing-final-newline behavior.
crates/rustledger-parser/tests/format_compat/cases/multiline_note_string_preserved/input.bean Golden fixture input for multiline string preservation.
crates/rustledger-parser/tests/format_compat/cases/multiline_note_string_preserved/expected.bean Golden fixture expected output for multiline string preservation.
crates/rustledger-parser/tests/format_compat/cases/multiple_trailing_blank_lines_collapsed/input.bean Golden fixture input for trailing blank line collapsing.
crates/rustledger-parser/tests/format_compat/cases/multiple_trailing_blank_lines_collapsed/expected.bean Golden fixture expected output for trailing blank line collapsing.
crates/rustledger-parser/tests/format_compat/cases/non_latin_account_names/input.bean Golden fixture input for unicode/non-Latin account name alignment.
crates/rustledger-parser/tests/format_compat/cases/non_latin_account_names/expected.bean Golden fixture expected output for unicode/non-Latin account name alignment.
crates/rustledger-parser/tests/format_compat/cases/options_includes_plugins_block/input.bean Golden fixture input for option/include/plugin block spacing.
crates/rustledger-parser/tests/format_compat/cases/options_includes_plugins_block/expected.bean Golden fixture expected output for option/include/plugin block spacing.
crates/rustledger-parser/tests/format_compat/cases/posting_arithmetic_with_parens/input.bean Golden fixture input for posting arithmetic/parens formatting.
crates/rustledger-parser/tests/format_compat/cases/posting_arithmetic_with_parens/expected.bean Golden fixture expected output for posting arithmetic/parens formatting.
crates/rustledger-parser/tests/format_compat/cases/posting_trailing_comment/input.bean Golden fixture input for posting trailing-comment preservation.
crates/rustledger-parser/tests/format_compat/cases/posting_trailing_comment/expected.bean Golden fixture expected output for posting trailing-comment preservation.
crates/rustledger-parser/tests/format_compat/cases/price_leading_unary_minus_preserves_sign/input.bean Golden fixture input for unary minus sign preservation in price.
crates/rustledger-parser/tests/format_compat/cases/price_leading_unary_minus_preserves_sign/expected.bean Golden fixture expected output for unary minus sign preservation in price.
crates/rustledger-parser/tests/format_compat/cases/pushmeta_popmeta_pair_preserved/input.bean Golden fixture input for pushmeta/popmeta round-trip.
crates/rustledger-parser/tests/format_compat/cases/pushmeta_popmeta_pair_preserved/expected.bean Golden fixture expected output for pushmeta/popmeta round-trip.
crates/rustledger-parser/tests/format_compat/cases/pushtag_poptag_pair_preserved/input.bean Golden fixture input for pushtag/poptag round-trip.
crates/rustledger-parser/tests/format_compat/cases/pushtag_poptag_pair_preserved/expected.bean Golden fixture expected output for pushtag/poptag round-trip.
crates/rustledger-parser/tests/format_compat/cases/section_header_comments_tight/input.bean Golden fixture input for section-header comment grouping.
crates/rustledger-parser/tests/format_compat/cases/section_header_comments_tight/expected.bean Golden fixture expected output for section-header comment grouping.
crates/rustledger-parser/tests/format_compat/cases/trailing_comment_eof_no_newline/input.bean Golden fixture input for trailing comment at EOF without newline.
crates/rustledger-parser/tests/format_compat/cases/trailing_comment_eof_no_newline/expected.bean Golden fixture expected output for trailing comment at EOF without newline.
crates/rustledger-parser/tests/format_compat/cases/trailing_comment_on_directive_header/input.bean Golden fixture input for directive-header trailing comment preservation.
crates/rustledger-parser/tests/format_compat/cases/trailing_comment_on_directive_header/expected.bean Golden fixture expected output for directive-header trailing comment preservation.
crates/rustledger-parser/tests/format_compat/cases/transaction_tags_and_links_source_order/input.bean Golden fixture input for tag/link source-order retention.
crates/rustledger-parser/tests/format_compat/cases/transaction_tags_and_links_source_order/expected.bean Golden fixture expected output for tag/link source-order retention.
crates/rustledger-parser/tests/format_compat/cases/transaction_with_pending_flag/input.bean Golden fixture input for pending (!) transaction flag formatting.
crates/rustledger-parser/tests/format_compat/cases/transaction_with_pending_flag/expected.bean Golden fixture expected output for pending (!) transaction flag formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 99%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen robcohen self-assigned this Jun 9, 2026
robcohen and others added 3 commits June 9, 2026 20:28
1. Stage-1 mismatch in format_compat.rs no longer `continue`s past
   the idempotence and parser-clean checks. All three stages run
   independently per fixture; a malformed expected.bean paired with
   a non-matching formatter output now surfaces both failures
   instead of hiding the unparsable golden file.

2. MIN_FIXTURES count floor (24 vs 30 actual) replaced with a
   REQUIRED_FIXTURES name-set. The count floor was too loose -
   six load-bearing fixtures could be silently deleted while
   passing CI. The name-set check forces removal of a critical
   bug-class fixture to be a deliberate, reviewable edit to the
   constant, not a silent disappearance from the cases directory.

3. Empty subdirectories no longer count toward the fixture set.
   The discovery filter requires each entry to actually contain
   input.bean, so a stray `mkdir` without a `git add` cannot mask
   coverage loss from a parallel deletion.

4. .gitattributes adds `crates/rustledger-parser/tests/format_compat/
   cases/**/*.bean -text` so a Windows contributor with
   core.autocrlf=true sees the CRLF-bearing fixtures
   (crlf_outside_strings_folded, crlf_inside_strings_preserved)
   byte-for-byte as committed. Without this, the literal \r bytes
   inside the in-string-CR fixture would be silently normalized on
   checkout and the test would either fail mysteriously or pass
   for the wrong reason.

5. README "Bump it when you add cases" rewritten to match the
   harness rustdoc: adding cases is free, only retiring a required
   fixture changes REQUIRED_FIXTURES.

6. issue_1252_destructive_repro narrative cleaned up. The previous
   input had load-bearing comments ("Commas should stay",
   "bean-format does not remove plus signs, neither should rledger
   format") that became passive-aggressive once the expected.bean
   pinned the opposite behavior. The fixture now pins ONLY the
   destructive-bug fixes (trailing comments, pushtag/poptag,
   cross-directive tag migration). The canonical-form choices on
   commas and unary `+` move to two dedicated fixtures:

   - commas_stripped_per_canonical_form
   - unary_plus_stripped_per_canonical_form

   These document the PR-4 decision explicitly and link the
   dispute back to #1252 in their input.bean comments. If the
   team later flips one of these choices, exactly one fixture's
   expected.bean changes - the historical destructive-bug pin
   stays stable.

7. posting_with_interleaved_metadata fixture added to cover the
   #1142 bug class (per-posting metadata interleaved between
   postings of the same transaction). The harness rustdoc claimed
   #1142 coverage but no fixture exercised the shape;
   balance_assertion_with_metadata only puts metadata on a balance
   directive, not interleaved between transaction postings.

8. README "what belongs here vs IDEMPOTENCE_MATRIX" section
   narrowed to acknowledge the overlap. Roughly half of the
   file-pair fixtures are reviewable mirrors of inline-matrix
   entries; the other half (issue_1252 repro, BOM, CRLF, pragma
   blocks, canonical-form-choice fixtures, posting-interleaved-
   metadata) are genuinely-new coverage shapes that don't fit the
   inline-string format ergonomically. Both layers are kept, the
   file-pair layer is the user-facing contract surface.

9. escape_for_diff no longer pass-throughs non-`\n\r\t` control
   bytes. NUL / BEL / VT / FF / DEL now render via
   `char::escape_debug` as visible escape sequences, so a fixture
   mismatch whose only delta is a stray control byte renders
   visibly in the failure output instead of looking byte-identical
   to the maintainer.

10. Bootstrap example gains BOOTSTRAP_FIXTURE=<name> for scoped
    re-baselining. The default (no env vars) skips fixtures with
    existing expected.bean. BOOTSTRAP_FIXTURE rewrites exactly
    one named fixture; an unknown name exits non-zero before
    touching any file. BOOTSTRAP_OVERWRITE=1 still rewrites the
    whole suite but the summary line warns to review `git diff`
    carefully before committing. The previous shape made
    BOOTSTRAP_OVERWRITE=1 the only way to re-baseline ANY fixture,
    which silently rebaselines unrelated golden files.

Verified: cargo test -p rustledger-parser (230+ tests including
the new format_compat shape), cargo clippy -p rustledger-parser
--all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings
cargo doc -p rustledger-parser --no-deps. All clean. The harness
also passes with a bogus empty subdir present in cases/ (filter
confirmed).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replace `filter_map(Result::ok)` in the format-compat harness and the
bootstrap example with explicit `unwrap_or_else(|e| panic!(...))` on
each `read_dir` entry. Per-entry errors now panic with a diagnostic
instead of being silently dropped, matching the convention in
`tests/baseline_common::walk`.

The previous shape was a recall hole. If a permission or filesystem
fault hit one fixture directory (e.g. a stale `.partial` upload from
a backup tool, an inaccessible sub-tree on a CI runner), the entry
would be discarded with no diagnostic. The harness would still
pass the count floor and the bootstrap would print "wrote N files"
as if the run was complete, hiding the silent coverage drop.

Copilot's third comment (about missing `.gitattributes` rule for the
CRLF fixtures) was already addressed in the round-1 review fixes
(commit 30adb81). The bot's review fired against the pre-fix
commit; that finding is moot.

Verified: cargo test -p rustledger-parser --test format_compat,
cargo clippy -p rustledger-parser --all-features --all-targets
-- -D warnings. All clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1. escape_for_diff now routes everything outside ASCII-printable
   through `char::escape_debug`, which renders BOM (U+FEFF), zero-
   width spaces (U+200B..=U+200D, U+2060), C1 controls
   (U+0080..=U+009F), and other format-category codepoints as
   visible `\u{...}` escapes. The previous shape passed those bytes
   through verbatim, so a regression that stopped stripping the
   BOM would have rendered `--- expected ---` and `--- got ---`
   panels byte-identical to the eye - undermining the bom_dropped
   fixture's whole purpose. Printable non-ASCII Unicode (Cyrillic,
   CJK, Greek, etc.) still passes through unchanged because
   escape_debug preserves printable categories.

2. `present_names` is now built via `to_string_lossy().into_owned()`
   instead of `.to_str().map(String::from)`. The previous shape
   silently dropped non-UTF-8 directory names from the set, so a
   present-but-non-UTF-8-named REQUIRED fixture would have been
   falsely reported as missing. Aligns with the bootstrap example's
   name-extraction policy.

3. REQUIRED_FIXTURES check now runs against the RAW directory
   listing (every subdir), not the filtered-for-input.bean set.
   A required fixture whose directory exists but is missing
   input.bean now surfaces as `[name] missing input.bean` in the
   per-fixture failure log, not as the misleading "required
   fixture missing from cases dir" assert. The two failure shapes
   correspond to two distinct contributor mistakes (forgot to
   create the dir vs. forgot to `git add` the input file); the
   error message now disambiguates them.

4. Bootstrap summary branch order swapped: target_fixture is
   checked BEFORE overwrite_all, so the combined
   `BOOTSTRAP_OVERWRITE=1 BOOTSTRAP_FIXTURE=<name>` invocation
   prints "only the named fixture's expected.bean was rewritten"
   instead of the previous misleading "rewritten across the whole
   suite". The actual write behavior was already correct; only
   the summary line was lying.

5. MIRROR_PAIRS constant added to tests/format_compat.rs listing
   17 (file_pair_name, matrix_name) bug-class twins across the
   file-pair suite and the inline IDEMPOTENCE_MATRIX. The
   integration test asserts every file_pair_name exists as a
   directory under cases/. A new inline unit test
   `idempotence_matrix_mirrors_format_compat_pairs` in
   cst::format::tests asserts every matrix_name exists in
   IDEMPOTENCE_MATRIX. A one-sided deletion now requires editing
   both lists (or fails CI on the unedited side), enforcing the
   "two audience" coverage coupling the README's split design
   previously left as documentation-only.

6. REQUIRED_FIXTURES grew from 20 to 25 entries. Promoted from
   non-required:
   - multiline_note_string_preserved (string-literal interior
     preservation, classic destructive-formatting class)
   - balance_assertion_with_metadata (per-directive metadata
     attachment, sibling of #1142)
   - transaction_tags_and_links_source_order (tag/link ordering
     preservation, sibling of #1252)
   - metadata_unary_minus_value (sign preservation on metadata
     values)
   - non_latin_account_names (Unicode column-alignment correctness)

   Each was identifiably load-bearing for a regression class but
   could previously be deleted without tripping the floor check.

7. Stale rustdoc on `canonicalize_directives` in cst/format.rs
   disambiguated. The reference to "the deleted format_compat
   test" was ambiguous now that PR #1292 reintroduces a
   format_compat test in a different crate. Rustdoc now names
   the OLD test (crates/rustledger/tests/format_compat.rs,
   deleted in phase 4.1) explicitly and clarifies the new
   file-pair suite does NOT exercise canonicalize_directives'
   reparse-error path.

8. Stages 2 and 3 of the harness now run inside `catch_unwind`.
   A panic in format_source or parse on a pathological expected
   no longer aborts the entire test and discards the stage-1
   failures recorded for earlier fixtures in the same loop. The
   panic is recorded as a per-fixture failure with a clear
   message ("format_source is contracted to be total over
   arbitrary input; this is a bug") so the contributor knows
   the regression is in the formatter, not the fixture.

9. Bootstrap's BOOTSTRAP_FIXTURE validation now requires the
   target fixture's input.bean to exist before allowing any I/O.
   The previous shape exited 0 with "wrote 0, missing input 1"
   on a BOOTSTRAP_FIXTURE=name where `cases/name/` was an empty
   directory (no input.bean), which a contributor could misread
   as "bootstrap succeeded". The new check exits with code 3 and
   a clear "directory has no input.bean" message. Distinct from
   the existing code 2 "directory does not exist" path.

10. issue_1252_destructive_repro/input.bean now opens with a
    cross-reference comment pointing forward to the
    commas_stripped and unary_plus_stripped sibling fixtures.
    A reviewer auditing the #1252 fixture no longer reads the
    `commas_stripped/input.bean` claim that "the dispute is
    tracked in #1252" and then finds zero comma cases in the
    #1252 fixture itself.

Verified: cargo test -p rustledger-parser (231+ tests; new
idempotence_matrix_mirrors_format_compat_pairs unit test green),
cargo clippy -p rustledger-parser --all-features --all-targets
-- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc
-p rustledger-parser --no-deps. All clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen enabled auto-merge (squash) June 9, 2026 18:53
@robcohen
robcohen merged commit 49df439 into main Jun 9, 2026
39 of 40 checks passed
@robcohen
robcohen deleted the feat/cst-phase-4-2-format-compat branch June 9, 2026 18:54
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.

2 participants