Skip to content

Commit fd5a7e2

Browse files
committed
test(webapp): update chat snapshot integration stubs for new apiClient methods
The chat-snapshot-integration and replay-after-crash MinIO integration tests stubbed the old `getPayloadUrl` / `createUploadPayloadUrl` methods on the apiClient. The SDK now calls `getChatSnapshotUrl` / `createChatSnapshotUploadUrl`, so the stubs return undefined and every test in those two files fails. Update the stubs to mirror the new snapshot-url route — derive the canonical key via the shared `chatSnapshotStoragePathForSession` helper and presign through it.
1 parent b589739 commit fd5a7e2

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

apps/webapp/test/chat-snapshot-integration.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import type { UIMessage } from "ai";
2727
import { afterEach, describe, expect, vi } from "vitest";
2828
import { env } from "~/env.server";
29+
import { chatSnapshotStoragePathForSession } from "~/services/realtime/sessions.server";
2930
import { generatePresignedUrl } from "~/v3/objectStore.server";
3031

3132
vi.setConfig({ testTimeout: 60_000 });
@@ -54,22 +55,21 @@ function makeSnapshot(opts: { messages?: UIMessage[]; lastOutEventId?: string }
5455

5556
/**
5657
* Stub `apiClientManager.clientOrThrow()` so the SDK helpers see a fake
57-
* api client whose `getPayloadUrl` / `createUploadPayloadUrl` return
58-
* presigned URLs minted by the webapp's real `generatePresignedUrl`
59-
* (which signs against MinIO).
60-
*
61-
* The SDK helpers internally do `fetch(presignedUrl, ...)` to read/write
62-
* the blob, so MinIO ends up holding the actual bytes.
58+
* api client. Mirrors the snapshot-url route: derive the canonical
59+
* `sessions/{id}/snapshot.json` key (with optional default-protocol
60+
* prefix) and sign it via `generatePresignedUrl` against MinIO.
6361
*/
6462
function stubApiClient(opts: { projectRef: string; envSlug: string }) {
6563
vi.spyOn(apiClientManager, "clientOrThrow").mockReturnValue({
66-
async getPayloadUrl(filename: string) {
67-
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, filename, "GET");
64+
async getChatSnapshotUrl(sessionId: string) {
65+
const key = chatSnapshotStoragePathForSession(sessionId);
66+
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, key, "GET");
6867
if (!result.success) throw new Error(result.error);
6968
return { presignedUrl: result.url };
7069
},
71-
async createUploadPayloadUrl(filename: string) {
72-
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, filename, "PUT");
70+
async createChatSnapshotUploadUrl(sessionId: string) {
71+
const key = chatSnapshotStoragePathForSession(sessionId);
72+
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, key, "PUT");
7373
if (!result.success) throw new Error(result.error);
7474
return { presignedUrl: result.url };
7575
},

apps/webapp/test/replay-after-crash.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import type { UIMessageChunk } from "ai";
3434
import { afterEach, describe, expect, vi } from "vitest";
3535
import { env } from "~/env.server";
36+
import { chatSnapshotStoragePathForSession } from "~/services/realtime/sessions.server";
3637
import { generatePresignedUrl } from "~/v3/objectStore.server";
3738

3839
vi.setConfig({ testTimeout: 60_000 });
@@ -77,13 +78,15 @@ function stubApiClient(opts: {
7778
})
7879
);
7980
vi.spyOn(apiClientManager, "clientOrThrow").mockReturnValue({
80-
async getPayloadUrl(filename: string) {
81-
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, filename, "GET");
81+
async getChatSnapshotUrl(sessionId: string) {
82+
const key = chatSnapshotStoragePathForSession(sessionId);
83+
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, key, "GET");
8284
if (!result.success) throw new Error(result.error);
8385
return { presignedUrl: result.url };
8486
},
85-
async createUploadPayloadUrl(filename: string) {
86-
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, filename, "PUT");
87+
async createChatSnapshotUploadUrl(sessionId: string) {
88+
const key = chatSnapshotStoragePathForSession(sessionId);
89+
const result = await generatePresignedUrl(opts.projectRef, opts.envSlug, key, "PUT");
8790
if (!result.success) throw new Error(result.error);
8891
return { presignedUrl: result.url };
8992
},

0 commit comments

Comments
 (0)