Repository navigation
fix: prefer HEAD-reachable atoms in Lore-id lookups, add doctor --all (fixes #57) - #74
Conversation
Implements the maintainer's accepted proposal for issue #57. Previously findByLoreId ran a single git log --all grep, so the newest commit by date across every ref won: a future-dated commit on a side branch sharing a Lore-id shadowed the legitimate current-branch atom in lore trace, while lore doctor (current-branch scan only) stayed silent. (a) findByLoreId now greps the HEAD-reachable history first and consults --all only on a miss, so a side branch can never shadow the current branch. The #67 Lore-id index follows the same rule: one HEAD pass seeds every id, then an --all pass fills only missing ids, keeping trace BFS, follow-link resolution, and reference validation consistent with the grep path. A failing HEAD pass (unborn branch on a fresh repo) is treated as a miss so fresh-repo behavior is unchanged. (b) lore doctor --all opts the Lore-id uniqueness check into scanning every ref (findAll allRefs: --all) and reports duplicates found across refs as 'Lore-id uniqueness (all refs)'. Default output is unchanged; off by default because backup branches make cross-ref duplicates noisy. (c) not implemented: no collision guard in lore commit, per the proposal. Review hardening: the duplicated maxCommits bound in doctor is extracted to the DOCTOR_SCAN_LIMIT constant. Docs follow the contributor convention verified from merge history (#55, #56, #59, #66, #67): README doctor row and PROJECT_ARCHITECTURE lookup-semantics notes added in-PR; CHANGELOG.md left untouched because the changelog is maintainer-owned, written at release time with contributor credits. Lore-id: d181468e Constraint: findByLoreId stays a targeted git log --grep per id; no full-index build for single lookups Constraint: getLoreIdIndex keeps its single ReadonlyMap API so trace BFS, validator, and follow-link consumers stay unchanged Constraint: doctor default output must stay byte-equivalent to before; --all only widens the uniqueness scan Constraint: fresh-repo (unborn HEAD) behavior preserved: lookups return null/empty, not a git error Constraint: CHANGELOG.md is maintainer-owned release notes; contributors update README and PROJECT_ARCHITECTURE in-PR (verified from merge history of #55/#56/#59/#66/#67) Rejected: Keeping the single --all pass with newest-first ordering: that is the reported bug (side-branch shadowing) Rejected: Collision guard in lore commit: maintainer explicitly deferred it as (c) Rejected: Replacing the index API with a two-tier lazy lookup method: ripples through trace and validator consumers for no behavioral gain Rejected: Swallowing --all pass failures: real git errors must stay loud; only the HEAD pass falls through Directive: If a commit-time collision guard is ever added, keep it a warning; the maintainer deliberately deferred it Directive: Keep lookup HEAD-first when extending to new consumers; do not reintroduce bare --all-first resolution Tested: npm run build Tested: npm run typecheck Tested: npm test: 484 passing (467 baseline + 17 new) Tested: integration repro of issue #57: trace resolves the HEAD-reachable atom over a 2030-dated poison commit, doctor default silent, doctor --all reports the duplicate Tested: unit: HEAD-hit skips --all, miss falls back to --all, unborn-HEAD HEAD-pass failure falls back, index HEAD-preference and off-branch fill Tested: integration: fresh repo (no commits) returns null and empty index Tested: review-fix re-run: full suite 484 green after DOCTOR_SCAN_LIMIT extraction Not-tested: performance on very large corpora with many refs (two log passes per index build) Not-tested: repositories with a detached HEAD Confidence: high Scope-risk: moderate Reversibility: clean
|
Merged to One non-blocking follow-up if you feel like it: |
|
Taking up the non-blocking follow-up from your review: #75 makes the second pass walk only the delta. One design note beyond the suggestion: instead of |
Follow-up on PR Ian-stetsenko#74 (d181468e), from the maintainer's review note: getLoreIdIndex walked HEAD history twice. The HEAD pass seeds every reachable id, then the --all pass re-walked and re-parsed those same commits before first-wins deduplication discarded the duplicate work. On small repositories the cost is unmeasurable; on a 1.4M-commit corpus (issue Ian-stetsenko#55) every index build pays the double walk. The index now resolves HEAD once, walks exactly that pinned commit, then runs git log --all --not <pin> for the delta. Resolving before walking is what makes the pin sound under concurrency: the first pass always walks exactly the commit the second pass excludes, so the exclusion boundary stays self-consistent under concurrent branch movement or landing commits - walked history is never dropped from the delta pass and new history is never hidden from it (which duplicate of a mid-build-landing shared Lore-id wins first-wins remains timing-dependent, as it was before). Plain --all remains the fallback whenever HEAD cannot be resolved (unborn HEAD on a fresh repository, a single --all walk) or the pinned walk fails (the exclusion is given up so --all covers HEAD). Semantics are unchanged: pinned-pass atoms are inserted first and the delta pass only fills missing ids, so a side branch can never shadow the current branch (issue Ian-stetsenko#57), and newest-first first-wins within each pass keeps the same atom a grep-based findByLoreId returns. Coverage: unit tests pin the exact args of both passes in all three paths (pinned walk then delta; unresolved HEAD, single --all; walk failure then plain --all), and a real-git integration test asserts the index itself holds the side-branch-only id and lets the HEAD-reachable atom win the shared id, alongside the existing shadowing and unborn-HEAD integration tests. Lore-id: de1d01a2 Constraint: Resolve HEAD before walking and walk the pinned commit: the pin must always equal what the first pass walked, or the delta exclusion can misclassify history under concurrent branch movement. Constraint: Unresolved HEAD and failed pinned walk both keep the plain --all fallback, so the union of the passes never shrinks below git log --all. Constraint: Index semantics stay identical to PR Ian-stetsenko#74: HEAD-reachable atoms win, delta pass fills only missing ids, first-wins within each pass. Tested: npm run typecheck: clean Tested: Full suite on Windows: 508 tests in 34 files, all passing Tested: Unit: pass-1 args are [pin], pass-2 args ['--all', '--not', pin] after a successful walk; unresolved HEAD runs a single ['--all'] walk; a failed pinned walk falls back to ['--all'] with head atoms retained Tested: Real-git integration: the index holds the side-branch-only id (cafe1234) and the HEAD-reachable atom wins the shared id (deadbeef); existing unborn-HEAD and shadowing integration tests pass Related: d181468e Confidence: high Scope-risk: narrow Reversibility: clean
lore traceresolved Lore-ids with a singlegit log --allgrep, so the newest commit by date across every ref won. A side branch (or a future-dated "poison" commit) sharing a Lore-id could shadow the legitimate current-branch decision, whilelore doctor, which scans only the current branch, stayed silent about the duplicate.This implements the accepted proposal:
findByLoreIdnow greps the HEAD-reachable history first and consults--allonly on a miss, and the Lore-id index is built the same way (HEAD pass seeds,--allpass fills misses) so trace BFS and reference validation stay consistent.lore doctor --allopts the Lore-id uniqueness check into scanning every ref and reports duplicates found across refs; the default stays current-branch only to avoid backup-branch noise, and no collision guard was added tolore commitper the plan. An integration test mirrors the reproduction from #57 (future-dated poison commit on a side branch plus a HEAD-reachable commit sharing the Lore-id) and covers trace resolution, silent default doctor,doctor --allreporting, and the side-branch-only fallback. Full suite is 484 green.README and PROJECT_ARCHITECTURE updated in-PR; CHANGELOG left for release notes per repo convention.