mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-27 14:30:44 -07:00
Allow telemetry exporters to GCP to utilize user's login credentials, if requested (#13778)
This commit is contained in:
committed by
GitHub
parent
92e95ed806
commit
b9b3b8050d
@@ -4,9 +4,17 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { main as generateDocs } from '../generate-settings-doc.ts';
|
||||
|
||||
vi.mock('fs', () => ({
|
||||
readFileSync: vi.fn().mockReturnValue(''),
|
||||
createWriteStream: vi.fn(() => ({
|
||||
write: vi.fn(),
|
||||
on: vi.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
describe('generate-settings-doc', () => {
|
||||
it('keeps documentation in sync in check mode', async () => {
|
||||
const previousExitCode = process.exitCode;
|
||||
|
||||
@@ -4,12 +4,21 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { main as generateSchema } from '../generate-settings-schema.ts';
|
||||
|
||||
vi.mock('fs', () => ({
|
||||
readFileSync: vi.fn().mockReturnValue(''),
|
||||
writeFileSync: vi.fn(),
|
||||
createWriteStream: vi.fn(() => ({
|
||||
write: vi.fn(),
|
||||
on: vi.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
describe('generate-settings-schema', () => {
|
||||
it('keeps schema in sync in check mode', async () => {
|
||||
const previousExitCode = process.exitCode;
|
||||
|
||||
56
scripts/tests/telemetry_gcp.test.ts
Normal file
56
scripts/tests/telemetry_gcp.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
|
||||
const mockSpawn = vi.fn(() => ({ on: vi.fn(), pid: 123 }));
|
||||
|
||||
vi.mock('node:child_process', () => ({
|
||||
spawn: mockSpawn,
|
||||
execSync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('node:fs', () => ({
|
||||
readFileSync: vi.fn(),
|
||||
writeFileSync: vi.fn(),
|
||||
openSync: vi.fn(() => 1),
|
||||
unlinkSync: vi.fn(),
|
||||
mkdirSync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../telemetry_utils.js', () => ({
|
||||
ensureBinary: vi.fn(() => Promise.resolve('/fake/path/to/otelcol-contrib')),
|
||||
waitForPort: vi.fn(() => Promise.resolve()),
|
||||
manageTelemetrySettings: vi.fn(),
|
||||
registerCleanup: vi.fn(),
|
||||
fileExists: vi.fn(() => true), // Assume all files exist for simplicity
|
||||
OTEL_DIR: '/tmp/otel',
|
||||
BIN_DIR: '/tmp/bin',
|
||||
}));
|
||||
|
||||
describe('telemetry_gcp.js', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules(); // This is key to re-run the script
|
||||
vi.clearAllMocks();
|
||||
process.env.OTLP_GOOGLE_CLOUD_PROJECT = 'test-project';
|
||||
// Clear the env var before each test
|
||||
delete process.env.GEMINI_CLI_CREDENTIALS_PATH;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.OTLP_GOOGLE_CLOUD_PROJECT;
|
||||
});
|
||||
|
||||
it('should not set GOOGLE_APPLICATION_CREDENTIALS when env var is not set', async () => {
|
||||
await import('../telemetry_gcp.js');
|
||||
|
||||
expect(mockSpawn).toHaveBeenCalled();
|
||||
const spawnOptions = mockSpawn.mock.calls[0][2];
|
||||
expect(spawnOptions?.env).not.toHaveProperty(
|
||||
'GOOGLE_APPLICATION_CREDENTIALS',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user