diff --git a/frontend-v2/src/features/collaboration/README.md b/frontend-v2/src/features/collaboration/README.md index 3d1c6c7aa..5fca4f5eb 100644 --- a/frontend-v2/src/features/collaboration/README.md +++ b/frontend-v2/src/features/collaboration/README.md @@ -15,18 +15,19 @@ ## 已经有的 - 任务列表显示状态、标题、项目、指派对象,以及谁在干活(某个 Agent 执行中、等待追问)。看板按「待处理 / 进行中 / 待验收 / 已完成」分列,「已取消」默认隐藏。把卡片拖到另一列,等同于点任务里对应的推进按钮:拖动时只有合法的下一步亮起,状态逐级推进,不能跳过待验收;Agent 正在执行的卡片拿不起来;指派给 Agent 的任务只能在任务里「开始处理」进入进行中,不能拖进去。松手后卡片立即移动,服务端拒绝(例如 `409 run_active`)时退回原列,并弹出提示说明原因,几秒后自动消失。拖动只支持指针,键盘用任务页的按钮。窄屏下看板变成单列。 -- **拆分**:大需求在任务页点「拆分」,选一个已发布的工作流(默认「需求拆分」)运行,任务的标题和描述是输入。能否拆分由服务端判定(`GET …/decomposition-workflows`,客户端在 `decomposition-api/`):可拆分的排在前面,不可拆分的放进禁用分组「不可拆分(缺少 tasks 输出)」,下面的折叠说明只写一次原因,再列出它挡住的工作流名;启动被拒绝时显示服务端 `params.message`。跑完后输出的 `tasks` 变成这个任务的子任务:待处理、未指派、同一个项目,任务页列出它们,看板上子任务标着「拆分自 …」,大需求标着「N 个子任务」,Tech Lead 再把它们分给人和 Agent。拆分中按钮变成「拆分中…」,失败时任务页写明原因并可「重新拆分」。子任务不能再拆。工作流运行也在工作流页的运行历史里。 +- **拆分**:大需求在任务页点「拆分」,选一个已发布的工作流(默认「需求拆分」)运行,任务的标题和描述是输入。能否拆分由服务端判定(`GET …/decomposition-workflows`,客户端在 `decomposition-api/`):可拆分的排在前面,不可拆分的放进禁用分组「不可拆分(缺少 tasks 输出)」,下面的折叠说明只写一次原因,再列出它挡住的工作流名;启动被拒绝时显示服务端 `params.message`。跑完后输出的 `tasks` 变成这个任务的子任务:待处理、未指派、同一个项目,任务页列出它们,看板上子任务标着「拆分自 …」,大需求标着「N 个子任务」,Tech Lead 再把它们分给人和 Agent。只有待处理、进行中的任务能拆,谁能拆见下文「谁能改任务」。拆分中按钮变成「拆分中…」,失败时任务页写明原因;任务仍能拆时可以「重新拆分」,没有权限的人看到禁用的按钮和原因。子任务不能再拆。工作流运行也在工作流页的运行历史里。 - **工作流页签**:始终显示,按持久任务身份列出处理、拆分、巡检来源与评论 @ 四类记录,包含版本、真实发起人、状态、失败原因与时间;不按标题匹配。点一行在页签里打开同一个运行视图(`?tab=workflows&workflow=<运行 id>`),巡检来源不再跳转到对话页。拆分开始后直接打开运行。运行视图不提供启动和重跑;能查看任务的成员可在活处理运行的列表或打开的运行中点「停止」,使用对话页同一取消接口,不限发起人。标题左边返回列表;页头「工作区」查看这次运行的文件。打开运行时收起输入框并折叠子任务,让画布获得空间。 - 任务指派给人、可执行的预装 Agent 或未归档的小队;指派给小队不挑具体的人:每个队员的「我的任务」都有它,队员还没评论或开始处理时它也在「待我处理」,卡片标出是哪个小队派来的。 - **执行**:指派给 Agent 的任务在右侧选模型后「开始处理」,用你的身份运行,任务进入进行中,一轮结束自动进入待验收;停止或服务重启后回到待处理。Agent 执行期间不能手动推进状态。已经有运行时按钮是「重新执行」,会结束空闲的旧会话。运行开始后和对话页一样显示准备阶段:列出全部阶段、当前第几步和已用时,首次输出后收起为总用时。项目第一次用某个 Agent 要先在 Node 里安装,这段时间算在「安装插件」里。 - **工作区**:页头的「工作区」打开当前运行的文件和 diff,占掉右侧属性栏的位置,可以拖宽,关掉后属性栏恢复。390px 下工作区占用可用全宽,关闭后返回任务,避免挤压任务与文件内容。每次 Agent 运行和每次工作流运行都有自己的目录,互相看不到改动,所以面板标明正在看哪次运行;没有运行在屏幕上时,它打开最新一次。变更和 diff 读这次运行最近一次成功的回合交付,可以下载 patch;交付失败时任务回到待处理(服务端),失败原因显示在这次运行的工作区面板「变更」上方,规则与对话相同(见根目录 README 的对话一节);任务的工作流处理运行按工作流的规则,任一节点交付失败都会提示并写明节点。 -- **派给人的任务**:负责人本人可以在右侧「用 Agent 处理」:从自己能用的全部 Agent 与模型里选一个,用自己的身份开一次运行,之后和 Agent 任务一样(跑完进入待验收、可停止、只有发起人能追问)。其他人看不到这组控件,输入框只发评论;负责人不用 Agent 时照旧手动推进。 +- **派给人的任务**:负责人本人可以在右侧「用 Agent 处理」:从自己能用的全部 Agent 与模型里选一个,用自己的身份开一次运行,之后和 Agent 任务一样(跑完进入待验收、只有发起人能追问)。停止由发起人、任务创建人或工作区 owner 来做;创建人和 owner 看不到「用 Agent 处理」,但运行时右侧有「执行」一节可以停止。其他人看不到这组控件,输入框只发评论;负责人不用 Agent 时照旧手动推进。 - **用工作流处理**:权限与 Agent 处理一致:人类负责人本人、小队当前成员,以及 Agent 任务的任一工作区成员可见,其他成员看到不可用原因;不受 demo 开关控制。明确选择已发布工作流,编辑需求及 Start 变量后,以负责人的身份启动;服务端固定项目与发布快照、持久记录关联并按幂等键防重。活 Agent 会话(含空闲会话)与处理工作流互斥。开始进入进行中,成功或失败进入待验收,执行后取消或重启中断回到待处理;执行前就被停止或删除的启动不算发生过,任务保持原状态,提交后启动失败而运行已开始执行的改由宿主停止并按真实结果结算。按处理关联自己的修订号与所写任务状态防护,元数据与指派修改不阻止结算;状态循环会撤销旧运行的状态所有权;活处理运行期间禁止人工推进与关闭任务,能查看任务的成员先在「工作流」页签点击「停止」。启动前拒绝不创建关联、不移动状态;提交后拒绝恢复原状态;拆分与巡检不推进状态。 - **派给小队的任务**:和派给人的任务一样,任一队员都能用自己能用的 Agent 与模型开运行;同一时间一个运行,只有发起人能追问,其他队员可以重新执行。队外的人可以评论,不能开运行。 - **运行过程**:全团队都能看每次运行的思考、工具调用和回答,按运行切换;运行结束的原因(停止、被重新执行替代、任务结束、重启中断)和最近一轮的结果写在运行上方。 - **讨论与 @**:能发给这个任务的 Agent 时(指派了 Agent、它没在执行、调用者是当前运行的发起人或还没有运行),输入框默认发给 Agent,评论同时全团队可见;关掉「发给 Agent」就只发团队评论;发不了时开关关闭并说明原因。输入 `@` 弹出工作区成员、Agent 和已发布的工作流:选成员是提及,被提及的人在回复前会在「待我处理」里看到这个任务,卡片标着谁 @ 了他;选这个任务的 Agent 等同打开「发给 Agent」;选工作流会加载它的启动表单、按字段校验输入,发送后以评论人身份启动运行(不改变任务状态、不占用处理锁),并在讨论时间线卡片实时显示运行状态、链接(`?tab=workflows&workflow=<运行 id>`)与完成后的输出。只有从菜单选中的对象算数,正文里手打的「@名字」不路由。 - **谁能追问**:运行属于发起人,只有发起人能追问(不然就是用别人的身份跑);其他成员的「发给 Agent」是灰的并写明原因,他们可以评论,或重新执行用自己的身份开一次新运行。 -- **谁能结束任务**:「确认完成」和「取消任务」只限任务创建人和工作区 owner,由服务端判定(其他人 `403`)。负责人负责开始和提交验收,不能验收自己接到的任务;自己建给自己的任务,创建人身份照常可以结束。其他人在任务页看到禁用的按钮和原因,在看板上拖到这两列会被拦下并说明原因。其余操作(编辑、指派、拆分、停止)目前仍对全体成员开放。 +- **谁能结束任务**:「确认完成」「取消任务」和待验收时的「退回待处理」只限任务创建人和工作区 owner,由服务端判定(其他人 `403`)。负责人负责开始和提交验收,不能验收自己接到的任务;验收不通过时创建人把任务退回待处理让负责人返工,不必只能取消。自己建给自己的任务,创建人身份照常可以结束。其他人在任务页看到禁用的按钮和原因,在看板上拖到这几列会被拦下并说明原因。 +- **谁能改任务**:编辑、改派、拆分只限创建人、工作区 owner 和当前负责人(派给人的是负责人本人,派给小队的是现任队员);Agent 任务没有人类负责人,只有创建人和 owner 能改。停止运行只限运行发起人、创建人和 owner。已结束的任务只读,Agent 正在执行一轮时不能改派。都由服务端判定,前端用同一套规则(`task-views.ts` 的 `canManageTask`、`canStopRun`)禁用按钮并写明谁能做。 - **按指派对象筛选**:「全部任务」页头可以按人、Agent、小队或未指派筛选(`?assignee=human:`、`?assignee=none`),只列手上有任务的对象和数量;和小队切换互斥,选一个清掉另一个。 - 写操作按任务 version 做乐观校验;被拒绝时按服务端的码给出原因,不静默重试。 diff --git a/frontend-v2/src/features/collaboration/task-decomposition.tsx b/frontend-v2/src/features/collaboration/task-decomposition.tsx index 8248d7909..d944e36cf 100644 --- a/frontend-v2/src/features/collaboration/task-decomposition.tsx +++ b/frontend-v2/src/features/collaboration/task-decomposition.tsx @@ -96,9 +96,11 @@ export function DecomposeDialog({ tenantId, task, onClose, onStarted }: { /** * The task's family on its page: for a big requirement, its latest decomposition and the subtasks * it wrote; for a subtask, the requirement it came from. The subtasks fold away, and start folded - * when `folded` says the page needs the room; a person's own choice then holds. + * when `folded` says the page needs the room; a person's own choice then holds. A failed + * decomposition offers 「重新拆分」 only while the task may be split (`onRetry` given); when the + * caller may not split it, `retryRefusal` says who can and the button stays disabled. */ -export function TaskFamily({ tenantId, task, latest, folded = false, onRetry }: { tenantId: string; task: Task; latest?: TaskDecomposition; folded?: boolean; onRetry: () => void }) { +export function TaskFamily({ tenantId, task, latest, folded = false, onRetry, retryRefusal = '' }: { tenantId: string; task: Task; latest?: TaskDecomposition; folded?: boolean; onRetry?: () => void; retryRefusal?: string }) { const list = useTaskList(tenantId) const [picked, setPicked] = useState() const open = picked ?? !folded @@ -113,7 +115,7 @@ export function TaskFamily({ tenantId, task, latest, folded = false, onRetry }: if (!latest && subtasks.length === 0) return null return
- {latest && } + {latest && } {subtasks.length > 0 && } @@ -128,7 +130,7 @@ export function TaskFamily({ tenantId, task, latest, folded = false, onRetry }:
} -function DecompositionStatus({ decomposition: d, onRetry }: { decomposition: TaskDecomposition; onRetry: () => void }) { +function DecompositionStatus({ decomposition: d, onRetry, refusal }: { decomposition: TaskDecomposition; onRetry?: () => void; refusal: string }) { switch (d.status) { case 'running': return

} } diff --git a/frontend-v2/src/features/collaboration/task-detail.tsx b/frontend-v2/src/features/collaboration/task-detail.tsx index 3c1032c8f..730557608 100644 --- a/frontend-v2/src/features/collaboration/task-detail.tsx +++ b/frontend-v2/src/features/collaboration/task-detail.tsx @@ -5,7 +5,7 @@ import type { SquadSummary } from '@/lib/squads-api/generated' import { formatTime } from './task-model' import { TaskAssigneePicker } from '@/components/task-assignee-picker' import { assigneeKindLabel, assigneeLabel, isTaskFinished, taskActions } from './task-model' -import { closeRefusal, runsAgent } from './task-views' +import { closeRefusal, manageRefusal, needsCloser, runsAgent, stopRefusal } from './task-views' import type { Task, TaskAssigneeRef, TaskExecutor, TaskStatusProperty } from './tasks-api/generated' /** The run controls' state, decided by the page from the task and its timeline. */ @@ -26,14 +26,18 @@ export interface RunControls { * One task's facts and the moves on it: who owns it, running its Agent, and the manual status * moves. While the Agent runs a turn, the run owns the status, so manual moves wait for it. */ -export function TaskDetailView({ task, me, inSquad, canClose, projectName, squads, busy, workflowActive = false, error, run, onWorkflow, onStatus, onAssign }: { +export function TaskDetailView({ task, me, inSquad, canClose, canManage, canStop, projectName, squads, busy, workflowActive = false, error, run, onWorkflow, onStatus, onAssign }: { task: Task /** The caller's user id: a person's task runs an Agent only for that person. */ me: string /** The caller is a member of the squad that owns the task. */ inSquad: boolean - /** The caller may end the task: confirm it or cancel it. */ + /** The caller may end the task (confirm or cancel it) or send it back from 待验收. */ canClose: boolean + /** The caller may edit, reassign or split the task. */ + canManage: boolean + /** The caller may stop the task's live run. */ + canStop: boolean /** The project's display name, resolved from the workspace list. */ projectName: string /** Live squads the task may be reassigned to. */ @@ -70,8 +74,12 @@ export function TaskDetailView({ task, me, inSquad, canClose, projectName, squad

指派对象

- +

当前:{assigneeLabel(task)}{task.assignee && `(${assigneeKindLabel(task)})`}。{task.assignee?.type === 'squad' && '每个队员都会收到,任一队员都能评论和用 Agent 处理。'}

+ {finished + ?

任务已结束,不能再改派。

+ : !canManage ?

{manageRefusal(task, '改派')}

+ : running &&

Agent 正在执行,等这一轮结束或先停止,再改派。

}
{runsAgent(task, me, inSquad) &&
@@ -89,9 +97,7 @@ export function TaskDetailView({ task, me, inSquad, canClose, projectName, squad {run.hasRuns ? : } {run.starting ? '正在启动…' : run.hasRuns ? '重新执行' : personal ? '用 Agent 处理' : '开始处理'} - {task.activeRun && } + {task.activeRun && }

{running @@ -105,6 +111,14 @@ export function TaskDetailView({ task, me, inSquad, canClose, projectName, squad }

} + {!runsAgent(task, me, inSquad) && task.activeRun &&
+

执行

+

{running ? `${task.activeRun.startedByName} 发起的运行正在执行。` : `${task.activeRun.startedByName} 的会话在等追问。`}

+ {canStop + ?
+ :

{stopRefusal(task)}

} +
} + {onWorkflow &&
{runsAgent(task, me, inSquad) ? @@ -121,13 +135,21 @@ export function TaskDetailView({ task, me, inSquad, canClose, projectName, squad ?

运行正在执行,结束后再推进。

: <>
{actions.map(action => { - const refused = isTaskFinished(action.status) && !canClose - return + const refused = needsCloser(task.status, action.status) && !canClose + return })}
- {!canClose &&

{task.status === 'review' ? `等待 ${task.createdByName} 验收。${closeRefusal(task, '确认完成或取消任务')}` : closeRefusal(task, '取消任务')}

} + {!canClose &&

{task.status === 'review' ? `等待 ${task.createdByName} 验收。${closeRefusal(task, '确认完成、退回或取消任务')}` : closeRefusal(task, '取消任务')}

} + {canClose && task.status === 'review' &&

不满意可以退回待处理,让负责人返工。

} }
{error &&

{error}

} } + +/** Stops the live run's turn, or ends its idle session; refused callers see who can. */ +function StopButton({ running, stopping, refusal, onStop }: { running: boolean; stopping: boolean; refusal: string; onStop: () => void }) { + return +} diff --git a/frontend-v2/src/features/collaboration/task-model.test.ts b/frontend-v2/src/features/collaboration/task-model.test.ts index ea3b0fec4..067c19c6e 100644 --- a/frontend-v2/src/features/collaboration/task-model.test.ts +++ b/frontend-v2/src/features/collaboration/task-model.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import type { Task } from './tasks-api/generated' import { assigneeKindLabel, assigneeLabel, isTaskFinished, MAX_TASK_TITLE, projectLabel, taskActions, - boardMoveMessageFor, decompositionMessageFor, taskMessageFor, taskRunMessageFor, taskStatusLabel, validateTask, + boardMoveMessageFor, decompositionMessageFor, stopMessageFor, taskMessageFor, taskRunMessageFor, taskStatusLabel, validateTask, } from './task-model' const task = (overrides: Partial = {}): Task => ({ @@ -21,7 +21,7 @@ describe('task status', () => { it('moves one step at a time and never reopens a finished task', () => { expect(taskActions('pending')).toEqual([{ status: 'running', label: '开始处理' }, { status: 'cancelled', label: '取消任务' }]) expect(taskActions('running').map(action => action.status)).toEqual(['review', 'cancelled']) - expect(taskActions('review').map(action => action.status)).toEqual(['done', 'cancelled']) + expect(taskActions('review').map(action => action.status)).toEqual(['done', 'pending', 'cancelled']) expect(taskActions('done')).toEqual([]) expect(taskActions('cancelled')).toEqual([]) expect(isTaskFinished('done')).toBe(true) @@ -72,6 +72,15 @@ describe('task errors', () => { expect(taskMessageFor(http(400, 'invalid_project'))).toBe('所选项目不在当前工作区,请重新选择。') }) + it('names who may change a task, and that a finished one is read-only', () => { + expect(taskMessageFor(http(403, 'forbidden'))).toBe('只有创建人、负责人或工作区管理员能修改这个任务。') + expect(taskMessageFor(http(409, 'task_closed'))).toBe('任务已结束,只能查看,不能再修改。') + expect(taskMessageFor(http(409, 'run_active'))).toBe('Agent 正在执行,等这一轮结束或先停止,再改派。') + expect(taskMessageFor(http(409, 'version_conflict'))).toBe('任务已被其他人修改,请关闭后重新打开。') + expect(stopMessageFor(http(403, 'forbidden'))).toBe('只有运行发起人、任务创建人或工作区管理员能停止这次运行。') + expect(stopMessageFor(http(409, 'no_live_run'))).toBe('这次运行已经结束了。') + }) + it('falls back for anything else', () => { expect(taskMessageFor(new Error('boom'))).toBe('操作失败,请重试。') }) @@ -81,7 +90,7 @@ describe('task errors', () => { expect(boardMoveMessageFor(http(409, 'workflow_active'))).toBe('工作流正在处理这个任务,结束后任务会自动推进,之后再改状态。') expect(boardMoveMessageFor(http(409, 'version_conflict'))).toBe('任务刚被其他人改过,看板已刷新,请再拖一次。') expect(boardMoveMessageFor(http(400, 'invalid_transition'))).toContain('待处理 → 进行中 → 待验收 → 已完成') - expect(boardMoveMessageFor(http(403, 'forbidden'))).toBe('只有任务创建人或工作区管理员能确认完成或取消任务。') + expect(boardMoveMessageFor(http(403, 'forbidden'))).toBe('只有任务创建人或工作区管理员能确认完成、退回或取消任务。') expect(taskRunMessageFor(http(400, 'workflow_role_not_found'))).toBe('工作流引用的角色在工作区角色目录里不存在,请先在设置的角色页新建同名角色再启动。') }) }) @@ -100,4 +109,9 @@ describe('decomposition refusals', () => { expect(decompositionMessageFor(fault('decomposition_output_required', { message: 7 }))).toBe('所选工作流的输出不满足拆分要求,请修改后重新发布。') expect(decompositionMessageFor(fault('invalid_workflow'))).toBe('所选工作流不存在或还没有发布,请重新选择。') }) + + it('says why a task cannot be split now', () => { + expect(decompositionMessageFor(fault('task_in_review'))).toBe('任务在待验收,不能拆分;退回待处理后再拆。') + expect(decompositionMessageFor({ isAxiosError: true, response: { status: 403, data: { code: 'forbidden', requestId: 'r' } } })).toBe('只有创建人、负责人或工作区管理员能拆分这个任务。') + }) }) diff --git a/frontend-v2/src/features/collaboration/task-model.ts b/frontend-v2/src/features/collaboration/task-model.ts index 202e091ab..1ddbbe654 100644 --- a/frontend-v2/src/features/collaboration/task-model.ts +++ b/frontend-v2/src/features/collaboration/task-model.ts @@ -34,14 +34,14 @@ export interface TaskAction { const ACTIONS: Record = { pending: [{ status: 'running', label: '开始处理' }, { status: 'cancelled', label: '取消任务' }], running: [{ status: 'review', label: '提交验收' }, { status: 'cancelled', label: '取消任务' }], - review: [{ status: 'done', label: '确认完成' }, { status: 'cancelled', label: '取消任务' }], + review: [{ status: 'done', label: '确认完成' }, { status: 'pending', label: '退回待处理' }, { status: 'cancelled', label: '取消任务' }], done: [], cancelled: [], } /** * The moves a person may make by hand. This mirrors the server's `CanTransitionTask`: review is - * never skipped, and a finished task never reopens. + * never skipped, a finished task never reopens, and 待验收 may go back to 待处理 for rework. */ export const taskActions = (status: string): TaskAction[] => ACTIONS[status as TaskStatus] ?? [] @@ -74,9 +74,13 @@ export function validateTask(title: string, description: string): Record { expect(within(dialog).getByRole('button', { name: '开始拆分' })).toBeDisabled() }) +it('offers to split again after a failure only while the caller may split the task', async () => { + workspace.role = 'member' + const failed = { items: [decomposition({ status: 'failed', failure: '工作流的输出里没有 tasks 数组。' })] } + vi.mocked(api.listTaskDecompositions).mockResolvedValue(failed) + // Someone else's requirement, assigned to someone else: the button stays, disabled, and says who can. + vi.mocked(api.getTask).mockResolvedValue({ ...requirement, createdBy: 'user-lead', createdByName: '陈默', assignee: { type: 'human', id: 'user-doer', displayName: '鲍勃' } }) + const { unmount } = renderPage() + const retry = await screen.findByRole('button', { name: '重新拆分' }) + expect(retry).toBeDisabled() + expect(retry).toHaveAttribute('title', '只有创建人 陈默、负责人 鲍勃 或工作区管理员能拆分。') + unmount() + // A requirement in 待验收 is not split at all, so the failure offers no retry. + vi.mocked(api.getTask).mockResolvedValue({ ...requirement, status: 'review' }) + renderPage() + expect(await screen.findByRole('alert')).toHaveTextContent('拆分失败') + expect(screen.queryByRole('button', { name: '重新拆分' })).not.toBeInTheDocument() +}) + it('names the requirement a subtask came from and offers no split', async () => { vi.mocked(api.getTask).mockResolvedValue(task({ id: 'task-1', parentId: 'parent-1' })) vi.mocked(api.listTasks).mockResolvedValue({ nextCursor: '', items: [task({ id: 'parent-1', title: '账号体系' })] }) @@ -491,13 +509,49 @@ it('opens the linked historical run instead of the newest run',async()=>{ const handedToMe = (status: Task['status']) => task({ status, createdBy: 'user-lead', createdByName: '陈默', assignee: { type: 'human', id: 'user-me', displayName: '演示用户' } }) -it('keeps 确认完成 and 取消任务 from an assignee, and says who decides', async () => { +it('keeps 确认完成, 退回待处理 and 取消任务 from an assignee, and says who decides', async () => { workspace.role = 'member' vi.mocked(api.getTask).mockResolvedValue(handedToMe('review')) renderPage() expect(await screen.findByRole('button', { name: '确认完成' })).toBeDisabled() + expect(screen.getByRole('button', { name: '退回待处理' })).toBeDisabled() expect(screen.getByRole('button', { name: '取消任务' })).toBeDisabled() - expect(screen.getByText('等待 陈默 验收。只有创建人 陈默 或工作区管理员能确认完成或取消任务。')).toBeInTheDocument() + expect(screen.getByText('等待 陈默 验收。只有创建人 陈默 或工作区管理员能确认完成、退回或取消任务。')).toBeInTheDocument() + // Editing stays with whoever does the work. + expect(screen.getByRole('button', { name: '编辑' })).toBeEnabled() +}) + +it('lets the creator send work in 待验收 back for rework', async () => { + workspace.role = 'member' + const askedByMe = (status: Task['status']) => task({ status, createdBy: 'user-me', createdByName: '演示用户', assignee: { type: 'human', id: 'user-doer', displayName: '鲍勃' } }) + vi.mocked(api.getTask).mockResolvedValue(askedByMe('review')) + vi.mocked(api.setTaskStatus).mockResolvedValue(askedByMe('pending')) + renderPage() + await userEvent.click(await screen.findByRole('button', { name: '退回待处理' })) + await waitFor(() => expect(api.setTaskStatus).toHaveBeenCalledWith('tenant', 'task-1', { status: 'pending', version: 1 })) +}) + +it('keeps editing, reassigning and stopping from a member with no part in the task, and says who can', async () => { + workspace.role = 'member' + vi.mocked(api.getTask).mockResolvedValue(task({ status: 'running', createdBy: 'user-lead', createdByName: '陈默', + assignee: { type: 'human', id: 'user-doer', displayName: '鲍勃' }, + activeRun: { id: 'run-1', state: 'running', startedBy: 'user-doer', startedByName: '鲍勃', executorName: 'Claude Code / Sonnet' } })) + renderPage() + const edit = await screen.findByRole('button', { name: '编辑' }) + expect(edit).toBeDisabled() + expect(edit).toHaveAttribute('title', '只有创建人 陈默、负责人 鲍勃 或工作区管理员能编辑。') + expect(screen.getByText('只有创建人 陈默、负责人 鲍勃 或工作区管理员能改派。')).toBeInTheDocument() + expect(screen.getByText('只有发起人 鲍勃、创建人 陈默 或工作区管理员能停止这次运行。')).toBeInTheDocument() + expect(screen.queryByRole('button', { name: '停止' })).not.toBeInTheDocument() +}) + +it('lets the creator stop a run on work assigned to someone else', async () => { + workspace.role = 'member' + vi.mocked(api.getTask).mockResolvedValue(task({ status: 'running', createdBy: 'user-me', createdByName: '演示用户', + assignee: { type: 'human', id: 'user-doer', displayName: '鲍勃' }, + activeRun: { id: 'run-1', state: 'running', startedBy: 'user-doer', startedByName: '鲍勃', executorName: 'Claude Code / Sonnet' } })) + renderPage() + expect(await screen.findByRole('button', { name: '停止' })).toBeEnabled() }) it('leaves an assignee the moves that are theirs', async () => { diff --git a/frontend-v2/src/features/collaboration/task-page.tsx b/frontend-v2/src/features/collaboration/task-page.tsx index 20ca648b1..89d18f5ad 100644 --- a/frontend-v2/src/features/collaboration/task-page.tsx +++ b/frontend-v2/src/features/collaboration/task-page.tsx @@ -22,12 +22,12 @@ import { TaskForm, type TaskDraft } from './task-form' import { TaskWorkflowDialog } from './task-workflow-dialog' import { TaskWorkflows } from './task-workflows' import { statusOf } from '@/lib/api-client' -import { projectLabel, taskMessageFor, taskMoveMessageFor, taskRunMessageFor, taskStatusLabel } from './task-model' +import { isTaskFinished, projectLabel, stopMessageFor, taskMessageFor, taskMoveMessageFor, taskRunMessageFor, taskStatusLabel } from './task-model' import { createTaskComment, getTask, getTaskTimeline, listTaskExecutors, setTaskAssignee, setTaskStatus, startTaskRun, stopTaskRun, updateTask, type Task, type TaskAssigneeRef, type TaskComment, type TaskStatusProperty, } from './tasks-api/generated' -import { canCloseTask, canDecompose, runsAgent } from './task-views' +import { canCloseTask, canDecompose, canManageTask, canStopRun, manageRefusal, runsAgent } from './task-views' import { useDecompositions, useMySquadTasks, useWorkspace } from './workspace' /** Fresh idempotency key for one submission: a retry of the same click reuses it. */ @@ -211,7 +211,7 @@ export default function TaskPage() { const stop = useMutation({ mutationFn: (runId: string) => stopTaskRun(tenantId, taskId, runId), onSuccess: async () => { setError(''); await refresh() }, - onError: e => setError(taskRunMessageFor(e)), + onError: e => setError(stopMessageFor(e)), }) const commentKeyRef = useRef<{ signature: string; key: string } | null>(null) const comment = useMutation({ @@ -242,16 +242,18 @@ export default function TaskPage() { } const projectList = projects.data?.items ?? [] + const canManage = canManageTask(task, me.id, role, inSquad) + const editRefusal = isTaskFinished(task.status) ? '任务已结束,只能查看。' : canManage ? '' : manageRefusal(task, '编辑') return
{taskStatusLabel(task.status)}

{task.title}

- {canDecompose(task) && } + {canDecompose(task) && } {(newestRun || selected) && } - +
{task.description &&

{task.description}

} - setDecomposing(true)} /> + setDecomposing(true) : undefined} retryRefusal={canManage ? '' : manageRefusal(task, '拆分')} />
@@ -291,7 +294,7 @@ export default function TaskPage() { }} />}
{!workspaceShown &&