mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 22:14:52 -07:00
fix(core): resolve crash in ClearcutLogger when os.cpus() is empty (#19555)
This commit is contained in:
@@ -43,6 +43,7 @@ import { InstallationManager } from '../../utils/installationManager.js';
|
|||||||
|
|
||||||
import si from 'systeminformation';
|
import si from 'systeminformation';
|
||||||
import type { Systeminformation } from 'systeminformation';
|
import type { Systeminformation } from 'systeminformation';
|
||||||
|
import * as os from 'node:os';
|
||||||
|
|
||||||
interface CustomMatchers<R = unknown> {
|
interface CustomMatchers<R = unknown> {
|
||||||
toHaveMetadataValue: ([key, value]: [EventMetadataKey, string]) => R;
|
toHaveMetadataValue: ([key, value]: [EventMetadataKey, string]) => R;
|
||||||
@@ -120,6 +121,7 @@ vi.mock('node:os', async (importOriginal) => {
|
|||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
cpus: vi.fn(() => [{ model: 'Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz' }]),
|
cpus: vi.fn(() => [{ model: 'Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz' }]),
|
||||||
|
availableParallelism: vi.fn(() => 8),
|
||||||
totalmem: vi.fn(() => 32 * 1024 * 1024 * 1024),
|
totalmem: vi.fn(() => 32 * 1024 * 1024 * 1024),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -438,6 +440,26 @@ describe('ClearcutLogger', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles empty os.cpus() gracefully', async () => {
|
||||||
|
const { logger, loggerConfig } = setup({});
|
||||||
|
vi.mocked(os.cpus).mockReturnValueOnce([]);
|
||||||
|
|
||||||
|
await logger?.logStartSessionEvent(new StartSessionEvent(loggerConfig));
|
||||||
|
|
||||||
|
const event = logger?.createLogEvent(EventNames.API_ERROR, []);
|
||||||
|
const metadata = event?.event_metadata[0];
|
||||||
|
|
||||||
|
const cpuInfoEntry = metadata?.find(
|
||||||
|
(m) => m.gemini_cli_key === EventMetadataKey.GEMINI_CLI_CPU_INFO,
|
||||||
|
);
|
||||||
|
expect(cpuInfoEntry).toBeUndefined();
|
||||||
|
|
||||||
|
const cpuCoresEntry = metadata?.find(
|
||||||
|
(m) => m.gemini_cli_key === EventMetadataKey.GEMINI_CLI_CPU_CORES,
|
||||||
|
);
|
||||||
|
expect(cpuCoresEntry?.value).toBe('8');
|
||||||
|
});
|
||||||
|
|
||||||
type SurfaceDetectionTestCase = {
|
type SurfaceDetectionTestCase = {
|
||||||
name: string;
|
name: string;
|
||||||
env: Record<string, string | undefined>;
|
env: Record<string, string | undefined>;
|
||||||
|
|||||||
@@ -615,14 +615,17 @@ export class ClearcutLogger {
|
|||||||
|
|
||||||
// Add hardware information only to the start session event
|
// Add hardware information only to the start session event
|
||||||
const cpus = os.cpus();
|
const cpus = os.cpus();
|
||||||
data.push(
|
if (cpus && cpus.length > 0) {
|
||||||
{
|
data.push({
|
||||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_INFO,
|
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_INFO,
|
||||||
value: cpus[0].model,
|
value: cpus[0].model,
|
||||||
},
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
data.push(
|
||||||
{
|
{
|
||||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_CORES,
|
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_CORES,
|
||||||
value: cpus.length.toString(),
|
value: os.availableParallelism().toString(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_RAM_TOTAL_GB,
|
gemini_cli_key: EventMetadataKey.GEMINI_CLI_RAM_TOTAL_GB,
|
||||||
|
|||||||
Reference in New Issue
Block a user