Skip to content

Commit 809a2ae

Browse files
author
jleechan
committed
test(codex): add coverage for root-level flat files with date filters
Reviewer (Copilot + CodeRabbit) flagged that listSessionFiles() with since/until active skipped flat *.jsonl files stored directly under sessionsDir. Added a test that mixes a root-level flat.jsonl with a dated 2026/03/05/dated.jsonl and asserts both are returned when since is set — confirming the rootFiles glob fix covers the legacy layout.
1 parent 9c587b3 commit 809a2ae

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎apps/codex/src/data-loader.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,47 @@ if (import.meta.vitest != null) {
567567
expect(events[0]!.inputTokens).toBe(1_000);
568568
});
569569

570+
it('includes root-level *.jsonl files when date filters are active', async () => {
571+
const makeEvent = (timestamp: string, input_tokens: number) =>
572+
JSON.stringify({
573+
timestamp,
574+
type: 'event_msg',
575+
payload: {
576+
type: 'token_count',
577+
info: {
578+
last_token_usage: {
579+
input_tokens,
580+
cached_input_tokens: 0,
581+
output_tokens: 100,
582+
reasoning_output_tokens: 0,
583+
total_tokens: input_tokens + 100,
584+
},
585+
model: 'gpt-5',
586+
},
587+
},
588+
});
589+
590+
// Mix of flat root-level file (legacy layout) and dated subdir file.
591+
await using fixture = await createFixture({
592+
'flat.jsonl': makeEvent('2026-03-05T10:00:00.000Z', 500),
593+
'2026': {
594+
'03': {
595+
'05': { 'dated.jsonl': makeEvent('2026-03-05T11:00:00.000Z', 1_000) },
596+
},
597+
},
598+
});
599+
600+
// With since set, both the flat file and the dated file should be returned.
601+
const { events } = await loadTokenUsageEvents({
602+
sessionDirs: [fixture.getPath('.')],
603+
since: '2026-03-01',
604+
});
605+
606+
expect(events).toHaveLength(2);
607+
const tokens = events.map((e) => e.inputTokens).sort((a, b) => a - b);
608+
expect(tokens).toEqual([500, 1_000]);
609+
});
610+
570611
it('falls back to legacy model when metadata is missing entirely', async () => {
571612
await using fixture = await createFixture({
572613
sessions: {

0 commit comments

Comments
 (0)