Skip to content

fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic - #2945

Merged
robcohen merged 7 commits into
mainfrom
fix/option-includes-and-locations
Nov 12, 2026
Merged

robcohen merged 7 commits into
mainfrom
fix/option-includes-and-locations

Conversation

@robcohen

@robcohen robcohen commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

What

Part 2 of #2925 (part 1 was #2930).

  1. Options in included files are validated, as beancount does. beancount parses each included file with its own Builder and fresh options. It reports every value an option's converter rejects as an error at the included file's line (exit 1). Then it keeps only the top-level file's values. rledger reported every included option as the E7009 warning, valid or not, and exited 0.
    • Options::set_scoped_inner now reads an included non-accumulating option into a scratch Options that starts from the defaults. It keeps that option's diagnostics (E7008, E7002, and E7004 for a deprecated option) and discards the value.
    • E7009 is left for a value the converter accepts, which is still ignored with that warning.
    • An unrecognized boolean word in an include gets its E7011 warning and the E7009 (both warnings, as bean-check is clean).
    • A rejected included booking_method stays in the scratch, so it refuses no query: the top-level method governs.
  2. Deliberate deviation, kept: an included file's name_* root does not root that file's own accounts. option "name_equity" "Capital" followed by open Capital:Z in the same included file is still E1005 (bean-check is clean; beancount loads the account with no account type). A Stricter than Python comment sits in set_scoped_inner and in errors.md. The test is included_name_option_does_not_root_its_own_file.
  3. Every option diagnostic (E7001 to E7011) has a file and line.
    • OptionWarning gains site: Option<OptionSite>. set_scoped_at stamps every warning the option raises with its site.
    • E7006 and E7010 are raised after all options are set. They get their option's site from the applied values (Options::locate, Options::site_of).
    • Options::set and Options::set_scoped still give no site.
    • Surfaces:
      • CLI text: rledger check prints file:line: error[E7002]: ....
      • CLI JSON: reports that file and line.
      • ag-rledger: ag-rledger check gets both through the CLI.
      • LSP: both paths (all_diagnostics and ledger_diagnostics_multi) publish each option diagnostic in the file its option is in, with the range on the option line, trimmed. An included file's go on that file. A warning with no site stays at the top of the main file.
      • WASM: option_errors and the single-source parse carry the line and column 1 (no file, as their other errors), and a multi-file Ledger's errors carry the file too; end_line and end_column are null, as on every LedgerError-derived error. validateMultiFile and validateWithHost left option diagnostics out entirely, so a tree with an invalid option validated clean; they now report them (beside a fatal load error too), and such a tree is valid: false.
      • FFI: nothing to change here. The FFI does not report option diagnostics yet; fix(ffi)!: report option errors, and validate file loads as rledger check does #2946 (fix(ffi): load() and validate() never report option errors such as E7002 #2929) does, and will rebase onto rustledger_loader::option_warnings_to_errors from this PR, which carries the location.
  4. rledger merge / split compare options with Options::without_locations(), since moving an option line to another file must not count as a different ledger.

Why

Each row below was a difference from bean-check 3.2.3, and none of rledger's option diagnostics had a location, where all of beancount's do.

Before / after

Each row is a main.beancount holding include "sub.beancount" and 2024-01-01 open Assets:A, with sub.beancount holding one line, option "<key>" "<value>". bean-check 3.2.3 is from nix develop .#bench. rledger is check --no-cache, from main (d728311) and from this branch. Cells are exit code then codes.

Option Value bean-check 3.2.3 rledger main rledger this PR
name_equity capital 1, error at sub:1 0, E7009 1, E7008 at sub:1
name_equity Capital 0, clean 0, E7009 0, E7009 at sub:1
account_previous_balances bad leaf 1, error at sub:1 0, E7009 1, E7002 at sub:1
account_previous_balances Opening 0, clean 0, E7009 0, E7009
account_rounding bad leaf 1, error at sub:1 0, E7009 1, E7002
inferred_tolerance_default USD:-0.01 1, error at sub:1 0, E7009 1, E7002
inferred_tolerance_default USD:0.01 0, clean 0, E7009 0, E7009
tolerance_multiplier abc 1, error at sub:1 0, E7009 1, E7002
tolerance_multiplier 0.6 0, clean 0, E7009 0, E7009
inferred_tolerance_multiplier abc 1, renamed + error at sub:1 1, E7004 E7009 1, E7004 E7002
booking_method fifo 1, error at sub:1 0, E7009 1, E7002
booking_method FIFO 0, clean 0, E7009 0, E7009
plugin_processing_mode weird 1, error at sub:1 0, E7009 1, E7002
plugin_processing_mode raw 0, clean 0, E7009 0, E7009
render_commas bogus 0, clean 0, E7009 0, E7011 E7009 (warnings)
render_commas TRUE 0, clean 0, E7009 0, E7009
title Sub 0, clean 0, E7009 0, E7009
display_precision USD:-0.01 (accumulates) 1, error at sub:1 1, E7002 1, E7002 at sub:1
issue example: name_equity "capital", booking_method "fifo", inferred_tolerance_default "USD:-0.01" 1, three errors 0, 3x E7009 1, E7008 E7002 E7002 at sub:1-3
deviation: name_equity "Capital" + open Capital:Z in the include 0, clean 1, E7009 E1005 1, E7009 E1005 (kept)

