Skip to content

feat(ffi): add missing options and entry fields to FFI output - #311

Merged
robcohen merged 3 commits into
mainfrom
fix/ffi-missing-fields
Feb 8, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/ffi-missing-fields

Conversation

@robcohen

@robcohen robcohen commented Feb 7, 2026

Copy link
Copy Markdown
Member

Summary

Add missing fields to the FFI layer that weren't being passed through from the core types. This closes the gap between what the Rust loader knows and what Fava/Python consumers can access.

LedgerOptions (13 new fields)

  • render_commas: boolean for number formatting
  • inferred_tolerance_default: per-currency tolerance map (e.g., {"USD": "0.005", "*": "0.01"})
  • inferred_tolerance_multiplier: tolerance multiplier (default 0.5)
  • infer_tolerance_from_cost: boolean flag
  • account_rounding: optional rounding account
  • account_previous_balances: opening balances account
  • account_previous_earnings: previous earnings account
  • account_previous_conversions: previous conversions account
  • account_current_earnings: current earnings account
  • account_current_conversions: optional current conversions account
  • account_unrealized_gains: optional unrealized gains account
  • conversion_currency: optional conversion currency

Entry fields

  • Posting.flag: posting-level flag (e.g., "!" for pending)
  • Balance.tolerance: explicit tolerance (e.g., "~ 0.01")

Test plan

  • cargo fmt --check - passes
  • cargo clippy - no warnings
  • cargo test --all - all tests pass
  • just test-cov - coverage generated

Related issues

Fixes #308
Fixes #310

🤖 Generated with Claude Code

Add missing fields to the FFI layer that weren't being passed through
from the core types:

LedgerOptions (13 new fields):
- render_commas: boolean for number formatting
- inferred_tolerance_default: per-currency tolerance map
- inferred_tolerance_multiplier: tolerance multiplier (default 0.5)
- infer_tolerance_from_cost: boolean flag
- account_rounding: optional rounding account
- account_previous_balances: opening balances account
- account_previous_earnings: previous earnings account
- account_previous_conversions: previous conversions account
- account_current_earnings: current earnings account
- account_current_conversions: optional current conversions account
- account_unrealized_gains: optional unrealized gains account
- conversion_currency: optional conversion currency

Entry fields:
- Posting.flag: posting-level flag (e.g., "!" for pending)
- Balance.tolerance: explicit tolerance (e.g., "~ 0.01")

Fixes #308, #310

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner February 7, 2026 21:02
Copilot AI review requested due to automatic review settings February 7, 2026 21:02

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

Adds missing ledger option fields and entry-level fields to the WASI FFI JSON output so downstream consumers (e.g., Python/Fava) can access the same data as the Rust loader.

Changes:

  • Extended FFI output types with posting-level flag and balance tolerance.
  • Added 13 missing LedgerOptions fields to the FFI output and defaults.
  • Plumbed the new options from loader results and parsing helpers into the load-full command output.

Reviewed changes

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

Show a summary per file
File Description
crates/rustledger-ffi-wasi/src/types/output.rs Expands serialized FFI output types to include new posting/balance fields and ledger options.
crates/rustledger-ffi-wasi/src/helpers.rs Parses additional option keys from source metadata into LedgerOptions.
crates/rustledger-ffi-wasi/src/convert.rs Populates new JSON fields (Posting.flag, Balance.tolerance) during conversion.
crates/rustledger-ffi-wasi/src/commands/load.rs Wires loader display_precision and new ledger option fields into the load-full output.
crates/rustledger-ffi-wasi/src/commands/clamp.rs Initializes the new Posting.flag field when constructing postings.

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

@codecov

codecov Bot commented Feb 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 44.6ms ± 2.7ms 23.3 MB
beancount 884.1ms ± 5.7ms 50.2 MB
Comparison 19.8x faster 2.2x less

vs main branch (2026-02-07)

Metric main this PR Change
Time 58.4ms 44.6ms -23.6% 🟢
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

- Add skip_serializing_if for empty inferred_tolerance_default map
- Make boolean parsing consistent (accept "1" for infer_tolerance_from_cost)
- Trim whitespace when parsing inferred_tolerance_default values
- Simplify display_precision cloning with .clone()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions

github-actions Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

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

@mergify

mergify Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

🧪 CI Insights

Here's what we observed from your CI run for bc72b73.

🟢 All jobs passed!

But CI Insights is watching 👀

The loader uses FxHashMap (with FxBuildHasher) but FFI output uses
std::collections::HashMap (with RandomState). Direct .clone() fails
on MSRV because the hasher types don't match.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@robcohen
robcohen enabled auto-merge February 8, 2026 00:32
@robcohen
robcohen added this pull request to the merge queue Feb 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to Branch Protection failures Feb 8, 2026
You're not authorized to push to this branch. Visit "About protected branches" for more information.
@robcohen
robcohen added this pull request to the merge queue Feb 8, 2026
Merged via the queue into main with commit faf15ca Feb 8, 2026
26 checks passed
@robcohen
robcohen deleted the fix/ffi-missing-fields branch February 8, 2026 02:09
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.

FFI: LedgerOptions missing several beancount options inferred_tolerance_default option not honored

2 participants