add hermes kanban board (#534)
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const mockExecFileAsync = vi.hoisted(() => vi.fn())
|
||||
const mockLoggerError = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('util', () => ({
|
||||
promisify: () => mockExecFileAsync,
|
||||
}))
|
||||
|
||||
vi.mock('../../packages/server/src/services/logger', () => ({
|
||||
logger: {
|
||||
error: mockLoggerError,
|
||||
},
|
||||
}))
|
||||
|
||||
import * as service from '../../packages/server/src/services/hermes/hermes-kanban'
|
||||
|
||||
describe('hermes kanban service', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('builds list/create/stats CLI calls correctly', async () => {
|
||||
mockExecFileAsync
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify([{ id: 'task-1' }]) })
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify({ id: 'task-2' }) })
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify({ total: 1, by_status: {}, by_assignee: {} }) })
|
||||
|
||||
await expect(service.listTasks({ status: 'todo', assignee: 'alice', tenant: 'ops' })).resolves.toEqual([{ id: 'task-1' }])
|
||||
await expect(service.createTask('Ship', { body: 'write', assignee: 'alice', priority: 3, tenant: 'ops' })).resolves.toEqual({ id: 'task-2' })
|
||||
await expect(service.getStats()).resolves.toEqual({ total: 1, by_status: {}, by_assignee: {} })
|
||||
|
||||
expect(mockExecFileAsync.mock.calls[0][1]).toEqual(['kanban', 'list', '--json', '--status', 'todo', '--assignee', 'alice', '--tenant', 'ops'])
|
||||
expect(mockExecFileAsync.mock.calls[1][1]).toEqual(['kanban', 'create', 'Ship', '--json', '--body', 'write', '--assignee', 'alice', '--priority', '3', '--tenant', 'ops'])
|
||||
expect(mockExecFileAsync.mock.calls[2][1]).toEqual(['kanban', 'stats', '--json'])
|
||||
})
|
||||
|
||||
it('builds action CLI calls and maps not-found show to null', async () => {
|
||||
mockExecFileAsync
|
||||
.mockRejectedValueOnce({ code: 1 })
|
||||
.mockResolvedValueOnce({})
|
||||
.mockResolvedValueOnce({})
|
||||
.mockResolvedValueOnce({})
|
||||
.mockResolvedValueOnce({})
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify([{ name: 'alice' }]) })
|
||||
|
||||
await expect(service.getTask('missing')).resolves.toBeNull()
|
||||
await service.completeTasks(['task-1'], 'done')
|
||||
await service.blockTask('task-1', 'wait')
|
||||
await service.unblockTasks(['task-1'])
|
||||
await service.assignTask('task-1', 'alice')
|
||||
await expect(service.getAssignees()).resolves.toEqual([{ name: 'alice' }])
|
||||
|
||||
expect(mockExecFileAsync.mock.calls[1][1]).toEqual(['kanban', 'complete', 'task-1', '--summary', 'done'])
|
||||
expect(mockExecFileAsync.mock.calls[2][1]).toEqual(['kanban', 'block', 'task-1', 'wait'])
|
||||
expect(mockExecFileAsync.mock.calls[3][1]).toEqual(['kanban', 'unblock', 'task-1'])
|
||||
expect(mockExecFileAsync.mock.calls[4][1]).toEqual(['kanban', 'assign', 'task-1', 'alice'])
|
||||
expect(mockExecFileAsync.mock.calls[5][1]).toEqual(['kanban', 'assignees', '--json'])
|
||||
})
|
||||
|
||||
it('wraps CLI failures with service-specific errors', async () => {
|
||||
mockExecFileAsync.mockRejectedValue(new Error('boom'))
|
||||
|
||||
await expect(service.listTasks()).rejects.toThrow('Failed to list kanban tasks: boom')
|
||||
expect(mockLoggerError).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,156 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const mockReadFile = vi.hoisted(() => vi.fn())
|
||||
const mockListTasks = vi.hoisted(() => vi.fn())
|
||||
const mockGetTask = vi.hoisted(() => vi.fn())
|
||||
const mockCreateTask = vi.hoisted(() => vi.fn())
|
||||
const mockCompleteTasks = vi.hoisted(() => vi.fn())
|
||||
const mockBlockTask = vi.hoisted(() => vi.fn())
|
||||
const mockUnblockTasks = vi.hoisted(() => vi.fn())
|
||||
const mockAssignTask = vi.hoisted(() => vi.fn())
|
||||
const mockGetStats = vi.hoisted(() => vi.fn())
|
||||
const mockGetAssignees = vi.hoisted(() => vi.fn())
|
||||
const mockSearchSessions = vi.hoisted(() => vi.fn())
|
||||
const mockGetSessionDetail = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('fs/promises', () => ({
|
||||
readFile: mockReadFile,
|
||||
}))
|
||||
|
||||
vi.mock('os', () => ({
|
||||
homedir: () => '/Users/tester',
|
||||
}))
|
||||
|
||||
vi.mock('../../packages/server/src/services/hermes/hermes-kanban', () => ({
|
||||
listTasks: mockListTasks,
|
||||
getTask: mockGetTask,
|
||||
createTask: mockCreateTask,
|
||||
completeTasks: mockCompleteTasks,
|
||||
blockTask: mockBlockTask,
|
||||
unblockTasks: mockUnblockTasks,
|
||||
assignTask: mockAssignTask,
|
||||
getStats: mockGetStats,
|
||||
getAssignees: mockGetAssignees,
|
||||
}))
|
||||
|
||||
vi.mock('../../packages/server/src/db/hermes/sessions-db', () => ({
|
||||
searchSessionSummariesWithProfile: mockSearchSessions,
|
||||
getSessionDetailFromDbWithProfile: mockGetSessionDetail,
|
||||
}))
|
||||
|
||||
import * as ctrl from '../../packages/server/src/controllers/hermes/kanban'
|
||||
|
||||
function ctx(overrides: Record<string, any> = {}) {
|
||||
return {
|
||||
query: {},
|
||||
params: {},
|
||||
request: { body: {} },
|
||||
status: 200,
|
||||
body: null,
|
||||
...overrides,
|
||||
} as any
|
||||
}
|
||||
|
||||
describe('kanban controller', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('lists tasks with filters', async () => {
|
||||
mockListTasks.mockResolvedValue([{ id: 'task-1' }])
|
||||
const c = ctx({ query: { status: 'todo', assignee: 'alice', tenant: 'ops' } })
|
||||
await ctrl.list(c)
|
||||
expect(mockListTasks).toHaveBeenCalledWith({ status: 'todo', assignee: 'alice', tenant: 'ops' })
|
||||
expect(c.body).toEqual({ tasks: [{ id: 'task-1' }] })
|
||||
})
|
||||
|
||||
it('enriches completed task details using the latest run profile', async () => {
|
||||
mockGetTask.mockResolvedValue({
|
||||
task: { id: 'task-1', status: 'done' },
|
||||
runs: [{ profile: 'stale' }, { profile: 'fresh' }],
|
||||
comments: [],
|
||||
events: [],
|
||||
})
|
||||
mockSearchSessions.mockResolvedValue([{ id: 'session-1' }])
|
||||
mockGetSessionDetail.mockResolvedValue({
|
||||
title: 'Session one',
|
||||
source: 'codex',
|
||||
model: 'gpt-5.5',
|
||||
started_at: 1,
|
||||
ended_at: 2,
|
||||
messages: [],
|
||||
})
|
||||
|
||||
const c = ctx({ params: { id: 'task-1' } })
|
||||
await ctrl.get(c)
|
||||
|
||||
expect(mockSearchSessions).toHaveBeenCalledWith('task-1', 'fresh', undefined, 5)
|
||||
expect(mockGetSessionDetail).toHaveBeenCalledWith('session-1', 'fresh')
|
||||
expect(c.body.session).toMatchObject({ id: 'session-1', title: 'Session one' })
|
||||
})
|
||||
|
||||
it('validates create/search/readArtifact requests', async () => {
|
||||
const createCtx = ctx({ request: { body: {} } })
|
||||
await ctrl.create(createCtx)
|
||||
expect(createCtx.status).toBe(400)
|
||||
|
||||
const searchCtx = ctx({ query: { task_id: 'task-1' } })
|
||||
await ctrl.searchSessions(searchCtx)
|
||||
expect(searchCtx.status).toBe(400)
|
||||
|
||||
const fileCtx = ctx({ query: { path: '/tmp/outside.txt' } })
|
||||
await ctrl.readArtifact(fileCtx)
|
||||
expect(fileCtx.status).toBe(403)
|
||||
})
|
||||
|
||||
it('reads workspace artifacts and proxies action routes', async () => {
|
||||
mockReadFile.mockResolvedValue('artifact-content')
|
||||
mockCreateTask.mockResolvedValue({ id: 'task-2' })
|
||||
mockCompleteTasks.mockResolvedValue(undefined)
|
||||
mockBlockTask.mockResolvedValue(undefined)
|
||||
mockUnblockTasks.mockResolvedValue(undefined)
|
||||
mockAssignTask.mockResolvedValue(undefined)
|
||||
mockGetStats.mockResolvedValue({ total: 1, by_status: {}, by_assignee: {} })
|
||||
mockGetAssignees.mockResolvedValue([{ name: 'alice' }])
|
||||
mockSearchSessions.mockResolvedValue([{ id: 'session-2' }])
|
||||
|
||||
const fileCtx = ctx({ query: { path: '/Users/tester/.hermes/kanban/workspaces/task/out.txt' } })
|
||||
await ctrl.readArtifact(fileCtx)
|
||||
expect(fileCtx.body).toEqual({
|
||||
content: 'artifact-content',
|
||||
path: '/Users/tester/.hermes/kanban/workspaces/task/out.txt',
|
||||
})
|
||||
|
||||
const createCtx = ctx({ request: { body: { title: 'Ship', body: 'x' } } })
|
||||
await ctrl.create(createCtx)
|
||||
expect(createCtx.body).toEqual({ task: { id: 'task-2' } })
|
||||
|
||||
const completeCtx = ctx({ request: { body: { task_ids: ['task-1'], summary: 'done' } } })
|
||||
await ctrl.complete(completeCtx)
|
||||
expect(mockCompleteTasks).toHaveBeenCalledWith(['task-1'], 'done')
|
||||
|
||||
const blockCtx = ctx({ params: { id: 'task-1' }, request: { body: { reason: 'wait' } } })
|
||||
await ctrl.block(blockCtx)
|
||||
expect(mockBlockTask).toHaveBeenCalledWith('task-1', 'wait')
|
||||
|
||||
const unblockCtx = ctx({ request: { body: { task_ids: ['task-1'] } } })
|
||||
await ctrl.unblock(unblockCtx)
|
||||
expect(mockUnblockTasks).toHaveBeenCalledWith(['task-1'])
|
||||
|
||||
const assignCtx = ctx({ params: { id: 'task-1' }, request: { body: { profile: 'alice' } } })
|
||||
await ctrl.assign(assignCtx)
|
||||
expect(mockAssignTask).toHaveBeenCalledWith('task-1', 'alice')
|
||||
|
||||
const statsCtx = ctx()
|
||||
await ctrl.stats(statsCtx)
|
||||
expect(statsCtx.body).toEqual({ stats: { total: 1, by_status: {}, by_assignee: {} } })
|
||||
|
||||
const assigneesCtx = ctx()
|
||||
await ctrl.assignees(assigneesCtx)
|
||||
expect(assigneesCtx.body).toEqual({ assignees: [{ name: 'alice' }] })
|
||||
|
||||
const searchCtx = ctx({ query: { task_id: 'task-1', profile: 'alice', q: 'custom' } })
|
||||
await ctrl.searchSessions(searchCtx)
|
||||
expect(mockSearchSessions).toHaveBeenCalledWith('custom', 'alice', undefined, 10)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,53 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const handlers = {
|
||||
stats: vi.fn(async (ctx: any) => { ctx.body = { stats: {} } }),
|
||||
assignees: vi.fn(async (ctx: any) => { ctx.body = { assignees: [] } }),
|
||||
readArtifact: vi.fn(async (ctx: any) => { ctx.body = { content: 'x' } }),
|
||||
searchSessions: vi.fn(async (ctx: any) => { ctx.body = { results: [] } }),
|
||||
list: vi.fn(async (ctx: any) => { ctx.body = { tasks: [] } }),
|
||||
get: vi.fn(async (ctx: any) => { ctx.body = { task: {} } }),
|
||||
create: vi.fn(async (ctx: any) => { ctx.body = { task: {} } }),
|
||||
complete: vi.fn(async (ctx: any) => { ctx.body = { ok: true } }),
|
||||
unblock: vi.fn(async (ctx: any) => { ctx.body = { ok: true } }),
|
||||
block: vi.fn(async (ctx: any) => { ctx.body = { ok: true } }),
|
||||
assign: vi.fn(async (ctx: any) => { ctx.body = { ok: true } }),
|
||||
}
|
||||
|
||||
vi.mock('../../packages/server/src/controllers/hermes/kanban', () => handlers)
|
||||
|
||||
describe('kanban routes', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
Object.values(handlers).forEach(fn => fn.mockClear())
|
||||
})
|
||||
|
||||
it('registers all kanban routes', async () => {
|
||||
const { kanbanRoutes } = await import('../../packages/server/src/routes/hermes/kanban')
|
||||
const paths = kanbanRoutes.stack.map((entry: any) => entry.path)
|
||||
|
||||
expect(paths).toEqual(expect.arrayContaining([
|
||||
'/api/hermes/kanban/stats',
|
||||
'/api/hermes/kanban/assignees',
|
||||
'/api/hermes/kanban/artifact',
|
||||
'/api/hermes/kanban/search-sessions',
|
||||
'/api/hermes/kanban',
|
||||
'/api/hermes/kanban/:id',
|
||||
'/api/hermes/kanban/complete',
|
||||
'/api/hermes/kanban/unblock',
|
||||
'/api/hermes/kanban/:id/block',
|
||||
'/api/hermes/kanban/:id/assign',
|
||||
]))
|
||||
})
|
||||
|
||||
it('delegates search-sessions to the controller', async () => {
|
||||
const { kanbanRoutes } = await import('../../packages/server/src/routes/hermes/kanban')
|
||||
const layer = kanbanRoutes.stack.find((entry: any) => entry.path === '/api/hermes/kanban/search-sessions')
|
||||
const ctx: any = { query: { task_id: 'task-1', profile: 'alice' }, body: null, params: {} }
|
||||
|
||||
await layer.stack[0](ctx)
|
||||
|
||||
expect(handlers.searchSessions).toHaveBeenCalledWith(ctx)
|
||||
expect(ctx.body).toEqual({ results: [] })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user