Skip to content

chore: pin CostNumber wire parity across all five mirrors - #1740

Merged
robcohen merged 4 commits into
mainfrom
chore/costnumber-wire-parity
Jul 10, 2026
Merged

robcohen merged 4 commits into
mainfrom
chore/costnumber-wire-parity

Conversation

@robcohen

@robcohen robcohen commented Jul 9, 2026

Copy link
Copy Markdown
Member

What

Pins wire-format parity for the CostNumber family across all five hand-written mirrors. Test-only — no production code changes.

Why

Phase-1 correctness sweep, finding W1 (marshaling family). CostNumber crosses process boundaries through five mirrors unified only by convention:

  1. rustledger_core::CostNumber serde (kind-tagged JSON)
  2. rustledger_plugin_types::CostNumberData (plugin wire + Python shim)
  3. rustledger_wasm::types::CostNumberJson (TypeScript clients)
  4. rustledger_ffi_wasi::InputCostNumber (builder ingress, Deserialize-only)
  5. the WIT cost-number variant (component model, positional)

Each JSON mirror pinned its own shape against its own literals, so a crate could change its pin and shape "consistently" without noticing the other four exist. Concretely: nothing asserted the shapes are the same, the compound variant was entirely unpinned in the core and wasm mirrors, and the WIT lowering/raising (cost_number_from_core / input_cost_number) had no tests at all.

How

  • rustledger-wasm/tests/cost_number_wire_parity.rs — one canonical fixture set covering all four variants (values chosen to also pin scale preservation: "5.00" must not collapse to "5"). Every JSON mirror is held to it in one place: core/plugin/wasm must serialize to it byte-identically; plugin and ffi-wasi ingress must accept it; core must round-trip it. Hosted in the wasm crate (already the one with native-only serde_json), with plugin-types + ffi-wasi as cfg(not(wasm32)) dev-dependencies — test-only, nothing enters the wasm32 build.
  • ffi-component unit tests for the WIT mirror in both directions: every core variant lowers to the same-named WIT arm with scale-preserved string payloads, and every WIT arm raises to the matching InputCostNumber variant. A future CostNumber variant now forces non-exhaustive-match updates at exactly these pinned sites.
  • Cross-references added between the existing per-crate pin tests and the new suite.

The registry's alternative — a shared lower/raise helper — doesn't fit here: the mirrors deliberately differ in value type (Decimal vs String) and capability (ingress-only vs bidirectional), so the contract is best enforced by fixture, not by code sharing.

Testing

New suites green (2 parity tests × 4 variants × 4 JSON mirrors; 2 WIT-direction tests); full plugin-types/wasm/ffi-component suites green; clippy --all-features --all-targets -D warnings + fmt clean.

🤖 Generated with Claude Code

CostNumber crosses process boundaries through five hand-written
mirrors unified only by convention: core serde, plugin-types
CostNumberData, wasm CostNumberJson, ffi-wasi InputCostNumber (all
kind-tagged JSON), and the WIT cost-number variant (positional).
Each JSON mirror pinned its own shape against its own literals —
nothing asserted the shapes are THE SAME, the compound variant was
entirely unpinned in the core and wasm mirrors, and the WIT
lowering/raising had no tests at all (sweep finding W1).

Add:

- rustledger-wasm/tests/cost_number_wire_parity.rs — one canonical
  fixture set (all four variants, values chosen to pin scale
  preservation: "5.00" stays "5.00") that every JSON mirror is held
  to: core/plugin/wasm serialize to it byte-identically; plugin and
  ffi-wasi ingress (Deserialize-only) accept it; core round-trips it.
  Native-only test with plugin-types + ffi-wasi as
  cfg(not(wasm32)) dev-deps.
- ffi-component unit tests for the WIT mirror, both directions:
  cost_number_from_core lowers every core variant to the same-named
  WIT arm with scale-preserved string payloads, and input_cost_number
  raises every WIT arm to the matching InputCostNumber variant. A new
  CostNumber variant now forces non-exhaustive-match updates at
  exactly these pinned sites.
- cross-references between the per-crate pin tests and the new
  parity suite so the next person finds the full picture.

No production code changes.

Co-Authored-By: Claude Fable 5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner July 9, 2026 20:59
Copilot AI review requested due to automatic review settings July 9, 2026 20: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

Pins and verifies wire-format parity for the CostNumber family across the project’s five “mirror” representations (core/plugin/wasm/ffi-wasi JSON mirrors + ffi-component WIT mirror), by centralizing parity fixtures and adding bidirectional WIT mapping tests.

Changes:

  • Added a canonical fixture-driven parity test in rustledger-wasm to ensure all JSON mirrors serialize/deserialize the same shapes for all CostNumber variants.
  • Added rustledger-ffi-component unit tests to pin core↔WIT lowering and WIT↔FFI ingress raising for cost-number.
  • Updated dev-dependencies / lockfiles and supply-chain metadata to support the new test-only coverage.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
supply-chain/imports.lock Updates publisher import record for crossbeam-epoch (version/date).
supply-chain/config.toml Removes no-longer-needed crossbeam-epoch exemptions.
crates/rustledger-wasm/tests/cost_number_wire_parity.rs New cross-mirror JSON parity fixture suite (core/plugin/wasm serialize; plugin/ffi-wasi deserialize; core round-trip).
crates/rustledger-wasm/Cargo.toml Adds host-only dev-deps (rustledger-plugin-types, rustledger-ffi-wasi) for the parity test.
crates/rustledger-plugin-types/tests/cost_number_wire_format.rs Adds cross-reference comment to the new parity suite / WIT tests.
crates/rustledger-ffi-component/src/convert.rs Adds WIT cost-number lowering/raising unit tests and imports.
Cargo.lock Reflects added host-only dev-dependency edges for rustledger-wasm.

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

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 33.7ms ± 0.5ms 23.6 MB
beancount 794.9ms ± 3.6ms 50.7 MB
Comparison 23.6x faster 2.1x less

vs main branch (2026-07-10)

Metric main this PR Change
Time 33.7ms 33.7ms +0.0% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 811
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 and others added 2 commits July 10, 2026 02:49
zip() truncates to the shortest iterator; a variant dropped from any
mirror list would have silently shrunk the parity guarantee.

Co-Authored-By: Claude Fable 5 <[email protected]>
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit cc1a1e6 into main Jul 10, 2026
48 of 49 checks passed
@robcohen
robcohen deleted the chore/costnumber-wire-parity branch July 10, 2026 09:47
robcohen added a commit that referenced this pull request Jul 11, 2026
…needs them (#1758)

The parity-test dev-deps (#1740) used workspace inheritance, which
bakes a version requirement into the published package's dev-deps —
cargo publish of rustledger-wasm then fails whenever the sibling
isn't on crates.io at that exact version yet (broke the v0.21.0
publish: the script orders wasm before ffi-wasi). Path-only dev-deps
are stripped at publish, which is exactly right for test-only
siblings. Verified: parity test still runs; cargo publish --dry-run
packages clean.

Co-authored-by: Claude Fable 5 <[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