Skip to content

Commit e7fafbf

Browse files
committed
fix(webapp): watches test replays every dashboard-agent migration and uses the tenancy-scoped list signature
The suite pinned a migration list that stopped before last_read_at (42703 on CI) and two tests still called listActiveWatchesForChats with the pre-tenancy array signature. Migrations are now read from the folder so a new one can't silently stale the schema.
1 parent 0dece13 commit e7fafbf

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

apps/webapp/test/dashboardAgentWatches.test.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import type { WatchSpec } from "@internal/dashboard-agent-contracts";
2121
import { postgresTest } from "@internal/testcontainers";
2222
import type { PrismaClient } from "@trigger.dev/database";
23-
import { readFileSync } from "node:fs";
23+
import { readdirSync, readFileSync } from "node:fs";
2424
import path from "node:path";
2525
import { afterEach, beforeEach, describe, expect, vi } from "vitest";
2626
import type { WatchCheckDeps, WatchRunRow } from "~/services/dashboardAgentWatchChecks";
@@ -84,17 +84,18 @@ const { env } = await import("~/env.server");
8484

8585
// --- Fixtures ---------------------------------------------------------------
8686

87-
const AGENT_MIGRATIONS = [
88-
"0000_magenta_lilandra",
89-
"0001_slimy_living_tribunal",
90-
"0002_luxuriant_king_cobra",
91-
];
92-
93-
/** Apply the dashboard-agent schema by replaying its Drizzle migration SQL. */
87+
/**
88+
* Apply the dashboard-agent schema by replaying its Drizzle migration SQL —
89+
* every migration in the folder, in order, so a new migration can never leave
90+
* this suite running against a stale schema (a fixed list once did).
91+
*/
9492
async function applyAgentSchema(prisma: PrismaClient) {
9593
const folder = path.resolve(__dirname, "../../../internal-packages/dashboard-agent-db/drizzle");
96-
for (const name of AGENT_MIGRATIONS) {
97-
const sql = readFileSync(path.join(folder, `${name}.sql`), "utf8");
94+
const migrations = readdirSync(folder)
95+
.filter((file) => file.endsWith(".sql"))
96+
.sort();
97+
for (const name of migrations) {
98+
const sql = readFileSync(path.join(folder, name), "utf8");
9899
for (const statement of sql.split("--> statement-breakpoint")) {
99100
const trimmed = statement.trim();
100101
if (trimmed.length > 0) await prisma.$executeRawUnsafe(trimmed);
@@ -560,7 +561,11 @@ describe("the chat cascade and the list view", () => {
560561
const c = await create({ seeded, chatId: "chat_2" });
561562
expect(a.ok && b.ok && c.ok).toBe(true);
562563

563-
const byChat = await listActiveWatchesForChats(["chat_1", "chat_2", "chat_missing"]);
564+
const byChat = await listActiveWatchesForChats({
565+
chatIds: ["chat_1", "chat_2", "chat_missing"],
566+
organizationId: seeded.organization.id,
567+
userId: seeded.user.id,
568+
});
564569
expect(byChat.chat_1).toHaveLength(2);
565570
expect(byChat.chat_2).toHaveLength(1);
566571
expect(byChat.chat_missing).toBeUndefined();
@@ -573,13 +578,23 @@ describe("the chat cascade and the list view", () => {
573578

574579
// Terminal watches drop off the chips.
575580
await cancelWatchesForDeletedChat("chat_1");
576-
expect((await listActiveWatchesForChats(["chat_1"])).chat_1).toBeUndefined();
581+
expect(
582+
(
583+
await listActiveWatchesForChats({
584+
chatIds: ["chat_1"],
585+
organizationId: seeded.organization.id,
586+
userId: seeded.user.id,
587+
})
588+
).chat_1
589+
).toBeUndefined();
577590
}
578591
);
579592

580593
postgresTest("returns nothing for an empty chat list", async ({ prisma, postgresContainer }) => {
581594
await boot(prisma, postgresContainer.getConnectionUri());
582-
expect(await listActiveWatchesForChats([])).toEqual({});
595+
expect(
596+
await listActiveWatchesForChats({ chatIds: [], organizationId: "org_x", userId: "user_x" })
597+
).toEqual({});
583598
});
584599
});
585600

0 commit comments

Comments
 (0)