Repository navigation
fix: align include-cycle error wording with Python beancount - #767
Conversation
rustledger previously reported circular includes as `"include cycle detected: a -> b -> a"`. Python beancount reports the same condition as `"Duplicate filename parsed: \"a\""`. The pta-standards `include-cycle-detection` conformance test asserts on the substring `"Duplicate filename"`, so rustledger's wording didn't match even though both tools correctly detect the cycle. See #765. Change `LoadError::IncludeCycle`'s Display to lead with beancount's phrasing while preserving the cycle path for debuggability: Duplicate filename parsed: "/path/a.beancount" \ (include cycle: /path/a.beancount -> /path/b.beancount -> \ /path/a.beancount) The duplicate filename is `cycle.last()`, which is the path re-encountered during traversal and is equal to one of the earlier entries. Also collapse the two hardcoded CLI strings in `crates/rustledger/src/cmd/check.rs` (JSON and stdout paths) to use `load_error.to_string()` instead of reconstructing the message. This makes the `#[error(...)]` attribute on the variant the single source of truth and prevents future wording drift between the library error and the CLI output. Regression test: `test_include_cycle_display_contains_duplicate_filename_issue_765` in `rustledger-loader/tests/loader_test.rs` pins the exact substrings the conformance suite depends on (`"Duplicate filename"`, the cycle file name, and `"include cycle:"` for the debuggability guarantee). Closes #765 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR aligns rustledger’s circular-include (LoadError::IncludeCycle) error wording with Python beancount by leading with Duplicate filename parsed, while preserving the include-cycle path for debugging, to satisfy pta-standards conformance (issue #765).
Changes:
- Updated
LoadError::IncludeCycle’sDisplayformat string to includeDuplicate filename parsed: "<file>"plus the cycle path in parentheses. - Updated
rustledger checkto use the canonicalLoadErrorDisplaystring for both JSON diagnostics and stdout output. - Added a regression test that pins the required substrings in the rendered
IncludeCycledisplay.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger/src/cmd/check.rs | Routes IncludeCycle diagnostics/printing through LoadError::to_string() to keep wording centralized. |
| crates/rustledger-loader/src/lib.rs | Changes IncludeCycle Display text to match beancount substring requirements while retaining cycle path. |
| crates/rustledger-loader/tests/loader_test.rs | Adds a regression test asserting the new display string contains required substrings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Benchmark Results
vs main branch (2026-04-11)
What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
|
Acknowledging @Copilot's inline comment on The code compiles cleanly, which you can verify from the CI status: Copilot's suggestion (adding No code changes. |
Bumps the whole workspace from 0.11.0 to 0.12.0 (minor version bump under pre-1.0 semver because the cycle since 0.11.0 includes user-visible breaking changes that release-plz's auto-detection missed). release-plz auto-generated a v0.11.1 patch bump from the `fix:` / `feat:` commits since 0.11.0. That's too conservative. The cycle since 0.11.0 shipped the following breaking changes, all merged as `refactor:` / `fix:` without the `!` conventional-commit marker: - **`rustledger_booking::BookingError`** collapsed three variants (`InsufficientUnits`, `NoMatchingLot`, `AmbiguousMatch`) into a single `Inventory(AccountedBookingError)` variant (#751). Out-of-tree consumers pattern-matching on the old variants break. - **`rustledger_core::AccountedBookingError`** added as a new canonical user-facing type with `BookingError::with_account()` as the constructor (#751). Not a break on its own, but part of the unification. - **`rustledger_lsp::handlers::diagnostics::all_diagnostics`** signature changed to take an additional `other_buffer_overlays: &[(u16, &[Spanned<Directive>])]` parameter for multi-buffer LSP overlays (#760 / #764). - **`rustledger_lsp::handlers::diagnostics::validation_errors_to_diagnostics`** signature changed to take an owned `Vec<Spanned<Directive>>` instead of borrowed slices (#758). Optimizes a hot path but breaks the function's public signature. - **`rustledger_loader::LoadError::IncludeCycle`** Display format rewritten to match Python beancount's `"Duplicate filename parsed: ..."` wording (#767). Substring-matching consumers break. Under pre-1.0 semver, any breaking change should bump the minor version (0.x → 0.(x+1)). So 0.11.0 → 0.12.0 is correct. Highlights since 0.11.0: ### Breaking - Unified `BookingError` under a single `Inventory` variant with one canonical `Display` impl, preventing the wording drift that produced #748 (#751). - `LoadError::IncludeCycle` Display now begins with `"Duplicate filename parsed: "` to match beancount's wording for conformance (#767). - LSP `all_diagnostics` and `validation_errors_to_diagnostics` signatures changed to support the multi-buffer overlay and avoid double-cloning directive lists (#758 / #764). ### Features - LSP live overlay so in-memory buffer edits reflect in diagnostics before save, for both the current file (#685 / #758) and any other open buffer in a multi-file ledger (#760 / #764). - Parser `Vec::with_capacity` hints with DoS caps on `source.len()` heuristics (#754). - `working_inventories` cloning in the booking engine now only touches accounts actually referenced in the transaction, and dedupes repeated account references (#756). ### Fixes - `InsufficientUnits` booking error wording restored to `"Not enough units in ..."` so pta-standards `reduction-exceeds-inventory` conformance assertion passes (#748 / #749). - `noduplicates` plugin now hashes flag, tags, links, cost, and price in addition to date and narration — complete beancount `hash_entry` parity (#746 / #747). - Parser test suite: 14 fake-coverage tests replaced with real tests that exercise the functions they claim to cover (#766). - All Copilot inline review comments on #754-#763, #766, #767 addressed in fix commits. - Closed PRs #768 (dead incremental parser) and #769 (hallucinated simdutf8 API) — no code shipped from these. ### Internal - Forbid-unsafe-code invariant now has a dedicated CI check and pre-push hook (#770). - New pre-push `cargo check` hook to catch compile errors before PRs are opened (#770). This commit supersedes release-plz's auto-generated v0.11.1 proposal to produce the minor bump the breaking changes require. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Closes #765.
Summary
rustledger reported circular includes as
"include cycle detected: a -> b -> a". Python beancount reports the same condition as"Duplicate filename parsed: \"a\"". The pta-standardsinclude-cycle-detectionconformance test asserts on the substring"Duplicate filename", so rustledger's wording didn't match even though both tools correctly detect the cycle.Before:
After:
The new wording leads with beancount's substring (satisfying conformance) and keeps the cycle path in a trailing parenthetical (preserving rustledger's debugging advantage).
What changed
LoadError::IncludeCycle#[error(...)]incrates/rustledger-loader/src/lib.rs— updated to the new format. The duplicate filename comes fromcycle.last(), which is always equal to one of the earlier entries in the cycle (that's how it got detected). Docstring explains why the wording is load-bearing.crates/rustledger/src/cmd/check.rsLoadError::IncludeCyclehandling — collapsed two hardcoded strings (JSON output and stdout output) to useload_error.to_string(). This makes the#[error(...)]attribute the single source of truth and prevents the library error and the CLI output from drifting apart again. Pattern matches what fix: restore "not enough" phrasing for InsufficientUnits booking error #749 did forInsufficientUnits.Regression test
test_include_cycle_display_contains_duplicate_filename_issue_765incrates/rustledger-loader/tests/loader_test.rspins three substrings that matter:"Duplicate filename"— the conformance assertioncycle_a.beancount— the file name is still shown"include cycle:"— the debuggability guarantee is preservedIf a future refactor drops any of these, the test fails loudly with the actual rendered string. Same pattern as #749's
test_insufficient_units_display_contains_not_enough.Test plan
cargo test -p rustledger-loader— 57 + 31 + 2 pass, including the new regression testcargo test --workspace --all-features— all suites green, 0 failurescargo clippy --all-features --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleaninclude-cycle-detectionshould flip from failing to passing once this landsNote for reviewers
The existing
test_load_include_cycle_detectiontest only inspects thecyclevec, not the Display string, so it continues to pass unchanged. The new test is additive and specifically targets the wording.