skip one flaky integration test (#1137)

This commit is contained in:
tanzhenxin
2025-12-03 19:40:14 +08:00
committed by GitHub
parent e426c15e9e
commit 2ca36d7508

View File

@@ -10,71 +10,67 @@ import { TestRig } from './test-helper.js';
describe('Ctrl+C exit', () => { describe('Ctrl+C exit', () => {
// (#9782) Temporarily disabling on windows because it is failing on main and every // (#9782) Temporarily disabling on windows because it is failing on main and every
// PR, which is potentially hiding other failures // PR, which is potentially hiding other failures
it.skipIf(process.platform === 'win32')( it.skip('should exit gracefully on second Ctrl+C', async () => {
'should exit gracefully on second Ctrl+C', const rig = new TestRig();
async () => { await rig.setup('should exit gracefully on second Ctrl+C');
const rig = new TestRig();
await rig.setup('should exit gracefully on second Ctrl+C');
const { ptyProcess, promise } = rig.runInteractive(); const { ptyProcess, promise } = rig.runInteractive();
let output = ''; let output = '';
ptyProcess.onData((data) => { ptyProcess.onData((data) => {
output += data; output += data;
}); });
const isReady = await rig.waitForText('Type your message', 15000); const isReady = await rig.waitForText('Type your message', 15000);
expect( expect(isReady, 'CLI did not start up in interactive mode correctly').toBe(
isReady, true,
'CLI did not start up in interactive mode correctly', );
).toBe(true);
// Send first Ctrl+C // Send first Ctrl+C
ptyProcess.write(String.fromCharCode(3)); ptyProcess.write(String.fromCharCode(3));
// Wait for the exit prompt // Wait for the exit prompt
const showedExitPrompt = await rig.poll( const showedExitPrompt = await rig.poll(
() => output.includes('Press Ctrl+C again to exit'), () => output.includes('Press Ctrl+C again to exit'),
1500, 1500,
50, 50,
); );
expect(showedExitPrompt, `Exit prompt not shown. Output: ${output}`).toBe( expect(showedExitPrompt, `Exit prompt not shown. Output: ${output}`).toBe(
true, true,
); );
// Send second Ctrl+C // Send second Ctrl+C
ptyProcess.write(String.fromCharCode(3)); ptyProcess.write(String.fromCharCode(3));
// Wait for process exit with timeout to fail fast // Wait for process exit with timeout to fail fast
const EXIT_TIMEOUT = 5000; const EXIT_TIMEOUT = 5000;
const result = await Promise.race([ const result = await Promise.race([
promise, promise,
new Promise<never>((_, reject) => new Promise<never>((_, reject) =>
setTimeout( setTimeout(
() => () =>
reject( reject(
new Error( new Error(
`Process did not exit within ${EXIT_TIMEOUT}ms. Output: ${output}`, `Process did not exit within ${EXIT_TIMEOUT}ms. Output: ${output}`,
),
), ),
EXIT_TIMEOUT, ),
), EXIT_TIMEOUT,
), ),
]); ),
]);
// Expect a graceful exit (code 0) // Expect a graceful exit (code 0)
expect( expect(
result.exitCode, result.exitCode,
`Process exited with code ${result.exitCode}. Output: ${result.output}`, `Process exited with code ${result.exitCode}. Output: ${result.output}`,
).toBe(0); ).toBe(0);
// Check that the quitting message is displayed // Check that the quitting message is displayed
const quittingMessage = 'Agent powering down. Goodbye!'; const quittingMessage = 'Agent powering down. Goodbye!';
// The regex below is intentionally matching the ESC control character (\x1b) // The regex below is intentionally matching the ESC control character (\x1b)
// to strip ANSI color codes from the terminal output. // to strip ANSI color codes from the terminal output.
// eslint-disable-next-line no-control-regex // eslint-disable-next-line no-control-regex
const cleanOutput = output.replace(/\x1b\[[0-9;]*m/g, ''); const cleanOutput = output.replace(/\x1b\[[0-9;]*m/g, '');
expect(cleanOutput).toContain(quittingMessage); expect(cleanOutput).toContain(quittingMessage);
}, });
);
}); });