mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -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 type { Systeminformation } from 'systeminformation';
|
||||
import * as os from 'node:os';
|
||||
|
||||
interface CustomMatchers<R = unknown> {
|
||||
toHaveMetadataValue: ([key, value]: [EventMetadataKey, string]) => R;
|
||||
@@ -120,6 +121,7 @@ vi.mock('node:os', async (importOriginal) => {
|
||||
return {
|
||||
...actual,
|
||||
cpus: vi.fn(() => [{ model: 'Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz' }]),
|
||||
availableParallelism: vi.fn(() => 8),
|
||||
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 = {
|
||||
name: string;
|
||||
env: Record<string, string | undefined>;
|
||||
|
||||
@@ -615,14 +615,17 @@ export class ClearcutLogger {
|
||||
|
||||
// Add hardware information only to the start session event
|
||||
const cpus = os.cpus();
|
||||
data.push(
|
||||
{
|
||||
if (cpus && cpus.length > 0) {
|
||||
data.push({
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_INFO,
|
||||
value: cpus[0].model,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
data.push(
|
||||
{
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user