Repository navigation
feat(test): bean-price compat harness — symbol-set differential (refs #967) - #978
Merged
Merged
Conversation
…967) Lands the keystone deliverable from issue #967's audit: a Rust integration test that runs both `rledger price` and `bean-price -n` against a fixture beancount file and asserts they discover the same set of (symbol, quote_currency) pairs to fetch. How it works: - Fixture is written to a temp file with two declared commodities carrying `price: "USD:yahoo/SYMBOL"` metadata. - `bean-price -n` (dry-run) is parsed from its tabular output. - `rledger price -f <fixture> --source-cmd <stub>` is run with a no-op stub that returns "1.00" for any symbol — no network, no fetching. - Both symbol-sets are compared; mismatch fails the test with a useful diff in the assertion message. The harness skips (with a notice) when `bean-price` is not on PATH so contributors running `cargo test` outside `nix develop` aren't blocked. CI uses the dev shell (where #976 added beanprice), so this runs there. Note on the stub source: written into a `TempDir` with a plain file (not `NamedTempFile`) — the latter holds an open write handle and Linux refuses to exec it (ETXTBSY). Once landed, every per-candidate audit item from #967 (#967 items 1-6) can add its own fixture + assertion against this harness. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Rust integration test in crates/rustledger to differentially compare rledger price against upstream bean-price -n for symbol discovery from a beancount fixture. This supports the compatibility audit tracked in #967 by establishing a reusable test harness inside the existing CLI/test suite.
Changes:
- Introduces a
bean_price_compatintegration test that writes a temporary beancount fixture, runs both CLIs, and compares discovered(symbol, quote_currency)pairs. - Adds helper functions to detect
bean-price, create a stub external source, invoke both commands, and parse their outputs into comparable sets. - Seeds the harness with one basic fixture covering declared commodities with
price:metadata.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 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
…nd fixture Self-review fixes for PR #978: 1. Scope correction. Rename "symbol-set" -> "commodity discovery". The harness uses --source-cmd, which bypasses rledger's source-resolution layer — so it cannot validate source-precedence (audit item 5), per-spec ticker preservation (#970), or fallback chains. Module docstring now states this explicitly. Validating those needs an HTTP mock or a future --dry-run flag on rledger. 2. Switch rledger output extraction to --beancount format. Stable, documented format (`<date> price <SYM> <amt> <CCY>`); decouples the parser from whatever the stub source happens to print. 3. #![cfg(unix)]. The set_mode(0o755) call needs unix::fs::PermissionsExt; without the gate, Windows builds would fail to compile. 4. Tighten extract_bean_price_jobs: require uppercase ticker shape + uppercase currency. Previously a stray log line beginning with an identifier could be wrongly interpreted as a job. 5. New CI sanity test bean_price_must_be_on_path_in_dev_shell. Without it, removing beanprice from the flake would silently turn every compat test into a no-op (skip path) and we wouldn't notice. Gated on IN_NIX_SHELL or CI env vars to avoid false failures locally. 6. New fixture FIXTURE_MIXED_CURRENCIES (USD AAPL + EUR SAP). On its first run it found a real bug — see #979: parse_simple_format hardcodes "USD" when --source-cmd output omits a currency. The stub now echoes the requested --currency back as a workaround so the harness can land independently; #979 tracks the underlying fix. 7. Drop noise docstrings on private helpers; consolidate via assert_same_commodities helper. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
rledger parses --source-cmd through shell_words::split, so a temp directory containing whitespace would cause the path to be word-split into separate tokens and the exec to fail before discovery could be compared. Quote the path with shell_words::quote before passing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
enabled auto-merge (squash)
May 3, 2026 04:43
…shell The bean_price_must_be_on_path_in_dev_shell sanity test was gated on \`IN_NIX_SHELL OR CI\`, but CI doesn't currently run inside \`nix develop\` — so on CI the gate fired but bean-price wasn't on PATH, causing the test to fail. Drop the CI env-var trigger; only assert when actually inside the dev shell. Local devs running tests via \`nix develop\` still get the flake-regression guard; making CI also run under nix is a separate workflow change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The harness in crates/rustledger/tests/bean_price_compat.rs depends on bean-price being on PATH, which is only true inside the nix dev shell (added to the flake in #976). The main Test matrix uses dtolnay/rust-toolchain + cargo nextest directly, with no nix involved, so the harness silently skipped there. Add a dedicated bean-price-compat job that uses cachix/install-nix-action and runs `cargo test -p rustledger --test bean_price_compat` inside `nix develop`. Wire it into the build aggregator's required-results list. This ensures CI actually executes the differential tests against bean-price so a flake regression (or a real divergence between rledger and bean-price discovery) breaks the PR loudly instead of silently. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
disabled auto-merge
May 3, 2026 13:06
This reverts commit 919fee1.
Reverts the CI workflow approach (commit 919fee1, reverted in adad0b28) in favor of a local pre-push hook gated on relevant file changes. Why local instead of CI: running the harness in CI requires nix shell (for bean-price), which adds noticeable runtime to every PR. The harness mostly catches regressions in the price command's discovery layer or in the flake's beanprice packaging — both areas are touched rarely. Running the check pre-push when those specific files change concentrates the cost on the contributor making the relevant change. The hook fires when any of these change: - crates/rustledger/src/cmd/price/**, price_cmd.rs (discovery / source layer) - crates/rustledger/tests/bean_price_compat.rs (the harness itself) - flake.nix, flake.lock (could drop or break beanprice) Uses `nix develop --command cargo test ...` so bean-price is reliably on PATH; if nix isn't installed, the push fails loudly with a clear error rather than silently skipping. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 3, 2026
Two follow-ups to PR #982 / issue #967. (item 4) --date as-of for the active-commodity filter ===================================================== Before this change, `rledger price -f file.beancount --date 2020-01-01` parsed the date and passed it to source requests, but the active filter that decides which commodities to include used the LATEST balances — so a commodity bought before 2020 and sold afterward was excluded from the historical fetch. Bean-price walks the file as-of `--date` for both balance computation and price lookup; this aligns rledger. Implementation: - discover_symbols and active_commodities now take Option<NaiveDate>. - Transactions with date > as_of are skipped from the balance roll-up. - Close directives after as_of are ignored (the account WAS open then). - price_cmd.rs parses args.date once, early, and threads it into discovery (was previously parsed only later for the source request). Tests: - as_of_filter_includes_holdings_at_that_date_only - as_of_ignores_close_directive_after_cutoff (harness extension) Source-resolution differential via --dry-run ================================================================ The compat harness (#978) previously compared only commodity discovery because rledger had no equivalent of `bean-price -n`. With #982's `rledger price -n` flag now landed, the harness can compare full (symbol, currency, source, ticker) resolution between the two binaries — covering source precedence (audit item 5), per-spec ticker preservation (#970), and fallback chains (#963/#970). Adds two new tests: - rledger_and_bean_price_resolve_same_attempts_basic - rledger_and_bean_price_resolve_same_attempts_mixed_currencies Both pass against the existing FIXTURE_BASIC and FIXTURE_MIXED_CURRENCIES fixtures. Docs: - Drop the --date row from the "Differences from bean-price" table — it's no longer a divergence. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 3, 2026
Two follow-ups to PR #982 / issue #967. (item 4) --date as-of for the active-commodity filter ===================================================== Before this change, `rledger price -f file.beancount --date 2020-01-01` parsed the date and passed it to source requests, but the active filter that decides which commodities to include used the LATEST balances — so a commodity bought before 2020 and sold afterward was excluded from the historical fetch. Bean-price walks the file as-of `--date` for both balance computation and price lookup; this aligns rledger. Implementation: - discover_symbols and active_commodities now take Option<NaiveDate>. - Transactions with date > as_of are skipped from the balance roll-up. - Close directives after as_of are ignored (the account WAS open then). - price_cmd.rs parses args.date once, early, and threads it into discovery (was previously parsed only later for the source request). Tests: - as_of_filter_includes_holdings_at_that_date_only - as_of_ignores_close_directive_after_cutoff (harness extension) Source-resolution differential via --dry-run ================================================================ The compat harness (#978) previously compared only commodity discovery because rledger had no equivalent of `bean-price -n`. With #982's `rledger price -n` flag now landed, the harness can compare full (symbol, currency, source, ticker) resolution between the two binaries — covering source precedence (audit item 5), per-spec ticker preservation (#970), and fallback chains (#963/#970). Adds two new tests: - rledger_and_bean_price_resolve_same_attempts_basic - rledger_and_bean_price_resolve_same_attempts_mixed_currencies Both pass against the existing FIXTURE_BASIC and FIXTURE_MIXED_CURRENCIES fixtures. Docs: - Drop the --date row from the "Differences from bean-price" table — it's no longer a divergence. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 3, 2026
#983) * feat(price): --date as-of for active filter + extend compat harness Two follow-ups to PR #982 / issue #967. (item 4) --date as-of for the active-commodity filter ===================================================== Before this change, `rledger price -f file.beancount --date 2020-01-01` parsed the date and passed it to source requests, but the active filter that decides which commodities to include used the LATEST balances — so a commodity bought before 2020 and sold afterward was excluded from the historical fetch. Bean-price walks the file as-of `--date` for both balance computation and price lookup; this aligns rledger. Implementation: - discover_symbols and active_commodities now take Option<NaiveDate>. - Transactions with date > as_of are skipped from the balance roll-up. - Close directives after as_of are ignored (the account WAS open then). - price_cmd.rs parses args.date once, early, and threads it into discovery (was previously parsed only later for the source request). Tests: - as_of_filter_includes_holdings_at_that_date_only - as_of_ignores_close_directive_after_cutoff (harness extension) Source-resolution differential via --dry-run ================================================================ The compat harness (#978) previously compared only commodity discovery because rledger had no equivalent of `bean-price -n`. With #982's `rledger price -n` flag now landed, the harness can compare full (symbol, currency, source, ticker) resolution between the two binaries — covering source precedence (audit item 5), per-spec ticker preservation (#970), and fallback chains (#963/#970). Adds two new tests: - rledger_and_bean_price_resolve_same_attempts_basic - rledger_and_bean_price_resolve_same_attempts_mixed_currencies Both pass against the existing FIXTURE_BASIC and FIXTURE_MIXED_CURRENCIES fixtures. Docs: - Drop the --date row from the "Differences from bean-price" table — it's no longer a divergence. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(price): self-review on PR #983 — boundary date assertions Add boundary-date assertions for the as_of filter: - as_of exactly on buy date → buy applies, SHIB active - as_of exactly on sell date → both apply, SHIB inactive - as_of exactly on close date → close applies, DOGE inactive Pins down the inclusive `<=` comparison so a future change to `<` would break loudly with a focused test rather than only via integration. Also: comment on the harness's two-space skip-annotation strip noting it's coupled to dump_fetch_plan's exact output format. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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
Lands the keystone deliverable from #967's audit: a Rust integration test that drives both `rledger price` and `bean-price -n` against a fixture beancount file and asserts they discover the same set of `(symbol, quote_currency)` pairs to fetch.
Once this is in, every per-candidate audit item from #967 (`--expressive`, `--clobber`, cache semantics, `--date`, source-selection precedence, logging) can add its own fixture + assertion against the same harness instead of inventing its own scaffolding.
How it works
Constraints handled
Test plan
Out of scope
This PR does one comparison (a basic `commodity` + `price:` fixture). Per-candidate audits will add more fixtures (with `quote_currency:`, fallback chains, undeclared/inactive flags, etc.) in their own dedicated PRs — that was the recommendation in my last comment on #967.
Refs #967.