Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 124 additions & 1 deletion packages/cli/src/ui/components/ModelStatsDisplay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { ModelStatsDisplay } from './ModelStatsDisplay.js';
import * as SessionContext from '../contexts/SessionContext.js';
import type { SessionMetrics } from '../contexts/SessionContext.js';
import { ToolCallDecision } from '@google/gemini-cli-core';
import { ToolCallDecision, LlmRole } from '@google/gemini-cli-core';

// Mock the context to provide controlled data for testing
vi.mock('../contexts/SessionContext.js', async (importOriginal) => {
Expand Down Expand Up @@ -95,6 +95,7 @@
thoughts: 0,
tool: 0,
},
roles: {},
},
},
tools: {
Expand Down Expand Up @@ -137,6 +138,7 @@
thoughts: 2,
tool: 0,
},
roles: {},
},
'gemini-2.5-flash': {
api: { totalRequests: 1, totalErrors: 0, totalLatencyMs: 50 },
Expand All @@ -149,6 +151,7 @@
thoughts: 0,
tool: 3,
},
roles: {},
},
},
tools: {
Expand Down Expand Up @@ -191,6 +194,7 @@
thoughts: 10,
tool: 5,
},
roles: {},
},
'gemini-2.5-flash': {
api: { totalRequests: 20, totalErrors: 2, totalLatencyMs: 500 },
Expand All @@ -203,6 +207,7 @@
thoughts: 20,
tool: 10,
},
roles: {},
},
},
tools: {
Expand Down Expand Up @@ -248,6 +253,7 @@
thoughts: 111111111,
tool: 222222222,
},
roles: {},
},
},
tools: {
Expand Down Expand Up @@ -286,6 +292,7 @@
thoughts: 2,
tool: 1,
},
roles: {},
},
},
tools: {
Expand Down Expand Up @@ -313,11 +320,11 @@
expect(output).toMatchSnapshot();
});

it('should handle models with long names (gemini-3-*-preview) without layout breaking', () => {

Check warning on line 323 in packages/cli/src/ui/components/ModelStatsDisplay.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
const { lastFrame } = renderWithMockedStats(
{
models: {
'gemini-3-pro-preview': {

Check warning on line 327 in packages/cli/src/ui/components/ModelStatsDisplay.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
api: { totalRequests: 10, totalErrors: 0, totalLatencyMs: 2000 },
tokens: {
input: 1000,
Expand All @@ -328,8 +335,9 @@
thoughts: 100,
tool: 50,
},
roles: {},
},
'gemini-3-flash-preview': {

Check warning on line 340 in packages/cli/src/ui/components/ModelStatsDisplay.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
api: { totalRequests: 20, totalErrors: 0, totalLatencyMs: 1000 },
tokens: {
input: 2000,
Expand All @@ -340,6 +348,7 @@
thoughts: 200,
tool: 100,
},
roles: {},
},
},
tools: {
Expand All @@ -364,8 +373,122 @@
);

const output = lastFrame();
expect(output).toContain('gemini-3-pro-');

Check warning on line 376 in packages/cli/src/ui/components/ModelStatsDisplay.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
expect(output).toContain('gemini-3-flash-');

Check warning on line 377 in packages/cli/src/ui/components/ModelStatsDisplay.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
});

it('should display role breakdown correctly', () => {
const { lastFrame } = renderWithMockedStats({
models: {
'gemini-2.5-pro': {
api: { totalRequests: 2, totalErrors: 0, totalLatencyMs: 200 },
tokens: {
input: 20,
prompt: 30,
candidates: 40,
total: 70,
cached: 10,
thoughts: 0,
tool: 0,
},
roles: {
[LlmRole.MAIN]: {
totalRequests: 1,
totalErrors: 0,
totalLatencyMs: 100,
tokens: {
input: 10,
prompt: 15,
candidates: 20,
total: 35,
cached: 5,
thoughts: 0,
tool: 0,
},
},
},
},
},
tools: {
totalCalls: 0,
totalSuccess: 0,
totalFail: 0,
totalDurationMs: 0,
totalDecisions: {
accept: 0,
reject: 0,
modify: 0,
[ToolCallDecision.AUTO_ACCEPT]: 0,
},
byName: {},
},
files: {
totalLinesAdded: 0,
totalLinesRemoved: 0,
},
});

const output = lastFrame();
expect(output).toContain('main');
expect(output).toContain('Input');
expect(output).toContain('Output');
expect(output).toContain('Cache Reads');
expect(output).toMatchSnapshot();
});

it('should handle long metric names with truncation', () => {
const longRoleName =
'this_is_a_very_long_role_name_that_should_be_truncated' as LlmRole;
const { lastFrame } = renderWithMockedStats({
models: {
'gemini-2.5-pro': {
api: { totalRequests: 1, totalErrors: 0, totalLatencyMs: 100 },
tokens: {
input: 10,
prompt: 10,
candidates: 20,
total: 30,
cached: 0,
thoughts: 0,
tool: 0,
},
roles: {
[longRoleName]: {
totalRequests: 1,
totalErrors: 0,
totalLatencyMs: 100,
tokens: {
input: 10,
prompt: 10,
candidates: 20,
total: 30,
cached: 0,
thoughts: 0,
tool: 0,
},
},
},
},
},
tools: {
totalCalls: 0,
totalSuccess: 0,
totalFail: 0,
totalDurationMs: 0,
totalDecisions: {
accept: 0,
reject: 0,
modify: 0,
[ToolCallDecision.AUTO_ACCEPT]: 0,
},
byName: {},
},
files: {
totalLinesAdded: 0,
totalLinesRemoved: 0,
},
});

expect(lastFrame()).toMatchSnapshot();
});
});
Loading