Files
Hermes-ui/tests/server/skills-controller.test.ts
T

60 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-05-24 08:48:40 +08:00
import { beforeEach, describe, expect, it, vi } from 'vitest'
const mockGetSkillUsageStatsFromDb = vi.hoisted(() => vi.fn())
const mockGetActiveProfileName = vi.hoisted(() => vi.fn())
vi.mock('../../packages/server/src/db/hermes/sessions-db', () => ({
getSkillUsageStatsFromDb: mockGetSkillUsageStatsFromDb,
}))
vi.mock('../../packages/server/src/services/hermes/hermes-profile', () => ({
getActiveProfileName: mockGetActiveProfileName,
}))
vi.mock('../../packages/server/src/services/hermes/hermes-cli', () => ({
pinSkill: vi.fn(),
}))
async function loadController() {
vi.resetModules()
return import('../../packages/server/src/controllers/hermes/skills')
}
describe('skills controller', () => {
beforeEach(() => {
vi.clearAllMocks()
mockGetActiveProfileName.mockReturnValue('default')
mockGetSkillUsageStatsFromDb.mockResolvedValue({
period_days: 7,
summary: {
total_skill_loads: 0,
total_skill_edits: 0,
total_skill_actions: 0,
distinct_skills_used: 0,
},
by_day: [],
top_skills: [],
})
})
it('loads skill usage from the request-scoped profile state database', async () => {
const { usageStats } = await loadController()
const ctx: any = { query: { days: '30' }, state: { profile: { name: 'research' } }, body: null }
await usageStats(ctx)
expect(mockGetSkillUsageStatsFromDb).toHaveBeenCalledWith(30, undefined, 'research')
expect(ctx.body.period_days).toBe(7)
})
it('falls back to active profile when no request profile is set', async () => {
mockGetActiveProfileName.mockReturnValue('travel')
const { usageStats } = await loadController()
const ctx: any = { query: {}, state: {}, body: null }
await usageStats(ctx)
expect(mockGetSkillUsageStatsFromDb).toHaveBeenCalledWith(7, undefined, 'travel')
})
})