Repository navigation
feat(extract): refuse an unconfigured liability import - #2263
Conversation
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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟡 Changes recommended
The new refusal guard can incorrectly trigger even when the account was configured via importers.toml or --ledger (including to the default string), contradicting the intended “unset vs explicitly set” semantics.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens rledger extract against accidentally importing OFX/QFX liability statements (credit cards / credit lines) into the default Assets:Bank:Checking account when the user did not configure an account, preventing silent sign inversion and mis-posting.
Changes:
- Make
--accountoptional (Option<String>) and apply the default only at point-of-use viaArgs::account_or_default(). - Refuse unconfigured OFX/QFX liability imports when the default account would otherwise be used, with a prescriptive error message.
- Expose OFX statement-kind detection (
StatementKind,detect_statement_kind) for reuse by the CLI, and update docs/tests accordingly.
File summaries
| File | Description |
|---|---|
| docs/commands/extract.md | Documents the new refusal behavior for unconfigured OFX liability statements. |
| crates/rustledger/src/cmd/extract_cmd/mod.rs | Implements Option<String> for account, centralizes defaulting, adds refusal guard + tests. |
| crates/rustledger/src/bin/ag-rledger.rs | Updates struct-literal arg construction to preserve “unset” account as None. |
| crates/rustledger-importer/src/ofx_importer.rs | Exposes statement-kind detection API needed by the CLI guard. |
Review details
- Files reviewed: 4/4 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 #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
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]>
…adapter Review of #2308 (Copilot, three threads). `--balance` built its assertion from the raw flags, so an `importers.toml` entry naming `Liabilities:Card` in GBP produced postings there and a balance on `Assets:Bank:Checking` in USD — an assertion that can never hold. Even with `--account` the currency stayed USD. It now reads the resolved config, after the entry, flags, and any `--ledger` profile. This pre-dates the PR, but it is the same bug class as #2304 in the same function. Mutation-verified: reading `args` again fails the new test. `ag-rledger`'s `build_extract_args` constructs `Args` by hand, and nothing tested it against an entry: restoring a USD default there left all 14 existing tests passing. A binary-level test now checks both directions through the real binary — omitted flags keep the entry's account, currency, delimiter and skip_rows; passed flags replace them, including an explicit `--skip-rows 0`. It reads `result.stdout`, because the envelope echoes the command line and would contain the flag values either way. Restoring the currency, skip_rows or delimiter default each fails it. The `Args` field type change is source-breaking for code that constructs `Args` directly, and the crate is published. Recorded under Breaking in the CHANGELOG, together with the identical change #2263 made to `account` without an entry. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Closes #2256.
#2259 used the OFX statement kind to warn when a configured account contradicts it. This covers the case underneath: when nothing configured an account at all.
Previously that imported silently, inverting the sign of every transaction into an account the user never named.
--accountbecomesOption<String>"Not named" and "named as the default" are genuinely different, and only the first is refused. My first attempt compared the resolved account against the default string, which refused an explicit
-a Assets:Bank:Checkingwhile merely warning about-a Assets:Foo— arbitrary, and the error text claimed "no account was configured" when one had been. Modelling the absence honestly removes that.The clap default is gone;
Args::account_or_default()applies it at the point of use, and a test pins that clap and the guard share one constant, including that it is anAssets:account (which is what makes the contradiction a contradiction).What this deliberately does not do
The issue also asked to infer the account name —
CREDITCARDMSGSRSV1→Liabilities:.... Not implemented, on purpose:Liabilities:CreditCardis a guess about someone's chart of accounts, and this module already refuses to guess a currency for the same reason.opendirective metadata #2262 gave two ways to supply the account without repeating yourself — animporters.tomlentry, or anopendirective via--ledger. In the--ledgercase the account comes from the user's own chart of accounts, which is the only place the real name exists.So the remaining value was in the unconfigured path, which is what this closes. Reasoning recorded on the issue rather than left implicit.
Tests
483 pass. Four new:
Also checked by hand that CSV imports,
--ledgerprofiles,importers.tomlentries and explicit-aare all unaffected.