Skip to content

fix: add STRICT_WITH_SIZE to parser valid booking methods - #900

Merged
robcohen merged 6 commits into
mainfrom
fix/issue-891-strict-with-size
Apr 23, 2026
Merged

robcohen merged 6 commits into
mainfrom
fix/issue-891-strict-with-size

Conversation

@robcohen

@robcohen robcohen commented Apr 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fix [Compat]: Compatibility with booking method STRICT_WITH_SIZE #891: Parser now accepts STRICT_WITH_SIZE as a valid booking method
  • The booking method was already implemented in rustledger-core and rustledger-booking, but the parser's VALID_BOOKING_METHODS list was missing it
  • Update error message to include STRICT_WITH_SIZE in the list of valid options

Scope note

This branch is stacked on the changes from #899 (fix: resolve document paths against option "documents" directories, issue #889). The bottom commit of this branch will drop out cleanly once #899 merges.

Changes

  • crates/rustledger-parser/src/winnow_parser.rs — Added STRICT_WITH_SIZE to valid booking methods
  • crates/rustledger-parser/src/error.rs — Updated error message to include STRICT_WITH_SIZE
  • Parser integration tests for STRICT_WITH_SIZE (accept, reject, error-message content)
  • Loader integration tests covering all 7 booking methods end-to-end (FIFO/LIFO/HIFO/STRICT/STRICT_WITH_SIZE/NONE/AVERAGE), per-account overrides, and API-vs-file-level precedence

Review-fix commits

  • fix(lsp): resolve single-file document_dirs against current file path — addresses Copilot's single-file mode concern; relative option "documents" paths now resolve against the current file's parent directory instead of the LSP process CWD.
  • validate_document now has a doc comment describing the resolution precedence (absolute → document_base → document_dirs → CWD fallback).

Known CI failures

  • Semver Check — 3 crates need major-version bumps (Inventory::is_reduced_by arity change, CsvConfig and ValidationOptions new pub fields). These are being addressed separately in the release process.

Copilot AI review requested due to automatic review settings April 23, 2026 15:22
@robcohen
robcohen requested a review from a team as a code owner April 23, 2026 15:22
@github-actions

github-actions Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 34.3ms ± 2.4ms 21.4 MB
beancount 771.1ms ± 36.8ms 50.2 MB
Comparison 22.5x faster 2.3x less

vs main branch (2026-04-23)

Metric main this PR Change
Time 34.6ms 34.3ms -0.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

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

This PR extends Beancount compatibility by allowing STRICT_WITH_SIZE as an open booking method, and also adds document-path validation support for option "documents" directories (plus a sizeable README update).

Changes:

  • Accept STRICT_WITH_SIZE as a valid booking method in the parser and include it in the invalid-booking error message.
  • Add ValidationOptions.document_dirs and use it to resolve relative Document paths against option "documents" directories (with new unit tests).
  • Update LSP/loader wiring to pass document directories into validation; expand README with bank import/categorization section and update doc links.

Reviewed changes

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

Show a summary per file
File Description
crates/rustledger-validate/src/validators/document.rs Resolve relative Document paths using document_base or document_dirs; improve missing-doc context.
crates/rustledger-validate/src/lib.rs Add document_dirs to ValidationOptions + default; add tests for document dir resolution.
crates/rustledger-validate/Cargo.toml Add tempfile for validator tests.
crates/rustledger-parser/src/winnow_parser.rs Add STRICT_WITH_SIZE to the valid booking-method list for open.
crates/rustledger-parser/src/error.rs Update invalid booking method error message to list STRICT_WITH_SIZE.
crates/rustledger-lsp/src/handlers/diagnostics.rs Populate validator document_dirs from loader/file options.
crates/rustledger-loader/src/process.rs Pass file_options.documents into ValidationOptions.document_dirs during validation.
README.md Add “Import & Categorization” section and update documentation links + feature tables.
Cargo.lock Lockfile update for tempfile inclusion.
Comments suppressed due to low confidence (1)

