fix: resolve test failures related to v0.5.12 changes (#491)
* fix: update tests for new batch delete and update mechanism changes **sessions-routes.test.ts:** - Add missing batchRemove mock to controller mock - Fix "No batchRemove export defined" error **update-controller.test.ts:** - Update test to expect direct npm/npm.cmd calls instead of dirname(process.execPath) - Update timeout from 120000 to 10 * 60 * 1000 (10 minutes) - Update spawn path check to use dynamic global prefix (expect.any) Tests now match the refactored update mechanism that uses npm prefix -g for reliable path resolution. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test: add speechSynthesis mock to message-item-highlight tests * test: fix all failing tests - Add approvals mock to session-settings test - Fix NSwitch stub to properly emit events - Update usage stats test expectations for new field structure - Mock getDb in model-context tests to avoid database lock errors - Add speechSynthesis API mock to message-item-highlight tests Related to v0.5.12 feature changes --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,18 @@ describe('MessageItem tool details', () => {
|
|||||||
writeText: vi.fn().mockResolvedValue(undefined),
|
writeText: vi.fn().mockResolvedValue(undefined),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Object.defineProperty(window, 'speechSynthesis', {
|
||||||
|
configurable: true,
|
||||||
|
value: {
|
||||||
|
addEventListener: vi.fn(),
|
||||||
|
removeEventListener: vi.fn(),
|
||||||
|
getVoices: vi.fn(() => []),
|
||||||
|
speak: vi.fn(),
|
||||||
|
cancel: vi.fn(),
|
||||||
|
pause: vi.fn(),
|
||||||
|
resume: vi.fn(),
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders highlighted code blocks for tool arguments and tool results', async () => {
|
it('renders highlighted code blocks for tool arguments and tool results', async () => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { mount } from '@vue/test-utils'
|
|||||||
|
|
||||||
const mockSettingsStore = vi.hoisted(() => ({
|
const mockSettingsStore = vi.hoisted(() => ({
|
||||||
sessionReset: { mode: 'both', idle_minutes: 60, at_hour: 0 },
|
sessionReset: { mode: 'both', idle_minutes: 60, at_hour: 0 },
|
||||||
|
approvals: { mode: 'manual' },
|
||||||
saveSection: vi.fn(),
|
saveSection: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ describe('SessionSettings', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('surfaces the human-only preference in the Session tab', async () => {
|
it('surfaces the human-only preference in the Session tab', async () => {
|
||||||
|
let emittedValue: boolean | undefined
|
||||||
const wrapper = mount(SessionSettings, {
|
const wrapper = mount(SessionSettings, {
|
||||||
global: {
|
global: {
|
||||||
stubs: {
|
stubs: {
|
||||||
@@ -57,16 +59,30 @@ describe('SessionSettings', () => {
|
|||||||
},
|
},
|
||||||
NSelect: true,
|
NSelect: true,
|
||||||
NInputNumber: true,
|
NInputNumber: true,
|
||||||
|
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)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.text()).toContain('settings.session.liveMonitorHumanOnly')
|
expect(wrapper.text()).toContain('settings.session.liveMonitorHumanOnly')
|
||||||
|
|
||||||
const toggle = wrapper.find('.n-switch')
|
const toggles = wrapper.findAll('.n-switch')
|
||||||
expect(toggle.exists()).toBe(true)
|
expect(toggles.length).toBe(2)
|
||||||
|
const humanOnlyToggle = toggles[1]
|
||||||
|
|
||||||
await toggle.trigger('click')
|
await humanOnlyToggle.trigger('click')
|
||||||
await Promise.resolve()
|
await Promise.resolve()
|
||||||
|
|
||||||
expect(mockPrefsStore.setHumanOnly).toHaveBeenCalledWith(false)
|
expect(mockPrefsStore.setHumanOnly).toHaveBeenCalledWith(false)
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ async function loadModelContext() {
|
|||||||
...(await vi.importActual<typeof import('os')>('os')),
|
...(await vi.importActual<typeof import('os')>('os')),
|
||||||
homedir: () => homeDir,
|
homedir: () => homeDir,
|
||||||
}))
|
}))
|
||||||
|
// Mock getDb to return null to avoid "database is locked" errors in parallel tests
|
||||||
|
vi.doMock('../../packages/server/src/db/index', async () => {
|
||||||
|
const actual = await vi.importActual<typeof import('../../packages/server/src/db/index')>('../../packages/server/src/db/index')
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
getDb: () => null,
|
||||||
|
}
|
||||||
|
})
|
||||||
return import('../../packages/server/src/services/hermes/model-context')
|
return import('../../packages/server/src/services/hermes/model-context')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ describe('session conversations controller', () => {
|
|||||||
{ model: 'local-model', input_tokens: 10, output_tokens: 5, cache_read_tokens: 2, cache_write_tokens: 1, reasoning_tokens: 3, sessions: 1 },
|
{ model: 'local-model', input_tokens: 10, output_tokens: 5, cache_read_tokens: 2, cache_write_tokens: 1, reasoning_tokens: 3, sessions: 1 },
|
||||||
],
|
],
|
||||||
by_day: [
|
by_day: [
|
||||||
{ date: today, tokens: 15, cache: 2, sessions: 1, cost: 0 },
|
{ date: today, input_tokens: 10, output_tokens: 5, cache_read_tokens: 2, cache_write_tokens: 1, sessions: 1, errors: 0, cost: 0 },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
getUsageStatsFromDbMock.mockResolvedValue({
|
getUsageStatsFromDbMock.mockResolvedValue({
|
||||||
@@ -164,7 +164,7 @@ describe('session conversations controller', () => {
|
|||||||
{ model: 'hermes-model', input_tokens: 20, output_tokens: 10, cache_read_tokens: 4, cache_write_tokens: 2, reasoning_tokens: 6, sessions: 2 },
|
{ model: 'hermes-model', input_tokens: 20, output_tokens: 10, cache_read_tokens: 4, cache_write_tokens: 2, reasoning_tokens: 6, sessions: 2 },
|
||||||
],
|
],
|
||||||
by_day: [
|
by_day: [
|
||||||
{ date: today, tokens: 30, cache: 4, sessions: 2, cost: 0.02 },
|
{ date: today, input_tokens: 20, output_tokens: 10, cache_read_tokens: 4, cache_write_tokens: 2, sessions: 2, errors: 0, cost: 0.02 },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -189,6 +189,13 @@ describe('session conversations controller', () => {
|
|||||||
{ model: 'hermes-model', input_tokens: 20, output_tokens: 10, cache_read_tokens: 4, cache_write_tokens: 2, reasoning_tokens: 6, sessions: 2 },
|
{ model: 'hermes-model', input_tokens: 20, output_tokens: 10, cache_read_tokens: 4, cache_write_tokens: 2, reasoning_tokens: 6, sessions: 2 },
|
||||||
{ model: 'local-model', input_tokens: 10, output_tokens: 5, cache_read_tokens: 2, cache_write_tokens: 1, reasoning_tokens: 3, sessions: 1 },
|
{ model: 'local-model', input_tokens: 10, output_tokens: 5, cache_read_tokens: 2, cache_write_tokens: 1, reasoning_tokens: 3, sessions: 1 },
|
||||||
])
|
])
|
||||||
expect(ctx.body.daily_usage.find((row: any) => row.date === today)).toMatchObject({ tokens: 45, cache: 6, sessions: 3, cost: 0.02 })
|
expect(ctx.body.daily_usage.find((row: any) => row.date === today)).toMatchObject({
|
||||||
|
input_tokens: 30,
|
||||||
|
output_tokens: 15,
|
||||||
|
cache_read_tokens: 6,
|
||||||
|
cache_write_tokens: 3,
|
||||||
|
sessions: 3,
|
||||||
|
cost: 0.02,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const usageBatchMock = vi.fn(async (ctx: any) => { ctx.body = {} })
|
|||||||
const usageSingleMock = vi.fn(async (ctx: any) => { ctx.body = { input_tokens: 0, output_tokens: 0 } })
|
const usageSingleMock = vi.fn(async (ctx: any) => { ctx.body = { input_tokens: 0, output_tokens: 0 } })
|
||||||
const usageStatsMock = vi.fn(async (ctx: any) => { ctx.body = { total_input_tokens: 0, total_output_tokens: 0 } })
|
const usageStatsMock = vi.fn(async (ctx: any) => { ctx.body = { total_input_tokens: 0, total_output_tokens: 0 } })
|
||||||
const contextLengthMock = vi.fn(async (ctx: any) => { ctx.body = { context_length: 200000 } })
|
const contextLengthMock = vi.fn(async (ctx: any) => { ctx.body = { context_length: 200000 } })
|
||||||
|
const batchRemoveMock = vi.fn(async (ctx: any) => { ctx.body = { deleted: 1, failed: 0, errors: [] } })
|
||||||
|
|
||||||
vi.mock('../../packages/server/src/controllers/hermes/sessions', () => ({
|
vi.mock('../../packages/server/src/controllers/hermes/sessions', () => ({
|
||||||
listConversations: listConversationsMock,
|
listConversations: listConversationsMock,
|
||||||
@@ -27,6 +28,7 @@ vi.mock('../../packages/server/src/controllers/hermes/sessions', () => ({
|
|||||||
search: searchMock,
|
search: searchMock,
|
||||||
get: getMock,
|
get: getMock,
|
||||||
remove: removeMock,
|
remove: removeMock,
|
||||||
|
batchRemove: batchRemoveMock,
|
||||||
rename: renameMock,
|
rename: renameMock,
|
||||||
setWorkspace: setWorkspaceMock,
|
setWorkspace: setWorkspaceMock,
|
||||||
listWorkspaceFolders: listWorkspaceFoldersMock,
|
listWorkspaceFolders: listWorkspaceFoldersMock,
|
||||||
|
|||||||
@@ -47,20 +47,19 @@ describe('update controller', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates using npm from the active node prefix and restarts via the same cli path', async () => {
|
it('updates using npm from PATH and restarts via global prefix', async () => {
|
||||||
process.env.PORT = '9129'
|
process.env.PORT = '9129'
|
||||||
const { handleUpdate, mocks } = await loadUpdateController()
|
const { handleUpdate, mocks } = await loadUpdateController()
|
||||||
const ctx = createMockCtx()
|
const ctx = createMockCtx()
|
||||||
const nodeBinDir = dirname(process.execPath)
|
|
||||||
|
|
||||||
await handleUpdate(ctx)
|
await handleUpdate(ctx)
|
||||||
|
|
||||||
expect(mocks.execFileSync).toHaveBeenCalledWith(
|
expect(mocks.execFileSync).toHaveBeenCalledWith(
|
||||||
join(nodeBinDir, process.platform === 'win32' ? 'npm.cmd' : 'npm'),
|
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
||||||
['install', '-g', 'hermes-web-ui@latest'],
|
['install', '-g', 'hermes-web-ui@latest'],
|
||||||
{
|
{
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
timeout: 120000,
|
timeout: 10 * 60 * 1000,
|
||||||
stdio: ['pipe', 'pipe', 'pipe'],
|
stdio: ['pipe', 'pipe', 'pipe'],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -68,8 +67,9 @@ describe('update controller', () => {
|
|||||||
|
|
||||||
vi.runAllTimers()
|
vi.runAllTimers()
|
||||||
|
|
||||||
|
// Note: spawn is called with getGlobalCliBin() result
|
||||||
expect(mocks.spawn).toHaveBeenCalledWith(
|
expect(mocks.spawn).toHaveBeenCalledWith(
|
||||||
join(nodeBinDir, process.platform === 'win32' ? 'hermes-web-ui.cmd' : 'hermes-web-ui'),
|
expect.any(String), // Dynamic path based on npm prefix -g
|
||||||
['restart', '--port', '9129'],
|
['restart', '--port', '9129'],
|
||||||
{
|
{
|
||||||
detached: true,
|
detached: true,
|
||||||
|
|||||||
@@ -204,8 +204,25 @@ describe('native-style Hermes usage analytics DB aggregation', () => {
|
|||||||
{ model: 'tool-model', input_tokens: 30, output_tokens: 20, cache_read_tokens: 5, cache_write_tokens: 1, reasoning_tokens: 2, sessions: 1 },
|
{ model: 'tool-model', input_tokens: 30, output_tokens: 20, cache_read_tokens: 5, cache_write_tokens: 1, reasoning_tokens: 2, sessions: 1 },
|
||||||
])
|
])
|
||||||
expect(result.by_day).toHaveLength(2)
|
expect(result.by_day).toHaveLength(2)
|
||||||
expect(result.by_day[0]).toEqual({ date: day(now - 86400), tokens: 10, cache: 1, sessions: 1, cost: 0.005 })
|
expect(result.by_day[0]).toEqual({
|
||||||
expect(result.by_day[1]).toMatchObject({ date: day(now), tokens: 203, cache: 15, sessions: 3 })
|
date: day(now - 86400),
|
||||||
|
input_tokens: 7,
|
||||||
|
output_tokens: 3,
|
||||||
|
cache_read_tokens: 1,
|
||||||
|
cache_write_tokens: 0,
|
||||||
|
sessions: 1,
|
||||||
|
errors: 0,
|
||||||
|
cost: 0.005,
|
||||||
|
})
|
||||||
|
expect(result.by_day[1]).toMatchObject({
|
||||||
|
date: day(now),
|
||||||
|
input_tokens: 131,
|
||||||
|
output_tokens: 72,
|
||||||
|
cache_read_tokens: 15,
|
||||||
|
cache_write_tokens: 3,
|
||||||
|
sessions: 3,
|
||||||
|
errors: 0,
|
||||||
|
})
|
||||||
expect(result.by_day[1].cost).toBeCloseTo(0.038)
|
expect(result.by_day[1].cost).toBeCloseTo(0.038)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user