Repository navigation
fix(price): config quote_currency, dotted-ticker discovery (closes #952) - #953
Merged
Merged
Conversation
Issue #952 surfaced three distinct gaps in the price command after #951 landed metadata-driven discovery. This PR addresses two of them; the third (Yahoo returning a TRY/GBP cross-rate when EUR was requested) needs a reproducer from the user and is being followed up separately. 1. **`[price.mapping.X] quote_currency` was silently ignored.** The user wrote `[price.mapping.AUD] currency = "EUR"` and got USD prices because: - Our `CommodityMapping::Detailed` had no `currency`/`quote_currency` field at all, so the value was dropped at deserialization. - The struct didn't enforce `deny_unknown_fields`, so the typo passed silently. Fix is two-fold: - Pull `Detailed` out of the inline `untagged` enum variant into its own `DetailedMapping` struct so it can carry `#[serde(deny_unknown_fields)]`. Future typos error at config load with a clear "unknown field" diagnostic. - Add a `quote_currency: Option<String>` field. Per-symbol quote currency from config now resolves with the same precedence as the ledger-side `quote_currency:` metadata added in #948. New `resolve_quote_currency` helper centralizes the high-to-low precedence lookup (discovered metadata, then config mapping, then global `--currency`) so the network and `--source-cmd` paths apply it identically. 2. **Exchange-suffixed tickers (`VECP.AS`, `BRK.B`, `7203.T`) were silently skipped.** The `looks_like_ticker` heuristic in `discovery.rs` rejected `.` even though beancount's commodity grammar permits it. Added `.` to the allowed character set, and extended the existing test. Tests: - `test_parse_commodity_mapping_with_quote_currency` — config field round-trips through TOML deserialization. - `test_parse_commodity_mapping_rejects_unknown_field` — the `currency = "EUR"` typo now errors instead of being dropped. - 4 new `resolve_quote_currency` unit tests covering each level of the precedence chain. - Existing `ticker_heuristic_rejects_long_or_lowercase` extended with `VECP.AS`, `BRK.B`, `7203.T`. Docs: - `docs/commands/price.md` config example shows `quote_currency = "EUR"`. New "Quote currency resolution" section enumerates the three-step precedence and notes that unknown keys now error. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR closes gaps in the price command’s configuration and discovery logic identified in #952, aligning behavior between config, ledger metadata discovery, and ticker heuristics.
Changes:
- Add
quote_currencysupport to per-commodity[price.mapping.X]config by introducing a dedicatedDetailedMapping(withdeny_unknown_fieldsto prevent silent typos likecurrency = ...). - Centralize quote-currency precedence via
resolve_quote_currencyand apply it to both network fetch and--source-cmdpaths. - Expand ticker discovery heuristic to allow dotted tickers (e.g.,
VECP.AS,BRK.B,7203.T) and extend tests/docs accordingly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| docs/commands/price.md | Documents quote-currency precedence and updates config examples; notes unknown-key rejection. |
| crates/rustledger/src/config.rs | Adds DetailedMapping with quote_currency and deny_unknown_fields; updates parsing tests and adds new ones. |
| crates/rustledger/src/cmd/price_cmd.rs | Introduces resolve_quote_currency helper; threads effective currency through cache + fetch paths; adds unit tests. |
| crates/rustledger/src/cmd/price/mod.rs | Updates mapping resolution code/tests to new DetailedMapping shape. |
| crates/rustledger/src/cmd/price/discovery.rs | Allows . in ticker heuristic; updates discovery mapping construction for new struct; extends tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-04-29)
What do these numbers mean?
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Self-review found five small improvements: 1. `test_parse_commodity_mapping_rejects_unknown_field` now asserts the error message references the bad block (AUD) or mentions the unknown-field reason, not just `is_err()`. 2. New `test_resolve_quote_currency_detailed_without_quote_currency_uses_default` covers the most common shape: a `[price.mapping.X]` block with `source = "..."` and no `quote_currency` falls through to the global default. 3. Code comment at the `--source-cmd` callsite explains why it passes `&price_config.mapping` instead of the merged `combined_mapping` (CLI `--mapping` only creates `Simple` entries with no quote_currency, so merging wouldn't add anything for currency resolution). 4. Code comment in `looks_like_ticker` documents the deliberate permissiveness about leading characters (`7203.T` legitimately starts with a digit) so a future maintainer doesn't tighten it and break valid tickers. 5. PR description amended to reflect actual test count (separate edit). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…opilot #953) Copilot review on PR #953 caught a real precedence bug. With the network path passing `&combined_mapping` to `resolve_quote_currency`, a CLI override like `--mapping AUD:NEW-TICKER` overwrites the config-file `Detailed` entry with `Simple` in the merged map and silently drops the config's `quote_currency`. The user's intended override was the ticker only, but the merge took the currency with it. Fix: resolve quote currency against `&price_config.mapping` (the raw config map) on both the network and `--source-cmd` paths. Source/ticker lookup still uses the merged map further down — only currency resolution stays config-only, matching the documented precedence "config quote_currency wins over global default". Updated the call-site comments in both paths to record the contract: "use the raw config map so a CLI Simple override can't wipe out a Detailed.quote_currency". New regression test `test_resolve_quote_currency_uses_raw_config_not_merged_mapping` locks in the helper-level invariant. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 99% |
| BQL Compatibility | 85% |
| Full AST Match | 99% |
| Total Files | 782 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #952 surfaced three gaps in the price command after #951 landed metadata-driven discovery. This PR addresses two of them; the third (Yahoo returning a TRY/GBP cross-rate when EUR was requested) needs a reproducer from the user and is being followed up separately.
Changes
1.
[price.mapping.X] quote_currency(was:currency) is now honoredThe user wrote:
and got USD prices. Two reasons:
CommodityMapping::Detailedhad no quote-currency field at all. The value was dropped silently at deserialization.deny_unknown_fields, so the typo passed without warning.Fix:
Detailedout of the inlineuntaggedenum variant into its ownDetailedMappingstruct so it can carry#[serde(deny_unknown_fields)]. Future typos error at config load with a clear "unknown field" diagnostic.quote_currency: Option<String>field. Per-symbol quote currency from config now resolves with the same precedence as the ledger-sidequote_currency:metadata added in [Feature]: Get Symbols from active commodities #948.New
resolve_quote_currencyhelper centralizes the precedence chain so the network and--source-cmdpaths apply it identically. High-to-low:quote_currency:/ firstprice:entry from a commodity directivequote_currency = "..."in[price.mapping.X](this PR)--currencyflag2. Exchange-suffixed tickers like
VECP.AS,BRK.B,7203.Twere silently skippedThe
looks_like_tickerheuristic indiscovery.rsrejected.even though beancount's commodity grammar permits it. Added.to the allowed character set; extended the existing test.Tests
7 new test functions:
test_parse_commodity_mapping_with_quote_currency— config field round-trips through TOML deserialization.test_parse_commodity_mapping_rejects_unknown_field— thecurrency = "EUR"typo errors at load, with the error message referencing the bad block.resolve_quote_currencyunit tests covering each level of the precedence chain (discovery wins over config, config wins over default, default fallback for empty maps, default fallback forDetailed { quote_currency: None }, Simple-mapping carries no currency).Plus 3 new assertions in the existing
ticker_heuristic_rejects_long_or_lowercase:VECP.AS,BRK.B,7203.T.Docs
docs/commands/price.md:quote_currency = "EUR"on[price.mapping.AUD].[price.mapping.X]blocks reject unknown keys with an explicit error.Migration impact
This is a small wire-format tightening: previously-permissive configs that contained typos under
[price.mapping.X](e.g.currencyinstead ofquote_currency) now fail loud at config load. Real-world impact is low because typos in those blocks were silently dropping the user's intent anyway, so loud failure is strictly better.Out of scope
The user's third report (
2026-04-29 price TRY 311.0 GBPreturned for a USD-quoted query) is not addressed here. It looks like a Yahoo Finance source-side quirk; needs a reproducer from the user with-v --no-cacheoutput and the relevant config block.Verification
cargo test -p rustledger: 232 + 27 + 43 + 7 + 65 + 17 = 391 tests pass (was 384, +7 new test functions plus assertion updates)cargo clippy --all-features --all-targets -- -D warnings: cleancargo fmt --check: cleanTest plan
rledger price AUD -bwith[price.mapping.AUD] source = "ecb", quote_currency = "EUR"returns EUR-quoted price (was returning USD)[price.mapping.AUD] currency = "EUR"(typo) errors at config load with a clear messagerledger price -f main.beancountpicks upcommodity VECP.AS(was silently skipped)Closes #952
🤖 Generated with Claude Code