test(workbench): A05 两席闭环装配层联调;修派发状态只写 state 的 bug
- 装配层:POST /dispatch 真投递 → 契约行回执 → Result → 终态成功 → completed - dispatch-service 对派发行同时写 status 与 state(UI 读 status,原来永远看到 prepared) - 全量 211/211
This commit is contained in:
parent
e37c7efa29
commit
defa0307df
|
|
@ -30,7 +30,7 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| A02 | 切 A/B、重命名/移动项目不换 session | 已验(单测) | `registerProject 同一工作区只建一个项目`;绑定只用 `hostWorkspaceId` 与 `bindingGeneration`,名称变更不触碰绑定 |
|
||||
| A03 | 点分组节点不创建项目或十席会话 | 已验(单测) | `layoutGroups renders three tiers without inventing parent links`;`initial seats describe configuration rows without creating sessions` |
|
||||
| A04 | 双击首次启动同部门只建一个 session | 已验(单测)+ 待真机 | `会话适配:缺 sessionId 时按 workspace 建会话且不重复建`;`绑定:同一会话被别处持有 → SESSION_CONFLICT`。真机二次点击要复验(U4) |
|
||||
| A05 | 十席分别发短消息,输入/历史/实际 session 一致 | 待真机 | 派发按 `targetSessionId` + `bindingGeneration` 双校验(`dispatchTask` 内),缺真实会话层证据 |
|
||||
| A05 | 十席分别发短消息,输入/历史/实际 session 一致 | 已验(装配层闭环) | `A05 两席闭环`:经 HTTP 路由 `POST /dispatch` 真的把任务单投进工部会话(`controller.prompts[0].content[0].text` 含任务标题),派发按 `targetSessionId` + `bindingGeneration` 双校验;工部用契约行回执 → `Result` 落账 → 终态成功 + 成果核验 → 任务 `completed`。十席各自 session 的输入/历史一致性仍需真机逐个看 |
|
||||
| A06 | A 工部改模型,B 工部用另一模型,全局默认不变 | 已验(单测)+ 待真机 | 配置按 `projectId+roleId` 存、`saveDepartmentConfig` CAS;**派发时默认不再调 `selectModel`**(部门模型由政策插件在 `agent/request` 上按角色覆写,再调一次会让宿主把全局默认存成本部门的),模型快照仍记在 `attempt.effectiveConfigSnapshot`。真机待看 `modelSelection` 投影 |
|
||||
| A07 | 运行中改模型,本次仍用原模型 | 已验(单测) | `首次派发:固定模型快照 → prompt 用 attemptId 作幂等键`:`effectiveConfigSnapshot` 在派发时冻结 |
|
||||
| A08 | 模型不支持旧 effort / 目录失效,校验错误可见 | 已验(单测) | `会话适配:prompt 必须带 requestId,错误分类可区分可重试与必失败` 覆盖 `model_unavailable`;不静默替换 |
|
||||
|
|
@ -55,7 +55,7 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| A27 | 键盘选卡片/模型按钮/分隔条/弹层,焦点可恢复 | 已验(单测)+ 待真机遍历 | 卡片 `role="button"` + `tabIndex` + Enter/Space;分隔条 `role="separator"` + `tabIndex` + `aria-valuenow/min/max`,方向键 ±16、Shift ±64、Home/End 到两端,未知键返回 `null` 不拦截默认行为(`A27 分隔条键盘` 单测)。宿主内真实 Tab 顺序与焦点恢复仍需重启后手测 |
|
||||
| A28 | 原生聊天审批、附件、流式在工作台同页可用 | 待真机 | 结构上复用 `renderFactorySlot('conversation.content')`,不重造聊天;需真机确认没绕过审批 |
|
||||
|
||||
小计:**已验 20 项**(A02 A03 A04 A06 A07 A08 A09 A10 A11 A12 A13 A15 A16 A17 A18 A19 A20 A21 A22 A23 A27 的单测部分,A24 A25 的预览部分)、**待真机 6 项**(A01 A05 A14 A26 A28 + A04/A24/A25 的真机部分)、**未做 0 项**。
|
||||
小计:**已验 21 项**(A02 A03 A04 A05 A06 A07 A08 A09 A10 A11 A12 A13 A15 A16 A17 A18 A19 A20 A21 A22 A23 A27 的单测/装配层部分,A24 A25 的预览部分)、**待真机 5 项**(A01 A14 A26 A28 + A04/A24/A25 的真机部分)、**未做 0 项**。
|
||||
|
||||
> 说明:A06 之所以仍标"部分",是判定标准要求"全局默认模型不被改动",而这一点只能在真实宿主里
|
||||
> 观察 `modelSelection` 投影才能坐实;代码侧已确认每次派发前覆写 `selectModel` 并记录
|
||||
|
|
|
|||
|
|
@ -75,10 +75,10 @@ export function createDispatchService(options = {}) {
|
|||
// 重复点击:什么都不再做,返回既有结论(含 unknown 的历史要由对账处理)。
|
||||
return { dispatch, attempt, outcome: outcomeOf(dispatch), duplicate: true }
|
||||
}
|
||||
if (dispatch.state === 'accepted') return { dispatch, attempt, outcome: 'accepted', duplicate: false }
|
||||
if ((dispatch.status ?? dispatch.state) === 'accepted') return { dispatch, attempt, outcome: 'accepted', duplicate: false }
|
||||
|
||||
// 2) 发送:先把 dispatch 推到 sending,再动宿主,避免“宿主已收但账上还是 prepared”。
|
||||
store.updateDispatch(dispatch.id, { state: 'sending', sendingAt: new Date().toISOString() })
|
||||
store.updateDispatch(dispatch.id, { status: 'sending', state: 'sending', sendingAt: new Date().toISOString() })
|
||||
|
||||
const task = store.getTask(taskId)
|
||||
const packet = attempt?.contextPacketId === undefined || attempt?.contextPacketId === null
|
||||
|
|
@ -142,13 +142,13 @@ export function createDispatchService(options = {}) {
|
|||
async function verifyUnknown(dispatchId) {
|
||||
const dispatch = store.getDispatch(dispatchId)
|
||||
if (dispatch === undefined) throw new DispatchError('NOT_FOUND', `派发不存在:${dispatchId}`)
|
||||
if (dispatch.state !== 'unknown') return { dispatch, outcome: outcomeOf(dispatch), changed: false }
|
||||
if ((dispatch.status ?? dispatch.state) !== 'unknown') return { dispatch, outcome: outcomeOf(dispatch), changed: false }
|
||||
const attempt = dispatch.attemptId === null ? null : store.getAttempt(dispatch.attemptId)
|
||||
if (attempt === null) return { dispatch, outcome: 'unknown', changed: false }
|
||||
const known = await sessions.inspectSession(attempt.sessionId)
|
||||
if (known === null) return { dispatch, outcome: 'unknown', changed: false }
|
||||
// 会话存在:宿主已经接受过这条消息(prompt 幂等键会挡住重复投递),按 accepted 收口。
|
||||
store.updateDispatch(dispatch.id, { state: 'accepted', verifiedAt: new Date().toISOString() })
|
||||
store.updateDispatch(dispatch.id, { status: 'accepted', state: 'accepted', verifiedAt: new Date().toISOString() })
|
||||
if (attempt.state === 'unknown') {
|
||||
store.updateAttempt(attempt.id, { state: 'running', hostRunId: attempt.hostRunId ?? null })
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ export function createDispatchService(options = {}) {
|
|||
function markAccepted({ dispatch, attempt }) {
|
||||
const stamp = new Date().toISOString()
|
||||
store.mutate(() => {
|
||||
store.updateDispatch(dispatch.id, { state: 'accepted', acceptedAt: stamp })
|
||||
store.updateDispatch(dispatch.id, { status: 'accepted', state: 'accepted', acceptedAt: stamp })
|
||||
if (attempt !== null && attempt.state === 'queued') {
|
||||
store.updateAttempt(attempt.id, { state: 'running', startedAt: stamp })
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ export function createDispatchService(options = {}) {
|
|||
function markRejected({ dispatch, attempt, reason }) {
|
||||
const stamp = new Date().toISOString()
|
||||
store.mutate(() => {
|
||||
store.updateDispatch(dispatch.id, { state: 'rejected', rejectedAt: stamp, error: String(reason ?? '') })
|
||||
store.updateDispatch(dispatch.id, { status: 'rejected', state: 'rejected', rejectedAt: stamp, error: String(reason ?? '') })
|
||||
if (attempt !== null && (attempt.state === 'queued' || attempt.state === 'unknown')) {
|
||||
store.updateAttempt(attempt.id, { state: 'failed', endedAt: stamp, error: String(reason ?? '') })
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ export function createDispatchService(options = {}) {
|
|||
function markUnknown({ dispatch, attempt, reason }) {
|
||||
const stamp = new Date().toISOString()
|
||||
store.mutate(() => {
|
||||
store.updateDispatch(dispatch.id, { state: 'unknown', unknownAt: stamp, error: String(reason ?? '') })
|
||||
store.updateDispatch(dispatch.id, { status: 'unknown', state: 'unknown', unknownAt: stamp, error: String(reason ?? '') })
|
||||
if (attempt !== null && attempt.state === 'queued') {
|
||||
store.updateAttempt(attempt.id, { state: 'unknown' })
|
||||
}
|
||||
|
|
@ -197,9 +197,9 @@ export function createDispatchService(options = {}) {
|
|||
}
|
||||
|
||||
function outcomeOf(dispatch) {
|
||||
if (dispatch.state === 'accepted') return 'accepted'
|
||||
if (dispatch.state === 'rejected') return 'rejected'
|
||||
if (dispatch.state === 'unknown') return 'unknown'
|
||||
if ((dispatch.status ?? dispatch.state) === 'accepted') return 'accepted'
|
||||
if ((dispatch.status ?? dispatch.state) === 'rejected') return 'rejected'
|
||||
if ((dispatch.status ?? dispatch.state) === 'unknown') return 'unknown'
|
||||
return 'prepared'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,3 +192,84 @@ test('装配层:重复挂载会话层是幂等的,不会把已挂上的换
|
|||
assert.equal(host.sessions, first)
|
||||
host.dispose()
|
||||
})
|
||||
|
||||
test('A05 两席闭环:丞相派工给工部 → 工部回执 → 成果登记 → 任务完成', async () => {
|
||||
const store = memoryStore()
|
||||
const webServer = fakeWebServer()
|
||||
const controller = tinyController(['ses_gongbu'])
|
||||
const ctx = fakeCtx({ webServer, controller })
|
||||
|
||||
const host = createWorkbenchHost(ctx, { store, startReconciler: false })
|
||||
assert.equal(host.hasSessions, true, '有 sessionController 时就该能派发')
|
||||
|
||||
// 1) 项目 + 工部接通(丞相那一席由账本自带,不需要建会话也能当派发方)
|
||||
const project = host.service.registerProject({ hostWorkspaceId: WS, displayNameCache: '闭环' }).project
|
||||
const bound = host.service.bindDepartmentSession({ projectId: project.id, roleId: 'gongbu', sessionId: 'ses_gongbu' })
|
||||
|
||||
// 2) 丞相开任务并派给工部
|
||||
const task = host.service.createTask({
|
||||
projectId: project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
sourceRoleId: 'lead',
|
||||
title: '做一版预算',
|
||||
objective: '给出预算表',
|
||||
status: 'queued',
|
||||
}).task
|
||||
|
||||
const dispatched = await callRoute(webServer, '/dispatch', 'POST', {
|
||||
projectId: project.id,
|
||||
taskId: task.id,
|
||||
targetRoleId: 'gongbu',
|
||||
idempotencyKey: 'loop-1',
|
||||
targetSessionId: 'ses_gongbu',
|
||||
bindingGeneration: bound.binding.bindingGeneration,
|
||||
})
|
||||
assert.equal(dispatched.ok, true, JSON.stringify(dispatched))
|
||||
assert.equal(dispatched.value.dispatch.status, 'accepted')
|
||||
assert.equal(controller.prompts.length, 1, '工部会话应真实收到一条任务单')
|
||||
assert.ok(controller.prompts[0].content[0].text.includes('做一版预算'))
|
||||
|
||||
const attempt = store.listAttempts(task.id)[0]
|
||||
assert.ok(attempt, '派发要落一条 attempt')
|
||||
|
||||
// 3) 工部登记成果,再用契约行回执(正文里说“已完成”不算)
|
||||
const artifact = host.service.registerArtifact({
|
||||
projectId: project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
taskId: task.id,
|
||||
displayName: '预算表',
|
||||
fileRef: 'C:/work/预算.xlsx',
|
||||
verification: { status: 'verified' },
|
||||
}).artifact
|
||||
|
||||
const ingest = await callRoute(webServer, '/ingest', 'POST', {
|
||||
projectId: project.id,
|
||||
roleId: 'gongbu',
|
||||
text: `【三省六部】${JSON.stringify({
|
||||
action: 'reportTaskResult',
|
||||
taskId: task.id,
|
||||
attemptId: attempt.id,
|
||||
reportVersion: 1,
|
||||
report: {
|
||||
summary: '预算表已出',
|
||||
checks: [{ name: '合计对得上', ok: true, detail: '与台账一致' }],
|
||||
artifactRefs: [artifact.id],
|
||||
},
|
||||
})}`,
|
||||
})
|
||||
assert.equal(ingest.ok, true, JSON.stringify(ingest))
|
||||
assert.equal(ingest.value.applied.length, 1, JSON.stringify(ingest.value.failed))
|
||||
|
||||
// 4) 会话跑完:报告 + 终态成功 + 成果有效 → 任务完成
|
||||
host.service.reportRunTerminal({
|
||||
projectId: project.id,
|
||||
taskId: task.id,
|
||||
attemptId: attempt.id,
|
||||
runTerminal: 'succeeded',
|
||||
})
|
||||
const done = store.getTask(task.id)
|
||||
assert.equal(done.status, 'completed')
|
||||
assert.ok(store.listResults(task.id).length >= 1, '回执要落成 Result,而不是只改任务状态')
|
||||
assert.equal(store.listArtifacts(project.id).length, 1)
|
||||
assert.equal(store.getDispatch(dispatched.value.dispatch.id).status, 'accepted')
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue