Skip to content
Merged
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
12 changes: 9 additions & 3 deletions pi/glance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,23 @@ describe("pi/glance", () => {

const session = {
id: "session-1",
url: "https://glance.sh/s/session-1",
url: "/s/session-1",
} satisfies SessionResponse;

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

await expect(__testing.createSession()).resolves.toEqual(session);
await expect(__testing.createSession()).resolves.toEqual({
...session,
url: "https://glance.sh/s/session-1",
});
expect(fetchMock).toHaveBeenCalledWith("https://glance.sh/api/session", {
method: "POST",
});
expect(__testing.getState().currentSession).toEqual(session);
expect(__testing.getState().currentSession).toEqual({
...session,
url: "https://glance.sh/s/session-1",
});
expect(__testing.isSessionStale()).toBe(false);

vi.setSystemTime(new Date("2026-03-07T15:08:00.001Z"));
Expand Down
5 changes: 5 additions & 0 deletions pi/glance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ interface GlanceDetails {
expiresAt?: number;
}

function normalizeSessionUrl(url: string): string {
return new URL(url, BASE_URL).toString();
}

// ── Persistent background session ──────────────────────────────────

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