Repository navigation
fix: validate after a parse error on every surface, as rledger check does - #2952
Merged
Merged
Conversation
ParsedLedger.fromCache and Ledger.fromCache threw "Deserialization failed: unaligned pointer ... alignment 8" on any ledger with a custom directive or a metadata entry. Root cause: rkyv::from_bytes reads the archive in place, so every archived value must sit at its own alignment in memory. ArchivedMetaValue needs 8 bytes (its Int(i64) variant, added in #1513), and every custom value and metadata entry archives one. The WASM cache blob puts its archive 12 bytes in, after the magic and version header, so even in a 16-aligned blob those values sat 4 bytes off. The blob itself is not aligned either: wasm-bindgen copies a JS Uint8Array into wasm memory with alignment 1. Fix: decoding copies the payload into an rkyv AlignedVec before reading it, which does not depend on where the caller's bytes lie. The cache format is unchanged, so CACHE_VERSION stays at 94 and blobs already written restore as they are. The loader's on-disk cache reads its header separately, so it does not have the offset bug, but it read the archive into a plain Vec<u8>, whose alignment is 1 by contract and 16 only because the system allocator happens to give it. It now reads straight into an AlignedVec. Its format is unchanged too. Tests: a round trip over one ledger per directive type, per metadata value type and per custom value type, plus error cases, comparing directives, errors and options on both ParsedLedger and Ledger, natively and under wasm-pack test --node; a native round trip over every .beancount file in the repository's test corpora; a decode of each payload at every offset from a 16-byte boundary; and a loader save/load of custom values and metadata. All but the loader test fail without the fix. Closes #2934 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ter a booking error Two cases where the diagnostic surfaces disagreed (#2937), settled by bean-check 3.2.3: - Closing an account that still holds a balance (E1004). bean-check does not flag it, with or without auto_accounts / currency_accounts, and `rledger check` stays silent to match (`lint closed-nonempty` reports it). WASM, the FFI component and the LSP reported it. They now leave it out through the one predicate, `ErrorCode::is_advisory_only`. - Validation after a booking error. bean-check and `check` report an ambiguous STRICT reduction and the `Balance failed` that follows it, the refused transaction left out of the balance. WASM `validateSource` and `ParsedLedger` skipped validation on any load error, and the FFI counted the refused transaction into the balance (-1600 USD where bean-check says -2100 USD). The loader now records which transactions booking refused (`Ledger::booking_refused`), and both surfaces set them aside as the validating loader does: Early sees them, Late does not, and the session reports the account errors Early held for them. A shared case file (`rustledger-loader/tests/surface_agreement/cases.rs`) drives one drift-guard test per surface: the loader, `rledger check`, WASM (`validateSource`, `validateMultiFile`, `ParsedLedger`, `Ledger`, fresh and from cache), the FFI component (`validate`, `load`) and the LSP, each comparing codes (the FFI wire error has none: line and message), lines and messages. The WASM cache moves to v97: both payloads' archived errors change. WASM `fromCache` now reads the archive from an aligned copy: it starts 12 bytes into the blob, and the new cache round trip hit an "unaligned pointer" refusal on it. The format is unchanged. Closes #2937 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The AlignedVec copy in deserialize_parsed / deserialize_ledger duplicates the fix in #2942 (#2934), which also covers the loader cache and has its own tests. #2942's branch is merged in next, so this PR's WASM cache round trip still decodes; #2947 depends on #2942 landing first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2947's WASM cache round trip needs #2942's aligned decode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Rewrite the comments that still said run_validation gates on load.errors or skips on has_fatal (helpers.rs, api.rs, parsed_ledger.rs). - run_validation: drop the span-length-mismatch branch, which set refused transactions aside without noting them; load_and_book always keeps one span per directive, now a debug_assert. - CHANGELOG: Ledger::booking_refused listed under Breaking, as PluginError::failed was. - Cache notes: v93 and v96 were never released; #2931 holds v95. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…does `rledger check` and bean-check 3.2.3 report a syntax error and still validate the entries that did parse. WASM (`validateSource`, `ParsedLedger`, `validateMultiFile`, `validateWithHost`), the FFI component (`validate`, `load`) and the LSP validated nothing once a file failed to parse, so one bad line hid every other finding. Each surface now follows the validating loader's rule, under which no load error stops validation: - WASM `load_and_book` no longer returns early on a parse error; the loader keeps what parsed and `process` books it, and `run_validation` validates it. `validateMultiFile` / `validateWithHost` report every load error, then run `process` with them cleared, as `check` does. - `LoadResult::take_parse_errors` (new) takes the parse errors out of a load so a surface reports them one by one with code and line, rather than `process` folding them into one line-less `parse errors in <path>`. WASM's single-source load, `Ledger.fromFiles` and the FFI string load use it. - The FFI's `semantic_validation_errors` drops its parse-phase gate. - The LSP's `validation_would_run` keeps only the size cap, and an open buffer with a parse error is overlaid in a multi-file ledger. The shared surface_agreement cases gain one parse error plus an unbalanced transaction and a failing balance (P0012 line 8, E3001 line 4, E2001 line 10, bean-check's three findings on the same lines), asserted on the CLI, the loader, WASM, the FFI and the LSP. WASM cache v101. Closes #2949 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
added a commit
that referenced
this pull request
Nov 11, 2026
…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]>
- LSP: restore the #1813 guard in `ledger_diagnostics_multi`, so a buffer broken mid-edit no longer replaces the stored plugins the unopened files are validated with, and re-add `broken_current_parse_keeps_stored_plugins_for_cross_file_validation`. - LSP: keep overlaying a broken current buffer (its own diagnostics come from its text, as in `rledger check`), but hold the unopened files' diagnostics while it has a parse error, so a half-typed string that swallows an `open` cannot make them flap. Keep overlaying other broken open buffers. Pin both through `MainLoopState`. - WASM: `validateMultiFile` / `validateWithHost` take only the parse errors and leave the other load errors to `process`, as `Ledger.fromFiles` does, so they keep the code `LOAD`; drift guard `validate_and_ledger_report_load_errors_alike`. - WASM cache comment: v100 is not held by an open PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2947 merged as 4bc5bd8. Its hunks take main's side; this PR's own changes (6c601dd..00c8866) are applied on top. In the test tail of the LSP main loop, #2941's coalescing tests and this PR's tests are both kept, and change_doc flushes the debounced diagnostics pass before the publishes are read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review round 2 of #2952. Round 1 held the unopened files' diagnostics while the edited buffer had a parse error. That hold never published the includes of a main file saved with a syntax error, let a clean buffer's edit recompute them against another broken buffer, and the restored plugin guard made a broken buffer's own diagnostics differ from rledger check on its text. Replace it with a stateless rule. Every file other than the one being published is validated against the clean view: the ledger as loaded with each open buffer that parses cleanly overlaid, a broken one left as on disk. The published buffer's own diagnostics come from the clean view plus its own text and plugins, as check reports them. For a clean buffer the two views coincide, so the all-clean path still runs one validation. didClose republishes the unopened files from disk. Removed: the hold flag, multi_file_diagnostics' with_unopened, and the parse-error plugin guard in ledger_diagnostics_multi. The changelog now names the surfaces that report parse errors one by one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 12, 2026
…lugins in the clean view Review round 3 of #2952. - The clean view used the stored load for a broken buffer, so breaking a buffer with unsaved clean edits undid them for every other file. Each open buffer now keeps its last clean parse (dropped on close) and contributes it while its current text is broken. - The clean view applied only the published buffer's plugin lines, so one revalidation could publish a file twice with different content. ledger_diagnostics_multi now takes the view as parses: every file in it contributes its directives and its plugin lines, replaced in place. - didClose republishes every other open ledger buffer, not only the unopened files. - Docs: the own view's file set is the stored load's (an include edit takes effect on the next load); the WIT balance diff and the ffi-wasi error-phase docs no longer describe the removed parse gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ean parse only in diagnostics passes Review round 4 of #2952. - view_plugins appended the plugins of a view file that had none stored at the end, in the order the view listed its files (the published buffer first, then VFS HashMap order), so two chained rename_accounts ran in a different order than rledger check runs them and the clean view depended on which buffer was published. It now stable-sorts by file_id, the loader's order (pinned by a new loader test). - last_clean_parse was recorded by every parse_result() call, request handlers included; it is now recorded only by clean_view_parse, which only diagnostics passes call. - The wasm cache comment no longer calls v100 unreleased. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r's plugin order on disk Review round 5 of #2952 (issue #2949). - After every successful load of the ledger (watched-file reload, root adoption), an open buffer whose current text equals the text that load read for its file drops its last clean parse: it was saved, so until it next parses cleanly its file is validated as `rledger check` validates the saved text. A buffer edited past what was saved keeps it. Before, a buffer saved broken kept validating its includes against its old clean text, hiding the E1001 `check` reports on disk. - Docs: the set AND ORDER of the files come from the last load (plugin order and same-day tie-breaks follow it), on `publish_diagnostics`, `view_plugins` and in the CHANGELOG. - Loader test: the plugin `file_id` order on disk, through the parallel pre-parse branch (a glob include matching several files). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
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]>
…s a BOM The loader keeps a file's leading BOM, while editors send the buffer without it, so the round-5 "saved broken" check never matched a BOM-prefixed file and kept validating other files against its last clean text. Compare both texts with the parser's canonical `bom::strip_leading`, and pin the BOM and CRLF cases with tests. Review round 6 of #2952. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG and WASM cache conflicts with #2944. Main is now at WASM cache v102 (loader v73), so this PR moves its WASM CACHE_VERSION from 101 to 103, with its note after main's v102 note; v101 was never released. LOADER_CACHE_VERSION_PIN stays at main's 73, since this PR does not move the loader cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
Loader cache v74 and WASM cache v104 for #2931, above main's v73 / v102 (#2944) and #2952's WASM v103. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
#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]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
… it was hiding (#2962) The Check, Clippy and Documentation jobs ran cargo without --workspace, so they acted on default-members only, which leaves out rustledger-wasm, rustledger-ffi-wasi, rustledger-ffi-component and rustledger-ffi-component-tests. All four build on the host target, so --workspace needs no extra target or feature set. That gap let #2952 land a redundant_pub_crate failure in rustledger-wasm (pub(crate) load_errors_to_errors inside the private api module). Make it pub; the module stays private, so visibility is unchanged. Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
rledger checkand bean-check 3.2.3 report a syntax error and still validate the entries that did parse. WASM (validateSource,ParsedLedger,validateMultiFile,validateWithHost), the FFI component (validate,load) and the LSP validated nothing once a file failed to parse, so one bad line hid every other finding (#2949).bean-check 3.2.3 on one bad line (
garbage, line 8) plus an unbalanced transaction (line 4) and a failing balance (line 10) reports all three:rledger checkreports P0012 at line 8, E3001 at line 4 (residual 10 USD) and E2001 at line 10 (got 100 USD). After this PR every surface reports exactly those three.Each surface now follows the rule of the validating loader (
process): no load error stops validation. Each gate is removed rather than replaced, and each surface reaches validation through the code it already shares.load_and_book, undervalidateSourceandParsedLedger): the early return on a parse error is gone. The loader keeps what parsed,processbooks it, andrun_validationvalidates it. The parse errors are still reported one by one with their code, line and span.validateMultiFile/validateWithHost): these stopped on any load error except a duplicate include, an include cycle or an empty glob, so an unreadable include (an I/O error) also stopped validation. They now do whatcheckdoes: report every load error, then runprocesswith those errors cleared. bean-check also validates after a missing include.load_error_is_fatalis gone.rustledger_loader::LoadResult::take_parse_errorstakes the parse errors out of a load, so a surface reports each one with its code and line. Left in,processfolds them into a singleparse errors in <path>with no line. Three paths use it: WASM single-source,Ledger.fromFiles(which already validated but reported that folded error) and the FFI string load (ffi-wasiload_source). Whether a query refuses still comes fromLoadError::blocks_querieson what was taken out.semantic_validation_errorsdrops itsphase == "parse"gate (3 lines). The rest of the FFI change is inffi-wasiload_sourceand a few comments that described the old gate. It is kept small because fix(ffi)!: report option errors, and validate file loads as rledger check does #2946 also touches these files.validation_would_runkeeps only the size cap. The code lens follows it, so the balance lens shows a verdict after a parse error, because one was now computed. In a multi-file ledger the published buffer's own diagnostics come from its text and its ownpluginlines, parse error or not, so they are whatcheckreports for that text, with one caveat: the set and order of the files come from the LSP's last load, so an added, removed, changed or reorderedincludeline takes effect on the next load (pre-existing); the order matters as plugins run file by file in it. Every other file is validated with each open buffer's last text that parsed cleanly, directives andpluginlines (fix(lsp): validate multi-file ledgers once, not once per file (#1799) #1813), so a half-typed buffer never changes what is published for another file. See Review rounds 2, 3 and 5. A buffer saved broken counts as loaded once the ledger is reloaded (Review round 5, F1).Cache: the WASM
CACHE_VERSIONgoes from 102 to 103. AParsedLedgernow archives the directives and validation errors of a source with a parse error. ALedgernow archives each parse error with its code and line. The loader cache is unchanged, because the rawLoadResultit archives does not move.Built on #2947, which has merged (squashed as 4bc5bd8). It reuses that PR's
surface_agreementdrift guards andbooking_refused. The branch is updated frommainby a merge, so the diff againstmainis this PR's changes only.Behavior to review
MainLoopState::publish_diagnostics). A deliberate difference fromcheck: while a buffer is broken, the OTHER files are validated with its last text that parsed cleanly (as loaded, if it has not parsed cleanly since it was opened), not with its broken text, so they do not flap on each keystroke (fix(lsp): validate multi-file ledgers once, not once per file (#1799) #1813).validateMultiFile/validateWithHostrender only the parse errors themselves (code and line, throughtake_parse_errors) and leave every other load error toprocess, asLedger.fromFilesdoes. A duplicate include and a missing include keep the codeLOADand the placeprocessgives them: the missing include's file and line, none for the duplicate (asrledger checkprints it).Tests
crates/rustledger-loader/tests/surface_agreement/cases.rs) gain "validation after a parse error", with exactly P0012 at 8, E3001 at 4 and E2001 at 10. The following run it:surface_agreement_test. The parse errors are read from the raw load, ascheckreads them.rledger check --format json.validateSource,validateMultiFile,ParsedLedgerfresh and from cache, andLedger.fromFilesfresh and from cache, underwasm-pack test --node. The multi-file surfaces prefix a parse message withledger.beancount:; the test requires that prefix.validate, andloadwith and withoutexpand_pads.all_diagnostics.LoadResult::take_parse_errors:test_take_parse_errors_leaves_the_other_load_errors.checkreports it.Mutation check. Each mutation restores one gate, in its own worktree with a fresh target dir. The drift guard fails each time:
run_validationreturns nothing on a parse errorwasm_surfaces_report_the_shared_findingsvalidateMultiFilestops on a load error that leaves the ledger incompletewasm_surfaces_report_the_shared_findingssemantic_validation_errorsparse-phase gateconvert::surface_agreementall_diagnosticsskips on parse errorshandlers::diagnostics::surface_agreementHow to test
Passing locally:
cargo fmt --checkcargo clippy --all-features --all-targets -D warningsRUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depscargo test --all-featuresfor loader, validate, wasm, ffi-wasi, ffi-component, lsp and rustledgerwasm-pack test --nodeReview round 1
primary_parse.errors.is_empty()guard inledger_diagnostics_multilet a buffer broken mid-edit replace the stored plugin list with what it recovered. Withmain=plugin "auto_accounts"+include "b.beancount"on disk andbusing accounts it never opens, the bufferplugin "auto_acc⏎include "b.beancount"(the unterminated string swallows the include; the recovered plugin is namedauto_acc\ninclude) or@@@ not valid beancountput 2 E1001s onb.beancount, thoughrledger checkon that text never loadsb. The guard is back.broken_current_parse_keeps_stored_plugins_for_cross_file_validationis back too, driving both buffers through the overlay the main loop builds; it fails with the guard removed."makes a string of every line up to the next quote,opens included.rledger checkoninclude "b.beancount"/2024-01-01 * "oops/ the twoopens /2024-01-05 * "z"+ postings reports P0012 at 5 and E1001 twice at line 2 of main and twice inb, and the next keystroke takes them away again. Restoring the old guard (overlay the current file only when it parses) is not the answer: the edited file's own diagnostics would then come from its stale on-disk entries, mapped onto the buffer's text (wrong lines, or errors the buffer no longer has; with this PR the file is validated, so this is no longer hidden). So the broken buffer stays overlaid, its own diagnostics are exactlycheck's for its text, and while it has a parse error the unopened files are not remapped or republished; they keep what was last published and are recomputed when it parses again (or a clean buffer is edited).checkvalidates, and they do not change while another file is edited, so they cannot flap. The stale on-disk entries they replace can be wrong in the other direction: an open buffercthat opensAssets:Z(not yet saved) would otherwise give the editedmainan E1001 onAssets:Z.validateMultiFile/validateWithHostrendered every load error themselves and then cleared them, so a duplicate include and a missing include lost the codeLOADthatLedger.fromFilesgives them. They now do whatLedger::from_file_mapdoes:take_parse_errors, render only those, leave the rest toprocess. The "Behavior to review" bullet that presented the lost code as matchingcheckis corrected. New drift guardvalidate_and_ledger_report_load_errors_alikeasserts both surfaces give identical code/file/line for a duplicate include, a missing include and a parse error, and that validation runs past them.ffi-wasiload_source. Whichever of fix(ffi)!: report option errors, and validate file loads as rledger check does #2946 / fix: validate after a parse error on every surface, as rledger check does #2952 merges second switches it to fix(ffi)!: report option errors, and validate file loads as rledger check does #2946'srustledger_loader::parse_errors_to_ledger_errors.New tests, each driven through the real path:
handlers::diagnostics::tests::broken_current_parse_keeps_stored_plugins_for_cross_file_validationledger_diagnostics_multiwith the broken buffer overlaidmain_loop::tests::a_broken_ledger_buffer_is_validated_from_its_text_and_holds_unopened_filesMainLoopStatedidOpen/didChange, published notificationscheck's P0012 + 2 E1001 for the quote case); unopenedbnot republished while broken, republished once cleanmain_loop::tests::a_broken_other_open_buffer_is_overlaid_with_what_parsedMainLoopState, two open buffersapi::load_error_tests::validate_and_ledger_report_load_errors_alikevalidate_with_filesystemvsLedger::from_file_mapMutation check, one scratch copy, run sequentially, reverted after each (
cargo test -p rustledger-lsp --all-features --lib; WASM--lib load_error_tests):ledger_diagnostics_multibroken_current_parse_keeps_stored_plugins_for_cross_file_validation(b: E1001, E1001)a_broken_other_open_buffer_is_overlaid_with_what_parsed(main: E1001 at line 3)a_broken_ledger_buffer_is_validated_from_its_text_and_holds_unopened_files(only P0012; the E3001 is gone)a_broken_ledger_buffer_is_validated_from_its_text_and_holds_unopened_files(bgets 4 E1001s)validate_with_filesystemagainvalidate_and_ledger_report_load_errors_alike(codeNonevsLOAD)(The LSP tests and mutations in the two tables above are replaced in round 2.)
Gates on 00c8866, against a cleaned target dir:
cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, andwasm-pack test --nodeincrates/rustledger-wasm: all pass.Review round 2
Updated from
mainby a merge (no rebase, no force-push). #2947 merged as 4bc5bd8; for its hunksmain's side was taken, and this PR's own changes (6c601ddc147..00c886632dd) were applied on top.git diff origin/mainis exactly those changes plus this round. The one semantic conflict was the test tail ofmain_loop.rs, where #2941'smod coalescingmeets this PR's tests: both are kept, and the test helperchange_docflushes the debounced pass (flush_pending_diagnostics) before reading publishes.Refined in round 3 (below): the clean view keeps a broken buffer's last clean text instead of falling back to the ledger as loaded, and takes the
pluginlines of every buffer in it.The LSP rule, redesigned (F1, F2, F3). Round 1's hold was state carried between passes, and it was wrong three ways: a main file saved with a syntax error never published its includes (F1, a regression); editing a clean buffer while another was broken recomputed the unopened files against the broken one and the flapping E1001s stuck (F2); and the restored plugin guard made a broken buffer's own diagnostics differ from
check's on its text (F3). It is replaced by a stateless rule with two views:pluginlines. Its diagnostics arecheck's for the ledger with that text.For a clean buffer the two views are the same, so the all-clean path still runs ONE validation, as before. Only a broken ledger buffer costs a second validation, for its own diagnostics. A file saved broken is in the ledger as loaded with its parse error, so its includes are validated as
checkvalidates them (F1).didClosenow republishes the unopened files from the clean view without the closed buffer, so its unsaved text stops counting.Removed: the hold flag,
multi_file_diagnostics'with_unopenedparameter, theprimary_parse.errors.is_empty()plugin guard inledger_diagnostics_multi(the caller passes a primary only when its parse belongs in the view), and the unit testbroken_current_parse_keeps_stored_plugins_for_cross_file_validation, which only pinned that guard; its cases now run throughMainLoopState. A changed behavior: another open buffer with a parse error is no longer overlaid (round 1 overlaid it); withcbroken and openingAssets:Zonly in its unsaved text, the editedmainreportsAssets:Zunopened, ascheckdoes withcon disk.Also fixed: two stale comments that still said a parse error skips LSP validation (
docs/development/lsp-support.mdand a test doc comment).New tests, all through
MainLoopState(didOpen,didChangewith a flush,didClose, root adoption / revalidation,didChangeWatchedFiles), reading the published notifications:a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk* "oopsbuffer exactlycheck's P0012 + 2 E1001 in main;bkeeps its own E1001 on every passa_saved_broken_main_still_publishes_its_includes(F1)bgets its E1001 ondidOpen(configured journal), on root adoption, and on a watched-file changeediting_a_clean_buffer_while_another_is_broken_does_not_flap(F2)* "oops,copen and edited:bunchanged; main closed:brepublished from diskclosing_a_buffer_republishes_the_unopened_files_from_diskopenin main clearsb's error; closing main unsaved brings it backa_broken_buffer_uses_the_plugins_it_declares(F3)plugin "beancount.plugins.auto_accounts": P0012 alone, ascheckreportsa_broken_buffer_does_not_drop_its_plugins_from_other_files(#1813)plugin "auto_acc⏎include "b.beancount"and@@@ not valid beancount: no E1001 published intoba_broken_other_open_buffer_is_validated_as_loadedMutation check, one scratch copy with its own target dir, run sequentially, reverted after each (
cargo test -p rustledger-lsp --all-features --lib):editing_a_clean_buffer_while_another_is_broken_does_not_flap,a_broken_other_open_buffer_is_validated_as_loadeda_broken_buffer_does_not_drop_its_plugins_from_other_files,a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk,a_saved_broken_main_still_publishes_its_includes,a_broken_buffer_uses_the_plugins_it_declares,editing_a_clean_buffer_while_another_is_broken_does_not_flapa_broken_ledger_buffer_is_validated_from_its_text_and_others_from_diskledger_diagnostics_multia_broken_buffer_uses_the_plugins_it_declaresdidCloseclosing_a_buffer_republishes_the_unopened_files_from_disk,editing_a_clean_buffer_while_another_is_broken_does_not_flapa_saved_broken_main_still_publishes_its_includes,a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_diskCHANGELOG (F4). It no longer says parse errors are reported one by one "on every surface that loads through the loader". It names them: WASM
validateSource,ParsedLedger,validateMultiFile,validateWithHost,Ledger.fromFiles, and the FFI component's string surfaces (load,validate, andvalidate_file, which validates the file's text alone without following its includes). The FFI'sload_filestill reports one line-lessparse errors in <path>per file, under its load-only contract. The LSP entry describes the new rule.Cache: v101 is still above
main's 97 and claimed by no other open PR (#2944: 98, #2945 / #2946: 99).Gates on 5b20a12 (the merged tree):
cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, andwasm-pack test --nodeincrates/rustledger-wasm: all pass.Review round 3
Round 3 found the code right on the tested paths but two documented promises not kept (F1, F2), plus docs (F3, F5) and a stale-diagnostics gap on close (F4). F1 and F2 are fixed, not documented away; both turned out contained.
F1: a broken buffer's last clean text stays in the clean view (fix). The clean view said a broken buffer's file is "as last loaded from disk", which is the stored
LedgerStateload (startup, root adoption, watched-file change; there is no didSave), so breaking a buffer with unsaved CLEAN edits undid those edits for every other file. Withbunopened and its own E1001 at line 3: adding an unsavedopen Assets:Qto main cleared b, typing2024-01-06 * "typing(swallows nothing) brought the E1001 back, closing the quote cleared it again. Each open buffer now keeps its last clean parse (vfs::Document::last_clean_parse, dropped on close; since round 4, F2, recorded only by diagnostics passes), and its clean-view entry is its current parse when clean, else that last clean parse, else the stored load (never parsed cleanly since open).publish_diagnosticsnow parses the published buffer through the VFS cache (when the VFS holds that text), so its own clean parses are recorded too.F2: the clean view's plugins come from every buffer in it (fix).
ledger_diagnostics_multireplaced only the PRIMARY's plugin lines, andpublish_unopened_diagnosticsused the stored plugins, so the clean view depended on which buffer was published: with main declaring an unsavedplugin "auto_accounts", b was[]from main's pass and[E1001@0, E1001@0]from c's, a single revalidation published b twice with different content, and closing c left the two E1001s.ledger_diagnostics_multinow takes the view as(file_id, &ParseResult)and dropsprimary_file_id/primary_parse: every file in the view contributes its directives AND its plugin lines, which replace that file's stored plugins (view_plugins); the own view replaces the published buffer's entry with its current parse. (Corrected in round 4: as first written,view_pluginsappended the plugins of a file that had none stored at the END, in the order the view listed its files, so the plugin ORDER, and with it the result, still depended on the published buffer and on the VFS's HashMap order. It now orders them as the loader does; see Review round 4, F1.)F3: caveat on "what
rledger checkreports" (docs). The own view's file set is always the stored load's, so a buffer whoseincludelines changed is validated with the old set until the next load (pre-existing onmain). Stated onMainLoopState::publish_diagnostics, in the CHANGELOG and above. (Extended in round 5, F2: the ORDER of the files comes from the last load too.)F4: closing a buffer republishes the other open buffers (fix).
on_did_closerepublished only the unopened files, so an open buffer validated against the closed buffer's unsaved text kept stale diagnostics until edited. It now republishes every other open ledger buffer from its own view (which republishes the unopened files too), or the unopened files alone when no other ledger buffer is open.F5: stale FFI docs (docs).
world.wit'sbalance-dir.diffno longer says it isnoneafter a parse error. Comment-only:scripts/check-wit-version-bump.shreports no interface change, so no version bump;scripts/check-wit-version-citations.shpasses.ffi-wasi'squery_refusal_errorcomment andledger_error_to_ffirustdoc no longer describe the removed parse gate (the wire phase now only feedsvalidate'sparse-error-count; query blocking is carried byerror_blocks_queries).F6: out of scope, filed as #2955 ("LSP: a scratch buffer outside the ledger shows the whole ledger's errors"), with a repro checked by a throwaway
MainLoopStatetest on this branch.New tests:
main_loop::tests::a_broken_buffer_keeps_its_last_clean_text_in_the_clean_view(F1)MainLoopState: b stays clean on every stepmain_loop::tests::the_clean_view_takes_every_clean_buffers_plugins(F2)auto_accounts: b clean after main's edit, after editing c, after closing c; two E1001s back once main is closedmain_loop::tests::a_revalidation_publishes_each_file_the_same_way_every_time(F2)revalidate_open_documentspublishes b at least twice, every publish identical (b unbalanced so each pass sends it)main_loop::tests::closing_a_buffer_republishes_the_other_open_buffers(F4)open; closing main republishes b with its E1001main_loop::tests::a_clean_pass_is_one_validation_and_a_broken_one_twovfs::tests::test_clean_view_parse_keeps_the_last_clean_parse_until_closehandlers::diagnostics::tests::test_view_plugins_replaces_each_view_files_plugins_in_placeExisting tests updated: the
ledger_diagnostics_multicall sites take the view;multi_file_vs_checkloses its unusedprimary; two round-2 test docs now say "last clean text (here as loaded)".Mutation check, one scratch copy with its own target dir, run sequentially, reverted after each (
cargo test -p rustledger-lsp --all-features --lib):clean_view_parsereturnsNonewhen broken)a_broken_buffer_keeps_its_last_clean_text_in_the_clean_view,test_clean_view_parse_keeps_the_last_clean_parse_until_closea_broken_buffer_keeps_its_last_clean_text_in_the_clean_viewthe_clean_view_takes_every_clean_buffers_plugins,a_revalidation_publishes_each_file_the_same_way_every_timea_broken_buffer_uses_the_plugins_it_declarestest_view_plugins_replaces_each_view_files_plugins_in_placea_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk,a_broken_buffer_uses_the_plugins_it_declaresdidCloserepublishes the unopened files onlyclosing_a_buffer_republishes_the_other_open_buffersa_clean_pass_is_one_validation_and_a_broken_one_twoa_broken_buffer_keeps_its_last_clean_text_in_the_clean_viewGates on 3cf52d6:
cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, wasm, lsp, ffi-wasi, ffi-component and rustledger,wasm-pack test --nodeincrates/rustledger-wasm, and (the WIT file changed, comments only)cargo build -p rustledger-ffi-component --target wasm32-wasip2pluscargo test -p rustledger-ffi-component-tests --lib --tests(no skip marker): all pass.Review round 4
F1: a view's plugins run in the loader's order (fix).
view_pluginsappended the plugins of a view file that had none stored at the END, in the order the view listed its files (the published buffer first, then the other buffers in VFSHashMaporder). Plugins run in list order, so that order changed results: with b declaringrename_accountsB -> Cand main's unsaved buffer addingA -> B, b'sExpenses:Astayed unopened (E1001 on b line 3) wherecheckon the saved texts says b is clean; and with both renames in buffers (mainA -> B, cB -> C), editing c published b with an E1001, editing main published it clean, and one revalidation published b twice with different content (with 3+ buffers it followedHashMaporder). The loader gives a file its id and pushes its plugins in the same step, before following its includes, so its list is infile_idorder, each file's in declaration order (checked for nested includes and a plugin declared after aninclude).view_pluginsnow drops the view files' stored plugins, adds their parses' plugins, and stable-sorts byfile_id: the loader's order, whatever order the view lists its files in. The loader's order is pinned by a new loader test, so the LSP's sort cannot silently drift from it. Docs corrected:view_pluginsandledger_diagnostics_multirustdoc,MainLoopState::publish_diagnostics, the CHANGELOG, and round 3's F2 above.F2: the clean view no longer depends on request timing (fix).
last_clean_parsewas recorded wheneverparse_result()ran, so a hover, semantic-tokens or workspace-symbols request that parsed a clean text between two passes changed what a broken buffer contributed. It is now recorded only inDocument::clean_view_parse, which only diagnostics passes call: a broken buffer's part of the clean view is the last text a diagnostics pass saw parse cleanly. Contained tovfs.rs.F3: cache comment (docs).
crates/rustledger-wasm/src/cache.rsno longer says v100 was never released; it lists the numbers held by open PRs when it was written (v98 #2944, v99 #2945 and #2946, v100 #2931).Info:
unique_priceserror at main line 0. Pre-existing: reproduced onmain(4bc5bd8) with a throwawayMainLoopStateprobe,checkatb.beancount:4, the LSP atmain.beancountline 0. The LSP keeps plugin errors as(severity, code, message)and shows them in file 0 at line 0. Filed as #2957.New tests:
main_loop::tests::a_buffers_plugins_run_in_checks_order(F1, scenario 1)A -> Bbefore b's storedB -> C: b ascheckreports it on the saved texts ([]; on disk E1001@3)main_loop::tests::the_clean_views_plugin_order_does_not_depend_on_the_published_buffer(F1, scenario 2)revalidate_open_documents, b equalscheckon the saved texts ([]; on disk E1001@2)handlers::diagnostics::tests::test_view_plugins_replaces_each_view_files_plugins_in_place(extended)file_idorder, for two listing orders of the viewrustledger-loadertests::test_load_plugins_are_collected_in_file_id_orderfile_idorder with nested includes and a plugin after aninclude(the invariantview_pluginsreproduces)vfs::tests::test_clean_view_parse_ignores_clean_texts_only_a_request_parsed(F2)rename_accountsis a native plugin (beancount_reds_plugins.rename_accounts.rename_accounts), so it runs in the LSP tests. The F1 tests compute the reference withrustledger_loader::load(.., LoadOptions::default())on the saved texts, and assert it is clean while the on-disk state is not, so equality cannot hold vacuously.Mutations, in place, sequential, reverted after each (
cargo test -p rustledger-lsp --all-features --lib):view_pluginsa_buffers_plugins_run_in_checks_order,the_clean_views_plugin_order_does_not_depend_on_the_published_buffer,test_view_plugins_replaces_each_view_files_plugins_in_placeparse_resultrecords the last clean parse againtest_clean_view_parse_ignores_clean_texts_only_a_request_parsedGates on 8688510:
cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, andwasm-pack test --nodeincrates/rustledger-wasm: all pass. (Round 4 touches no WIT file.)Review round 5
F1: a buffer saved broken is validated as loaded (fix).
Document::clean_view_parsereturned the last clean parse whenever the current text was broken, and nothing dropped it on a reload. So with main opened clean (openingAssets:X,Equity:E,Assets:Q; b usesAssets:XandAssets:Q), then edited to drop theAssets:Qopen and addgarbage, then SAVED broken (watched-file change, reload), b was still validated against main's old clean text and published clean, whererledger checkon disk reports E1001Assets:Qin b. After every successful load of the ledger (watched-file reload, and both root-adoption paths),MainLoopState::forget_clean_parses_of_loaded_buffersnow drops the last clean parse of every open buffer whose current text equals the text that load read for its file (Document::forget_last_clean_parse): such a buffer is as loaded, so until it next parses cleanly its file is validated ascheckvalidates the saved text. A buffer edited past what was saved (its text differs from the loaded one) keeps its last clean parse. NodidSavehandler or new client capability: the watched-file change a save raises, and its reload, is the save signal; matching the loaded TEXT rather than the event also covers a root adopted from a file already saved broken. Docs:MainLoopState::publish_diagnostics,Document::last_clean_parse, the CHANGELOG.F2: the set AND ORDER of files come from the last load (docs). Reordering
includelines in an unsaved buffer changescheck's plugin order (plugins run file by file) and same-day tie-breaks between files, butview_pluginssorts by the stored load'sfile_id. The caveat now reads "the set and order of the files come from the last load" onMainLoopState::publish_diagnostics, onview_plugins, in the CHANGELOG and in this body; "plugins run in the ordercheckruns them for those texts" now says "with the files in the order of the last load".F3: the loader's plugin order on disk (test). The parallel pre-parse branch in
load_recursiveis taken for ONEincludethat resolves to more than one file (a glob) on a filesystem thatsupports_parallel_read(valid_paths.len() > 1 && self.fs.supports_parallel_read()); separate siblingincludelines each go through the sequential branch, andVirtualFileSystemnever takes it. Newtest_load_plugins_are_collected_in_file_id_order_on_diskloads from a temp dir withinclude "sub/*.beancount"(a.beancount with a nested include and a plugin after it, then b.beancount) and a plugin after the glob include in main, and asserts the samefile_idorder and source-map order. That it exercises the parallel branch is shown by mutation: merging that branch's siblings in reverse fails it while the VFS variant passes.New tests:
main_loop::tests::a_buffer_saved_broken_is_validated_as_loaded(F1)didChangeWatchedFiles, b equalsrustledger_loader::loadon disk ([E1001@3], asserted non-empty), main stays[P0012@1]; a further still-broken edit keeps b as loadedmain_loop::tests::a_buffer_edited_past_its_saved_text_keeps_its_last_clean_text(F1)[])rustledger-loadertests::test_load_plugins_are_collected_in_file_id_order_on_disk(F3)Mutations, on a scratch copy with its own target dir, sequential:
forget_clean_parses_of_loaded_buffersa_buffer_saved_broken_is_validated_as_loadeda_buffer_edited_past_its_saved_text_keeps_its_last_clean_texttest_load_plugins_are_collected_in_file_id_order_on_disk(the VFS variant passes)Gates on d95af80 (round 5 plus a merge of
mainat e6c8054):cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, andwasm-pack test --nodeincrates/rustledger-wasm: all pass. (Round 5 touches no WIT file.)Merge of main (#2945)
git merge origin/mainat 526f833 (#2945: located option diagnostics, options in included files validated, loader cache v71, WASM cache v99). Resolutions:validate_with_filesystem(crates/rustledger-wasm/src/api.rs). fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945 added the option diagnostics (option_warnings_to_errors, through the loader's canonicalrustledger_loader::option_warnings_to_errors) and appended them on all three exits, including the early return on a "fatal" load error; this PR deletes that early return. Kept: the option diagnostics, read beforeprocessconsumes the options and appended after the ledger's errors (or afterProcessing error), the same orderLedger.fromFilesuses, sovalidate_and_ledger_report_load_errors_alikestill compares equal lists. Dropped: the early stop, decided by probingrledger check(built from this tree;check.rsis main's, untouched here): it reports and validates past a missing include, an unreadable (EACCES) include, an include naming a directory, a duplicate include, an include cycle and an empty glob (each printederror: ...and stillE2001 Balance failed, exit 1); it stops only when the entry file itself cannot be loaded (exit 2), which isloader.load'sErrarm here too.validateWithHostwas probed over the same disk trees (Node, realfs) and agrees. The decision is documented at the code site.validate_reports_option_errors_beside_a_fatal_load_error(from fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945) renamedvalidate_reports_option_errors_beside_a_missing_include, doc updated: there is no early return any more; its assertions are unchanged and pass.load_errors_to_errors. This PR's signature (&[LoadError],&SourceMap) andtake_parse_errorssplit are kept; fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945 did not change it; its one use of the old signature was in the early-stop hunk, gone with the stop. Parse errors are rendered once here, every other load error byprocess(LOAD).load_and_book(helpers.rs). fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945 changed the parse-error early return'svalidate_option_tuples(.., &lookup); this PR deletes that early return, so the hunk is dropped. A source with a parse error now gets its option diagnostics from the loader (without_files(option_warnings_to_errors(..))), located, as every other source does. fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945's other changes (without_files, the locatedvalidate_option_tupleson the load-failure path and inparse()) are kept as they are.Ledger::from_file_map(parsed_ledger.rs). Both arms combine: parse errors first (this PR), then the ledger's errors (orProcessing error), then fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945'soption_errorsread beforeprocess.cache.rs). Main's v99 note kept; this PR's v101 note follows it, now "loader v71, unchanged", with the held-by list corrected to v100 by fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does #2931 and v102 by fix(parser): keep each header string in its own field after an invalid token #2944.CACHE_VERSION = 101.handlers/diagnostics.rs, auto-merged). fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945's new testoption_diagnostics_are_located_like_checkcalled the old six-argumentledger_diagnostics_multi(state, Some(0), &parses[0], &[], ..); adapted to this PR's view form&[(0u16, &parses[0])](same meaning: file 0 validated with its own parse).validateMultiFile/validateWithHost"report every load error and the option diagnostics, and validate whatever loaded"; fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945's "beside a fatal load error" now reads "beside a load error", since no load error stops them after this PR.Surface comparison after the merge (
rledger checkvs each surface; findings as code@line):rledger checkvalidateMultiFile/validateWithHost/Ledger.fromFilesvalidateSource/ParsedLedger(main text only)validate/load(main text only)Balance failedLOAD@1, E2001@4 (got 0)LOAD@1, E2001@4failed to read missing.beancount, E1002@5, E2001@4LOAD@1(file main), E1002@5, E2001@4 (each)LOAD@1, E1002@5, E2001@4ledger_statediscards the loader's errors; neither PR touches it)cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, validate, wasm, lsp, ffi-wasi, ffi-component and rustledger (2654 passed, 0 failed), andwasm-pack test --nodeincrates/rustledger-wasm: all pass.Review round 6
main_loop.rs,forget_clean_parses_of_loaded_buffers). The loader keeps a file's leading BOM (DiskFileSystem::read), while editors send the buffer without it, so the round-5 text match never held for a BOM-prefixed file: its last clean parse was never forgotten, and the files it includes stayed validated against that clean text after it was saved broken. Both texts are now compared as the parser reads them, through the canonicalrustledger_parser::bom::strip_leading. New testsa_buffer_saved_broken_with_a_bom_is_validated_as_loaded(main on disk with a BOM, opened without one, saved broken: b gets[("E1001", 3)], ascheckreports on disk) anda_buffer_saved_broken_with_crlf_is_validated_as_loaded(CRLF in both buffer and disk), sharing the helperb_after_saving_main_broken. Mutation: comparing without stripping fails the BOM test ([]vs[("E1001", 3)]); the CRLF and round-5 tests keep passing.CACHE_VERSION"from 99 to 101" (main is at 99).Gates on a411148:
cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-features -p rustledger-lsp(392 unit tests and the integration suites pass), andcargo check --workspace --all-features --all-targets: all pass.Merge of main (#2944)
git merge origin/mainat 8773d67 (#2944: header strings kept in their own fields after an invalid token, loader cache v73, WASM cache v102). Conflicts only in the cache note and the CHANGELOG:cache.rs). Main's v102 note kept; this PR's note follows it as v103 ("loader v73, unchanged"), says what a stale blob would serve (aParsedLedgerwith no directives and no validation errors for a source with a parse error, aLedgerwith one line-less parse error per file), and that v101 was never released.CACHE_VERSION = 103, above main's 102; v104 is held by fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does #2931.LOADER_CACHE_VERSION_PINstays at main's 73: this PR does not move the loader cache.Gates on a5096d3 (the merge):
cargo fmt --all --check,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo test --all-featuresfor loader, validate, wasm, lsp, ffi-wasi, ffi-component and rustledger,wasm-pack test --nodeincrates/rustledger-wasm, and thescripts/check-*.shscripts CI runs: all pass.Closes #2949
🤖 Generated with Claude Code