Files
hermes-ui/tests/client/chat-store-reasoning-effort.test.ts
toor 1e9ea89d86
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
chore: bootstrap hermes-ui skeleton from 0.6.29 snapshot
Import the client, server, skills, tests, and build scripts as the starting
point for the rebuild, then trim the surfaces this project does not ship:
Electron desktop packaging, the marketing website, and the ESP32 firmware
tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows.

Rename the package and CLI entry points to hermes-ui, drop the prepare hook so
npm ci no longer triggers a build, and drop the removed tsconfig and nodemon
references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs
so the documented package map and hard rules match this repository.

reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
2026-10-16 10:34:35 +08:00

128 lines
3.9 KiB
TypeScript

// @vitest-environment jsdom
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
const chatApi = vi.hoisted(() => ({
registerSessionHandlers: vi.fn(),
unregisterSessionHandlers: vi.fn(),
getChatRunSocket: vi.fn(() => ({ emit: vi.fn() })),
}))
vi.mock('@/api/hermes/chat', () => ({
startRunViaSocket: vi.fn(),
resumeSession: vi.fn(),
registerSessionHandlers: chatApi.registerSessionHandlers,
unregisterSessionHandlers: chatApi.unregisterSessionHandlers,
getChatRunSocket: chatApi.getChatRunSocket,
respondToolApproval: vi.fn(),
respondClarify: vi.fn(),
onPeerUserMessage: vi.fn(() => vi.fn()),
onSessionCommand: vi.fn(() => vi.fn()),
onSessionTitleUpdated: vi.fn(() => vi.fn()),
onSessionWorkspaceUpdated: vi.fn(() => vi.fn()),
}))
vi.mock('@/api/client', () => ({
getActiveProfileName: () => 'default',
}))
vi.mock('@/api/hermes/sessions', () => ({
archiveSession: vi.fn(),
deleteSession: vi.fn(),
fetchSession: vi.fn(),
fetchSessions: vi.fn(),
fetchWorkspaceRunChangesForSession: vi.fn(async () => []),
fetchWorkspaceRunChangeFile: vi.fn(async () => null),
setSessionModel: vi.fn(),
}))
vi.mock('@/api/hermes/download', () => ({
getDownloadUrl: (_path: string, name: string) => `/download/${name}`,
}))
vi.mock('@/utils/completion-sound', () => ({
primeCompletionSound: vi.fn(),
playCompletionSound: vi.fn(),
}))
import { useChatStore, type Session } from '@/stores/hermes/chat'
function makeSession(id = 'session-1'): Session {
return {
id,
title: 'session',
messages: [],
createdAt: Date.now(),
updatedAt: Date.now(),
}
}
const LS_PREFIX = 'hermes:reasoning_effort:'
describe('chat store per-session reasoning effort', () => {
beforeEach(() => {
vi.resetAllMocks()
setActivePinia(createPinia())
localStorage.clear()
})
it('persists the chosen effort on the active session', () => {
const store = useChatStore()
const session = makeSession('s1')
store.sessions = [session]
store.setSessionReasoningEffort('s1', 'low')
expect(store.sessions[0].reasoningEffort).toBe('low')
expect(localStorage.getItem(LS_PREFIX + 's1')).toBe('low')
})
it('clears persistence when the value is empty', () => {
const store = useChatStore()
const session = makeSession('s2')
store.sessions = [session]
store.setSessionReasoningEffort('s2', 'high')
expect(localStorage.getItem(LS_PREFIX + 's2')).toBe('high')
store.setSessionReasoningEffort('s2', '')
expect(store.sessions[0].reasoningEffort).toBeUndefined()
expect(localStorage.getItem(LS_PREFIX + 's2')).toBeNull()
})
it('keeps each session independent', () => {
const store = useChatStore()
const a = makeSession('a')
const b = makeSession('b')
store.sessions = [a, b]
store.setSessionReasoningEffort('a', 'minimal')
store.setSessionReasoningEffort('b', 'high')
expect(store.sessions.find(s => s.id === 'a')?.reasoningEffort).toBe('minimal')
expect(store.sessions.find(s => s.id === 'b')?.reasoningEffort).toBe('high')
})
it('is a no-op when the session does not exist', () => {
const store = useChatStore()
store.sessions = [makeSession('only-one')]
expect(() => store.setSessionReasoningEffort('missing', 'high')).not.toThrow()
expect(store.sessions[0].reasoningEffort).toBeUndefined()
expect(localStorage.getItem(LS_PREFIX + 'missing')).toBeNull()
})
it('hydrates reasoningEffort from localStorage when sessions arrive without it', async () => {
localStorage.setItem(LS_PREFIX + 'rehydrated', 'medium')
const store = useChatStore()
// Simulate a fresh session list coming from the server (no reasoningEffort)
store.sessions = [makeSession('rehydrated')]
// The watcher fires asynchronously; flush microtasks
await new Promise(resolve => setTimeout(resolve, 0))
expect(store.sessions[0].reasoningEffort).toBe('medium')
})
})