Skip to content

Commit 97085d5

Browse files
committed
fix(webapp): isolate chat-snapshot key helper from db.server import chain
The integration tests for chat snapshot + replay-after-crash imported `chatSnapshotStoragePathForSession` from sessions.server.ts, which transitively pulls in `~/db.server` and constructs the singleton PrismaClient. In CI the testcontainer Postgres is on a random port, so the eager Prisma client throws `P1001: Can't reach database server at localhost:5432` as an unhandled rejection — tests pass but vitest exits non-zero. Extract the helper into its own `chatSnapshot.server.ts` module that only depends on env.server. Update the route, session create handler, and both integration tests to import from the new location. No behavior change.
1 parent fd5a7e2 commit 97085d5

6 files changed

Lines changed: 19 additions & 24 deletions

File tree

apps/webapp/app/routes/api.v1.sessions.$sessionId.snapshot-url.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { json } from "@remix-run/server-runtime";
22
import { z } from "zod";
33
import { $replica } from "~/db.server";
4-
import {
5-
chatSnapshotStoragePathForSession,
6-
resolveSessionByIdOrExternalId,
7-
} from "~/services/realtime/sessions.server";
4+
import { chatSnapshotStoragePathForSession } from "~/services/realtime/chatSnapshot.server";
5+
import { resolveSessionByIdOrExternalId } from "~/services/realtime/sessions.server";
86
import {
97
createActionApiRoute,
108
createLoaderApiRoute,

apps/webapp/app/routes/api.v1.sessions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import {
1717
ensureRunForSession,
1818
type SessionTriggerConfig,
1919
} from "~/services/realtime/sessionRunManager.server";
20-
import {
21-
chatSnapshotStoragePathForSession,
22-
serializeSession,
23-
} from "~/services/realtime/sessions.server";
20+
import { chatSnapshotStoragePathForSession } from "~/services/realtime/chatSnapshot.server";
21+
import { serializeSession } from "~/services/realtime/sessions.server";
2422
import { SessionsRepository } from "~/services/sessionsRepository/sessionsRepository.server";
2523
import {
2624
anyResource,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { env } from "~/env.server";
2+
3+
/**
4+
* Canonical storage URI for a session's chat.agent snapshot. Stamped on
5+
* `Session.chatSnapshotStoragePath` at row creation so PUT/GET presigns
6+
* resolve to the same store even if `OBJECT_STORE_DEFAULT_PROTOCOL`
7+
* changes later.
8+
*/
9+
export function chatSnapshotStoragePathForSession(friendlyId: string): string {
10+
const path = `sessions/${friendlyId}/snapshot.json`;
11+
const protocol = env.OBJECT_STORE_DEFAULT_PROTOCOL;
12+
return protocol ? `${protocol}://${path}` : path;
13+
}

apps/webapp/app/services/realtime/sessions.server.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
import type { PrismaClient, Session } from "@trigger.dev/database";
22
import type { SessionItem } from "@trigger.dev/core/v3";
33
import { $replica } from "~/db.server";
4-
import { env } from "~/env.server";
5-
6-
/**
7-
* Canonical storage URI for a session's chat.agent snapshot. Stamped on
8-
* `Session.chatSnapshotStoragePath` at row creation so PUT/GET presigns
9-
* resolve to the same store even if `OBJECT_STORE_DEFAULT_PROTOCOL`
10-
* changes later. The protocol prefix (when set) is what makes
11-
* generic-packets PUT and GET agree on the target provider.
12-
*/
13-
export function chatSnapshotStoragePathForSession(friendlyId: string): string {
14-
const path = `sessions/${friendlyId}/snapshot.json`;
15-
const protocol = env.OBJECT_STORE_DEFAULT_PROTOCOL;
16-
return protocol ? `${protocol}://${path}` : path;
17-
}
184

195
/**
206
* Prefix that {@link SessionId.generate} attaches to every Session friendlyId.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +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";
29+
import { chatSnapshotStoragePathForSession } from "~/services/realtime/chatSnapshot.server";
3030
import { generatePresignedUrl } from "~/v3/objectStore.server";
3131

3232
vi.setConfig({ testTimeout: 60_000 });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +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";
36+
import { chatSnapshotStoragePathForSession } from "~/services/realtime/chatSnapshot.server";
3737
import { generatePresignedUrl } from "~/v3/objectStore.server";
3838

3939
vi.setConfig({ testTimeout: 60_000 });

0 commit comments

Comments
 (0)