Skip to content

fix(hook): tolerate untracked specs/INDEX.md + e2e suite - #17

Merged
morrieinmaas merged 1 commit into
mainfrom
fix/hook-tolerates-untracked-index
Jun 3, 2026
Merged

fix(hook): tolerate untracked specs/INDEX.md + e2e suite#17
morrieinmaas merged 1 commit into
mainfrom
fix/hook-tolerates-untracked-index

Conversation

@morrieinmaas

Copy link
Copy Markdown
Owner

Summary

Second real-user pre-commit-hook bug surfaced on sensor-sender (apple-updates branch): a back-in-time checkout had .zettelgeist.yaml in its history but no specs/INDEX.md, so the hook's regen --check hard-errored with specs/INDEX.md is missing and blocked every commit on that branch.

Fix: HOOK_BLOCK gains a second pre-flight that exits 0 when the index file isn't tracked on the current branch. Nothing to be stale about ⇒ nothing to enforce. Re-run install-hook to update existing hooks (they pick up the new block via the existing marker-region replacement).

Plus an end-to-end pre-commit suite that would have caught both this and the prior non-zg bug. The suite spins up real git repos and drives git commit through five states using a stub CLI on PATH:

  1. non-zg repo → commit passes; CLI not invoked
  2. zg repo, INDEX.md not in HEAD → commit passes; CLI not invoked
  3. zg repo, INDEX.md in HEAD + check passes → commit passes; CLI invoked
  4. zg repo, INDEX.md in HEAD + check fails → commit blocked; CLI invoked
  5. checkout to a pre-INDEX branch + commit → commit passes; CLI not invoked

(1) and (5) regression-guard the two real bugs; (3) and (4) pin the "actually-stale state must still block" invariant the hook exists for.

Changes

  • packages/git-hook/src/install-hook.ts — second pre-flight in HOOK_BLOCK: git ls-files --error-unmatch specs/INDEX.md >/dev/null 2>&1 || exit 0.
  • packages/git-hook/tests/install-hook.test.ts — unit assertion the new guard string is present.
  • packages/git-hook/tests/pre-commit-e2e.test.ts — new e2e suite (5 cases).
  • .changeset/hook-skips-when-index-not-tracked.md — cli patch.

Workaround for currently-stuck users (pre-merge)

Run zettelgeist regen on the stuck branch — that materializes specs/INDEX.md, then commits pass. Or rm .git/hooks/pre-commit and reinstall after upgrading.

Test plan

  • pnpm -r typecheck — clean
  • pnpm -r test — all 9 packages, all green
  • pnpm conformance — 46 fixtures
  • new e2e tests cover both real bug shapes + the must-still-block invariant
  • After merge: Version Packages PR → publish from local
  • After publish: rebuild + ship 0.4.3 vsix to Open VSX + Microsoft Marketplace

Second real-user pre-commit-hook bug surfaced on `sensor-sender`:
checking out a branch that predates the first `regen` (or a fresh
init pre-regen) carried `.zettelgeist.yaml` but had no `specs/INDEX.md`
in its history, so the hook's `regen --check` errored with
`specs/INDEX.md is missing` and blocked every commit on the branch.

Fix: HOOK_BLOCK gains a second pre-flight —
  git ls-files --error-unmatch specs/INDEX.md >/dev/null 2>&1 || exit 0
If the index file isn't tracked on the current branch there's nothing
to be stale about, and the hook exits 0. Re-run `install-hook` to
update existing hooks (they pick up the new block via marker-region
replacement, no config change needed).

Add an end-to-end pre-commit suite under packages/git-hook/tests that
spins up real git repos, installs the hook through the same code path
users hit, and drives `git commit` through five states:

  1. non-zg repo                              → commit passes; CLI not invoked
  2. zg repo, INDEX.md not in HEAD            → commit passes; CLI not invoked
  3. zg repo, INDEX.md in HEAD + check passes → commit passes; CLI invoked
  4. zg repo, INDEX.md in HEAD + check fails  → commit blocked; CLI invoked
  5. checkout to a pre-INDEX branch + commit  → commit passes; CLI not invoked

The CLI is stubbed with a small `zettelgeist` shell shim on PATH so we
can deterministically drive both the success-path and the failure-path
and assert pre-flight reachability via a touched marker file. Tests (1)
and (5) regression-guard the two real bugs users have hit; the others
pin the "actually-stale state must still block" invariant the hook
exists for.
@morrieinmaas
morrieinmaas merged commit 95a7adc into main Jun 3, 2026
2 checks passed
@morrieinmaas
morrieinmaas deleted the fix/hook-tolerates-untracked-index branch June 3, 2026 08:04
morrieinmaas added a commit that referenced this pull request Jun 3, 2026
Carries the hook fix from #17 (tolerate branches without tracked
specs/INDEX.md) via the @zettelgeist/git-hook workspace dep. Already
published to Open VSX as morrieinmaas.zettelgeist@0.4.3; MS
Marketplace gets zettelgeist-msm-0.4.3.vsix uploaded manually.
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.

1 participant