Import the client, server, skills, tests, and build scripts as the starting point for the rebuild, then trim the surfaces this project does not ship: Electron desktop packaging, the marketing website, and the ESP32 firmware tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows. Rename the package and CLI entry points to hermes-ui, drop the prepare hook so npm ci no longer triggers a build, and drop the removed tsconfig and nodemon references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs so the documented package map and hard rules match this repository. reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const getOpsRuntimeSnapshot = vi.fn()
|
|
|
|
vi.mock('../../packages/server/src/services/hermes/ops-monitor', () => ({
|
|
createEmptyOpsRuntimeSnapshot: (error?: string) => ({ timestamp: 0, error }),
|
|
getOpsRuntimeSnapshot,
|
|
}))
|
|
|
|
describe('performance monitor controller', () => {
|
|
afterEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('returns the runtime snapshot from the performance service', async () => {
|
|
const snapshot = {
|
|
timestamp: 1,
|
|
bridge: { workers: [] },
|
|
sessions: { active: 0 },
|
|
}
|
|
getOpsRuntimeSnapshot.mockResolvedValue(snapshot)
|
|
const ctx: any = {}
|
|
|
|
const { runtime } = await import('../../packages/server/src/controllers/hermes/performance-monitor')
|
|
await runtime(ctx)
|
|
|
|
expect(ctx.body).toBe(snapshot)
|
|
})
|
|
|
|
it('returns a zero snapshot when metrics collection fails', async () => {
|
|
getOpsRuntimeSnapshot.mockRejectedValue(new Error('boom'))
|
|
const ctx: any = {}
|
|
|
|
const { runtime } = await import('../../packages/server/src/controllers/hermes/performance-monitor')
|
|
await runtime(ctx)
|
|
|
|
expect(ctx.status).toBeUndefined()
|
|
expect(ctx.body).toEqual({ timestamp: 0, error: 'boom' })
|
|
})
|
|
|
|
it('requires super admin on the runtime route', async () => {
|
|
const { performanceMonitorRoutes } = await import('../../packages/server/src/routes/hermes/performance-monitor')
|
|
const layer = performanceMonitorRoutes.stack.find((entry: any) => entry.path === '/api/hermes/performance/runtime')
|
|
expect(layer).toBeTruthy()
|
|
|
|
const deniedCtx: any = { state: { user: { role: 'admin' } }, status: 200, body: null }
|
|
const deniedNext = vi.fn(async () => {})
|
|
await layer.stack[0](deniedCtx, deniedNext)
|
|
|
|
expect(deniedCtx.status).toBe(403)
|
|
expect(deniedNext).not.toHaveBeenCalled()
|
|
|
|
const allowedCtx: any = { state: { user: { role: 'super_admin' } }, status: 200, body: null }
|
|
const allowedNext = vi.fn(async () => {})
|
|
await layer.stack[0](allowedCtx, allowedNext)
|
|
expect(allowedNext).toHaveBeenCalledOnce()
|
|
})
|
|
})
|