@@ -26,6 +26,7 @@ import {
2626import type { UIMessage } from "ai" ;
2727import { afterEach , describe , expect , vi } from "vitest" ;
2828import { env } from "~/env.server" ;
29+ import { chatSnapshotStoragePathForSession } from "~/services/realtime/chatSnapshot.server" ;
2930import { generatePresignedUrl } from "~/v3/objectStore.server" ;
3031
3132vi . 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 */
6462function 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 } ,
0 commit comments