Scope skills and memory to request profile

This commit is contained in:
ekko
2026-05-24 08:59:21 +08:00
committed by ekko
parent 4db3940e65
commit 289a958684
10 changed files with 142 additions and 50 deletions
@@ -92,6 +92,7 @@ function makeSocket() {
connected: true,
emit: vi.fn(),
join: vi.fn(),
to: vi.fn(() => ({ emit: vi.fn() })),
} as any
}
+34 -2
View File
@@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
const mockGetSkillUsageStatsFromDb = vi.hoisted(() => vi.fn())
const mockGetActiveProfileName = vi.hoisted(() => vi.fn())
const mockGetProfileDir = vi.hoisted(() => vi.fn())
const mockUpdateConfigYamlForProfile = vi.hoisted(() => vi.fn())
vi.mock('../../packages/server/src/db/hermes/sessions-db', () => ({
getSkillUsageStatsFromDb: mockGetSkillUsageStatsFromDb,
@@ -9,10 +11,15 @@ vi.mock('../../packages/server/src/db/hermes/sessions-db', () => ({
vi.mock('../../packages/server/src/services/hermes/hermes-profile', () => ({
getActiveProfileName: mockGetActiveProfileName,
getProfileDir: mockGetProfileDir,
}))
vi.mock('../../packages/server/src/services/hermes/hermes-cli', () => ({
pinSkill: vi.fn(),
vi.mock('../../packages/server/src/services/config-helpers', () => ({
readConfigYamlForProfile: vi.fn(),
updateConfigYamlForProfile: mockUpdateConfigYamlForProfile,
safeReadFile: vi.fn(),
extractDescription: vi.fn(),
listFilesRecursive: vi.fn(),
}))
async function loadController() {
@@ -24,6 +31,8 @@ describe('skills controller', () => {
beforeEach(() => {
vi.clearAllMocks()
mockGetActiveProfileName.mockReturnValue('default')
mockGetProfileDir.mockImplementation((profile: string) => `/tmp/hermes-${profile}`)
mockUpdateConfigYamlForProfile.mockImplementation(async (_profile: string, updater: (config: Record<string, any>) => Record<string, any>) => updater({}))
mockGetSkillUsageStatsFromDb.mockResolvedValue({
period_days: 7,
summary: {
@@ -56,4 +65,27 @@ describe('skills controller', () => {
expect(mockGetSkillUsageStatsFromDb).toHaveBeenCalledWith(7, undefined, 'travel')
})
it('toggles skills in the request-scoped profile config', async () => {
let updatedConfig: Record<string, any> | undefined
mockUpdateConfigYamlForProfile.mockImplementation(async (_profile: string, updater: (config: Record<string, any>) => Record<string, any>) => {
updatedConfig = await updater({ skills: { disabled: ['old-skill'] }, model: { default: 'glm-5.1' } })
return undefined
})
const { toggle } = await loadController()
const ctx: any = {
request: { body: { name: 'new-skill', enabled: false } },
state: { profile: { name: 'research' } },
body: null,
}
await toggle(ctx)
expect(mockUpdateConfigYamlForProfile).toHaveBeenCalledWith('research', expect.any(Function))
expect(updatedConfig).toEqual({
skills: { disabled: ['old-skill', 'new-skill'] },
model: { default: 'glm-5.1' },
})
expect(ctx.body).toEqual({ success: true })
})
})