fix(test): deflake flicker integration test (#11308)

This commit is contained in:
Sandy Tao
2025-10-16 13:53:08 -07:00
committed by GitHub
parent 6b866d1282
commit 2aa1d74286
2 changed files with 30 additions and 2 deletions

View File

@@ -20,8 +20,8 @@ describe('Flicker Detector', () => {
const hasUserPromptEvent = await rig.waitForTelemetryEvent('user_prompt');
expect(hasUserPromptEvent).toBe(true);
const sessionCountMetric = rig.readMetric('session.count');
expect(sessionCountMetric).not.toBeNull();
const hasSessionCountMetric = await rig.waitForMetric('session.count');
expect(hasSessionCountMetric).toBe(true);
// We expect NO flicker event to be found.
const flickerMetric = rig.readMetric('ui.flicker.count');

View File

@@ -910,6 +910,34 @@ export class TestRig {
return apiRequests.pop() || null;
}
async waitForMetric(metricName: string, timeout?: number) {
await this.waitForTelemetryReady();
const fullName = metricName.startsWith('gemini_cli.')
? metricName
: `gemini_cli.${metricName}`;
return poll(
() => {
const logs = this._readAndParseTelemetryLog();
for (const logData of logs) {
if (logData.scopeMetrics) {
for (const scopeMetric of logData.scopeMetrics) {
for (const metric of scopeMetric.metrics) {
if (metric.descriptor.name === fullName) {
return true;
}
}
}
}
}
return false;
},
timeout ?? getDefaultTimeout(),
100,
);
}
readMetric(metricName: string): Record<string, unknown> | null {
const logs = this._readAndParseTelemetryLog();
for (const logData of logs) {