Repository navigation
fix(extract): let importers.toml configure the OFX importer - #2261
Conversation
`importers.toml` could not reach the OFX importer at all, and the two dispatch paths failed in opposite directions. Closes #2260. - `--importer <name>` forced `CsvImporter` unconditionally, so naming an OFX statement's entry parsed the file as CSV: "missing date column", zero transactions. - Without `--importer`, extension dispatch reached `OfxImporter`, which took the minimal-config branch and built its config from CLI arguments alone. A matching entry's `account` was silently discarded and every posting landed on the `--account` default. Entries now declare their format with `type = "csv"` (default) or `type = "ofx"`, and `select_importer` dispatches on it. The older force-CSV behavior is preserved for entries that declare nothing, which is what keeps a CSV entry's column mappings from being dropped when its file happens to be named `.ofx` — the regression the existing tests guard. The non-CSV branch now takes `account`/`currency` from a resolved entry, falling back to CLI arguments. Entry values are authoritative when an entry applies, matching `build_config_from_entry` on the CSV path, which builds purely from the entry and does not merge CLI arguments. `ImporterEntry` gains `deny_unknown_fields`. Before this, `type = "ofx"` parsed fine and did nothing, and so did any typo; a silently-ignored key is indistinguishable from a working one. An unrecognized `type` value is an error rather than a silent fallback to CSV. Entry resolution warns rather than fails in the non-CSV branch. WASM importers share it, and erroring would fail a `--wasm-importer` run whose config simply has no entry matching the file — something that worked before. The warning keeps the fallback visible instead of silent, which was the actual complaint. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟡 Changes recommended
type validation is not consistently enforced across all config-consumer paths (e.g., build_config_from_entry can still silently ignore invalid type values without an explicit validation call).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes rledger extract’s importer selection so importers.toml can correctly configure the built-in OFX/QFX importer, especially when --importer <name> is used. It introduces an explicit per-entry format declaration (type = "csv" default, or type = "ofx") and ensures non-CSV dispatch paths can consume entry-derived account/currency values instead of silently falling back to CLI defaults.
Changes:
- Added
type/format support toimporters.tomlentries (with strict TOML parsing viadeny_unknown_fields) and introducedEntryFormatparsing/validation. - Updated
select_importerso--importerno longer forces CSV unconditionally; it can dispatch to OFX when the chosen entry declarestype = "ofx". - Updated the non-CSV config path to use entry-derived
account/currency(falling back to CLI args with a warning when config resolution fails).
File summaries
| File | Description |
|---|---|
| crates/rustledger/src/cmd/extract_cmd/mod.rs | Adds minimal-entry resolution for dispatch/config and updates importer selection to respect entry-declared format under --importer. |
| crates/rustledger-importer/src/toml_entry.rs | Extends ImporterEntry schema with type, rejects unknown keys, and adds EntryFormat + validation logic and tests. |
Review details
Suppressed comments (2)
crates/rustledger-importer/src/toml_entry.rs:223
entry_format()accepts"qfx"as an alias for OFX, but the error message claims the only valid non-CSV value is"ofx". The message should list all accepted values to avoid misleading users.
Some(other) => Err(anyhow::anyhow!(
"importer '{}': unknown type '{other}' (expected \"csv\" or \"ofx\")",
self.name
)),
crates/rustledger/src/cmd/extract_cmd/mod.rs:669
- The
select_importerrustdoc still says--importeralways forcesCsvImporter, but the implementation now dispatches toOfxImporterwhen the chosen entry declarestype = "ofx". This comment is now misleading.
/// - If the user explicitly chose a TOML entry (`--importer <name>`),
/// force [`CsvImporter`]: TOML profiles are CSV-only by definition
/// of [`rustledger_importer::config::ImporterType`] today, and the
/// profile's column mappings would be lost if registry-identify
/// silently routed the file to a different engine (e.g. a
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
📊 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?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Copilot review on #2261, both valid. `type` was validated only where `entry_format()` was called, at CLI dispatch. `build_config_from_entry` is the other consumer — the WASI component's importer interface calls it without going through the CLI dispatcher — and never called it, so `type = "nonsense"` stayed accepted and ignored on that path. That is the exact silent-misconfiguration failure the field was added to end. It now validates there as well. An `ofx` entry is not rejected by that function: `account` and `currency` are meaningful to it and the unused column fields are simply absent from the built config. Only an unrecognized value errors. Also documented the `qfx` spelling on the field. `entry_format()` accepted it while the doc named only `csv` and `ofx`, which is precisely the mismatch a user with Quicken exports would hit. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
* feat(extract): refuse an unconfigured liability import Closes #2256. An OFX statement states which side of the balance sheet it describes. #2259 used that to warn when the configured account contradicts it. This covers the case underneath: when nothing configured an account at all. Importing a credit-card statement with no `--account`, no importers.toml entry and no `--ledger` profile posted it to the `Assets:Bank:Checking` default, inverting the sign of every transaction and using an account the user never named. That is now refused, with the three ways to name one. The account argument becomes `Option<String>` rather than carrying a clap default, because "not named" and "named as the default" are genuinely different and only the first is refused. Comparing against the default string instead would have refused an explicit `-a Assets:Bank:Checking` while merely warning about `-a Assets:Foo`, which is arbitrary. A test pins that clap and the guard share one constant. Deliberately not the account NAME inference the issue also asked about. `Liabilities:CreditCard` is a guess about someone's chart of accounts, not a fact in the file, and the module already refuses to guess a currency for the same reason. Since the issue was filed, #2261 and #2262 gave two ways to supply the account without repeating it, so the case for inventing a name is weaker than it was; the reasoning is recorded on the issue. Four tests, and the refusal test fails with the guard disabled. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr * fix(extract): the refusal must consider every account source Copilot review on #2263, plus the rustdoc failure it exposed. The guard's comment said "no --account, no importers.toml entry, no --ledger profile", but the code checked only `args.account`. An entry or profile naming the same string as the default was therefore treated as "nobody named an account" and the import refused. The comment described the intent; the code implemented a third of it. All three sources now collapse into one `named_account` binding, used both to build the config and to decide the refusal, so the two cannot disagree about what was named. Also: - The rustdoc build failed: the public `account` field linked to `DEFAULT_ACCOUNT` and `Args::account_or_default`, both private. Named in prose instead. `cargo clippy` and `cargo test` do not catch this; `cargo doc -D warnings` does, and it is now run before pushing. - The `DEFAULT_ACCOUNT` comment still called it "the clap default" after the clap default was removed. One test, which fails with the guard reverted to the args-only check. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Minor bump because two of the five commits are breaking under 0.x semver: - importers.toml entries reject unknown keys (#2261). A config carrying a stray key now fails to parse instead of ignoring it. That is the point of the change, but it breaks configs that were quietly wrong. - extract refuses an OFX credit-card statement when nothing named an account (#2263), rather than posting it to the Assets default with every sign inverted. Bumped with `cargo set-version 0.24.0`, plus the three surfaces it does not reach: mcp-server package.json version only (the @rustledger/wasm dependency and package-lock.json stay put, as release-publish.yml sets both from the tag), the rpm spec Version/Source0/%setup, and all eight standalone lockfiles enumerated from git rather than a hand-kept list. Pre-flight: check-publish-crates.py --check-registry reports 17/17 crates present on crates.io; workspace check with --all-features --all-targets, mcp-server npm ci + tsc, and wasm-pack build all pass. Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Closes #2260.
importers.tomlcould not reach the OFX importer at all. The two dispatch paths failed in opposite directions, so there was no invocation that worked:rledger extract card.qfxaccountsilently discarded, postings on the--accountdefaultrledger extract card.qfx --importer cardAfter, with
type = "ofx"on the entry, both giveLiabilities:CreditCard.Changes
Entries declare their format.
type = "csv"(default) ortype = "ofx", andselect_importerdispatches on it instead of forcingCsvImporterwhenever--importeris present.The old force-CSV behavior is kept for entries that declare nothing. That is deliberate: it is what stops a CSV entry's column mappings being dropped when its file happens to be named
.ofx, which is the regression the existingtest_select_importer_explicit_importer_flag_forces_csv_even_on_ofx_fileguards. Both cases are now pinned by tests.The non-CSV branch reads the entry.
account/currencycome from a resolved entry, falling back to CLI arguments. Entry values are authoritative when an entry applies — matchingbuild_config_from_entryon the CSV path, which builds purely from the entry and does not merge CLI arguments.deny_unknown_fieldsonImporterEntry. Before this,type = "ofx"parsed fine and did nothing, and so did any typo. I hit this myself while investigating: my first test config hadtype = "ofx"and I assumed it worked. An unrecognizedtypevalue is likewise an error rather than a silent fallback to CSV.Behavior notes
Entry resolution warns rather than fails in the non-CSV branch:
WASM importers share that branch, and erroring would fail a
--wasm-importerrun whose config simply has no entry matching the file — something that worked before. Falling back keeps that working while making the fallback visible, which was the actual complaint.deny_unknown_fieldsis a breaking change for malformed configs. A config carrying a stray key now fails to parse instead of silently ignoring it. That is the point, but it will surface in configs that were quietly wrong.Tests
676 pass across both crates. New:
select_importer_honors_an_ofx_entry_typeselect_importer_still_forces_csv_for_an_untyped_entry(the older guard, bothNoneand explicitCsv)entry_format_defaults_to_csv_and_reads_ofxentry_format_rejects_an_unknown_typeunknown_keys_are_rejectedVerified not vacuous: removing
deny_unknown_fieldsand makingentry_formatfall back to CSV failsunknown_keys_are_rejectedandentry_format_rejects_an_unknown_type.Worth flagging for reviewers:
cargo test -p rustledger-importersilently skips the entiretoml_entrymodule, which is behind thetoml-configfeature — 163 tests run and none of them are these.--all-featuresis required to see them.Interaction with #2259
That PR warns when a statement's account type contradicts the configured account. Until this fix, it warned against the CLI default rather than the user's configured account, so a correct
importers.tomlstill produced a mismatch warning. With both, the warning is silent for a correctly configured OFX entry — confirmed by hand.