Skip to content

fix(ffi)!: report option errors, and validate file loads as rledger check does - #2946

Merged
robcohen merged 19 commits into
mainfrom
fix/ffi-option-and-file-errors
Nov 12, 2026
Merged

robcohen merged 19 commits into
mainfrom
fix/ffi-option-and-file-errors

Conversation

@robcohen

@robcohen robcohen commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

What changed

#2929: the FFI reports option errors.

  • rustledger_loader::option_warnings_to_errors (new) is the one mapping from OptionWarning to LedgerError. The WASM helper of the same name now delegates to it, and its output is unchanged.
  • rustledger_ffi_wasi::helpers::{LoadResult, FileLoad} gain a separate, non-gating option_errors list. The component appends it to the outgoing errors last, after the host's plugins and validation have run. This applies to load, load-file, validate, validate-file, a session's info(), and batch / batch-file loads.
  • Effects of keeping option errors out of errors:
    • an invalid option no longer skips semantic validation;
    • session plugins still run;
    • parse-error-count does not count option errors.
  • valid and the apply_plugins gate now go by severity (Error::is_error). This fixes two older bugs:
    • a ledger plugin's warning skipped every host plugin;
    • valid was false when the only diagnostic was a warning.
  • Query results list the option diagnostics, as WASM query does. They no longer also list the booking-method refusal beside its E7002, per the Ledger::query_refusal doc. The session's private query_refusal field is gone; query_refusal on the ffi-wasi structs remains for the query gate.

#2935: multi-file FFI.

  • load_file_with_fs takes validate. load-file and validate-file validate through the canonical pipeline: process with validate: true, so Early runs before booking and Late after the ledger's plugins, with build_validation_options over validation_options_from_options.
  • validate-file resolves includes, confined to the ledger's tree as query-file confines them. It used to read the entry file's text and validate it as one source.
  • LedgerError::is_validation_finding (new) separates the validator's findings into FileLoad::validation_errors. That keeps them out of the host-plugin gate, so a failed balance does not stop host plugins.
  • Each finding keeps its own file and line.
  • The source-text span-to-line mapping (convert.rs, semantic_validation_errors) now maps a span only when its file id is 0, as WASM does. Before, a check_closing balance landed on line 1 of the text.
  • rustledger_ffi_wasi::Error gains code and file, which the component carries as the WIT 4.0.0 error record's code and filename.

WIT contract: see Review round 1 below (now rustledger:[email protected], a record shape change).

Caches: the loader cache does not move. The WASM cache moves to v105 in review round 3 (both cached ledgers archive what a query lists); see "Review round 3" below.

Why

Fava and beancount's loader report option errors, and the FFI dropped them. Also, rledger check and WASM fromFiles report validation errors on multi-file ledgers, but the component's file surfaces reported none.

Known differences from rledger check

  • Host plugins run after the pipeline, so validation does not see their output. check --plugin runs plugins inside the pipeline.
  • check hides the advisory-only E1004; the FFI still reports it, as before.

How to test

  • Drift guard: crates/rustledger/tests/ffi_check_parity/cases.rs pins one list of diagnostics (codes, severities, messages, files and lines). It covers a multi-file ledger and a single-file ledger, each with a balance failure (E2001, in the included file in the multi-file case), a padded cost lot (E2005), booking_method "fifo", name_equity "x" and a duplicate title. Three tests check against it:
    • cargo test -p rustledger --test ffi_check_parity_test checks rledger check --format json.
    • cargo test -p rustledger-ffi-component check_parity checks load, load-file, validate and validate-file natively, and compares codes and files on the ffi-wasi errors. The same module also checks:
      • session plugins and load-file plugins still run when option errors are present;
      • a ledger plugin's warning (rename_accounts) no longer skips host plugins, and a warning alone leaves valid true;
      • a plugin-made directive's finding maps to no source line.
    • cargo build -p rustledger-ffi-component --target wasm32-wasip2 && cargo test -p rustledger-ffi-component-tests runs the four surfaces through the built component.
  • Other tests:
    • cargo test -p rustledger-loader --lib option_errors_tests covers the canonical mapping and is_validation_finding.
    • cargo test -p rustledger-ffi-wasi covers the severity gate in apply_plugins.
  • CI coverage: since ci: run Test and Doctests over every workspace member #2965 (which fixed ci: Test and Doctests jobs skip rustledger-wasm and the FFI crates #2963) CI's Test job runs --workspace, so the native drift guards above (the rustledger-ffi-component and rustledger-ffi-wasi tests, and rustledger-wasm's native tests such as parse_error_mapping_parity) run in CI, alongside the built-component parity tests (Component Parity job), wasm-pack test --node (WASM job) and ffi_check_parity_test.
  • I mutation-checked the gate test and the file-id test: each fails on the old code.
  • Gates run locally:
    • fmt;
    • clippy --all-features --all-targets -D warnings;
    • RUSTDOCFLAGS=-Dwarnings cargo doc;
    • tests for loader, wasm, ffi-wasi, ffi-component and ffi-component-tests;
    • wasm-pack test --node.

Review round 1

This round built on #2945 (since merged as 526f833). It uses #2945's canonical rustledger_loader::option_warnings_to_errors, which locates every option diagnostic; this PR has no copy of its own.

  1. Query refusal restored. New loader canonical: Ledger::query_option_errors. It returns the option diagnostics with the rejected booking_method's E7002 replaced by query_refusal.
    • query, query-file, session.query (from source and from a file), and batch / batch-file list the refusal, and not the plain E7002. For batch, the refusal follows BATCH_REFUSED, and that doc is fixed.
    • load, info() and the batch load keep the plain E7002.
    • ffi-wasi gains query_option_errors on LoadResult and FileLoad.
    • Pinned by check_parity::test_query_surfaces_list_the_booking_method_refusal, which covers all of those surfaces and asserts the refusal is at the option's line. Also pinned by the loader test test_query_option_errors_replaces_the_refused_e7002.
  2. WIT error gains code: option<string> and filename: option<string>.
    • Package is now rustledger:[email protected], API_VERSION is 4.0, and the AGENTS.md, architecture and integration docs plus the ci.yml comment cite @4.x.
    • filename is set for every located error:
      • option diagnostics;
      • findings in an included file (that file's own path);
      • source text (the name given to load, else <string> for validate);
      • a plugin's placeholder location.
    • The drift guard compares code, severity, file, line and message directly on the WIT record: natively, and through the built wasip2 component.
    • CHANGELOG: the stale 3.19 claims are corrected, and the WIT change is listed under Breaking.
    • No rustfava checkout exists next to this repo, so the rustfava change is drafted at /home/user/Documents/my-projects/rustledger-review-drafts/rustfava-wit4-change.md. It covers:
      • the _WIT_VERSION and SUPPORTED_API_MAJOR bump;
      • err.get("filename") or filename, because the field is present-but-None when an error has no location.
  3. Unrun plugins. rledger check does not skip or demote validation when a declared plugin is not run. With plugin "my_plugins.opener" (E8004) or plugin "no_such_plugin" (E8001), it still reports the E1001s beside the plugin error. The FFI now does the same, and this is documented at the partition in load_file_with_fs.
    • Shared case unresolved-plugin (E8001, the same in every build).
    • test_an_unrun_python_plugin_keeps_the_findings_as_check_does covers a Python plugin the component cannot run: E8005 in a build without Python, E8004 when the plugin is named by module.
    • Consequence: rustfava runs Python plugins itself and filters E8005, so it can see E1001s for accounts its Python plugin opens. This is noted in the draft.
  4. Vacuous predicate. The host-plugin tests now assert Missing Commodity directive for 'HOOL' exactly once (and 'USD' for the warning test). I checked two mutations, adding the option errors to the gate list before apply_plugins in load-file and in session.from-file. Both now fail the test.
  5. E1004.
  6. Located option diagnostics. OPTION_DIAGNOSTICS now carries real main.beancount lines (2, 3, 5). The CLI test runs check from the case directory with a relative entry. That way its no-location stand-in (the entry as given, line 1), which is now used only for the unresolved plugin, cannot be confused with a located diagnostic.
  7. Back-references. The file-id span rule in convert.rs (semantic_validation_errors) and in WASM validation_error_to_wasm now cite each other.

Caches: no archived payload changes: the WASM side has a comment only, and LedgerError is not cached. No numbers taken.

Gates run locally on this head:

  • fmt;
  • clippy --all-features --all-targets -D warnings;
  • RUSTDOCFLAGS=-Dwarnings cargo doc;
  • tests for loader, ffi-wasi and ffi-component;
  • the wasip2 build plus ffi-component-tests (31 passed, no skip);
  • the CLI ffi_check_parity_test;
  • wasm-pack test --node;
  • check-wit-version-bump.sh (3.18.0 -> 4.0.0) and check-wit-version-citations.sh.

Review round 2

Built on #2945's head at the time (3d52f7b741e); #2945 has since merged.

  1. Host-requested plugin errors keep code, file, line and severity. apply_plugins pushed Error::new(err.message), which dropped the plugin's source_file / line_number / severity and skipped the untrusted-text escaping.
    • The per-error mapping inside the loader's record_plugin_errors is now the public canonical rustledger_loader::plugin_error_to_ledger_error. record_plugin_errors and apply_plugins both go through it, and apply_plugins then goes through ledger_error_to_ffi.
    • apply_plugins gains a source_map argument (the load's), so a plugin's file resolves as it does for a declared plugin.
    • Drift test: check_parity::test_host_requested_plugin_errors_match_ledger_declared_ones runs leafonly declared in the ledger and requested by the host (load-file and session.from-file). It asserts the same (code, severity, line, message) rows, PLUGIN at line 2, with filename naming the file.
  2. Each parse error is reported with its code and location. Parse errors came out as one unlocated LOAD error (parse errors in <path>).
    • LoadResult::take_parse_errors is the same method, name and signature as in fix: validate after a parse error on every surface, as rledger check does #2952 (the hunk is identical), so the two PRs converge.
    • New canonical rustledger_loader::parse_errors_to_ledger_errors maps each parse error as rledger check reports it: P + kind code, phase parse, hint, and its file, line, column and span.
    • ffi-wasi's load_source and load_file_with_fs use both. load_file_with_fs now builds the loader itself (load / load_with_fs plus the take), then calls process, which validates what did parse, as check does.
    • load(src, "main.beancount") names the given file on parse errors too: every <string> location is rewritten to the embedder's name.
    • New shared case parse-error-in-include expects P0012 at inc.beancount:3 plus the main file's E2001. CheckParityCase::counts() derives the expected parse-error-count / validate-error-count, used natively and through the component.
  3. rustfava draft (rustledger-review-drafts/rustfava-wit4-change.md).
    • The errors loop in component_engine.py's _rewrite_guest_paths gains error["filename"] = to_host(error["filename"]) when it is set, and the docstring's list of path kinds gains the fourth.
    • It notes that ComponentSession.query returns _finalize_query_result(...) with no _rewrite_guest_paths, so a file session's query errors keep /work/ paths in filename and message.
    • Checked against rustfava main via gh api.
  4. Nits.
    • world.wit:
      • The error doc describes both behaviors for plugin-made directives: file surfaces give the placeholder name at the plugin's line, often 0, which is called out as the exception to 1-based; load / validate give no file and no line.
      • It names the source-text filenames per surface.
      • The version() example is "4.0".
    • batch names its source one way: query errors now say <stdin>, as its load and entries do (likewise a session from source). The query result rows' filename column is unchanged (<string>, as bean-query answers).
    • Stale comments are fixed in ffi-wasi/src/types/output.rs and the cases.rs header.
    • M2 is pinned by test_query_option_errors_replaces_the_e7002_at_the_refusals_site: main and an include both set booking_method "fifo"; the query lists the refusal at main:1 plus the include's plain E7002. Mutation-checked.
    • M11 is pinned: test_query_surfaces_list_the_booking_method_refusal asserts the refusal's phase (validate) and code on every query surface. Mutation-checked.
    • query_option_errors shares query_refusal_error's conversion (refusal_to_ffi) instead of re-deriving validate_phase.
  5. Test memory.
    • Every parity / corpus_parity test compiled the debug component from scratch on its own Engine, and check_parity_through_the_component did it once per case. With parallel test threads, that is what held 10-12 GB for 20+ minutes.
    • rustledger_ffi_component_tests::compiled_component() now compiles it once per test binary, under a lock, and hands out Engine / Component clones.
    • wasmtime and anyhow move to that crate's [dependencies].

Gates run locally on c9c3d95b6fe:

  • cargo fmt --all -- --check;
  • clippy --all-features --all-targets -D warnings;
  • RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps;
  • tests for loader, ffi-wasi, ffi-component and rustledger (--all-features, including ffi_check_parity_test);
  • the wasip2 component build plus ffi-component-tests (31 + 2 passed, no skip);
  • wasm-pack test --node in crates/rustledger-wasm;
  • check-wit-version-bump.sh (3.18.0 -> 4.0.0) and check-wit-version-citations.sh.

Merge of main (cba1fa0)

git merge origin/main (no rebase): #2945 (squash-merged as 526f833), #2947, #2950, #2939, #2942.

Caches: none move. The loader cache stores only the raw load (directives, options, plugins, files) of an error-free load, which this PR does not change; the new LedgerError field and the Ledger methods are not archived. This PR changes no WASM output (its WASM change is a comment), so the WASM cache stays at main's v99 and LOADER_CACHE_VERSION_PIN at 71. (Numbers held by open PRs: WASM 100 by #2931, 101 by #2952, 102 by #2944; loader 72 by #2931, 73 by #2944. This PR would have taken WASM 103 / loader 74; it takes neither.)

Gates on the merge: cargo fmt --all --check; clippy --all-features --all-targets -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps; cargo test --all-features for loader, validate, wasm, lsp, ffi-wasi, ffi-component and rustledger (including ffi_check_parity_test and every surface agreement test); the wasip2 build plus rustledger-ffi-component-tests (31 + 2 + 5 passed, no skip); wasm-pack test --node; check-wit-version-bump.sh (3.18.0 -> 4.0.0) and check-wit-version-citations.sh.

Review round 3

No correctness bug in what the PR changes. Findings and what was done:

  • F1 (canonical discipline): every WASM query surface now lists option diagnostics through Ledger::query_option_errors. Before, the free query and ParsedLedger.query listed the plain E7002 where the refusal belongs. queryMultiFile (query_with_filesystem) listed the refusal and no other option diagnostic. Ledger.query (multi-file) listed the plain E7002 too; it was not named in the review and is fixed the same way. ProcessedLedger gains query_option_errors and reported_query_errors(). ParsedLedger keeps query_option_errors beside option_errors, and Ledger keeps query_errors beside errors. getErrors and every reporting surface still list the plain E7002.
    • New drift guard: crates/rustledger-loader/tests/query_option_errors/cases.rs has three ledgers: a refused booking_method, an invalid one in an include, and both together. The cases compare code, message, file and line, in order, and whether the query answers. Three tests share them: query_option_errors_test.rs (the canonical itself), convert::query_option_parity (FFI query, session.query from source, query-file, session.query from a file), and wasm_query_option_errors.rs (WASM query, ParsedLedger.query, queryMultiFile and Ledger.query, the last two from cache too; runs under wasm-pack test --node).
    • WASM cache v105. Both payloads archive what a query lists (ParsedLedgerPayload::query_option_errors, LedgerPayload::query_errors), so the archived layout moved. One note in cache.rs. The loader cache does not move (main's v73).
    • Left open: a source that fails to parse. WASM's parse-error paths (load_and_book, and the refusal in query_with_filesystem) return before a Ledger exists. On such a source they list the plain option diagnostics or none, while the FFI lists the refusal. Both sides refuse the query; only the listed diagnostics differ. I narrowed the canonical's doc to sources that load and added paired comments at both WASM sites and the canonical, with a revisit condition. Follow-up: WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960.
  • F2 (pins):
    • column is now compared everywhere the parity rows are compared: check_parity::rows, parity.rs::check_rows and ffi_check_parity_test.rs. Adding it surfaced a real gap: load and validate gave validation findings a line and no column, where check gives column 1. semantic_validation_errors now locates a finding through SourceFile::line_col, as the loader's error_location does.
    • batch query errors are asserted to be named <stdin>, and so are the errors of a session.query from source.
    • The host-plugin test files now have a tab in their names. escape_untrusted_line would rewrite a name a plugin claims, so passing an empty SourceMap to apply_plugins would change the error's filename. Each of the two call sites (load-file, session.from-file) is pinned separately by mutation.
  • F3: paired cross-reference comments are added at parse_errors_to_ledger_errors and at check's inline JSON arm for parse errors, with a revisit condition. The parse-error-in-include case gains a second parse error, at column 26 after a two-byte Ü. That pins the character columns of both renderers against each other (column included, per F2).
  • F6: the option errors from session.from-entries (booking_method, tolerance_multiplier) now carry code E7002, the code the loader gives the same values. The tests assert it, the tolerance case against the loader's own code.

Mutations (one scratch copy, run one at a time, each restored afterwards). Every one was caught:

  • the file-surface column fill (ffi-wasi ledger_error_to_ffi);
  • the source-surface column;
  • the batch <stdin> naming;
  • the empty SourceMap at the load-file site, and separately at the session.from-file site;
  • the parse-error column in parse_errors_to_ledger_errors;
  • the parse-error column in check;
  • the held-option code;
  • the FFI's query_option_errors reverted to the plain list;
  • the loader canonical pushing the refusal instead of replacing the E7002;
  • WASM: free query back to reported_errors, queryMultiFile back to the refusal alone, ParsedLedger.query back to option_errors, Ledger.query back to errors, and each fromCache restoring the plain list.

Coordination with #2952

#2952 merges first; this PR merges second. After #2952 lands, this PR will git merge origin/main and:

  1. switch ffi-wasi load_source to parse_errors_to_ledger_errors, keeping parse_errors_of;
  2. take fix: validate after a parse error on every surface, as rledger check does #2952's removal of the parse gate in semantic_validation_errors;
  3. add a single-file parse-error case to CHECK_PARITY_CASES.

Caches, after #2944 merged into main (loader 73, WASM 102): #2952 holds WASM 103, #2931 loader 74 / WASM 104, and this PR takes WASM 105. The loader cache does not move here; 75 is this PR's if it ever needs one.

Merge of main (e9656dc)

git merge origin/main brings in #2944 (8773d67). One conflict, in crates/rustledger-wasm/src/cache.rs: main's v102 note is kept, and this PR's v105 note follows it. The CHANGELOG merged cleanly.

Gates on e9656dc, all passing:

  • cargo fmt --all --check;
  • scripts/check-sync-primitives.sh, check-unsafe-invariant.sh, check-uri-boundary.sh, check-plugin-test-quality.sh, check-hot-path-collections.sh, check-wit-version-citations.sh, and check-wit-version-bump.sh origin/main;
  • clippy --workspace --all-features --all-targets -D warnings;
  • RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps;
  • cargo test --all-features for loader (446 passed), validate (183), wasm (178), lsp (407), ffi-wasi (54), ffi-component (72) and rustledger (1310);
  • the wasip2 component build, then rustledger-ffi-component-tests --lib --tests (31 + 2 + 5 passed, no skip markers);
  • wasm-pack test --node.

Review round 4 (1182070)

  • Column test gap (medium), fixed. Every expected validation column in ffi_check_parity/cases.rs was 1, so a hardcoded e.column = Some(1) in semantic_validation_errors survived. New cases bom and bom-crlf: a BOM-prefixed entry file whose balance on line 1 gives E1001 and E2001 at 1:2, as rledger check --format json reports them. The mutation now fails test_source_surfaces_report_what_check_reports.
  • Canonical location (low), fixed. The loader's private error_location is now SourceMap::locate(file_id, offset). The loader's validation and booking errors, the FFI's semantic_validation_errors and the WASM surface all call it; the FFI keeps its own file-id-0 filter and its line_lookup fallback for a load with no source map.
  • WASM byte columns (low, pre-existing), fixed. validateSource, ParsedLedger.getErrors (fresh and from cache), parse and format counted columns in bytes, so a BOM put a line-1 finding at column 4 and an Ü put a parse error one column high, where validateMultiFile and check did not. Parse errors now go through the loader's LineIndex (parse_errors_to_wasm, built only when there is an error) and validation findings through SourceMap::locate on the load's own map. LineLookup::byte_to_line_col is removed; LineLookup keeps lines only. Contained: no layout change, and the WASM cache stays at this PR's 105 (its note now says the archived errors carry character columns). The paired file-id comments at both sites now say the location itself is shared. Tests: native test_error_columns_count_characters, and tests/wasm_error_columns.rs (BOM validation, and a parse error after Ü with and without a BOM, on every surface above plus validateMultiFile).
  • WIT doc. The error record's doc says column is 1-based in characters and 0 at a plugin placeholder on the file surfaces, and absent on the source-text surfaces. Doc only; still 4.0.0.
  • rustfava draft (local, not posted): notes that rustfava is at WIT 3.11, so the upgrade also brings 3.12 to 3.18; that the E8005 filter misses a Python plugin named by module, reported as E8004 (pre-existing); and that the source-text load now sets each error's filename to the name passed in.

Mutation: e.column = Some(1) in semantic_validation_errors: caught by the bom case (it survived round 3).

Gates on 1182070, all passing: cargo fmt --all --check; scripts/check-unsafe-invariant.sh, check-sync-primitives.sh, check-uri-boundary.sh, check-plugin-test-quality.sh, check-hot-path-collections.sh, check-slim-no-wasmtime.sh, check-wit-version-citations.sh, check-wit-version-bump.sh; clippy --workspace --all-features --all-targets -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps; cargo test --all-features for loader (446), validate (183), wasm (178), lsp (407), ffi-wasi (54), ffi-component (72) and rustledger (1310); the wasip2 component build, then rustledger-ffi-component-tests --lib --tests (31 + 2 + 5, no skip markers); wasm-pack test --node (including wasm_error_columns).

Merge of main with #2952 (68542c1)

git merge origin/main brings in #2952 (48fccee), which keeps loading past a parse error on every surface. Conflicts in ffi-wasi helpers.rs, surface_agreement/cases.rs, and wasm api.rs, cache.rs, helpers.rs and parsed_ledger.rs, resolved as planned:

  1. ffi-wasi load_source reports parse errors through parse_errors_to_ledger_errors (via parse_errors_of), with code, line and column. fix: validate after a parse error on every surface, as rledger check does #2952's per-error Error::new mapping is not kept.
  2. fix: validate after a parse error on every surface, as rledger check does #2952's removal of the parse gate in semantic_validation_errors is taken. The comments that described the gate (ledger_error_to_ffi, refusal_to_ffi, the fatal-load arm) now say why "parse" still matters: validate counts it in parse-error-count.
  3. CHECK_PARITY_CASES gains parse-error-single-file, so load and validate run a parse error too. It reports P0012 at 2:1 and the E2001 after it, as check does.
  4. WASM Ledger::from_file_map: query_errors is built after fix: validate after a parse error on every surface, as rledger check does #2952's errors = parse_errors; errors.extend(...), so Ledger.query lists the parse errors. The processing-error branch chains them into query_errors too. load_and_book combines fix: validate after a parse error on every surface, as rledger check does #2952's load with this PR's query_option_errors through the canonical. Its parse errors go through parse_errors_to_wasm, so their columns count characters.
  5. query_option_errors/cases.rs gains a parse_errors field and a refused-booking-method-with-parse-error case: a refused booking_method plus a bad line. It runs on the FFI's four query surfaces, WASM query, ParsedLedger.query (fresh and from cache) and Ledger.query (fresh and from cache), each listing P0012 and then the refusal. The canonical's own test compares the option errors alone (expected_option_errors). queryMultiFile skips this case: it refuses on a parse error before a Ledger exists, and that is issue WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960. WASM's multi-file surfaces prefix a parse error's message with its file, as validateMultiFile already did, so the WASM test expects the prefix there. That difference is noted in WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960.
  6. WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960 is narrowed to query_with_filesystem. Updated to match: the Ledger::query_option_errors doc, the ProcessedLedger::query_option_errors doc, the CHANGELOG fix(ffi): load() and validate() never report option errors such as E7002 #2929 entry, and WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960's title and body. load_and_book lost its WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960 comment when its early return was removed. The paired comment that remains is at query_with_filesystem.
  7. WASM cache: main's v103 note is kept, and this PR's v105 note follows it (now "a v103 blob"; v104 is still held by fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does #2931).
  8. load_errors_to_errors (from fix: validate after a parse error on every surface, as rledger check does #2952) is now pub instead of pub(crate), because clippy -D warnings (redundant_pub_crate) fails on it after the merge.

Mutations:

  • In from_file_map's success branch, build query_errors before the parse errors are added. Caught: Ledger.query then lists only the refusal.
  • The processing-error branch is not reachable. process never returns Err, so no test can catch a mutation there. It is resolved by reading the code.

Gates on 68542c1, all passing: cargo fmt --all --check; the eight scripts/check-*.sh listed above; clippy --workspace --all-features --all-targets -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps; cargo test --all-features for loader (449), validate (183), wasm (178), lsp (428), ffi-wasi (54), ffi-component (72) and rustledger (1310); the wasip2 component build, then rustledger-ffi-component-tests --lib --tests (5 + 2 + 31, no skip markers); wasm-pack test --node.

Review round 5 (c4090a4)

  1. A parse error alone refuses a query, pinned on every query surface. Mutating err.blocking_load = failure.blocks_queries() to false in parse_errors_to_ledger_errors survived everything, and the FFI query then answered over a ledger that failed to parse.
    • query_option_errors/cases.rs gains refused-by-parse-error-alone: a bad open and no option diagnostic, answers: false, P0012 at line 3. It runs on the canonical, the FFI's four query surfaces, and WASM query, ParsedLedger.query (fresh and from cache), Ledger.query (fresh and from cache) and queryMultiFile (which skips only a case with both a parse error and an option diagnostic, issue WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960).
    • rustledger-ffi-component-tests' query_short_circuits_on_parse_error gains the same ledger through the built component: P0012 at line 3 and no rows. Its old input (2024-01-01 oepn Assets:Cash) had nothing that parsed, so it gave no rows under the mutant either.
  2. WASM's file-id rule is pinned. test_a_plugin_directives_finding_maps_to_no_source_line in wasm helpers.rs is the counterpart of the FFI test of that name: check_closing's balance has no line, column, end or file.
  3. WASM end positions are pinned. wasm_error_columns.rs now checks end_line / end_column on every surface, and a native test does the same for parse_error_to_wasm and validation_error_to_wasm. A parse error ends just past the unexpected 10 (column 28 in characters, 29 in bytes). A finding on the balance directive ends at line 2, column 1, past its newline. validateMultiFile reports a finding through LedgerError, whose location is one point, so its end is null; the test pins that as it is.
  4. Nit: the comment glued to }, in cases.rs is on its own line; the file passes rustfmt --edition 2024 --check.
  5. One WASM parse-error mapping, with a drift guard against the loader's.
    • New parse_error_fields (wasm helpers.rs) maps message, P code, phase and hint once. parse_error_to_wasm and load_errors_to_errors both build on it; load_errors_to_errors no longer re-derives them. It reads ParseError::message(), as the loader and check do (the same text today; with_context is never called outside tests).
    • It is a deliberate copy of parse_errors_to_ledger_errors: WASM reports an end position, which LedgerError lacks, and its single-source surfaces have no LoadError or SourceMap. Paired comments at both sites name each other, with "revisit if LedgerError gains an end position".
    • Drift guard parse_error_mapping_parity: one source (a BOM, an Ü, four parse errors, one with a hint) through parse_errors_to_ledger_errors, load_errors_to_errors and parse_errors_to_wasm agrees on message, code, phase, hint, file, line and column.
  6. The path prefix is its own issue, WASM multi-file surfaces prefix parse error messages with the file path, unlike rledger check and the FFI #2961. WASM's multi-file surfaces prefix a parse error's message with its file, unlike rledger check and the FFI. WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960's body now points there instead of describing it, and load_errors_to_errors and wasm_query_option_errors.rs point at WASM multi-file surfaces prefix parse error messages with the file path, unlike rledger check and the FFI #2961. (The "noted in WASM queryMultiFile lists no option diagnostics on a source that fails to parse #2960" in the merge section above now means WASM multi-file surfaces prefix parse error messages with the file path, unlike rledger check and the FFI #2961.)
  7. The processing-error branches stay as they are: process never returns Err, so they are unreachable (see the merge section above).

Mutations, each run on its own and restored:

  • blocking_load = false in parse_errors_to_ledger_errors: caught by query_option_parity (FFI, native) and query_short_circuits_on_parse_error (built component). WASM does not call this function, so the WASM tests cannot catch it; they pin WASM's own refusal on the same case.
  • .filter(|_| true) in validation_error_to_wasm: caught by the new WASM file-id test.
  • End equals start in parse_error_to_wasm, in validation_error_to_wasm, and in load_errors_to_errors: each caught by wasm_error_columns under wasm-pack test --node. The first two are also caught natively.

Gates on c4090a4, all passing: cargo fmt --all --check (and rustfmt --edition 2024 --check on the include!d cases.rs); the eight scripts/check-*.sh listed above; clippy --workspace --all-features --all-targets -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps; cargo test --all-features for loader (449), validate (183), wasm (181), lsp (428), ffi-wasi (54), ffi-component (72) and rustledger (1310); the wasip2 component build, then rustledger-ffi-component-tests --lib --tests (5 + 2 + 31, no skip markers); wasm-pack test --node.

Merge of main with #2962 (9c05110)

#2962 made load_errors_to_errors pub, as this branch already had it, and added --workspace to CI's Check, Clippy and Documentation jobs. The one conflict was the doc comment above load_errors_to_errors; both sides kept.

Review round 6 (bd3ed4f)

No code defect found; text fixes only.

  1. Why WASM keeps its own parse-error mapping, restated. Round 5's paired comments (and items 3 and 5 of that section above) said a LedgerError has no end position. It has one: source_span and file_id carry it, and only ErrorLocation is a point. The comments at parse_error_fields (wasm helpers.rs) and parse_errors_to_ledger_errors (loader process.rs) now give the real reason: WASM's single-source surfaces (parse, format, validateSource) build no LoadError or SourceMap. The revisit condition is now "if those surfaces come to build a LoadError and SourceMap".
  2. New issue wasm: multi-file surfaces report null end positions and drop hints for loader findings #2964 (low priority, pre-existing). validateMultiFile and Ledger report null end_line / end_column for validation findings because From<LedgerError> for Error does not locate the end from source_span through the source map, and that conversion sets hint: None, dropping hints such as E8001's. Cited from both comments above, from the From impl in wasm types.rs, and from wasm_error_columns.rs, which pins the null ends until wasm: multi-file surfaces report null end positions and drop hints for loader findings #2964 is fixed.
  3. WASM multi-file surfaces prefix parse error messages with the file path, unlike rledger check and the FFI #2961's body now describes the current code (parse_error_fields(...), then err.message = format!(...)) and lists parse_error_mapping_parity as a second test that strips the prefix; the load_errors_to_errors comment names it too.
  4. This body: dropped the stale claim that the WIT record lacks code and file (WIT 4.0.0 has code and filename), and the stale "option diagnostics have no location" bullet under Known differences (they are located; the ffi_check_parity cases pin lines 2, 3 and 5). Added the CI coverage note under How to test (ci: Test and Doctests jobs skip rustledger-wasm and the FFI crates #2963, since fixed by ci: run Test and Doctests over every workspace member #2965).
  5. ffi_check_parity/cases.rs (an include!d file cargo fmt skips) is formatted with rustfmt --edition 2024: a chain from the fix: validate after a parse error on every surface, as rledger check does #2952 merge was over the chain width.

Gates on bd3ed4f, all passing: cargo fmt --all --check and rustfmt --edition 2024 --check on cases.rs; the eight scripts/check-*.sh listed above; clippy --workspace --all-features --all-targets -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --all-features --no-deps; cargo test --all-features for loader, validate, wasm, lsp, ffi-wasi, ffi-component and rustledger (2677 in all, the same per-crate counts as round 5); the wasip2 component build, then rustledger-ffi-component-tests --lib --tests (5 + 2 + 31, no skip markers); wasm-pack test --node.

Merge of main with #2965 (9666ed2)

#2965 (fixing #2963) makes CI's Test job run --workspace (except rustledger-ffi-component-tests, which has its own job) and Doctests --workspace, so this head is the first on which CI runs the native FFI and WASM drift guards. Only .github/workflows/ci.yml changed; no conflict.

Closes #2929
Closes #2935

🤖 Generated with Claude Code

…nd locate every option diagnostic

beancount parses each included file with its own Builder and fresh
options: every value an option's converter rejects is an error at the
included file's line (bean-check exits 1), and only the top-level file's
values are kept. rledger reported every included option as the E7009
warning, valid or not, and exited 0.

set_scoped_inner now reads an included non-accumulating option into a
scratch Options, keeps its diagnostics and drops the value. E7009 is left
for a value the converter accepts. An included name_* root still does
not root that file's own accounts (E1005), a deliberate deviation now
commented and pinned.

Every option diagnostic (E7001 to E7011) carries the option's file and
line: OptionWarning gains `site`, stamped by set_scoped_at, and E7006 /
E7010 are located from the applied values. rledger check (text, JSON, and
ag-rledger check through it), the LSP (diagnostic on the option line, in
the file it is in), WASM option_errors and multi-file Ledger errors read
it. WASM validateMultiFile now reports option diagnostics at all.

Drift guards pin check's JSON and text, the LSP's two paths and WASM's
two multi-file paths to the loader's sites. WASM cache v99; the loader
cache never stores a ledger with option diagnostics, so it stays at v69.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 11, 2026 07:56
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 52.4ms ± 0.8ms 826.2ms ± 4.6ms 15.8x 45.0 MB / 51.1 MB
investment 78.5ms ± 1.5ms 2989.3ms ± 30.2ms 38.1x 47.2 MB / 59.0 MB
fifo 75.5ms ± 0.7ms 14741.9ms ± 70.5ms 195.4x 49.2 MB / 58.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 51.2ms ± 0.6ms 52.4ms ± 0.8ms +2.3% ✅ within noise 45.2 MB → 45.0 MB (-0.4%)
investment 79.3ms ± 3.2ms 78.5ms ± 1.5ms -1.1% ✅ within noise 46.9 MB → 47.2 MB (+0.7%)
fifo 78.4ms ± 6.0ms 75.5ms ± 0.7ms -3.7% ✅ within noise 49.2 MB → 49.2 MB (+0.0%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.4ms, investment 1.6ms, fifo 2.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 826
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 Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.47343% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-loader/src/process.rs 85.41% 28 Missing ⚠️

📢 Thoughts on this report? Let us know!

…er's options off unrelated LSP buffers

Review round 1 of #2945.

- rustledger_loader::option_warnings_to_errors maps OptionWarning::site to
  LedgerError::location (column 1). rledger check, the LSP and WASM (via
  From<LedgerError>) read it; the WASM helper is a one-argument wrapper
  and single-source entry points drop the file with without_files.
- LSP: a buffer the ledger does not include gets its own options'
  diagnostics, never the ledger's drawn on its lines.
- LSP option range stops before a `; comment`; the live-buffer limitation
  is documented.
- Options::locate is by occurrence, so a repeated documents value is
  located at each of its lines.
- validate_with_filesystem reports option diagnostics beside a fatal load
  error or a processing failure.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 3 commits November 11, 2026 06:54
…eck does

The FFI component never reported a ledger's option diagnostics (E7001 to
E7011): ffi-wasi built `errors` from `ledger.errors` only. They now travel
in a separate, non-gating `option_errors` list on `LoadResult` and
`FileLoad`, mapped by `rustledger_loader::option_warnings_to_errors`, the
canonical function the WASM surface now calls too, and are appended to the
outgoing `errors` last, after the host's plugins and validation have run,
so an invalid option neither skips validation, nor stops session plugins,
nor counts in `parse-error-count`. `valid` and the host-plugin gate go by
severity, which fixes two older bugs: a ledger plugin's warning skipped the
host's plugins, and `valid` was false over a warning alone. Query results
list the option diagnostics, as the WASM query does, and so no longer list
the booking-method refusal beside its E7002 (#2929).

`load-file` reported no validation errors and `validate-file` validated the
entry file's text as one source. Both now validate through the canonical
pipeline (`load_file_with_fs(..., validate: true)`), and the validator's
findings, told apart by the new `LedgerError::is_validation_finding`, are
kept out of the host-plugin gate, so a failed balance does not stop the
host's plugins. Each finding keeps its own file and line. A source-text
finding maps to a line only when its span is in the text (file id 0), as
on WASM; a plugin directive's finding was mapped to an unrelated line
(#2935).

A drift guard pins `rledger check` and the component's `load`,
`load-file`, `validate` and `validate-file` to one list of diagnostics
(codes, messages, files and lines) on a multi-file and a single-file
ledger with a balance failure, a padded cost lot and invalid options, run
natively and through the built wasip2 component.

WIT contract rustledger:[email protected] (behavior only, no shape change).
No cache payload changes.

Closes #2929
Closes #2935

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review round 1 of #2946.

- The WIT `error` record gains `code` and `filename`, filled for every
  error with a location (an included file's own path, the name given to
  `load` for source text, a plugin's placeholder name), so a line can say
  which file it is in. A record change: package rustledger:[email protected],
  `API_VERSION` 4.0, docs cite @4.x.
- Query surfaces (`query`, `query-file`, `batch`, `batch-file`,
  `session.query`) list a rejected booking_method as the refusal again, in
  place of its plain E7002, through one loader canonical,
  `Ledger::query_option_errors`; `load` and `info()` keep the plain E7002.
- Option diagnostics come from #2945's located
  `option_warnings_to_errors` (this branch is rebased onto it), so they
  carry the option's file and line on every surface, and the drift guard
  pins those lines.
- Validation findings leave out the advisory-only E1004 on every surface,
  as `rledger check` does, and are kept beside an unrun plugin's error
  (E8001, E8004, E8005), as `check` keeps them.
- The host-plugin tests assert `check_commodity`'s exact finding, so the
  mutations that put option errors in the plugin gate fail them.
- The file-id span rule cites its WASM twin, and the WASM rule cites it.

No cache payload changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 4 commits November 11, 2026 10:20
…nd locate query's option diagnostics

Review round 2 of #2945.

- documents leaves ACCUMULATE_ACROSS_INCLUDES: beancount 3.2.3 keeps only
  the top-level file's (load_file gives documents == [] for an included
  root and bean-check exits 0 with it missing), so an included value is
  read by the scratch converter and ignored with E7009, never scanned or
  checked (no E7006).
- rledger query prints option diagnostics through the canonical mapping,
  with file and line; ag-rledger's query warnings carry them.
- WASM Ledger::from_file_map's processing-error arm keeps the option
  diagnostics, as validate_with_filesystem does.
- LSP option_error_file_id uses SourceFile::id.
- Tests pin site_of's last-line choice (E7010), without_locations
  clearing every site, and included documents.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…heck does

Review round 2 of #2946.

- A plugin the host asks for (`load-file`, `session.from-file`) reported
  its errors as a bare message: no code, file, line or severity, and its
  text unescaped. The loader's per-error mapping is now the public
  `rustledger_loader::plugin_error_to_ledger_error`, which
  `record_plugin_errors` and ffi-wasi's `apply_plugins` (which gains the
  load's `source_map`) both use. A drift test compares a host-requested
  and a ledger-declared `leafonly`.
- Parse errors were one line-less `parse errors in <path>`, an included
  file's too. `LoadResult::take_parse_errors` (the same method as #2952)
  takes them out before `process`, and the new
  `rustledger_loader::parse_errors_to_ledger_errors` reports each with its
  code, file, line and column, as `check` does. `load(src, name)` names
  the given file on them. New shared case `parse-error-in-include`.
- `batch` and a session from source name their errors `<stdin>`, as their
  entries, not the loader's `<string>`.
- `query_option_errors` shares `query_refusal_error`'s conversion.
- Pin the refusal's site match (an include repeating the main file's bad
  `booking_method` keeps its plain E7002) and the refusal's phase on
  every query surface; both mutation-checked.
- world.wit: both behaviors for a plugin-made directive's finding, line 0
  as the exception to 1-based, and the `version()` example is "4.0".
  Stale comments fixed in ffi-wasi `Error` and the parity cases.
- ffi-component-tests compile the component once per test binary
  (`compiled_component`). Every `parity` / `corpus_parity` test compiled
  the 93 MB debug component on its own `Engine`, the check-parity test once
  per case, many at once on parallel threads: the `parity` binary held
  10-12 GB for 20+ minutes. The crate's tests now take 26 s at 0.9 GB peak.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 11, 2026 22:06
#2945, which this branch carried, is squash-merged as 526f833; its
hunks take main's final form (loader cache v71, `escape_untrusted_text`
in `rledger query`, its CHANGELOG notes).

With #2947: the FFI's `semantic_validation_errors` keeps #2947's
`booking_refused` set-aside and its `is_advisory_only` filter, which
replaces this branch's equivalent one. `convert::surface_agreement` now
matches each finding's code too (the 4.0.0 wire error carries it) and
runs `validate-file` and `load-file` over the shared cases, so the file
surfaces are pinned to leave out E1004 and set a refused transaction
aside.

No cache moves: the loader cache stores only error-free raw loads, and
this branch changes no WASM output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ponent

CI's Sync Primitives check forbids std::sync locks in non-test library code
(#1076), and `compiled_component` lives in the crate's lib. Switch it to
parking_lot::Mutex (no poisoning, so the PoisonError recovery goes), end
the guard explicitly after the first compile, and split the doc's first
paragraph for clippy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen robcohen changed the title fix(ffi): report option errors, and validate file loads as rledger check does fix(ffi)!: report option errors, and validate file loads as rledger check does Nov 12, 2026
robcohen added a commit that referenced this pull request Nov 12, 2026
… the matrix's cause()

Review round 18 of #2931:

- The BOM guard of line-start-bom-before-comment is needed, not
  equivalent: beancount's EOL error for the line before can land on a
  skipped line start. Reword its comment and pin it on real counts.
- inner_boms_are_the_difference now checks the line has an inner BOM,
  as its doc says, and its test reads a real table row.
- Drop the unreachable BOM strip before poptag / popmeta, pin
  block_err's look past the indentation, and comment the remaining
  equivalent guards.
- Name only the real holders of the next cache versions in the loader
  and WASM cache notes (#2946 holds none).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 4 commits November 12, 2026 01:10
…lumns (#2946 review round 3)

- WASM query surfaces (free `query`, `ParsedLedger.query`,
  `queryMultiFile`, `Ledger.query`) list option diagnostics through
  `Ledger::query_option_errors`, as the FFI does: the rejected
  `booking_method`'s E7002 is the refusal. Shared drift guard
  `rustledger-loader/tests/query_option_errors/cases.rs` across the
  loader, the FFI and WASM. WASM cache v105 (both payloads archive
  what a query lists). A source that fails to parse still differs
  (#2960), documented at both sites.
- The check parity rows compare `column`; `load` and `validate` now
  give a validation finding its column, as `check` does. A mid-line
  parse error after a two-byte character pins character columns.
- Paired comments between `parse_errors_to_ledger_errors` and
  `check`'s inline parse-error arm.
- Pin `batch` errors named `<stdin>` and the host-plugin `source_map`
  argument (file names with a tab).
- `session.from-entries` option errors carry code E7002.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…WASM columns in characters (#2946 review round 4)

- loader: `SourceMap::locate(file_id, offset)` replaces the private
  `error_location`; the loader, the FFI component's validation findings and
  the WASM surface all locate through it.
- ffi-component: `semantic_validation_errors` calls `SourceMap::locate`
  instead of re-deriving it.
- check parity: BOM-prefixed cases (LF and CRLF) put a line-1 finding at
  column 2, so a hardcoded column 1 no longer passes.
- wasm: `validateSource`, `ParsedLedger.getErrors`, `parse` and `format`
  counted columns in bytes (4 after a BOM); parse errors now go through the
  loader's `LineIndex` and validation findings through `SourceMap::locate`.
  `LineLookup` keeps lines only. Native and wasm-bindgen tests pin a BOM and
  a multi-byte character before an error.
- WIT: the `error` record's doc says `column` is 1-based in characters and
  0 at a plugin placeholder (doc only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2952 keeps loading past a parse error on every surface. Resolved:

- ffi-wasi `load_source`: parse errors through
  `parse_errors_to_ledger_errors` (via `parse_errors_of`), with code,
  line and column; #2952's per-error `Error::new` mapping is not kept.
- ffi-component: #2952's removal of the parse gate in
  `semantic_validation_errors` is taken.
- wasm `load_and_book`: #2952's no-early-return load, with this PR's
  `query_option_errors` through the canonical, and the parse errors through
  `parse_errors_to_wasm` (character columns).
- wasm `Ledger::from_file_map`: `query_errors` is built after the parse
  errors are in `errors`, so `Ledger.query` lists them; the processing-error
  branch chains them too.
- wasm cache: main's v103 note kept, this PR's v105 after it.
- `load_errors_to_errors` is `pub` (clippy `redundant_pub_crate`).

Follow-ups in the same commit:

- `CHECK_PARITY_CASES` gains `parse-error-single-file`, so the source-text
  surfaces run a parse error too.
- `query_option_errors/cases.rs` gains `parse_errors` and a
  `refused-booking-method-with-parse-error` case, run by the FFI's query
  surfaces, WASM `query`, `ParsedLedger.query` and `Ledger.query`;
  `queryMultiFile` skips it (issue #2960).
- #2960 shrinks to `query_with_filesystem`: the `Ledger::query_option_errors`
  and `ProcessedLedger::query_option_errors` docs and the CHANGELOG say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…end positions, and map WASM parse errors once (#2946 review round 5)

- query_option_errors/cases.rs: new refused-by-parse-error-alone case
  (a parse error and no option diagnostic must refuse), run by the
  canonical, the FFI query surfaces and every WASM query surface,
  queryMultiFile included; the component's
  query_short_circuits_on_parse_error gains the same ledger. Moves a
  comment glued to `},` onto its own line.
- wasm: test_a_plugin_directives_finding_maps_to_no_source_line, the
  counterpart of the FFI test; end_line/end_column pinned natively and
  in wasm_error_columns on every surface.
- wasm: parse_error_fields maps a parse error's message, code, phase
  and hint once for parse_error_to_wasm and load_errors_to_errors, with
  paired comments against the loader's parse_errors_to_ledger_errors
  and a drift guard (parse_error_mapping_parity).
- The multi-file path prefix on parse error messages points at #2961.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 12, 2026 07:32
Conflict in crates/rustledger-wasm/src/api.rs: main made
load_errors_to_errors pub; this branch had added its doc comment.
Kept both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
 review round 6)

The paired comments at parse_error_fields and parse_errors_to_ledger_errors
said a LedgerError has no end position. It does: source_span and file_id
carry it; only ErrorLocation is a point. The copy exists because WASM's
single-source surfaces build no LoadError or SourceMap. The multi-file
surfaces report null ends for validation findings only because
From<LedgerError> for Error does not locate them, and that conversion also
drops the hint: both pre-existing, now issue #2964, cited from the
comments, the From impl and wasm_error_columns.rs. The revisit condition
is now "if the single-source surfaces come to build a LoadError".

The load_errors_to_errors comment also names parse_error_mapping_parity
as a test that strips the #2961 path prefix.

Formats the include!d ffi_check_parity/cases.rs with rustfmt (a chain
from the #2952 merge exceeded the chain width).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit d38898f into main Nov 12, 2026
73 of 74 checks passed
@robcohen
robcohen deleted the fix/ffi-option-and-file-errors branch November 12, 2026 17:41
robcohen added a commit that referenced this pull request Nov 13, 2026
… beancount does (#2931)

* fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does

A BOM-led lexer error kept its own extent wherever it stood, so a `"`,
`#!` or `#+` right after a mid-line BOM started a token of its own:
`<BOM>"x"` opened a string (kept as the narration), and `<BOM>#!d`,
`<BOM>#+x`, `<BOM><BOM>"x"` and `<BOM>abc` were two errors. beancount's
`<INVALID>[^ \t\n\r]+` reads each as one invalid token. The own extent
only matters at the start of a line, where it keeps a concatenated
file's next directive lexing, so the lexer now keeps it only there
(`at_line_start && span.start == last_newline_end`, in the `Err` arm),
and `error_later_in_run` no longer stops at a BOM after a lone capital.

The CST recovery treated every BOM-led error token as layout. Now only
one that starts its line is (`is_line_start_bom_token`, one look back at
the character before the token): `report_invalid_tokens_of_error_line`,
`quiet_after_invalid_tokens` and `holds_an_invalid_token` count a mid-line
BOM-led run as the invalid token it is, so `313<BOM>x` is two errors as in
bean-check. When the line's error is another one (an invalid account),
the secondary `BomInDirectiveBody` stands for the line's first BOM-led
token, which is not counted twice.

Parse-error parity: 78,306 of 111,323 inputs match beancount, from
78,225 (85 newly match, 4 regress on pre-existing causes: a stray
mid-line `\r` and an end-of-file grammar error, both of which the old
split BOM token happened to offset). Green and red agree on the whole
pinned fuzz corpus. Loader cache v70, WASM cache v93.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): report a BOM-led directive argument once, and let the secondary BOM error stand for either kind of BOM token

Review round 1 of #2931.

A BOM-led invalid token where a directive's argument or account belongs
(`price USD 1 <BOM>EUR`, `commodity <BOM>EUR`, `note Assets:A <BOM>"x"`,
`open <BOM>Assets:C`) gave the dropped directive's generic line error and
the token's inline `BomInDirectiveBody`: two errors, where main and
bean-check report one. `drop_errors_inside_a_line_error` now takes an
inline BOM error as an inner error too: when the header grammar first
fails at that token, the inner error is dropped and the line error takes
the BOM kind and hint, as an invalid token's generic error is merged
there already.

The secondary BOM error after another line error (an invalid account)
stands for the line's first token with a stray BOM, whether the BOM leads
it or sits inside it, so a later BOM-led token keeps its own error
(`Ü:A x<BOM>y <BOM>z` is three errors, as in bean-check).

Parse-error parity: 78,367 of 111,323 inputs match beancount (61 more
than round 0, no new regressions).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): report a BOM-led directive argument at the token, and count every other stray-BOM token after an invalid account

Review round 2 of #2931.

When the header grammar first fails at a BOM-led token, the token's own
`BomInDirectiveBody` is now the error kept, and the generic whole-node
error is dropped for it, so the error has the token's span (main reported
the BOM there too) rather than the directive's. The formatter still copies
the directive verbatim: the token lies inside its node.

After an invalid account, the secondary BOM error stands for one token
with a stray BOM in it; every other such token, BOM-led or with the BOM
inside it, has its own error, as in bean-check (`Ü:A <BOM>z x<BOM>y` is
three errors). A BOM that starts its line is skipped when finding the
line's first invalid token, so `<BOM>tApo` at the start of a line is the
one token the line error stands for, as in beancount.

Parse-error parity: 78,399 of 111,323 inputs match beancount (32 more
than round 1; the 2 inputs that no longer match have pre-existing causes).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): count a run with a BOM inside it once the line's BOM error stands for a line-start BOM, and pin every BOM combination against beancount

Review round 3 of #2931.

A BOM that starts its line keeps its own extent here, where beancount's
invalid token runs on through whatever is glued to it, so it is always the
line's first invalid token, the one the line error stands for. An invalid
run glued to it (`<BOM>foo`) is part of that token. A run that only
follows it (`<BOM>  k:`) is one more token, where round 2 took it as the
first: `<BOM>  k: Ü:A x<BOM>y0` lost the `k:` (bean-check 3, main 3,
round 2: 2). And once the line's BOM diagnostic stands for that BOM, a run
with a BOM inside it later on the line has its own error (`<BOM>foo x<BOM>y`
is two errors, as in bean-check and on main; round 2 gave one).

Each review round found another combination that drifted, so this adds a
guard. `scripts/bom-combination-matrix.py` records beancount 3.2.3's
per-line counts for every combination of up to three BOM-led, inner-BOM
and plain invalid tokens, with no prefix, a line-start BOM, or a
line-start BOM glued to a run, in nine line contexts (1,078 inputs), and
`tests/bom_combination_matrix.rs` checks rledger against it on both parse
paths. The 386 inputs that still differ are listed with their cause and
rledger's counts. All three causes predate #2928, and none of those
inputs is further from beancount than on main.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): re-pin one parity row whose first differing line moved

`e8844718a38e` stays a mismatch: its `<BOM>   Ra` line now matches
beancount (two invalid tokens), so its first differing line is a
pre-existing posting-line difference and its category changes.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): spend the BOM diagnostic on a BOM-led first token, take a line-start BOM's whole blank-free run as one token, and widen the BOM matrix

Review round 4 of #2931.

A BOM-led first token after a date or an indentation is the one the
line's error stands for, and that error is the BOM diagnostic, so a later
run with a BOM inside it has its own error (`2024-01-02 <BOM>a x<BOM>y`
is two errors, as in bean-check). On an indented line whose start
beancount reads, the token's own `BomInDirectiveBody` now stands for the
line's first error as the generic one does, so `  <BOM>a` and
`  <BOM>; c` are one and two errors, not two and three.

A BOM that starts its line is one beancount token with its whole
blank-free run, through tokens that lex here (`<BOM>12$`), so an invalid
token in that run is not counted again. The unread rest of a `<BOM>*`
heading line holds a blank and is still reported.

The BOM-combination matrix gains a date-alone context, a metadata line
under a header with no narration, a BOM after the indentation (glued to
a run and to a `;`), and two prefixes that glue a BOM through a valid
token to an invalid one: 2,598 inputs. Reverting each round-3 and
round-4 fix fails it. The known list names its four causes, with the
account cause corrected: it appears only after a line-start BOM.

Parse-error parity: 78,461 of 111,323 inputs match beancount (62 more,
no regressions).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): lex a BOM-led account as an account, count `A<BOM>b` and a `<BOM>*` heading's rest as beancount does, and add a seeded probe to the BOM matrix

Review round 5 of #2931.

Beancount's account type is `([A-Z]|{UTF-8-ONLY})...`, so a BOM glued to
an account shape (`<BOM>Assets:A`, `<BOM>Ü:A`, `<BOM>1:A`) is one ACCOUNT
there, and only its name is rejected, when the file loads. The account
token regex no longer excludes U+FEFF from the first character, so it is
one account here too, which the account-name check (`E1005`) rejects. A
line-start BOM's own extent is capped at the BOM, as logos may now scan
it into a failed account.

A lone capital glued to a BOM (`A<BOM>b`) counts as BOM-led, so it is
never left to the line's BOM diagnostic. After a `<BOM>*` heading start,
the part up to the first blank is the BOM's token, and each blank-free run
after it that beancount cannot read is one more error.

The BOM matrix gains a BOM-led account kind and a lone-capital kind, the
shapes the reviews found, and a seeded random probe of 2,000 inputs,
5,727 rows in all. Every row further from beancount than main is checked
against the same input without its BOMs on main and named as such.

Parse-error parity stays at 78,461 of 111,323.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): revert the BOM-led account token, keep a BOM run glued to an account as its own token, and keep BOM runs linear

Review round 6 of #2931.

Letting U+FEFF start `Token::Account` made a line of BOMs quadratic and
hid the BOM from the user (no `P0026`, no "Remove BOM" quick fix, a
BOM-led account offered for completion and `open`). The account token is
as on main again. Instead, a mid-line run of BOMs followed by an
account-shaped word (`logos_lexer::starts_with_account`, the lexer's own
account rule, read up to the next blank) keeps its own extent as a
line-start BOM does: it is the `P0026` the quick fix acts on, the account
lexes as one, and the error recovery counts the run as no invalid token,
as beancount reads it into the account.

Line-start BOMs stay one logos error each, a mid-line run is taken whole,
and the recovery's account lookahead stops at the next BOM, so long BOM
runs are linear end to end. `test_tokenize_long_bom_runs_are_linear`
counts the bytes scanned while lexing and parsing 1 MB of BOMs, and fails
on the quadratic versions.

The known list now names a cause for every differing line, from a rule
per cause, and unclosed `pushtag` / `pushmeta` errors are line 0 on both
sides, as in the parity harness.

Parse-error parity: 78,460 of 111,323 inputs match beancount.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): read BOMs into an account by beancount's account rule at every count site, keep line-start bookkeeping before an account, and commit the BOM matrix classifier

Review round 7 of #2931.

`logos_lexer::bom_led_account` decides whether a run of BOMs starts an
account as beancount does (a BOM may be an account's first character),
with the lexer's own account rule on the word with a non-ASCII stand-in
for the BOMs: `<BOM>assets:A`, `<BOM>1:A`, `<BOM>:A` are accounts too.
When an account of rledger's follows, the BOMs keep their own token
(P0026 and its quick fix, the account kept); otherwise the token ends
where beancount's account does. One predicate,
`is_bom_account_token`, now serves all four counting sites, the
heading-rest `invalid_runs` included. A line-start BOM run before an
account spends the BOM diagnostic and glues nothing after the account.

The matrix gains a BOM-led account beancount reads only with its BOM, a
glued tail after an account, and two line-start BOMs before every token,
and records main's counts and the BOM-free analog's, so the test itself
classifies each differing line (`cause`, one rule per cause) and checks
the known list against it; `BOM_MATRIX_UPDATE=1` rewrites the list.

The linearity guard gains a wall-clock bound that a lookahead the byte
counters miss fails, and the LSP's grouped quick fix says "BOMs", not
"BOM bytes".

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): count the tail after a line-start BOM's account as beancount does, and refuse any BOM-matrix line further from beancount than main unless accepted by hand

Review round 8 of #2931.

A line-start BOM run followed by an account beancount reads only with
its BOM (`<BOM>assets:A$x`, `<BOM>1:A$x`) glued nothing after the
account, so its tail's error was lost. The run's account now ends at
`bom_led_account`'s end: tokens before it are part of it, and the part
of a token past it is beancount's next token, counted when it lexes as
an invalid one (`$x`, `.b`), not when it lexes (`"x"`, `#t`, `;c`).
Errors that start inside an error token are the lexer's own in
`quiet_after_invalid_tokens`.

The BOM matrix test now fails on any line rledger counts further from
beancount than main unless `bom_combination_matrix_worse_than_main.tsv`,
kept by hand and never written by `BOM_MATRIX_UPDATE`, lists it with a
cause the test checks: the BOM-free analog for `like-main-without-bom`,
a standalone match for a recovery cause, and the same difference alone
for a line's own cause. All six of the reviewer's mutations of the
BOM-account predicate now fail, the lexer one through a unit test that
pins the kept account, and the metadata site through a new booking
method test. The linearity guard's wall-clock backstop is 30 s.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): bound the BOM-led account lookahead and count BOM line tails as beancount does

Review round 9 of the mid-line BOM run fix.

- bom_led_account reads only the characters an account can hold, so a
  line of BOM-led runs is linear again; the linearity guard covers the
  three new run shapes.
- A comment ends the tail of a BOM-led account; on a line that starts
  with a BOM, an account inside an invalid token is no extra error. The
  token is masked byte for byte, so a BOM-glued account is not split
  off and a partly masked account is reported as written.
- The BOM combination matrix gains account tails and a heading context,
  checks the mid-line hash-bang cause against its analog, folds in the
  account probe, and requires an accepted line's cause to be the cause
  the classifier finds.
- Parse-error parity 78,461 (one explained manifest row).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): end BOM-led tails at a comment and read a heading's `{#` as beancount does

Review round 10 of the mid-line BOM run fix.

- A `;` after any BOM-led account of a tail starts beancount's comment,
  so nothing after it is counted.
- After a `<BOM>*` heading, `{#` is a brace and whatever the `#` starts;
  the rest's lexer resumes mid-line after the brace (new
  `TokenIter::new_mid_line`), so the cost stays linear. Invalid runs are
  reported from where beancount's invalid token starts.
- The BOM matrix checks the error kinds each cause names (`P0026`,
  `P0006`), and verifies a glued-account line with its accounts written
  as ordinary ones; it gains the comment tails, a `{#t` heading context,
  the price shape and a `brace-hash-before-tag` cause.
- The linearity guard runs the 1 MB pass under a time budget from the
  short pass, so a quadratic version fails instead of hanging.
- Tests pin masking to BOM-led lines and name the partly-invalid
  account test as preserving main's message.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): verify BOM matrix causes part by part and pin reported token text

Review round 11 of the mid-line BOM run fix.

- The matrix table records beancount's count for each line alone, and a
  recovery cause is asked first when the line alone counts as beancount
  does alone.
- A line may have two causes (`&`): a glued BOM with a mid-line `#!` /
  `#+`, or with a construct error main also makes. Each part's share is
  measured in turn and the shares must be the whole difference.
- The invalid-token texts rledger reports for BOM inputs are recorded and
  checked; an update that keeps counts but changes causes or texts needs
  BOM_MATRIX_RELABEL=1.
- The linearity guard caps the short run at 1 s, gives the long run 10x
  the linear ratio plus 5 s, and re-raises a worker's own panic.
- `invalid_runs` reads a `{#` through the common token path (a lone
  capital glued to it starts beancount's invalid token, `A{#`), and the
  dead heading-rest comment break is gone; `new_mid_line` is pinned.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): read BOM roles from beancount's lexer and refuse regressions on update

Review round 12 of the mid-line BOM run fix.

- The matrix generator records where beancount's own lexer puts each
  input's BOMs (BOM-led ACCOUNT tokens, BOMs inside invalid tokens) and
  each line's grammar errors after its first; the test reads these
  instead of guessing token boundaries.
- inner-bom-under-line-error now requires a BOM inside beancount's
  invalid token whose replacement by `$` makes rledger count the line as
  beancount does; one-diagnostic-per-line and the new
  bom-account-under-line-diagnostic are verified from the table.
- kinds_hold is gone; composite share signs are documented.
- An update refuses a line counted further from beancount than recorded
  (a new matching list tells rows that matched from new ones) unless
  BOM_MATRIX_RELABEL=1 and the known row carries a reason.
- The linearity guard bounds the short run by a load-scaled reference.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): seal the BOM matrix matching list and verify the one-diagnostic fallback

Review round 13 of the mid-line BOM run fix.

- The plain test checks the matching list is exactly the rows that
  match, and a `# total` seal line catches a cut or edited list in
  either mode, so a stale list cannot switch off the update guard.
- one-diagnostic-per-line now needs beancount's later grammar errors
  to be the whole difference; pop-without-push is asked first;
  line-start-bom-before-comment covers every skipped line start; new
  eof-error-on-last-line and bom-free-line-as-on-main causes; the lines
  no rule explains are listed by hand with their facts.
- A regression reason is written for exact counts and expires with
  them; a row that matched regresses from beancount's counts even with
  a hand-added known row.
- The generator requires beancount 3.2.3.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): pin the BOM price/cost gap, test the EOF and indented-BOM rules, verify matrix exceptions

Pin the dropped price or cost after a mid-line BOM (#2954) with a test
that the follow-up must update. Test the trailing pending-BOM rule of
holds_an_invalid_token and the line-start offset test in the lexer Err
arm, and note why the at_line_start conjunct is kept.

In the BOM matrix guard, keep line-start-bom-before-comment off lines
beancount reads as a BOM-led ACCOUNT (32 rows go back to
bom-account-under-line-diagnostic), ask like-main-without-bom last on
lines no worse than main (six exceptions now have that verified cause),
and check each exception reason against the counts it names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(parser): drop the no-op line-start BOM tests, test the late analog rule

Review round 15 of #2931.

- holds_an_invalid_token: drop the line-start BOM test. It walks only an
  open or a transaction, whose header starts with its date and whose later
  lines all start with indentation, so a line a BOM starts is an ERROR_NODE
  of its own and never in the node. The `before` tracking goes with it, and
  bom_token_starts_its_line folds back into is_line_start_bom_token.
- quiet_after_invalid_tokens: count a line-start BOM as its line's first
  invalid token, as beancount does. It changes no output: the line is an
  ERROR_NODE line, whose errors after the BOM are all of the kinds kept.
  Documented at both sites.
- bom_combination_matrix: a direct test of cause() pins that the late
  like-main-without-bom rule needs beancount's analog count to equal its
  count here; reason_counts reads the counts only from the start of a
  reason and panics otherwise, with tests for both.

No parse output changes: parity --check at 78,461 of 111,323, and a
420,000-input differential against the previous head shows no difference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): pin both analog counts of the late like-main-without-bom rule

Round 16 found that dropping the main half of the late rule's condition
(`get(&counts.analog_main, l) == r`) passed every test, because the
round-15 test fixed main's analog count at rledger's. The test now also
gives main a different count on the BOM-free analog and expects the line
to stay unexplained. Renamed to say it needs both counts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): pin every non-equivalent guard of the matrix's cause()

