test: fix hook integration test flakiness on Windows CI (#18665)

This commit is contained in:
N. Taylor Mullen
2026-02-15 11:42:13 -08:00
committed by GitHub
parent 7f7424dd1e
commit 884acda2dc
7 changed files with 555 additions and 317 deletions

View File

@@ -35,7 +35,6 @@ const DEFAULT_HOOK_TIMEOUT = 60000;
* Exit code constants for hook execution
*/
const EXIT_CODE_SUCCESS = 0;
const EXIT_CODE_BLOCKING_ERROR = 2;
const EXIT_CODE_NON_BLOCKING_ERROR = 1;
/**
@@ -353,28 +352,25 @@ export class HookRunner {
// Parse output
let output: HookOutput | undefined;
if (exitCode === EXIT_CODE_SUCCESS && stdout.trim()) {
const textToParse = stdout.trim() || stderr.trim();
if (textToParse) {
try {
let parsed = JSON.parse(stdout.trim());
let parsed = JSON.parse(textToParse);
if (typeof parsed === 'string') {
// If the output is a string, parse it in case
// it's double-encoded JSON string.
parsed = JSON.parse(parsed);
}
if (parsed) {
if (parsed && typeof parsed === 'object') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
output = parsed as HookOutput;
}
} catch {
// Not JSON, convert plain text to structured output
output = this.convertPlainTextToHookOutput(stdout.trim(), exitCode);
output = this.convertPlainTextToHookOutput(
textToParse,
exitCode || EXIT_CODE_SUCCESS,
);
}
} else if (exitCode !== EXIT_CODE_SUCCESS && stderr.trim()) {
// Convert error output to structured format
output = this.convertPlainTextToHookOutput(
stderr.trim(),
exitCode || EXIT_CODE_NON_BLOCKING_ERROR,
);
}
resolve({
@@ -435,18 +431,18 @@ export class HookRunner {
decision: 'allow',
systemMessage: text,
};
} else if (exitCode === EXIT_CODE_BLOCKING_ERROR) {
// Blocking error
return {
decision: 'deny',
reason: text,
};
} else {
// Non-blocking error (EXIT_CODE_NON_BLOCKING_ERROR or any other code)
} else if (exitCode === EXIT_CODE_NON_BLOCKING_ERROR) {
// Non-blocking error (EXIT_CODE_NON_BLOCKING_ERROR = 1)
return {
decision: 'allow',
systemMessage: `Warning: ${text}`,
};
} else {
// All other non-zero exit codes (including 2) are blocking
return {
decision: 'deny',
reason: text,
};
}
}
}

View File

@@ -18,6 +18,9 @@ export interface PtyProcess {
}
export const getPty = async (): Promise<PtyImplementation> => {
if (process.env['GEMINI_PTY_INFO'] === 'child_process') {
return null;
}
try {
const lydell = '@lydell/node-pty';
const module = await import(lydell);