A 32-line include covering every option family gives the same errors on the same lines as bean-check, plus the E7011 and E7009 warnings. (In round 1 rledger also gave E7006 for the include's missing documents root; since round 2 that is the E7009 warning, as bean-check ignores it.)

Location, booking_method "fifo" in the include:

Surface main this PR
check text warning[E7009]: ... (no location) .../sub.beancount:1: error[E7002]: ...
check --format json "file": ".../main.beancount", "line": 1 "file": ".../sub.beancount", "line": 1
LSP top of the main file sub.beancount, on the option line
WASM Ledger errors no file or line file: "sub.beancount", line: 1

Canonical-function check

There is one source of truth for the location: OptionWarning::site, set by the loader. Every surface reads it.

Drift guards compare each surface with the loader's sites end to end, on a two-file tree. The tree has an E7003 in the main file, and an invalid E7008 and a valid E7009 in the include:

  • cli_commands_test::test_check_option_diagnostics_are_located_like_the_loader: check's JSON (code, file, line) equals the loader's, and the text lines start with file:line: severity[code].
  • diagnostics::tests::option_diagnostics_are_located_like_check (LSP): both ledger_diagnostics_multi and all_diagnostics (each file as the current one) give the loader's (code, file, line), and the option-line range is checked.
  • parsed_ledger::...::ledger_option_errors_are_located_like_check and api::...::validate_reports_option_errors_located_like_check (WASM).
  • helpers::...::both_paths_agree_for_every_option_code now compares the line and file of the WASM single-source paths too.

Caches

How to test

cargo test -p rustledger-loader --test included_options_test
cargo test -p rustledger-loader --lib set_scoped_at
cargo test -p rustledger --test cli_commands_test option
cargo test -p rustledger-lsp located_like_check
cargo test -p rustledger-wasm located_like_check

Gates, all exit 0:

  • cargo fmt --check
  • clippy --all-features --all-targets -D warnings
  • RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps
  • cargo test --all-features --no-fail-fast for loader, validate, lsp, wasm, ffi-wasi, ffi-component and rustledger
  • wasm-pack test --node

Review round 1

Commit 18dd60c.

  1. LSP regression fixed. A buffer the loaded ledger does not include (current_file_id is None) took here = 0, so the main file's option diagnostics were drawn on the unrelated buffer's lines. With None the ledger's option warnings are no longer attached; the buffer's own options go through the single-file fallback. Pinned by a_buffer_outside_the_ledger_gets_only_its_own_option_diagnostics: a ledger with an E7003 at line 3 and a scratch buffer of three opens gives no option diagnostic, and the buffer's own option "nosuch" is E7001 on its line 2.
  2. One canonical mapping. rustledger_loader::option_warnings_to_errors(&[OptionWarning]) -> Vec<LedgerError> (the name and signature fix(ffi)!: report option errors, and validate file loads as rledger check does #2946 uses) is now the single mapping. It maps OptionWarning::site to LedgerError::location as ErrorLocation { file, line, column: 1 }.
    • rledger check (text and JSON) and the LSP (file matching, range, severity) read the mapped LedgerError.
    • WASM's option_warnings_to_errors is a one-argument wrapper through the existing Error::from(LedgerError). The single-source entry points clear file with without_files instead of a name_files flag.
    • End-of-range: WASM option errors now have line and column (1) and null end_line / end_column, as every LedgerError-derived WASM error. Documented on the WASM helper. (They had end_line = line before.) The CLI JSON keeps end_line = line, end_column = column, as its other diagnostics always fill them.
    • Pinned by test_option_warnings_to_errors_carries_the_site (loader); the existing drift guards now go through the mapping.

Nits:

  • CHANGELOG names validateWithHost beside validateMultiFile.
  • LSP range stops before a ; comment outside a string (option_line_extent, with a test; the multi-file guard's fixture now has a comment containing a quoted ;). The limitation that the line comes from the loaded ledger while the range is drawn on the live buffer is documented on option_error_to_diagnostic; it is the same for every diagnostic the loaded ledger locates.
  • Options::locate is by occurrence: the n-th warning for an (option, value) gets the n-th site that applied it, so the same documents value in two files is located at both. Pinned by test_locate_is_by_occurrence. site_of (last applied) remains for E7010, which is about the last value.
  • validate_with_filesystem reads the option diagnostics right after the load, so they are reported beside a fatal load error and a processing failure too. Pinned by validate_reports_option_errors_beside_a_fatal_load_error.

Main has not moved; caches stay WASM 99 and loader 69.

Gates were re-run, all exit 0: fmt --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc, cargo test --all-features --no-fail-fast for loader, validate, lsp, wasm, ffi-wasi, ffi-component and rustledger, and wasm-pack test --node.

Review round 2

Commit e4f6388, then a merge of origin/main (3d52f7b, bringing in #2941 and #2943, no conflicts). No history was rewritten.

  1. documents in an included file is ignored, as in beancount.
    • bean-check 3.2.3 behaviour, checked:
      • loader.load_file gives documents == [] for an included root.
      • bean-check exits 0 when that root is missing.
      • A missing top-level root is one error, at main:0.
    • "documents" is removed from ACCUMULATE_ACROSS_INCLUDES. An included value now goes through the scratch converter and gets E7009. It is never applied, so nothing is scanned under it and there is no E7006.
    • Consumers checked: document discovery, E7006, the E8001 hint, the LSP and query all read Options::documents, which an include no longer reaches.
    • The remaining list matches beancount's aggregate_options_map: operating_currency is merged, display_precision goes into the merged dcontext, and insert_pythonpath becomes pythonpath. This is documented on the constant.
    • With display_precision in an include, bean-check 3.2.3 itself crashes (_FixedPrecisionContext has no fractional_dist), so that row has no reference.
    • Tests:
      • test_load_included_documents_is_ignored: E7009 at sub:1, documents empty, no errors.
      • test_load_documents_in_both_files_is_one_e7006: the same root in both files gives E7009 for the include and one E7006 at the top-level line, where bean-check also gives one error.
      • included_files_still_contribute_accumulating_options now expects documents to be ignored.
    • errors.md and the Options::locate rustdoc are updated.
    • test_locate_is_by_occurrence now repeats the value within one file (lines 4 and 9).
  2. Surviving mutations are now pinned.
    • site_of without .rev(): test_rooted_leaf_warning_is_at_the_last_line_that_set_it sets the same account_previous_balances "Equity:Open" on lines 2 and 5 and expects E7010 at 5.
    • without_locations not clearing sites: test_without_locations_drops_every_site builds the same options at other lines and files, with an E7001, a rejected booking_method and a value site. The originals differ, the stripped copies are equal, and every site is gone.
    • The api.rs "Processing error" arm (and the same arm in from_file_map) is not tested, because no input reaches it. process returns Err only from run_plugins' ?, and no ProcessError is constructed anywhere in the loader: plugin and booking failures are pushed as LedgerErrors and apply_plugin_ops returns Ok(()). Both arms now carry the option diagnostics anyway.

Nits:

  • WASM Ledger::from_file_map: reads the option diagnostics before process, so its processing-error arm reports them, as validate_with_filesystem does.
  • option_error_file_id: uses SourceFile::id.
  • errors.md: now says bean-check reports a missing documents root at line 0 of the main file, where rledger reports it at the option's line.
  • rledger query: prints option diagnostics through the canonical mapping, as file:line: CODE: message, and the ag-rledger envelope's warnings carry file and line.
    • Test: test_query_option_diagnostics_are_located.
    • query_warnings_match_what_rledger_query_prints now rebuilds the location from the envelope.
  • Loader-level without_files: not added. ErrorLocation::file is a PathBuf, not optional, so a loader helper could only drop the whole location (losing the line) or invent an empty path. WASM's without_files works on its own wire type, where file is Option. The FFI's single-source path can do the same on its wire type.

Caches: WASM stays at 99 and the loader at 69 (unbumped). Nothing archived changes in this round, and the merged main commits move neither cache.

Gates:

Gate Result
cargo fmt --check exit 0
clippy --all-features --all-targets -D warnings exit 0
RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps exit 0
cargo test -p rustledger-loader 438 passed, 0 failed
cargo test -p rustledger-validate 183 passed, 0 failed
cargo test -p rustledger-lsp 405 passed, 0 failed (after the merge)
cargo test -p rustledger-wasm 175 passed, 0 failed
cargo test -p rustledger-ffi-wasi 53 passed, 0 failed
cargo test -p rustledger-ffi-component 61 passed, 0 failed (after the merge)
cargo test -p rustledger 1307 passed, 0 failed
wasm-pack test --node 35 passed, 0 failed

All cargo test runs use --all-features --no-fail-fast. fmt, clippy and doc were re-run after the merge.

Review round 3

Commit b316d6b (added on top; no history rewritten).

  1. Loader cache bumped to v71. The round-2 change (an included documents option is ignored with E7009) changes loader output, and round 2 wrongly left the loader at 69. Repro: main.beancount includes sub.beancount, which sets option "documents" "docs", with docs/Assets/A/2024-02-01.receipt.pdf present. A main build's rledger check writes the v69 blob ("No errors found"); the fixed build then rejects it and reports sub.beancount:1: warning[E7009], and rledger query main.beancount 'SELECT date, type FROM #entries' returns only the open row.
  2. rledger query escapes option messages on the terminal path, as Diagnostic::to_line does (Escape control characters in ledger strings on output #2538). These messages quote option keys and values. Test: test_query_option_diagnostic_message_is_escaped, where an ESC in a name_equity value prints as \u{1b}.
  3. CHANGELOG:
    • ag-rledger query warnings now carry optional file and line keys.
    • rledger merge now refuses a tree whose include sets documents, because inlining would make that root effective. Checked: merge -n reports that the directive stream differs (a document entry appears) and writes nothing.
    • The cache line now gives loader v71.

Left as they are: the "mixed locations" nit and the non-UTF-8 path nit.

Gates:

Gate Result
cargo fmt --all --check exit 0
clippy --all-features --all-targets -D warnings exit 0
RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps exit 0
cargo test -p rustledger-loader 438 passed, 0 failed
cargo test -p rustledger-wasm 175 passed, 0 failed
cargo test -p rustledger 1308 passed, 0 failed
wasm-pack test --node 35 passed, 0 failed

Closes #2925

Merge of origin/main (99d51d0)

Brings in #2939 and #2942. One conflict, in the CHANGELOG's Fixed section, resolved by keeping both entries. No history rewritten. Neither merged commit moves a cache version (main is still loader 69, WASM 94), so this PR stays at loader 71 (with the WASM pin and both FIXTURE_VERSION tripwires at 71) and WASM 99.

Gates, all exit 0: cargo fmt --all --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, validate, lsp and rustledger, and wasm-pack test --node.

Merge of origin/main (b6ce2d4)

Brings in #2947. Conflicts, resolved keeping both sides: the CHANGELOG's Fixed section (both entries kept); the WASM cache version note (main's v97 note kept, this PR's v99 note after it, and its held-numbers remark now reads v98 held by #2944); and the error lists in WASM validate_with_filesystem and Ledger (main's reported_ledger_errors, which leaves out advisory-only E1004, plus this PR's located option diagnostics). Main is now loader 69, WASM 97, so this PR stays at loader 71 and WASM 99.

Gates re-run, all exit 0: cargo fmt --all --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, validate, lsp and rustledger, and wasm-pack test --node.

🤖 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 58.5ms ± 2.5ms 718.1ms ± 6.9ms 12.3x 45.1 MB / 51.0 MB
investment 82.3ms ± 0.8ms 2666.9ms ± 11.4ms 32.4x 46.1 MB / 59.1 MB
fifo 79.8ms ± 0.6ms 15577.5ms ± 180.3ms 195.3x 49.1 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 57.4ms ± 0.4ms 58.5ms ± 2.5ms +2.0% ✅ within noise 45.0 MB → 45.1 MB (+0.4%)
investment 83.1ms ± 0.6ms 82.3ms ± 0.8ms -0.9% ✅ within noise 47.0 MB → 46.1 MB (-1.9%)
fifo 80.7ms ± 1.0ms 79.8ms ± 0.6ms -1.2% ✅ within noise 48.9 MB → 49.1 MB (+0.4%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 1.1ms, investment 0.5ms, fifo 0.5ms), 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

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.83793% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-loader/src/options.rs 99.63% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@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

…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 added a commit that referenced this pull request Nov 11, 2026
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 3 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]>
… and escape query's option messages

Review round 3 of #2945.

- Loader CACHE_VERSION 69 -> 71 (WASM pin 71). Ignoring an included
  `documents` option (E7009) changes loader output: a v69 blob of a ledger
  whose include sets an existing `documents` root kept serving the
  `document` entries with no E7009. v70 is held by #2931 and v73 by #2944.
  The CostNumber and MetaValue fixture tripwires move to 71; no archived
  layout moved.
- rledger query escapes an option diagnostic's message on the terminal
  path, as Diagnostic::to_line does (#2538), with a test.
- CHANGELOG: ag-rledger query warnings carry optional file and line keys;
  rledger merge refuses a tree whose include sets documents.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 11, 2026 16:24
Brings in #2939 and #2942. CHANGELOG conflict in Fixed resolved by
keeping both entries. Cache versions unchanged: loader 71, WASM 99.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #2947. Conflicts resolved keeping both sides:
- CHANGELOG Fixed section: both entries kept.
- rustledger-wasm cache.rs: main's v97 note kept, this branch's v99
  note follows it (v98 is held by #2944). CACHE_VERSION stays 99.
- rustledger-wasm api.rs and parsed_ledger.rs: main's
  reported_ledger_errors (drops advisory-only E1004) plus this branch's
  located option diagnostics.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit 526f833 into main Nov 12, 2026
71 of 72 checks passed
@robcohen
robcohen deleted the fix/option-includes-and-locations branch November 12, 2026 03:42
robcohen added a commit that referenced this pull request Nov 12, 2026
#2945 took loader v71 and WASM v99, so this branch keeps loader v73 and
moves WASM to v102 (v100 and v101 are held by #2931 and #2952).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
#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]>
robcohen added a commit that referenced this pull request Nov 12, 2026
Main took loader cache v71 and WASM cache v99 (#2945, for #2925). This
PR's loader cache moves to v72 (v70 was never released), its WASM cache
stays v100, and the WASM loader pin and both loader fixture versions
follow to 72. The CHANGELOG and LSP test conflicts keep both sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
Resolve the WASM conflicts so both behaviors hold: #2945's located option
diagnostics (`option_warnings_to_errors`, through the loader's canonical
mapping) on validateMultiFile, validateWithHost and Ledger.fromFiles, and
this branch's validation of whatever loaded after a parse or load error.

- validate_with_filesystem: drop the early stop on a "fatal" load error.
  `rledger check` reports and validates past a missing, unreadable or
  directory include, a duplicate include, an include cycle and an empty
  glob, and stops only when the entry file cannot be loaded (the `Err`
  arm here). Option diagnostics follow the ledger's errors, in the same
  order as Ledger.fromFiles.
- load_and_book: the parse-error early return stays deleted; a source
  with a parse error gets its located option diagnostics from the loader.
- Ledger::from_file_map: parse errors, then ledger errors, then options.
- WASM cache: main's v99 note, then this branch's v101 (loader v71).
- LSP: adapt #2945's option_diagnostics_are_located_like_check to the
  view form of ledger_diagnostics_multi.
- CHANGELOG: keep both entries; reword for the merged behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
…heck does (#2946)

* fix(loader)!: validate options in included files as beancount does, and 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]>

* fix(loader): one canonical option-diagnostic mapping, and keep a ledger'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]>

* fix(ffi): report option errors, and validate file loads as rledger check 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]>

* fix(ffi)!: WIT 4.0.0 error code and filename, and keep the query refusal

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]>

* fix(loader): ignore an included documents option as beancount does, and 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]>

* fix(ffi): locate each parse error and host plugin error, as rledger check 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]>

* fix(ffi-component-tests): use parking_lot for the shared compiled component

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]>

* fix(wasm): list query option errors through the canonical, and pin columns (#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]>

* fix(ffi,wasm): locate every finding through one canonical, and count 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]>

* test(ffi,wasm): pin a parse error's refusal, WASM's file-id rule and 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]>

* docs(wasm,loader): say why WASM keeps its own parse-error mapping (#2946 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]>

---------

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

Development

Successfully merging this pull request may close these issues.

compat(loader): option value handling differs from beancount for booleans, tolerances, and options in included files

1 participant