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.
163 lines
5.1 KiB
TypeScript
163 lines
5.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
const mockSettingsStore = vi.hoisted(() => ({
|
|
sessionReset: { mode: 'both', idle_minutes: 60, at_hour: 0 },
|
|
approvals: { mode: 'manual' },
|
|
memory: { write_approval: false },
|
|
skills: { write_approval: true },
|
|
updateLocal: vi.fn((section: string, values: Record<string, any>) => {
|
|
Object.assign((mockSettingsStore as any)[section], values)
|
|
}),
|
|
saveSection: vi.fn(),
|
|
}))
|
|
|
|
const mockPrefsStore = vi.hoisted(() => ({
|
|
humanOnly: true,
|
|
setHumanOnly: vi.fn((value: boolean) => {
|
|
mockPrefsStore.humanOnly = value
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@/stores/hermes/settings', () => ({
|
|
useSettingsStore: () => mockSettingsStore,
|
|
}))
|
|
|
|
vi.mock('@/stores/hermes/session-browser-prefs', () => ({
|
|
useSessionBrowserPrefsStore: () => mockPrefsStore,
|
|
}))
|
|
|
|
vi.mock('vue-i18n', () => ({
|
|
useI18n: () => ({
|
|
t: (key: string) => key,
|
|
}),
|
|
}))
|
|
|
|
vi.mock('naive-ui', async () => {
|
|
const actual = await vi.importActual<any>('naive-ui')
|
|
return {
|
|
...actual,
|
|
useMessage: () => ({
|
|
success: vi.fn(),
|
|
error: vi.fn(),
|
|
}),
|
|
}
|
|
})
|
|
|
|
import SessionSettings from '@/components/hermes/settings/SessionSettings.vue'
|
|
|
|
describe('SessionSettings', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockPrefsStore.humanOnly = true
|
|
mockSettingsStore.memory.write_approval = false
|
|
mockSettingsStore.skills.write_approval = true
|
|
})
|
|
|
|
it('surfaces the human-only preference in the Session tab', async () => {
|
|
let emittedValue: boolean | undefined
|
|
const wrapper = mount(SessionSettings, {
|
|
global: {
|
|
stubs: {
|
|
SettingRow: {
|
|
props: ['label', 'hint'],
|
|
template: '<div class="setting-row"><div class="setting-row-label">{{ label }}</div><slot /></div>',
|
|
},
|
|
NSelect: true,
|
|
NInputNumber: true,
|
|
NButton: { template: '<button><slot /></button>' },
|
|
NTag: { template: '<span><slot /></span>' },
|
|
NSwitch: {
|
|
props: ['value'],
|
|
emits: ['update:value'],
|
|
template: '<div class="n-switch" @click="$emit(\'update:value\', !value)"></div>',
|
|
setup(props: any, { emit }: any) {
|
|
return {
|
|
onClick: () => {
|
|
emittedValue = !props.value
|
|
emit('update:value', emittedValue)
|
|
},
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
await flushPromises()
|
|
|
|
expect(wrapper.text()).toContain('settings.session.liveMonitorHumanOnly')
|
|
|
|
const toggles = wrapper.findAll('.n-switch')
|
|
expect(toggles.length).toBe(4)
|
|
const humanOnlyToggle = toggles[3]
|
|
|
|
await humanOnlyToggle.trigger('click')
|
|
await Promise.resolve()
|
|
|
|
expect(mockPrefsStore.setHumanOnly).toHaveBeenCalledWith(false)
|
|
})
|
|
|
|
it('saves write approval toggles to memory and skills config sections', async () => {
|
|
const wrapper = mount(SessionSettings, {
|
|
global: {
|
|
stubs: {
|
|
SettingRow: {
|
|
props: ['label', 'hint'],
|
|
template: '<div class="setting-row"><div class="setting-row-label">{{ label }}</div><slot /></div>',
|
|
},
|
|
NSelect: true,
|
|
NInputNumber: true,
|
|
NButton: { template: '<button><slot /></button>' },
|
|
NTag: { template: '<span><slot /></span>' },
|
|
NSwitch: {
|
|
props: ['value'],
|
|
emits: ['update:value'],
|
|
template: '<button class="n-switch" @click="$emit(\'update:value\', !value)"></button>',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
await flushPromises()
|
|
|
|
expect(wrapper.text()).toContain('settings.session.memoryWriteApproval')
|
|
expect(wrapper.text()).toContain('settings.session.skillsWriteApproval')
|
|
|
|
const toggles = wrapper.findAll('.n-switch')
|
|
await toggles[1].trigger('click')
|
|
await Promise.resolve()
|
|
await toggles[2].trigger('click')
|
|
await Promise.resolve()
|
|
|
|
expect(mockSettingsStore.updateLocal).toHaveBeenCalledWith('memory', { write_approval: true })
|
|
expect(mockSettingsStore.saveSection).toHaveBeenCalledWith('memory', { write_approval: true })
|
|
expect(mockSettingsStore.updateLocal).toHaveBeenCalledWith('skills', { write_approval: false })
|
|
expect(mockSettingsStore.saveSection).toHaveBeenCalledWith('skills', { write_approval: false })
|
|
})
|
|
|
|
it('shows write approval toggles without probing Hermes Agent support', async () => {
|
|
const wrapper = mount(SessionSettings, {
|
|
global: {
|
|
stubs: {
|
|
SettingRow: {
|
|
props: ['label', 'hint'],
|
|
template: '<div class="setting-row"><div class="setting-row-label">{{ label }}</div><slot /></div>',
|
|
},
|
|
NSelect: true,
|
|
NInputNumber: true,
|
|
NSwitch: {
|
|
props: ['value'],
|
|
emits: ['update:value'],
|
|
template: '<button class="n-switch" @click="$emit(\'update:value\', !value)"></button>',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
await flushPromises()
|
|
|
|
expect(wrapper.text()).toContain('settings.session.memoryWriteApproval')
|
|
expect(wrapper.text()).toContain('settings.session.skillsWriteApproval')
|
|
})
|
|
})
|