mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 23:06:17 +01:00
test: support bounded external PostgreSQL in incoming wake regressions
This commit is contained in:
1 parent
d900d37bce
commit
6be8fbae45
2 files changed
+36
-10
No files matched your search
@@ -20,6 +20,7 @@ import {
|
||||
companies,
|
||||
companyMemberships,
|
||||
createDb,
|
||||
closeRegisteredClients,
|
||||
heartbeatRuns,
|
||||
issueComments,
|
||||
issueRecoveryActions,
|
||||
@@ -43,12 +44,15 @@ import {
|
||||
} from "./helpers/embedded-postgres.ts";
|
||||
import { parseWakePayloadFromMessage } from "./helpers/wake-message.ts";
|
||||
|
||||
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
|
||||
|
||||
const externalDatabaseUrl = resolveExternalTestDatabaseUrl("PAPERCLIP_HEARTBEAT_COMMENT_WAKE_TEST_DATABASE_URL");
|
||||
const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();
|
||||
const describeEmbeddedPostgres = embeddedPostgresSupport.supported
|
||||
const describeEmbeddedPostgres = externalDatabaseUrl || embeddedPostgresSupport.supported
|
||||
? describe
|
||||
: describe.skip;
|
||||
|
||||
if (!embeddedPostgresSupport.supported) {
|
||||
if (!externalDatabaseUrl && !embeddedPostgresSupport.supported) {
|
||||
console.warn(
|
||||
`Skipping embedded Postgres heartbeat comment wake batching tests on this host: ${embeddedPostgresSupport.reason ?? "unsupported environment"}`,
|
||||
);
|
||||
@@ -295,6 +299,10 @@ describeEmbeddedPostgres("heartbeat comment wake batching", () => {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
if (externalDatabaseUrl) {
|
||||
db = createDb(externalDatabaseUrl, { maxConnections: 4 });
|
||||
return; // The external owner applies the normal migrations once before this process.
|
||||
}
|
||||
const started = await startEmbeddedPostgresTestDatabase(
|
||||
"paperclip-heartbeat-comment-wake-",
|
||||
);
|
||||
@@ -303,9 +311,13 @@ describeEmbeddedPostgres("heartbeat comment wake batching", () => {
|
||||
}, 120_000);
|
||||
|
||||
afterAll(async () => {
|
||||
await heartbeatService(db).drainActiveRunExecutions();
|
||||
await closeDbClient(db);
|
||||
await tempDb?.cleanup();
|
||||
const failures: unknown[] = [];
|
||||
try { await heartbeatService(db).drainActiveRunExecutions(); } catch (error) { failures.push(error); }
|
||||
try { await closeDbClient(db); } catch (error) { failures.push(error); }
|
||||
try { if (externalDatabaseUrl) await closeRegisteredClients(externalDatabaseUrl, { scope: "database" }); }
|
||||
catch (error) { failures.push(error); }
|
||||
try { await tempDb?.cleanup(); } catch (error) { failures.push(error); }
|
||||
if (failures.length) throw new AggregateError(failures, "Comment-wake fixture cleanup failed");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { and, eq, inArray, sql } from "drizzle-orm";
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { agentWakeupRequests, agents, authUsers, companies, companyMemberships, createDb, heartbeatRuns, issues } from "@paperclipai/db";
|
||||
import { agentWakeupRequests, agents, authUsers, companies, companyMemberships, closeRegisteredClients, createDb, heartbeatRuns, issues } from "@paperclipai/db";
|
||||
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
||||
import { heartbeatService } from "../services/heartbeat.ts";
|
||||
import { runningProcesses } from "../adapters/index.ts";
|
||||
@@ -21,8 +21,11 @@ vi.mock("../adapters/index.ts", async () => {
|
||||
return { ...actual, getServerAdapter: vi.fn(() => ({ supportsLocalAgentJwt: false, execute: mockAdapterExecute })) };
|
||||
});
|
||||
|
||||
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
|
||||
|
||||
const externalDatabaseUrl = resolveExternalTestDatabaseUrl("PAPERCLIP_PERSON_TREE_DISPATCH_TEST_DATABASE_URL");
|
||||
const support = await getEmbeddedPostgresTestSupport();
|
||||
const suite = support.supported ? describe : describe.skip;
|
||||
const suite = externalDatabaseUrl || support.supported ? describe : describe.skip;
|
||||
const MINUTE = 60_000;
|
||||
|
||||
suite("dispatch of work on a task tree a person created, through the heartbeat queue", () => {
|
||||
@@ -32,8 +35,12 @@ suite("dispatch of work on a task tree a person created, through the heartbeat q
|
||||
const userId = randomUUID();
|
||||
|
||||
beforeAll(async () => {
|
||||
temporary = await startEmbeddedPostgresTestDatabase("paperclip-person-tree-dispatch-");
|
||||
db = createDb(temporary.connectionString);
|
||||
if (externalDatabaseUrl) {
|
||||
db = createDb(externalDatabaseUrl, { maxConnections: 4 });
|
||||
} else {
|
||||
temporary = await startEmbeddedPostgresTestDatabase("paperclip-person-tree-dispatch-");
|
||||
db = createDb(temporary.connectionString);
|
||||
}
|
||||
heartbeat = heartbeatService(db);
|
||||
await db.insert(authUsers).values({ id: userId, name: "Board", email: `${userId}@example.test`, emailVerified: true,
|
||||
createdAt: new Date(), updatedAt: new Date() });
|
||||
@@ -50,7 +57,14 @@ suite("dispatch of work on a task tree a person created, through the heartbeat q
|
||||
await db.execute(sql`truncate table ${companies} cascade`);
|
||||
}, 180_000);
|
||||
|
||||
afterAll(async () => { await db?.$client.end(); await temporary?.cleanup(); }, 120_000);
|
||||
afterAll(async () => {
|
||||
const failures: unknown[] = [];
|
||||
try { await db?.$client.end(); } catch (error) { failures.push(error); }
|
||||
try { if (externalDatabaseUrl) await closeRegisteredClients(externalDatabaseUrl, { scope: "database" }); }
|
||||
catch (error) { failures.push(error); }
|
||||
try { await temporary?.cleanup(); } catch (error) { failures.push(error); }
|
||||
if (failures.length) throw new AggregateError(failures, "Person-tree fixture cleanup failed");
|
||||
}, 120_000);
|
||||
|
||||
async function seed() {
|
||||
const companyId = randomUUID(), agentId = randomUUID();
|
||||
|
||||
Reference in new issue
Block a user