Skip to content

Commit d6ccca9

Browse files
committed
fix(test): skip prepush rows on bash without assoc arrays
The prepush focus note rows drive the hook through run-with-bash-5.sh, which refuses on macOS /bin/bash 3.2, so they now skip on HOOK_BASH_FOUND like the decision rows. The hard-stop hook rows run run-all-checks.sh on plain bash, which stops at its declare -A line on bash 3.2, so they skip on a bash without associative arrays and a row asserts that refusal.
1 parent 1e4c536 commit d6ccca9

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎tests/prepush_cap_smoke.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ describe('writeOwed', () => {
9999

100100
// Git Bash on Windows: a bare `bash` may be WSL's, so the Windows path is spelled out.
101101
const GIT_BASH = process.platform === 'win32' ? 'C:/Program Files/Git/bin/bash.exe' : 'bash'
102+
// Whether GIT_BASH has associative arrays, which run-all-checks.sh declares at its top (`declare -A`): macOS ships bash 3.2, where the hook stops on that line. Windows names Git Bash directly.
103+
const HOOK_BASH_HAS_ASSOC = process.platform === 'win32' || spawnSync(GIT_BASH, ['-c', 'declare -A probe'], { encoding: 'utf8' }).status === 0
102104
const CAP_SCRIPT = fileURLToPath(new URL('../.lefthook-scripts/prepush-cap.sh', import.meta.url))
103105
const slash = (p: string): string => p.replace(/\\/g, '/')
104106
// How long after the hook's exit the cleanup process may keep ending legs, read from the script so a change to the constant cannot pass unnoticed.
@@ -250,7 +252,16 @@ afterAll(() => {
250252

251253
// The hook's own stop path, run for real: a temp copy of .lefthook-scripts and scripts, with the four leg scripts replaced by stubs that sleep for a set time and record their pid. The seam is the copy; nothing in the hook is stubbed but the legs.
252254
describe('the hard stop ends the legs of a real hook run', () => {
253-
const bashAvailable = process.platform !== 'win32' || existsSync(GIT_BASH)
255+
// The rows below are gated on HOOK_BASH_HAS_ASSOC: the hook cannot start on a bash without associative arrays.
256+
const bashAvailable = (process.platform !== 'win32' || existsSync(GIT_BASH)) && HOOK_BASH_HAS_ASSOC
257+
258+
// Only where GIT_BASH is older than 4.0: the rows below are skipped there, and this row pins the reason (the hook's `declare -A` is refused). CAPTURE: the `invalid option` text is from the macOS CI log of run 43028369623, job 130548734108.
259+
it.skipIf(HOOK_BASH_HAS_ASSOC)('the bash on this host has no associative arrays, which the hook declares at its top', () => {
260+
const r = spawnSync(GIT_BASH, ['-c', 'declare -A probe'], { encoding: 'utf8' })
261+
expect(r.status).not.toBe(0)
262+
expect(r.stderr).toContain('invalid option')
263+
})
264+
254265
const REPO = fileURLToPath(new URL('..', import.meta.url))
255266
// The stop fires as an event, not on the clock. The hook's start-up and planning are about 25 process starts before the first leg, 0.1 s each on a quiet host and 2 to 3 s each on this loaded Windows one (a stop timed against that start-up fired before any leg began, 2026-10-27), so a stub leg ends the watchdog by TERM once it has started: the watchdog's own TERM trap exits it, which wait_legs reads as the stop. HOOK_STOP_S is only the watchdog's own deadline, set past anything a row reaches.
256267
const HOOK_STOP_S = 300

‎tests/prepush_focus.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe.skipIf(BASH === null || !CAN_JUNCTION || !HOOK_BASH_FOUND)('prepush foc
344344
})
345345
})
346346

347-
describe.skipIf(BASH === null || !CAN_JUNCTION)('prepush focus note', () => {
347+
describe.skipIf(BASH === null || !CAN_JUNCTION || !HOOK_BASH_FOUND)('prepush focus note', () => {
348348
it('an empty range is a doubt that still runs the guards', () => {
349349
const r = decide({})
350350
expect(r.note).toContain('win leg focused')

0 commit comments

Comments
 (0)