mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 22:55:13 +00:00
chore: refactored test-helper to handle boilerplate for interactive mode (#10322)
Co-authored-by: Taneja Hriday <hridayt@google.com>
This commit is contained in:
@@ -855,4 +855,48 @@ export class TestRig {
|
||||
|
||||
return { ptyProcess, promise };
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for an interactive session to be fully ready for input.
|
||||
* This is a higher-level utility to be used with `runInteractive`.
|
||||
*
|
||||
* It handles the initial setup boilerplate:
|
||||
* 1. Automatically handles the authentication prompt if it appears.
|
||||
* 2. Waits for the "Type your message" prompt to ensure the CLI is ready for input.
|
||||
*
|
||||
* Throws an error if the session fails to become ready within the timeout.
|
||||
*
|
||||
* @param ptyProcess The process returned from `runInteractive`.
|
||||
*/
|
||||
async ensureReadyForInput(ptyProcess: pty.IPty): Promise<void> {
|
||||
const timeout = 25000;
|
||||
const pollingInterval = 200;
|
||||
const startTime = Date.now();
|
||||
let authPromptHandled = false;
|
||||
|
||||
while (Date.now() - startTime < timeout) {
|
||||
const output = stripAnsi(this._interactiveOutput).toLowerCase();
|
||||
|
||||
// If the ready prompt appears, we're done.
|
||||
if (output.includes('type your message')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the auth prompt appears and we haven't handled it yet.
|
||||
if (
|
||||
!authPromptHandled &&
|
||||
output.includes('how would you like to authenticate')
|
||||
) {
|
||||
ptyProcess.write('2');
|
||||
authPromptHandled = true;
|
||||
}
|
||||
|
||||
// Wait for the next poll.
|
||||
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`CLI did not start up in interactive mode correctly. Output: ${this._interactiveOutput}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user