- Fix persistence edge cases around pagination offsets, assistant message ordering, and checkpoint merge semantics - Make state DB and sqlite adapter failures safer with better cleanup and runtime errors - Treat `threads.update` as unsupported, keep `threads.updateTerminalState` canonical, and avoid failing revert RPCs on persistence-write errors - Add focused server/web/contracts tests for the new failure and compatibility paths
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { openSqliteDatabase } from "./sqliteAdapter";
|
|
|
|
describe("sqliteAdapter", () => {
|
|
it("opens a database and runs basic statements", () => {
|
|
const db = openSqliteDatabase(":memory:");
|
|
db.exec("CREATE TABLE sample (id INTEGER PRIMARY KEY AUTOINCREMENT, value TEXT NOT NULL);");
|
|
|
|
const insertResult = db.prepare("INSERT INTO sample (value) VALUES (?);").run("hello") as {
|
|
changes?: number;
|
|
lastInsertRowid?: number;
|
|
};
|
|
expect(insertResult.changes).toBe(1);
|
|
|
|
const row = db.prepare("SELECT value FROM sample WHERE id = ?;").get(1) as
|
|
| { value?: string }
|
|
| undefined;
|
|
expect(row?.value).toBe("hello");
|
|
|
|
const rows = db.prepare("SELECT value FROM sample ORDER BY id ASC;").all() as Array<{
|
|
value?: string;
|
|
}>;
|
|
expect(rows.map((entry) => entry.value)).toEqual(["hello"]);
|
|
|
|
db.close();
|
|
});
|
|
|
|
it("throws a helpful error when node:sqlite is unavailable", () => {
|
|
const missingModuleError = new Error("No such built-in module: node:sqlite");
|
|
(missingModuleError as NodeJS.ErrnoException).code = "ERR_UNKNOWN_BUILTIN_MODULE";
|
|
const requireFn = vi.fn((specifier: string) => {
|
|
if (specifier === "node:sqlite") {
|
|
throw missingModuleError;
|
|
}
|
|
throw new Error(`Unexpected module request: ${specifier}`);
|
|
});
|
|
|
|
expect(() => openSqliteDatabase(":memory:", requireFn as never, false)).toThrow(
|
|
"node:sqlite is unavailable",
|
|
);
|
|
});
|
|
});
|