Skip to content

Commit 84411b6

Browse files
committed
fix(stats/db.test): use rolling TODAY date to avoid stale 7-day window failures
1 parent c12a54c commit 84411b6

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

plugins/stats/tests/db.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ describe("db", () => {
3535
}
3636
});
3737

38-
function makeSession(id: string, project = "/test/project", date = "2026-03-26"): SessionMetrics {
38+
const TODAY = new Date().toISOString().slice(0, 10);
39+
40+
function makeSession(id: string, project = "/test/project", date = TODAY): SessionMetrics {
3941
return {
4042
session_id: id,
4143
date,
@@ -48,14 +50,14 @@ describe("db", () => {
4850
duration_ms: 50,
4951
success: true,
5052
activity_category: "research",
51-
timestamp: "2026-03-26T10:00:00.000Z",
53+
timestamp: `${date}T10:00:00.000Z`,
5254
},
5355
{
5456
tool_name: "Write",
5557
duration_ms: 30,
5658
success: true,
5759
activity_category: "coding",
58-
timestamp: "2026-03-26T10:01:00.000Z",
60+
timestamp: `${date}T10:01:00.000Z`,
5961
},
6062
],
6163
activity_counts: {
@@ -193,9 +195,8 @@ describe("db", () => {
193195

194196
test("getSessionSummary returns aggregate stats", () => {
195197
const db = openDb(dbPath);
196-
const today = new Date().toISOString().slice(0, 10);
197-
insertSession(db, makeSession("s1", "/test/project", today));
198-
insertSession(db, makeSession("s2", "/test/project", today));
198+
insertSession(db, makeSession("s1", "/test/project", TODAY));
199+
insertSession(db, makeSession("s2", "/test/project", TODAY));
199200

200201
const summary = getSessionSummary(db, 7, "/test/project");
201202
expect(summary.session_count).toBe(2);
@@ -229,7 +230,7 @@ describe("db", () => {
229230
insertToolCalls(db, metrics.tool_calls, "old-session");
230231

231232
// Insert a recent session
232-
const recent = makeSession("recent-session", "/test/project", "2026-03-26");
233+
const recent = makeSession("recent-session", "/test/project", TODAY);
233234
insertSession(db, recent);
234235

235236
const { deletedCount } = deleteOldSessions(db, 90);

0 commit comments

Comments
 (0)