修复 WUI Kanban 看板选择与隔离 (#594)
* fix: add explicit kanban board selection * fix: tighten kanban board counts and management
This commit is contained in:
@@ -20,19 +20,61 @@ describe('hermes kanban service', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('builds list/create/stats CLI calls correctly', async () => {
|
||||
it('lists boards without mutating or depending on CLI current', async () => {
|
||||
mockExecFileAsync.mockResolvedValueOnce({ stdout: JSON.stringify([{ slug: 'default' }]) })
|
||||
|
||||
await expect(service.listBoards({ includeArchived: true })).resolves.toEqual([{ slug: 'default' }])
|
||||
|
||||
expect(mockExecFileAsync.mock.calls[0][1]).toEqual(['kanban', 'boards', 'list', '--json', '--all'])
|
||||
})
|
||||
|
||||
it('creates and archives boards through canonical CLI board commands', async () => {
|
||||
mockExecFileAsync
|
||||
.mockResolvedValueOnce({ stdout: '' })
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify([{ slug: 'project-a', name: 'Project A' }]) })
|
||||
.mockResolvedValueOnce({ stdout: '' })
|
||||
|
||||
await expect(service.createBoard({ slug: 'project-a', name: 'Project A', description: 'desc', icon: '📌', color: '#8b5cf6', switchCurrent: true })).resolves.toEqual({ slug: 'project-a', name: 'Project A' })
|
||||
await expect(service.archiveBoard('project-a')).resolves.toBeUndefined()
|
||||
|
||||
expect(mockExecFileAsync.mock.calls[0][1]).toEqual(['kanban', 'boards', 'create', 'project-a', '--name', 'Project A', '--description', 'desc', '--icon', '📌', '--color', '#8b5cf6', '--switch'])
|
||||
expect(mockExecFileAsync.mock.calls[1][1]).toEqual(['kanban', 'boards', 'list', '--json', '--all'])
|
||||
expect(mockExecFileAsync.mock.calls[2][1]).toEqual(['kanban', 'boards', 'rm', 'project-a'])
|
||||
})
|
||||
|
||||
it('exposes capability metadata for WUI/canonical parity gaps', async () => {
|
||||
await expect(service.getCapabilities()).resolves.toMatchObject({
|
||||
source: 'hermes-cli',
|
||||
supports: { boardsList: true, boardCreate: true, commentsWrite: false, dispatch: false },
|
||||
missing: expect.arrayContaining(['commentsWrite', 'dispatch']),
|
||||
})
|
||||
})
|
||||
|
||||
it('builds list/create/stats CLI calls with global --board before the action', 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: {} })
|
||||
await expect(service.listTasks({ board: 'project-a', status: 'todo', assignee: 'alice', tenant: 'ops' })).resolves.toEqual([{ id: 'task-1' }])
|
||||
await expect(service.createTask('Ship', { board: 'project-a', body: 'write', assignee: 'alice', priority: 3, tenant: 'ops' })).resolves.toEqual({ id: 'task-2' })
|
||||
await expect(service.getStats({ board: 'project-a' })).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'])
|
||||
expect(mockExecFileAsync.mock.calls[0][1]).toEqual(['kanban', '--board', 'project-a', 'list', '--json', '--status', 'todo', '--assignee', 'alice', '--tenant', 'ops'])
|
||||
expect(mockExecFileAsync.mock.calls[1][1]).toEqual(['kanban', '--board', 'project-a', 'create', 'Ship', '--json', '--body', 'write', '--assignee', 'alice', '--priority', '3', '--tenant', 'ops'])
|
||||
expect(mockExecFileAsync.mock.calls[2][1]).toEqual(['kanban', '--board', 'project-a', 'stats', '--json'])
|
||||
})
|
||||
|
||||
it('normalizes omitted board to default instead of falling through to CLI current', async () => {
|
||||
mockExecFileAsync
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify([]) })
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify({ total: 0, by_status: {}, by_assignee: {} }) })
|
||||
|
||||
await service.listTasks()
|
||||
await service.getStats()
|
||||
|
||||
expect(mockExecFileAsync.mock.calls[0][1]).toEqual(['kanban', '--board', 'default', 'list', '--json'])
|
||||
expect(mockExecFileAsync.mock.calls[1][1]).toEqual(['kanban', '--board', 'default', 'stats', '--json'])
|
||||
})
|
||||
|
||||
it('builds action CLI calls and maps not-found show to null', async () => {
|
||||
@@ -44,18 +86,24 @@ describe('hermes kanban service', () => {
|
||||
.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' }])
|
||||
await expect(service.getTask('missing', { board: 'default' })).resolves.toBeNull()
|
||||
await service.completeTasks(['task-1'], 'done', { board: 'default' })
|
||||
await service.blockTask('task-1', 'wait', { board: 'default' })
|
||||
await service.unblockTasks(['task-1'], { board: 'default' })
|
||||
await service.assignTask('task-1', 'alice', { board: 'default' })
|
||||
await expect(service.getAssignees({ board: 'default' })).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'])
|
||||
expect(mockExecFileAsync.mock.calls[0][1]).toEqual(['kanban', '--board', 'default', 'show', 'missing', '--json'])
|
||||
expect(mockExecFileAsync.mock.calls[1][1]).toEqual(['kanban', '--board', 'default', 'complete', 'task-1', '--summary', 'done'])
|
||||
expect(mockExecFileAsync.mock.calls[2][1]).toEqual(['kanban', '--board', 'default', 'block', 'task-1', 'wait'])
|
||||
expect(mockExecFileAsync.mock.calls[3][1]).toEqual(['kanban', '--board', 'default', 'unblock', 'task-1'])
|
||||
expect(mockExecFileAsync.mock.calls[4][1]).toEqual(['kanban', '--board', 'default', 'assign', 'task-1', 'alice'])
|
||||
expect(mockExecFileAsync.mock.calls[5][1]).toEqual(['kanban', '--board', 'default', 'assignees', '--json'])
|
||||
})
|
||||
|
||||
it('rejects invalid board slugs before shelling out', async () => {
|
||||
await expect(service.listTasks({ board: 'bad;slug' })).rejects.toThrow('Invalid kanban board slug')
|
||||
expect(mockExecFileAsync).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('wraps CLI failures with service-specific errors', async () => {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const mockReadFile = vi.hoisted(() => vi.fn())
|
||||
const mockListBoards = vi.hoisted(() => vi.fn())
|
||||
const mockCreateBoard = vi.hoisted(() => vi.fn())
|
||||
const mockArchiveBoard = vi.hoisted(() => vi.fn())
|
||||
const mockGetCapabilities = vi.hoisted(() => vi.fn())
|
||||
const mockListTasks = vi.hoisted(() => vi.fn())
|
||||
const mockGetTask = vi.hoisted(() => vi.fn())
|
||||
const mockCreateTask = vi.hoisted(() => vi.fn())
|
||||
@@ -24,6 +28,15 @@ vi.mock('os', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('../../packages/server/src/services/hermes/hermes-kanban', () => ({
|
||||
normalizeBoardSlug: (board?: string | null) => {
|
||||
const value = board?.trim() || 'default'
|
||||
if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(value)) throw new Error('Invalid kanban board slug')
|
||||
return value
|
||||
},
|
||||
listBoards: mockListBoards,
|
||||
createBoard: mockCreateBoard,
|
||||
archiveBoard: mockArchiveBoard,
|
||||
getCapabilities: mockGetCapabilities,
|
||||
listTasks: mockListTasks,
|
||||
getTask: mockGetTask,
|
||||
createTask: mockCreateTask,
|
||||
@@ -60,12 +73,40 @@ describe('kanban controller', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('lists tasks with filters', async () => {
|
||||
it('lists boards and tasks with explicit/default board context', async () => {
|
||||
mockListBoards.mockResolvedValue([{ slug: 'default' }])
|
||||
mockListTasks.mockResolvedValue([{ id: 'task-1' }])
|
||||
const c = ctx({ query: { status: 'todo', assignee: 'alice', tenant: 'ops' } })
|
||||
|
||||
const boardsCtx = ctx({ query: { includeArchived: 'true' } })
|
||||
await ctrl.listBoards(boardsCtx)
|
||||
expect(mockListBoards).toHaveBeenCalledWith({ includeArchived: true })
|
||||
expect(boardsCtx.body).toEqual({ boards: [{ slug: 'default' }] })
|
||||
|
||||
const c = ctx({ query: { board: 'project-a', status: 'todo', assignee: 'alice', tenant: 'ops' } })
|
||||
await ctrl.list(c)
|
||||
expect(mockListTasks).toHaveBeenCalledWith({ status: 'todo', assignee: 'alice', tenant: 'ops' })
|
||||
expect(mockListTasks).toHaveBeenCalledWith({ board: 'project-a', status: 'todo', assignee: 'alice', tenant: 'ops' })
|
||||
expect(c.body).toEqual({ tasks: [{ id: 'task-1' }] })
|
||||
|
||||
mockCreateBoard.mockResolvedValue({ slug: 'project-b' })
|
||||
const createBoardCtx = ctx({ request: { body: { slug: 'project-b', name: 'Project B', switchCurrent: false } } })
|
||||
await ctrl.createBoard(createBoardCtx)
|
||||
expect(mockCreateBoard).toHaveBeenCalledWith({ slug: 'project-b', name: 'Project B', description: undefined, icon: undefined, color: undefined, switchCurrent: false })
|
||||
expect(createBoardCtx.body).toEqual({ board: { slug: 'project-b' } })
|
||||
|
||||
mockArchiveBoard.mockResolvedValue(undefined)
|
||||
const archiveCtx = ctx({ params: { slug: 'project-b' } })
|
||||
await ctrl.archiveBoard(archiveCtx)
|
||||
expect(mockArchiveBoard).toHaveBeenCalledWith('project-b')
|
||||
expect(archiveCtx.body).toEqual({ ok: true })
|
||||
|
||||
mockGetCapabilities.mockResolvedValue({ source: 'hermes-cli', supports: {}, missing: [] })
|
||||
const capabilitiesCtx = ctx()
|
||||
await ctrl.capabilities(capabilitiesCtx)
|
||||
expect(capabilitiesCtx.body).toEqual({ capabilities: { source: 'hermes-cli', supports: {}, missing: [] } })
|
||||
|
||||
const defaultCtx = ctx({ query: { status: 'ready' } })
|
||||
await ctrl.list(defaultCtx)
|
||||
expect(mockListTasks).toHaveBeenLastCalledWith({ board: 'default', status: 'ready', assignee: undefined, tenant: undefined })
|
||||
})
|
||||
|
||||
it('enriches completed task details using the latest run profile', async () => {
|
||||
@@ -85,7 +126,7 @@ describe('kanban controller', () => {
|
||||
messages: [],
|
||||
})
|
||||
|
||||
const c = ctx({ params: { id: 'task-1' } })
|
||||
const c = ctx({ params: { id: 'task-1' }, query: { board: 'project-a' } })
|
||||
await ctrl.get(c)
|
||||
|
||||
expect(mockFindLatestExactSessionId).toHaveBeenCalledWith('task-1', 'fresh')
|
||||
@@ -110,7 +151,7 @@ describe('kanban controller', () => {
|
||||
messages: [{ id: 'm1', role: 'user', content: 'work kanban task t_348bfaaf', timestamp: 1 }],
|
||||
})
|
||||
|
||||
const c = ctx({ params: { id: 't_348bfaaf' } })
|
||||
const c = ctx({ params: { id: 't_348bfaaf' }, query: { board: 'project-a' } })
|
||||
await ctrl.get(c)
|
||||
|
||||
expect(c.body.session).toMatchObject({
|
||||
@@ -176,32 +217,35 @@ describe('kanban controller', () => {
|
||||
path: '/Users/tester/.hermes/kanban/workspaces/task/out.txt',
|
||||
})
|
||||
|
||||
const createCtx = ctx({ request: { body: { title: 'Ship', body: 'x' } } })
|
||||
const createCtx = ctx({ query: { board: 'project-a' }, request: { body: { title: 'Ship', body: 'x' } } })
|
||||
await ctrl.create(createCtx)
|
||||
expect(mockCreateTask).toHaveBeenCalledWith('Ship', { board: 'project-a', body: 'x', assignee: undefined, priority: undefined, tenant: undefined })
|
||||
expect(createCtx.body).toEqual({ task: { id: 'task-2' } })
|
||||
|
||||
const completeCtx = ctx({ request: { body: { task_ids: ['task-1'], summary: 'done' } } })
|
||||
const completeCtx = ctx({ query: { board: 'project-a' }, request: { body: { task_ids: ['task-1'], summary: 'done' } } })
|
||||
await ctrl.complete(completeCtx)
|
||||
expect(mockCompleteTasks).toHaveBeenCalledWith(['task-1'], 'done')
|
||||
expect(mockCompleteTasks).toHaveBeenCalledWith(['task-1'], 'done', { board: 'project-a' })
|
||||
|
||||
const blockCtx = ctx({ params: { id: 'task-1' }, request: { body: { reason: 'wait' } } })
|
||||
const blockCtx = ctx({ query: { board: 'project-a' }, params: { id: 'task-1' }, request: { body: { reason: 'wait' } } })
|
||||
await ctrl.block(blockCtx)
|
||||
expect(mockBlockTask).toHaveBeenCalledWith('task-1', 'wait')
|
||||
expect(mockBlockTask).toHaveBeenCalledWith('task-1', 'wait', { board: 'project-a' })
|
||||
|
||||
const unblockCtx = ctx({ request: { body: { task_ids: ['task-1'] } } })
|
||||
const unblockCtx = ctx({ query: { board: 'project-a' }, request: { body: { task_ids: ['task-1'] } } })
|
||||
await ctrl.unblock(unblockCtx)
|
||||
expect(mockUnblockTasks).toHaveBeenCalledWith(['task-1'])
|
||||
expect(mockUnblockTasks).toHaveBeenCalledWith(['task-1'], { board: 'project-a' })
|
||||
|
||||
const assignCtx = ctx({ params: { id: 'task-1' }, request: { body: { profile: 'alice' } } })
|
||||
const assignCtx = ctx({ query: { board: 'project-a' }, params: { id: 'task-1' }, request: { body: { profile: 'alice' } } })
|
||||
await ctrl.assign(assignCtx)
|
||||
expect(mockAssignTask).toHaveBeenCalledWith('task-1', 'alice')
|
||||
expect(mockAssignTask).toHaveBeenCalledWith('task-1', 'alice', { board: 'project-a' })
|
||||
|
||||
const statsCtx = ctx()
|
||||
const statsCtx = ctx({ query: { board: 'project-a' } })
|
||||
await ctrl.stats(statsCtx)
|
||||
expect(mockGetStats).toHaveBeenCalledWith({ board: 'project-a' })
|
||||
expect(statsCtx.body).toEqual({ stats: { total: 1, by_status: {}, by_assignee: {} } })
|
||||
|
||||
const assigneesCtx = ctx()
|
||||
const assigneesCtx = ctx({ query: { board: 'project-a' } })
|
||||
await ctrl.assignees(assigneesCtx)
|
||||
expect(mockGetAssignees).toHaveBeenCalledWith({ board: 'project-a' })
|
||||
expect(assigneesCtx.body).toEqual({ assignees: [{ name: 'alice' }] })
|
||||
|
||||
const searchCtx = ctx({ query: { task_id: 'task-1', profile: 'alice', q: 'custom' } })
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const handlers = {
|
||||
listBoards: vi.fn(async (ctx: any) => { ctx.body = { boards: [] } }),
|
||||
createBoard: vi.fn(async (ctx: any) => { ctx.body = { board: {} } }),
|
||||
archiveBoard: vi.fn(async (ctx: any) => { ctx.body = { ok: true } }),
|
||||
capabilities: vi.fn(async (ctx: any) => { ctx.body = { capabilities: {} } }),
|
||||
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' } }),
|
||||
@@ -27,6 +31,9 @@ describe('kanban routes', () => {
|
||||
const paths = kanbanRoutes.stack.map((entry: any) => entry.path)
|
||||
|
||||
expect(paths).toEqual(expect.arrayContaining([
|
||||
'/api/hermes/kanban/boards',
|
||||
'/api/hermes/kanban/boards/:slug',
|
||||
'/api/hermes/kanban/capabilities',
|
||||
'/api/hermes/kanban/stats',
|
||||
'/api/hermes/kanban/assignees',
|
||||
'/api/hermes/kanban/artifact',
|
||||
|
||||
Reference in New Issue
Block a user