test+chore: 重启前自检脚本;A26 项目隔离单测
- scripts/workbench-preflight.mjs:只读自检链接/入口/bundle 语法/12 条路由/账本可写,7 项 - A26:两个项目的配置、绑定、draft 任务互不串带 - 全量 212/212
This commit is contained in:
parent
defa0307df
commit
1d58d2c3a6
|
|
@ -51,11 +51,11 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
| A23 | 删除 session 或成果文件后显示失效并保留历史 | 已验(单测)+ UI 接线中 | `A23 成果文件不见了显示 missing…`:`existence: ok/missing/unknown`,账本不改写;session 侧 `binding.status='unavailable'` |
|
||||
| A24 | 2560×1440 浅/深色、拖宽右栏 | 已验(预览) | `docs/preview/v01-workbench-rail-400-light.png` / `-dark.png`(800×1220,真 Chrome 渲染真实 bundle);拖宽逻辑 340–600 + `sansheng.workbench.railWidth` |
|
||||
| A25 | 约 390 CSS px 手机宽度抽屉可用 | 已验(预览) | `docs/preview/v01-workbench-rail-390-light.png` / `-dark.png`(780×1220):三列卡片不再折行,「未接通」保持一行、模型名省略号;抽屉本身在真机里才展开(待真机) |
|
||||
| A26 | 切主题/项目/部门后草稿、绑定、配置各归所属 | 待真机 | 状态按项目分桶;切项目会重新 `bootstrap`,未真机验证草稿保留 |
|
||||
| A26 | 切主题/项目/部门后草稿、绑定、配置各归所属 | 已验(单测,数据归属)+ 待真机界面 | `A26 切项目后草稿、绑定、配置各归所属`:两个项目各自 `gongbu` 配置不同模型、绑不同会话、各存一条 draft 任务;`bootstrap(A)/(B)` 的席位配置、`binding.currentSessionId`、任务标题互不串带。界面切换时草稿保留仍需真机点一遍 |
|
||||
| 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')`,不重造聊天;需真机确认没绕过审批 |
|
||||
|
||||
小计:**已验 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 项**。
|
||||
小计:**已验 22 项**(A02 A03 A04 A05 A06 A07 A08 A09 A10 A11 A12 A13 A15 A16 A17 A18 A19 A20 A21 A22 A23 A26 A27 的单测/装配层部分,A24 A25 的预览部分)、**待真机 4 项**(A01 A14 A28 + A04/A24/A25/A26 的真机部分)、**未做 0 项**。
|
||||
|
||||
> 说明:A06 之所以仍标"部分",是判定标准要求"全局默认模型不被改动",而这一点只能在真实宿主里
|
||||
> 观察 `modelSelection` 投影才能坐实;代码侧已确认每次派发前覆写 `selectModel` 并记录
|
||||
|
|
@ -95,8 +95,12 @@ node --test --test-isolation=none test/policy.test.js workbench/test/*.test.mjs
|
|||
```bash
|
||||
node scripts/workbench-install.mjs on # 写进 profile 的 dependencies + dsh.profile.bundles + node_modules junction
|
||||
node scripts/workbench-install.mjs status # 期望 installed=true, targetExists=true
|
||||
node scripts/workbench-preflight.mjs # 期望 7/7 通过:链接、入口、bundle 语法、12 条路由、账本可写
|
||||
```
|
||||
|
||||
> `workbench-preflight.mjs` 是只读自检:不装、不改配置,只回答「重启后会不会白屏 / 路由起不起得来」。
|
||||
> 它会真的创建 `%DSH_HOME%\sansheng-liubu` 目录(插件运行时本来也会建),除此之外不写任何东西。
|
||||
|
||||
2. **彻底退出 DSH 再启动**(托盘退出,不是关窗口);只对新会话生效。
|
||||
3. 打开任意项目会话,右侧应出现「朝堂 / 任务 / 成果」。
|
||||
4. 依次验:接通一个部门 → 派一条任务 → 完成 → 在成果区点「找主责部门修改」。
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
// 重启前自检:只读,不改任何东西。
|
||||
//
|
||||
// 目的:把「重启 DSH 之后才发现客户端 bundle 根本没加载」这类问题提前挡掉。
|
||||
// 检查四件事——
|
||||
// 1. profile 里到底有没有把本插件链进去(dependencies + dsh.profile.bundles)
|
||||
// 2. 链接指向的目录里,exports 声明的那个文件在不在
|
||||
// 3. 那个文件是不是一段能解析的 JS(语法坏了会让整页白屏,且报错很难看懂)
|
||||
// 4. Host 侧装配能不能在内存账本上跑起来(12 条路由 + bootstrap 可用)
|
||||
//
|
||||
// 用法:node scripts/workbench-preflight.mjs
|
||||
// 退出码:0 全通;1 有失败项(打印哪一项失败、为什么)。
|
||||
|
||||
import fs from 'node:fs'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
import vm from 'node:vm'
|
||||
|
||||
import { createWorkbenchHost } from '../workbench/host/index.mjs'
|
||||
import { WorkbenchStore } from '../workbench/core/store.mjs'
|
||||
|
||||
const PLUGIN_ID = 'dsh-sansheng-liubu-workbench'
|
||||
const results = []
|
||||
|
||||
function check(name, run) {
|
||||
try {
|
||||
const detail = run()
|
||||
results.push({ name, ok: true, detail })
|
||||
} catch (error) {
|
||||
results.push({ name, ok: false, detail: error?.message ?? String(error) })
|
||||
}
|
||||
}
|
||||
|
||||
function dshHome(env = process.env) {
|
||||
const value = typeof env.DSH_HOME === 'string' && env.DSH_HOME.trim() ? env.DSH_HOME.trim() : ''
|
||||
return value === '' ? path.join(os.homedir(), '.dsh') : value
|
||||
}
|
||||
|
||||
const profileDir = path.join(dshHome(), 'profiles', 'desktop')
|
||||
const profilePackage = path.join(profileDir, 'package.json')
|
||||
|
||||
let profile = null
|
||||
check('读取 profile/package.json', () => {
|
||||
profile = JSON.parse(fs.readFileSync(profilePackage, 'utf8'))
|
||||
return profilePackage
|
||||
})
|
||||
|
||||
check('profile 的 dependencies 里链了本插件', () => {
|
||||
const spec = profile?.dependencies?.[PLUGIN_ID]
|
||||
if (typeof spec !== 'string' || spec === '') throw new Error(`dependencies 里没有 ${PLUGIN_ID}`)
|
||||
return spec
|
||||
})
|
||||
|
||||
check('profile 的 bundles 里登记了本插件', () => {
|
||||
const bundles = profile?.dsh?.profile?.bundles
|
||||
if (!Array.isArray(bundles) || !bundles.includes(PLUGIN_ID)) {
|
||||
throw new Error(`dsh.profile.bundles 里没有 ${PLUGIN_ID}(现有:${Array.isArray(bundles) ? bundles.join(', ') : '无'})`)
|
||||
}
|
||||
return `${bundles.length} 个 bundle`
|
||||
})
|
||||
|
||||
const linkedDir = path.join(profileDir, 'node_modules', PLUGIN_ID)
|
||||
|
||||
let entryFile = null
|
||||
check('链接目录与入口文件存在', () => {
|
||||
const stat = fs.statSync(linkedDir)
|
||||
if (!stat.isDirectory()) throw new Error(`${linkedDir} 不是目录`)
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(linkedDir, 'package.json'), 'utf8'))
|
||||
const exported = pkg?.exports?.['./client']
|
||||
const rel = typeof exported === 'string' ? exported : exported?.import ?? exported?.default
|
||||
if (typeof rel !== 'string') throw new Error('package.json 没有 exports["./client"]')
|
||||
entryFile = path.join(linkedDir, rel)
|
||||
const size = fs.statSync(entryFile).size
|
||||
if (size < 1024) throw new Error(`入口文件过小(${size} 字节),可能是空壳`)
|
||||
return `${path.basename(entryFile)} · ${size} 字节`
|
||||
})
|
||||
|
||||
check('客户端 bundle 语法可解析(语法错会让整页白屏)', () => {
|
||||
if (entryFile === null) throw new Error('上一个检查没通过,跳过')
|
||||
const text = fs.readFileSync(entryFile, 'utf8')
|
||||
if (!text.includes('__ModuleLoader__')) throw new Error('入口不像 DSH 客户端 bundle(缺少 __ModuleLoader__)')
|
||||
if (!text.includes(PLUGIN_ID)) throw new Error(`入口里没有插件 id ${PLUGIN_ID}`)
|
||||
// 只解析不执行:能抓住未闭合括号、非法 token 这类致命错误。
|
||||
new vm.Script(text, { filename: entryFile })
|
||||
return `${Math.round(text.length / 1024)} KB`
|
||||
})
|
||||
|
||||
check('Host 侧装配:内存账本上能起 12 条路由', () => {
|
||||
const routes = new Map()
|
||||
const fakeCtx = {
|
||||
get: () => undefined,
|
||||
webServer: {
|
||||
register(route) {
|
||||
routes.set(route.path, route)
|
||||
return () => routes.delete(route.path)
|
||||
},
|
||||
},
|
||||
}
|
||||
const store = new WorkbenchStore({ file: null })
|
||||
const host = createWorkbenchHost(fakeCtx, { store, startReconciler: false, load: false })
|
||||
try {
|
||||
if (routes.size !== 12) throw new Error(`注册了 ${routes.size} 条路由,预期 12 条`)
|
||||
// bootstrap 要落在具体项目上才有席位;这里现建一个临时项目,不写磁盘。
|
||||
const project = host.service.registerProject({ hostWorkspaceId: 'preflight' }).project
|
||||
const boot = host.service.bootstrap(project.id)
|
||||
if (!Array.isArray(boot.seats) || boot.seats.length !== 10) throw new Error('bootstrap 没有给出十席')
|
||||
return `${routes.size} 条路由 · 十席就位`
|
||||
} finally {
|
||||
host.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
check('账本落点可写(重启后第一次写账不会失败)', () => {
|
||||
const dir = path.join(dshHome(), 'sansheng-liubu')
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
const probe = path.join(dir, '.preflight')
|
||||
fs.writeFileSync(probe, String(Date.now()))
|
||||
fs.rmSync(probe, { force: true })
|
||||
return dir
|
||||
})
|
||||
|
||||
let failed = 0
|
||||
for (const row of results) {
|
||||
const mark = row.ok ? 'PASS' : 'FAIL'
|
||||
if (!row.ok) failed += 1
|
||||
process.stdout.write(`[${mark}] ${row.name}${row.detail ? ` — ${row.detail}` : ''}\n`)
|
||||
}
|
||||
process.stdout.write(`\n${results.length - failed}/${results.length} 通过\n`)
|
||||
if (failed > 0) process.exitCode = 1
|
||||
|
|
@ -205,3 +205,47 @@ test('A17 宿主重启:账本重开后项目/绑定/配置/任务/派发都还
|
|||
rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('A26 切项目后草稿、绑定、配置各归所属,不互相串', () => {
|
||||
const store = memoryStore()
|
||||
const service = createWorkbenchService({ store, clock })
|
||||
const a = service.registerProject({ hostWorkspaceId: 'ws-a', displayNameCache: 'A' }).project
|
||||
const b = service.registerProject({ hostWorkspaceId: 'ws-b', displayNameCache: 'B' }).project
|
||||
|
||||
// 两个项目各自的工部配置不同,且都绑了不同会话。
|
||||
service.saveDepartmentConfig({ projectId: a.id, roleId: 'gongbu', provider: 'magpie', model: 'workbuddy/deepseek-v4.1-flash', expectedRevision: 0 })
|
||||
service.saveDepartmentConfig({ projectId: b.id, roleId: 'gongbu', provider: 'magpie', model: 'workbuddy/deepseek-v4.1-pro', expectedRevision: 0 })
|
||||
service.bindDepartmentSession({ projectId: a.id, roleId: 'gongbu', sessionId: 'ses_a_gongbu' })
|
||||
service.bindDepartmentSession({ projectId: b.id, roleId: 'gongbu', sessionId: 'ses_b_gongbu' })
|
||||
|
||||
// A 里存一份草稿(还没派工的修订单)。
|
||||
const taskA = service.createTask({
|
||||
projectId: a.id, ownerRoleId: 'gongbu', sourceRoleId: 'lead',
|
||||
title: 'A 的草稿', objective: 'o', status: 'draft',
|
||||
}).task
|
||||
const taskB = service.createTask({
|
||||
projectId: b.id, ownerRoleId: 'gongbu', sourceRoleId: 'lead',
|
||||
title: 'B 的草稿', objective: 'o', status: 'draft',
|
||||
}).task
|
||||
|
||||
const bootA = service.bootstrap(a.id)
|
||||
const bootB = service.bootstrap(b.id)
|
||||
const gongbuA = bootA.seats.find((seat) => seat.roleId === 'gongbu')
|
||||
const gongbuB = bootB.seats.find((seat) => seat.roleId === 'gongbu')
|
||||
|
||||
// 配置与绑定各归各的:切项目不会把 A 的模型/会话带到 B。
|
||||
assert.equal(gongbuA.config.model, 'workbuddy/deepseek-v4.1-flash')
|
||||
assert.equal(gongbuB.config.model, 'workbuddy/deepseek-v4.1-pro')
|
||||
assert.equal(gongbuA.binding.currentSessionId, 'ses_a_gongbu')
|
||||
assert.equal(gongbuB.binding.currentSessionId, 'ses_b_gongbu')
|
||||
|
||||
// 草稿也只是各自项目里的任务,不会出现在对方列表里。
|
||||
const titlesA = bootA.tasks.map((task) => task.title)
|
||||
const titlesB = bootB.tasks.map((task) => task.title)
|
||||
assert.ok(titlesA.includes('A 的草稿'))
|
||||
assert.ok(!titlesA.includes('B 的草稿'))
|
||||
assert.ok(titlesB.includes('B 的草稿'))
|
||||
assert.ok(!titlesB.includes('A 的草稿'))
|
||||
assert.equal(taskA.projectId, a.id)
|
||||
assert.equal(taskB.projectId, b.id)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue