Skip to content

fix: resolve document paths against option "documents" directories - #899

Merged
robcohen merged 1 commit into
mainfrom
fix/issue-889-document-dir
Apr 23, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/issue-889-document-dir

Conversation

@robcohen

@robcohen robcohen commented Apr 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Fix #889: document directives with relative paths (e.g. "./credit-card-statement.pdf") now resolve against option "documents" directories before falling back to CWD.

This PR builds on main (which already has the basic document_dirs search) to:

  • Store resolved absolute PathBuf instead of raw String so resolution is stable regardless of the process CWD
  • Mark ValidationOptions #[non_exhaustive] + add builder methods so downstream crates don't break when new fields are added
  • Use portable Path::join everywhere (no more OS-specific "{}/{}" concat)
  • Make test filenames unique so the CWD fallback can't accidentally resolve to a collider

Changes

  • rustledger-validate:
    • ValidationOptions.document_dirs: Vec<PathBuf> (was Vec<String>)
    • #[non_exhaustive] on ValidationOptions
    • New builder methods: with_account_types, with_require_commodities, with_check_documents, with_warn_future_dates, with_document_dirs, with_infer_tolerance_from_cost, with_tolerance_multiplier, with_inferred_tolerance_default
    • validate_document doc comment describes resolution precedence (absolute → document_base → document_dirs → CWD fallback)
    • Tests use unique filenames (rustledger_test_889_*.pdf) to avoid CWD collisions
    • tempfile now uses tempfile.workspace = true for consistency with the rest of the workspace
  • rustledger-loader: run_validation builds ValidationOptions via builder chain, passes resolved Vec<PathBuf> document dirs
  • rustledger-lsp: build_validation_options_from_loader and build_validation_options_from_file return Vec<PathBuf> and use builder methods; signatures preserve the base_dir: Option<&Path> threading added by fix: add STRICT_WITH_SIZE to parser valid booking methods #900

Known CI failures

  • Semver: ValidationOptions.document_dirs type change (Vec<String> → Vec<PathBuf>) is a breaking change requiring a major version bump. Addressed separately at release time.

Copilot review comments addressed

All 7 original + 4 re-review comments addressed:

  • document_dirs resolved to absolute paths at load time
  • #[non_exhaustive] + builder methods eliminate struct-literal breakage
  • Tests use PathBuf::join instead of format! with path separators
  • Error context uses Path::join for portable paths
  • Unique test filenames avoid CWD non-determinism
  • tempfile now uses workspace dependency
  • README scope creep dropped on rebase (already on main via PR docs: update README with import pipeline, categorization, and ops crate #898)
  • Stale doc comment on build_validation_options_from_file replaced

Copilot AI review requested due to automatic review settings April 23, 2026 15:19
@robcohen
robcohen requested a review from a team as a code owner April 23, 2026 15:19
@codecov

codecov Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.82716% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-lsp/src/handlers/diagnostics.rs 76.47% 4 Missing ⚠️
crates/rustledger-loader/src/process.rs 92.85% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 30.7ms ± 0.6ms 21.5 MB
beancount 882.4ms ± 17.1ms 50 MB
Comparison 28.7x faster 2.3x less

vs main branch (2026-04-23)

Metric main this PR Change
Time 34.6ms 30.7ms -11.3% 🟢
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

Fixes #889 by improving how document directive file paths are resolved, preferring option "documents" directories before falling back to the current working directory.

Changes:

  • Add document_dirs to ValidationOptions and plumb it from loader/LSP into validation.
  • Update document validator to search document_dirs when resolving relative document paths.
  • Add validation tests for relative/absolute document path behaviors; add tempfile dev-dependency.

Reviewed changes

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

Show a summary per file
File Description
crates/rustledger-validate/src/validators/document.rs Resolve relative document paths by searching configured document directories and improve error context
crates/rustledger-validate/src/lib.rs Introduce document_dirs on ValidationOptions and add tests covering the new behavior
crates/rustledger-validate/Cargo.toml Add tempfile dev dependency for filesystem-based tests
crates/rustledger-loader/src/process.rs Pass documents option into validator options
crates/rustledger-lsp/src/handlers/diagnostics.rs Forward documents option into validation options for both loader-based and file-based validation
README.md Adds/updates “bank import” documentation and links
Cargo.lock Lockfile update for tempfile

💡 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-loader/src/process.rs Resolved
Comment thread README.md Resolved
@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

@robcohen
robcohen force-pushed the fix/issue-889-document-dir branch from d410d31 to 30d5c3d Compare April 23, 2026 18:14
robcohen added a commit that referenced this pull request Apr 23, 2026
…tability

- Change ValidationOptions.document_dirs from Vec<String> to Vec<PathBuf>
  to store resolved paths instead of raw values
- Add #[non_exhaustive] to ValidationOptions to prevent breaking changes
  when new fields are added
- Resolve document paths against source_map base_dir in run_validation()
  and build_validation_options_from_loader() to match run_plugins() behavior
- Use Path::join() instead of string concatenation for portable paths
- Fix test to use doc_subdir.join() instead of format! for path construction

Addresses Copilot review comments #1, #2, #3, #4, #5, #7 on PR #899
@robcohen
robcohen requested a review from Copilot April 23, 2026 18:14

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 5 out of 6 changed files in this pull request and generated 2 comments.


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

robcohen added a commit that referenced this pull request Apr 23, 2026
…tability

- Change ValidationOptions.document_dirs from Vec<String> to Vec<PathBuf>
  to store resolved paths instead of raw values
- Add #[non_exhaustive] to ValidationOptions to prevent breaking changes
  when new fields are added
- Resolve document paths against source_map base_dir in run_validation()
  and build_validation_options_from_loader() to match run_plugins() behavior
- Use Path::join() instead of string concatenation for portable paths
- Fix test to use doc_subdir.join() instead of format! for path construction

Addresses Copilot review comments #1, #2, #3, #4, #5, #7 on PR #899
@robcohen
robcohen force-pushed the fix/issue-889-document-dir branch from 30d5c3d to 7370ffe Compare April 23, 2026 18:20
robcohen added a commit that referenced this pull request Apr 23, 2026
…tability

- Change ValidationOptions.document_dirs from Vec<String> to Vec<PathBuf>
  to store resolved paths instead of raw values
- Add #[non_exhaustive] to ValidationOptions to prevent breaking changes
  when new fields are added
- Resolve document paths against source_map base_dir in run_validation()
  and build_validation_options_from_loader() to match run_plugins() behavior
- Use Path::join() instead of string concatenation for portable paths
- Fix test to use doc_subdir.join() instead of format! for path construction

Addresses Copilot review comments #1, #2, #3, #4, #5, #7 on PR #899
@robcohen
robcohen force-pushed the fix/issue-889-document-dir branch from 7370ffe to cf3c41a Compare April 23, 2026 18:48
…tability

- Change ValidationOptions.document_dirs from Vec<String> to Vec<PathBuf>
  to store resolved paths instead of raw values
- Add #[non_exhaustive] to ValidationOptions to prevent breaking changes
  when new fields are added
- Resolve document paths against source_map base_dir in run_validation()
  and build_validation_options_from_loader() to match run_plugins() behavior
- Use Path::join() instead of string concatenation for portable paths
- Fix test to use doc_subdir.join() instead of format! for path construction

Addresses Copilot review comments #1, #2, #3, #4, #5, #7 on PR #899
@robcohen
robcohen force-pushed the fix/issue-889-document-dir branch from cf3c41a to ae5e560 Compare April 23, 2026 18:53
@robcohen
robcohen added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit 1960448 Apr 23, 2026
36 of 38 checks passed
@robcohen
robcohen deleted the fix/issue-889-document-dir branch April 23, 2026 19:12
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.

[Bug]: Fail to recognize files under default documents directory

2 participants