fix(cli): gemini command stuck in git bash (#6397)

Co-authored-by: Arya Gummadi <aryagummadi@google.com>
This commit is contained in:
Sudheer Tripathi
2025-08-23 05:49:20 +05:30
committed by GitHub
parent da73f13d02
commit d89f7ea9b5
5 changed files with 198 additions and 78 deletions

View File

@@ -67,4 +67,31 @@ describe('stdin context', () => {
'Expected the model to identify the secret word from stdin',
).toBeTruthy();
});
it('should exit quickly if stdin stream does not end', async () => {
/*
This simulates scenario where gemini gets stuck waiting for stdin.
This happens in situations where process.stdin.isTTY is false
even though gemini is intended to run interactively.
*/
const rig = new TestRig();
await rig.setup('should exit quickly if stdin stream does not end');
try {
await rig.run({ stdinDoesNotEnd: true });
throw new Error('Expected rig.run to throw an error');
} catch (error: unknown) {
expect(error).toBeInstanceOf(Error);
const err = error as Error;
expect(err.message).toContain('Process exited with code 1');
expect(err.message).toContain('No input provided via stdin.');
console.log('Error message:', err.message);
}
const lastRequest = rig.readLastApiRequest();
expect(lastRequest).toBeNull();
// If this test times out, runs indefinitely, it's a regression.
}, 3000);
});

View File

@@ -177,7 +177,9 @@ export class TestRig {
}
run(
promptOrOptions: string | { prompt?: string; stdin?: string },
promptOrOptions:
| string
| { prompt?: string; stdin?: string; stdinDoesNotEnd?: boolean },
...args: string[]
): Promise<string> {
let command = `node ${this.bundlePath} --yolo`;
@@ -221,7 +223,13 @@ export class TestRig {
if (execOptions.input) {
child.stdin!.write(execOptions.input);
}
child.stdin!.end();
if (
typeof promptOrOptions === 'object' &&
!promptOrOptions.stdinDoesNotEnd
) {
child.stdin!.end();
}
child.stdout!.on('data', (data: Buffer) => {
stdout += data;