test(server): isolate route imports and watchdog fixture identities

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-24 19:29:45 -07:00
1 parent 4d15c08428
commit 2f6b52c187
2 files changed
+15 -13

No files matched your search

@@ -2,7 +2,10 @@ import express from "express";
import request from "supertest";
import { getTableName } from "drizzle-orm";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { HttpError } from "../errors.js";
import { HttpError, unprocessable } from "../errors.js";
import { normalizeIssueExecutionPolicy } from "../services/issue-execution-policy.js";
import { issueRoutes } from "../routes/issues.js";
import { errorHandler } from "../middleware/index.js";
vi.mock("../services/fast-responses.js", () => ({
enqueueFastResponse: vi.fn(async () => undefined),
@@ -233,10 +236,6 @@ async function installActor(
app: express.Express,
actor?: Record<string, unknown>,
) {
const [{ issueRoutes }, { errorHandler }] = await Promise.all([
import("../routes/issues.js"),
import("../middleware/index.js"),
]);
app.use((req, _res, next) => {
(req as any).actor = actor ?? {
type: "board",
@@ -261,8 +260,6 @@ async function normalizePolicy(input: {
>;
}>;
}) {
const { normalizeIssueExecutionPolicy } =
await import("../services/issue-execution-policy.js");
return normalizeIssueExecutionPolicy(input);
}
@@ -3666,7 +3663,6 @@ describe("issue comment reopen routes", () => {
authorAgentId: reviewerAgentId,
authorUserId: null,
});
const { unprocessable } = await import("../errors.js");
mockIssueService.update.mockRejectedValue(
unprocessable("Issue can only have one assignee"),
);
@@ -28,7 +28,10 @@ import {
} from "./helpers/embedded-postgres.js";
import { taskWatchdogService } from "../services/task-watchdogs.ts";
const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
const externalUrl = resolveExternalTestDatabaseUrl("PAPERCLIP_WATCHDOG_TEST_DATABASE_URL");
const embeddedPostgresSupport = externalUrl ? { supported: true, reason: undefined } : await getEmbeddedPostgresTestSupport();
const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip;
if (!embeddedPostgresSupport.supported) {
@@ -42,8 +45,8 @@ describeEmbeddedPostgres("task watchdog scheduler", () => {
let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;
beforeAll(async () => {
tempDb = await startEmbeddedPostgresTestDatabase("paperclip-task-watchdogs-scheduler-");
db = createDb(tempDb.connectionString);
if (!externalUrl) tempDb = await startEmbeddedPostgresTestDatabase("paperclip-task-watchdogs-scheduler-");
db = createDb(externalUrl ?? tempDb!.connectionString);
}, 20_000);
afterEach(async () => {
@@ -64,6 +67,7 @@ describeEmbeddedPostgres("task watchdog scheduler", () => {
});
afterAll(async () => {
await db?.$client.end({ timeout: 1 });
await tempDb?.cleanup();
});
@@ -96,16 +100,18 @@ describeEmbeddedPostgres("task watchdog scheduler", () => {
return id;
}
let nextFixtureIssueNumber = 10_000;
async function seedIssue(companyId: string, overrides: Partial<typeof issues.$inferInsert> = {}) {
const id = overrides.id ?? randomUUID();
const issueNumber = overrides.issueNumber ?? ++nextFixtureIssueNumber;
await db.insert(issues).values({
id,
companyId,
title: overrides.title ?? "Watched issue",
status: overrides.status ?? "done",
priority: overrides.priority ?? "medium",
identifier: overrides.identifier ?? `WDOG-${Math.floor(Math.random() * 10_000)}`,
issueNumber: overrides.issueNumber ?? Math.floor(Math.random() * 10_000),
identifier: overrides.identifier ?? `WDOG-${issueNumber}`,
issueNumber,
parentId: overrides.parentId,
assigneeAgentId: overrides.assigneeAgentId,
originKind: overrides.originKind,