fix profile-aware session history actions (#1011)

This commit is contained in:
ekko
2026-05-25 12:32:42 +08:00
committed by GitHub
parent bbb8b1d536
commit 56c6cf3e2d
7 changed files with 211 additions and 58 deletions
+29
View File
@@ -15,6 +15,7 @@ vi.mock('@/router', () => ({
import { getApiKey, setApiKey, clearApiKey, hasApiKey, getStoredUserRole, isStoredSuperAdmin, request } from '../../packages/client/src/api/client'
import { getDownloadUrl } from '../../packages/client/src/api/hermes/download'
import { uploadFiles } from '../../packages/client/src/api/hermes/files'
import { batchDeleteSessions } from '../../packages/client/src/api/hermes/sessions'
import router from '@/router'
function fakeJwt(payload: Record<string, unknown>) {
@@ -202,4 +203,32 @@ describe('API Client', () => {
expect(options.body).toBeInstanceOf(FormData)
})
})
describe('sessions API', () => {
it('sends profile-qualified targets for batch deletes', async () => {
localStorage.setItem('hermes_active_profile_name', 'research')
mockFetch.mockResolvedValue({
ok: true,
status: 200,
json: () => Promise.resolve({ deleted: 2, failed: 0, errors: [] }),
})
await batchDeleteSessions([
{ id: 'session-default', profile: 'default' },
{ id: 'session-travel', profile: 'travel' },
])
const [url, options] = mockFetch.mock.calls[0]
expect(url).toBe('/api/hermes/sessions/batch-delete')
expect(options.method).toBe('POST')
expect(options.headers['X-Hermes-Profile']).toBeUndefined()
expect(JSON.parse(options.body)).toEqual({
ids: ['session-default', 'session-travel'],
sessions: [
{ id: 'session-default', profile: 'default' },
{ id: 'session-travel', profile: 'travel' },
],
})
})
})
})