Repository navigation
fix(wasm): emit Posting.flag on the wire (closes #1205) - #1209
Merged
Merged
Conversation
The WASM binding's PostingJson dropped the per-posting flag entirely; FFI-WASI emitted it as `"flag": "!"`. JS consumers using `@rustledger/wasm` had no way to read posting-level flags from parsed ledgers. Mirror the FFI-WASI shape: add `flag: Option<String>` (with `skip_serializing_if = "Option::is_none"`) between `price` and `meta`, and populate it via `p.flag.map(|c| c.to_string())`. The `beancount_wasm.d.ts` already declared `flag?: string` on the Posting interface, so the JS type surface was already correct -- this fix lines the Rust side up with what consumers expected. The cross-binding equivalence test (`posting_with_flag_equivalence`) had been `#[ignore]`-pinned with this issue as the rationale; remove the ignore so the test now guards convergence in CI. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes WASM wire-format drift for posting-level flags by adding Posting.flag to the WASM JSON DTO and enabling the cross-binding regression test for #1205.
Changes:
- Adds
flag: Option<String>to WASMPostingJson. - Populates the field from core
Posting.flag. - Re-enables the cross-binding
posting_with_flag_equivalencetest.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/rustledger-wasm/src/types.rs |
Adds the posting-level flag field to the WASM wire DTO. |
crates/rustledger-wasm/src/convert.rs |
Serializes core posting flags into the new DTO field. |
crates/rustledger-wire-format-tests/tests/equivalence.rs |
Unignores and updates the regression test for posting flag equivalence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-05-27)
What do these numbers mean?
|
3 tasks done
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…unt.d.ts Addresses Copilot inline review on #1209: adding flag to the Rust DTO exposes it in the JSON output, but the public TypeScript declarations need updating too. Three TS surfaces ship with the WASM build: - crates/rustledger-wasm/src/lib.rs typescript_custom_section (wasm-bindgen embeds this in the generated .d.ts) -- Posting was missing flag (and meta, audited in the followup PR). - crates/rustledger-wasm/beancount.d.ts (hand-maintained .d.ts) -- Posting was missing flag. - crates/rustledger-wasm/beancount_wasm.d.ts -- already declared flag? before this PR; no change needed here. JS consumers using @rustledger/wasm now see flag?: string on Posting regardless of which TS surface they pick up. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
robcohen
added a commit
that referenced
this pull request
May 27, 2026
PR #1209 surfaced via Copilot that the WASM crate ships three hand-maintained TypeScript surfaces, not one. Extend the audit (begun in the initial commit on beancount_wasm.d.ts) to the other two: **`src/lib.rs` typescript_custom_section** (wasm-bindgen embeds this in the generated .d.ts that ships with the npm package): - Declare the `MetaValueJson` type so directive/posting `meta?` fields are properly typed instead of relying on `unknown`. - Add `meta?: Record<string, MetaValueJson>` to `BaseDirective` (inherited by Transaction/Balance/Open/Close). - Add `meta?` to each inline directive shape in the `Directive` union (commodity, pad, event, note, document, price, query, custom), spelled out since these don't extend `BaseDirective`. - Add `values?: MetaValueJson[]` to the `custom` inline shape (the positional arguments after the type keyword -- wire shape since #1199, but the TS surface had been silently dropping them from the type system). - Add `meta?` to the `Posting` interface (posting-level metadata from #1168; wire-shape `meta?` was present but the type elided it). **`beancount.d.ts`**: - Add `price?: Amount` to `Posting` -- the `@`/`@@` annotation is emitted on the wire (and has been for ages) but the type didn't expose it. Note: `Posting.flag?` is added to both surfaces by the companion commit on #1209; this PR's edits stay clear of that line to avoid a merge conflict. Long term, hand-maintaining three TS surfaces is the structural problem -- issue #1200 item 2 (ts-rs generation) is the cure. Co-Authored-By: Claude Opus 4.7 <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 27, 2026
Hand-maintained drift between the .d.ts and the Rust DTOs surfaced while reviewing #1209. Audit findings: 1. **`Posting` was missing `price?: Amount`** -- the `@`/`@@` price annotation is emitted by the Rust side but JS consumers could only see it via the `unknown` index signature on `Directive`. 2. **`Posting.flag` was declared in the wrong position** -- the .d.ts listed `flag?` between `cost` and `meta`, while `rustledger_wasm::types::PostingJson` (and the JSON output) puts it after `price`. Cosmetic only; reorder to match. 3. **7 of 12 directive variants had no narrowed interface**: commodity, pad, event, note, document, query, custom. The `DirectiveType` union listed them but consumers had to inspect the raw base `Directive` with its `[key: string]: unknown` index signature to read their fields. Add `CommodityDirective`, `PadDirective`, `EventDirective`, `NoteDirective`, `DocumentDirective`, `QueryDirective`, `CustomDirective`. Each new interface mirrors the corresponding variant on `DirectiveJson` (custom_type, source_account, event_type, etc.). Long term, hand-maintenance of the .d.ts is the root cause -- issue #1200 item 2 (ts-rs generation from the Rust DTOs) will eliminate this whole class of drift. This PR is a tactical fix to close the current gaps; doesn't change the runtime wire shape. Co-Authored-By: Claude Opus 4.7 <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 27, 2026
PR #1209 surfaced via Copilot that the WASM crate ships three hand-maintained TypeScript surfaces, not one. Extend the audit (begun in the initial commit on beancount_wasm.d.ts) to the other two: **`src/lib.rs` typescript_custom_section** (wasm-bindgen embeds this in the generated .d.ts that ships with the npm package): - Declare the `MetaValueJson` type so directive/posting `meta?` fields are properly typed instead of relying on `unknown`. - Add `meta?: Record<string, MetaValueJson>` to `BaseDirective` (inherited by Transaction/Balance/Open/Close). - Add `meta?` to each inline directive shape in the `Directive` union (commodity, pad, event, note, document, price, query, custom), spelled out since these don't extend `BaseDirective`. - Add `values?: MetaValueJson[]` to the `custom` inline shape (the positional arguments after the type keyword -- wire shape since #1199, but the TS surface had been silently dropping them from the type system). - Add `meta?` to the `Posting` interface (posting-level metadata from #1168; wire-shape `meta?` was present but the type elided it). **`beancount.d.ts`**: - Add `price?: Amount` to `Posting` -- the `@`/`@@` annotation is emitted on the wire (and has been for ages) but the type didn't expose it. Note: `Posting.flag?` is added to both surfaces by the companion commit on #1209; this PR's edits stay clear of that line to avoid a merge conflict. Long term, hand-maintaining three TS surfaces is the structural problem -- issue #1200 item 2 (ts-rs generation) is the cure. Co-Authored-By: Claude Opus 4.7 <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 27, 2026
* docs(wasm): align beancount_wasm.d.ts with the actual wire shape Hand-maintained drift between the .d.ts and the Rust DTOs surfaced while reviewing #1209. Audit findings: 1. **`Posting` was missing `price?: Amount`** -- the `@`/`@@` price annotation is emitted by the Rust side but JS consumers could only see it via the `unknown` index signature on `Directive`. 2. **`Posting.flag` was declared in the wrong position** -- the .d.ts listed `flag?` between `cost` and `meta`, while `rustledger_wasm::types::PostingJson` (and the JSON output) puts it after `price`. Cosmetic only; reorder to match. 3. **7 of 12 directive variants had no narrowed interface**: commodity, pad, event, note, document, query, custom. The `DirectiveType` union listed them but consumers had to inspect the raw base `Directive` with its `[key: string]: unknown` index signature to read their fields. Add `CommodityDirective`, `PadDirective`, `EventDirective`, `NoteDirective`, `DocumentDirective`, `QueryDirective`, `CustomDirective`. Each new interface mirrors the corresponding variant on `DirectiveJson` (custom_type, source_account, event_type, etc.). Long term, hand-maintenance of the .d.ts is the root cause -- issue #1200 item 2 (ts-rs generation from the Rust DTOs) will eliminate this whole class of drift. This PR is a tactical fix to close the current gaps; doesn't change the runtime wire shape. Co-Authored-By: Claude Opus 4.7 <[email protected]> * docs(wasm): extend audit to typescript_custom_section + beancount.d.ts PR #1209 surfaced via Copilot that the WASM crate ships three hand-maintained TypeScript surfaces, not one. Extend the audit (begun in the initial commit on beancount_wasm.d.ts) to the other two: **`src/lib.rs` typescript_custom_section** (wasm-bindgen embeds this in the generated .d.ts that ships with the npm package): - Declare the `MetaValueJson` type so directive/posting `meta?` fields are properly typed instead of relying on `unknown`. - Add `meta?: Record<string, MetaValueJson>` to `BaseDirective` (inherited by Transaction/Balance/Open/Close). - Add `meta?` to each inline directive shape in the `Directive` union (commodity, pad, event, note, document, price, query, custom), spelled out since these don't extend `BaseDirective`. - Add `values?: MetaValueJson[]` to the `custom` inline shape (the positional arguments after the type keyword -- wire shape since #1199, but the TS surface had been silently dropping them from the type system). - Add `meta?` to the `Posting` interface (posting-level metadata from #1168; wire-shape `meta?` was present but the type elided it). **`beancount.d.ts`**: - Add `price?: Amount` to `Posting` -- the `@`/`@@` annotation is emitted on the wire (and has been for ages) but the type didn't expose it. Note: `Posting.flag?` is added to both surfaces by the companion commit on #1209; this PR's edits stay clear of that line to avoid a merge conflict. Long term, hand-maintaining three TS surfaces is the structural problem -- issue #1200 item 2 (ts-rs generation) is the cure. Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
This was referenced May 28, 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
flag: Option<String>to WASM'sPostingJson(mirrors FFI-WASI's shape atcrates/rustledger-ffi-wasi/src/types/output.rs:217).posting.flag.map(|c| c.to_string())in the WASM converter.#[ignore]onposting_with_flag_equivalenceso the cross-binding harness from feat(test): cross-binding wire-format equivalence harness (#1200 item 1) #1204 now guards convergence in CI.The TypeScript declaration in
beancount_wasm.d.tsalready hadflag?: stringon thePostinginterface, so this fix aligns the Rust side with what JS consumers were already typed against.Caught by the cross-binding wire-format harness (#1200 / #1204).
Test plan
cargo test -p rustledger-wasm— 78/78 passcargo test -p rustledger-wire-format-tests posting_with_flag_equivalence— passes (was previously#[ignore]d)cargo clippy -p rustledger-wasm -p rustledger-wire-format-tests --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleanCloses #1205.
🤖 Generated with Claude Code