@@ -68,10 +68,14 @@ function makeTempDir(): string {
6868 return dir ;
6969}
7070
71+ const TODAY = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
72+ const YESTERDAY = new Date ( Date . now ( ) - 86400000 ) . toISOString ( ) . slice ( 0 , 10 ) ;
73+ const TWO_DAYS_AGO = new Date ( Date . now ( ) - 2 * 86400000 ) . toISOString ( ) . slice ( 0 , 10 ) ;
74+
7175function makeSession (
7276 id : string ,
7377 project = "/test/project" ,
74- date = "2026-03-26" ,
78+ date = TODAY ,
7579 overrides : Partial < SessionMetrics > = { }
7680) : SessionMetrics {
7781 return {
@@ -113,7 +117,7 @@ function makeSessionRow(
113117) : SessionRow {
114118 return {
115119 id,
116- date : "2026-03-26" ,
120+ date : TODAY ,
117121 project : "/test/project" ,
118122 duration_sec : 600 ,
119123 total_tool_calls : 10 ,
@@ -123,7 +127,7 @@ function makeSessionRow(
123127 testing_calls : 1 ,
124128 delegation_calls : 1 ,
125129 other_calls : 1 ,
126- created_at : "2026-03-26T10 :00:00.000Z" ,
130+ created_at : ` ${ TODAY } T10 :00:00.000Z` ,
127131 ...overrides ,
128132 } ;
129133}
@@ -378,8 +382,8 @@ describe("Database: schema, CRUD, retention, queries", () => {
378382 const db = openDb ( dbPath ) ;
379383
380384 // Insert 2 sessions with known tool counts
381- insertSession ( db , makeSession ( "s1" , "/test/project" , "2026-03-26" ) ) ;
382- insertSession ( db , makeSession ( "s2" , "/test/project" , "2026-03-26" ) ) ;
385+ insertSession ( db , makeSession ( "s1" , "/test/project" , TODAY ) ) ;
386+ insertSession ( db , makeSession ( "s2" , "/test/project" , TODAY ) ) ;
383387 insertToolCalls ( db , makeSession ( "s1" ) . tool_calls , "s1" ) ;
384388 insertToolCalls ( db , makeSession ( "s2" ) . tool_calls , "s2" ) ;
385389
@@ -412,7 +416,7 @@ describe("Database: schema, CRUD, retention, queries", () => {
412416 // Old session (well beyond 90 days)
413417 insertSession ( db , makeSession ( "old" , "/test/project" , "2024-01-01" ) ) ;
414418 // Recent session
415- insertSession ( db , makeSession ( "recent" , "/test/project" , "2026-03-26" ) ) ;
419+ insertSession ( db , makeSession ( "recent" , "/test/project" , TODAY ) ) ;
416420
417421 const { deletedCount } = deleteOldSessions ( db , 90 ) ;
418422
@@ -443,7 +447,7 @@ describe("Database: schema, CRUD, retention, queries", () => {
443447
444448 test ( "deleteOldSessions returns 0 when no sessions are old enough" , ( ) => {
445449 const db = openDb ( dbPath ) ;
446- insertSession ( db , makeSession ( "recent" , "/test/project" , "2026-03-26" ) ) ;
450+ insertSession ( db , makeSession ( "recent" , "/test/project" , TODAY ) ) ;
447451
448452 const { deletedCount } = deleteOldSessions ( db , 90 ) ;
449453
@@ -454,14 +458,14 @@ describe("Database: schema, CRUD, retention, queries", () => {
454458
455459 test ( "getTopTools returns tools ranked by call count" , ( ) => {
456460 const db = openDb ( dbPath ) ;
457- insertSession ( db , makeSession ( "s1" , "/test/project" , "2026-03-26" ) ) ;
461+ insertSession ( db , makeSession ( "s1" , "/test/project" , TODAY ) ) ;
458462
459463 const calls : ToolCallRecord [ ] = [
460- { tool_name : "Read" , duration_ms : 10 , success : true , activity_category : "research" , timestamp : "2026-03-26T10 :00:00.000Z" } ,
461- { tool_name : "Read" , duration_ms : 20 , success : true , activity_category : "research" , timestamp : "2026-03-26T10 :01:00.000Z" } ,
462- { tool_name : "Read" , duration_ms : 15 , success : true , activity_category : "research" , timestamp : "2026-03-26T10 :02:00.000Z" } ,
463- { tool_name : "Write" , duration_ms : 30 , success : true , activity_category : "coding" , timestamp : "2026-03-26T10 :03:00.000Z" } ,
464- { tool_name : "Bash" , duration_ms : 100 , success : true , activity_category : "other" , timestamp : "2026-03-26T10 :04:00.000Z" } ,
464+ { tool_name : "Read" , duration_ms : 10 , success : true , activity_category : "research" , timestamp : ` ${ TODAY } T10 :00:00.000Z` } ,
465+ { tool_name : "Read" , duration_ms : 20 , success : true , activity_category : "research" , timestamp : ` ${ TODAY } T10 :01:00.000Z` } ,
466+ { tool_name : "Read" , duration_ms : 15 , success : true , activity_category : "research" , timestamp : ` ${ TODAY } T10 :02:00.000Z` } ,
467+ { tool_name : "Write" , duration_ms : 30 , success : true , activity_category : "coding" , timestamp : ` ${ TODAY } T10 :03:00.000Z` } ,
468+ { tool_name : "Bash" , duration_ms : 100 , success : true , activity_category : "other" , timestamp : ` ${ TODAY } T10 :04:00.000Z` } ,
465469 ] ;
466470 insertToolCalls ( db , calls , "s1" ) ;
467471
@@ -484,10 +488,10 @@ describe("Database: schema, CRUD, retention, queries", () => {
484488 test ( "getDurationTrend returns daily data in ASC date order" , ( ) => {
485489 const db = openDb ( dbPath ) ;
486490
487- // Insert sessions on different dates
488- insertSession ( db , makeSession ( "s1" , "/test/project" , "2026-03-24" ) ) ;
489- insertSession ( db , makeSession ( "s2" , "/test/project" , "2026-03-25" ) ) ;
490- insertSession ( db , makeSession ( "s3" , "/test/project" , "2026-03-26" ) ) ;
491+ // Insert sessions on different dates (all within the 14-day window)
492+ insertSession ( db , makeSession ( "s1" , "/test/project" , TWO_DAYS_AGO ) ) ;
493+ insertSession ( db , makeSession ( "s2" , "/test/project" , YESTERDAY ) ) ;
494+ insertSession ( db , makeSession ( "s3" , "/test/project" , TODAY ) ) ;
491495
492496 const trend = getDurationTrend ( db , 14 , "/test/project" ) ;
493497
0 commit comments