Skip to content

Commit df4d3cd

Browse files
committed
test(prepush): require reaper stamps and await stub teardown
The cleanup-deadline check now fails by name when the reaper wrote no stamp, the never-up row waits up to 5 s for its stub to exit, and the spawn-timeout row's stand-in execs sleep so its process keeps the row directory in its command line. The focus fixture's doc comment sits back above decide().
1 parent 023e15e commit df4d3cd

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎tests/prepush_cap_smoke.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ describe('the hard stop ends the legs of a real hook run', () => {
304304
const recorded = reaperRecord()
305305
rmSync(dir, { recursive: true, force: true })
306306
expect(reaperGone, `the cleanup process ${reaper} never exited`).toBe(true)
307+
if (reaper > 1 && reaperGone) {
308+
expect(gone, `the cleanup process ${reaper} wrote no "hook gone" stamp\n${recorded}`).not.toBeNull()
309+
expect(exited, `the cleanup process ${reaper} wrote no "exit" stamp\n${recorded}`).not.toBeNull()
310+
}
307311
if (gone !== null && exited !== null) expect(exited - gone, `the cleanup process outlived its deadline, past the end of the row\n${recorded}`).toBeLessThanOrEqual(REAP_GRACE_S)
308312
// A row whose cleanup ended the runner shows up as a vitest run that exits 0 with no summary; this names the row instead, while the worker still lives to say so.
309313
expect(runnerAlive(), `the vitest runner (pid ${process.ppid}) was ended during this row`).toBe(true)
@@ -378,9 +382,9 @@ describe('the hard stop ends the legs of a real hook run', () => {
378382
const marker = path.join(dir, 'slow-reaper.pid')
379383
writeFileSync(path.join(dir, '.lefthook-scripts', 'prepush-reaper.sh'), `#!/usr/bin/env bash\necho "$(cat /proc/$$/winpid 2>/dev/null || echo $$)" >"${slash(marker)}"\nexec sleep 300\n`)
380384
const r = runHook({ PREPUSH_HARD_STOP_S: '8' })
381-
// Ended by the hook itself on its way out, so the stub is gone at once; a survivor is ended here first so the row fails by name.
385+
// The hook ends the stub on its way out; the wait is bounded at 5 s, and a survivor is ended here after it so the row fails by name.
382386
const stub = Number(readFileSync(marker, 'utf8').trim())
383-
const stubGone = goneWithin(stub, 0)
387+
const stubGone = goneWithin(stub, 5)
384388
if (!stubGone) endRecordedTrees([marker], dir)
385389
expect(stubGone, `the slow cleanup process ${stub} outlived the hook`).toBe(true)
386390
expect(r.timedOut, r.out).toBe(false)
@@ -392,7 +396,7 @@ describe('the hard stop ends the legs of a real hook run', () => {
392396
// A hook still starting when the spawn timeout ends it leaves its tree behind; the row ends that tree, so the directory can be removed and nothing outlives the row.
393397
hookRow('a hook the spawn timeout ended leaves no process holding its directory', () => {
394398
const marker = path.join(dir, 'slow-reaper.pid')
395-
writeFileSync(path.join(dir, '.lefthook-scripts', 'prepush-reaper.sh'), `#!/usr/bin/env bash\necho "$(cat /proc/$$/winpid 2>/dev/null || echo $$)" >"${slash(marker)}"\nsleep 300\n`)
399+
writeFileSync(path.join(dir, '.lefthook-scripts', 'prepush-reaper.sh'), `#!/usr/bin/env bash\necho "$(cat /proc/$$/winpid 2>/dev/null || echo $$)" >"${slash(marker)}"\nexec sleep 300\n`)
396400
const r = runHook({}, 8000)
397401
expect(r.timedOut, 'the hook returned before the spawn timeout, so it was not still starting').toBe(true)
398402
const tag = path.basename(dir)

‎tests/prepush_focus.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ function firstCommitTemplate(seed: Record<string, string>): { dir: string; base:
110110
return made
111111
}
112112

113-
/** A sandbox repo with one recorded failing test, then the given files changed in a second commit. Returns the decision note and the focus list. */
114113
// The caller's environment without the PREPUSH_ and TG_PREPUSH_ knobs (PREPUSH_FULL, the budgets, the elapsed seconds), so only what a test sets reaches the script.
115114
const inheritedEnv = (): NodeJS.ProcessEnv => Object.fromEntries(Object.entries(process.env).filter(([k]) => !/^(?:TG_)?PREPUSH_/.test(k)))
116115

116+
/** A sandbox repo with one recorded failing test, then the given files changed in a second commit. Returns the decision note and the focus list. */
117117
function decide(change: Record<string, string>, env: Record<string, string> = {}, opts: DecideOpts = {}): { note: string; focus: string[]; deferred: string } {
118118
// The sandbox is reached through a symlink, as every macOS temp directory is (/var points into /private): a script that mistakes a symlinked path for a different file does nothing here
119119
realDir = mkdtempSync(path.join(tmpdir(), 'tg-focus-'))

0 commit comments

Comments
 (0)