Repository navigation
feat(importer): a transaction-id link convention for WASM importers - #2532
Conversation
A WASM importer adds a `wasm-<importer>/<id>` link, built by the new rustledger_plugin_types::wasm_id_link, and extract --existing treats it as an id like ^ofx- and ^csv-, with one namespace per importer. The id sanitizer moves to rustledger_plugin_types::id_link so guests share it; rustledger_ops::dedup::id_link delegates. A link rather than a new ImporterOutput field, which would break importers built with struct literals. Closes #2519 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
📊 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?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
The importer name was lowercased and every other character mapped to `-`, so `My Bank` and `my-bank` (or `a/b` and `a-b`) shared a namespace and one importer's id could match the other's with equal money, dropping a different transaction. Keep letters (case included), digits, `-` and `.`, and write every other byte as `_` plus two hex digits. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Review (adversarial pass)Namespace collision: a real finding, fixed in 4e08a1e. The importer name was lowercased and every other character mapped to
Cross-PR integration (applies to #2524, #2526, #2527, #2531, #2532, #2533)All six PRs were merged onto
Second review round (the injective encoding, as fresh code): no new defectsAdded 311de54:
|
Every emitted link uses only the link charset, decodes back to the importer name, and survives parse -> canonical format -> parse; different names never share a namespace (a literal `_20` is escaped again); dedup splits at the first `/` even when the id contains `/`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
…ansaction-ids # Conflicts: # CHANGELOG.md
What changed
WASM importers can now give each transaction the source format's own id, and
extract --existinguses it as identity, as it does^ofx-<FITID>and^csv-<id>.The convention: a link
wasm-<importer>/<id>, built by the new guest-side helperrustledger_plugin_types::wasm_id_link(importer, raw_id):-and.stay, and every other byte becomes_plus two hex digits (My Bank→My_20Bank,a/b→a_2Fb). So two different importer names can never share a namespace. The id is sanitized by the same rule as CSV/OFX ids.Noneis returned when either has no letter or digit.rustledger_ops::dedup) now finds an id's namespace withid_namespace. The namespaces areofx-,csv-, and one per WASM importer,wasm-<importer>/. A shared id with equal money is the same transaction on any date. Different ids within one namespace mean two transactions. Ids in different namespaces never contradict each other, so moving a bank from one importer (or format) to another falls back to text, as moving from OFX to CSV already does. Awasm-…link with no/<id>is not an id. Importers namedMy Bank,My-Bank,My_Bank,My/Bankandmy-bankget five distinct namespaces; a test pins that one's id never matches another's. Behavior forofx-/csv-is unchanged.id_linkmoved torustledger_plugin_types::id_link, since a guest cannot depend onrustledger-ops.rustledger_ops::dedup::id_linkdelegates to it, andWASM_ID_LINK_PREFIXandwasm_id_linkare re-exported fromrustledger_ops::dedup.Docs: the importing guide has a new "Transaction ids from a WASM importer" section.
wasm_importer_main!has a "Transaction ids" section, the guest module docs have "Transaction ids for duplicate detection", and the plugin-types README,docs/commands/extract.mdand the CHANGELOG are updated.Why a link convention and not an explicit id field
The issue preferred an explicit id field the host turns into a link, if that fits without a breaking change. It doesn't fit:
#[serde(default)]field onImporterOutputwould have been fine for already-built modules (serde's derived sequence decoding defaults a missing trailing#[serde(default)]field; not exercised here).ImporterOutputandEnrichedImporterOutputhave public fields and are built with struct literals in importer code.EnrichedImporterOutputhas no constructor at all (seetests/guest_macro_compiles.rs,default_enriched_from). A new field would break every importer's source, and a per-directive id would also need a parallel vector that importers keep aligned by hand.A link is a field every transaction already carries, and the helper makes the convention explicit rather than a magic string. The namespace includes the importer name so ids from different importers cannot contradict each other.
How tested
a_wasm_importer_id_link_is_an_id: a sharedwasm-mt940/1link is decisive across a date and narration change.mt940/1vsmt940/2are two transactions despite the same text.camt/2vsmt940/1, or anofx-id, fall back to text. Barewasm-1/wasm-2links are not ids.id_namespaces: every namespace shape and edge case (wasm-mt940/,wasm-/1,wasm-1).id_linkandwasm_id_link. All existingofx-/csv-id tests pass unchanged.wasm-links not recognized as ids, both new tests fail.cargo testfor plugin-types, ops, importer and rustledger (all features); workspace clippy (-D warnings); rustdoc (-D warnings) for the changed crates: clean.Closes #2519
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr