hermes-agent/apps/desktop/src/lib/session-ids.test.ts
xxxigm 069011dd0c test(desktop): cover runtime->stored notification id resolution
Unit-test `storedSessionIdForNotification`: runtime ids resolve to their
stored id, unknown ids and empty maps pass through unchanged, the right
stored id is picked among several sessions, and stored ids (map keys) are
never rewritten.
2026-06-19 17:50:35 +05:30

44 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { storedSessionIdForNotification } from './session-ids'
describe('storedSessionIdForNotification', () => {
it('translates a runtime id back to its stored id', () => {
// The route is keyed by the stored id, but notifications carry the runtime
// id. Resolving runtime -> stored keeps notification-click navigation from
// resuming a non-existent stored session ("session not found").
const map = new Map([['stored-abc', 'runtime-123']])
expect(storedSessionIdForNotification('runtime-123', map)).toBe('stored-abc')
})
it('returns the id unchanged when no mapping is known', () => {
// A notification for a session this window never opened may already carry a
// stored id; let the resume/REST lookup handle it as-is.
const map = new Map([['stored-abc', 'runtime-123']])
expect(storedSessionIdForNotification('stored-xyz', map)).toBe('stored-xyz')
})
it('returns the id unchanged for an empty map', () => {
expect(storedSessionIdForNotification('runtime-123', new Map())).toBe('runtime-123')
})
it('resolves the correct stored id among several sessions', () => {
const map = new Map([
['stored-1', 'runtime-1'],
['stored-2', 'runtime-2'],
['stored-3', 'runtime-3']
])
expect(storedSessionIdForNotification('runtime-2', map)).toBe('stored-2')
})
it('does not treat a stored id as a runtime id (keys are not matched)', () => {
// The map is stored -> runtime. A value that only appears as a *key* must
// not be rewritten, otherwise an already-stored id could be mangled.
const map = new Map([['stored-1', 'runtime-1']])
expect(storedSessionIdForNotification('stored-1', map)).toBe('stored-1')
})
})