Repository navigation
fix(ffi-wasi,wasm): emit Document.tags and Document.links (closes #1208) - #1212
Merged
Merged
Conversation
Both bindings' DirectiveJson::Document variants dropped tags and links entirely from the wire output. The fields were added to rustledger_core::Document in #1144 but never plumbed through to either binding's DTO. Lockstep-wrong drop -- equivalence alone would have missed it, but the new field-presence helper from #1204 caught it on first run. Mirror the established Vec<Tag> -> Vec<String> pattern: - Add `tags: Vec<String>`, `links: Vec<String>` with `skip_serializing_if = "Vec::is_empty"` to both bindings' Document variants. - Populate via `d.tags.iter().map(ToString::to_string).collect()` in each binding's converter -- same pattern Transaction already uses for its tags/links. `skip_serializing_if` (rather than always-emit, which is what Transaction does for these vec fields) chosen here because: - The fields are absent in today's wire output, so existing JS consumers parsing Document directives don't see them at all. - skip-if-empty is backward-compatible: documents without tags continue to emit no tags field. - always-emit would add `"tags": []` to every Document, which is a larger contract change for an audit fix. TS declarations updated on all three surfaces (`beancount_wasm.d.ts`, `beancount.d.ts`, the `typescript_custom_section` inline shape) with `tags?: string[]` / `links?: string[]` matching the skip-if-empty serialization. The cross-binding equivalence test (`document_directive_with_tags_and_links_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 a wire-format regression/omission where both rustledger-ffi-wasi and rustledger-wasm failed to emit Document.tags and Document.links in their JSON DTOs, and adds a cross-binding test to prevent the fields from being dropped again.
Changes:
- Add
tags/linkstoDirectiveJson::Documentfor both WASM and FFI-WASI, withskip_serializing_if = "Vec::is_empty"behavior. - Populate
tags/linksin both conversion layers (directive_to_json) by stringifying tag/link entries. - Update all TS surfaces to reflect
tags?: string[]/links?: string[], and enable the previously-ignored equivalence test to guard convergence in CI.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-wire-format-tests/tests/equivalence.rs | Un-ignores and documents the Document.tags/links fixture to enforce field presence going forward. |
| crates/rustledger-wasm/src/types.rs | Extends WASM DirectiveJson::Document with tags/links (skip-if-empty + default). |
| crates/rustledger-wasm/src/lib.rs | Updates the TS custom section Directive union to include optional tags/links on document. |
| crates/rustledger-wasm/src/convert.rs | Plumbs doc.tags/doc.links into the WASM wire DTO conversion. |
| crates/rustledger-wasm/beancount.d.ts | Adds optional tags/links to DocumentData in the JS/TS surface. |
| crates/rustledger-wasm/beancount_wasm.d.ts | Adds optional tags/links to DocumentDirective in the wasm-facing TS definitions. |
| crates/rustledger-ffi-wasi/src/types/output.rs | Extends FFI-WASI DirectiveJson::Document with tags/links (skip-if-empty). |
| crates/rustledger-ffi-wasi/src/convert.rs | Plumbs d.tags/d.links into the FFI-WASI wire DTO conversion. |
💡 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?
|
Contributor
✅ 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! |
This was referenced May 28, 2026
3 tasks done
robcohen
added a commit
that referenced
this pull request
May 28, 2026
#1216) The output wire shape of `Document.tags` and `Document.links` was fixed for both bindings in #1212, but the FFI-WASI input side was still missing the fields entirely. `InputEntry::Document` had no `tags` / `links` slots, and the converter at line 542 hardcoded `Vec::new()` -- so callers using `entry.create` / `entry.createBatch` to construct Document directives could never attach tags or links, even though the core type and the output wire shape both support them. Mirror the `InputEntry::Transaction` shape: - Add `tags: Vec<String>` and `links: Vec<String>` with `#[serde(default)]` to `InputEntry::Document`. The default-empty serde behavior keeps the wire backward-compatible -- a payload without the new fields still deserializes cleanly. - Update the converter to populate the core `Document.tags` and `Document.links` via the same `.iter().map(|t| t.clone().into())` pattern Transaction already uses. Add two regression tests: - `document_tags_and_links_round_trip_1213` -- a Document payload with tags + links round-trips through the bridge and arrives on the core `Document` with both fields populated. - `document_tags_and_links_default_to_empty_1213` -- a legacy payload without `tags`/`links` fields still converts cleanly, producing empty vectors. Backward-compat guard for pre-#1213 clients in the wild. 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
Both
rustledger-ffi-wasiandrustledger-wasm'sDirectiveJson::Documentvariants droppedtagsandlinksfrom the wire output. The fields were added torustledger_core::Documentin #1144 but never plumbed through to either binding's wire DTO. This is a lockstep-wrong drop — equivalence alone would have missed it, but the new field-presence helper from #1204 caught it on first run.tags: Vec<String>andlinks: Vec<String>(withskip_serializing_if = "Vec::is_empty") to both bindings'Documentvariants.d.tags.iter().map(ToString::to_string).collect()— mirrors howTransaction.tags/linksare converted.tags?: string[]/links?: string[]on all three TS surfaces:beancount_wasm.d.ts,beancount.d.ts,typescript_custom_section.#[ignore]ondocument_directive_with_tags_and_links_equivalenceso the cross-binding harness from feat(test): cross-binding wire-format equivalence harness (#1200 item 1) #1204 now guards convergence in CI.Why
skip_serializing_if(not always-emit like Transaction)Transaction.tags/linksalways emit as[]when empty — but Document's tags/links are absent from today's wire output entirely, so JS consumers parsing Document directives don't see those fields at all.skip-if-emptyis backward-compatible: documents without tags continue to emit notagsfield; documents with tags now emit them. Always-emit would add"tags": []to every Document, which is a larger contract change for an audit fix.Test plan
cargo test -p rustledger-wire-format-tests document_directive— both Document fixtures passcargo test -p rustledger-wasm— 78/78 passcargo test -p rustledger-ffi-wasi— 56/56 passcargo clippy -p rustledger-wasm -p rustledger-ffi-wasi -p rustledger-wire-format-tests --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleanCloses #1208.
🤖 Generated with Claude Code