修复 WUI Kanban 看板选择与隔离 (#594)

* fix: add explicit kanban board selection

* fix: tighten kanban board counts and management
This commit is contained in:
Zhicheng Han
2026-05-10 13:58:44 +02:00
committed by GitHub
parent 377fa4144d
commit 838791a740
17 changed files with 1199 additions and 156 deletions
+59 -17
View File
@@ -8,7 +8,12 @@ vi.mock('../../packages/client/src/api/client', () => ({
}))
import {
listBoards,
createBoard,
archiveBoard,
getCapabilities,
listTasks,
getTask,
createTask,
completeTasks,
blockTask,
@@ -23,16 +28,36 @@ describe('Kanban API', () => {
vi.clearAllMocks()
})
it('serializes list filters into query params', async () => {
it('serializes board and list filters into query params', async () => {
mockRequest.mockResolvedValue({ tasks: [{ id: 'task-1' }] })
const result = await listTasks({ status: 'blocked', assignee: 'alice', tenant: 'ops' })
const result = await listTasks({ board: 'default', status: 'blocked', assignee: 'alice', tenant: 'ops' })
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban?status=blocked&assignee=alice&tenant=ops')
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban?board=default&status=blocked&assignee=alice&tenant=ops')
expect(result).toEqual([{ id: 'task-1' }])
})
it('posts create and action payloads in the expected shape', async () => {
it('keeps default board explicit when no board is supplied', async () => {
mockRequest
.mockResolvedValueOnce({ tasks: [] })
.mockResolvedValueOnce({ stats: { total: 0, by_status: {}, by_assignee: {} } })
.mockResolvedValueOnce({ assignees: [] })
.mockResolvedValueOnce({ task: { id: 'task-1' }, comments: [], events: [], runs: [] })
await listTasks()
await getStats()
await getAssignees()
await getTask('task-1')
expect(mockRequest.mock.calls.map(call => call[0])).toEqual([
'/api/hermes/kanban?board=default',
'/api/hermes/kanban/stats?board=default',
'/api/hermes/kanban/assignees?board=default',
'/api/hermes/kanban/task-1?board=default',
])
})
it('posts create and action payloads with explicit board in the URL', async () => {
mockRequest
.mockResolvedValueOnce({ task: { id: 'task-1' } })
.mockResolvedValueOnce({ ok: true })
@@ -40,27 +65,44 @@ describe('Kanban API', () => {
.mockResolvedValueOnce({ ok: true })
.mockResolvedValueOnce({ ok: true })
expect(await createTask({ title: 'Ship', assignee: 'alice', priority: 3 })).toEqual({ id: 'task-1' })
await completeTasks(['task-1'], 'done')
await blockTask('task-1', 'waiting')
await unblockTasks(['task-1'])
await assignTask('task-1', 'bob')
expect(await createTask({ title: 'Ship', assignee: 'alice', priority: 3 }, { board: 'project-a' })).toEqual({ id: 'task-1' })
await completeTasks(['task-1'], 'done', { board: 'project-a' })
await blockTask('task-1', 'waiting', { board: 'project-a' })
await unblockTasks(['task-1'], { board: 'project-a' })
await assignTask('task-1', 'bob', { board: 'project-a' })
expect(mockRequest.mock.calls).toEqual([
['/api/hermes/kanban', { method: 'POST', body: JSON.stringify({ title: 'Ship', assignee: 'alice', priority: 3 }) }],
['/api/hermes/kanban/complete', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'], summary: 'done' }) }],
['/api/hermes/kanban/task-1/block', { method: 'POST', body: JSON.stringify({ reason: 'waiting' }) }],
['/api/hermes/kanban/unblock', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'] }) }],
['/api/hermes/kanban/task-1/assign', { method: 'POST', body: JSON.stringify({ profile: 'bob' }) }],
['/api/hermes/kanban?board=project-a', { method: 'POST', body: JSON.stringify({ title: 'Ship', assignee: 'alice', priority: 3 }) }],
['/api/hermes/kanban/complete?board=project-a', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'], summary: 'done' }) }],
['/api/hermes/kanban/task-1/block?board=project-a', { method: 'POST', body: JSON.stringify({ reason: 'waiting' }) }],
['/api/hermes/kanban/unblock?board=project-a', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'] }) }],
['/api/hermes/kanban/task-1/assign?board=project-a', { method: 'POST', body: JSON.stringify({ profile: 'bob' }) }],
])
})
it('unwraps stats and assignee response envelopes', async () => {
it('lists and manages boards through explicit board endpoints', async () => {
mockRequest
.mockResolvedValueOnce({ boards: [{ slug: 'default' }] })
.mockResolvedValueOnce({ board: { slug: 'project-a' } })
.mockResolvedValueOnce({ ok: true })
.mockResolvedValueOnce({ capabilities: { source: 'hermes-cli', supports: { boardsList: true }, missing: [] } })
.mockResolvedValueOnce({ stats: { total: 3, by_status: {}, by_assignee: {} } })
.mockResolvedValueOnce({ assignees: [{ name: 'alice', on_disk: true, counts: { todo: 1 } }] })
await expect(getStats()).resolves.toEqual({ total: 3, by_status: {}, by_assignee: {} })
await expect(getAssignees()).resolves.toEqual([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
await expect(listBoards({ includeArchived: true })).resolves.toEqual([{ slug: 'default' }])
await expect(createBoard({ slug: 'project-a', name: 'Project A' })).resolves.toEqual({ slug: 'project-a' })
await expect(archiveBoard('project-a')).resolves.toEqual({ ok: true })
await expect(getCapabilities()).resolves.toEqual({ source: 'hermes-cli', supports: { boardsList: true }, missing: [] })
await expect(getStats({ board: 'project-a' })).resolves.toEqual({ total: 3, by_status: {}, by_assignee: {} })
await expect(getAssignees({ board: 'project-a' })).resolves.toEqual([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
expect(mockRequest.mock.calls).toEqual([
['/api/hermes/kanban/boards?includeArchived=true'],
['/api/hermes/kanban/boards', { method: 'POST', body: JSON.stringify({ slug: 'project-a', name: 'Project A' }) }],
['/api/hermes/kanban/boards/project-a', { method: 'DELETE' }],
['/api/hermes/kanban/capabilities'],
['/api/hermes/kanban/stats?board=project-a'],
['/api/hermes/kanban/assignees?board=project-a'],
])
})
})
+139 -6
View File
@@ -3,6 +3,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
const mockKanbanApi = vi.hoisted(() => ({
listBoards: vi.fn(),
createBoard: vi.fn(),
archiveBoard: vi.fn(),
getCapabilities: vi.fn(),
listTasks: vi.fn(),
getStats: vi.fn(),
getAssignees: vi.fn(),
@@ -15,20 +19,43 @@ const mockKanbanApi = vi.hoisted(() => ({
vi.mock('@/api/hermes/kanban', () => mockKanbanApi)
import { useKanbanStore } from '@/stores/hermes/kanban'
import { KANBAN_SELECTED_BOARD_STORAGE_KEY, useKanbanStore } from '@/stores/hermes/kanban'
describe('Kanban store', () => {
beforeEach(() => {
window.localStorage.clear()
setActivePinia(createPinia())
vi.clearAllMocks()
mockKanbanApi.listBoards.mockResolvedValue([
{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 },
{ slug: 'project-a', name: 'Project A', archived: false, counts: { todo: 1 }, total: 1 },
])
mockKanbanApi.getCapabilities.mockResolvedValue({ source: 'hermes-cli', supports: { boardsList: true }, missing: [] })
})
it('fetchTasks uses active filters and updates loading', async () => {
it('persists selected board, including default, and falls back to default for missing boards', async () => {
const store = useKanbanStore()
await store.fetchBoards()
expect(store.setSelectedBoard('project-a')).toBe('project-a')
expect(window.localStorage.getItem(KANBAN_SELECTED_BOARD_STORAGE_KEY)).toBe('project-a')
expect(store.setSelectedBoard('default')).toBe('default')
expect(window.localStorage.getItem(KANBAN_SELECTED_BOARD_STORAGE_KEY)).toBe('default')
const recovered = store.recoverSelectedBoard('missing-board')
expect(recovered).toEqual({ board: 'default', recovered: true })
expect(store.selectedBoard).toBe('default')
expect(store.boardWarning).toContain('missing-board')
})
it('fetchTasks uses active filters and selected board while updating loading', async () => {
mockKanbanApi.listTasks.mockImplementation(
() => new Promise(resolve => setTimeout(() => resolve([{ id: 'task-1', status: 'todo' }]), 0))
)
const store = useKanbanStore()
store.setSelectedBoard('project-a')
store.setFilter('status', 'blocked')
store.setFilter('assignee', 'alice')
const promise = store.fetchTasks()
@@ -36,20 +63,22 @@ describe('Kanban store', () => {
expect(store.loading).toBe(true)
await promise
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ status: 'blocked', assignee: 'alice' })
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ board: 'project-a', status: 'blocked', assignee: 'alice' })
expect(store.tasks).toEqual([{ id: 'task-1', status: 'todo' }])
expect(store.loading).toBe(false)
})
it('create and status actions update local task state and refresh stats', async () => {
it('create and status actions pass selected board, update local task state, and refresh board counts', async () => {
mockKanbanApi.createTask.mockResolvedValue({ id: 'task-2', status: 'todo', assignee: null })
mockKanbanApi.completeTasks.mockResolvedValue({ ok: true })
mockKanbanApi.blockTask.mockResolvedValue({ ok: true })
mockKanbanApi.unblockTasks.mockResolvedValue({ ok: true })
mockKanbanApi.assignTask.mockResolvedValue({ ok: true })
mockKanbanApi.getStats.mockResolvedValue({ total: 2, by_status: { done: 1 }, by_assignee: {} })
mockKanbanApi.getAssignees.mockResolvedValue([{ name: 'bob', on_disk: true, counts: { ready: 1 } }])
const store = useKanbanStore()
store.setSelectedBoard('project-a')
store.tasks = [{ id: 'task-1', status: 'running', assignee: null }] as any
await store.createTask({ title: 'Ship' })
@@ -58,21 +87,125 @@ describe('Kanban store', () => {
await store.unblockTasks(['task-2'])
await store.assignTask('task-2', 'bob')
expect(mockKanbanApi.createTask).toHaveBeenCalledWith({ title: 'Ship' }, { board: 'project-a' })
expect(mockKanbanApi.completeTasks).toHaveBeenCalledWith(['task-1'], 'done', { board: 'project-a' })
expect(mockKanbanApi.blockTask).toHaveBeenCalledWith('task-2', 'waiting', { board: 'project-a' })
expect(mockKanbanApi.unblockTasks).toHaveBeenCalledWith(['task-2'], { board: 'project-a' })
expect(mockKanbanApi.assignTask).toHaveBeenCalledWith('task-2', 'bob', { board: 'project-a' })
expect(mockKanbanApi.listBoards).toHaveBeenCalledTimes(4)
expect(mockKanbanApi.getAssignees).toHaveBeenCalledWith({ board: 'project-a' })
expect(store.tasks[0]).toMatchObject({ id: 'task-2', status: 'ready', assignee: 'bob' })
expect(store.tasks[1]).toMatchObject({ id: 'task-1', status: 'done' })
expect(mockKanbanApi.getStats).toHaveBeenCalledTimes(4)
})
it('refreshAll loads tasks, stats, and assignees together', async () => {
it('creates and archives boards without relying on CLI current board', async () => {
mockKanbanApi.listBoards.mockResolvedValue([
{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 },
{ slug: 'new-board', name: 'New Board', archived: false, counts: {}, total: 0 },
])
mockKanbanApi.createBoard.mockResolvedValue({ slug: 'new-board', name: 'New Board', archived: false, counts: {}, total: 0 })
mockKanbanApi.archiveBoard.mockResolvedValue({ ok: true })
mockKanbanApi.listTasks.mockResolvedValue([])
mockKanbanApi.getStats.mockResolvedValue({ total: 0, by_status: {}, by_assignee: {} })
mockKanbanApi.getAssignees.mockResolvedValue([])
const store = useKanbanStore()
await store.createBoard({ slug: 'new-board', name: 'New Board' })
expect(mockKanbanApi.createBoard).toHaveBeenCalledWith({ slug: 'new-board', name: 'New Board' })
expect(store.selectedBoard).toBe('new-board')
await store.archiveSelectedBoard()
expect(mockKanbanApi.archiveBoard).toHaveBeenCalledWith('new-board')
expect(store.selectedBoard).toBe('default')
})
it('refreshAll loads boards, tasks, stats, and assignees for the same board', async () => {
mockKanbanApi.listTasks.mockResolvedValue([{ id: 'task-1' }])
mockKanbanApi.getStats.mockResolvedValue({ total: 1, by_status: {}, by_assignee: {} })
mockKanbanApi.getAssignees.mockResolvedValue([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
const store = useKanbanStore()
store.setSelectedBoard('project-a')
await store.refreshAll()
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ board: 'project-a', status: undefined, assignee: undefined })
expect(mockKanbanApi.getStats).toHaveBeenCalledWith({ board: 'project-a' })
expect(mockKanbanApi.getAssignees).toHaveBeenCalledWith({ board: 'project-a' })
expect(mockKanbanApi.listBoards).toHaveBeenCalledWith({ includeArchived: false })
expect(store.tasks).toEqual([{ id: 'task-1' }])
expect(store.stats).toEqual({ total: 1, by_status: {}, by_assignee: {} })
expect(store.assignees).toEqual([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
})
it('ignores stale board-list responses after a newer request', async () => {
let resolveSlowBoards: (value: unknown) => void = () => {}
mockKanbanApi.listBoards
.mockImplementationOnce(() => new Promise(resolve => { resolveSlowBoards = resolve }))
.mockResolvedValueOnce([
{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 },
{ slug: 'project-a', name: 'Project A', archived: false, counts: { todo: 2 }, total: 2 },
])
const store = useKanbanStore()
store.setSelectedBoard('project-a')
const slowFetch = store.fetchBoards()
await store.fetchBoards()
resolveSlowBoards([{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 }])
await slowFetch
expect(store.selectedBoard).toBe('project-a')
expect(store.activeBoards).toEqual(expect.arrayContaining([
expect.objectContaining({ slug: 'project-a', total: 2 }),
]))
})
it('ignores stale same-board fetch responses after a newer request', async () => {
let resolveSlow: (value: unknown) => void = () => {}
mockKanbanApi.listTasks
.mockImplementationOnce(() => new Promise(resolve => { resolveSlow = resolve }))
.mockResolvedValueOnce([{ id: 'new-filter-task' }])
const store = useKanbanStore()
store.setSelectedBoard('project-a')
const slowFetch = store.fetchTasks()
await store.fetchTasks()
resolveSlow([{ id: 'old-filter-task' }])
await slowFetch
expect(store.tasks).toEqual([{ id: 'new-filter-task' }])
})
it('does not leave loading stuck when a silent fetch supersedes a visible fetch', async () => {
let resolveVisible: (value: unknown) => void = () => {}
mockKanbanApi.listTasks
.mockImplementationOnce(() => new Promise(resolve => { resolveVisible = resolve }))
.mockResolvedValueOnce([{ id: 'silent-task' }])
const store = useKanbanStore()
const visibleFetch = store.fetchTasks()
expect(store.loading).toBe(true)
await store.fetchTasks(true)
resolveVisible([{ id: 'visible-task' }])
await visibleFetch
expect(store.tasks).toEqual([{ id: 'silent-task' }])
expect(store.loading).toBe(false)
})
it('ignores stale fetch responses after a board switch', async () => {
let resolveSlow: (value: unknown) => void = () => {}
mockKanbanApi.listTasks
.mockImplementationOnce(() => new Promise(resolve => { resolveSlow = resolve }))
.mockResolvedValueOnce([{ id: 'new-board-task' }])
const store = useKanbanStore()
store.setSelectedBoard('default')
const slowFetch = store.fetchTasks()
store.setSelectedBoard('project-a')
await store.fetchTasks()
resolveSlow([{ id: 'old-board-task' }])
await slowFetch
expect(store.tasks).toEqual([{ id: 'new-board-task' }])
})
})
+2 -1
View File
@@ -37,6 +37,7 @@ vi.mock('@/api/hermes/kanban', () => ({
vi.mock('@/stores/hermes/kanban', () => ({
useKanbanStore: () => ({
selectedBoard: 'project-a',
assignees: [{ name: 'alice', counts: { todo: 1 } }, { name: 'bob', counts: { ready: 1 } }],
completeTasks: mockCompleteTasks,
blockTask: mockBlockTask,
@@ -198,7 +199,7 @@ describe('KanbanTaskDrawer', () => {
await sessionsTitle?.trigger('click')
await flushPromises()
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban/search-sessions?task_id=task-2&profile=fresh')
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban/search-sessions?task_id=task-2&profile=fresh&board=project-a')
await wrapper.find('.session-item').trigger('click')
expect(mockRouterPush).toHaveBeenCalledWith({ name: 'hermes.chat', query: { session: 'session-2' } })
})
+114 -3
View File
@@ -3,19 +3,40 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { defineComponent } from 'vue'
import { mount, flushPromises } from '@vue/test-utils'
const routeState = vi.hoisted(() => ({
query: { board: 'project-a' } as Record<string, string>,
}))
const routerReplace = vi.hoisted(() => vi.fn())
const storeState = vi.hoisted(() => ({
tasks: [] as Array<{ id: string; title: string; status: string; created_at: number }>,
stats: { by_status: { todo: 1, done: 0 }, by_assignee: {}, total: 1 } as Record<string, any>,
assignees: [] as Array<{ name: string; counts: Record<string, number> | null }>,
activeBoards: [] as Array<{ slug: string; name: string; icon?: string; total?: number }>,
loading: false,
boardsLoading: false,
selectedBoard: 'default',
boardWarning: null as string | null,
capabilities: null as Record<string, any> | null,
filterStatus: null as string | null,
filterAssignee: null as string | null,
}))
const mockFetchBoards = vi.hoisted(() => vi.fn())
const mockFetchCapabilities = vi.hoisted(() => vi.fn())
const mockRefreshAll = vi.hoisted(() => vi.fn())
const mockFetchTasks = vi.hoisted(() => vi.fn())
const mockFetchStats = vi.hoisted(() => vi.fn())
const mockSetFilter = vi.hoisted(() => vi.fn())
const mockRecoverSelectedBoard = vi.hoisted(() => vi.fn())
const mockCreateBoard = vi.hoisted(() => vi.fn())
const mockArchiveSelectedBoard = vi.hoisted(() => vi.fn())
vi.mock('vue-router', () => ({
useRoute: () => routeState,
useRouter: () => ({ replace: routerReplace }),
}))
vi.mock('vue-i18n', () => ({
useI18n: () => ({
@@ -24,12 +45,18 @@ vi.mock('vue-i18n', () => ({
}))
vi.mock('@/stores/hermes/kanban', () => ({
DEFAULT_KANBAN_BOARD: 'default',
useKanbanStore: () => ({
...storeState,
fetchBoards: mockFetchBoards,
fetchCapabilities: mockFetchCapabilities,
refreshAll: mockRefreshAll,
fetchTasks: mockFetchTasks,
fetchStats: mockFetchStats,
setFilter: mockSetFilter,
recoverSelectedBoard: mockRecoverSelectedBoard,
createBoard: mockCreateBoard,
archiveSelectedBoard: mockArchiveSelectedBoard,
}),
}))
@@ -58,6 +85,7 @@ vi.mock('@/components/hermes/kanban/KanbanCreateForm.vue', () => ({
}))
vi.mock('naive-ui', () => ({
useMessage: () => ({ warning: vi.fn(), error: vi.fn(), success: vi.fn() }),
NButton: defineComponent({
name: 'NButton',
emits: ['click'],
@@ -65,9 +93,21 @@ vi.mock('naive-ui', () => ({
}),
NSelect: defineComponent({
name: 'NSelect',
props: { value: null, options: { type: Array, default: () => [] } },
props: { value: null, options: { type: Array, default: () => [] }, loading: Boolean },
emits: ['update:value'],
template: '<div class="n-select-stub"></div>',
template: '<button class="n-select-stub" @click="$emit(\'update:value\', options[1]?.value || value)"><span v-for="option in options" :key="option.value">{{ option.label }}</span>{{ value }}</button>',
}),
NInput: defineComponent({
name: 'NInput',
props: { value: { type: String, default: '' }, placeholder: { type: String, required: false } },
emits: ['update:value'],
template: '<input class="n-input-stub" :placeholder="placeholder" :value="value" @input="$emit(\'update:value\', $event.target.value)" />',
}),
NModal: defineComponent({
name: 'NModal',
props: { show: Boolean },
emits: ['update:show', 'close'],
template: '<div v-if="show" class="n-modal-stub"><slot /><slot name="action" /></div>',
}),
NSpin: defineComponent({
name: 'NSpin',
@@ -91,6 +131,8 @@ describe('KanbanView', () => {
beforeEach(() => {
vi.useFakeTimers()
vi.clearAllMocks()
routeState.query = { board: 'project-a' }
routerReplace.mockResolvedValue(undefined)
storeState.tasks = [
{ id: 'task-1', title: 'Task one', status: 'todo', created_at: 10 },
{ id: 'task-2', title: 'Task two', status: 'done', created_at: 20 },
@@ -101,12 +143,28 @@ describe('KanbanView', () => {
total: 2,
}
storeState.assignees = []
storeState.activeBoards = [
{ slug: 'default', name: 'Default', total: 0 },
{ slug: 'project-a', name: 'Project A', total: 2 },
]
storeState.loading = false
storeState.boardsLoading = false
storeState.selectedBoard = 'default'
storeState.boardWarning = null
storeState.capabilities = null
storeState.filterStatus = null
storeState.filterAssignee = null
mockFetchBoards.mockResolvedValue(undefined)
mockFetchCapabilities.mockResolvedValue(undefined)
mockRefreshAll.mockResolvedValue(undefined)
mockFetchTasks.mockResolvedValue(undefined)
mockFetchStats.mockResolvedValue(undefined)
mockCreateBoard.mockResolvedValue({ slug: 'new-board' })
mockArchiveSelectedBoard.mockResolvedValue(undefined)
mockRecoverSelectedBoard.mockImplementation((candidate: string) => {
storeState.selectedBoard = candidate || 'default'
return { board: storeState.selectedBoard, recovered: false }
})
mockSetFilter.mockImplementation((key: 'status' | 'assignee', value: string | null) => {
if (key === 'status') storeState.filterStatus = value
else storeState.filterAssignee = value
@@ -117,11 +175,15 @@ describe('KanbanView', () => {
})
})
it('starts with collapsed panels and refreshes stats alongside tasks', async () => {
it('initializes board from route query and refreshes stats alongside tasks', async () => {
const wrapper = mount(KanbanView)
await flushPromises()
expect(mockFetchBoards).toHaveBeenCalledOnce()
expect(mockFetchCapabilities).toHaveBeenCalledOnce()
expect(mockRecoverSelectedBoard).toHaveBeenCalledWith('project-a')
expect(mockRefreshAll).toHaveBeenCalledOnce()
expect(routerReplace).not.toHaveBeenCalled()
expect(wrapper.find('.n-collapse-stub').attributes('data-default-expanded')).toBe('null')
await wrapper.find('.drawer-updated').trigger('click')
@@ -131,7 +193,56 @@ describe('KanbanView', () => {
await vi.advanceTimersByTimeAsync(15000)
await flushPromises()
expect(mockFetchBoards).toHaveBeenCalledTimes(2)
expect(mockFetchTasks).toHaveBeenCalledTimes(2)
expect(mockFetchStats).toHaveBeenCalledTimes(2)
})
it('renders board and assignee count labels with explicit context', async () => {
storeState.assignees = [{ name: 'alice', counts: { todo: 2, done: 1 } }]
const wrapper = mount(KanbanView)
await flushPromises()
expect(wrapper.text()).toContain('kanban.title: Default · kanban.stats.tasks: 0')
expect(wrapper.text()).toContain('kanban.title: Project A · kanban.stats.tasks: 2')
expect(wrapper.text()).toContain('kanban.detail.assignee: alice · kanban.stats.tasks: 3')
})
it('creates and archives boards from the board toolbar', async () => {
storeState.selectedBoard = 'project-a'
const wrapper = mount(KanbanView)
await flushPromises()
await wrapper.findAll('.n-button-stub')[0].trigger('click')
await flushPromises()
const inputs = wrapper.findAll('.n-input-stub')
await inputs[0].setValue('new-board')
await inputs[1].setValue('New Board')
await wrapper.findAll('.n-button-stub').at(-1)!.trigger('click')
await flushPromises()
expect(mockCreateBoard).toHaveBeenCalledWith({ slug: 'new-board', name: 'New Board' })
expect(routerReplace).toHaveBeenCalledWith({ query: { board: 'new-board' } })
vi.spyOn(window, 'confirm').mockReturnValueOnce(true)
await wrapper.findAll('.n-button-stub')[1].trigger('click')
await flushPromises()
expect(mockArchiveSelectedBoard).toHaveBeenCalled()
expect(routerReplace).toHaveBeenCalledWith({ query: { board: 'default' } })
})
it('makes default board explicit when route query is absent', async () => {
routeState.query = {}
mockRecoverSelectedBoard.mockImplementation(() => {
storeState.selectedBoard = 'default'
return { board: 'default', recovered: false }
})
mount(KanbanView)
await flushPromises()
expect(routerReplace).toHaveBeenCalledWith({ query: { board: 'default' } })
expect(mockRefreshAll).toHaveBeenCalledOnce()
})
})
+66 -18
View File
@@ -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 () => {
+60 -16
View File
@@ -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' } })
+7
View File
@@ -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',