A 69-mutant sweep of `cause()` left 12 survivors. Pin each one that can
change a result with a direct `cause()` test on made-up counts
(`line3_counts`, `line3_cause`, `with_account_role`):

- `bom-free-line-as-on-main` needs main's count to be rledger's;
- `listed-exception` needs the counts its reason was written for, read
  from the first exception's own table row (`row_counts`, split out of
  `check_row`);
- both glued-BOM causes need a BOM-led account on the line;
- `bom-glued-to-account-in-error-line`, `brace-hash-before-tag` explain
  errors beyond beancount's only, and `line-start-bom-before-comment`,
  `inner-bom-under-line-error`, `pop-without-push` errors short of it
  only; the inner-BOM cause also needs a `P0026` on the line.

The guards that cannot change a result are commented at their sites
(the glued gate's `r != b` and `boms > 0`, now named `glued_asked`; the
line-start rule's BOM check; the later-grammar rule's `r < b`), and the
recovery filter's `l > 0` is removed: `recovery` is already `None` on
line 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): push the made-up account role instead of a one-range vec

clippy (single_range_in_vec_init) rejects `vec![a..b]`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): pin the line-start BOM guard and the inner-BOM check of the matrix's cause()

Review round 18 of #2931:

- The BOM guard of line-start-bom-before-comment is needed, not
  equivalent: beancount's EOL error for the line before can land on a
  skipped line start. Reword its comment and pin it on real counts.
