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.
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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.
|
||||
// 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);
|
||||
|
||||
@@ -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(");
|
||||
|
||||
Reference in New Issue
Block a user