Repository navigation
feat: expose import over the component boundary (WIT 3.5.0) - #1764
Conversation
The import engine (CSV auto-inference, OFX, categorization, dedup) was reachable only through `rledger extract` — rustfava's import UI runs Python beangulp and the WASI component had no import surface, so every GUI user was cut off from the Rust machinery (import review, roadmap "import over the component boundary"). This adds an `importer` interface to the `rustledger:ledger` world (3.4.0 -> 3.5.0, additive): - identify(filename, content) — builtin recognition by extension with an OFX/CSV content sniff for misnamed downloads; - infer(filename, content) — CSV auto-inference returning an `importers.toml` entry (bare TOML table) that round-trips into extract, so a host can show it, let the user edit, and pass it back; - extract(filename, content, config) — CSV/OFX extraction from bytes, entries carrying the statement filename as provenance. The `[[importers]]` entry schema moves from the CLI into `rustledger-importer::toml_entry` (feature `toml-config`) so both surfaces share ONE canonical config parser instead of the component re-deriving it (Phase-3 discipline); the CLI now consumes the moved module, including `parse_amount_locale`. The `.wasm` plugin-importer runtime stays host-side — a component cannot host nested guests. Verified end-to-end: the wasip2 component builds and the parity suite (21 tests) passes against it, including a new importer_extract_matches_native_engine drift guard; API_VERSION "3.5" stays in lockstep with the WIT package (parity-enforced). Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📊 Benchmark Results
vs main branch (2026-07-11)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
This PR exposes the existing rledger extract import engine (CSV inference + CSV/OFX extraction) over the WASI Component Model boundary by adding a new importer interface to the rustledger:ledger WIT world and implementing it in rustledger-ffi-component. It also centralizes the [[importers]] TOML entry schema + config mapping in rustledger-importer so the CLI and component share one canonical parser.
Changes:
- Bump WIT world version to
rustledger:[email protected]and add an exportedimporterinterface (identify,infer,extract). - Introduce
rustledger_importer::toml_entry(feature-gatedtoml-config) as the canonical parser/mapping for a single importer entry, reused by CLI + component. - Add component/native parity and unit tests covering identify/infer/extract flows.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger/src/cmd/extract_cmd/mod.rs | Switches CLI locale parsing/tests to use the canonical toml_entry module. |
| crates/rustledger/src/cmd/extract_cmd/config.rs | Keeps CLI-side config discovery/wrapper while re-exporting canonical entry/schema helpers. |
| crates/rustledger/Cargo.toml | Enables rustledger-importer’s toml-config feature for the CLI crate. |
| crates/rustledger-importer/src/toml_entry.rs | Adds canonical importers.toml entry schema, parsing, config building, and inference→TOML rendering. |
| crates/rustledger-importer/src/lib.rs | Exposes toml_entry behind the toml-config feature. |
| crates/rustledger-importer/Cargo.toml | Adds the toml-config feature (optional serde + toml). |
| crates/rustledger-ffi-component/wit/world.wit | Bumps package to 3.5.0 and defines the new importer interface. |
| crates/rustledger-ffi-component/src/lib.rs | Implements and exports the new importer guest interface; bumps runtime API version to 3.5. |
| crates/rustledger-ffi-component/src/convert.rs | Implements importer identify/infer/extract logic bridging bytes + canonical config parsing. |
| crates/rustledger-ffi-component/Cargo.toml | Adds rustledger-importer dependency with toml-config for importer interface support. |
| crates/rustledger-ffi-component-tests/tests/parity.rs | Adds a parity/drift-guard test comparing component extraction vs native importer engine. |
| crates/rustledger-ffi-component-tests/Cargo.toml | Enables toml-config on rustledger-importer for the parity test. |
| Cargo.lock | Records new dependency edges and adds toml as a resolved dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Four confirmed correctness bugs and three test/CI-quality findings from the multi-agent review of #1764: - Format dispatch is now the canonical rustledger_importer::detect_format, with the extension AUTHORITATIVE when recognized: a .csv whose narration mentions "<OFX" stays on the CSV path (the sniff previously overrode the extension, and the WIT surface had no way to force CSV). The policy lives in the importer crate so it cannot drift per-surface. - currency defaults to USD in the component's extract, matching the schema's documented default (the CLI injects it via --currency); an account-only entry no longer errors on OFX. - Non-UTF-8 content is decoded lossily in extract, consistent with identify — a Latin-1 OFX 1.x download (CHARSET:1252) degrades to replacement characters instead of dead-ending a file identify just recognized. - A mistyped column value (amount_column = 2.0) is now an ERROR naming the field instead of a silent fallback to the default column — on the CLI too, where it was previously ignored. - The parity drift guard compares dates/narrations/postings/warnings field-by-field, not entry counts (drift-guard rule: assert the exact observable). - New drift test pins the TOML round-trip path against the canonical InferredCsvConfig::to_csv_config mapping, plus a test pinning the inference-never-emits-Index-secondary-date invariant the TOML serializer relies on. - The component-parity CI job now greps its output for the graceful skip marker and fails loudly if the suite skipped despite the component having been built (availability-gated-tests rule). Co-Authored-By: Claude Fable 5 <[email protected]>
- OFX extraction now requires account in the config entry instead of silently importing into the builder's Expenses:Unknown default. - entry_toml_from_inferred returns Result rather than swallowing a serialization error into an empty string. - Grammar/spelling nits in the config.rs module comment. Co-Authored-By: Claude Fable 5 <[email protected]>
The version gate is right: 3.5.0 landed on main in #1764, so this PR's interface additions need their own minor. API_VERSION tracks it (parity-enforced). Co-Authored-By: Claude Fable 5 <[email protected]>
* feat: dedup + format-loaded on the component import surface Closes the two gaps a rustfava ingest backend would hit immediately (walked the fava import flow end-to-end against 3.5.0 before cutting the release): - importer.dedup(candidates, existing) -> list<bool> flags duplicate entries via the canonical rustledger_ops::dedup::is_duplicate — the same fuzzy matcher 'rledger extract --existing' filters with, so the review UI and the CLI agree on what counts as a duplicate. Per-candidate conversion keeps flags aligned with input order even when a candidate fails conversion. - format.format-loaded(entries) renders LOADED directives (extract output, session entries) to canonical beancount text, with the loaded->input down-conversion inside the component — previously only input-directive could be formatted, forcing hosts to reshape directives themselves to save extracted entries. Both land in the still-unreleased 3.5.0. Parity suite (21 tests) passes against the rebuilt wasip2 component, now exercising the full extract -> dedup -> format-loaded loop. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: bump WIT contract to 3.6.0 for dedup/format-loaded The version gate is right: 3.5.0 landed on main in #1764, so this PR's interface additions need their own minor. API_VERSION tracks it (parity-enforced). Co-Authored-By: Claude Fable 5 <[email protected]> * feat: session-held dedup, structured import warnings (WIT deep dive) Redesigns the 3.6.0 additions per the WIT design review before anything ships: - dedup moves from importer.dedup(candidates, existing) to session.dedup(candidates). One move fixes three findings: the host no longer re-marshals the full ledger per import (the exact pattern the session resource exists to kill); the held side's conversion-drop policy is the documented, info()-observable from-entries one instead of a silent comparison-set shrink; and the implementation uses the batch canonical find_fuzzy_duplicates, which precomputes held keys once instead of rebuilding every key per candidate. - extract-result.warnings becomes list<error> (severity "warning", phase "extract") — the structured diagnostic record every other surface uses, so line/field attribution is additive later rather than a record-shape break. - format-loaded errors now name the failing entry index, so a host can exclude one bad entry instead of losing the whole batch. - WIT dedup doc corrected: the matcher requires the SAME date (plus amount and text similarity) — "date proximity" promised behavior the canonical does not have. - format_loaded rustdoc version tag fixed (3.6.0, not 3.5.0). - The parity dedup guard now checks a fuzzy near-miss (reworded narration) against the NATIVE matcher's verdict, not just degenerate identity/empty inputs; extract warnings assert message parity plus severity/phase. Remaining design debt (options-less entries surfaces) is tracked in issue #1766 rather than patched piecemeal here. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
Implements the top Now item from the revised importing roadmap (#1763): the import engine was reachable only through
rledger extract— rustfava imports via Python beangulp and the component had no import surface, so no GUI user could touch the Rust machinery.What
Adds an
importerinterface to therustledger:ledgerWIT world (3.4.0 → 3.5.0, additive):identify(filename, content)— builtin recognition by extension, with an OFX/CSV content sniff so misnamed downloads (e.g. an OFX body served as.txt) still resolve.infer(filename, content)— CSV auto-inference returning animporters.tomlentry as a bare TOML table that round-trips intoextract: the host shows it, the user tweaks it, it goes straight back.extract(filename, content, config)— CSV/OFX extraction from bytes (no filesystem needed); extracted entries carry the statement filename as their source location.Canonical-function discipline
The
[[importers]]entry schema moves from the CLI intorustledger_importer::toml_entry(newtoml-configfeature: serde + toml, off by default so slim builds stay slim). The CLI and the component now share one config parser — includingparse_amount_localeand the #1133 regression test, which moved with it. The.wasmplugin-importer runtime stays host-side (a component cannot host nested guests); WIT docs say so explicitly.Testing
toml_entry: entry parsing, config building, bare-table shape, inference→TOML→config round-trip, locale Debug-form round-trip.convertunit tests (native): identify by extension + sniff, infer→extract loop, OFX minimal config, malformed-config rejection.importer_extract_matches_native_enginedrift guard (component result vs native engine on identical input) and the version-lockstep test at "3.5".rustledgerCLI suite green; clippy-D warnings(all features/targets), fmt, rustdoc clean.Follow-up (separate PRs)
rustfava ingest backend consuming this interface (beangulp stays as the escape hatch); enrichment (dedup-against-session, ML suggestions) as a 3.6 addition once the UI flow exists.
🤖 Generated with Claude Code