From bb5a6fb83b972c3d4d92f042dbc7fd36d3015546 Mon Sep 17 00:00:00 2001 From: Isaac Sanchez-Hawkins <266845420+isanchez404@users.noreply.github.com> Date: Tue, 12 May 2026 04:05:54 -0400 Subject: [PATCH] fix(sessions): update changed share URLs (#1184) Co-authored-by: Isaac Sanchez --- .../src/stores/useGlobalSessionsStore.test.ts | 30 +++++++++++++++++++ .../ui/src/stores/useGlobalSessionsStore.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 packages/ui/src/stores/useGlobalSessionsStore.test.ts diff --git a/packages/ui/src/stores/useGlobalSessionsStore.test.ts b/packages/ui/src/stores/useGlobalSessionsStore.test.ts new file mode 100644 index 00000000..ee1696e0 --- /dev/null +++ b/packages/ui/src/stores/useGlobalSessionsStore.test.ts @@ -0,0 +1,30 @@ +import { beforeEach, describe, expect, test } from 'bun:test'; +import type { Session } from '@opencode-ai/sdk/v2'; + +import { useGlobalSessionsStore } from './useGlobalSessionsStore'; + +const buildSession = (shareUrl: string): Session => ({ + id: 'ses_1', + title: 'Shared session', + time: { created: 1, updated: 2 }, + share: { url: shareUrl }, +} as Session); + +describe('useGlobalSessionsStore', () => { + beforeEach(() => { + useGlobalSessionsStore.setState({ + activeSessions: [], + archivedSessions: [], + sessionsByDirectory: new Map(), + hasLoaded: false, + status: 'idle', + }); + }); + + test('updates an existing session when the share URL changes', () => { + useGlobalSessionsStore.getState().upsertSession(buildSession('https://share.example/a')); + useGlobalSessionsStore.getState().upsertSession(buildSession('https://share.example/b')); + + expect(useGlobalSessionsStore.getState().activeSessions[0]?.share?.url).toBe('https://share.example/b'); + }); +}); diff --git a/packages/ui/src/stores/useGlobalSessionsStore.ts b/packages/ui/src/stores/useGlobalSessionsStore.ts index 9dbd1d6d..21b313fe 100644 --- a/packages/ui/src/stores/useGlobalSessionsStore.ts +++ b/packages/ui/src/stores/useGlobalSessionsStore.ts @@ -76,7 +76,7 @@ const getSessionSignature = (session: Session): string => { session.time?.created ?? 0, session.time?.updated ?? 0, session.time?.archived ?? 0, - session.share ? 1 : 0, + session.share?.url ?? '', resolveGlobalSessionDirectory(session) ?? '', ].join(':'); };