Skip to content

Commit 1c4d94d

Browse files
committed
test(ccusage): snapshot direct agent commands
1 parent 0f78e45 commit 1c4d94d

5 files changed

Lines changed: 144 additions & 30 deletions

File tree

‎apps/ccusage/test/cli-output.test.ts‎

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,28 @@ function createAgentFixtureTree() {
8787
},
8888
},
8989
claude: {
90-
projects: {},
90+
projects: {
91+
project: {
92+
'session-id.jsonl': JSON.stringify({
93+
timestamp: '2026-01-02T00:00:00.000Z',
94+
sessionId: 'claude-session',
95+
message: {
96+
role: 'assistant',
97+
id: 'claude-message',
98+
model: 'claude-sonnet-4-20250514',
99+
usage: {
100+
input_tokens: 100,
101+
output_tokens: 50,
102+
cache_creation_input_tokens: 20,
103+
cache_read_input_tokens: 10,
104+
},
105+
},
106+
requestId: 'claude-request',
107+
costUSD: 0.25,
108+
version: '1.0.0',
109+
}),
110+
},
111+
},
91112
},
92113
codex: {
93114
sessions: {
@@ -374,18 +395,18 @@ describe('ccusage all-agent CLI', () => {
374395
expect(output.daily[0]).toEqual(
375396
expect.objectContaining({
376397
agent: 'all',
377-
cacheCreationTokens: 60,
378-
cacheReadTokens: 40,
379-
inputTokens: 400,
380-
outputTokens: 200,
398+
cacheCreationTokens: 80,
399+
cacheReadTokens: 50,
400+
inputTokens: 500,
401+
outputTokens: 250,
381402
period: '2026-01-02',
382-
totalTokens: 700,
403+
totalTokens: 880,
383404
}),
384405
);
385-
expect(output.daily[0]?.metadata?.agents).toEqual(['amp', 'codex', 'opencode', 'pi']);
406+
expect(output.daily[0]?.metadata?.agents).toEqual(['amp', 'claude', 'codex', 'opencode', 'pi']);
386407
});
387408

388-
it('runs agent namespaces through the main ccusage command', async () => {
409+
it('runs Codex daily JSON through the main ccusage namespace instead of the deprecated standalone wrapper', async () => {
389410
await using fixture = await createFixture(createAgentFixtureTree());
390411

391412
const result = runCcusage(
@@ -413,7 +434,39 @@ describe('ccusage all-agent CLI', () => {
413434
]);
414435
});
415436

416-
it('passes offline mode through agent namespaces', async () => {
437+
it('runs Claude daily JSON through the main ccusage namespace while preserving the Claude Code optimized loader output shape', async () => {
438+
await using fixture = await createFixture(createAgentFixtureTree());
439+
440+
const result = runCcusage(
441+
['claude', '--offline', '--json', '--since', '20260102', '--until', '20260102'],
442+
createAgentCliEnv(fixture.path),
443+
);
444+
445+
expect(result.status).toBe(0);
446+
expect(result.stderr).toBe('');
447+
const stdout = getStdout(result).replace(/\n$/u, '');
448+
await mkdir(snapshotRoot, { recursive: true });
449+
await expect(stdout).toMatchFileSnapshot(
450+
path.join(snapshotRoot, 'claude-direct-daily-json.txt'),
451+
);
452+
});
453+
454+
it('runs pi-agent daily JSON through the main ccusage namespace with its agent-specific path option still available', async () => {
455+
await using fixture = await createFixture(createAgentFixtureTree());
456+
457+
const result = runCcusage(
458+
['pi', '--offline', '--json', '--since', '20260102', '--until', '20260102'],
459+
createAgentCliEnv(fixture.path),
460+
);
461+
462+
expect(result.status).toBe(0);
463+
expect(result.stderr).toBe('');
464+
const stdout = getStdout(result).replace(/\n$/u, '');
465+
await mkdir(snapshotRoot, { recursive: true });
466+
await expect(stdout).toMatchFileSnapshot(path.join(snapshotRoot, 'pi-direct-daily-json.txt'));
467+
});
468+
469+
it('passes offline mode through OpenCode namespaces without fetching pricing from the network', async () => {
417470
await using fixture = await createFixture(createAgentFixtureTree());
418471

419472
const result = runCcusage(['opencode', '--offline', '--json'], createAgentCliEnv(fixture.path));
@@ -503,7 +556,7 @@ describe('ccusage all-agent CLI', () => {
503556
await mkdir(snapshotRoot, { recursive: true });
504557
await expect(output).toMatchFileSnapshot(path.join(snapshotRoot, 'all-agent-daily-table.txt'));
505558
expect(output).toContain('Coding Agent Usage Report - Daily');
506-
expect(output).toContain('Detected: Amp, Codex, OpenCode, pi-agent');
559+
expect(output).toContain('Detected: Amp, Claude, Codex, OpenCode, pi-agent');
507560
expect(output.match(/2026-01-02/gu)).toHaveLength(1);
508561
expect(output).toContain('Amp');
509562
expect(output).toContain('Codex');

‎apps/ccusage/test/snapshots/cli-output/all-agent-daily-json.txt‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
"claude-sonnet-4-20250514",
1010
"gpt-5"
1111
],
12-
"inputTokens": 400,
13-
"outputTokens": 200,
14-
"cacheCreationTokens": 60,
15-
"cacheReadTokens": 40,
16-
"totalTokens": 700,
17-
"totalCost": 0.0009897500000000002,
12+
"inputTokens": 500,
13+
"outputTokens": 250,
14+
"cacheCreationTokens": 80,
15+
"cacheReadTokens": 50,
16+
"totalTokens": 880,
17+
"totalCost": 0.25098975,
1818
"metadata": {
1919
"agents": [
2020
"amp",
21+
"claude",
2122
"codex",
2223
"opencode",
2324
"pi"
@@ -26,11 +27,11 @@
2627
}
2728
],
2829
"totals": {
29-
"inputTokens": 400,
30-
"outputTokens": 200,
31-
"cacheCreationTokens": 60,
32-
"cacheReadTokens": 40,
33-
"totalTokens": 700,
34-
"totalCost": 0.0009897500000000002
30+
"inputTokens": 500,
31+
"outputTokens": 250,
32+
"cacheCreationTokens": 80,
33+
"cacheReadTokens": 50,
34+
"totalTokens": 880,
35+
"totalCost": 0.25098975
3536
}
3637
}

‎apps/ccusage/test/snapshots/cli-output/all-agent-daily-table.txt‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11

2-
╭────────────────────────────────────────────╮
3-
│ │
4-
│ Coding Agent Usage Report - Daily │
5-
│ Detected: Amp, Codex, OpenCode, pi-agent │
6-
│ │
7-
╰────────────────────────────────────────────╯
2+
╭────────────────────────────────────────────────────╮
3+
│ │
4+
│ Coding Agent Usage Report - Daily │
5+
│ Detected: Amp, Claude, Codex, OpenCode, pi-agent │
6+
│ │
7+
╰────────────────────────────────────────────────────╯
88

99
┌────────────┬────────────┬──────────────┬──────────────┐
1010
│ Date │ Agent │ Total Tokens │ Cost (USD) │
1111
├────────────┼────────────┼──────────────┼──────────────┤
12-
│ 2026-01-02 │ All │ 700 │ $0.00 │
12+
│ 2026-01-02 │ All │ 880 │ $0.25 │
1313
├────────────┼────────────┼──────────────┼──────────────┤
1414
│ │ - Amp │ 180 │ $0.00 │
1515
├────────────┼────────────┼──────────────┼──────────────┤
16+
│ │ - Claude │ 180 │ $0.25 │
17+
├────────────┼────────────┼──────────────┼──────────────┤
1618
│ │ - Codex │ 160 │ $0.00 │
1719
├────────────┼────────────┼──────────────┼──────────────┤
1820
│ │ - OpenCode │ 180 │ $0.00 │
1921
├────────────┼────────────┼──────────────┼──────────────┤
2022
│ │ - pi-agent │ 180 │ $0.00 │
2123
├────────────┼────────────┼──────────────┼──────────────┤
22-
│ Total │ │ 700 │ $0.00 │
24+
│ Total │ │ 880 │ $0.25 │
2325
└────────────┴────────────┴──────────────┴──────────────┘
2426

2527
[ccusage] ℹ Running in Compact Mode
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"daily": [
3+
{
4+
"date": "2026-01-02",
5+
"inputTokens": 100,
6+
"outputTokens": 50,
7+
"cacheCreationTokens": 20,
8+
"cacheReadTokens": 10,
9+
"totalTokens": 180,
10+
"totalCost": 0.25,
11+
"modelsUsed": [
12+
"claude-sonnet-4-20250514"
13+
],
14+
"modelBreakdowns": [
15+
{
16+
"modelName": "claude-sonnet-4-20250514",
17+
"inputTokens": 100,
18+
"outputTokens": 50,
19+
"cacheCreationTokens": 20,
20+
"cacheReadTokens": 10,
21+
"cost": 0.25
22+
}
23+
]
24+
}
25+
],
26+
"totals": {
27+
"inputTokens": 100,
28+
"outputTokens": 50,
29+
"cacheCreationTokens": 20,
30+
"cacheReadTokens": 10,
31+
"totalCost": 0.25,
32+
"totalTokens": 180
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"daily": [
3+
{
4+
"date": "2026-01-02",
5+
"inputTokens": 100,
6+
"outputTokens": 50,
7+
"cacheCreationTokens": 20,
8+
"cacheReadTokens": 10,
9+
"totalTokens": 180,
10+
"totalCost": 0,
11+
"modelsUsed": [
12+
"[pi] claude-opus-4-20250514"
13+
]
14+
}
15+
],
16+
"totals": {
17+
"inputTokens": 100,
18+
"outputTokens": 50,
19+
"cacheCreationTokens": 20,
20+
"cacheReadTokens": 10,
21+
"totalTokens": 180,
22+
"totalCost": 0
23+
}
24+
}

0 commit comments

Comments
 (0)