- inner_boms_are_the_difference now checks the line has an inner BOM,
  as its doc says, and its test reads a real table row.
- Drop the unreachable BOM strip before poptag / popmeta, pin
  block_err's look past the indentation, and comment the remaining
  equivalent guards.
- Name only the real holders of the next cache versions in the loader
  and WASM cache notes (#2946 holds none).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): pin the rest of cause()'s helpers, and say why the others change nothing

Round 19 of the review mutated cause()'s helpers. New made-up-count tests
kill each mutant that can change a result: the BOM inside a header string
for block_err, a poptag that does not start its line, a negative construct
share, the in-error-line rule's non-BOM error, a tag after a line-start
BOM, the brace rule's tag character, each eof_error_on_last_line
condition, date_alone's length and BOM strip, lone_capital_glued's BOM
strip, account_after_bom's colon, account_at at an earlier account, and an
account role on another line for both glued causes.

The rest are commented as changing no result where they stand, each with
the reason: the header range, later_grammar's rl >= 1, the hash-bang check
and the dead (r, b) update in parts_hold, eof's bc[eof] > 0, the inner-BOM
rewrite's span filter, line_span's end, and the in-error-line rule's `>`.
skipped_line_start no longer checks for a `\n` a single line cannot hold,
an unknown part is unreachable!, and GLUED's own zero check is left to the
shared one, which the matrix test now needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): sweep cause() and every helper with 451 mutants, and pin or document each survivor

