Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 17 additions & 34 deletions apps/webapp/test/chat-snapshot-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
// Plan F.3: integration test that round-trips a `ChatSnapshotV1` blob
// through the SDK's snapshot helpers + a real MinIO backing store. Mirrors
// the testcontainer pattern from `objectStore.test.ts`.
//
// What this verifies end-to-end:
// - SDK's `writeChatSnapshot` calls `apiClient.createUploadPayloadUrl`
// to mint a presigned PUT, then PUTs JSON to it.
// - SDK's `readChatSnapshot` calls `apiClient.getPayloadUrl` to mint a
// presigned GET, then fetches and parses.
// - The webapp's `generatePresignedUrl` produces URLs MinIO accepts.
// - The blob round-trips with `version: 1` shape preserved.
// - 404 (no snapshot for a fresh session) returns `undefined`, not an
// error.
//
// This is the integration safety net behind the unit tests in
// `packages/trigger-sdk/test/chat-snapshot.test.ts` — those tests mock
// `fetch`; this one drives a real S3-compatible backend.

import { postgresAndMinioTest } from "@internal/testcontainers";
import { apiClientManager } from "@trigger.dev/core/v3";
import { apiClientManager, type TranscriptSnapshotV2 } from "@trigger.dev/core/v3";
import {
__readChatSnapshotProductionPathForTests as readChatSnapshot,
__writeChatSnapshotProductionPathForTests as writeChatSnapshot,
type ChatSnapshotV1,
} from "@trigger.dev/sdk/ai";
import type { UIMessage } from "ai";
import { afterEach, describe, expect, vi } from "vitest";
Expand All @@ -35,22 +16,24 @@ vi.setConfig({ testTimeout: 60_000 });

function makeSnapshot(
opts: { messages?: UIMessage[]; lastOutEventId?: string } = {}
): ChatSnapshotV1 {
): TranscriptSnapshotV2 {
const messages = opts.messages ?? [
{
id: "u-1",
role: "user",
parts: [{ type: "text", text: "hello" }],
},
{
id: "a-1",
role: "assistant",
parts: [{ type: "text", text: "world" }],
},
];
return {
version: 1,
version: 2,
savedAt: 1_700_000_000_000,
messages: opts.messages ?? [
{
id: "u-1",
role: "user",
parts: [{ type: "text", text: "hello" }],
},
{
id: "a-1",
role: "assistant",
parts: [{ type: "text", text: "world" }],
},
],
messages: messages.map((message) => ({ id: message.id, final: true, message })),
state: null,
lastOutEventId: opts.lastOutEventId ?? "evt-42",
};
}
Expand Down
24 changes: 18 additions & 6 deletions apps/webapp/test/replay-after-crash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
// through it), even though the replay path itself doesn't read from S3.

import { postgresAndMinioTest } from "@internal/testcontainers";
import { apiClientManager } from "@trigger.dev/core/v3";
import { apiClientManager, type TranscriptSnapshotV2 } from "@trigger.dev/core/v3";
import {
__readChatSnapshotProductionPathForTests as readChatSnapshot,
__replaySessionOutTailProductionPathForTests as replaySessionOutTail,
type ChatSnapshotV1,
} from "@trigger.dev/sdk/ai";
import type { UIMessageChunk } from "ai";
import { afterEach, describe, expect, vi } from "vitest";
Expand Down Expand Up @@ -265,13 +264,26 @@ describe("replay after crash (MinIO + SDK helpers)", () => {

// Pre-write a snapshot to MinIO via real apiClient stub.
const sessionId = "sess_merge_round_trip";
const snapshot: ChatSnapshotV1 = {
version: 1,
const snapshot: TranscriptSnapshotV2 = {
version: 2,
savedAt: 1_700_000_000_000,
messages: [
{ id: "u-1", role: "user", parts: [{ type: "text", text: "hi" }] },
{ id: "a-1", role: "assistant", parts: [{ type: "text", text: "stale-assistant" }] },
{
id: "u-1",
final: true,
message: { id: "u-1", role: "user", parts: [{ type: "text", text: "hi" }] },
},
{
id: "a-1",
final: true,
message: {
id: "a-1",
role: "assistant",
parts: [{ type: "text", text: "stale-assistant" }],
},
},
],
state: null,
lastOutEventId: "evt-prev",
};

Expand Down
Loading
Loading