Repository navigation
fix: add STRICT_WITH_SIZE to parser valid booking methods - #900
Conversation
📊 Benchmark Results
vs main branch (2026-04-23)
What do these numbers mean?
|
There was a problem hiding this comment.
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_SIZEas a valid booking method in the parser and include it in the invalid-booking error message. - Add
ValidationOptions.document_dirsand use it to resolve relativeDocumentpaths againstoption "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_dirsis populated fromfile_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_documentsinrun_plugins). Passing the unresolved strings into validation meansvalidate_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 resolvingfile_options.documentsagainst the ledger base directory (same logic asrun_plugins) before passing them intoValidationOptions.
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.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
✅ Compatibility Test Results
What's tested
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.
19841fe to
0b60579
Compare
There was a problem hiding this comment.
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.
Summary
STRICT_WITH_SIZEas a valid booking methodrustledger-coreandrustledger-booking, but the parser'sVALID_BOOKING_METHODSlist was missing itSTRICT_WITH_SIZEin the list of valid optionsScope 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— AddedSTRICT_WITH_SIZEto valid booking methodscrates/rustledger-parser/src/error.rs— Updated error message to includeSTRICT_WITH_SIZESTRICT_WITH_SIZE(accept, reject, error-message content)Review-fix commits
fix(lsp): resolve single-file document_dirs against current file path— addresses Copilot's single-file mode concern; relativeoption "documents"paths now resolve against the current file's parent directory instead of the LSP process CWD.validate_documentnow has a doc comment describing the resolution precedence (absolute →document_base→document_dirs→ CWD fallback).Known CI failures
Inventory::is_reduced_byarity change,CsvConfigandValidationOptionsnew pub fields). These are being addressed separately in the release process.