feat(workbench): A09 附件级材料引用 / A17 账本重开 / A19 跨项目材料隔离补齐
- session-adapter: describeMaterialRef 让成果与附件在任务单里可读且带可追溯 ID - service: normalizeMaterialRefs 校验同项目、自动补 revision/title - test: 新增 acceptance-extra 3 例;全量 209/209
This commit is contained in:
parent
047d2a267e
commit
320889437f
|
|
@ -34,7 +34,7 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| A06 | A 工部改模型,B 工部用另一模型,全局默认不变 | 部分 | 配置按 `projectId+roleId` 存,`saveDepartmentConfig 走 CAS` 验过;`selectModel` 会改宿主全局默认这点只能在真机确认(记录 L4) |
|
||||
| A07 | 运行中改模型,本次仍用原模型 | 已验(单测) | `首次派发:固定模型快照 → prompt 用 attemptId 作幂等键`:`effectiveConfigSnapshot` 在派发时冻结 |
|
||||
| A08 | 模型不支持旧 effort / 目录失效,校验错误可见 | 已验(单测) | `会话适配:prompt 必须带 requestId,错误分类可区分可重试与必失败` 覆盖 `model_unavailable`;不静默替换 |
|
||||
| A09 | 丞相带文件交接工部,材料可读、引用可追溯 | 部分 | `contextPacket` 有 `materialRefs / authorizationRefs / originMessageRef / excerpts`,`buildDispatchText` 把 materialRefs 写进任务单;**附件级(attachmentId)引用未接** |
|
||||
| A09 | 丞相带文件交接工部,材料可读、引用可追溯 | 已验(单测,附件级已通) | `A09 交接材料:附件引用原样进 packet,成果引用带版本,文本里可读`:`{attachmentId}` 保留 name/mime/size,`{artifactId}` 自动补 `revision` 与成果显示名;`buildDispatchText` 渲染成 `成果 预算表 art_x(第 1 版)`、`附件 att_abc(预算.xlsx · application/vnd.ms-excel · 2048 字节)`;缺 ID / 未知 ID 报 `INVALID_INPUT` / `NOT_FOUND`。真机"从聊天里带附件"仍需重启后确认 |
|
||||
| A10 | 正常完成:有效报告+终态+成果核验 | 已验(单测) | `完成判定分支一:报告+终态成功+成果有效 → completed` |
|
||||
| A11 | 仅变 idle 或输出"已完成"不标记完成 | 已验(单测) | `对账:运行结束但无报告 → needs_attention`;`契约解析只认四动作`(正文里的"已完成"不进状态机) |
|
||||
| A12 | 重复投递/重复完成/乱序事件不重复、不倒退 | 已验(单测) | `重复点击同一幂等键:不重复投递`;`结果去重:同 (attemptId, reportVersion) 与同 sourceMessageRef 只登记一次`;`isRegressingEvent` 拒绝倒退终态 |
|
||||
|
|
@ -42,9 +42,9 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| A14 | 用户直聊与派工同时到达,同 session 串行 | 已验(单测)+ 待真机 | 错误分类 `busy`;真实串行由宿主 inbox 保证,需真机观察 |
|
||||
| A15 | A/B 同时跑,停止 A,B 继续 | 已验(单测)+ 待真机 | `cancelTask:业务落 cancelled,运行中的尝试只到 cancel_requested`;取消带 `attemptId`,不会误停 B |
|
||||
| A16 | A 运行时切到 B,A 迟到回调不改 B | 已验(单测) | `对账` 全按 `attemptId` 判定;`宿主重启后查不到会话时不猜` |
|
||||
| A17 | 刷新/关闭重开/重启宿主后绑定配置任务恢复 | 部分 | 账本落盘 + `events` 游标可重放(`events:since 之后只给新事件,游标可重放`);**U7 宿主重启后客户端重建未验证** |
|
||||
| A17 | 刷新/关闭重开/重启宿主后绑定配置任务恢复 | 已验(单测,账本重开) | `A17 宿主重启:账本重开后项目/绑定/配置/任务/派发都还在,换绑代号不回退`:同一 `workbench.json` 新建 store + `load()` 后项目/绑定/配置(`config.model`、`configRevision`)/任务/幂等键全部还原,重复派发返回 `duplicate:true` 且同 `dispatch.id`;`events` 游标可重放。**U7 宿主重启后客户端重建仍需真机** |
|
||||
| A18 | 伪造其他项目 session/task/artifact/run ID 被拒 | 已验(单测) | `项目隔离` 四条:`CROSS_PROJECT` / `NOT_FOUND` 且不泄露归属 |
|
||||
| A19 | B 不自动获得 A 的材料/记忆 | 部分 | 交接材料只装本任务 packet;记忆隔离属宿主能力,未接 |
|
||||
| A19 | B 不自动获得 A 的材料/记忆 | 已验(单测,材料侧) | `A09/A19 跨项目成果引用被拒`:B 项目引用 A 的 `artifactId` → `CROSS_PROJECT`,`details` 不含 A 的归属;B 的 packet 只装本任务材料(无跨项目串带)。**记忆隔离属宿主能力,仍需真机** |
|
||||
| A20 | 相同目录/父子目录识别为冲突,不宣称完全隔离 | 已验(单测) | `A20 同目录/父子目录登记成另一个项目时明确报冲突`:`DUPLICATE_PROJECT` + `relation: same/nested` + `allowSharedRoot` 显式放行 |
|
||||
| A21 | 两窗口同时改设置/消费队列不覆盖 | 已验(单测) | `saveDepartmentConfig 走 CAS:旧 revision 冲突并带回当前值`;事件日志为只读游标,多标签页不互相偷事件 |
|
||||
| A22 | 主责部门局部修改成果,保留来源/版本,不重跑全链 | 已验(单测)+ UI 接线中 | `A22 成果修订只开一条修订任务给原主责部门`:`kind:'revision'`、`reviseOfArtifactId`、版本 +1、派发自动带 `materialRefs:[{artifactId,revision}]` |
|
||||
|
|
@ -55,10 +55,11 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| A27 | 键盘选卡片/模型按钮/分隔条/弹层,焦点可恢复 | 待真机 | 卡片 `tabIndex` + Enter/Space、resizer `role="separator"`,未做键盘遍历测试 |
|
||||
| A28 | 原生聊天审批、附件、流式在工作台同页可用 | 待真机 | 结构上复用 `renderFactorySlot('conversation.content')`,不重造聊天;需真机确认没绕过审批 |
|
||||
|
||||
小计:**已验 16 项**(A02 A03 A04 A07 A08 A10 A11 A12 A13 A15 A16 A18 A20 A21 A22 A23 的单测部分,A24 A25 的预览部分)、**部分 4 项**(A06 A09 A17 A19)、**待真机 8 项**(A01 A05 A14 A26 A27 A28 + A04/A24/A25 的真机部分)、**未做 0 项**。
|
||||
小计:**已验 18 项**(A02 A03 A04 A07 A08 A09 A10 A11 A12 A13 A15 A16 A17 A18 A19 A20 A21 A22 A23 的单测部分,A24 A25 的预览部分)、**部分 1 项**(A06 全局默认模型只验了"每次派发前覆写、派发后不动全局"的代码路径)、**待真机 8 项**(A01 A05 A14 A26 A27 A28 + A04/A24/A25 的真机部分)、**未做 0 项**。
|
||||
|
||||
> 说明:A06/A09/A17/A19 之所以标"部分",是因为判定标准里有一半依赖宿主真实行为或附件通道,
|
||||
> 光靠单测无法给结论。这几项与 A01/A05/A25–A28 一样,都需要重启 DSH 后补证据。
|
||||
> 说明:A06 之所以仍标"部分",是判定标准要求"全局默认模型不被改动",而这一点只能在真实宿主里
|
||||
> 观察 `modelSelection` 投影才能坐实;代码侧已确认每次派发前覆写 `selectModel` 并记录
|
||||
> `effectiveConfigSnapshot`,派发结束后不写回全局。A01/A05/A14/A25–A28 同理,都需要重启 DSH 后补证据。
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -74,6 +75,17 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| `workbench/test/routes.test.mjs` | 路由数 11 → 12 |
|
||||
| `workbench/panel/lib/client.js` | 成果区补「文件已失效/位置未核验」标记、修订按钮与内联表单、任务「修订」标签 |
|
||||
|
||||
### 本轮(A09/A17/A19 补齐)
|
||||
|
||||
| 文件 | 改动 |
|
||||
|---|---|
|
||||
| `workbench/host/session-adapter.mjs` | 新增 `describeMaterialRef(ref)` 并用于 `buildDispatchText`:成果写成「成果 预算表 art_x(第 1 版)」,附件写成「附件 att_abc(预算.xlsx · application/vnd.ms-excel · 2048 字节)」,字符串材料原样 |
|
||||
| `workbench/host/service.mjs` | 新增 `normalizeMaterialRefs(value, project)`:`{artifactId}` 校验同项目并自动补 `revision`/`title`(标题取 `artifact.displayName`),`{attachmentId}` 保留 name/mime/size,字符串放行,未知/缺 ID 报 `NOT_FOUND`/`INVALID_INPUT`;`dispatchTask` 的材料走它而不是裸数组 |
|
||||
| `workbench/test/acceptance-extra.test.mjs` | 新增 3 例:A09 材料可读、A09/A19 跨项目材料被拒且不泄露归属、A17 账本重开后全量还原 |
|
||||
| `workbench/test/service.test.mjs` | A22 断言补齐 `title`(材料引用现在带可读名) |
|
||||
|
||||
测试数:206 → **209**(全绿)。
|
||||
|
||||
---
|
||||
|
||||
## 3. 复现步骤(真机部分)
|
||||
|
|
|
|||
|
|
@ -689,7 +689,10 @@ export function createWorkbenchService(options = {}) {
|
|||
constraints: packet.constraints === undefined ? task.constraints : optionalArray(packet.constraints, 'packet.constraints'),
|
||||
originMessageRef: packet.originMessageRef ?? task.originMessageRef,
|
||||
excerpts: optionalArray(packet.excerpts, 'packet.excerpts'),
|
||||
materialRefs: packet.materialRefs === undefined ? revisionMaterials : optionalArray(packet.materialRefs, 'packet.materialRefs'),
|
||||
materialRefs: normalizeMaterialRefs(
|
||||
packet.materialRefs === undefined ? revisionMaterials : packet.materialRefs,
|
||||
project,
|
||||
),
|
||||
authorizationRefs: optionalArray(packet.authorizationRefs, 'packet.authorizationRefs'),
|
||||
scope: packet.scope ?? task.scope,
|
||||
expectedOutputs: optionalArray(packet.expectedOutputs, 'packet.expectedOutputs'),
|
||||
|
|
@ -1130,6 +1133,57 @@ export function createWorkbenchService(options = {}) {
|
|||
return { ...copy(artifact), existence }
|
||||
}
|
||||
|
||||
/**
|
||||
* 交接材料引用(A09):两种可追溯形态,别的一律拒绝。
|
||||
* - 字符串:历史数据里的自由文本引用,原样保留
|
||||
* - {artifactId}:必须是本项目的成果;版本缺省取该成果当前版本,显式给了就按给的记
|
||||
* - {attachmentId}:附件的宿主侧 ID,允许带 name/mime/size 供阅读
|
||||
* 显式拒绝跨项目成果引用:交接材料不能成为越权读取的通道。
|
||||
*/
|
||||
function normalizeMaterialRefs(value, project) {
|
||||
const list = optionalArray(value, 'packet.materialRefs')
|
||||
return list.map((ref, index) => {
|
||||
if (typeof ref === 'string') {
|
||||
if (ref.trim() === '') throw new ServiceError(SERVICE_CODES.INVALID_INPUT, '材料引用不能是空字符串', { field: `materialRefs[${index}]` })
|
||||
return ref
|
||||
}
|
||||
if (ref === null || typeof ref !== 'object' || Array.isArray(ref)) {
|
||||
throw new ServiceError(SERVICE_CODES.INVALID_INPUT, '材料引用必须是字符串或 {artifactId} / {attachmentId} 对象', {
|
||||
field: `materialRefs[${index}]`,
|
||||
})
|
||||
}
|
||||
if (typeof ref.artifactId === 'string' && ref.artifactId !== '') {
|
||||
const artifact = store.getArtifact(ref.artifactId)
|
||||
if (artifact === undefined) {
|
||||
throw new ServiceError(SERVICE_CODES.NOT_FOUND, '材料引用指向的成果不存在', { field: `materialRefs[${index}]` })
|
||||
}
|
||||
if (artifact.projectId !== project.id) {
|
||||
throw new ServiceError(SERVICE_CODES.CROSS_PROJECT, '材料引用指向的成果属于别的项目', {
|
||||
field: `materialRefs[${index}]`,
|
||||
})
|
||||
}
|
||||
const revision = Number.isInteger(ref.revision) && ref.revision > 0 ? ref.revision : Number(artifact.revision ?? 1)
|
||||
const out = { artifactId: artifact.id, revision }
|
||||
// 名字只是给人读的,默认取成果自己的显示名;显式给了就以调用方为准。
|
||||
const title = typeof ref.title === 'string' && ref.title !== ''
|
||||
? ref.title
|
||||
: (typeof artifact.displayName === 'string' && artifact.displayName !== '' ? artifact.displayName : '')
|
||||
if (title !== '') out.title = title
|
||||
return out
|
||||
}
|
||||
if (typeof ref.attachmentId === 'string' && ref.attachmentId !== '') {
|
||||
const out = { attachmentId: ref.attachmentId }
|
||||
if (typeof ref.name === 'string' && ref.name !== '') out.name = ref.name
|
||||
if (typeof ref.mime === 'string' && ref.mime !== '') out.mime = ref.mime
|
||||
if (Number.isInteger(ref.size) && ref.size > 0) out.size = ref.size
|
||||
return out
|
||||
}
|
||||
throw new ServiceError(SERVICE_CODES.INVALID_INPUT, '材料引用缺少 artifactId 或 attachmentId', {
|
||||
field: `materialRefs[${index}]`,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/** 登记成果引用:只记引用与校验结论,不复制文件内容,也不改文件本体。 */
|
||||
const registerArtifact = guard((input = {}) => {
|
||||
const project = projectIdOf(input)
|
||||
|
|
|
|||
|
|
@ -249,6 +249,31 @@ function messageOf(error) {
|
|||
return error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一条材料引用写成人能读的一行,并保留可追溯的 ID。
|
||||
* - 字符串:原样(历史数据里的自由文本引用)
|
||||
* - {artifactId, revision}:成果引用,带版本号
|
||||
* - {attachmentId, name, mime, size}:附件引用(A09 附件级交接)
|
||||
*/
|
||||
export function describeMaterialRef(ref) {
|
||||
if (typeof ref === 'string') return ref
|
||||
if (ref === null || typeof ref !== 'object') return String(ref)
|
||||
if (typeof ref.artifactId === 'string' && ref.artifactId !== '') {
|
||||
const version = Number.isInteger(ref.revision) && ref.revision > 0 ? `(第 ${ref.revision} 版)` : ''
|
||||
const title = typeof ref.title === 'string' && ref.title !== '' ? ` ${ref.title}` : ''
|
||||
return `成果${title} ${ref.artifactId}${version}`
|
||||
}
|
||||
if (typeof ref.attachmentId === 'string' && ref.attachmentId !== '') {
|
||||
const bits = []
|
||||
if (typeof ref.name === 'string' && ref.name !== '') bits.push(ref.name)
|
||||
if (typeof ref.mime === 'string' && ref.mime !== '') bits.push(ref.mime)
|
||||
if (Number.isInteger(ref.size) && ref.size > 0) bits.push(`${ref.size} 字节`)
|
||||
const suffix = bits.length === 0 ? '' : `(${bits.join(' · ')})`
|
||||
return `附件 ${ref.attachmentId}${suffix}`
|
||||
}
|
||||
return JSON.stringify(ref)
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一次派发写成部门能直接执行的提示词。只放事实(任务、验收、材料、回传方式),
|
||||
* 不写“请确认已完成”这类引导语——完成判定只认结构化报告。
|
||||
|
|
@ -271,7 +296,7 @@ export function buildDispatchText({ task, packet, contractGuide, roleName } = {}
|
|||
const refs = Array.isArray(packet?.materialRefs) ? packet.materialRefs : []
|
||||
if (refs.length > 0) {
|
||||
lines.push('相关材料:')
|
||||
for (const ref of refs) lines.push(`- ${typeof ref === 'string' ? ref : JSON.stringify(ref)}`)
|
||||
for (const ref of refs) lines.push(`- ${describeMaterialRef(ref)}`)
|
||||
}
|
||||
lines.push('')
|
||||
lines.push(`完成后请用结构化回传(不要只在正文里说“已完成”,那样不算完成):`)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,207 @@
|
|||
// A09 / A17 / A19 的补强验收:附件级材料引用、宿主重启后的账本恢复、项目间材料隔离。
|
||||
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtempSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { WorkbenchStore } from '../core/store.mjs'
|
||||
import { createWorkbenchService } from '../host/service.mjs'
|
||||
import { buildDispatchText, describeMaterialRef } from '../host/session-adapter.mjs'
|
||||
|
||||
const clock = () => 1700000000000
|
||||
|
||||
function memoryStore() {
|
||||
return new WorkbenchStore({ file: null, clock })
|
||||
}
|
||||
|
||||
function seed(service, hostWorkspaceId) {
|
||||
const project = service.registerProject({ hostWorkspaceId, displayNameCache: hostWorkspaceId }).project
|
||||
const binding = service.bindDepartmentSession({ projectId: project.id, roleId: 'gongbu', sessionId: `ses_${hostWorkspaceId}` })
|
||||
return { project, generation: binding.binding.bindingGeneration }
|
||||
}
|
||||
|
||||
test('A09 交接材料:附件引用原样进 packet,成果引用带版本,文本里可读', () => {
|
||||
const store = memoryStore()
|
||||
const service = createWorkbenchService({ store, clock })
|
||||
const { project, generation } = seed(service, 'ws-a')
|
||||
const task = service.createTask({
|
||||
projectId: project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
sourceRoleId: 'lead',
|
||||
title: '按预算出方案',
|
||||
objective: 'o',
|
||||
status: 'queued',
|
||||
}).task
|
||||
const artifact = service.registerArtifact({
|
||||
projectId: project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
taskId: task.id,
|
||||
displayName: '预算表',
|
||||
fileRef: 'C:/work/预算.xlsx',
|
||||
kind: 'spreadsheet',
|
||||
}).artifact
|
||||
|
||||
const dispatched = service.dispatchTask({
|
||||
projectId: project.id,
|
||||
taskId: task.id,
|
||||
idempotencyKey: 'k-material',
|
||||
targetRoleId: 'gongbu',
|
||||
targetSessionId: 'ses_ws-a',
|
||||
bindingGeneration: generation,
|
||||
packet: {
|
||||
materialRefs: [
|
||||
{ artifactId: artifact.id },
|
||||
{ attachmentId: 'att_abc', name: '预算.xlsx', mime: 'application/vnd.ms-excel', size: 2048 },
|
||||
'聊天里贴过的那段口径',
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const refs = dispatched.contextPacket.materialRefs
|
||||
assert.deepEqual(refs[0], { artifactId: artifact.id, revision: 1, title: '预算表' })
|
||||
assert.deepEqual(refs[1], { attachmentId: 'att_abc', name: '预算.xlsx', mime: 'application/vnd.ms-excel', size: 2048 })
|
||||
assert.equal(refs[2], '聊天里贴过的那段口径')
|
||||
|
||||
// 派发文本必须把材料写成能读的一行,并保留可追溯 ID。
|
||||
const text = buildDispatchText({ task, packet: dispatched.contextPacket, contractGuide: 'G', roleName: '工部' })
|
||||
assert.ok(text.includes(`成果 预算表 ${artifact.id}(第 1 版)`))
|
||||
assert.match(text, /附件 att_abc(预算\.xlsx · application\/vnd\.ms-excel · 2048 字节)/)
|
||||
assert.match(text, /聊天里贴过的那段口径/)
|
||||
|
||||
// 纯函数本身也单独锁一下:非对象、空串、缺 ID 都不该糊过去。
|
||||
assert.equal(describeMaterialRef(null), 'null')
|
||||
assert.equal(describeMaterialRef('a.xlsx'), 'a.xlsx')
|
||||
})
|
||||
|
||||
test('A09/A19 交接材料不能越权:别的项目的成果引用直接拒绝,且不泄露归属', () => {
|
||||
const store = memoryStore()
|
||||
const service = createWorkbenchService({ store, clock })
|
||||
const a = seed(service, 'ws-a')
|
||||
const b = seed(service, 'ws-b')
|
||||
const taskA = service.createTask({
|
||||
projectId: a.project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
sourceRoleId: 'lead',
|
||||
title: 'A 的任务',
|
||||
objective: 'o',
|
||||
status: 'queued',
|
||||
}).task
|
||||
const artifact = service.registerArtifact({
|
||||
projectId: a.project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
taskId: taskA.id,
|
||||
title: 'A 的成果',
|
||||
fileRef: 'C:/work/a.xlsx',
|
||||
}).artifact
|
||||
const task = service.createTask({
|
||||
projectId: b.project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
sourceRoleId: 'lead',
|
||||
title: 'B 的任务',
|
||||
objective: 'o',
|
||||
status: 'queued',
|
||||
}).task
|
||||
|
||||
assert.throws(
|
||||
() =>
|
||||
service.dispatchTask({
|
||||
projectId: b.project.id,
|
||||
taskId: task.id,
|
||||
idempotencyKey: 'k-cross',
|
||||
targetRoleId: 'gongbu',
|
||||
targetSessionId: 'ses_ws-b',
|
||||
bindingGeneration: b.generation,
|
||||
packet: { materialRefs: [{ artifactId: artifact.id }] },
|
||||
}),
|
||||
(error) => error.code === 'CROSS_PROJECT' && !JSON.stringify(error.details ?? {}).includes(a.project.id),
|
||||
)
|
||||
|
||||
// 正常派发:B 的上下文包里只有自己的东西,绝不自动继承 A 的材料。
|
||||
const dispatched = service.dispatchTask({
|
||||
projectId: b.project.id,
|
||||
taskId: task.id,
|
||||
idempotencyKey: 'k-own',
|
||||
targetRoleId: 'gongbu',
|
||||
targetSessionId: 'ses_ws-b',
|
||||
bindingGeneration: b.generation,
|
||||
})
|
||||
assert.deepEqual(dispatched.contextPacket.materialRefs, [])
|
||||
|
||||
// 缺 ID 的引用、空字符串都要明确报错,而不是“尽力猜”。
|
||||
assert.throws(
|
||||
() =>
|
||||
service.dispatchTask({
|
||||
projectId: b.project.id,
|
||||
taskId: task.id,
|
||||
idempotencyKey: 'k-bad',
|
||||
targetRoleId: 'gongbu',
|
||||
targetSessionId: 'ses_ws-b',
|
||||
bindingGeneration: b.generation,
|
||||
packet: { materialRefs: [{ name: '没有 ID 的东西' }] },
|
||||
}),
|
||||
(error) => error.code === 'INVALID_INPUT',
|
||||
)
|
||||
})
|
||||
|
||||
test('A17 宿主重启:账本重开后项目/绑定/配置/任务/派发都还在,换绑代号不回退', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'wb-restart-'))
|
||||
const file = join(dir, 'workbench.json')
|
||||
try {
|
||||
const first = new WorkbenchStore({ file, clock })
|
||||
first.load()
|
||||
const service = createWorkbenchService({ store: first, clock })
|
||||
const { project, generation } = seed(service, 'ws-restart')
|
||||
service.saveDepartmentConfig({ projectId: project.id, roleId: 'gongbu', provider: 'magpie', model: 'workbuddy/deepseek-v4.1-flash', expectedRevision: 0 })
|
||||
const task = service.createTask({
|
||||
projectId: project.id,
|
||||
ownerRoleId: 'gongbu',
|
||||
sourceRoleId: 'lead',
|
||||
title: '重启前建的任务',
|
||||
objective: 'o',
|
||||
status: 'queued',
|
||||
}).task
|
||||
const dispatched = service.dispatchTask({
|
||||
projectId: project.id,
|
||||
taskId: task.id,
|
||||
idempotencyKey: 'k-restart',
|
||||
targetRoleId: 'gongbu',
|
||||
targetSessionId: 'ses_ws-restart',
|
||||
bindingGeneration: generation,
|
||||
})
|
||||
assert.equal(dispatched.dispatch.idempotencyKey, 'k-restart')
|
||||
|
||||
// —— 模拟宿主重启:新建 store 从同一文件重开 ——
|
||||
const second = new WorkbenchStore({ file, clock })
|
||||
second.load()
|
||||
const revived = createWorkbenchService({ store: second, clock })
|
||||
|
||||
const projects = revived.listProjects()
|
||||
assert.equal(projects.length, 1)
|
||||
assert.equal(projects[0].hostWorkspaceId, 'ws-restart')
|
||||
|
||||
const seats = revived.listSeats(project.id)
|
||||
const gongbu = seats.find((seat) => seat.roleId === 'gongbu')
|
||||
assert.equal(gongbu.connected, true)
|
||||
assert.equal(gongbu.config.model, 'workbuddy/deepseek-v4.1-flash')
|
||||
assert.equal(gongbu.config.configRevision, 1)
|
||||
|
||||
const revivedTask = revived.getTask(project.id, task.id)
|
||||
assert.equal(revivedTask.title, '重启前建的任务')
|
||||
|
||||
// 幂等键跨重启仍有效:再点一次不会重复投递。
|
||||
const again = revived.dispatchTask({
|
||||
projectId: project.id,
|
||||
taskId: task.id,
|
||||
idempotencyKey: 'k-restart',
|
||||
targetRoleId: 'gongbu',
|
||||
targetSessionId: 'ses_ws-restart',
|
||||
bindingGeneration: generation,
|
||||
})
|
||||
assert.equal(again.duplicate, true)
|
||||
assert.equal(again.dispatch.id, dispatched.dispatch.id)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
|
@ -612,7 +612,7 @@ test('A22 成果修订只开一条修订任务给原主责部门,派发自带
|
|||
const dispatched = ctx.service.dispatchTask({
|
||||
projectId: ctx.a.id, taskId: revised.task.id, targetRoleId: 'libu', idempotencyKey: 'rev-1',
|
||||
})
|
||||
assert.deepEqual(dispatched.contextPacket.materialRefs, [{ artifactId: artifact.id, revision: 1 }])
|
||||
assert.deepEqual(dispatched.contextPacket.materialRefs, [{ artifactId: artifact.id, revision: 1, title: "报告" }])
|
||||
|
||||
// 新成果接到旧成果上:版本 +1,且跨项目修订被拒
|
||||
const next = ctx.service.registerArtifact({
|
||||
|
|
|
|||
Loading…
Reference in New Issue