Skip to content

feat(commit): fail on reference trailers citing unresolvable Lore-ids - #79

Merged
Ian-stetsenko merged 1 commit into
mainfrom
feat/commit-ref-validation
Nov 9, 2026
Merged

Ian-stetsenko merged 1 commit into
mainfrom
feat/commit-ref-validation

Conversation

@TommyC81

@TommyC81 TommyC81 commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

lore commit now resolves every Supersedes / Depends-on / Related id against the repository's shared Lore-id index before creating the commit. A dangling id fails the commit (exit 1, nothing committed) with one batched validation error; format errors and resolution errors merge into a single failure so one retry fixes everything. A --no-verify-refs flag is the explicit escape hatch. The gate is best-effort: a transient index-build failure skips validation with a warning rather than blocking the commit.

Resolves #78.

Implementation

One commit, whose message carries the full design story. It was built and gated in four slices before squashing: (1) reference gate - resolution lives as methods on the atom repository (the index owner); the commit command receives the repository in its dependency bag exactly as the trace command does; unresolvable ids throw before the build, so nothing is committed. (2) --no-verify-refs - commander-negated always-defined boolean; joins NON_INPUT_KEYS so --amend --no-edit never trips input-conflict detection. (3) Merged batching + hints - format and reference issues merge into one error; two pinned hint sentences (git-hash shape: pure hex length 7 or 9-64; case-only mistake: 8-hex failing on case); near-match candidates (Hamming <= 2, index-order ties, cap 3); (trailer, id) dedup. (4) Best-effort + end-to-end proof - GitError-only catch emitting the fixed warning; interactive, unborn-HEAD, and unborn-HEAD-escape coverage; a real-git integration test drives the whole story on Windows.

Design notes (pre-empting review questions)

  • Why hard-fail when the validator only warns? The validator and doctor report after the fact, at warning severity, and demonstrably did not prevent 16 broken references in a production corpus. Prevention belongs at the moment of creation. This follows the project's own boundary-hardening precedent (0.7.0's --json unknown-key rejection): silent data loss is worse than a blocked commit. Scripts passing bad ids today are producing broken references; --no-verify-refs is their migration path.
  • Not git's --no-verify. That flag skips hooks; this flag skips only the reference check. The project ships hooks, so the near-collision is worth this sentence.
  • Severity vocabulary. The validator's reference-exists rule stays warning-severity in this PR (unchanged); aligning checking-surface vocabulary is a separate doctor-side change we'd like to discuss (see the companion issue's downstream notes).
  • The rule field in JSON errors. main.ts's JSON error mapping drops the rule name today (pre-existing, shared by all validation errors). A follow-up idea for scriptability; deliberately not touched here.
  • Hooks. The commit-msg hook runs the validator (warnings) and never this gate - no interplay change.
  • main.ts. Carries exactly one wiring line (the repository into the commit command's dependency bag), mirroring the trace command's existing seam.
  • Tests and tsconfig. The repo tsconfig excludes tests/, so the non-optional options key cannot fail the main typecheck - the PR uses a scoped tsc as proof. An observation, not a fix; happy to discuss adding a tests tsconfig separately.

Testing

36 files / 558 tests green on Windows (baseline 512 at main): +46 tests across the command seam, the repository service seam, and a new real-git integration suite (hermetic temp-dir git env: dangling id fails creating nothing - asserted via direct git rev-list --count - then the corrected id and the escape hatch each succeed). Behavior pins are mutation-verified (replay-on-error, catch-type, ignored-flag, and gate-neutering mutants all turn the suite red).

Changelog (maintainer surface)

This PR deliberately does not touch CHANGELOG.md; changelog entries are the maintainer's surface. Suggested line if wanted: lore commit reference validation - Supersedes/Depends-on/Related Lore-ids are now resolved against repository history before committing; a dangling id fails the commit with near-match suggestions instead of committing a broken link, --no-verify-refs skips the check, and a transient index build failure degrades to a fixed warning so "could not check" stays distinguishable from "check failed".

lore commit now resolves every Supersedes / Depends-on / Related id against the repository's shared all-refs Lore-id index before creating the commit. A dangling id fails the commit (exit 1, nothing committed) with one batched validation error that merges format and resolution issues, so one retry fixes everything. Format errors gain actionable hints: a pasted git-hash shape (pure hex, length 7 or 9-64) and a case-only mistake (8-hex failing on case) each get a targeted sentence; resolution errors suggest near matches (Hamming distance <= 2, capped at 3). A --no-verify-refs flag is the explicit escape hatch for the rare legitimate case (an atom existing only on an unfetched branch); it skips only this check, not hooks. The gate is best-effort: a transient index-build failure (GitError) skips validation with a fixed warning, so "could not check" stays distinguishable from "check failed". Resolution semantics match lore trace exactly (all refs, HEAD-preferred), and the commit-msg validator's warning-severity reference-exists rule is unchanged. Rationale: the existing checking surfaces report after the fact at warning severity and demonstrably did not prevent 16 broken references in a production corpus; prevention belongs at the moment of creation. CHANGELOG.md is untouched (maintainer surface).

Lore-id: 2d88edb7
Constraint: --no-verify-refs joins NON_INPUT_KEYS so --amend --no-edit never trips input-conflict detection
Constraint: Best-effort catch is GitError-only; other failures propagate
Constraint: CHANGELOG.md stays out of the PR; the maintainer authors changelog entries
Tested: Command and service seams plus a real-git integration suite (hermetic temp-dir repo): a dangling id fails creating nothing (asserted via direct git rev-list --count), then the corrected id and the escape hatch each succeed
Tested: Full gate on Windows: 36 files / 558 tests (baseline 512 at main), +46 tests
Confidence: high
Scope-risk: narrow
@TommyC81
TommyC81 force-pushed the feat/commit-ref-validation branch from 5cc5fff to 3ed6294 Compare November 7, 2026 13:52
@Ian-stetsenko
Ian-stetsenko merged commit 7f42cdc into main Nov 9, 2026
3 checks passed
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.

lore commit should fail when reference trailers cite Lore-ids that resolve on no ref

2 participants