mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
Use polling for extensions-reload integration test (#14391)
This commit is contained in:
@@ -13,6 +13,8 @@ import { safeJsonStringify } from '@google/gemini-cli-core/src/utils/safeJsonStr
|
|||||||
import { env } from 'node:process';
|
import { env } from 'node:process';
|
||||||
import { platform } from 'node:os';
|
import { platform } from 'node:os';
|
||||||
|
|
||||||
|
import stripAnsi from 'strip-ansi';
|
||||||
|
|
||||||
const itIf = (condition: boolean) => (condition ? it : it.skip);
|
const itIf = (condition: boolean) => (condition ? it : it.skip);
|
||||||
|
|
||||||
describe('extension reloading', () => {
|
describe('extension reloading', () => {
|
||||||
@@ -76,13 +78,22 @@ describe('extension reloading', () => {
|
|||||||
await run.expectText(
|
await run.expectText(
|
||||||
'test-extension (v0.0.1) - active (update available)',
|
'test-extension (v0.0.1) - active (update available)',
|
||||||
);
|
);
|
||||||
// Wait a bit for the UI to settle
|
// Wait for the UI to settle and retry the command until we see the update
|
||||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
await run.sendKeys('\u0015/mcp list\r');
|
|
||||||
await run.expectText(
|
// Poll for the updated list
|
||||||
'test-server (from test-extension) - Ready (1 tool)',
|
await rig.pollCommand(
|
||||||
|
() => run.sendKeys('\u0015/mcp list\r'),
|
||||||
|
() => {
|
||||||
|
const output = stripAnsi(run.output);
|
||||||
|
return (
|
||||||
|
output.includes(
|
||||||
|
'test-server (from test-extension) - Ready (1 tool)',
|
||||||
|
) && output.includes('- hello')
|
||||||
|
);
|
||||||
|
},
|
||||||
|
30000, // 30s timeout
|
||||||
);
|
);
|
||||||
await run.expectText('- hello');
|
|
||||||
|
|
||||||
// Update the extension, expect the list to update, and mcp servers as well.
|
// Update the extension, expect the list to update, and mcp servers as well.
|
||||||
await run.sendKeys('\u0015/extensions update test-extension');
|
await run.sendKeys('\u0015/extensions update test-extension');
|
||||||
@@ -97,16 +108,31 @@ describe('extension reloading', () => {
|
|||||||
await run.expectText(
|
await run.expectText(
|
||||||
'Extension "test-extension" successfully updated: 0.0.1 → 0.0.2',
|
'Extension "test-extension" successfully updated: 0.0.1 → 0.0.2',
|
||||||
);
|
);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
||||||
await run.sendKeys('\u0015/extensions list\r');
|
// Poll for the updated extension version
|
||||||
await run.expectText('test-extension (v0.0.2) - active (updated)');
|
await rig.pollCommand(
|
||||||
// Wait a bit for the UI to settle
|
() => run.sendKeys('\u0015/extensions list\r'),
|
||||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
() =>
|
||||||
await run.sendKeys('\u0015/mcp list\r');
|
stripAnsi(run.output).includes(
|
||||||
await run.expectText(
|
'test-extension (v0.0.2) - active (updated)',
|
||||||
'test-server (from test-extension) - Ready (1 tool)',
|
),
|
||||||
|
30000,
|
||||||
);
|
);
|
||||||
await run.expectText('- goodbye');
|
|
||||||
|
// Poll for the updated mcp tool
|
||||||
|
await rig.pollCommand(
|
||||||
|
() => run.sendKeys('\u0015/mcp list\r'),
|
||||||
|
() => {
|
||||||
|
const output = stripAnsi(run.output);
|
||||||
|
return (
|
||||||
|
output.includes(
|
||||||
|
'test-server (from test-extension) - Ready (1 tool)',
|
||||||
|
) && output.includes('- goodbye')
|
||||||
|
);
|
||||||
|
},
|
||||||
|
30000,
|
||||||
|
);
|
||||||
|
|
||||||
await run.sendText('/quit');
|
await run.sendText('/quit');
|
||||||
await run.sendKeys('\r');
|
await run.sendKeys('\r');
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,14 @@ interface ParsedLog {
|
|||||||
success?: boolean;
|
success?: boolean;
|
||||||
duration_ms?: number;
|
duration_ms?: number;
|
||||||
request_text?: string;
|
request_text?: string;
|
||||||
|
hook_event_name?: string;
|
||||||
|
hook_name?: string;
|
||||||
|
hook_input?: Record<string, unknown>;
|
||||||
|
hook_output?: Record<string, unknown>;
|
||||||
|
exit_code?: number;
|
||||||
|
stdout?: string;
|
||||||
|
stderr?: string;
|
||||||
|
error?: string;
|
||||||
};
|
};
|
||||||
scopeMetrics?: {
|
scopeMetrics?: {
|
||||||
metrics: {
|
metrics: {
|
||||||
@@ -1081,4 +1089,23 @@ export class TestRig {
|
|||||||
|
|
||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async pollCommand(
|
||||||
|
commandFn: () => Promise<void>,
|
||||||
|
predicateFn: () => boolean,
|
||||||
|
timeout: number = 30000,
|
||||||
|
interval: number = 1000,
|
||||||
|
) {
|
||||||
|
const startTime = Date.now();
|
||||||
|
while (Date.now() - startTime < timeout) {
|
||||||
|
await commandFn();
|
||||||
|
// Give it a moment to process
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
if (predicateFn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||||
|
}
|
||||||
|
throw new Error(`pollCommand timed out after ${timeout}ms`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user