Skip to content

fix(extract): let importers.toml configure the OFX importer - #2261

Merged
robcohen merged 2 commits into
mainfrom
fix/importers-toml-ofx-entries
Sep 5, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/importers-toml-ofx-entries

Conversation

@robcohen

@robcohen robcohen commented Sep 5, 2026

Copy link
Copy Markdown
Member

Closes #2260.

importers.toml could not reach the OFX importer at all. The two dispatch paths failed in opposite directions, so there was no invocation that worked:

before result
rledger extract card.qfx OFX parsed correctly, entry's account silently discarded, postings on the --account default
rledger extract card.qfx --importer card entry found, then CSV parsed the OFX file → "missing date column", zero transactions

After, with type = "ofx" on the entry, both give Liabilities:CreditCard.

Changes

Entries declare their format. type = "csv" (default) or type = "ofx", and select_importer dispatches on it instead of forcing CsvImporter whenever --importer is 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 existing test_select_importer_explicit_importer_flag_forces_csv_even_on_ofx_file guards. Both cases are now pinned by tests.

The non-CSV branch reads the entry. account/currency come 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.

deny_unknown_fields on ImporterEntry. Before this, type = "ofx" parsed fine and did nothing, and so did any typo. I hit this myself while investigating: my first test config had type = "ofx" and I assumed it worked. An unrecognized type value is likewise an error rather than a silent fallback to CSV.

Behavior notes

Entry resolution warns rather than fails in the non-CSV branch:

warning: could not apply importers.toml (importer 'card': unknown type 'nonsense'
         (expected "csv" or "ofx")); using --account/--currency instead

WASM importers share that branch, and erroring would fail a --wasm-importer run 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_fields is 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_type
  • select_importer_still_forces_csv_for_an_untyped_entry (the older guard, both None and explicit Csv)
  • entry_format_defaults_to_csv_and_reads_ofx
  • entry_format_rejects_an_unknown_type
  • unknown_keys_are_rejected

Verified not vacuous: removing deny_unknown_fields and making entry_format fall back to CSV fails unknown_keys_are_rejected and entry_format_rejects_an_unknown_type.

Worth flagging for reviewers: cargo test -p rustledger-importer silently skips the entire toml_entry module, which is behind the toml-config feature — 163 tests run and none of them are these. --all-features is 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.toml still produced a mismatch warning. With both, the warning is silent for a correctly configured OFX entry — confirmed by hand.

`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
@robcohen
robcohen requested a review from a team as a code owner September 5, 2026 03:02
Copilot AI lite review requested due to automatic review settings September 5, 2026 03:02
@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.20000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger/src/cmd/extract_cmd/mod.rs 92.50% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 to importers.toml entries (with strict TOML parsing via deny_unknown_fields) and introduced EntryFormat parsing/validation.
  • Updated select_importer so --importer no longer forces CSV unconditionally; it can dispatch to OFX when the chosen entry declares type = "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_importer rustdoc still says --importer always forces CsvImporter, but the implementation now dispatches to OfxImporter when the chosen entry declares type = "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.

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 45.8ms ± 2.4ms 716.6ms ± 8.1ms 15.6x 55.1 MB / 50.1 MB
investment 67.3ms ± 1.9ms 2879.0ms ± 283.6ms 42.8x 61.0 MB / 58.1 MB
fifo 65.0ms ± 1.8ms 15695.3ms ± 11.6ms 241.6x 61.1 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 46.2ms ± 4.6ms 45.8ms ± 2.4ms -0.8% ✅ within noise 54.9 MB → 55.1 MB (+0.2%)
investment 67.4ms ± 0.5ms 67.3ms ± 1.9ms -0.1% ✅ within noise 61.2 MB → 61.0 MB (-0.4%)
fifo 69.0ms ± 5.3ms 65.0ms ± 1.8ms -5.9% 🟢 faster 61.0 MB → 61.1 MB (+0.2%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 2.3ms, investment 0.9ms, fifo 2.5ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 99% (raw 93%, 169 masked)
Full AST Match 100%
Total Files 812
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

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
@robcohen
robcohen enabled auto-merge (squash) September 5, 2026 09:56
@robcohen
robcohen merged commit e01714e into main Sep 5, 2026
50 checks passed
@robcohen
robcohen deleted the fix/importers-toml-ofx-entries branch September 5, 2026 10:19
robcohen added a commit that referenced this pull request Sep 6, 2026
* 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]>
robcohen added a commit that referenced this pull request Sep 6, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

importers.toml cannot configure the OFX importer: named entries force the CSV parser, unnamed ones ignore the config

2 participants