fix(hub): restore project create payload and stabilize integration DB seed

Explorer POST /projects was dropping projectId/folderId/workspaceDir after a
narrowed response shape, breaking admin-explorer. Make seedTestOrganization
idempotent under shared-DB isolation, force single-worker vitest, and align the
OAuth no-membership redirect expectation with authRoutes.
This commit is contained in:
2026-07-30 14:44:11 +08:00
parent 0f4377f16c
commit ee928b5832
4 changed files with 52 additions and 37 deletions
+6 -1
View File
@@ -155,7 +155,12 @@ export async function registerExplorerRoutes(
workspaceRoot: config.projectWorkspaceRoot,
...(typeof body.folderId === "string" ? { folderId: body.folderId } : {}),
});
return reply.status(201).send({ id: result.projectId, name: body.name });
return reply.status(201).send({
projectId: result.projectId,
folderId: result.folderId,
workspaceDir: result.workspaceDir,
name: body.name,
});
} catch (err) {
return handleRouteError(reply, err);
}
+2 -1
View File
@@ -242,7 +242,8 @@ describe("admin auth + org API guards", () => {
headers: { cookie: `${OAUTH_STATE_COOKIE_NAME}=${nonce}` },
});
expect(res.statusCode).toBe(302);
expect(res.headers.location).toBe("/admin");
// New users without membership land on login error; session is still set.
expect(res.headers.location).toBe("/admin/login?error=no_organization");
expect(JSON.stringify(res.headers["set-cookie"])).toContain("cph_session=");
const user = await prisma.user.findUnique({ where: { feishuOpenId: "ou_new" } });
+12 -3
View File
@@ -80,7 +80,14 @@ export async function seedTestOrganization(
id: string = DEFAULT_ORG_ID,
slug: string = "test-default",
): Promise<void> {
// Serialise generate+inbox against concurrent callers in the same process.
// Integration tests share one DB and some files call seed without resetDb.
await prisma.$transaction(async (tx) => {
const existing = await tx.organization.findUnique({
where: { id },
select: { id: true },
});
if (existing === null) {
await tx.organization.create({
data: {
id,
@@ -100,13 +107,14 @@ export async function seedTestOrganization(
},
},
});
});
const inbox = await prisma.folder.findFirst({
}
const inbox = await tx.folder.findFirst({
where: { organizationId: id, kind: "SYSTEM_INBOX", archivedAt: null },
select: { id: true },
});
if (inbox === null) {
await prisma.folder.create({
await tx.folder.create({
data: {
id: `folder_inbox_${id}`,
organizationId: id,
@@ -116,6 +124,7 @@ export async function seedTestOrganization(
},
});
}
});
}
/** A logger that discards everything (tests don't need fastify's pino). */
+4 -4
View File
@@ -3,11 +3,11 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
include: ["test/**/*.test.ts"],
// Integration tests share one DB; run files sequentially to avoid
// concurrent truncate/insert races. Unit tests are fast either way.
pool: "forks",
fileParallelism: false,
// Integration tests share one DB. Single worker + sequential files so
// TRUNCATE + seed cannot race across files.
pool: "threads",
maxWorkers: 1,
fileParallelism: false,
env: { NODE_ENV: "test" },
},
});