Repository navigation
fix(wasm): converge Transaction.payee/narration wire shape with FFI-WASI (closes #1221) - #1222
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Converges the WASM binding's Transaction.payee/narration wire shape with FFI-WASI by adding skip_serializing_if = "Option::is_none" on both fields and normalizing empty narration to None in the converter. TypeScript surfaces and the equivalence harness docstring are updated to match.
Changes:
- Add
skip_serializing_iftopayee/narrationin WASMDirectiveJson::Transactionand normalize empty narration toNoneinconvert.rs. - Update
beancount.d.tsandbeancount_wasm.d.tssopayee/narrationare?: stringoptional rather thanstring | null/ requiredstring. - Add two regression tests pinning omit-on-empty and emit-on-present, and mark item 3 of the equivalence harness docstring as converged.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-wasm/src/types.rs | Adds skip_serializing_if to payee and narration. |
| crates/rustledger-wasm/src/convert.rs | Normalizes empty narration to None and adds two regression tests. |
| crates/rustledger-wasm/beancount.d.ts | Updates payee/narration to optional. |
| crates/rustledger-wasm/beancount_wasm.d.ts | Updates narration to optional and refreshes payee doc. |
| crates/rustledger-wire-format-tests/tests/equivalence.rs | Marks divergence item 3 as converged. |
💡 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 |
…WASI (closes #1221) BREAKING CHANGE: the WASM binding's wire shape for `Transaction.payee` and `Transaction.narration` now matches FFI-WASI. Pre-fix WASM emitted `"payee": null` when None and `"narration": ""` when empty; post-fix both fields are absent on the wire via `skip_serializing_if`. JS consumers using `"payee" in t` (now `false` instead of `true`) or `t.narration === ""` (now `undefined` instead of `""`) must update. See `crates/rustledger-wasm/CHANGELOG.md` for details. Surfaced by the ts-rs spike in #1220. FFI-WASI already used `skip_serializing_if = "Option::is_none"` on both fields, but the WASM binding diverged: - `payee`: WASM emitted `"payee": null` when None; FFI-WASI omitted. - `narration`: WASM wrapped `txn.narration` unconditionally in `Some(...)`, so an empty narration always emitted as `""` on the wire; FFI-WASI's converter normalized empty-string to None and thus elided the field via `skip_serializing_if`. This divergence was masked in the wire-format equivalence harness by the `strip_empty_meta_and_directive_nulls` normalization helper -- the harness was documented as a known divergence (item 3 in its module docstring) with the recommended convergence being exactly what this PR does. ## Changes - `src/types.rs`: add `#[serde(skip_serializing_if = "Option::is_none")]` to both `Transaction.payee` and `Transaction.narration`. - `src/convert.rs`: change `narration: Some(txn.narration.to_string())` to elide on empty string -- matches FFI-WASI's converter pattern at `crates/rustledger-ffi-wasi/src/convert.rs:133-137`. - Three TS surfaces aligned: - `beancount.d.ts`: `payee: string | null` → `payee?: string`; `narration: string` → `narration?: string`. - `beancount_wasm.d.ts`: `narration: string` → `narration?: string` (payee was already correct). - `typescript_custom_section` in `src/lib.rs`: already had `payee?: string` and `narration?: string`; no change needed. - `CHANGELOG.md`: BREAKING CHANGES entry under [Unreleased]. - Wire-format harness docstring updated -- divergence item 3 marked as ~~converged~~ with a pointer to this fix. ## Tests Two new regressions in `src/convert.rs`: - `transaction_omits_payee_and_empty_narration_1221` -- no-payee + empty narration transaction must have neither field on the wire. - `transaction_emits_payee_and_nonempty_narration_1221` -- present payee + non-empty narration must both appear on the wire. Counterpoint so a future regression that elides unconditionally also fails CI. The existing wire-format-tests harness already covered Transaction equivalence (`metadata_equivalence_on_transaction_directive`) and continues to pass; the null-stripping in `strip_empty_meta_and_directive_nulls` is no longer load-bearing for the payee/narration case but stays as a defensive guard against future regression. ## Notes The `.d.ts` audit that fixed Posting.price and 7 missing variants (#1210) didn't catch this because it looked for missing/extra fields, not type-mismatches on existing fields. The ts-rs spike (#1220) surfaced it as a side-effect of comparing generated TS against the hand-written shape -- evidence for ADR-0004's CI gate proposal. Co-Authored-By: Claude Opus 4.7 <[email protected]>
robcohen
force-pushed
the
fix/wasm-payee-narration-1221
branch
from
May 28, 2026 13:15
e0d2748 to
a4b2498
Compare
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
Surfaced by the ts-rs spike in #1220. FFI-WASI already uses `skip_serializing_if = "Option::is_none"` on both `payee` and `narration`; the WASM binding diverged on both fields:
The harness from #1204 documented this exact convergence path in its module docstring (item 3) — the null-stripping normalization was masking the divergence so the equivalence test would pass while the underlying bug persisted.
Changes
Two new regression tests pin both directions (omit-on-empty and emit-on-present).
Test plan
Notes
The .d.ts audit (#1210) didn't catch this because it looked for missing/extra fields, not type mismatches on existing fields. The ts-rs spike (#1220) surfaced it by comparing generated TS against the hand-written shape — concrete evidence for ADR-0004's CI gate proposal.
Closes #1221.
🤖 Generated with Claude Code