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(':'); };