From 20c0a2e4101d8507e7cbbaf547baa4f9f2340b73 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sun, 12 Jul 2026 03:13:15 +0200 Subject: [PATCH] test(coding-agent): fixed storage tests for schema v6 and slow CI disks - Compat tests assert the exported SCHEMA_VERSION instead of a stale hardcoded 5; the perf-sample change bumped agent.db to v6. - Backfill cap fixture inserts its 300 rows in one transaction; per-row implicit transactions fsynced 300 times and timed out on CI runners. --- packages/coding-agent/src/session/agent-storage.ts | 4 ++-- .../test/agent-storage-model-perf.test.ts | 13 ++++++++----- .../test/agent-storage-sqlite-compat.test.ts | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/coding-agent/src/session/agent-storage.ts b/packages/coding-agent/src/session/agent-storage.ts index d8c6dae8d..345edafa7 100644 --- a/packages/coding-agent/src/session/agent-storage.ts +++ b/packages/coding-agent/src/session/agent-storage.ts @@ -115,8 +115,8 @@ function normalizeModelPerfSample(modelKey: string, sample: ModelPerfSample): Mo return { modelKey, outputTokens, durationMs, ttftSamples: ttftMs !== undefined ? 1 : 0, ttftMs: ttftMs ?? 0 }; } -/** Bump when schema changes require migration */ -const SCHEMA_VERSION = 6; +/** Current agent.db schema version; bump when schema changes require migration. */ +export const SCHEMA_VERSION = 6; const SQLITE_NOW_EPOCH = "CAST(strftime('%s','now') AS INTEGER)"; /** Singleton instances per database path */ diff --git a/packages/coding-agent/test/agent-storage-model-perf.test.ts b/packages/coding-agent/test/agent-storage-model-perf.test.ts index e0c450513..c1ab335e6 100644 --- a/packages/coding-agent/test/agent-storage-model-perf.test.ts +++ b/packages/coding-agent/test/agent-storage-model-perf.test.ts @@ -144,11 +144,14 @@ describe("AgentStorage model perf aggregates", () => { const insert = statsDb.prepare("INSERT INTO messages VALUES (?, ?, ?, ?, ?, ?, ?)"); const now = Date.now(); // 300 rows: the newest 256 run at 100 t/s, the older 44 at a wild - // 10000 t/s. Only the newest 256 may count. - for (let i = 0; i < 300; i++) { - const fast = i < 44; // smallest timestamps = oldest rows - insert.run("openai", "gpt-5", fast ? 10_000 : 100, 1000, null, "stop", now - (300 - i) * 1000); - } + // 10000 t/s. Only the newest 256 may count. One transaction: per-row + // implicit transactions fsync 300 times and time out on slow CI disks. + statsDb.transaction(() => { + for (let i = 0; i < 300; i++) { + const fast = i < 44; // smallest timestamps = oldest rows + insert.run("openai", "gpt-5", fast ? 10_000 : 100, 1000, null, "stop", now - (300 - i) * 1000); + } + })(); statsDb.close(); const imported = await storage.backfillModelPerfFromStats(statsDbPath); diff --git a/packages/coding-agent/test/agent-storage-sqlite-compat.test.ts b/packages/coding-agent/test/agent-storage-sqlite-compat.test.ts index 522aac4ab..290da4024 100644 --- a/packages/coding-agent/test/agent-storage-sqlite-compat.test.ts +++ b/packages/coding-agent/test/agent-storage-sqlite-compat.test.ts @@ -1,7 +1,7 @@ import { Database } from "bun:sqlite"; import { afterEach, describe, expect, it } from "bun:test"; import * as path from "node:path"; -import { AgentStorage } from "@oh-my-pi/pi-coding-agent/session/agent-storage"; +import { AgentStorage, SCHEMA_VERSION } from "@oh-my-pi/pi-coding-agent/session/agent-storage"; import { TempDir } from "@oh-my-pi/pi-utils"; import { readTableSql } from "./helpers/sqlite-inspect"; @@ -53,7 +53,7 @@ describe("AgentStorage SQLite compatibility", () => { storage.recordModelUsage("openai/gpt-5"); expect(storage.getModelUsageOrder()).toEqual(["openai/gpt-5"]); - expect(readSchemaVersion(dbPath)).toBe(5); + expect(readSchemaVersion(dbPath)).toBe(SCHEMA_VERSION); expect(readTableSql(dbPath, "settings")).not.toContain("unixepoch("); expect(readTableSql(dbPath, "settings")).toContain("strftime('%s','now')"); expect(readTableSql(dbPath, "model_usage")).not.toContain("unixepoch("); @@ -87,7 +87,7 @@ describe("AgentStorage SQLite compatibility", () => { const storage = await AgentStorage.open(dbPath); - expect(readSchemaVersion(dbPath)).toBe(5); + expect(readSchemaVersion(dbPath)).toBe(SCHEMA_VERSION); expect(readTableSql(dbPath, "settings")).not.toContain("unixepoch("); expect(readTableSql(dbPath, "settings")).toContain("strftime('%s','now')"); expect(readTableSql(dbPath, "model_usage")).not.toContain("unixepoch(");