Round-20 review of the matrix test's classifier. `date_alone` now asks the
parser's own `parse_date` (beancount's `DATE`, slash dates and
`2024-01-021` included, and a real calendar date) and no longer strips
leading BOMs: beancount reads `<BOM>2024-01-02` as one invalid token and
reports nothing on the next line. `holds` is one match, with its two
standalone checks sharing `alone_counts`, and `parts_hold` checks the
construct sign in the construct arm.

New tests pin, on real counts where beancount and rledger differ (the
rows recorded by hand from bean-check 3.2.3, `recorded_row`) and on
made-up counts otherwise: the date shapes, each skipped line start, a
BOM-led `poptag`, each tag character after `{#`, each character after a
lone capital, the eof sum, the later-grammar difference, the glued
in-error-line difference, the `$` of the inner-BOM rewrite, the
hash-bang analog, `is_blank`, line 0 for an unclosed push, the
recovery-first `alone_matches`, both analog counts of the early
`like-main-without-bom`, main's count for `extra-construct-error`, and
every kind of cause `holds` checks.

Sweep on the final file: 451 mutants, 2 do not compile, 409 killed, 40
survive, each commented as equivalent at its site.

The WASM v102 note now says v100 and v101 were never released, and the
v104 note no longer repeats v93, v95, v100 and v101.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(parser): one error for a BOM glued before a price, cost or tolerance, and pin the matrix classifier's survivors

