mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 17:49:48 +00:00
feat(dashboard): add workflow tasks monitoring and stopping to team dashboard (#489)
* feat(dashboard): add workflow tasks monitoring and stopping to team dashboard * fix(asset): retain workflow tasks on asset purge and mark active tasks as failed * style(webui): add edge padding to audit logs and workflow tasks tables * fix(workflow): atomically update asset status to failed when task is stopped * fix(workflow): propagate cancellation errors, guard concurrent task stop, and localize UI * docs(changelog): keep only added log for workflow tasks dashboard * test(provider): mock upstream catalog api calls using saved fixtures * feat(dashboard): show file name, size, and project name in workflow tasks list
This commit is contained in:
@@ -68,6 +68,14 @@ vi.mock('@shumai/core/src/gotenberg/gotenberg', () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@shumai/core/src/workflowTask/workflowTask', () => ({
|
||||
workflowTaskService: {
|
||||
listWorkflowTasks: vi.fn(),
|
||||
getBatchWorkflowTaskStatus: vi.fn(),
|
||||
stopWorkflowTask: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
describe('team api', () => {
|
||||
const app = new Hono().use('*', authMiddleware).route('/', teamRoute)
|
||||
let mockCreateTeam: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
@@ -655,6 +663,129 @@ describe('team api', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/workflow-tasks returns list of workflow tasks for team owner', async () => {
|
||||
const { workflowTaskService } = await import('@shumai/core/src/workflowTask/workflowTask')
|
||||
vi.mocked(workflowTaskService.listWorkflowTasks).mockResolvedValue({
|
||||
nodes: [
|
||||
{
|
||||
id: 'task1',
|
||||
uid: 'uid1',
|
||||
teamId: 't1',
|
||||
projectId: 'p1',
|
||||
assetId: 'a1',
|
||||
type: 'transcode_video' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
status: 'processing' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
payload: {},
|
||||
output: null,
|
||||
heartbeat: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
model: null,
|
||||
sessionId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
pageInfo: {
|
||||
hasNextPage: false,
|
||||
endCursor: null,
|
||||
},
|
||||
total: 1,
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/workflow-tasks')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const data = await res.json()
|
||||
expect(data.nodes).toHaveLength(1)
|
||||
expect(data.nodes[0].id).toBe('task1')
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
permission: Permission.Admin,
|
||||
type: ResourceType.Team,
|
||||
id: 't1',
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('POST /teams/:teamId/workflow-tasks/batch-status returns batch task statuses', async () => {
|
||||
const { workflowTaskService } = await import('@shumai/core/src/workflowTask/workflowTask')
|
||||
vi.mocked(workflowTaskService.getBatchWorkflowTaskStatus).mockResolvedValue({
|
||||
tasks: [
|
||||
{
|
||||
id: 'task1',
|
||||
uid: 'uid1',
|
||||
teamId: 't1',
|
||||
projectId: 'p1',
|
||||
assetId: 'a1',
|
||||
type: 'transcode_video' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
status: 'completed' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
payload: {},
|
||||
output: null,
|
||||
heartbeat: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
model: null,
|
||||
sessionId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/workflow-tasks/batch-status', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ taskIds: ['task1'] }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const data = await res.json()
|
||||
expect(data.tasks).toHaveLength(1)
|
||||
expect(data.tasks[0].status).toBe('completed')
|
||||
})
|
||||
|
||||
it('POST /teams/:teamId/workflow-tasks/:taskId/stop stops task for team owner', async () => {
|
||||
const { workflowTaskService } = await import('@shumai/core/src/workflowTask/workflowTask')
|
||||
vi.mocked(workflowTaskService.stopWorkflowTask).mockResolvedValue({
|
||||
success: true,
|
||||
task: {
|
||||
id: 'task1',
|
||||
uid: 'uid1',
|
||||
teamId: 't1',
|
||||
projectId: 'p1',
|
||||
assetId: 'a1',
|
||||
type: 'transcode_video' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
status: 'failed' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
payload: {},
|
||||
output: { error: 'Task was stopped by user' },
|
||||
heartbeat: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
model: null,
|
||||
sessionId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/workflow-tasks/task1/stop', {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const data = await res.json()
|
||||
expect(data.success).toBe(true)
|
||||
expect(data.task.status).toBe('failed')
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
permission: Permission.Admin,
|
||||
type: ResourceType.Team,
|
||||
id: 't1',
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/turntable-settings returns turntable settings', async () => {
|
||||
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
|
||||
vi.mocked(turntableService.getSettings).mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user