Repository navigation
fix: remove .abs() from cost() to preserve sign for sells - #614
Merged
Merged
Conversation
The BQL cost() function was using .abs() on unit numbers, causing sell transactions to contribute positive costs instead of negative costs. This led to incorrect sums when mixing buys and sells. For example, with: - Buy 5 ABC @ 1.25 EUR = +6.25 EUR - Sell 5 ABC @ 1.25 EUR = -6.25 EUR (was incorrectly +6.25) SUM(cost(position)) would incorrectly sum to 12.50 instead of 0. This fix removes .abs() so that: - Positive units (buys) contribute positive costs - Negative units (sells) contribute negative costs - Net cost correctly reflects remaining position value Closes #593 Co-Authored-By: Claude Opus 4.5 <[email protected]>
These full-workspace checks took 10-30 minutes on every push, which is impractical. They now run only in CI where they can be parallelized and cached properly. Pre-push hooks now only validate branch names (fast). Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-03-30)
What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the BQL cost() sign handling so sell postings contribute negative cost, adds regression coverage for issue #593, and speeds up developer workflow by trimming slow pre-push hooks.
Changes:
- Remove
.abs()fromcost()computation to preserve unit sign (buys positive, sells negative). - Add regression tests + a beancount reproducer for issue #593 (
cost()sign +value()latest implicit price behavior). - Update pre-push hooks to only run fast checks locally (heavy checks deferred to CI).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
crates/rustledger-query/src/executor/functions/position.rs |
Adjusts COST() calculation to preserve sign when evaluating in posting context. |
crates/rustledger-query/tests/bql_integration_test.rs |
Adds issue #593 regression tests for cost() sign and value() price selection. |
tests/regressions/issue-593.beancount |
Adds a minimal beancount reproducer/fixture for the reported issue. |
.pre-commit-config.yaml |
Removes slow clippy/test/doc pre-push hooks, keeping only fast checks locally. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
- Replace write!(&mut hasher, ...) with hasher.update(...) since sha2
0.11 removed std::io::Write implementation
- Replace format!("{:x}", ...) with fold-based hex formatting since
sha2 0.11 removed LowerHex trait implementation
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Address PR review comments: - Fix duplicate cost() implementation in evaluate_function_on_values() that still used .abs() (caught by Copilot review) - Add test for cost(SUM(position)) pattern which is the actual issue #593 query shape, executing different code path than SUM(cost(position)) Co-Authored-By: Claude Opus 4.5 <[email protected]>
robcohen
enabled auto-merge
March 30, 2026 22:55
robcohen
disabled auto-merge
March 30, 2026 23:02
robcohen
enabled auto-merge
March 30, 2026 23:02
robcohen
added this pull request to the merge queue
Mar 30, 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
cost()function returning incorrect values by removing.abs()from unit numbersProblem
The
cost()function was using.abs()on unit numbers, causing sell transactions to contribute positive costs. This led to incorrect sums:Fix
Remove
.abs()so signs are preserved:Test plan
test_issue_593_cost_preserves_sign_for_sellsregression testtest_issue_593_value_uses_latest_implicit_priceregression testtests/regressions/issue-593.beancounttest fixtureCloses #593
🤖 Generated with Claude Code
Also closes #592 (same root cause -
.abs()in cost calculation)