Repository navigation
fix(price): late Copilot review on PR #983 (commodity as-of + ordered attempts) - #984
Merged
Merged
Conversation
PR #983 merged before three Copilot inline comments were addressed. Following up here: 1. (discovery.rs) `as_of` was only applied to the active-balance walk; the Commodity directive walk was unfiltered, so a commodity declared after the cutoff with `price:` metadata still triggered discovery. Add the missing filter, matching beanprice's `find_currencies_declared`'s `entry.date >= date: break` rule (commodity declared ON OR AFTER cutoff is excluded). Verified against the actual upstream source. New test: as_of_filters_commodity_directives_before_walking_them. 2. (bean_price_compat.rs) The harness's resolve-attempts comparison used `BTreeSet`, which discarded fallback-chain order. A regression that swapped `[ecbrates(GBP-EUR), ecb(GBP)]` to `[ecb(GBP), ecbrates(GBP-EUR)]` would silently pass. Switch to `BTreeMap<(symbol, currency), Vec<(source, ticker)>>` — keys still sorted (deterministic comparison), value `Vec` preserves chain order so swaps fail the test. 3. (Copilot's third comment about adding fallback-chain fixtures) Investigated and documented as not currently feasible: bean-price parses `price:` as `<curr>:<src1>,<src2>,...` (one currency block with multiple sources), while rledger parses it as `<curr>:<src>/<ticker>,<curr>:<src>/<ticker>,...` (each entry repeats the currency, per #963/#970). The two formats are incompatible — bean-price errors on rledger's syntax with "Invalid source name". So the differential harness can't currently exercise rledger's fallback-chain behavior end-to-end. The `Vec`-valued data structure is still load-bearing: when both binaries can speak the same chain syntax (a follow-up to extend rledger's parser to also accept bean-price's form), the harness will catch order regressions for free. Documented this in a comment where the fixture would otherwise live. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Follow-up fixes for the price command after PR #983 merged: ensures commodity discovery respects --date cutoffs consistently with upstream bean-price, and tightens the bean-price compatibility harness so fallback-chain ordering regressions are detectable.
Changes:
- Filter
Commoditydirectives byas_of(--date) during discovery so directives dated on/after the cutoff don’t influence historical fetch plans. - Change the compat harness’ resolved-attempt comparison from set semantics to an ordered per-(symbol,currency) chain representation.
- Add a regression test covering the commodity-directive cutoff behavior, and document why fallback-chain fixtures aren’t currently feasible in the differential harness.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/rustledger/tests/bean_price_compat.rs |
Preserves fallback-chain order in attempt comparisons by switching to a BTreeMap of ordered vectors. |
crates/rustledger/src/cmd/price/discovery.rs |
Applies as_of filtering to commodity directives during discovery and adds a regression test for the cutoff semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-05-03)
What do these numbers mean?
|
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 99% |
| BQL Compatibility | 91% |
| 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
…e syntaxes
After my previous comment claimed the formats were incompatible, the
maintainer pointed out that they could be unified. They were right.
Disambiguation rule: a comma-separated source entry is in rledger's
redundant per-entry form if and only if its part BEFORE the first `/`
contains `:`. Otherwise it's bean-price's bare `<source>/<ticker>` form
and inherits the surrounding currency block.
Strategy:
1. Split on whitespace/`;` → currency blocks (bean-price multi-currency)
2. Each block: `<currency>:<sources_part>`
3. sources_part: comma-separated entries, each either:
- `<source>/<ticker>` (inherits block currency), or
- `<currency>:<source>/<ticker>` (rledger's redundant form, overrides
block currency)
Handles all of these natively without a mode flag:
USD:yahoo/AAPL
USD:yahoo/AAPL,google/AAPL (bean-price multi-source)
USD:yahoo/AAPL,USD:google/AAPL (rledger redundant)
EUR:ecbrates/GBP-EUR,ecb/GBP (bean-price chain)
USD:yahoo/AAPL CAD:google/AAPL (bean-price multi-currency)
USD:google/NASDAQ:AAPL (ticker contains ':')
New parser tests cover each variant + the embedded-colon-in-ticker case.
Harness fallback fixture restored — both binaries now parse the same
chain syntax. Used yahoo/oanda for sources (both ship in beanprice's
sources/). Pass `--inactive` on both invocations so the resolution
test isn't gated on bean-price's discovery filter.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…urrency limitation Two findings from a re-read of #984: 1. parse_price_metadata's match arm did a redundant double-split: the first match captured `before_slash` from `entry.split_once('/')` then immediately threw away its second component and re-split `entry` to recover an `after_first_colon`. Replaced with a single split that produces all three values (currency, source, ticker) directly. Same behavior, less work, easier to read. 2. Multi-currency `price:` metadata (e.g. `USD:yahoo/AAPL CAD:google/AAPL`) parses correctly into 2 specs, but downstream `build_mapping` and `DiscoveredCommodity.quote_currency` only retain the first spec's currency — so today rledger fetches a multi-currency commodity in only one of its declared quotes. Bean-price emits one job per (base, quote). Pre-existing limitation surfaced by my parser change; documented inline near the relevant test, not fixed here. Tracked as a follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
9 tasks done
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
PR #983 merged before three Copilot inline comments arrived. Following up here.
What's in this PR
1. Commodity directive walk now respects
--dateas_ofwas only applied to the active-balance helper indiscovery.rs; theCommoditydirective walk itself was unfiltered. So a commodity declared after the cutoff (e.g.2030-01-01 commodity FUTURECOINwithprice:metadata) still triggered discovery onrledger price --date 2024-06-01.Fixed to match upstream
beanprice/price.py::find_currencies_declared's rule:Verified against the actual upstream source. Comparison is exclusive (
>=skips), so a commodity declared on the as-of date itself is excluded — matches bean-price exactly.New test:
as_of_filters_commodity_directives_before_walking_them.2. Harness preserves fallback-chain order
The resolve-attempts comparison previously used
BTreeSet<(symbol, currency, source, ticker)>, which threw away per-symbol ordering. A regression that swapped[ecbrates(GBP-EUR), ecb(GBP)]to[ecb(GBP), ecbrates(GBP-EUR)]would silently pass.Switched to:
BTreeMapkeys keep cross-symbol ordering deterministic; theVecvalue preserves chain order, so swaps fail the test.3. Fallback-chain fixture: investigated, not feasible
Copilot's third comment asked for a fallback-chain fixture. Investigated — turns out bean-price and rledger have incompatible
price:metadata syntaxes:<curr>:<src1>,<src2>,...(one currency block, comma-separated sources)<curr>:<src>/<ticker>,<curr>:<src>/<ticker>,...(each entry repeats the currency, per [Bug]: price download fallbacks ignored #963/fix(price): preserve per-spec tickers in fallback chains (closes #963) #970)bean-price errors with
Invalid source name: "EUR:ecb/GBP"when given rledger's syntax. Documented this in a comment where the fixture would otherwise live; chain order is unit-tested incmd/price_cmd.rs::tests::describe_attempts_*instead.The
Vec-valued data structure remains load-bearing: when both binaries can speak the same chain syntax (extending rledger's parser to also accept bean-price's form is a follow-up), the harness will catch order regressions for free.Test plan
cargo test -p rustledger --libpasses (262 + 1 new = 263)cargo test -p rustledger --test bean_price_compatpasses (5)cargo clippy --all-features --all-targets -- -D warningscleancargo fmt --all -- --checkclean