Skip to content

Commit 9096816

Browse files
committed
test(webapp): strengthen split suite assertions
1 parent b9f314e commit 9096816

5 files changed

Lines changed: 86 additions & 32 deletions

apps/webapp/test/apiRunListPresenter.readthrough.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ vi.mock("~/db.server", async () => {
4747

4848
import { createPostgresContainer, replicationContainerTest } from "@internal/testcontainers";
4949
import { PrismaClient } from "@trigger.dev/database";
50-
import { setTimeout } from "node:timers/promises";
50+
import { z } from "zod";
5151
import { CURRENT_API_VERSION } from "~/api/versions";
5252
import { ApiRunListPresenter } from "~/presenters/v3/ApiRunListPresenter.server";
5353
import { createRun, mirrorParents, seedParents } from "./helpers/apiRunListPresenterTestHelpers";
@@ -102,7 +102,23 @@ describe("ApiRunListPresenter public /runs routed read-through", () => {
102102
data: { id: migratedB.id },
103103
});
104104

105-
await setTimeout(1500);
105+
const replicatedRunsQuery = clickhouse.reader.query({
106+
name: "waitForApiRunListPresenterTaskRuns",
107+
query:
108+
"SELECT countDistinct(run_id) AS count FROM trigger_dev.task_runs_v2 WHERE run_id IN {run_ids:Array(String)}",
109+
schema: z.object({ count: z.number() }),
110+
params: z.object({ run_ids: z.array(z.string()) }),
111+
});
112+
await vi.waitFor(
113+
async () => {
114+
const [error, rows] = await replicatedRunsQuery({
115+
run_ids: [legacyOnlyA.id, legacyOnlyB.id, migratedA.id, migratedB.id],
116+
});
117+
if (error) throw error;
118+
expect(rows?.[0]?.count).toBe(4);
119+
},
120+
{ timeout: 15_000, interval: 100 }
121+
);
106122

107123
const presenter = new ApiRunListPresenter(prisma, prisma, {
108124
newClient: prismaNew,

apps/webapp/test/dashboardAgentWatches.delivery.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,13 @@ describe("the watch card submit", () => {
895895

896896
// The crash state: the request record is written and the watch is live, but the
897897
// process died before the confirmation was appended.
898-
await appendChatMessageOnce(ctx.agentDb, {
898+
const requestAppended = await appendChatMessageOnce(ctx.agentDb, {
899899
chatId: "chat_1",
900900
userId: seeded.user.id,
901+
organizationId: seeded.organization.id,
901902
message: { id: "watch-request:wreq_1", role: "user", parts: [] } as never,
902903
});
904+
expect(requestAppended).toBe(true);
903905
const created = await create({ seeded, chatId: "chat_1" });
904906
expect(created.ok).toBe(true);
905907
if (!created.ok || !created.watching) return;

apps/webapp/test/dashboardAgentWatches.lifecycle.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ describe("the check endpoint", () => {
862862
async function activeWatch(seeded: Seeded, spec?: WatchSpec) {
863863
const result = await create({ seeded, spec });
864864
if (!result.ok) throw new Error(`watch not created: ${result.code}`);
865+
if (!result.watching) throw new Error("expected an active watch");
865866
return result;
866867
}
867868

apps/webapp/test/engine/triggerTask.externalDeploymentId.helpers.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,53 @@ import {
1717

1818
export class RecordingExternalDeploymentCache implements ExternalDeploymentCache {
1919
readonly gets: Array<{ environmentId: string; externalId: string }> = [];
20-
readonly writes: Array<{ externalId: string; entry: ExternalDeploymentCacheEntry }> = [];
20+
readonly writes: Array<{
21+
environmentId: string;
22+
externalId: string;
23+
entry: ExternalDeploymentCacheEntry;
24+
}> = [];
25+
readonly missing: Array<{ environmentId: string; externalId: string }> = [];
26+
private readonly entries = new Map<string, ExternalDeploymentCacheEntry>();
2127

22-
constructor(private readonly entries = new Map<string, ExternalDeploymentCacheEntry>()) {}
23-
24-
readonly missing: string[] = [];
28+
constructor(
29+
entries: Array<{
30+
environmentId: string;
31+
externalId: string;
32+
entry: ExternalDeploymentCacheEntry;
33+
}> = []
34+
) {
35+
for (const { environmentId, externalId, entry } of entries) {
36+
this.entries.set(this.key(environmentId, externalId), entry);
37+
}
38+
}
2539

2640
async get(environmentId: string, externalId: string) {
2741
this.gets.push({ environmentId, externalId });
2842

29-
const entry = this.entries.get(externalId);
43+
const entry = this.entries.get(this.key(environmentId, externalId));
3044

3145
if (entry) {
3246
return { outcome: "deployed" as const, entry };
3347
}
3448

35-
return this.missing.includes(externalId) ? { outcome: "missing" as const } : null;
49+
return this.missing.some(
50+
(missing) => missing.environmentId === environmentId && missing.externalId === externalId
51+
)
52+
? { outcome: "missing" as const }
53+
: null;
3654
}
3755

38-
async setIfNewer(
39-
_environmentId: string,
40-
externalId: string,
41-
entry: ExternalDeploymentCacheEntry
42-
) {
43-
this.writes.push({ externalId, entry });
44-
this.entries.set(externalId, entry);
56+
async setIfNewer(environmentId: string, externalId: string, entry: ExternalDeploymentCacheEntry) {
57+
this.writes.push({ environmentId, externalId, entry });
58+
this.entries.set(this.key(environmentId, externalId), entry);
59+
}
60+
61+
async setMissing(environmentId: string, externalId: string) {
62+
this.missing.push({ environmentId, externalId });
4563
}
4664

47-
async setMissing(_environmentId: string, externalId: string) {
48-
this.missing.push(externalId);
65+
private key(environmentId: string, externalId: string) {
66+
return JSON.stringify([environmentId, externalId]);
4967
}
5068
}
5169

apps/webapp/test/engine/triggerTask.externalDeploymentId.resolution.test.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ describe("triggerTask external deployment id", () => {
4040

4141
const worker = await setupBackgroundWorker(engine, environment, taskIdentifier);
4242

43-
const cache = new RecordingExternalDeploymentCache(
44-
new Map([
45-
[
46-
"commit-cached",
47-
{
48-
workerId: worker.worker.id,
49-
version: worker.worker.version,
50-
sdkVersion: "",
51-
cliVersion: "",
52-
},
53-
],
54-
])
55-
);
43+
const cache = new RecordingExternalDeploymentCache([
44+
{
45+
environmentId: environment.id,
46+
externalId: "commit-cached",
47+
entry: {
48+
workerId: worker.worker.id,
49+
version: worker.worker.version,
50+
sdkVersion: "",
51+
cliVersion: "",
52+
},
53+
},
54+
]);
5655

5756
const service = createService(prisma, engine, cache);
5857

@@ -163,7 +162,19 @@ describe("triggerTask external deployment id", () => {
163162
},
164163
});
165164

166-
const service = createService(prisma, engine, new NoopExternalDeploymentCache());
165+
const cache = new RecordingExternalDeploymentCache([
166+
{
167+
environmentId: otherEnvironment.id,
168+
externalId: "commit-elsewhere",
169+
entry: {
170+
workerId: worker.worker.id,
171+
version: worker.worker.version,
172+
sdkVersion: "",
173+
cliVersion: "",
174+
},
175+
},
176+
]);
177+
const service = createService(prisma, engine, cache);
167178

168179
const result = await service.call({
169180
taskId: taskIdentifier,
@@ -177,6 +188,12 @@ describe("triggerTask external deployment id", () => {
177188

178189
expect(run.status).toBe("PENDING_VERSION");
179190
expect(run.lockedToVersionId).toBeNull();
191+
expect(cache.gets).toEqual([
192+
{ environmentId: environment.id, externalId: "commit-elsewhere" },
193+
]);
194+
expect(cache.missing).toEqual([
195+
{ environmentId: environment.id, externalId: "commit-elsewhere" },
196+
]);
180197
}
181198
);
182199
});

0 commit comments

Comments
 (0)