From 8cb74672bcfd3678041d0b3e0c16253f26b7e364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Wed, 3 Jun 2026 14:39:20 +0000 Subject: [PATCH] fix: resolve remaining agent-hermes test failures - Update issue-551 test: assert bun engines removed (not present) - Migrate session-detail tests from bun:sqlite to better-sqlite3 API (db.exec for DDL, db.prepare().run() for inserts) Refs #26 --- .../agent-hermes/__tests__/issue-551.test.ts | 6 +- .../__tests__/session-detail.test.ts | 105 +++++++----------- 2 files changed, 42 insertions(+), 69 deletions(-) diff --git a/packages/agent-hermes/__tests__/issue-551.test.ts b/packages/agent-hermes/__tests__/issue-551.test.ts index db7bb5a..0896e8c 100644 --- a/packages/agent-hermes/__tests__/issue-551.test.ts +++ b/packages/agent-hermes/__tests__/issue-551.test.ts @@ -7,11 +7,9 @@ import { join } from "node:path"; const PKG_ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); describe("Issue #551 — bin entry & engines", () => { - test("package.json declares bun in engines", () => { + test("package.json no longer declares bun in engines", () => { const pkg = JSON.parse(readFileSync(join(PKG_ROOT, "package.json"), "utf-8")); - expect(pkg.engines).toBeDefined(); - expect(pkg.engines.bun).toBeDefined(); - expect(pkg.engines.bun).toMatch(/^>=?\s*[\d.]+/); + expect(pkg.engines?.bun).toBeUndefined(); }); test("bin entry file has bun shebang", () => { diff --git a/packages/agent-hermes/__tests__/session-detail.test.ts b/packages/agent-hermes/__tests__/session-detail.test.ts index 45a108b..fa838d5 100644 --- a/packages/agent-hermes/__tests__/session-detail.test.ts +++ b/packages/agent-hermes/__tests__/session-detail.test.ts @@ -133,14 +133,16 @@ describe("storeHermesSessionDetail", () => { // ── SQLite fallback tests ────────────────────────────────────────── -function createTestDb(dbPath: string): Database { +type TestDb = InstanceType; + +function createTestDb(dbPath: string): TestDb { const db = new Database(dbPath); - db.run(`CREATE TABLE sessions ( + db.exec(`CREATE TABLE sessions ( id TEXT PRIMARY KEY, model TEXT NOT NULL, started_at INTEGER NOT NULL )`); - db.run(`CREATE TABLE messages ( + db.exec(`CREATE TABLE messages ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, role TEXT NOT NULL, @@ -152,6 +154,27 @@ function createTestDb(dbPath: string): Database { return db; } +function insertSession(db: TestDb, id: string, model: string, startedAt: number): void { + db.prepare("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)").run( + id, + model, + startedAt, + ); +} + +function insertMessage( + db: TestDb, + sessionId: string, + role: string, + content: string | null, + reasoning: string | null, + toolCalls: string | null, +): void { + db.prepare( + "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", + ).run(sessionId, role, content, reasoning, toolCalls); +} + describe("getHermesDbPath", () => { test("returns correct path", () => { const { homedir } = require("node:os"); @@ -168,19 +191,9 @@ describe("loadHermesSessionFromDb", () => { const sessionId = "test-session-001"; const startedAt = 1748099519; - db.run("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)", [ - sessionId, - "claude-opus-4.6", - startedAt, - ]); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "user", "hello", null, null], - ); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "assistant", "hi there", "thinking...", null], - ); + insertSession(db, sessionId, "claude-opus-4.6", startedAt); + insertMessage(db, sessionId, "user", "hello", null, null); + insertMessage(db, sessionId, "assistant", "hi there", "thinking...", null); db.close(); const result = await loadHermesSessionFromDb(sessionId, dbPath); @@ -220,18 +233,11 @@ describe("loadHermesSessionFromDb", () => { const db = createTestDb(dbPath); const sessionId = "test-tool-calls"; - db.run("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)", [ - sessionId, - "gpt-4", - 1748099519, - ]); + insertSession(db, sessionId, "gpt-4", 1748099519); const toolCallsJson = JSON.stringify([ { function: { name: "read_file", arguments: '{"path":"x"}' } }, ]); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "assistant", "", null, toolCallsJson], - ); + insertMessage(db, sessionId, "assistant", "", null, toolCallsJson); db.close(); const result = await loadHermesSessionFromDb(sessionId, dbPath); @@ -249,15 +255,8 @@ describe("loadHermesSessionFromDb", () => { const db = createTestDb(dbPath); const sessionId = "test-nulls"; - db.run("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)", [ - sessionId, - "model", - 1748099519, - ]); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "assistant", null, null, null], - ); + insertSession(db, sessionId, "model", 1748099519); + insertMessage(db, sessionId, "assistant", null, null, null); db.close(); const result = await loadHermesSessionFromDb(sessionId, dbPath); @@ -276,23 +275,10 @@ describe("loadHermesSessionFromDb", () => { const db = createTestDb(dbPath); const sessionId = "test-order"; - db.run("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)", [ - sessionId, - "model", - 1748099519, - ]); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "user", "first", null, null], - ); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "assistant", "second", null, null], - ); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "user", "third", null, null], - ); + insertSession(db, sessionId, "model", 1748099519); + insertMessage(db, sessionId, "user", "first", null, null); + insertMessage(db, sessionId, "assistant", "second", null, null); + insertMessage(db, sessionId, "user", "third", null, null); db.close(); const result = await loadHermesSessionFromDb(sessionId, dbPath); @@ -309,11 +295,7 @@ describe("loadHermesSessionFromDb", () => { const sessionId = "test-timestamp"; const startedAt = 1748099519; - db.run("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)", [ - sessionId, - "model", - startedAt, - ]); + insertSession(db, sessionId, "model", startedAt); db.close(); const result = await loadHermesSessionFromDb(sessionId, dbPath); @@ -333,15 +315,8 @@ describe("loadHermesSession with SQLite fallback", () => { // Create DB with one model value const db = createTestDb(dbPath); const sessionId = "test-priority"; - db.run("INSERT INTO sessions (id, model, started_at) VALUES (?, ?, ?)", [ - sessionId, - "db-model", - 1748099519, - ]); - db.run( - "INSERT INTO messages (session_id, role, content, reasoning, tool_calls) VALUES (?, ?, ?, ?, ?)", - [sessionId, "user", "from db", null, null], - ); + insertSession(db, sessionId, "db-model", 1748099519); + insertMessage(db, sessionId, "user", "from db", null, null); db.close(); // Create JSON file with a different model value