Files
Hermes-ui/tests/server/profiles-routes.test.ts
T
ekko 3d2b1c5e47 fix: job edit schedule format error and refactor services directory
- Fix #25: job update sends schedule as plain string but upstream expects
  { kind, expr, display } object, causing "'str' object has no attribute 'get'"
- Move hermes-cli.ts, hermes.ts, hermes-profile.ts into services/hermes/
  for multi-agent namespacing consistency
- Fix ts-node Set spread compatibility in filesystem.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 16:48:24 +08:00

88 lines
2.8 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
// Mock hermes-cli
vi.mock('../../packages/server/src/services/hermes/hermes-cli', () => ({
listProfiles: vi.fn(),
getProfile: vi.fn(),
createProfile: vi.fn(),
deleteProfile: vi.fn(),
renameProfile: vi.fn(),
useProfile: vi.fn(),
stopGateway: vi.fn(),
startGateway: vi.fn(),
startGatewayBackground: vi.fn(),
setupReset: vi.fn(),
exportProfile: vi.fn(),
importProfile: vi.fn(),
}))
import * as hermesCli from '../../packages/server/src/services/hermes/hermes-cli'
describe('Profile Routes', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('ensureApiServerConfig (via active profile switch)', () => {
it('should inject api_server config when missing', async () => {
// This tests the logic that profiles.ts ensures api_server config exists
// We test the ensureApiServerConfig behavior indirectly through the module
const { existsSync, readFileSync, writeFileSync } = await import('fs')
vi.mock('fs', () => ({
existsSync: vi.fn().mockReturnValue(true),
readFileSync: vi.fn().mockReturnValue('platforms: {}'),
writeFileSync: vi.fn(),
createReadStream: vi.fn(),
unlinkSync: vi.fn(),
mkdirSync: vi.fn(),
copyFileSync: vi.fn(),
mkdir: vi.fn(),
writeFile: vi.fn(),
}))
})
})
describe('hermes-cli wrapper', () => {
it('listProfiles returns array', async () => {
const mockProfiles = [{ name: 'default', active: true }]
vi.mocked(hermesCli.listProfiles).mockResolvedValue(mockProfiles as any)
const result = await hermesCli.listProfiles()
expect(result).toEqual(mockProfiles)
})
it('getProfile returns profile detail', async () => {
const mockDetail = { name: 'default', path: '/tmp/default' }
vi.mocked(hermesCli.getProfile).mockResolvedValue(mockDetail as any)
const result = await hermesCli.getProfile('default')
expect(result).toEqual(mockDetail)
expect(hermesCli.getProfile).toHaveBeenCalledWith('default')
})
it('createProfile calls CLI with name and clone flag', async () => {
vi.mocked(hermesCli.createProfile).mockResolvedValue('Profile created')
await hermesCli.createProfile('test', true)
expect(hermesCli.createProfile).toHaveBeenCalledWith('test', true)
})
it('deleteProfile calls CLI with name', async () => {
vi.mocked(hermesCli.deleteProfile).mockResolvedValue(true)
await hermesCli.deleteProfile('test')
expect(hermesCli.deleteProfile).toHaveBeenCalledWith('test')
})
it('renameProfile calls CLI with old and new name', async () => {
vi.mocked(hermesCli.renameProfile).mockResolvedValue(true)
await hermesCli.renameProfile('old', 'new')
expect(hermesCli.renameProfile).toHaveBeenCalledWith('old', 'new')
})
})
})