test(git): align admission lifetime contracts

This commit is contained in:
Brennan Benson
2026-08-27 17:45:14 -07:00
parent b990e0a80f
commit bd3cc2f98c
6 changed files with 42 additions and 16 deletions
+8 -4
View File
@@ -67,6 +67,8 @@ export async function withGitAdmission(
return
}
finalized = true
child.off('error', handleError)
child.off('close', handleClose)
grant?.release()
if (error) {
span.fail(error)
@@ -74,21 +76,23 @@ export async function withGitAdmission(
span.end()
}
}
child.on('error', (error) => {
const handleError = (error: Error): void => {
if (!child.pid) {
finalize(error)
} else {
liveError = error
}
})
child.once('close', (code, signal) => {
}
const handleClose = (code: number | null, signal: NodeJS.Signals | null): void => {
const exitError =
liveError ??
(code === 0 && signal === null
? undefined
: new Error(`git exited with ${code ?? signal ?? 'unknown'}.`))
finalize(exitError)
})
}
child.on('error', handleError)
child.once('close', handleClose)
return child
} catch (error) {
grant?.release()