Repository navigation
refactor: single-source the booking-order comparator (LSP + validator) - #1734
Merged
Merged
Conversation
The booking order (date, priority, cost-reduction-last) had THREE implementations: the canonical rustledger_core::booking_sort_key, an inline tuple closure in LSP diagnostics, and a chained-cmp closure in the validator's sort. Found by the Phase-0 duplication sweep (P1, finalize-consumers family). Both copies now delegate to the canonical fn, so a change to booking order cannot silently skew LSP diagnostics or validation relative to the loader and booking engine. Also strengthens the LSP pipeline-approximation doc with the sweep's verdict: the LSP's single-pass pipeline (sort -> book -> all-plugins -> validate) remains a DELIBERATE approximation of the loader's interleaved phases — the overlay model swaps per-buffer directive sets that process() (which ingests a raw LoadResult) cannot accept, and finalize's only value-touching step (normalize_prices) runs AFTER Late validation in the loader too, so its absence in the LSP does not change diagnostics. The doc now names the canonical pipeline and the condition under which the approximation must be revisited (any future finalize step that feeds validation). LSP 261+ tests and validator suites green; behavior identical (the comparators were value-equal — this removes the possibility of future drift, not present drift). Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-07-10)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes duplicated implementations of the “booking order” comparator across the codebase by delegating to the canonical rustledger_core::booking_sort_key, ensuring consistent directive ordering between the loader/booking engine, validator, and LSP diagnostics.
Changes:
- Validator sorting now compares directives using
rustledger_core::booking_sort_key. - LSP diagnostics sorting now uses
rustledger_core::booking_sort_key(cached-key sort) to match canonical booking order. - Expanded LSP documentation clarifying why its validation/processing pipeline is an intentional approximation of the loader pipeline and when it must be revisited.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/rustledger-validate/src/lib.rs | Replaces a local chained comparator with the canonical booking_sort_key ordering. |
| crates/rustledger-lsp/src/handlers/diagnostics.rs | Switches directive sort key to booking_sort_key and documents the deliberate pipeline approximation and revisit condition. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…y (review) Co-Authored-By: Claude Fable 5 <[email protected]>
The comparator recomputed both full keys per comparison, paying the O(postings) cost-reduction walk even on date mismatches where the old then_with chain short-circuited. Decorate-sort-undecorate computes each key once; both sorts are stable so equal-key source order is unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From the Phase-0 duplication sweep (P1, finalize-consumers family) — right-sized after investigation.
What the sweep flagged vs what investigation found
The sweep flagged the LSP as "re-implements the loader pipeline inline" (the #1648 pattern). Investigation showed the LSP's single-pass pipeline is a deliberate, documented approximation — the overlay model swaps per-buffer directive sets that
process()(which ingests a rawLoadResult) cannot accept, andfinalize's only value-touching step (normalize_prices) runs after Late validation in the loader too, so its absence from the LSP does not change diagnostics. Wholesale pipeline replacement would be a risky rewrite of an engineered trade-off for zero diagnostic delta — deliberately not done.What WAS real duplication (fixed)
The booking-order comparator
(date, priority, cost-reduction-last)existed three times: canonicalrustledger_core::booking_sort_key, an inline tuple closure in LSP diagnostics, and a chained-cmp closure in the validator's sort (the sweep undercounted — the validator copy was found during implementation). Both copies now delegate to the canonical fn — booking-order changes can no longer silently skew LSP diagnostics or validation relative to the loader/booking engine.Also
The LSP approximation doc now records the review verdict, names the canonical pipeline, and states the exact condition requiring revisit (any future finalize step that feeds validation) — greppable at the site.
Verified
🤖 Generated with Claude Code