mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
Clean up integration test warnings. (#10931)
This commit is contained in:
committed by
GitHub
parent
ead8928c39
commit
cd9193466e
@@ -108,7 +108,7 @@ export function validateModelOutput(
|
|||||||
console.warn('Expected content:', expectedContent);
|
console.warn('Expected content:', expectedContent);
|
||||||
console.warn('Actual output:', result);
|
console.warn('Actual output:', result);
|
||||||
return false;
|
return false;
|
||||||
} else if (process.env.VERBOSE === 'true') {
|
} else if (env['VERBOSE'] === 'true') {
|
||||||
console.log(`${testName}: Model output validated successfully.`);
|
console.log(`${testName}: Model output validated successfully.`);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -157,8 +157,8 @@ export class TestRig {
|
|||||||
|
|
||||||
// Get timeout based on environment
|
// Get timeout based on environment
|
||||||
getDefaultTimeout() {
|
getDefaultTimeout() {
|
||||||
if (env.CI) return 60000; // 1 minute in CI
|
if (env['CI']) return 60000; // 1 minute in CI
|
||||||
if (env.GEMINI_SANDBOX) return 30000; // 30s in containers
|
if (env['GEMINI_SANDBOX']) return 30000; // 30s in containers
|
||||||
return 15000; // 15s locally
|
return 15000; // 15s locally
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ export class TestRig {
|
|||||||
) {
|
) {
|
||||||
this.testName = testName;
|
this.testName = testName;
|
||||||
const sanitizedName = sanitizeTestName(testName);
|
const sanitizedName = sanitizeTestName(testName);
|
||||||
this.testDir = join(env.INTEGRATION_TEST_FILE_DIR!, sanitizedName);
|
this.testDir = join(env['INTEGRATION_TEST_FILE_DIR']!, sanitizedName);
|
||||||
mkdirSync(this.testDir, { recursive: true });
|
mkdirSync(this.testDir, { recursive: true });
|
||||||
|
|
||||||
// Create a settings file to point the CLI to the local collector
|
// Create a settings file to point the CLI to the local collector
|
||||||
@@ -196,7 +196,8 @@ export class TestRig {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
model: DEFAULT_GEMINI_MODEL,
|
model: DEFAULT_GEMINI_MODEL,
|
||||||
sandbox: env.GEMINI_SANDBOX !== 'false' ? env.GEMINI_SANDBOX : false,
|
sandbox:
|
||||||
|
env['GEMINI_SANDBOX'] !== 'false' ? env['GEMINI_SANDBOX'] : false,
|
||||||
...options.settings, // Allow tests to override/add settings
|
...options.settings, // Allow tests to override/add settings
|
||||||
};
|
};
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
@@ -230,7 +231,7 @@ export class TestRig {
|
|||||||
initialArgs: string[];
|
initialArgs: string[];
|
||||||
} {
|
} {
|
||||||
const isNpmReleaseTest =
|
const isNpmReleaseTest =
|
||||||
process.env.INTEGRATION_TEST_USE_INSTALLED_GEMINI === 'true';
|
env['INTEGRATION_TEST_USE_INSTALLED_GEMINI'] === 'true';
|
||||||
const command = isNpmReleaseTest ? 'gemini' : 'node';
|
const command = isNpmReleaseTest ? 'gemini' : 'node';
|
||||||
const initialArgs = isNpmReleaseTest
|
const initialArgs = isNpmReleaseTest
|
||||||
? extraInitialArgs
|
? extraInitialArgs
|
||||||
@@ -274,7 +275,7 @@ export class TestRig {
|
|||||||
const child = spawn(command, commandArgs, {
|
const child = spawn(command, commandArgs, {
|
||||||
cwd: this.testDir!,
|
cwd: this.testDir!,
|
||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
env: process.env,
|
env: env,
|
||||||
});
|
});
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
@@ -294,14 +295,14 @@ export class TestRig {
|
|||||||
|
|
||||||
child.stdout!.on('data', (data: Buffer) => {
|
child.stdout!.on('data', (data: Buffer) => {
|
||||||
stdout += data;
|
stdout += data;
|
||||||
if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') {
|
if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stderr!.on('data', (data: Buffer) => {
|
child.stderr!.on('data', (data: Buffer) => {
|
||||||
stderr += data;
|
stderr += data;
|
||||||
if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') {
|
if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') {
|
||||||
process.stderr.write(data);
|
process.stderr.write(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -315,10 +316,10 @@ export class TestRig {
|
|||||||
// Filter out telemetry output when running with Podman
|
// Filter out telemetry output when running with Podman
|
||||||
// Podman seems to output telemetry to stdout even when writing to file
|
// Podman seems to output telemetry to stdout even when writing to file
|
||||||
let result = stdout;
|
let result = stdout;
|
||||||
if (env.GEMINI_SANDBOX === 'podman') {
|
if (env['GEMINI_SANDBOX'] === 'podman') {
|
||||||
// Remove telemetry JSON objects from output
|
// Remove telemetry JSON objects from output
|
||||||
// They are multi-line JSON objects that start with { and contain telemetry fields
|
// They are multi-line JSON objects that start with { and contain telemetry fields
|
||||||
const lines = result.split(EOL);
|
const lines = result.split(os.EOL);
|
||||||
const filteredLines = [];
|
const filteredLines = [];
|
||||||
let inTelemetryObject = false;
|
let inTelemetryObject = false;
|
||||||
let braceDepth = 0;
|
let braceDepth = 0;
|
||||||
@@ -393,14 +394,14 @@ export class TestRig {
|
|||||||
|
|
||||||
child.stdout!.on('data', (data: Buffer) => {
|
child.stdout!.on('data', (data: Buffer) => {
|
||||||
stdout += data;
|
stdout += data;
|
||||||
if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') {
|
if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stderr!.on('data', (data: Buffer) => {
|
child.stderr!.on('data', (data: Buffer) => {
|
||||||
stderr += data;
|
stderr += data;
|
||||||
if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') {
|
if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') {
|
||||||
process.stderr.write(data);
|
process.stderr.write(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -426,7 +427,7 @@ export class TestRig {
|
|||||||
readFile(fileName: string) {
|
readFile(fileName: string) {
|
||||||
const filePath = join(this.testDir!, fileName);
|
const filePath = join(this.testDir!, fileName);
|
||||||
const content = readFileSync(filePath, 'utf-8');
|
const content = readFileSync(filePath, 'utf-8');
|
||||||
if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') {
|
if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') {
|
||||||
console.log(`--- FILE: ${filePath} ---`);
|
console.log(`--- FILE: ${filePath} ---`);
|
||||||
console.log(content);
|
console.log(content);
|
||||||
console.log(`--- END FILE: ${filePath} ---`);
|
console.log(`--- END FILE: ${filePath} ---`);
|
||||||
@@ -436,12 +437,12 @@ export class TestRig {
|
|||||||
|
|
||||||
async cleanup() {
|
async cleanup() {
|
||||||
// Clean up test directory
|
// Clean up test directory
|
||||||
if (this.testDir && !env.KEEP_OUTPUT) {
|
if (this.testDir && !env['KEEP_OUTPUT']) {
|
||||||
try {
|
try {
|
||||||
execSync(`rm -rf ${this.testDir}`);
|
execSync(`rm -rf ${this.testDir}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore cleanup errors
|
// Ignore cleanup errors
|
||||||
if (env.VERBOSE === 'true') {
|
if (env['VERBOSE'] === 'true') {
|
||||||
console.warn('Cleanup warning:', (error as Error).message);
|
console.warn('Cleanup warning:', (error as Error).message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -542,7 +543,7 @@ export class TestRig {
|
|||||||
while (Date.now() - startTime < timeout) {
|
while (Date.now() - startTime < timeout) {
|
||||||
attempts++;
|
attempts++;
|
||||||
const result = predicate();
|
const result = predicate();
|
||||||
if (env.VERBOSE === 'true' && attempts % 5 === 0) {
|
if (env['VERBOSE'] === 'true' && attempts % 5 === 0) {
|
||||||
console.log(
|
console.log(
|
||||||
`Poll attempt ${attempts}: ${result ? 'success' : 'waiting...'}`,
|
`Poll attempt ${attempts}: ${result ? 'success' : 'waiting...'}`,
|
||||||
);
|
);
|
||||||
@@ -552,7 +553,7 @@ export class TestRig {
|
|||||||
}
|
}
|
||||||
await new Promise((resolve) => setTimeout(resolve, interval));
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||||
}
|
}
|
||||||
if (env.VERBOSE === 'true') {
|
if (env['VERBOSE'] === 'true') {
|
||||||
console.log(`Poll timed out after ${attempts} attempts`);
|
console.log(`Poll timed out after ${attempts} attempts`);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -613,7 +614,7 @@ export class TestRig {
|
|||||||
// If no matches found with the simple pattern, try the JSON parsing approach
|
// If no matches found with the simple pattern, try the JSON parsing approach
|
||||||
// in case the format changes
|
// in case the format changes
|
||||||
if (logs.length === 0) {
|
if (logs.length === 0) {
|
||||||
const lines = stdout.split(EOL);
|
const lines = stdout.split(os.EOL);
|
||||||
let currentObject = '';
|
let currentObject = '';
|
||||||
let inObject = false;
|
let inObject = false;
|
||||||
let braceDepth = 0;
|
let braceDepth = 0;
|
||||||
@@ -712,7 +713,7 @@ export class TestRig {
|
|||||||
logs.push(logData);
|
logs.push(logData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Skip objects that aren't valid JSON
|
// Skip objects that aren't valid JSON
|
||||||
if (env.VERBOSE === 'true') {
|
if (env['VERBOSE'] === 'true') {
|
||||||
console.error('Failed to parse telemetry object:', e);
|
console.error('Failed to parse telemetry object:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -724,7 +725,7 @@ export class TestRig {
|
|||||||
readToolLogs() {
|
readToolLogs() {
|
||||||
// For Podman, first check if telemetry file exists and has content
|
// For Podman, first check if telemetry file exists and has content
|
||||||
// If not, fall back to parsing from stdout
|
// If not, fall back to parsing from stdout
|
||||||
if (env.GEMINI_SANDBOX === 'podman') {
|
if (env['GEMINI_SANDBOX'] === 'podman') {
|
||||||
// Try reading from file first
|
// Try reading from file first
|
||||||
const logFilePath = join(this.testDir!, 'telemetry.log');
|
const logFilePath = join(this.testDir!, 'telemetry.log');
|
||||||
|
|
||||||
@@ -766,13 +767,13 @@ export class TestRig {
|
|||||||
logData.attributes &&
|
logData.attributes &&
|
||||||
logData.attributes['event.name'] === 'gemini_cli.tool_call'
|
logData.attributes['event.name'] === 'gemini_cli.tool_call'
|
||||||
) {
|
) {
|
||||||
const toolName = logData.attributes.function_name;
|
const toolName = logData.attributes.function_name!;
|
||||||
logs.push({
|
logs.push({
|
||||||
toolRequest: {
|
toolRequest: {
|
||||||
name: toolName,
|
name: toolName,
|
||||||
args: logData.attributes.function_args,
|
args: logData.attributes.function_args ?? '{}',
|
||||||
success: logData.attributes.success,
|
success: logData.attributes.success ?? false,
|
||||||
duration_ms: logData.attributes.duration_ms,
|
duration_ms: logData.attributes.duration_ms ?? 0,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -781,7 +782,7 @@ export class TestRig {
|
|||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
readLastApiRequest(): Record<string, unknown> | null {
|
readLastApiRequest(): ParsedLog | null {
|
||||||
const logs = this._readAndParseTelemetryLog();
|
const logs = this._readAndParseTelemetryLog();
|
||||||
const apiRequests = logs.filter(
|
const apiRequests = logs.filter(
|
||||||
(logData) =>
|
(logData) =>
|
||||||
@@ -825,7 +826,6 @@ export class TestRig {
|
|||||||
async runInteractive(...args: string[]): Promise<pty.IPty> {
|
async runInteractive(...args: string[]): Promise<pty.IPty> {
|
||||||
const { command, initialArgs } = this._getCommandAndArgs(['--yolo']);
|
const { command, initialArgs } = this._getCommandAndArgs(['--yolo']);
|
||||||
const commandArgs = [...initialArgs, ...args];
|
const commandArgs = [...initialArgs, ...args];
|
||||||
const isWindows = os.platform() === 'win32';
|
|
||||||
|
|
||||||
this._interactiveOutput = ''; // Reset output for the new run
|
this._interactiveOutput = ''; // Reset output for the new run
|
||||||
|
|
||||||
@@ -835,21 +835,16 @@ export class TestRig {
|
|||||||
rows: 30,
|
rows: 30,
|
||||||
cwd: this.testDir!,
|
cwd: this.testDir!,
|
||||||
env: Object.fromEntries(
|
env: Object.fromEntries(
|
||||||
Object.entries(process.env).filter(([, v]) => v !== undefined),
|
Object.entries(env).filter(([, v]) => v !== undefined),
|
||||||
) as { [key: string]: string },
|
) as { [key: string]: string },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isWindows) {
|
|
||||||
// node-pty on Windows requires a shell to be specified when using winpty.
|
|
||||||
options.shell = process.env.COMSPEC || 'cmd.exe';
|
|
||||||
}
|
|
||||||
|
|
||||||
const executable = command === 'node' ? process.execPath : command;
|
const executable = command === 'node' ? process.execPath : command;
|
||||||
const ptyProcess = pty.spawn(executable, commandArgs, options);
|
const ptyProcess = pty.spawn(executable, commandArgs, options);
|
||||||
|
|
||||||
ptyProcess.onData((data) => {
|
ptyProcess.onData((data) => {
|
||||||
this._interactiveOutput += data;
|
this._interactiveOutput += data;
|
||||||
if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') {
|
if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user