feat(16-04): update route tests and MCP tests for multi-user userId

- All 8 route test files destructure { db, userId } from createTestDb()
- All route test middleware sets c.set("userId", userId)
- MCP tools.test.ts passes userId to all registerXTools(db, userId) calls
- MCP tools.test.ts passes userId to getCollectionSummary(db, userId)
- Added 4 cross-user isolation tests for MCP tools (items, item by ID, threads, collection summary)
- OAuth test db type annotation updated for new createTestDb return shape
- Images test now uses createTestDb with userId context

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 11:31:05 +02:00
parent f7c9f3dc94
commit 5085d8e3f7
9 changed files with 165 additions and 55 deletions

View File

@@ -7,28 +7,30 @@ import { createUser } from "../../src/server/services/auth.service.ts";
import { createTestDb } from "../helpers/db.ts";
function createTestApp() {
const db = createTestDb();
const app = new Hono<{ Variables: { db?: any } }>();
const { db, userId } = createTestDb();
const app = new Hono<{ Variables: { db?: any; userId?: number } }>();
app.use("*", async (c, next) => {
c.set("db", db);
c.set("userId", userId);
await next();
});
app.route("/.well-known", wellKnownRoute);
app.route("/oauth", oauthRoutes);
return { app, db };
return { app, db, userId };
}
function createFullTestApp() {
const db = createTestDb();
const app = new Hono<{ Variables: { db?: any } }>();
const { db, userId } = createTestDb();
const app = new Hono<{ Variables: { db?: any; userId?: number } }>();
app.use("*", async (c, next) => {
c.set("db", db);
c.set("userId", userId);
await next();
});
app.route("/.well-known", wellKnownRoute);
app.route("/oauth", oauthRoutes);
app.route("/mcp", mcpRoutes);
return { app, db };
return { app, db, userId };
}
function generatePkce() {
@@ -39,7 +41,7 @@ function generatePkce() {
describe("OAuth Routes", () => {
let app: Hono;
let db: ReturnType<typeof createTestDb>;
let db: ReturnType<typeof createTestDb>["db"];
beforeEach(async () => {
const testApp = createTestApp();