Skip to content

fix(plugin): plumb Document.tags/links through plugin round-trip (closes #1214) - #1217

Merged
robcohen merged 1 commit into
mainfrom
fix/plugin-doc-tags-1214
May 28, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/plugin-doc-tags-1214

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

The plugin layer dropped Document.tags and Document.links on both legs of the round-trip, meaning any Document passing through a plugin (even a no-op) lost its tags/links, and plugins synthesizing Document directives couldn't attach them. Surfaced during the #1212 deep review; same #1144-cascade as #1213, but with wider plumbing.

Four sites:

  1. DocumentData DTO (rustledger-plugin-types) — add tags/links with #[serde(default)] for backward-compat with serialized plugin state.
  2. document_to_data (rustledger-plugin/convert/to_wrapper.rs) — propagate from core Document; same pattern Transaction uses one site above.
  3. data_to_document (rustledger-plugin/convert/from_wrapper.rs) — reconstruct on the way back; mirror Transaction's reverse path.
  4. WIT record document (rustledger-plugin/wit/world.wit) — add tags: list<string>, links: list<string> so non-Rust Component Model plugins see the fields.

Drive-by: document_discovery.rs constructs DocumentData directly; updated to fill empty tags/links (no source for them in a filesystem-discovery plugin).

Adds test_roundtrip_document_tags_and_links_1214 — pre-fix it would fail at both legs.

Test plan

  • cargo test -p rustledger-plugin -p rustledger-plugin-types — all suites pass (126 + 176 + integration)
  • cargo check --workspace --all-targets — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean

Closes #1214.

🤖 Generated with Claude Code

 #1214)

The plugin layer dropped Document.tags and Document.links on **both
legs** of the round-trip, meaning any Document passing through a
plugin (even a no-op) lost its tags/links, and plugins synthesizing
Document directives couldn't attach them.

Four sites needed plumbing -- all `#1144`'s incomplete cascade:

1. **`DocumentData` DTO** (`crates/rustledger-plugin-types/src/lib.rs:821`)
   -- add `tags: Vec<String>` and `links: Vec<String>` with
   `#[serde(default)]` for backward-compat with serialized plugin
   state that predates this field.

2. **`document_to_data`** (`crates/rustledger-plugin/src/convert/to_wrapper.rs:236`)
   -- propagate `doc.tags`/`doc.links` via the same
   `.iter().map(ToString::to_string).collect()` pattern Transaction
   uses one site above.

3. **`data_to_document`** (`crates/rustledger-plugin/src/convert/from_wrapper.rs:389`)
   -- reconstruct `tags`/`links` from the DTO via
   `.iter().map(|t| t.as_str().into()).collect()`, mirroring
   Transaction's reverse path.

4. **WIT `record document`** (`crates/rustledger-plugin/wit/world.wit:145`)
   -- add `tags: list<string>, links: list<string>` so non-Rust
   plugins (Component Model consumers) see the new fields. No
   codegen to regenerate -- this WIT is a contract definition; the
   actual plugin transport uses MessagePack.

Drive-by: `document_discovery.rs` plugin constructs `DocumentData`
directly; updated to fill `tags: vec![], links: vec![]` so the new
required fields type-check (the plugin discovers documents from disk
and has no tag/link source).

Regression test `test_roundtrip_document_tags_and_links_1214` in
`rustledger-plugin::convert::tests` constructs a Document with
non-empty tags/links, runs it through `directive_to_wrapper` ->
`wrapper_to_directive`, and asserts both fields survived. Pre-fix
this test would have failed at both `document_to_data` (where
fields were unread) and `data_to_document` (where they were
hardcoded to empty).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Copilot AI review requested due to automatic review settings May 28, 2026 11:15
@robcohen
robcohen requested a review from a team as a code owner May 28, 2026 11:15
@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-plugin/src/convert/mod.rs 95.23% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Fixes loss of Document.tags and Document.links when Documents pass through the plugin system by plumbing these fields through both directions of the plugin wrapper conversion, updating the plugin DTOs and WASM plugin WIT schema, and adding a regression test to prevent recurrence.

Changes:

  • Added tags/links to DocumentData (with #[serde(default)] for backward compatibility) and populated them in document_to_data / data_to_document.
  • Extended the WASM plugin WIT document record to include tags/links.
  • Updated the filesystem-based document discovery plugin to initialize empty tags/links, and added a round-trip regression test.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rustledger-plugin-types/src/lib.rs Extends DocumentData with tags/links and defaults for backward-compatible deserialization.
crates/rustledger-plugin/src/convert/to_wrapper.rs Propagates Document.tags/links into DocumentData when wrapping core directives for plugins.
crates/rustledger-plugin/src/convert/from_wrapper.rs Reconstructs core Document.tags/links from DocumentData on the return path.
crates/rustledger-plugin/src/convert/mod.rs Adds a focused regression test ensuring Document tags/links survive plugin round-trip conversion.
crates/rustledger-plugin/src/native/plugins/document_discovery.rs Updates direct DocumentData construction to include empty tags/links.
crates/rustledger-plugin/wit/world.wit Updates WASM plugin ABI schema for Document directives to include tags/links.

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

@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 35.6ms ± 3.5ms 25.2 MB
beancount 905.5ms ± 8.9ms 50.7 MB
Comparison 25.4x faster 2.0x less

vs main branch (2026-05-28)

Metric main this PR Change
Time 29.7ms 35.6ms +19.9% 🔴
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

@robcohen
robcohen merged commit dab9ecf into main May 28, 2026
33 checks passed
@robcohen
robcohen deleted the fix/plugin-doc-tags-1214 branch May 28, 2026 11:22
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 791
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

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.

plugin: DocumentData drops tags/links on both legs of plugin round-trip

2 participants