crates/rustledger-loader/src/process.rs:708

  • document_dirs is populated from file_options.documents, but those values can be relative (per options parsing), and elsewhere in this file document directories are explicitly resolved relative to the main ledger file (resolved_documents in run_plugins). Passing the unresolved strings into validation means validate_document() will resolve relative paths against the process CWD instead of the ledger directory, which is inconsistent with the loader’s own document handling. Consider resolving file_options.documents against the ledger base directory (same logic as run_plugins) before passing them into ValidationOptions.
    let validation_options = ValidationOptions {
        account_types,
        document_dirs: file_options.documents.clone(),
        infer_tolerance_from_cost: file_options.infer_tolerance_from_cost,
        tolerance_multiplier: file_options.inferred_tolerance_multiplier,
        inferred_tolerance_default: file_options.inferred_tolerance_default.clone(),
        ..Default::default()

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

Comment thread README.md Resolved
@codecov

codecov Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.22222% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-lsp/src/handlers/diagnostics.rs 81.25% 9 Missing ⚠️
...tes/rustledger-validate/src/validators/document.rs 92.10% 3 Missing ⚠️
crates/rustledger-loader/src/process.rs 94.44% 1 Missing ⚠️
crates/rustledger-lsp/src/main_loop.rs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

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

When a document directive uses a relative path, the validator now searches
for the file under directories specified by option "documents" before
falling back to the current working directory.

Fixes #889
The booking method STRICT_WITH_SIZE was already implemented in core and
booking crates, but the parser rejected it as invalid. Add it to the
VALID_BOOKING_METHODS list and update the error message.

Fixes #891
Add loader-level tests for all 7 booking methods using full beancount
fixtures to verify end-to-end behavior:

- FIFO: matches oldest lot (existing fixture + test)
- LIFO: matches newest lot
- HIFO: matches highest-cost lot
- AVERAGE: merges lots and reduces from average
- NONE: works without cost tracking
- STRICT_WITH_SIZE: picks oldest exact-size match
- STRICT ambiguous: correctly errors when multiple lots match
- Per-account booking method: open directive overrides file-level default
- API-level override: LoadOptions.booking_method takes precedence

Fixes #891 (second comment verification)
- Add STRICT_WITH_SIZE to valid booking methods in parser
- Fix doc_markdown clippy warnings for STRICT_WITH_SIZE references
- Update 6 booking method test fixtures to match remote comprehensive tests
- Add 8 loader integration tests for booking methods
- Add 3 parser integration tests for STRICT_WITH_SIZE
- Optimize document.rs path resolution (remove redundant exists() calls, use Path::join)
- Add explanatory comments in LSP diagnostics for document_dirs resolution

Co-authored-by: AI Assistant
- Update run_validation to resolve documents via source_map base_dir
- Fix LSP build_validation_options_from_loader to accept and use base_dir
- Update build_validation_options_from_file to accept optional base_dir
- Address Copilot review comments on path resolution consistency
Previously, relative "option \"documents\"" paths in single-file
validation mode were resolved against the LSP process CWD, which
could produce false DocumentNotFound errors when the LSP was started
from a different directory than the ledger.

Thread the current file path through all_diagnostics and use its
parent directory as the base when building validation options in
single-file mode. Multi-file mode already resolved against the
ledger's base directory.

Also document the resolution precedence (absolute > document_base >
document_dirs > CWD fallback) on validate_document.
@robcohen
robcohen force-pushed the fix/issue-891-strict-with-size branch from 19841fe to 0b60579 Compare April 23, 2026 17:58
@robcohen
robcohen requested a review from Copilot April 23, 2026 17:58

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

Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.


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

Comment thread crates/rustledger-validate/src/lib.rs Resolved
Comment thread crates/rustledger-validate/src/lib.rs Resolved
Comment thread crates/rustledger-validate/Cargo.toml Resolved
@robcohen
robcohen added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit df30832 Apr 23, 2026
74 of 76 checks passed
@robcohen
robcohen deleted the fix/issue-891-strict-with-size branch April 23, 2026 18:28
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.

[Compat]: Compatibility with booking method STRICT_WITH_SIZE

2 participants