Repository navigation
refactor: the source-text query surfaces answer by the file-based rule - #2889
Merged
Merged
Conversation
#2881 gave every file-based query surface one rule for when a query answers despite load errors (`LedgerError::blocks_queries`): refuse on a parse error or a booking failure, otherwise answer and report every load error beside the rows, as bean-query 0.2.0 answers over a plugin's error. The source-text surfaces kept rules of their own, each stricter: - FFI `query`, `batch` and a session from source refused on any load error, a plugin warning included, and `batch` said "parse errors exist" whatever the cause; - WASM `query(source)` (and `balances`) refused on any severity-error, a plugin's or an unresolved include's; - WASM `ParsedLedger.query` refused on any load error; - the MCP `query`, `balances` and `report` tools refused whenever the result held an error, and dropped warnings from an answer. Each now decides with the canonical predicate: the FFI helpers' `LoadResult` carries `error_blocks_queries`, the WASM `ProcessedLedger` carries `query_blocked`, `ParsedLedger` archives `query_refused` (WASM cache v77), and the MCP tools share `queryResponse`. Answered FFI results report the load errors ahead of the query's own, as `batch-file` does. WIT `rustledger:[email protected]`, API_VERSION 3.18. The shared drift-guard table gains a `source_text` flag and a plugin-error case, and runs through FFI `query`, `batch` and a session from source, and WASM `query` and `ParsedLedger.query` fresh and from cache, with exact rows and the reported error. The MCP tests repeat the source-text answers. Also fixes a `clippy::single_match_else` in the FFI guard's `check`, which failed `cargo clippy --workspace --all-targets -D warnings` on main. Closes #2882 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 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 |
…lls a refusal by its columns Review round 1 of #2889. - The WASM drift guard asserted a refusal as "no rows, some errors", so a ledger that failed to parse (no entries, so no rows either) passed with its refusal removed: `query_blocked: false` on the parse-error path survived. A refusal must now have no columns, an answer the query's one column, and the load error must be in the result's own `errors`. - `ParsedLedger.query` answered with `errors: []` over a plugin's error or an unresolved include, so a caller reading the result got partial rows with nothing saying so. Its result's `errors` now lead with the load's errors and option diagnostics, as the free `query` reports them. `Ledger.query` (#2861) answered the same way; its answers now carry the ledger's errors too. Method docs and the `.d.ts` say so. - The WIT `batch` doc no longer says each query repeats every load error: semantic validation errors are in `load.errors` only. - MCP `queryResponse` keeps the load's warnings beside a refusal or a BQL error, and a test comment no longer misattributes the 0.24.0 plugin behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d document reading a result by its columns Review round 2 of #2889. - A refused `ParsedLedger.query` returned only the load errors; it now adds the option diagnostics, as the free `query` refuses with `reported_errors()`. - The `QueryResult.errors` doc (and the generated bindings) says a result with columns is an answer whatever `errors` holds, and that a refusal has no columns. - CHANGELOG Breaking entry: `Ledger.query` and `ParsedLedger.query` answers can now carry `errors`, which 0.24.0 never did; recognize a refusal by empty `columns`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2888 took WASM cache v77 (loader v60). This branch's ParsedLedger payload change moves to v78, its note after #2888's; LOADER_CACHE_VERSION_PIN is 60, as main's loader cache is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 7, 2026
robcohen
added a commit
to MoTechnicalities/rustledger
that referenced
this pull request
Nov 7, 2026
Brings in rustledger#2885-rustledger#2889. The only conflict was CHANGELOG.md, in Breaking and in Fixed, where both sides added entries; both are kept. 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.
Behavior changes (read first)
Each change below answers where the surface refused. None refuses where it answered. The rule is #2881's: a query refuses on a parse error or a booking failure, and otherwise answers with every load error reported beside the rows.
query,batch,sessionconstructor (source text)batchsaidCannot execute query: parse errors existwhatever the causeerrorsahead of the rows (asbatch-filedoes); still refuse on a parse or booking error. A refusedbatchnow saysCannot execute query: a load error leaves the ledger incomplete (a parse or booking error); see the load errorsquery(source)andbalanceshas_fatal): a plugin's error, or anincludethe text cannot resolveParsedLedger.query(fresh andfromCache)errorsleading with the load's errors and option diagnostics, as the freequeryreports them (review round 1); still refuses on a parse or booking errorLedger.query(#2861)errors: [], the load's errors only ingetErrors()errors(review round 1), so the two classes agreequery,balances,reporttoolsquery_fileshows themCompatibility notes:
ParsedLedger.queryalready refused on booking errors, because they were in its load-error list, so nothing became stricter.batchrefusal message. Nothing in the repo matched on it.@rustledger/wasmin CI. Its tool-level change (showing diagnostics and following the wasm's refusal) applies to any wasm version. The new answers over a plugin error need the next wasm release. Details under Verification.bean-query 0.2.0 (rustledger-compat image)
plugin "beancount.plugins.check_commodity"with an undeclaredUSD<check_commodity>:0: Missing Commodity directive for 'USD' in 'Assets:Cash', then the rows, exit 0beancount.plugins.nosuchplugin)Invalid reference to unknown account, then the rows, exit 0. Not a source-text case: the source-text surfaces load withvalidate: false, so a validation error is never among their load errors and is not tested here (FFIbatchlists it inload.errorsonly)What changed
rustledger-ffi-wasi:helpers::LoadResultgainederror_blocks_queries(parallel toerrors, fromLedgerError::blocks_queries; a failed load istrue) andblocks_queries().rustledger-ffi-component:query,batchandSessionState::from_sourcedecide withblocks_queries().rustledger:[email protected],API_VERSION3.18. The docs forquery,batch, thesessionconstructor andsession.querystate the rule and the old behavior.rustledger-wasm:ProcessedLedgergainedquery_blocked(parse errors and failed loads aretrue; otherwiseLedgerError::blocks_queries).query(source)uses it instead ofhas_fatal.has_fatalstays the soundness gate for validation,expandPadsand plugins.ParsedLedgerstoresquery_refusedand archives it, so the WASM cache goes to v78 (v77 before fix(parser): report the metadata shapes beancount rejects #2888 took it; see "Merge with fix(parser): report the metadata shapes beancount rejects #2888"): theParsedLedgerpayload gainedquery_refused. The loader cache is untouched.MCP: the new
queryResponsehelper is the one rule forquery,balances,reportandquery_file, which already followed it.A clippy fix in the existing guard.
cargo clippy --workspace --all-features --all-targets -- -D warningsfailed on main (refactor: one rule for when a query answers despite load errors #2881) withsingle_match_elsein the FFI guard'scheck. It now usesif let.Drift guard:
query_answer_rule/cases.rsgained:source_textflag on each case: a single file with no includes, run by the source-text surfaces. Source text has no files beside it to include: the FFI lists an include unresolved, and WASM reports it missing.It now runs through:
query,batchand a session from source: exact rows plus the reported error. A refusedbatchmust carryBATCH_REFUSEDand a non-emptyload.errors.query(source), andParsedLedger.queryfresh and from cache.includein source text.include!the table, so they repeat the source-text answers at tool level. They also pinqueryResponseon the answered and refused result shapes.Verification
Each guard fails with its fix reverted:
query_loaded/from_sourceback to!errors.is_empty()test_source_queries_answer_or_refuse_by_the_shared_rule:plugin error via query: QueryResult { columns: [], rows: [], ... }queryback tohas_fatalplugin error via query: rows []andinclude in source text via query: rows []ParsedLedger.queryback to!parse_errors.is_empty()plugin error via ParsedLedger.query: rows []handlers.tsback to mainanswers over a plugin's diagnostic, showing it beside the rowsThe cached flag is guarded by the booking-error case: a restored ledger that answered would return
pay,buy1,buy2.MCP against both wasm builds.
npm ci && npm run build && npm testpasses 134 tests (128 before) on the published@rustledger/wasm0.24.0, and again with this branch's wasm (wasm-pack build --target web) copied intonode_modules.node_moduleswas restored afterward. Against the branch wasm:query(source)over the plugin error answers["pay"]withMissing Commodity directive ....["pay"]withfailed to read file x.beancount ....Commands run:
cargo test --workspace --all-featurescargo clippy --workspace --all-features --all-targets -- -D warningsRUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depscargo fmt --checkwasm-pack test --node(all pass, including the three query-rule tests)cargo check -p rustledger-wasm --target wasm32-unknown-unknownscripts/check-wit-version-bump.sh(3.17.0 -> 3.18.0)scripts/check-wit-version-citations.shVersion numbers. Right before pushing, origin/main had WASM cache 76, loader cache 59 and WIT 3.17.0. No open PR branch sets 77 or 3.18.0, and the CHANGELOG has one v77 note.
How to test
Review round 1
checkasserted a refusal as "no rows plus some errors". ForParsedLedger.querythose errors came fromgetErrors(), soquery_blocked: falseon the parse-error path (helpers.rs:161) passed every guard: a ledger with no entries answers with no rows.narration.errors.checkno longer takesgetErrors().wasm-pack test --nodenow fails:a refusal has no columns: parse error via query: columns ["narration"], rows [].ParsedLedger.queryreports its load errors. It answered witherrors: []over a plugin's error, an unknown plugin or an unresolved include. Its result'serrorsnow lead with the load's errors and option diagnostics, on every path (answer, BQL parse error, execution error), as the freequery()reports them.getErrors()only, because the freequery()does not validate either..d.ts(lib.rs) say so.Ledger.query(refactor: one rule for when a query answers despite load errors #2861) now matches. It answered witherrors: []too, the ledger's errors reachable only throughgetErrors(). Its answers now carry the ledger's errors as well. This is additive: the rows are unchanged. It is in the behavior table above and in the CHANGELOG. Both classes go throughexecute_query, which now takes the load errors.validate: false, so a validation error is never among their load errors.batchdoc (and the Rust doc) now say each query repeats the load's parse, booking and plugin errors. Semantic validation errors are inload.errorsonly.queryResponselists every error, the load's warnings included, when it refuses or the BQL query fails. A synthetic test pins this.check_commodityreports a warning, and main's reports an error.cargo test --workspace --all-features: 6496 pass.-D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo fmt --check.wasm-pack test --node: all pass.npm run build && npm test: 134 pass.Review round 2
Ledger.queryandParsedLedger.queryalways haderrors: []. They can now carry errors: a failed balance assertion, a missing include, a plugin's error, an option diagnostic.if (r.errors.length) thrownow fails on ordinary ledgers.columns, not by a non-emptyerrors.ParsedLedger.queryrefusal now matches the freequery. It returned only the load errors. It now adds the option diagnostics, asreported_errors()does.QueryResult.errorsdoc (types.rs) says a result withcolumnsis an answer whatevererrorsholds, and that a refusal has no columns. The bindings were regenerated withscripts/regen-bindings.sh:index.d.ts,index.schema.json,types.py.cargo test -p rustledger-wasm --all-featuresandwasm-pack test --node: all pass.RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps,cargo fmt --check.4500c4a63c8. origin/main had not moved, so there was no merge.Merge with #2888
*as the argument of any function butcount, as bean-query does #2887. Both CHANGELOG entries are kept, in the Breaking and Fixed sections.CACHE_VERSION, its history note (placed after fix(parser): report the metadata shapes beancount rejects #2888's v77 note, which is unchanged) and the CHANGELOG mention.LOADER_CACHE_VERSION_PINis 60, matching main's loaderCACHE_VERSION.cargo test -p rustledger-wasm -p rustledger-loader -p rustledger-ffi-component --all-featuresandwasm-pack test --node: 620 tests, 0 failed.cargo fmt --check, plus the warm workspacecargo check.aab333e7f1c.Closes #2882
🤖 Generated with Claude Code