Bound route fixture setup separately from HTTP assertions

This commit is contained in:
Dotta 2026-09-11 15:32:44 -05:00
parent f0e3c430a0
commit 9e20cc132e
2 changed files with 22 additions and 10 deletions

View File

@ -139,11 +139,15 @@ function makeIssue(status: "todo" | "done") {
};
}
async function createApp(actor: Record<string, unknown>) {
const [{ errorHandler }, { issueRoutes }] = await Promise.all([
function loadAppModules() {
return Promise.all([
vi.importActual<typeof import("../middleware/index.js")>("../middleware/index.js"),
vi.importActual<typeof import("../routes/issues.js")>("../routes/issues.js"),
]);
}
async function createApp(actor: Record<string, unknown>) {
const [{ errorHandler }, { issueRoutes }] = await loadAppModules();
const app = express();
app.use(express.json());
app.use((req, _res, next) => {
@ -156,7 +160,7 @@ async function createApp(actor: Record<string, unknown>) {
}
describe("issue telemetry routes", () => {
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
vi.doUnmock("@paperclipai/shared/telemetry");
vi.doUnmock("../telemetry.js");
@ -197,7 +201,9 @@ describe("issue telemetry routes", () => {
permissions: null,
}]).then(onFulfilled, onRejected),
}));
});
// Keep cold route imports in setup rather than the HTTP assertion timeout.
await loadAppModules();
}, 60_000);
it("emits task-completed telemetry with the agent role, adapter type, and model", async () => {
mockAgentService.getById.mockResolvedValue({

View File

@ -260,6 +260,13 @@ function createIssue(overrides: Record<string, unknown> = {}) {
};
}
function loadAppModules() {
return Promise.all([
import("../routes/issues.js"),
import("../middleware/index.js"),
]);
}
async function createApp(actor: Record<string, unknown> = {
type: "board",
userId: "local-board",
@ -275,10 +282,7 @@ async function createApp(actor: Record<string, unknown> = {
responsibleUserId: actor.onBehalfOfUserId ?? null,
};
}
const [{ issueRoutes }, { errorHandler }] = await Promise.all([
import("../routes/issues.js"),
import("../middleware/index.js"),
]);
const [{ issueRoutes }, { errorHandler }] = await loadAppModules();
const app = express();
app.use(express.json());
app.use((req, _res, next) => {
@ -305,7 +309,7 @@ async function resolveMockInteraction(
}
describe.sequential("issue thread interaction routes", () => {
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
vi.doUnmock("../routes/issues.js");
vi.doUnmock("../routes/authz.js");
@ -577,7 +581,9 @@ describe.sequential("issue thread interaction routes", () => {
mockCrossIssueInfluence.sourceIssueId = ISSUE_ID;
mockCrossIssueInfluence.priorCount = 0;
mockCrossIssueInfluence.inserted.length = 0;
});
// Keep cold route imports in setup rather than the HTTP assertion timeout.
await loadAppModules();
}, 60_000);
it("creates board-authored interactions", async () => {
const app = await createApp();