feat(cli): add user identity info to stats command (#17612)

This commit is contained in:
Sehoon Shon
2026-01-28 16:26:33 -05:00
committed by GitHub
parent 30065c51fb
commit bee1267e2a
15 changed files with 429 additions and 112 deletions
@@ -12,6 +12,17 @@ import { MessageType } from '../types.js';
import { formatDuration } from '../utils/formatters.js';
import type { Config } from '@google/gemini-cli-core';
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
const actual =
await importOriginal<typeof import('@google/gemini-cli-core')>();
return {
...actual,
UserAccountManager: vi.fn().mockImplementation(() => ({
getCachedGoogleAccount: vi.fn().mockReturnValue('mock@example.com'),
})),
};
});
describe('statsCommand', () => {
let mockContext: CommandContext;
const startTime = new Date('2025-07-14T10:00:00.000Z');
@@ -40,6 +51,9 @@ describe('statsCommand', () => {
expect(mockContext.ui.addItem).toHaveBeenCalledWith({
type: MessageType.STATS,
duration: expectedDuration,
selectedAuthType: '',
tier: undefined,
userEmail: 'mock@example.com',
});
});
@@ -48,8 +62,10 @@ describe('statsCommand', () => {
const mockQuota = { buckets: [] };
const mockRefreshUserQuota = vi.fn().mockResolvedValue(mockQuota);
const mockGetUserTierName = vi.fn().mockReturnValue('Basic');
mockContext.services.config = {
refreshUserQuota: mockRefreshUserQuota,
getUserTierName: mockGetUserTierName,
} as unknown as Config;
await statsCommand.action(mockContext, '');
@@ -58,6 +74,7 @@ describe('statsCommand', () => {
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
quotas: mockQuota,
tier: 'Basic',
}),
);
});
@@ -73,6 +90,9 @@ describe('statsCommand', () => {
expect(mockContext.ui.addItem).toHaveBeenCalledWith({
type: MessageType.MODEL_STATS,
selectedAuthType: '',
tier: undefined,
userEmail: 'mock@example.com',
});
});