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:
@@ -65,7 +65,7 @@ function createMcpServer(db: Db): McpServer {
|
||||
mimeType: "application/json",
|
||||
},
|
||||
async () => {
|
||||
const summary = getCollectionSummary(db);
|
||||
const summary = await getCollectionSummary(db);
|
||||
return {
|
||||
contents: [
|
||||
{
|
||||
|
||||
@@ -7,12 +7,12 @@ import { getGlobalTotals } from "../../services/totals.service.ts";
|
||||
|
||||
type Db = typeof prodDb;
|
||||
|
||||
export function getCollectionSummary(db: Db) {
|
||||
const totals = getGlobalTotals(db);
|
||||
const categories = getAllCategories(db);
|
||||
const items = getAllItems(db);
|
||||
const setups = getAllSetups(db);
|
||||
const activeThreads = getAllThreads(db, false);
|
||||
export async function getCollectionSummary(db: Db) {
|
||||
const totals = await getGlobalTotals(db);
|
||||
const categories = await getAllCategories(db);
|
||||
const items = await getAllItems(db);
|
||||
const setups = await getAllSetups(db);
|
||||
const activeThreads = await getAllThreads(db, false);
|
||||
|
||||
// Build items-by-category map
|
||||
const itemsByCategory: Record<string, number> = {};
|
||||
|
||||
@@ -41,7 +41,7 @@ export function registerCategoryTools(db: Db) {
|
||||
return {
|
||||
list_categories: async (): Promise<ToolResult> => {
|
||||
try {
|
||||
const cats = getAllCategories(db);
|
||||
const cats = await getAllCategories(db);
|
||||
return textResult(cats);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -53,7 +53,7 @@ export function registerCategoryTools(db: Db) {
|
||||
icon?: string;
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const cat = createCategory(db, args);
|
||||
const cat = await createCategory(db, args);
|
||||
return textResult(cat);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
|
||||
@@ -95,7 +95,7 @@ export function registerItemTools(db: Db) {
|
||||
return {
|
||||
list_items: async (args: { categoryId?: number }): Promise<ToolResult> => {
|
||||
try {
|
||||
const items = getAllItems(db);
|
||||
const items = await getAllItems(db);
|
||||
if (args.categoryId) {
|
||||
return textResult(
|
||||
items.filter((i) => i.categoryId === args.categoryId),
|
||||
@@ -109,7 +109,7 @@ export function registerItemTools(db: Db) {
|
||||
|
||||
get_item: async (args: { id: number }): Promise<ToolResult> => {
|
||||
try {
|
||||
const item = getItemById(db, args.id);
|
||||
const item = await getItemById(db, args.id);
|
||||
if (!item) return errorResult(`Item ${args.id} not found`);
|
||||
return textResult(item);
|
||||
} catch (err) {
|
||||
@@ -128,7 +128,7 @@ export function registerItemTools(db: Db) {
|
||||
imageSourceUrl?: string;
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const item = createItem(db, args);
|
||||
const item = await createItem(db, args);
|
||||
return textResult(item);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -148,7 +148,7 @@ export function registerItemTools(db: Db) {
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const { id, ...data } = args;
|
||||
const item = updateItem(db, id, data);
|
||||
const item = await updateItem(db, id, data);
|
||||
if (!item) return errorResult(`Item ${id} not found`);
|
||||
return textResult(item);
|
||||
} catch (err) {
|
||||
@@ -158,7 +158,7 @@ export function registerItemTools(db: Db) {
|
||||
|
||||
delete_item: async (args: { id: number }): Promise<ToolResult> => {
|
||||
try {
|
||||
const item = deleteItem(db, args.id);
|
||||
const item = await deleteItem(db, args.id);
|
||||
if (!item) return errorResult(`Item ${args.id} not found`);
|
||||
return textResult({ deleted: true, item });
|
||||
} catch (err) {
|
||||
|
||||
@@ -64,7 +64,7 @@ export function registerSetupTools(db: Db) {
|
||||
return {
|
||||
list_setups: async (): Promise<ToolResult> => {
|
||||
try {
|
||||
const setupList = getAllSetups(db);
|
||||
const setupList = await getAllSetups(db);
|
||||
return textResult(setupList);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -73,7 +73,7 @@ export function registerSetupTools(db: Db) {
|
||||
|
||||
get_setup: async (args: { id: number }): Promise<ToolResult> => {
|
||||
try {
|
||||
const setup = getSetupWithItems(db, args.id);
|
||||
const setup = await getSetupWithItems(db, args.id);
|
||||
if (!setup) return errorResult(`Setup ${args.id} not found`);
|
||||
return textResult(setup);
|
||||
} catch (err) {
|
||||
@@ -83,7 +83,7 @@ export function registerSetupTools(db: Db) {
|
||||
|
||||
create_setup: async (args: { name: string }): Promise<ToolResult> => {
|
||||
try {
|
||||
const setup = createSetup(db, args);
|
||||
const setup = await createSetup(db, args);
|
||||
return textResult(setup);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -98,14 +98,14 @@ export function registerSetupTools(db: Db) {
|
||||
try {
|
||||
let setup = null;
|
||||
if (args.name) {
|
||||
setup = updateSetup(db, args.id, { name: args.name });
|
||||
setup = await updateSetup(db, args.id, { name: args.name });
|
||||
if (!setup) return errorResult(`Setup ${args.id} not found`);
|
||||
}
|
||||
if (args.itemIds) {
|
||||
syncSetupItems(db, args.id, args.itemIds);
|
||||
await syncSetupItems(db, args.id, args.itemIds);
|
||||
}
|
||||
// Return updated setup with items
|
||||
const result = getSetupWithItems(db, args.id);
|
||||
const result = await getSetupWithItems(db, args.id);
|
||||
if (!result) return errorResult(`Setup ${args.id} not found`);
|
||||
return textResult(result);
|
||||
} catch (err) {
|
||||
|
||||
@@ -119,7 +119,7 @@ export function registerThreadTools(db: Db) {
|
||||
includeResolved?: boolean;
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const threadList = getAllThreads(db, args.includeResolved ?? false);
|
||||
const threadList = await getAllThreads(db, args.includeResolved ?? false);
|
||||
return textResult(threadList);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -128,7 +128,7 @@ export function registerThreadTools(db: Db) {
|
||||
|
||||
get_thread: async (args: { id: number }): Promise<ToolResult> => {
|
||||
try {
|
||||
const thread = getThreadWithCandidates(db, args.id);
|
||||
const thread = await getThreadWithCandidates(db, args.id);
|
||||
if (!thread) return errorResult(`Thread ${args.id} not found`);
|
||||
return textResult(thread);
|
||||
} catch (err) {
|
||||
@@ -141,7 +141,7 @@ export function registerThreadTools(db: Db) {
|
||||
categoryId: number;
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const thread = createThread(db, args);
|
||||
const thread = await createThread(db, args);
|
||||
return textResult(thread);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -153,7 +153,7 @@ export function registerThreadTools(db: Db) {
|
||||
candidateId: number;
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const result = resolveThread(db, args.threadId, args.candidateId);
|
||||
const result = await resolveThread(db, args.threadId, args.candidateId);
|
||||
if (!result.success) {
|
||||
return errorResult(result.error ?? "Failed to resolve thread");
|
||||
}
|
||||
@@ -177,7 +177,7 @@ export function registerThreadTools(db: Db) {
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const { threadId, ...data } = args;
|
||||
const candidate = createCandidate(db, threadId, data);
|
||||
const candidate = await createCandidate(db, threadId, data);
|
||||
return textResult(candidate);
|
||||
} catch (err) {
|
||||
return errorResult((err as Error).message);
|
||||
@@ -200,7 +200,7 @@ export function registerThreadTools(db: Db) {
|
||||
}): Promise<ToolResult> => {
|
||||
try {
|
||||
const { id, ...data } = args;
|
||||
const candidate = updateCandidate(db, id, data);
|
||||
const candidate = await updateCandidate(db, id, data);
|
||||
if (!candidate) return errorResult(`Candidate ${id} not found`);
|
||||
return textResult(candidate);
|
||||
} catch (err) {
|
||||
@@ -210,7 +210,7 @@ export function registerThreadTools(db: Db) {
|
||||
|
||||
remove_candidate: async (args: { id: number }): Promise<ToolResult> => {
|
||||
try {
|
||||
const candidate = deleteCandidate(db, args.id);
|
||||
const candidate = await deleteCandidate(db, args.id);
|
||||
if (!candidate) return errorResult(`Candidate ${args.id} not found`);
|
||||
return textResult({ deleted: true, candidate });
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user