feat(14-06): convert route tests + MCP tests to async PGlite

- All 8 route test files: async createTestApp(), async beforeEach
- MCP tools test: await createTestDb(), await getCollectionSummary()
- Fixed MCP tool files: added await to all service calls in items, categories, threads, setups tools
- Fixed MCP collection resource: made getCollectionSummary async
- Fixed MCP index.ts: await getCollectionSummary call
- Increased test timeout to 30s in bunfig.toml for PGlite WASM overhead
- Zero SQLite references remain in tests/

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 15:40:14 +02:00
parent 458b33f1c7
commit f30d375544
15 changed files with 80 additions and 79 deletions

View File

@@ -14,7 +14,7 @@ function parseResult(result: {
describe("MCP Item Tools", () => {
test("list_items returns array", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerItemTools(db);
const result = await tools.list_items({});
const data = parseResult(result);
@@ -22,7 +22,7 @@ describe("MCP Item Tools", () => {
});
test("create_item creates and returns item", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerItemTools(db);
const result = await tools.create_item({
name: "Test Tent",
@@ -38,7 +38,7 @@ describe("MCP Item Tools", () => {
});
test("get_item retrieves by ID", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerItemTools(db);
const created = parseResult(
await tools.create_item({ name: "Sleeping Bag", categoryId: 1 }),
@@ -50,7 +50,7 @@ describe("MCP Item Tools", () => {
});
test("get_item returns error for missing item", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerItemTools(db);
const result = await tools.get_item({ id: 999 });
const data = parseResult(result);
@@ -58,7 +58,7 @@ describe("MCP Item Tools", () => {
});
test("delete_item removes item", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerItemTools(db);
const created = parseResult(
await tools.create_item({ name: "To Delete", categoryId: 1 }),
@@ -76,7 +76,7 @@ describe("MCP Item Tools", () => {
describe("MCP Category Tools", () => {
test("list_categories returns array with Uncategorized", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerCategoryTools(db);
const result = await tools.list_categories();
const data = parseResult(result);
@@ -86,7 +86,7 @@ describe("MCP Category Tools", () => {
});
test("create_category creates a new category", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerCategoryTools(db);
const result = await tools.create_category({
name: "Shelter",
@@ -100,7 +100,7 @@ describe("MCP Category Tools", () => {
describe("MCP Thread Tools", () => {
test("create_thread starts a thread with status active", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerThreadTools(db);
const result = await tools.create_thread({
name: "Handlebar Bag",
@@ -112,7 +112,7 @@ describe("MCP Thread Tools", () => {
});
test("add_candidate adds to thread", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerThreadTools(db);
const thread = parseResult(
await tools.create_thread({ name: "Saddle Bag", categoryId: 1 }),
@@ -132,7 +132,7 @@ describe("MCP Thread Tools", () => {
});
test("resolve_thread picks winner and creates item", async () => {
const db = createTestDb();
const db = await createTestDb();
const threadTools = registerThreadTools(db);
const itemTools = registerItemTools(db);
@@ -179,7 +179,7 @@ describe("MCP Thread Tools", () => {
describe("MCP Setup Tools", () => {
test("create_setup and list_setups", async () => {
const db = createTestDb();
const db = await createTestDb();
const tools = registerSetupTools(db);
await tools.create_setup({ name: "Weekend Trip" });
const result = await tools.list_setups();
@@ -189,7 +189,7 @@ describe("MCP Setup Tools", () => {
});
test("get_setup returns setup with items", async () => {
const db = createTestDb();
const db = await createTestDb();
const setupTools = registerSetupTools(db);
const itemTools = registerItemTools(db);
@@ -210,10 +210,10 @@ describe("MCP Setup Tools", () => {
});
describe("MCP Collection Summary Resource", () => {
test("returns overview with correct counts", () => {
const db = createTestDb();
test("returns overview with correct counts", async () => {
const db = await createTestDb();
const summary = getCollectionSummary(db);
const summary = await getCollectionSummary(db);
expect(summary.overview).toBeDefined();
expect(summary.overview.totalItems).toBe(0);
expect(summary.overview.categoryCount).toBe(1); // Uncategorized
@@ -223,7 +223,7 @@ describe("MCP Collection Summary Resource", () => {
});
test("reflects items and threads after creation", async () => {
const db = createTestDb();
const db = await createTestDb();
const itemTools = registerItemTools(db);
const threadTools = registerThreadTools(db);
@@ -242,7 +242,7 @@ describe("MCP Collection Summary Resource", () => {
categoryId: 1,
});
const summary = getCollectionSummary(db);
const summary = await getCollectionSummary(db);
expect(summary.overview.totalItems).toBe(2);
expect(summary.overview.totalWeightGrams).toBe(2000);
expect(summary.overview.activeThreadCount).toBe(1);

View File

@@ -3,8 +3,8 @@ import { Hono } from "hono";
import { authRoutes } from "../../src/server/routes/auth.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono<{ Variables: { db?: any } }>();
app.use("*", async (c, next) => {
@@ -19,8 +19,8 @@ function createTestApp() {
describe("Auth Routes", () => {
let app: Hono;
beforeEach(() => {
const testApp = createTestApp();
beforeEach(async () => {
const testApp = await createTestApp();
app = testApp.app;
});

View File

@@ -4,8 +4,8 @@ import { categoryRoutes } from "../../src/server/routes/categories.ts";
import { itemRoutes } from "../../src/server/routes/items.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono();
// Inject test DB into context for all routes
@@ -22,8 +22,8 @@ function createTestApp() {
describe("Category Routes", () => {
let app: Hono;
beforeEach(() => {
const testApp = createTestApp();
beforeEach(async () => {
const testApp = await createTestApp();
app = testApp.app;
});

View File

@@ -4,8 +4,8 @@ import { categoryRoutes } from "../../src/server/routes/categories.ts";
import { itemRoutes } from "../../src/server/routes/items.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono();
// Inject test DB into context for all routes
@@ -22,8 +22,8 @@ function createTestApp() {
describe("Item Routes", () => {
let app: Hono;
beforeEach(() => {
const testApp = createTestApp();
beforeEach(async () => {
const testApp = await createTestApp();
app = testApp.app;
});

View File

@@ -6,8 +6,8 @@ import { oauthRoutes, wellKnownRoute } from "../../src/server/routes/oauth.ts";
import { createUser } from "../../src/server/services/auth.service.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono<{ Variables: { db?: any } }>();
app.use("*", async (c, next) => {
c.set("db", db);
@@ -18,8 +18,8 @@ function createTestApp() {
return { app, db };
}
function createFullTestApp() {
const db = createTestDb();
async function createFullTestApp() {
const db = await createTestDb();
const app = new Hono<{ Variables: { db?: any } }>();
app.use("*", async (c, next) => {
c.set("db", db);
@@ -39,10 +39,10 @@ function generatePkce() {
describe("OAuth Routes", () => {
let app: Hono;
let db: ReturnType<typeof createTestDb>;
let db: any;
beforeEach(async () => {
const testApp = createTestApp();
const testApp = await createTestApp();
app = testApp.app;
db = testApp.db;
await createUser(db, "admin", "secret123");
@@ -182,7 +182,7 @@ describe("OAuth Routes", () => {
});
describe("Full OAuth flow", () => {
it("register authorize token exchange", async () => {
it("register -> authorize -> token exchange", async () => {
// 1. Register client
const regRes = await app.request("/oauth/register", {
method: "POST",
@@ -245,9 +245,9 @@ describe("OAuth Routes", () => {
});
});
describe("Full OAuth MCP Flow", () => {
it("complete flow: register authorize token MCP call", async () => {
const { app, db } = createFullTestApp();
describe("Full OAuth -> MCP Flow", () => {
it("complete flow: register -> authorize -> token -> MCP call", async () => {
const { app, db } = await createFullTestApp();
await createUser(db, "admin", "secret123");
const { verifier, challenge } = generatePkce();
@@ -321,7 +321,7 @@ describe("OAuth Routes", () => {
});
it("rejects MCP call without auth when user exists", async () => {
const { app, db } = createFullTestApp();
const { app, db } = await createFullTestApp();
await createUser(db, "admin", "secret123");
const mcpRes = await app.request("/mcp", {

View File

@@ -6,8 +6,8 @@ import { setupRoutes } from "../../src/server/routes/setups";
import { threadRoutes } from "../../src/server/routes/threads";
import { createTestDb } from "../helpers/db";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono();
app.use("*", async (c, next) => {
c.set("db", db);
@@ -23,8 +23,8 @@ function createTestApp() {
describe("Invalid ID parameter handling", () => {
let app: Hono;
beforeEach(() => {
app = createTestApp();
beforeEach(async () => {
app = await createTestApp();
});
describe("items", () => {

View File

@@ -4,8 +4,8 @@ import { itemRoutes } from "../../src/server/routes/items.ts";
import { setupRoutes } from "../../src/server/routes/setups.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono();
app.use("*", async (c, next) => {
@@ -39,8 +39,8 @@ async function createItemViaAPI(app: Hono, data: any) {
describe("Setup Routes", () => {
let app: Hono;
beforeEach(() => {
const testApp = createTestApp();
beforeEach(async () => {
const testApp = await createTestApp();
app = testApp.app;
});

View File

@@ -3,8 +3,8 @@ import { Hono } from "hono";
import { threadRoutes } from "../../src/server/routes/threads.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
async function createTestApp() {
const db = await createTestDb();
const app = new Hono();
// Inject test DB into context for all routes
@@ -38,8 +38,8 @@ async function createCandidateViaAPI(app: Hono, threadId: number, data: any) {
describe("Thread Routes", () => {
let app: Hono;
beforeEach(() => {
const testApp = createTestApp();
beforeEach(async () => {
const testApp = await createTestApp();
app = testApp.app;
});