Kanban:补齐看板事件、链接与批量操作闭环 (#634)

* feat(kanban): add board-scoped event stream bridge

* test(kanban): align event refresh expectation

* feat(kanban): add links and partial bulk bridge

* test(kanban): align links bulk refresh expectation

* fix(kanban): treat mutation stderr as failed
This commit is contained in:
Zhicheng Han
2026-05-13 01:32:38 +02:00
committed by GitHub
parent 44d1b13741
commit 57cdf87bef
14 changed files with 758 additions and 50 deletions
+28
View File
@@ -2,9 +2,13 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const mockRequest = vi.hoisted(() => vi.fn())
const mockGetApiKey = vi.hoisted(() => vi.fn(() => ''))
const mockGetBaseUrlValue = vi.hoisted(() => vi.fn(() => ''))
vi.mock('../../packages/client/src/api/client', () => ({
request: mockRequest,
getApiKey: mockGetApiKey,
getBaseUrlValue: mockGetBaseUrlValue,
}))
import {
@@ -20,6 +24,9 @@ import {
unblockTasks,
assignTask,
addComment,
linkTasks,
unlinkTasks,
bulkUpdateTasks,
getTaskLog,
getDiagnostics,
reclaimTask,
@@ -28,11 +35,23 @@ import {
dispatch,
getStats,
getAssignees,
buildKanbanEventsWebSocketUrl,
} from '../../packages/client/src/api/hermes/kanban'
describe('Kanban API', () => {
beforeEach(() => {
vi.clearAllMocks()
localStorage.clear()
mockGetApiKey.mockReturnValue('')
mockGetBaseUrlValue.mockReturnValue('')
})
it('builds board-scoped kanban event websocket URLs with auth token', () => {
mockGetBaseUrlValue.mockReturnValue('https://wui.example.test')
mockGetApiKey.mockReturnValue('token value')
expect(buildKanbanEventsWebSocketUrl({ board: 'project-a' })).toBe('wss://wui.example.test/api/hermes/kanban/events?board=project-a&token=token+value')
expect(buildKanbanEventsWebSocketUrl()).toBe('wss://wui.example.test/api/hermes/kanban/events?board=default&token=token+value')
})
it('serializes board, list filters, and archived inclusion into query params', async () => {
@@ -116,6 +135,9 @@ describe('Kanban API', () => {
it('calls parity-gap APIs with explicit board query params', async () => {
mockRequest
.mockResolvedValueOnce({ ok: true, output: 'commented' })
.mockResolvedValueOnce({ ok: true, output: 'linked' })
.mockResolvedValueOnce({ ok: true, output: 'unlinked' })
.mockResolvedValueOnce({ results: [{ id: 'task-1', ok: true }] })
.mockResolvedValueOnce({ task_id: 'task-1', path: null, exists: true, size_bytes: 10, content: 'worker log', truncated: false })
.mockResolvedValueOnce({ diagnostics: [{ task_id: 'task-1' }] })
.mockResolvedValueOnce({ ok: true, output: 'reclaimed' })
@@ -124,6 +146,9 @@ describe('Kanban API', () => {
.mockResolvedValueOnce({ result: { spawned: 1 } })
await addComment('task-1', { body: 'needs review', author: 'han' }, { board: 'default' })
await linkTasks({ parent_id: 'task-1', child_id: 'task-2' }, { board: 'project-a' })
await unlinkTasks({ parent_id: 'task-1', child_id: 'task-2' }, { board: 'project-a' })
await expect(bulkUpdateTasks({ ids: ['task-1'], status: 'done', assignee: null, summary: 'closed' }, { board: 'project-a' })).resolves.toEqual({ results: [{ id: 'task-1', ok: true }] })
await expect(getTaskLog('task-1', { board: 'default', tail: 4000 })).resolves.toEqual({ task_id: 'task-1', path: null, exists: true, size_bytes: 10, content: 'worker log', truncated: false })
await expect(getDiagnostics({ board: 'default', task: 'task-1', severity: 'warning' })).resolves.toEqual([{ task_id: 'task-1' }])
await reclaimTask('task-1', { board: 'project-a', reason: 'stale' })
@@ -133,6 +158,9 @@ describe('Kanban API', () => {
expect(mockRequest.mock.calls).toEqual([
['/api/hermes/kanban/task-1/comments?board=default', { method: 'POST', body: JSON.stringify({ body: 'needs review', author: 'han' }) }],
['/api/hermes/kanban/links?board=project-a', { method: 'POST', body: JSON.stringify({ parent_id: 'task-1', child_id: 'task-2' }) }],
['/api/hermes/kanban/links?board=project-a&parent_id=task-1&child_id=task-2', { method: 'DELETE' }],
['/api/hermes/kanban/tasks/bulk?board=project-a', { method: 'POST', body: JSON.stringify({ ids: ['task-1'], status: 'done', assignee: null, summary: 'closed' }) }],
['/api/hermes/kanban/task-1/log?board=default&tail=4000'],
['/api/hermes/kanban/diagnostics?board=default&task=task-1&severity=warning'],
['/api/hermes/kanban/task-1/reclaim?board=project-a', { method: 'POST', body: JSON.stringify({ reason: 'stale' }) }],
+74
View File
@@ -16,12 +16,16 @@ const mockKanbanApi = vi.hoisted(() => ({
unblockTasks: vi.fn(),
assignTask: vi.fn(),
addComment: vi.fn(),
linkTasks: vi.fn(),
unlinkTasks: vi.fn(),
bulkUpdateTasks: vi.fn(),
getTaskLog: vi.fn(),
getDiagnostics: vi.fn(),
reclaimTask: vi.fn(),
reassignTask: vi.fn(),
specifyTask: vi.fn(),
dispatch: vi.fn(),
openKanbanEventStream: vi.fn(),
}))
vi.mock('@/api/hermes/kanban', () => mockKanbanApi)
@@ -49,6 +53,7 @@ describe('Kanban store', () => {
{ slug: 'project-a', name: 'Project A', archived: false, counts: { todo: 1 }, total: 1 },
])
mockKanbanApi.getCapabilities.mockResolvedValue({ source: 'hermes-cli', supports: { boardsList: true }, missing: [] })
mockKanbanApi.openKanbanEventStream.mockReturnValue({ close: vi.fn(), onmessage: null, onclose: null, onerror: null })
})
it('persists selected board, including default, and falls back to default for missing boards', async () => {
@@ -137,6 +142,75 @@ describe('Kanban store', () => {
expect(mockKanbanApi.dispatch).not.toHaveBeenCalled()
})
it('passes selected board to link and partial bulk parity actions', async () => {
mockKanbanApi.getCapabilities.mockResolvedValue({
source: 'hermes-cli',
supports: { links: true, bulk: false },
missing: ['bulk'],
capabilities: [
{ key: 'links', status: 'supported', requiresBoard: true },
{ key: 'bulk', status: 'partial', requiresBoard: true },
],
})
mockKanbanApi.linkTasks.mockResolvedValue({ ok: true })
mockKanbanApi.unlinkTasks.mockResolvedValue({ ok: true })
mockKanbanApi.bulkUpdateTasks.mockResolvedValue({ results: [{ id: 'task-1', ok: true }] })
mockKanbanApi.listTasks.mockResolvedValue([])
mockKanbanApi.getStats.mockResolvedValue({ total: 0, by_status: {}, by_assignee: {} })
mockKanbanApi.getAssignees.mockResolvedValue([])
const store = useKanbanStore()
store.setSelectedBoard('project-a')
await store.fetchCapabilities()
await store.linkTasks('task-1', 'task-2')
await store.unlinkTasks('task-1', 'task-2')
await expect(store.bulkUpdateTasks({ ids: ['task-1'], status: 'done', assignee: null, summary: 'closed' })).resolves.toEqual({ results: [{ id: 'task-1', ok: true }] })
expect(mockKanbanApi.linkTasks).toHaveBeenCalledWith({ parent_id: 'task-1', child_id: 'task-2' }, { board: 'project-a' })
expect(mockKanbanApi.unlinkTasks).toHaveBeenCalledWith({ parent_id: 'task-1', child_id: 'task-2' }, { board: 'project-a' })
expect(mockKanbanApi.bulkUpdateTasks).toHaveBeenCalledWith({ ids: ['task-1'], status: 'done', assignee: null, summary: 'closed' }, { board: 'project-a' })
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ board: 'project-a', status: undefined, assignee: undefined, includeArchived: true })
})
it('opens board-scoped event streams, refreshes on events, and reconnects on board switch', async () => {
vi.useFakeTimers()
const socketA = { close: vi.fn(), onmessage: null as ((event: { data: string }) => void) | null, onclose: null, onerror: null }
const socketB = { close: vi.fn(), onmessage: null as ((event: { data: string }) => void) | null, onclose: null, onerror: null }
mockKanbanApi.openKanbanEventStream
.mockReturnValueOnce(socketA)
.mockReturnValueOnce(socketB)
mockKanbanApi.getCapabilities.mockResolvedValue({
source: 'hermes-cli',
supports: {},
missing: [],
capabilities: [{ key: 'events', status: 'partial', requiresBoard: true }],
})
mockKanbanApi.listTasks.mockResolvedValue([])
mockKanbanApi.getStats.mockResolvedValue({ total: 0, by_status: {}, by_assignee: {} })
mockKanbanApi.getAssignees.mockResolvedValue([])
const store = useKanbanStore()
store.setSelectedBoard('project-a')
await store.fetchCapabilities()
expect(store.startEventStream()).toBe(true)
expect(mockKanbanApi.openKanbanEventStream).toHaveBeenCalledWith({ board: 'project-a' })
socketA.onmessage?.({ data: JSON.stringify({ type: 'event', line: 'changed' }) })
await vi.advanceTimersByTimeAsync(100)
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ board: 'project-a', status: undefined, assignee: undefined, includeArchived: true })
expect(mockKanbanApi.getStats).toHaveBeenCalledWith({ board: 'project-a' })
expect(mockKanbanApi.getAssignees).toHaveBeenCalledWith({ board: 'project-a' })
store.setSelectedBoard('default')
expect(socketA.close).toHaveBeenCalled()
expect(mockKanbanApi.openKanbanEventStream).toHaveBeenLastCalledWith({ board: 'default' })
store.stopEventStream()
expect(socketB.close).toHaveBeenCalled()
vi.useRealTimers()
})
it('passes selected board to parity actions and refreshes affected board state', async () => {
mockKanbanApi.getCapabilities.mockResolvedValue({
source: 'hermes-cli',
+4
View File
@@ -32,6 +32,8 @@ const mockSetFilter = vi.hoisted(() => vi.fn())
const mockRecoverSelectedBoard = vi.hoisted(() => vi.fn())
const mockCreateBoard = vi.hoisted(() => vi.fn())
const mockArchiveSelectedBoard = vi.hoisted(() => vi.fn())
const mockStartEventStream = vi.hoisted(() => vi.fn())
const mockStopEventStream = vi.hoisted(() => vi.fn())
vi.mock('vue-router', () => ({
useRoute: () => routeState,
@@ -57,6 +59,8 @@ vi.mock('@/stores/hermes/kanban', () => ({
recoverSelectedBoard: mockRecoverSelectedBoard,
createBoard: mockCreateBoard,
archiveSelectedBoard: mockArchiveSelectedBoard,
startEventStream: mockStartEventStream,
stopEventStream: mockStopEventStream,
}),
}))