A posting's trailing-tokens check starts its error where the amount ends,
so a token glued to the currency (`1 HOOL<BOM>@ 2 USD`, `<BOM>{2 USD}`,
`<BOM>{{4 USD}} @@ 5 USD`) put it right at the token, where
`quiet_after_invalid_tokens` kept it: two errors where bean-check 3.2.3 and
main report one. A construct check's error that starts at the token and
runs past it is now treated like one that starts before it. On a header
line, a construct check around the token (a balance's malformed amount,
`1.00 <BOM>~ 0.01 USD`, `1.00 $~ 0.01 USD`) is dropped too when the
header's grammar reads up to the token (`header_grammar_reaches`, the rule
`directive_header_check` applies). 17 parity inputs now match beancount.

The matrix table gains the round-21 shapes (a BOM glued or spaced before
`@`, `@@`, `{`, `{{`, `~`, LF and CRLF; a date alone with a comment; a
line-start BOM before `*` / `#` and a BOM). `date_alone` reads beancount's
DATE token by hand (regex, Python date range, 32-bit field wrap, a `;`
comment after it) instead of asking the parser, and the
`eol-reported-on-next-line` rule needs exactly one error moved. The
classifier survivors of the round-21 review are killed by tests or
commented as equivalent; the stale-exception check and the hash-bang share
are functions with tests of their own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore(cache): keep loader cache v73; WASM cache v104 only

