Skip to content

Commit 97b2fdd

Browse files
authored
Normalize Pi session URLs (#5)
1 parent e38767c commit 97b2fdd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pi/glance.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,23 @@ describe("pi/glance", () => {
190190

191191
const session = {
192192
id: "session-1",
193-
url: "https://glance.sh/s/session-1",
193+
url: "/s/session-1",
194194
} satisfies SessionResponse;
195195

196196
const fetchMock = vi.fn(async () => jsonResponse(session));
197197
vi.stubGlobal("fetch", fetchMock);
198198

199-
await expect(__testing.createSession()).resolves.toEqual(session);
199+
await expect(__testing.createSession()).resolves.toEqual({
200+
...session,
201+
url: "https://glance.sh/s/session-1",
202+
});
200203
expect(fetchMock).toHaveBeenCalledWith("https://glance.sh/api/session", {
201204
method: "POST",
202205
});
203-
expect(__testing.getState().currentSession).toEqual(session);
206+
expect(__testing.getState().currentSession).toEqual({
207+
...session,
208+
url: "https://glance.sh/s/session-1",
209+
});
204210
expect(__testing.isSessionStale()).toBe(false);
205211

206212
vi.setSystemTime(new Date("2026-03-07T15:08:00.001Z"));

pi/glance.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ interface GlanceDetails {
4646
expiresAt?: number;
4747
}
4848

49+
function normalizeSessionUrl(url: string): string {
50+
return new URL(url, BASE_URL).toString();
51+
}
52+
4953
// ── Persistent background session ──────────────────────────────────
5054

5155
let currentSession: SessionResponse | null = null;
@@ -57,6 +61,7 @@ async function createSession(): Promise<SessionResponse> {
5761
const res = await fetch(`${BASE_URL}/api/session`, { method: "POST" });
5862
if (!res.ok) throw new Error(`HTTP ${res.status}`);
5963
const session = (await res.json()) as SessionResponse;
64+
session.url = normalizeSessionUrl(session.url);
6065
currentSession = session;
6166
sessionCreatedAt = Date.now();
6267
return session;

0 commit comments

Comments
 (0)