Scope skill usage to request profile
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user