Every input #2931 changes has a parse error on main and here, and the
loader saves a cache blob only for an error-free load, so no loader blob
can hold a changed output: the v74 bump is dropped. The WASM payloads
archive sources with parse errors, so WASM v104 stays, pinned to loader
v73.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): a price after a dropped cost is kept

The glued-BOM test asserted every price gone; `{{4 USD}} @@ 5 USD` drops
only the cost the BOM stands in front of.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): pin the matrix checker by a second sweep

The known, texts and matching lists are compared through one list_diff,
the known list is parsed once (parse_known_rows), and the update-only
helpers (relabeled_rows, reason_holds, regressed_rows) get tests of their
own. beancount_date covers every month length, and
glued_boms_replace_construct the P0026s a rewrite leaves. Every other
survivor of the sweep is commented as equivalent at its site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(parser): kill or explain the round-22 survivors in quiet_after_invalid_tokens

- quiet_after_invalid_tokens: drop an error that spans the token only
  when it is a construct check (the SyntaxError and indented-line
  conjuncts, and the construct check on an error at the token, were
  that and nothing more), and drop the redundant `start > at` in the
  other branch. Each remaining equivalent mutant is argued at its
  site. A header's line error after two leading BOMs is kept, as a new
  test pins. The `end > at` boundary is #2967.
- header_grammar_reaches: pass `first` as the rule's `end`, which it
  never reads here; unit tests for each early return, the ancestor
  search, the right-biased token and the final defect check.
- Tests: tab-indented postings (a glued BOM or `$` before a price,
  cost or tolerance), extra BOMs at the start of a file.
- Matrix checker: `eol-reported-on-next-line` needs both halves at
  once; `regressed_rows` goes on past a new row; CRLF in data_lines;
  the data files hold no `\r`; two survivors commented.
- WASM cache v105 note: v104 was held by #2931 and never released.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant