Repository navigation
fix(ffi): run pre-booking synth pass through the FFI load surface - #1404
Merged
Merged
Conversation
The FFI `load_file`/`load_source` helpers hand-rolled a partial loader (parse + manual booking) that ran in parallel to the canonical `rustledger_loader::process::load` pipeline. That fork skipped the pre-booking SYNTH pass entirely, so `auto_accounts` / `document_discovery` never generated directives through ANY FFI surface (JSON-RPC `ledger.load` /`loadFile`, or the WIT component, which delegates to the same helpers) — even though the native loader did. No ffi-wasi or ffi-component test asserted synth through the FFI, so the divergence shipped green. Collapse the duplication instead of patching it: - `load_file` now delegates to `rustledger_loader::load` (the canonical `process::load`). `validate: false` preserves this surface's load-only error contract; `run_plugins` (default true) brings the synth pass. - `load_source` reuses the canonical `run_plugins(.., PreBookingSynth)` entry point rather than a fork, keeping its parse/book/error-phase and include-reporting behavior so `ledger.validate`/`query` are unaffected. - The WIT component inherits the fix (it delegates to these helpers). Synth-generated directives surface with `lineno 0` / `<unknown>` file — the "generated entry" marker embedders rely on. Close the test-coverage gap that let this through: - New `rustledger-ffi-wasi/tests/load_synth_plugins.rs`: asserts synth generation through `load_file`, `load_source`, and the JSON-RPC `loadFile`/`load` handlers, plus a guard that plain ledgers gain no spurious generated directives. - New `rustledger-ffi-component-tests` parity cases: assert synth through the real wasm component's `load` and `load-file`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-06-16)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a behavioral divergence in the FFI load surfaces by routing file loads through the canonical rustledger_loader processing pipeline (ensuring the pre-booking SYNTH pass runs), and adds regression tests to pin synth behavior across FFI JSON-RPC and WASM component surfaces.
Changes:
rustledger-ffi-wasiload_filenow delegates torustledger_loader::load(..)(canonical pipeline incl. synth), removing the hand-rolled booking loop.rustledger-ffi-wasiload_sourcenow runs the loader’sPreBookingSynthplugin pass on parsed directives.- New integration tests in
ffi-wasiand new parity tests inffi-component-testsassert synth-generatedOpendirectives surface with the expected “generated entry” marker (lineno == 0).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| crates/rustledger-ffi-wasi/tests/load_synth_plugins.rs | Adds integration coverage asserting synth Open generation through load_file, load_source, and JSON-RPC load handlers. |
| crates/rustledger-ffi-wasi/src/helpers.rs | Switches file loads to canonical loader pipeline; adds synth pass execution for string loads; introduces LedgerError -> FFI Error mapping. |
| crates/rustledger-ffi-component-tests/tests/parity.rs | Adds parity assertions that the WASM component surfaces synth Open directives for both load and load-file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Resolve Copilot review feedback on the load_source synth injection: - Don't ignore `run_plugins`'s `Result`: a fatal `ProcessError` is now surfaced as an error instead of being silently dropped. - Gate booking on parse success only (`no_parse_errors`), captured before the synth pass appends its diagnostics — so synth/plugin errors no longer suppress booking/interpolation (matches the canonical pipeline and prior load_source behavior, where the gate reflected only parse errors). - Mirror the loader's `python:` plugin-prefix handling: strip the prefix and set `force_python` instead of hardcoding `false`. - Fix the `ledger_error_to_ffi` doc comment to match the implementation (non-parse phases map to "validate", not "parse"). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Merged
robcohen
added a commit
that referenced
this pull request
Jun 16, 2026
Patch release. Includes the FFI synth-pass parity fix (#1404): the rustledger-ffi-wasi load surface now runs the pre-booking synth pass (auto_accounts, document_discovery) through the JSON-RPC and WIT/component surfaces, matching the native loader. Co-authored-by: Claude Opus 4.8 <[email protected]>
This was referenced Jun 16, 2026
robcohen
added a commit
that referenced
this pull request
Jun 20, 2026
The string-input FFI load surface (`load_source`, backing `ledger.load`, `ledger.validate`, and `ledger.query`) was a hand-rolled second loader — parse + a manual booking loop — that drifted from the canonical `process::load` pipeline (`sort → synth → book → regular → finalize`). Two phases were silently missing: 1. The post-booking REGULAR plugin pass. File-declared `plugin "..."` directives for regular plugins (`rename_accounts`, `split_expenses`, `currency_accounts`, `unrealized`, …) never ran when a ledger was loaded from source text. Confirmed: a ledger with `rename_accounts` returned the pre-rename account through `load_source`. 2. The date sort. Directives booked and surfaced in file order, not date order. This was the same class of bug as the synth-pass gap fixed in #1404 — which patched in one `run_plugins(PreBookingSynth)` call rather than removing the duplicate. `load_file` was already collapsed onto the canonical loader; only `load_source` remained hand-rolled because the string surface has no filesystem to resolve `include`s against. Collapse `load_source` onto the canonical pipeline via an in-memory VFS: build a `VirtualFileSystem` holding the source as `<source>`, run `Loader::with_filesystem(..).load()` + `process(.., validate:false)`, and rebuild the wire DTO from the returned `Ledger`. `validate:false` preserves this surface's load-only error contract (booking errors surface; semantic validation stays the `ledger.validate` endpoint's job). Declared includes are recovered from a parse for the DTO and stubbed as empty files in the VFS so include resolution is a no-op — preserving the historical "list includes, don't resolve, don't error" behavior (an unresolved include must not emit a parse-phase error, which would suppress validation). Any future pipeline phase now reaches the FFI for free. Regression tests in `tests/load_regular_plugins.rs` cover regular-plugin execution, date sorting, and include listing through `load_source`. Co-authored-by: Claude Opus 4.8 <[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.
Problem
The FFI
load_file/load_sourcehelpers hand-rolled a partial loader (parse + a manual booking loop) that ran in parallel to the canonicalrustledger_loader::process::loadpipeline. That fork skipped the pre-booking SYNTH pass entirely, soauto_accounts/document_discoverynever generated directives through any FFI surface — JSON-RPCledger.load/ledger.loadFile, or the WIT component (which delegates to the same helpers).The native loader runs synth correctly (
rustledger-loader'stest_plugin_execution_auto_accountsproves it), but norustledger-ffi-wasiorrustledger-ffi-componenttest asserted synth through the FFI, so the divergence shipped green.This was surfaced while embedding the engine in rustfava: a ledger declaring
plugin "auto_accounts"produced zero generatedOpendirectives through the FFI.Fix — collapse the duplicated pipeline
load_filenow delegates torustledger_loader::load(the canonicalprocess::load:sort → synth → book → regular → finalize). The hand-rolled booking loop is removed.validate: falsepreserves this surface's load-only error contract;run_plugins(defaulttrue) brings the synth pass.load_source(string surface) reuses the canonicalrun_plugins(.., PreBookingSynth)entry point rather than a fork, preserving its parse/book/error-phase and unresolved-include reporting soledger.validate/queryare unaffected.Synth-generated directives surface with
lineno 0/<unknown>file — the "generated entry" marker embedders rely on.Close the coverage gap
rustledger-ffi-wasi/tests/load_synth_plugins.rs— asserts synth generation throughload_file,load_source, and the JSON-RPCloadFile/loadhandlers, plus a regression guard that plain ledgers gain no spurious generated directives. (Verified failing before / passing after.)rustledger-ffi-component-tests— assert synth through the real wasm component'sloadandload-file.Testing
cargo test -p rustledger-ffi-wasi— 63 unit + 11 integration ✅cargo build -p rustledger-ffi-component --target wasm32-wasip2 && cargo test -p rustledger-ffi-component-tests— 13 ✅ (incl. the 2 new synth parity tests)Out of scope (follow-ups)
validate: falseto scope this to the synth bug).🤖 Generated with Claude Code