Repository navigation
fix(wasm): inventory query cells carry each position's cost - #2491
Conversation
PositionValue, the element of an inventory cell, had only `units`, so BALANCES or sum(position) over wasm showed lots at different costs as bare units side by side. A single position cell already carried its cost; the CLI, the component's WIT and beancount all report it. PositionValue gains an optional `cost` (skipped when absent, as in the Position cell), and both the Position and Inventory arms of value_to_cell now build their element through one `position_value` helper so they cannot drift again. TS, JSON Schema and Python bindings regenerated with scripts/regen-bindings.sh. Tests: a host unit test pins the inventory cell's JSON (costs, dates, an omitted cost key on a cost-less position, and equality with the Position cell), and wasm_booking_method.rs now asserts the 100 USD and 90 USD costs on every wasm entry point. Both fail with the cost dropped from the Inventory arm. Closes #2402 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Review follow-up for #2402. The MCP server's formatCell read only `units` from inventory positions, so the new `cost` key never reached its tables, and it printed a single position cell as raw JSON. Both now render `5 X {100 USD, 2020-01-02}` (label in quotes when present). A position without a cost, or an inventory from a wasm package that predates the field, renders as bare units, as before. Tested: three new formatCell cases in the MCP test suite (124 pass); two of them fail against the previous formatCell. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Review (adversarial pass)Consumers of the wasm query wire, checked for the new
Local verification on a per-worktree target: Second pass
Third pass
|
…ll-cost-2402 # Conflicts: # CHANGELOG.md
What
The wasm query result's inventory cell dropped each position's cost.
PositionValuehad onlyunits, soBALANCESandsum(position)over wasm showed lots at different costs as bare5 Xand-2 Xside by side. A single position cell already carried its cost, andrledger query, the component's WIT (#1398) and beancount all report5 X {100 USD}and-2 X {90 USD}.PositionValuegainscost: Option<CostValue>. The field isskip_serializing_if = "Option::is_none"/ts(optional), as onCellValue::Position, so a cost-less position omits the key.value_to_cell, thePositionandInventoryarms now both build their element through oneposition_valuehelper, so they cannot drift again.scripts/regen-bindings.shregeneratedbindings/index.d.ts(cost?: CostValue),index.schema.jsonandtypes.py.RUSTLEDGER_TS_CHECK=1passes locally.The repro ledger from the issue now returns:
Wire-format decision: no version bump, no Breaking entry
The change is additive. The new key is optional and absent exactly when there is no cost, so existing readers that ignore unknown keys keep working, and the TS type only gains an optional property. The one visible effect is for a consumer that compares whole result rows byte for byte (as
wasm_booking_method.rsdid): it now sees the key. The CHANGELOG### Fixedentry says so. Crate versions are set at release time byset-version, so nothing is bumped here. The in-repo MCP server'sformatCellnow renders the cost (5 X {100 USD, 2020-01-02}) for inventory and position cells. A position without a cost, or a wasm package without the field, renders as before.Tested
inventory_cell_keeps_each_position_cost_2402(convert.rs). It pins both lots' costs and dates, the omitted key on a cost-less position, and that an inventory element is identical to the same position'sPositioncell.tests/wasm_booking_method.rsnow asserts the100 USDand90 USDcosts on all four wasm entry points, plus theLedger.fromCacheround-trip.wasm-pack test --node -- --test wasm_booking_method: 4 passed.cost: None, the unit test panics and every wasm entry point fails withBALANCES must hold the 5 X {100 USD} and -2 X {90 USD} lots apart.cargo test -p rustledger-wasm --all-features: 153 + 2 passed.cargo clippy --workspace --all-features --all-targets -D warningsis clean, and so iscargo doc -D warnings -p rustledger-wasm.Closes #2402
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr