Commit Graph
3 Commits
Author SHA1 Message Date
timothyandClaude Opus 5 4822003004 fix(785): stop the tests writing to the PRODUCTION hook-fire log, and correct a mislabelled count
Two independent cold reviews, both against the real subjects rather than the diff. Five
findings; the first is the serious one.

HIGH — `test_worktree_ownership_guard.py` was defeating conftest's isolation. `_ENV` was a
module-level `{**os.environ, ...}` snapshot, taken at IMPORT time, which is before the
autouse `isolate_hook_fire_log` fixture monkeypatches `ETV_HOOK_FIRE_LOG_DIR`. So every
hook subprocess logged to the real `$HOME/.cache/ersatztv/hook-fire/`. Measured: 1,488
records for the two synthetic session ids, and one further run added 28 more.

That is #776's defect reintroduced inside the file meant to prove #776's hooks, and it
corrupts the surface `docs/guard-inventory.md` cites as the observability claim for every
guard still graded NONE. Nothing surfaced it because the fire-log library is fail-open by
design — a logging failure must leave the hook behaving exactly as an uninstrumented one.

The env is now built per call. Measured after: a full run of the file adds 0 records. The
stray records were deleted; `s1`/`unknown-session` were left alone, not being ours.

`test_the_subprocess_env_CARRIES_the_isolated_hook_fire_log_dir` pins it, witnessed red by
reintroducing the snapshot. It is per-file, which is the same narrowness as the guard that
should have caught this: `test_hook_fire_log.py::test_the_suite_does_not_write_to_the_
PRODUCTION_log` says conftest "must isolate every test, not just this file's" but checks
only the running test and its own sandbox. Recorded in the inventory and tracked in #809,
including why the obvious general check (diff the log dir per test) is racy against a real
session's hooks firing concurrently.

MEDIUM — a9433d5cb's commit message mislabels a measurement. It reports the ownership
comparison mutation as "2 failed, 8 passed (inverted)". Reproduced both: INVERTING the
clause reddens 8 of 12 at today's head; 2 failed / 8 passed is what DELETING it produces
(2 of 10 at that commit's head). The number is real but belongs to the mutation the
parenthetical says was rejected. The shipped test is unaffected — inversion genuinely
reddens `test_MUTATION_inverting_the_OWNERSHIP_COMPARISON_blocks_the_owner`. Corrected
here rather than by amending, since the history is the record.

LOW — `docs/guard-inventory.md` described the unproven set as "every PreToolUse hook
except ..." two paragraphs above a standing list of eight hooks spanning four events. Both
sentences named the same set. `design-sync-reminder.sh` is registered on BOTH PreToolUse
and Stop in `.claude/settings.json`, so any "every X hook" phrasing double-counts it; the
set is now named by enumeration.

LOW — a truncated sentence ("`test_hook_fire_log.py` asserts TWO clauses", no verb, no
closing bold) orphaned the following paragraph's "That unproven set". Completed with both
clauses and their proofs.

NIT — `_hook_calls` matched comment lines and only the `./` invocation form. A commented
ghost hook would have reddened a correct tree; a `bash .claude/hooks/x.sh` form would have
gone unstubbed and exited 127, which two tests read as "drift caught". Both verified.

Refs: #785
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 21:29:00 +02:00
timothyandClaude Opus 5 77317e5c71 test(785): pin the pre-push premise to both platforms, measured not assumed
The docstring said "git 2.55, macOS; the same holds on Linux". The second half was an
assertion, and this repo's canonical disaster (#775, the BOM guard) is precisely a guard
that behaved differently on the platform nobody measured — macOS had `xxd`, the Linux
runner did not, and it was fail-open there for months.

So it was measured on the runner host (Linux, git 2.47.3) rather than reasoned about:

  * git exports GIT_DIR=<repo>/.git/worktrees/<wt> to pre-push on a push from a worktree
  * `git rev-parse --show-toplevel` from web/ with that GIT_DIR answers `<wt>/web`
  * the nested `git diff --exit-code` reports exit 0 on a drifted file

and all three new suites were run there: 25 passed. Disarming the `unset` on that host
reddens 4 of the 9, the same four as on macOS.

Refs: #785
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 21:29:00 +02:00
timothyandClaude Opus 5 d05d6623d1 test(785): pin .husky/pre-push's unset GIT_DIR ..., and measure why it matters
The one-line fix at pre-push:11 had nothing pinning it, and #785 ranks it third because
the regression is a relocation rather than a deletion — a tidy-up that reads as a no-op.

What the investigation established, since the comment above it asserts the mechanism
without stating when it applies (git 2.55):

  * git exports GIT_DIR to pre-push when the push comes FROM A WORKTREE, and exports
    nothing from the main tree. `process.shared-tree-readonly` makes the worktree the
    mandated way to work here, so the exposed path is the normal one, not an edge case.
  * with GIT_DIR set and GIT_WORK_TREE unset, git stops discovering the repo and treats
    the CURRENT DIRECTORY as the work tree: `git rev-parse --show-toplevel` from web/
    answers `<wt>/web`.
  * so `cd web && npm run check:api`'s `git diff --exit-code` compares against index
    paths that do not exist there and reports NO DIFF, exit 0. Generated-API drift ships
    and the gate prints success.

The test drives the real pre-push file unedited, in a real worktree, with that exact
environment; the hook calls are stubs (DERIVED from the file, so a new hook cannot leave
the harness dying at a missing script and calling that a red) and `npm` is a stand-in
whose `run check:api` performs the nested diff.

Both mutations witnessed red against the real file: deletion -> 4 failed, 5 passed;
relocation to the end -> 5 failed, 4 passed.

The relocation mutation was wrong in the first draft. Appending the `unset` at the end
also makes it the script's last statement, and a bare `unset` succeeds — so a
`returncode == 0` assertion held for a reason unrelated to the nested git call. The
stand-in npm now records the nested diff's OWN exit code and the mutations assert on
that. Verified by making the mutation a no-op: the test fails, as it must.

Refs: #785
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 21:29:00 +02:00