-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsession-usage.test.mjs
More file actions
43 lines (38 loc) · 2.06 KB
/
session-usage.test.mjs
File metadata and controls
43 lines (38 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import assert from 'assert';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const logic = await import(pathToFileURL(path.join(__dirname, '..', '..', 'web-ui', 'logic.mjs')));
const { buildUsageChartGroups } = logic;
test('buildUsageChartGroups aggregates codex and claude sessions into day buckets', () => {
const now = Date.UTC(2026, 3, 6, 12, 0, 0);
const result = buildUsageChartGroups([
{ source: 'codex', updatedAt: '2026-04-06T08:00:00.000Z', messageCount: 5, cwd: '/a' },
{ source: 'claude', updatedAt: '2026-04-06T09:00:00.000Z', messageCount: 7, cwd: '/a' },
{ source: 'codex', updatedAt: '2026-04-05T09:00:00.000Z', messageCount: 3, cwd: '/b' }
], { range: '7d', now });
assert.strictEqual(result.summary.totalSessions, 3);
assert.strictEqual(result.summary.totalMessages, 15);
assert.strictEqual(result.summary.codexTotal, 2);
assert.strictEqual(result.summary.claudeTotal, 1);
assert.strictEqual(result.sourceShare.find(item => item.key === 'codex').percent, 67);
assert.strictEqual(result.topPaths[0].path, '/a');
assert.strictEqual(result.topPaths[0].count, 2);
const lastBucket = result.buckets[result.buckets.length - 1];
assert.strictEqual(lastBucket.codex, 1);
assert.strictEqual(lastBucket.claude, 1);
assert.strictEqual(lastBucket.totalMessages, 12);
});
test('buildUsageChartGroups ignores invalid sessions and keeps empty buckets stable', () => {
const now = Date.UTC(2026, 3, 6, 12, 0, 0);
const result = buildUsageChartGroups([
null,
{ source: 'other', updatedAt: '2026-04-06T08:00:00.000Z', messageCount: 9 },
{ source: 'codex', updatedAt: 'bad-date', messageCount: 2 }
], { range: '7d', now });
assert.strictEqual(result.summary.totalSessions, 0);
assert.strictEqual(result.summary.totalMessages, 0);
assert.strictEqual(result.buckets.length, 7);
assert.ok(result.buckets.every((item) => item.totalSessions === 0));
});