Skip to content

chore(nix): add beanprice to dev shell for bean-price differential tests - #976

Merged
robcohen merged 2 commits into
mainfrom
chore/nix-add-beanprice
May 3, 2026
Merged

robcohen merged 2 commits into
mainfrom
chore/nix-add-beanprice

Conversation

@robcohen

@robcohen robcohen commented May 3, 2026

Copy link
Copy Markdown
Member

Summary

Adds the `bean-price` CLI to the dev shell. Unblocks #967's acceptance criterion #1 (differential tests of `rledger price` against `bean-price`).

Why

`beanprice` is a separate PyPI distribution since beancount v3 and is not packaged in nixpkgs. Without it on PATH there is no way to drive a side-by-side comparison for the bean-price compat sweep tracked in #967.

What changed

  • New `beanprice` derivation built locally as a `buildPythonApplication` from PyPI (sdist 2.1.0, hash pinned).
  • Added to the default dev shell's package list.
  • Bumped `pythonWithBeancount` from python311 to python312. beanprice's `curl-cffi 0.14.0` dependency pulls in `sphinx 9.1.0`, which requires Python ≥ 3.12. python311 is also approaching EOL.
  • Tweaked the dev-shell greeting to mention beanprice.

Verification

  • `nix --extra-experimental-features 'nix-command flakes' build .#devShells.x86_64-linux.default` succeeds.
  • `bean-price`, `bean-check`, `bean-query` all on PATH.
  • `cargo check --workspace` still passes (no Rust impact from the python bump).

Test plan

  • CI green
  • Reviewer can run `nix develop` and confirm `bean-price --help` works

Refs #967.

beanprice is a separate PyPI distribution since beancount v3, and is not
packaged in nixpkgs. Build it locally as a buildPythonApplication so that
`bean-price` is on PATH in the dev shell — unblocks issue #967's
acceptance criterion #1 (differential tests of `rledger price` against
`bean-price`).

Also bump pythonWithBeancount from python311 to python312: beanprice's
curl-cffi 0.14.0 dependency pulls sphinx 9.1.0, which requires Python
≥ 3.12. python311 is also approaching EOL.

Verified `bean-price`, `bean-check`, and `bean-query` are all in PATH;
`cargo check --workspace` still passes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner May 3, 2026 02:56
Copilot AI review requested due to automatic review settings May 3, 2026 02:56
@robcohen
robcohen enabled auto-merge (squash) May 3, 2026 02:57
@robcohen
robcohen merged commit 3d5ca1d into main May 3, 2026
22 checks passed
@robcohen
robcohen deleted the chore/nix-add-beanprice branch May 3, 2026 02:59

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.

Pull request overview

Updates the Nix flake dev shell to include the bean-price CLI (via a locally-built beanprice Python application) so the project can run differential price-discovery tests against rledger price as tracked in #967.

Changes:

  • Add a local beanprice derivation built from PyPI (sdist 2.1.0) using buildPythonApplication.
  • Add beanprice to the default dev shell tool list so bean-price is on PATH.
  • Bump pythonWithBeancount from Python 3.11 to 3.12 and update the dev-shell greeting accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flake.nix Resolved
Comment thread flake.nix Resolved
@codecov

codecov Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ Compatibility Test Results

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

robcohen added a commit that referenced this pull request May 3, 2026
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 added a commit that referenced this pull request May 3, 2026
…967) (#978)

* feat(test): bean-price compat harness — symbol-set differential (refs #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]>

* test(price): tighten compat harness — scope clarity, robustness, second 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]>

* test(price): shell-quote --source-cmd path (Copilot review on PR #978)

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]>

* test(price): fix CI failure — only assert bean-price PATH inside nix 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]>

* ci: run bean-price compat harness inside nix develop

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]>

* Revert "ci: run bean-price compat harness inside nix develop"

This reverts commit 919fee1.

* ci: enforce bean-price compat harness in pre-push hook (local only)

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]>

---------

Co-authored-by: Claude Opus 4.7 (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.

2 participants