dsh-agent-board 1.7.5 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -480,6 +480,27 @@ test('buildVerifierPrompt: 注入交付物 + 验收脚本 + messages', () => {
480
480
  assert.match(p, /做完了/); assert.match(p, /npm test/); assert.match(p, /board_verdict/); assert.match(p, /方案B/)
481
481
  })
482
482
 
483
+ test('buildWorkerPrompt: git 纪律红线(禁还原命令)注入,verifier prompt 不注入(源码断言)', () => {
484
+ const t = mkTask({ id: 'g1' })
485
+ const p = core.buildWorkerPrompt(t)
486
+ assert.match(p, /git 纪律红线/)
487
+ assert.match(p, /禁止 git checkout \/ git restore \/ git reset --hard \/ git clean 等还原命令/)
488
+ assert.match(p, /会冲掉并行 Worker 与你自己的未提交在途编辑/)
489
+ assert.match(p, /确实需要干净基线时用 board_report(kind=escalate)上报/)
490
+ // verifier prompt 不动
491
+ const pv = core.buildVerifierPrompt(t)
492
+ assert.doesNotMatch(pv, /git 纪律红线/)
493
+ assert.doesNotMatch(pv, /reset --hard/)
494
+ // 源码级:条款只在 buildWorkerPrompt 体内(切片边界到 buildVerifierPrompt 之前),不在 buildVerifierPrompt 体内
495
+ const coreSrc = readFileSync(new URL('../lib/core.mjs', import.meta.url), 'utf8')
496
+ const wBody = coreSrc.slice(coreSrc.indexOf('export function buildWorkerPrompt'), coreSrc.indexOf('export function buildVerifierPrompt'))
497
+ assert.ok(wBody.length > 500, 'buildWorkerPrompt 切片成功')
498
+ assert.match(wBody, /git 纪律红线/)
499
+ assert.match(wBody, /git reset --hard/)
500
+ const vBody = coreSrc.slice(coreSrc.indexOf('export function buildVerifierPrompt'), coreSrc.indexOf('export function buildHookPrompt'))
501
+ assert.doesNotMatch(vBody, /git 纪律红线/)
502
+ })
503
+
483
504
  // ===== 预研上下文段(瘦身分离形态,task-muvjs392):笔记全文 + 文件清单,不含文件内容本体 =====
484
505
  // 形态:### 主窗口调研笔记(全文 ≤8000 字符)\n…\n\n### 调研文件清单(- 路径:L起-L止 — 一句用途)
485
506
  test('buildContextPackSection: 空清单返回空串', () => {
@@ -1297,6 +1318,103 @@ test('create-task RPC: 空描述 + 无调研上下文 + 整树 glob → 三条
1297
1318
  assert.equal(r.warning.split(';').length, 3)
1298
1319
  })
1299
1320
 
1321
+ // ===== 任务起草 lint(proposal n-muwlpbspl3w2):四规则 lintWarnings[],不阻塞 =====
1322
+ // 与「调研门禁」(createTaskWarnings,瞬态 warning)正交:这是起草质量持久诊断(存 task.lintWarnings[],
1323
+ // get-tasks 透出、详情页 ⚠️ 行)。纯函数 draftLint 在 core.mjs,双仓库歧义读盘经 io 注入。
1324
+
1325
+ test('touchDirPrefix: 剥 glob 尾段得目录前缀(裸文件名/纯 ** 无锚点 → 空)', () => {
1326
+ assert.equal(core.touchDirPrefix('packages/dsh-agent-board/**'), 'packages/dsh-agent-board')
1327
+ assert.equal(core.touchDirPrefix('src/**'), 'src')
1328
+ assert.equal(core.touchDirPrefix('src/x.mjs'), 'src')
1329
+ assert.equal(core.touchDirPrefix('a/b/c.mjs'), 'a/b')
1330
+ assert.equal(core.touchDirPrefix('core.mjs'), '') // 裸文件名无目录锚点,不参与判重
1331
+ assert.equal(core.touchDirPrefix('**'), '')
1332
+ })
1333
+
1334
+ test('ambiguousTouch: ≥2 子目录同名命中 → 返回相对路径原文;绝对路径/盘符/裸名/缺 io → null', () => {
1335
+ const two = { root: 'ws', subdirs: ['task-board-plugin', 'task-board-federation', 'other'], dirExists: (p) => p === path.join('ws', 'task-board-plugin', 'packages/dsh-agent-board') || p === path.join('ws', 'task-board-federation', 'packages/dsh-agent-board') }
1336
+ assert.equal(core.ambiguousTouch(['packages/dsh-agent-board/core.mjs'], two), 'packages/dsh-agent-board/core.mjs')
1337
+ const one = { root: 'ws', subdirs: ['task-board-plugin', 'other'], dirExists: (p) => p === path.join('ws', 'task-board-plugin', 'packages/dsh-agent-board') }
1338
+ assert.equal(core.ambiguousTouch(['packages/dsh-agent-board/core.mjs'], one), null)
1339
+ assert.equal(core.ambiguousTouch(['/abs/pkg/core.mjs'], two), null) // 绝对路径不判
1340
+ assert.equal(core.ambiguousTouch(['C:\\abs\\pkg\\core.mjs'], two), null) // 盘符不判
1341
+ assert.equal(core.ambiguousTouch(['core.mjs'], two), null) // 裸文件名不判
1342
+ assert.equal(core.ambiguousTouch(['src/**'], null), null) // 缺 io → 零 IO 安全
1343
+ assert.equal(core.ambiguousTouch(['src/**'], { subdirs: ['a', 'b'] }), null) // 缺 dirExists → 退化为不触发
1344
+ })
1345
+
1346
+ test('draftLint: 四规则各一触发 + 各一不触发(纯函数矩阵)', () => {
1347
+ const io2 = { root: 'ws', subdirs: ['a', 'b'], dirExists: (p) => p === path.join('ws', 'a', 'pkg') || p === path.join('ws', 'b', 'pkg') }
1348
+ // ① 整树 glob:触发 / 不触发(精确到文件级不触发)
1349
+ const t1 = mkTask({ title: '修复样式', description: 'd', acceptance: 'node --test', touches: ['src/**'] })
1350
+ assert.ok(core.draftLint(t1).includes(core.TREE_GLOB_LINT))
1351
+ assert.ok(!core.draftLint(mkTask({ title: '修复样式', description: 'd', acceptance: 'node --test', touches: ['src/x.mjs'] })).includes(core.TREE_GLOB_LINT))
1352
+ // ② 双仓库歧义:触发 / 不触发(目录前缀在两个子目录下都存在才算歧义)
1353
+ const t2 = mkTask({ title: '修复 x', description: 'd', acceptance: 'node --test', touches: ['pkg/core.mjs'] })
1354
+ assert.match(core.draftLint(t2, io2).find((w) => w.indexOf(core.AMBIGUOUS_PATH_LINT) === 0), /pkg\/core\.mjs/)
1355
+ const io1 = { root: 'ws', subdirs: ['a', 'b'], dirExists: (p) => p === path.join('ws', 'a', 'pkg') }
1356
+ assert.equal(core.draftLint(t2, io1).find((w) => w.indexOf(core.AMBIGUOUS_PATH_LINT) === 0), undefined)
1357
+ // ③ full 无验收:触发 / 不触发(work 档或有验收不触发)
1358
+ assert.ok(core.draftLint(mkTask({ title: '修复 x', description: 'd', pipeline: 'full', acceptance: '' })).includes(core.FULL_NO_ACCEPTANCE_LINT))
1359
+ assert.ok(!core.draftLint(mkTask({ title: '修复 x', description: 'd', pipeline: 'work', acceptance: '' })).includes(core.FULL_NO_ACCEPTANCE_LINT))
1360
+ assert.ok(!core.draftLint(mkTask({ title: '修复 x', description: 'd', pipeline: 'full', acceptance: 'node --test' })).includes(core.FULL_NO_ACCEPTANCE_LINT))
1361
+ // ④ 标题缺动词 / 描述空:触发 / 不触发
1362
+ const t4 = mkTask({ title: '看板规则', description: 'd', acceptance: 'node --test' })
1363
+ assert.ok(core.draftLint(t4).includes(core.TITLE_NO_VERB_LINT))
1364
+ const t4n = mkTask({ title: '修复 lint 规则', description: '明确描述', acceptance: 'node --test' })
1365
+ assert.ok(!core.draftLint(t4n).includes(core.TITLE_NO_VERB_LINT))
1366
+ assert.ok(!core.draftLint(t4n).includes(core.EMPTY_DESC_WARNING))
1367
+ assert.ok(core.draftLint(mkTask({ title: '修复 x', description: '', acceptance: 'node --test' })).includes(core.EMPTY_DESC_WARNING))
1368
+ })
1369
+
1370
+ test('create-task RPC: 起草 lint 落卡 lintWarnings[],get-tasks 透出(不阻断创建)', async () => {
1371
+ const board = mkBoard([])
1372
+ const h = mkRpcHandlers(board)
1373
+ const r = await h['create-task']({ title: '修复 lint 规则', description: '明确描述', touches: ['src/**'], acceptance: 'node --test' })
1374
+ assert.equal(r.ok, true)
1375
+ assert.deepEqual(r.task.lintWarnings, [core.TREE_GLOB_LINT])
1376
+ const got = await h['get-tasks']({})
1377
+ assert.deepEqual(got.tasks[0].lintWarnings, [core.TREE_GLOB_LINT])
1378
+ })
1379
+
1380
+ test('update-task RPC: 改标题后重算 lintWarnings(无动词标题触发,改回动词清空)', async () => {
1381
+ const board = mkBoard([mkTask({ id: 't1', title: '修复 x', description: 'd', acceptance: 'node --test' })])
1382
+ const h = mkRpcHandlers(board)
1383
+ assert.equal(board.tasks[0].lintWarnings, undefined) // 直接建卡无字段(老卡零字段)
1384
+ const r = await h['update-task']({ taskId: 't1', title: '看板规则' })
1385
+ assert.deepEqual(r.task.lintWarnings, [core.TITLE_NO_VERB_LINT])
1386
+ const r2 = await h['update-task']({ taskId: 't1', title: '修复 lint 规则' })
1387
+ assert.deepEqual(r2.task.lintWarnings, [])
1388
+ })
1389
+
1390
+ test('起草 lint:老卡无 lintWarnings 字段 → get-tasks 照常返回不炸(零字段兼容)', async () => {
1391
+ const board = mkBoard([mkTask({ id: 'old', title: '老卡', description: 'd', acceptance: 'node --test' })])
1392
+ const h = mkRpcHandlers(board)
1393
+ const got = await h['get-tasks']({})
1394
+ assert.equal(got.tasks.length, 1)
1395
+ assert.equal(got.tasks[0].lintWarnings, undefined) // 不补造字段,undefined 不炸
1396
+ })
1397
+
1398
+ test('起草 lint 接线:四入口 draftLint 落卡 + 详情 ⚠️ 行 + README 双份(源码级断言)', () => {
1399
+ const host = hostSrc()
1400
+ assert.equal((host.match(/t\.lintWarnings = draftLint\(t, draftLintIo\(sid, d\.ownerCwd\)/g) || []).length, 4) // task_create/create-task/task_update/update-task 四入口
1401
+ assert.equal((host.match(/function draftLintIo\(/g) || []).length, 1) // IO 注入 helper 单一出处
1402
+ const coreSrc = readFileSync(new URL('../lib/core.mjs', import.meta.url), 'utf8')
1403
+ assert.match(coreSrc, /export function draftLint\(t, io\)/)
1404
+ assert.match(coreSrc, /export function ambiguousTouch\(touches, io\)/)
1405
+ assert.match(coreSrc, /export function touchDirPrefix\(p\)/)
1406
+ assert.match(coreSrc, /TREE_GLOB_LINT = 'touches 粒度过粗,几乎锁整仓'/)
1407
+ assert.match(coreSrc, /AMBIGUOUS_PATH_LINT = '路径双仓库歧义,建议加仓库前缀'/)
1408
+ assert.match(coreSrc, /FULL_NO_ACCEPTANCE_LINT = 'full 管线建议带验收命令'/)
1409
+ assert.match(coreSrc, /TITLE_NO_VERB_LINT = '标题缺动作动词/)
1410
+ const detail = readFileSync(new URL('../lib/client/task-detail.js', import.meta.url), 'utf8')
1411
+ assert.match(detail, /task\.lintWarnings\.map\(function \(w, i\)/) // 详情 ⚠️ 行小块
1412
+ const pkgReadme = readFileSync(new URL('../README.md', import.meta.url), 'utf8')
1413
+ const rootReadme = readFileSync(new URL('../../../README.md', import.meta.url), 'utf8')
1414
+ assert.equal((pkgReadme.match(/lintWarnings\[\]/g) || []).length, 2) // 包 README 双处(调研门禁 + 三档通用)
1415
+ assert.equal((rootReadme.match(/lintWarnings\[\]/g) || []).length, 2) // 根 README 同步双处
1416
+ })
1417
+
1300
1418
  test('epicPrecheck: 字段有无 + 路径存在性(exists 注入),direct/归档子任务不参与', () => {
1301
1419
  const kids = [
1302
1420
  mkTask({ id: 'k1', title: '无材料', parentId: 'ep', context: { files: [], notes: '' } }),
@@ -1601,6 +1719,79 @@ test('buildVerifierPrompt: 含「立单缺调研」驳回归因条款', () => {
1601
1719
  assert.match(p, /驳回热点统计/)
1602
1720
  })
1603
1721
 
1722
+ // ===== Verifier 验收员加餐(task-muy3gm03):固定 persona + 文件纪律 + toolFilter 收窄 =====
1723
+ test('Verifier 加餐①:VERIFIER_PERSONA 常量——验收员四要点 + 无 {{ 连写括号(严格插值护栏)', () => {
1724
+ const ps = core.VERIFIER_PERSONA
1725
+ assert.equal(typeof ps, 'string')
1726
+ assert.match(ps, /独立验收员/) // 人设定位
1727
+ assert.match(ps, /独立判断/) // ① 独立判断
1728
+ assert.match(ps, /不轻信/) // ① 不轻信 Worker 汇报
1729
+ assert.match(ps, /实证为准/) // ② 以验收脚本实证为准
1730
+ assert.match(ps, /诚实分级/) // ③ 诚实分级(自测指南三档)
1731
+ assert.match(ps, /双读者/) // ④ 结论给主窗口与用户双读者
1732
+ // 宿主对 persona 做严格 {{…}} 插值(同 deployment persona 模板语义)——文本不得含连写 {
1733
+ assert.ok(!/\{\{/.test(ps), 'persona 文本不得含 {{(严格插值会抛异常)')
1734
+ })
1735
+
1736
+ test('Verifier 加餐②:文件纪律条款在 verifier prompt;worker prompt 不含(parity)', () => {
1737
+ const t = mkTask({ id: 'tx', status: 'verifying' })
1738
+ const pv = core.buildVerifierPrompt(t, '')
1739
+ assert.match(pv, /文件纪律/) // 条款标题
1740
+ assert.match(pv, /可以写必要的临时\/测试文件/) // 允许写临时/测试文件
1741
+ assert.match(pv, /_scratch/) // 临时文件落点
1742
+ assert.match(pv, /验收结束后自行清理/) // 验收结束清理
1743
+ assert.match(pv, /禁止改动工程代码与文档/) // 工程代码/文档只读
1744
+ assert.match(pv, /touches 审计兜底/) // 事后兜底威慑写明
1745
+ // 条款在结论契约之前(纪律先行)
1746
+ assert.ok(pv.indexOf('文件纪律') < pv.indexOf('结论契约'), '文件纪律段先于结论契约')
1747
+ // worker prompt 逐字 parity:不含任何文件纪律/加餐条款
1748
+ const pw = core.buildWorkerPrompt(mkTask({ id: 'tx', status: 'pending' }), '')
1749
+ assert.doesNotMatch(pw, /文件纪律/)
1750
+ assert.doesNotMatch(pw, /touches 审计/)
1751
+ })
1752
+
1753
+ test('Verifier 加餐③:toolFilter 保守收窄——只 deny 联网检索,无 allow 白名单(注释锁定保守理由)', () => {
1754
+ // 白名单断言:收窄为 deny 形态,只砍 web_fetch/web_search(验收不需联网)
1755
+ assert.deepEqual(core.VERIFIER_TOOL_FILTER, { deny: ['web_fetch', 'web_search'] })
1756
+ assert.equal(core.VERIFIER_TOOL_FILTER.allow, undefined, '不设 allow 白名单(拿不准的宁可不收窄)')
1757
+ // 注释存在性断言:core.mjs 写明保守理由(其余工具保留的逐类口径)
1758
+ const coreSrc = readFileSync(new URL('../lib/core.mjs', import.meta.url), 'utf8')
1759
+ assert.match(coreSrc, /toolFilter 收窄评估结论(保守口径)/)
1760
+ assert.match(coreSrc, /拿不准的宁可不收窄/)
1761
+ })
1762
+
1763
+ test('Verifier 加餐④:真派发接线——verifier spawn 挂 persona/toolFilter,worker spawn 逐字 parity', async () => {
1764
+ // 真跑 poolCycle:一张 verifying 卡(派 verifier)+ 一张 pending 卡(派 worker,continuable 路径)
1765
+ const tv = mkTask({ id: 'v1', status: 'verifying' })
1766
+ const tw = mkTask({ id: 'w1', status: 'pending' })
1767
+ const h = mkHookDispatch(mkBoard([tv, tw]))
1768
+ await h.dispatch.poolCycle(FULL_SID)
1769
+ const v = h.spawned.find((s) => s.label === 'verifier:v1')
1770
+ assert.ok(v, 'verifier 按真实派发路径 spawn(一次性 start)')
1771
+ assert.equal(v.persona, core.VERIFIER_PERSONA, 'verifier spawn 挂固定验收员 persona')
1772
+ assert.deepEqual(v.toolFilter, { deny: ['web_fetch', 'web_search'] }, 'verifier spawn 挂收窄 toolFilter')
1773
+ const w = h.spawnedContinuable.find((s) => s.label === 'worker:w1')
1774
+ assert.ok(w, 'worker 按真实派发路径 spawn(continuable)')
1775
+ assert.equal(w.persona, undefined, 'worker spawn 不挂 persona(逐字 parity)')
1776
+ assert.equal(w.toolFilter, undefined, 'worker spawn 不挂 toolFilter(逐字 parity)')
1777
+ // hook run 也不挂(hook 只吃 buildHookPrompt 薄框架,不加验收员人设)
1778
+ assert.ok(h.spawned.every((s) => s.label.indexOf('hook') !== 0 || s.persona === undefined), 'hook spawn 不挂加餐')
1779
+ })
1780
+
1781
+ test('Verifier 加餐⑤:源码级锁定——加餐只挂 verifier 分支 + 失败回退剥外挂参数', () => {
1782
+ const dsp = readFileSync(new URL('../lib/dispatch.mjs', import.meta.url), 'utf8')
1783
+ // ① 挂载点只有一处,且被 role === 'verifier' 守门(worker/hook 不可能挂上)
1784
+ assert.match(dsp, /if \(role === 'verifier'\) \{ req\.persona = VERIFIER_PERSONA; req\.toolFilter = VERIFIER_TOOL_FILTER \}/)
1785
+ assert.equal((dsp.match(/req\.persona = VERIFIER_PERSONA/g) || []).length, 1)
1786
+ assert.equal((dsp.match(/req\.toolFilter = VERIFIER_TOOL_FILTER/g) || []).length, 1)
1787
+ // ② 常量从 core 解构导入(单一事实源)
1788
+ assert.match(dsp, /VERIFIER_PERSONA, VERIFIER_TOOL_FILTER/)
1789
+ // ③ 回退兜底:spawn 失败剥光外挂参数(persona/toolFilter/agentOptions)裸请求重试
1790
+ assert.match(dsp, /delete req\.agentOptions; delete req\.persona; delete req\.toolFilter/)
1791
+ // ④ 注释写明 continuable 面不支持 persona 的实证结论(只挂一次性面的理由)
1792
+ assert.match(dsp, /continuable 面(ContinuableCreateRequest 仅 sessionId\/parent\/signal)/)
1793
+ })
1794
+
1604
1795
  test('调研遵循接线:双通道 attachContextSuggestions / 驳回 hint 双挂 / Verifier 归因条款(源码级断言)', () => {
1605
1796
  const src = hostSrc()
1606
1797
  assert.equal((src.match(/attachContextSuggestions\(/g) || []).length, 2) // task_create 工具 + create-task RPC
@@ -2077,7 +2268,7 @@ test('Token 日账接线:dispatch 记 byDay 双指标(本地日)+ 仪表
2077
2268
  assert.match(cli, /'近 7 天(总量,含缓存读)'/)
2078
2269
  assert.match(cli, /k\.slice\(5\) \+ ':总量 ' \+ String\(v\)/) // 条形 title:MM-DD:总量 N tok
2079
2270
  assert.match(cli, /' \/ 有效 ' \+ String\(c\.e\) \+ ' tok'/) // 条形 title 补有效对照
2080
- assert.match(cli, /口径:累计与 Top 8 仅看板派发的 Worker\/Verifier run 消耗/) // 口径边界明示(累计/Top8 仅 run 口径)
2271
+ assert.match(cli, /口径:累计与 Top 8 仅看板派发的 Worker\/Verifier run(= 一次执行)消耗/) // 口径边界明示(累计/Top8 仅 run 口径)
2081
2272
  assert.match(cli, /主窗口行=本会话对话消耗,与看板派发口径并列不混入/) // 主窗口行并列不混入(task-muwsol23 起单列展示)
2082
2273
  assert.match(cli, /主数字(今日 \/ 近 7 天 \/ 模型分布 \/ Top 8 \/ 主窗口行)均为总量口径(含缓存读)/) // 主数字口径翻转(task-muxnqunk)
2083
2274
  assert.match(cli, /其中缓存读 ' \+ String\(x\.cacheRead \|\| 0\)/) // Top8 title 补 缓存读 拆分(有效进 title)
@@ -2517,6 +2708,51 @@ test('FamilySection: 子任务清单含归档(灰化 + 「已归档」徽章 +
2517
2708
  assert.match(built, /csDone/)
2518
2709
  })
2519
2710
 
2711
+ test('详情「运行」区:渲染活跃 run 子会话 id(childId)+ 标注「对应子代理列表同名条目」(源码级断言)', () => {
2712
+ const src = readFileSync(new URL('../lib/client/task-detail.js', import.meta.url), 'utf8')
2713
+ // 运行区门禁:仅 in-progress + claimedBy(有活跃 run)才渲染,claimedBy 即该 run 的子会话 id(childId)
2714
+ assert.match(src, /task\.status === 'in-progress' && task\.claimedBy \?/)
2715
+ assert.match(src, /'子会话 id: ' \+ task\.claimedBy/)
2716
+ assert.match(src, /对应子代理列表同名条目/)
2717
+ // 组装产物里也要有(npm pretest 已保证 build-client 先跑)
2718
+ const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
2719
+ assert.match(built, /'子会话 id: ' \+ task\.claimedBy/)
2720
+ assert.match(built, /对应子代理列表同名条目/)
2721
+ })
2722
+
2723
+ test('README 双份:运行区子会话 id 归属标注 + git 纪律红线各补一句且逐字一致', () => {
2724
+ const r1 = readFileSync(new URL('../../../README.md', import.meta.url), 'utf8')
2725
+ const r2 = readFileSync(new URL('../README.md', import.meta.url), 'utf8')
2726
+ assert.equal(r1, r2, 'README 双份必须逐字一致(npm run sync-readme)')
2727
+ assert.ok(r1.indexOf('对应子代理列表同名条目') >= 0, 'README 缺运行区子会话 id 归属标注说明')
2728
+ assert.ok(r1.indexOf('git 纪律红线') >= 0, 'README 缺 git 纪律红线说明')
2729
+ })
2730
+
2731
+ // ===== 归档 tab 数据源口径(反馈 n-muyg3e0m9z7i):归档 tab 空 vs 仪表盘 68 根修 =====
2732
+ // 旧 ArchiveView 数据源走独立 state.archived/fetchArchived:异步填库却未接入 TopPanel 的 notify 更新项,
2733
+ // 归档 tab 打开后停在「暂无归档任务」空态;仪表盘「已归档」计数来自 state.tasks(get-tasks 全量含归档)。
2734
+ // 修法:ArchiveView 直接读 state.tasks.filter(status==='archived'),与仪表盘同源全量 + 归档时间倒序 + 顶部注条数。
2735
+ test('ArchiveView: 归档数据源读 state.tasks 全量(对齐仪表盘「已归档」),不依赖 state.archived/fetchArchived(源码级断言)', () => {
2736
+ const src = readFileSync(new URL('../lib/client/board-list.js', import.meta.url), 'utf8')
2737
+ // 数据源必须与仪表盘同源:state.tasks.filter(status==='archived')(get-tasks 全量含归档)
2738
+ assert.match(src, /var archived = state\.tasks\.filter\(function \(t\) \{ return t\.status === 'archived' \}\)/)
2739
+ // 反向断言:不得再读独立 state.archived.filter(异步填库不触发重渲染 → tab 恒空)
2740
+ assert.doesNotMatch(src, /state\.archived\.filter/)
2741
+ // 不得再挂「空则 fetchArchived」的 useEffect(独立数据源已移除)
2742
+ assert.doesNotMatch(src, /useEffect\(function \(\) \{ if \(!state\.archived\.length\) fetchArchived\(\) \}/)
2743
+ // 不得有任何 7 日窗口 cutoff(老归档 >7 天被整批滤掉是原根因候选形态之一)
2744
+ assert.doesNotMatch(src, /cutoff/)
2745
+ assert.doesNotMatch(src, /7 \* 24 \* 60|7 \* 86400000|604800000/)
2746
+ // 顶部注明条数(与仪表盘「已归档」同口径)
2747
+ assert.match(src, /'共 ' \+ archived\.length \+ ' 条归档/)
2748
+ // 归档时间倒序:archivedAt 优先,回退 resolvedAt/createdAt
2749
+ assert.match(src, /function archTs\(t\) \{ return t\.archivedAt \|\| t\.resolvedAt \|\| t\.createdAt \|\| '' \}/)
2750
+ // 组装产物同步(pretest 已跑 build-client)
2751
+ const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
2752
+ assert.match(built, /var archived = state\.tasks\.filter\(function \(t\) \{ return t\.status === 'archived' \}\)/)
2753
+ assert.match(built, /'共 ' \+ archived\.length \+ ' 条归档/)
2754
+ })
2755
+
2520
2756
  // ===== 史诗 hooks=agent run(task-muuw4ov7):host 生命周期接线(pre 闸门 / post 收口 / 薄框架 prompt / 主窗口限定写入)=====
2521
2757
  // 设计定稿:hook 点 = 一次**真实 agent 运行**(不是声明式命令);点位可选(epic 未声明 hooks 则全链路零变化);
2522
2758
  // 薄框架 + agent 自行决策 + 歧义上报兜底;commit/push 不入任何默认形态;hooks 只许主窗口设置。
@@ -2790,11 +3026,11 @@ function mkHookDispatch(board, over) {
2790
3026
  list: () => ['mock'],
2791
3027
  getProvider: () => ({ inheritsParentContext: false }),
2792
3028
  start: async (name, req) => {
2793
- spawned.push({ name, label: req.label, text: req.prompt[0].text, parent: req.parent })
3029
+ spawned.push({ name, label: req.label, text: req.prompt[0].text, parent: req.parent, persona: req.persona, toolFilter: req.toolFilter })
2794
3030
  return { id: 'run-' + spawned.length, result: new Promise(function () {}), dispose: async function () {} }
2795
3031
  },
2796
3032
  startContinuable: async (spec) => {
2797
- spawnedContinuable.push({ name: spec.provider, label: spec.label, text: spec.request.prompt[0].text, parent: spec.request.parent })
3033
+ spawnedContinuable.push({ name: spec.provider, label: spec.label, text: spec.request.prompt[0].text, parent: spec.request.parent, persona: spec.request.persona, toolFilter: spec.request.toolFilter })
2798
3034
  return { childId: 'child-' + spawnedContinuable.length, messageId: 'msg-' + spawnedContinuable.length }
2799
3035
  },
2800
3036
  },
@@ -3490,9 +3726,10 @@ test('史诗语义层接线:poolCycle 派发分支触发父卡流转 + get-tas
3490
3726
  // 两模块都从 core 解构引入(接线不断);rpc.mjs 解构表尾部随调研门禁(task-mute6zpw)、调研遵循三件套(task-mutnj3a4)、
3491
3727
  // tasksHash(task-mutrtwin)、hooks 浅校验(normalizeHooks/mergeHooks,本批 hooks=agent run)、
3492
3728
  // 自测指南归一(normalizeUserTest,task-muxyyvg0)扩展;
3493
- // dispatch.mjs 解构表尾部追加 hook 族(buildHookPrompt/hookOn/hookSetState/gsb)与驳回包 helper(pushRejection,task-muvg15p5)
3494
- assert.match(host, /parentKickOnDispatch, LESSON_RECALL_HINT, buildHookPrompt, applyHookSettle, hookOn, hookSetState, gsb, pushRejection \} = core/)
3495
- assert.match(host, /boardHome, aggregateChildStats, createTaskWarnings, epicPrecheck, epicPrecheckNote, attachContextSuggestions, REJECT_REDISPATCH_HINT, tasksHash, normalizeHooks, mergeHooks, pushRejection, normalizeUserTest \} = core/)
3729
+ // dispatch.mjs 解构表尾部追加 hook 族(buildHookPrompt/hookOn/hookSetState/gsb)与驳回包 helper(pushRejection,task-muvg15p5)、
3730
+ // Verifier 验收员加餐常量(VERIFIER_PERSONA/VERIFIER_TOOL_FILTER,task-muy3gm03)
3731
+ assert.match(host, /parentKickOnDispatch, LESSON_RECALL_HINT, buildHookPrompt, applyHookSettle, hookOn, hookSetState, gsb, pushRejection, VERIFIER_PERSONA, VERIFIER_TOOL_FILTER \} = core/)
3732
+ assert.match(host, /boardHome, aggregateChildStats, createTaskWarnings, epicPrecheck, epicPrecheckNote, attachContextSuggestions, REJECT_REDISPATCH_HINT, tasksHash, normalizeHooks, mergeHooks, pushRejection, normalizeUserTest, draftLint \} = core/)
3496
3733
  // 既有「全子任务 resolved → 父 verifying」逻辑不动(checkParentAuto 仍在 verifyApply 链路;
3497
3734
  // 但其内部已委托共享 helper maybeAutoCloseParent——单一判定口径,core.mjs 不在 hostSrc 清单,单独读)
3498
3735
  const coreSrc = readFileSync(new URL('../lib/core.mjs', import.meta.url), 'utf8')
@@ -5291,3 +5528,57 @@ test('高优干预④(源码级):continuable 投递点 = host-protocol 符
5291
5528
  // 回退链顺序:host 投递在 sendMessage 之前(能保留插件 source 的通道优先)
5292
5529
  assert.ok(rpcSrc.indexOf('await host.call(subagents, parent, childId') < rpcSrc.indexOf('await subagents.sendMessage(parent, childId'), 'host 投递必须先于 sendMessage 回退')
5293
5530
  })
5531
+
5532
+ // ===== 巡检三连修(巡检实证三条):草稿发布预警 / 优先级 chip 单一状态源 / 批量归档跳过原因 =====
5533
+ test('巡检①:草稿态「保存并重置」改「保存并发布」+ 发布预警 title(源码级 + 文案存在性)', () => {
5534
+ const src = readFileSync(new URL('../lib/client/task-detail.js', import.meta.url), 'utf8')
5535
+ // 草稿态按钮文案切换(含「发布」字样),非草稿仍「保存并重置」——单一 createElement 内条件三元
5536
+ assert.match(src, /task\.status === 'draft' \? ' 保存并发布' : ' 保存并重置'/)
5537
+ // 草稿态 title 发布预警文案存在(发布后可能被立即派发)
5538
+ assert.match(src, /'发布后按当前工作模式可能被立即派发'/)
5539
+ // 组装产物同步(pretest 已跑 build-client)
5540
+ const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
5541
+ assert.match(built, /保存并发布/)
5542
+ assert.match(built, /发布后按当前工作模式可能被立即派发/)
5543
+ })
5544
+
5545
+ test('巡检②:优先级 chip 高亮与「清除」显隐统一读全局 state.filterPrio(消灭本地 fp 副本)', () => {
5546
+ const src = readFileSync(new URL('../lib/client/board-list.js', import.meta.url), 'utf8')
5547
+ // chip 高亮读全局 state.filterPrio(单一事实源)
5548
+ assert.match(src, /var on = state\.filterPrio\.indexOf\(p\) >= 0/)
5549
+ // 「清除」显隐也读全局 state.filterPrio
5550
+ assert.match(src, /var hasFilter = q\.trim\(\) \|\| state\.filterPrio\.length > 0 \|\| ft/)
5551
+ // 消灭本地副本:不得再出现 fp 副本初始化 / setFp 同步
5552
+ assert.doesNotMatch(src, /useState\(state\.filterPrio\)/)
5553
+ assert.doesNotMatch(src, /setFp/)
5554
+ // 组装产物同步
5555
+ const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
5556
+ assert.match(built, /var on = state\.filterPrio\.indexOf\(p\) >= 0/)
5557
+ assert.doesNotMatch(built, /setFp/)
5558
+ })
5559
+
5560
+ test('巡检③:batch-op archive 跳过附 reasons(id → 原因)且 client 渲成「标题:原因」列表', async () => {
5561
+ // host 行为:非 resolved/cancelled 卡跳过时记录 'cannot archive' 原因(不再只 skip 无因)
5562
+ const a = mkTask({ id: 'tf-a', status: 'resolved' })
5563
+ const b = mkTask({ id: 'tf-b', status: 'in-progress' })
5564
+ const c = mkTask({ id: 'tf-c', status: 'pending' })
5565
+ const board = mkBoard([a, b, c])
5566
+ const h = mkRpcHandlers(board)
5567
+ const r = await h['batch-op']({ op: 'archive', ids: ['tf-a', 'tf-b', 'tf-c'] })
5568
+ assert.equal(r.ok, true)
5569
+ assert.equal(r.done, 1)
5570
+ assert.deepEqual(r.skipped, ['tf-b', 'tf-c'])
5571
+ assert.equal(r.reasons['tf-b'], 'cannot archive')
5572
+ assert.equal(r.reasons['tf-c'], 'cannot archive')
5573
+ assert.equal(a.status, 'archived')
5574
+ assert.equal(b.status, 'in-progress')
5575
+ // client 渲染:reasonRows 把 reasons 对象转「标题:原因」列表(逐条,不再只显示「跳过 N」无原因)
5576
+ const src = readFileSync(new URL('../lib/client/board-list.js', import.meta.url), 'utf8')
5577
+ assert.match(src, /function reasonRows\(r\) \{ var m = \(r && r\.reasons\) \|\| \{\}; return Object\.keys\(m\)\.map/)
5578
+ assert.match(src, /it\.title \+ ':' \+ it\.reason/)
5579
+ assert.match(src, /'跳过原因'/)
5580
+ // 组装产物同步
5581
+ const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
5582
+ assert.match(built, /it\.title \+ ':' \+ it\.reason/)
5583
+ assert.match(built, /'跳过原因'/)
5584
+ })
@@ -504,3 +504,40 @@ test('集成i·孤儿回收:in-progress 无活跃 rec 的卡推进时钟后回
504
504
  assert.equal(env.sent.length, 0, '孤儿回收的系统通知攒在 sysNotesBuf 等回执冲刷,不单独投递')
505
505
  } finally { await env.cleanup() }
506
506
  })
507
+
508
+ // ===== 场景 j:归档数据源全量——老归档(>7 天)与仪表盘同口径,get-tasks 全量返回 =====
509
+ // 归档 tab 空 vs 仪表盘 68 的根因锁定(反馈 n-muyg3e0m9z7i):归档 tab 数据源必须与仪表盘「已归档」
510
+ // 计数同源(state.tasks 全量,无 7 日窗口、无字段缺失)。host 侧 get-tasks 本就返回全量含归档,
511
+ // 本用例锁死这条数据源契约:建卡→resolve→archive(含 archivedAt>7 天前构造)→断言归档数据源含该卡。
512
+ test('集成j·归档数据源全量:老归档(>7天)与仪表盘同口径,get-tasks 返回全部归档', async () => {
513
+ var env = createMockCtx()
514
+ try {
515
+ plugin.apply(env.ctx)
516
+ // 新归档 + 老归档各一张:先建卡再 resolve 再 archive(省去派发链路,直接走到可归档态)
517
+ await createTask(env, 'task-j1', { pipeline: 'work' })
518
+ await createTask(env, 'task-j2', { pipeline: 'work' })
519
+ env.patchBoard(function (d) {
520
+ d.tasks.forEach(function (t) { if (t.id === 'task-j1' || t.id === 'task-j2') { t.status = 'resolved'; t.resolvedAt = new Date(Date.now() - 86400000).toISOString() } })
521
+ })
522
+ var a1 = await env.rpc('archive-task', { sessionId: env.sid, taskId: 'task-j1' })
523
+ var a2 = await env.rpc('archive-task', { sessionId: env.sid, taskId: 'task-j2' })
524
+ assert.equal(a1.ok, true, 'task-j1 可归档')
525
+ assert.equal(a2.ok, true, 'task-j2 可归档')
526
+ // 构造老归档:task-j1 归档于 20 天前(>7 天),task-j2 归档于现在
527
+ env.patchBoard(function (d) {
528
+ var j1 = d.tasks.find(function (x) { return x.id === 'task-j1' })
529
+ j1.archivedAt = new Date(Date.now() - 20 * 86400000).toISOString()
530
+ })
531
+ // 归档数据源(get-tasks 全量):两张归档都在,老归档(>7 天)不被窗口滤掉
532
+ var d = await env.rpc('get-tasks', { sessionId: env.sid, includeArchived: true })
533
+ var arch = d.tasks.filter(function (t) { return t.status === 'archived' })
534
+ assert.equal(arch.length, 2, '归档数据源含全部归档(全量,无 7 日窗口)')
535
+ assert.ok(arch.some(function (t) { return t.id === 'task-j1' && new Date(Date.now()) - new Date(t.archivedAt) > 7 * 86400000 }), '老归档(>7 天)仍在归档数据源')
536
+ assert.ok(arch.some(function (t) { return t.id === 'task-j2' }), '新归档也在归档数据源')
537
+ // 归档字段完整:archivedAt 已落卡(客户端按归档时间倒序的数据源字段不缺)
538
+ assert.ok(arch.every(function (t) { return !!t.archivedAt }), '每张归档卡都带 archivedAt')
539
+ // 与仪表盘口径一致:仪表盘「已归档」= state.tasks 里 status==='archived' 的计数,二者同源同值
540
+ var d2 = await env.rpc('get-tasks', { sessionId: env.sid })
541
+ assert.equal(d2.tasks.filter(function (t) { return t.status === 'archived' }).length, 2, '无 includeArchived 时同样全量(与仪表盘计数同源)')
542
+ } finally { await env.cleanup() }
543
+ })
@@ -0,0 +1,128 @@
1
+ // dsh-agent-board — 异常驱动审视②③:质量异动告警 + 报告导出批次 digest 单测(test/quality-alert-digest.test.mjs,task-muysyad1)
2
+ // 覆盖(对应任务断言①~④ + 接线):
3
+ // ② 质量异动告警 qualityChangeHints(scoreboard.trends 环比)
4
+ // ① 阈值边界——一次通过率恰好 10pp 跌不亮 / 10.1pp 跌亮
5
+ // ② 样本不足——任一侧 <5 不亮(即便跌幅巨大);恰好 5/5 判
6
+ // ③ 超时率/驳回率突变同构各一条(涨 >10pp 亮);三条同命全出;empty/null/脏输入全形态不炸
7
+ // ③ 报告导出 buildReport「## 批次摘要(近 24 小时)」段(client 无渲染 harness,源码级断言):
8
+ // 字段齐全 + 无数据优雅空态 + 产物重组装
9
+ // ④ 接线 + README 双份——usage/rpc/index 挂 qualityChangeHints + rejectByDay + README 各补一句
10
+ import { test } from 'node:test'
11
+ import assert from 'node:assert/strict'
12
+ import { readFileSync } from 'node:fs'
13
+ import { qualityChangeHints, QUALITY_CHANGE_PP, QUALITY_MIN_SAMPLE, QUALITY_WINDOW_DAYS } from '../index.mjs'
14
+ import { localDayKey } from '../lib/usage.mjs'
15
+
16
+ // 固定「今天」= 2026-10-30 12:00(本地):近 7 天 = 10-24..10-30,再前 7 天 = 10-17..10-23
17
+ const NOW = new Date(2026, 9, 30, 12, 0, 0).getTime()
18
+ function dayOf(y, m, d) { return localDayKey(new Date(y, m - 1, d, 12)) }
19
+ const NEAR = dayOf(2026, 10, 30) // 近窗口某日
20
+ const PRIOR = dayOf(2026, 10, 20) // 前窗口某日
21
+
22
+ // ===== ②① 阈值边界 =====
23
+ test('②① 阈值边界:一次通过率恰好 10pp 跌不亮 / 10.1pp 跌亮(常量置顶核对)', () => {
24
+ assert.equal(QUALITY_CHANGE_PP, 10)
25
+ assert.equal(QUALITY_MIN_SAMPLE, 5)
26
+ assert.equal(QUALITY_WINDOW_DAYS, 7)
27
+ // 恰好 10pp:近 90%(900/1000)vs 前 100%(1000/1000)→ drop 10.0pp → 不亮
28
+ const exact = { trends: { firstPassByDay: { [NEAR]: { resolved: 1000, firstPass: 900 }, [PRIOR]: { resolved: 1000, firstPass: 1000 } }, timeoutByDay: {}, rejectByDay: {} } }
29
+ assert.deepEqual(qualityChangeHints(exact, NOW), [])
30
+ // 10.1pp:近 89.9%(899/1000)vs 前 100% → drop 10.1pp → 亮,文案逐字核对
31
+ const over = { trends: { firstPassByDay: { [NEAR]: { resolved: 1000, firstPass: 899 }, [PRIOR]: { resolved: 1000, firstPass: 1000 } }, timeoutByDay: {}, rejectByDay: {} } }
32
+ const h = qualityChangeHints(over, NOW)
33
+ assert.equal(h.length, 1)
34
+ assert.equal(h[0].level, 'warn')
35
+ assert.match(h[0].text, /质量异动:一次通过率本周 90%(上周 100%),建议抽查近期验收/)
36
+ })
37
+
38
+ // ===== ②② 样本不足 =====
39
+ test('②② 样本不足:任一侧 <5 不亮(即便 0% vs 100%);恰好 5/5 判', () => {
40
+ // 双侧皆 4(<5)→ 不亮
41
+ const s = { trends: { firstPassByDay: { [NEAR]: { resolved: 4, firstPass: 0 }, [PRIOR]: { resolved: 4, firstPass: 4 } }, timeoutByDay: {}, rejectByDay: {} } }
42
+ assert.deepEqual(qualityChangeHints(s, NOW), [])
43
+ // 仅一侧不足(近 5 / 前 4)→ 不亮
44
+ const s2 = { trends: { firstPassByDay: { [NEAR]: { resolved: 5, firstPass: 0 }, [PRIOR]: { resolved: 4, firstPass: 4 } }, timeoutByDay: {}, rejectByDay: {} } }
45
+ assert.deepEqual(qualityChangeHints(s2, NOW), [])
46
+ // 恰好 5/5 且大幅跌 → 亮(护栏边界:恰好 5 判,非 5 不判)
47
+ const s3 = { trends: { firstPassByDay: { [NEAR]: { resolved: 5, firstPass: 0 }, [PRIOR]: { resolved: 5, firstPass: 5 } }, timeoutByDay: {}, rejectByDay: {} } }
48
+ assert.equal(qualityChangeHints(s3, NOW).length, 1)
49
+ })
50
+
51
+ // ===== ②③ 超时率/驳回率同构 + 空形态 =====
52
+ test('②③ 超时率/驳回率突变同构各一条 + 三规则同命全出 + empty/null/脏输入不炸', () => {
53
+ // 超时率涨:近 20%(20/100)vs 前 5%(5/100)→ 涨 15pp → 亮
54
+ const to = { trends: { firstPassByDay: {}, timeoutByDay: { [NEAR]: { runs: 100, timeout: 20 }, [PRIOR]: { runs: 100, timeout: 5 } }, rejectByDay: {} } }
55
+ const ht = qualityChangeHints(to, NOW)
56
+ assert.equal(ht.length, 1)
57
+ assert.match(ht[0].text, /质量异动:超时率本周 20%(上周 5%),建议排查派发\/超时链路/)
58
+ // 驳回率涨:近 20 次驳回 / 前 5 次(分母 runs 各 100)→ 涨 15pp → 亮
59
+ const rj = { trends: { firstPassByDay: {}, timeoutByDay: { [NEAR]: { runs: 100, timeout: 0 }, [PRIOR]: { runs: 100, timeout: 0 } }, rejectByDay: { [NEAR]: { rejects: 20 }, [PRIOR]: { rejects: 5 } } } }
60
+ const hr = qualityChangeHints(rj, NOW)
61
+ assert.equal(hr.length, 1)
62
+ assert.match(hr[0].text, /质量异动:驳回率本周 20%(上周 5%),建议审查近期驳回原因/)
63
+ // 三条规则同时命中 → 三条全出(一次通过率 + 超时率 + 驳回率)
64
+ const all3 = { trends: { firstPassByDay: { [NEAR]: { resolved: 100, firstPass: 0 }, [PRIOR]: { resolved: 100, firstPass: 100 } }, timeoutByDay: { [NEAR]: { runs: 100, timeout: 50 }, [PRIOR]: { runs: 100, timeout: 0 } }, rejectByDay: { [NEAR]: { rejects: 50 }, [PRIOR]: { rejects: 0 } } } }
65
+ assert.equal(qualityChangeHints(all3, NOW).length, 3)
66
+ // empty/null/脏输入全形态不炸(老 host 缺 trends / rejectByDay 等)
67
+ assert.deepEqual(qualityChangeHints(null, NOW), [])
68
+ assert.deepEqual(qualityChangeHints({}, NOW), [])
69
+ assert.deepEqual(qualityChangeHints({ trends: {} }, NOW), [])
70
+ assert.deepEqual(qualityChangeHints({ trends: 'garbage' }, NOW), [])
71
+ assert.deepEqual(qualityChangeHints({ buckets: [] }, NOW), [])
72
+ // 缺 rejectByDay(老 host)只有超时率规则可判,驳回率规则静默跳过不炸
73
+ const noRj = { trends: { firstPassByDay: {}, timeoutByDay: { [NEAR]: { runs: 100, timeout: 30 }, [PRIOR]: { runs: 100, timeout: 0 } } } }
74
+ const hnr = qualityChangeHints(noRj, NOW)
75
+ assert.equal(hnr.length, 1)
76
+ assert.match(hnr[0].text, /质量异动:超时率本周/)
77
+ })
78
+
79
+ // ===== ③ 报告导出「批次摘要」段(源码级)=====
80
+ test('③ 报告段:buildReport「## 批次摘要(近 24 小时)」字段齐全 + 无数据优雅空态 + 产物重组装', () => {
81
+ const dash = readFileSync(new URL('../lib/client/dashboard.js', import.meta.url), 'utf8')
82
+ const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
83
+ // 段标题 + 五字段(完成/驳回/Token/异常事件/质量趋势)+ 无数据优雅空态
84
+ assert.ok(dash.indexOf('## 批次摘要(近 24 小时)') >= 0, '报告缺批次摘要段标题')
85
+ assert.ok(dash.indexOf('- 完成:') >= 0, '缺「完成」字段')
86
+ assert.ok(dash.indexOf('- 驳回:') >= 0, '缺「驳回」字段')
87
+ assert.ok(dash.indexOf('- Token:约 ') >= 0, '缺「Token」字段')
88
+ assert.ok(dash.indexOf('- 异常事件:超时 ') >= 0, '缺「异常事件」字段')
89
+ assert.ok(dash.indexOf('· 幽灵回收 ') >= 0, '缺「幽灵回收」字段')
90
+ assert.ok(dash.indexOf('- 质量趋势:') >= 0, '缺「质量趋势」字段')
91
+ assert.ok(dash.indexOf('近 24 小时无活动记录(无完成 / 驳回 / 消耗 / 异常事件)') >= 0, '缺无数据优雅空态')
92
+ assert.ok(dash.indexOf('function batchDigest()') >= 0, '缺 batchDigest 数据源')
93
+ // 纯聚合现有字段(不新建 host 状态、不重拉):run 级 token 现算 + healthHints 读幽灵回收
94
+ assert.match(dash, /r\.usage && typeof r\.usage === 'object'/)
95
+ assert.ok(dash.indexOf('本轮回收') >= 0, '缺幽灵回收 healthHints 读取')
96
+ // 产物重组装:关键标记逐一出现在 lib/client.js
97
+ for (const m of ['## 批次摘要(近 24 小时)', '近 24 小时无活动记录', 'function batchDigest()']) {
98
+ assert.ok(built.indexOf(m) >= 0, 'client.js 缺标记:' + m + '(需 npm run build-client 重组装)')
99
+ }
100
+ })
101
+
102
+ // ===== ④ 接线 + README 双份 =====
103
+ test('④ 接线:usage/rpc/index 挂 qualityChangeHints + rejectByDay;README 双份逐字一致 + 各补一句', () => {
104
+ const rpc = readFileSync(new URL('../lib/rpc.mjs', import.meta.url), 'utf8')
105
+ const usage = readFileSync(new URL('../lib/usage.mjs', import.meta.url), 'utf8')
106
+ const idx = readFileSync(new URL('../index.mjs', import.meta.url), 'utf8')
107
+ // usage.mjs:质量异动常量置顶 + 函数 + rejectByDay 数据源
108
+ assert.match(usage, /export var QUALITY_CHANGE_PP = 10/)
109
+ assert.match(usage, /export var QUALITY_MIN_SAMPLE = 5/)
110
+ assert.match(usage, /export var QUALITY_WINDOW_DAYS = 7/)
111
+ assert.match(usage, /export function qualityChangeHints\(sb, now\)/)
112
+ assert.match(usage, /rejectByDay: \{\}/)
113
+ assert.match(usage, /tr\.rejectByDay\[rcj\.mDay\]/)
114
+ // rpc:import + healthHints 拼 qualityChangeHints(scoreboard 就位后现算,在 modelPerfHint 之后)
115
+ assert.match(rpc, /modelPerfHint, qualityChangeHints \} from '\.\/usage\.mjs'/)
116
+ const iQch = rpc.indexOf('var __qch = qualityChangeHints(d.usageSummary.scoreboard)')
117
+ const iMph = rpc.indexOf('var __mph = modelPerfHint(d.usageSummary.scoreboard)')
118
+ assert.ok(iQch >= 0 && iMph >= 0 && iQch > iMph, 'qualityChangeHints 必须在 modelPerfHint 之后现算')
119
+ assert.match(rpc, /d\.healthHints = __rh\.hints\.concat\(computeHealthHints\(d\.tasks\)\)\.concat\(__qch\)\.concat\(__mph \? \[__mph\] : \[\]\)/)
120
+ // index 兼容 re-export
121
+ assert.match(idx, /qualityChangeHints, QUALITY_CHANGE_PP, QUALITY_MIN_SAMPLE, QUALITY_WINDOW_DAYS/)
122
+ // README 双份:逐字一致 + 各补一句(质量异动 / 批次摘要)
123
+ const r1 = readFileSync(new URL('../../../README.md', import.meta.url), 'utf8')
124
+ const r2 = readFileSync(new URL('../README.md', import.meta.url), 'utf8')
125
+ assert.equal(r1, r2, 'README 双份必须逐字一致(npm run sync-readme)')
126
+ assert.ok(r1.indexOf('质量异动') >= 0, 'README 缺「质量异动」说明')
127
+ assert.ok(r1.indexOf('批次摘要') >= 0, 'README 缺「批次摘要」说明')
128
+ })
@@ -192,11 +192,11 @@ test('卡5⑤b:接线(源码级)——rpc healthHints 拼 modelPerfHint /
192
192
  const dash = readFileSync(new URL('../lib/client/dashboard.js', import.meta.url), 'utf8')
193
193
  const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
194
194
  // host:modelPerfHint 从 usage.mjs import;scoreboard 就位后现算;拼在 computeHealthHints 结果尾部
195
- assert.match(rpc, /import \{ findRunLog, readLogBytes, readLogFrames, aggregateUsageSummary, readMainWindowUsage, buildScoreboard, modelPerfHint \} from '\.\/usage\.mjs'/)
195
+ assert.match(rpc, /import \{ findRunLog, readLogBytes, readLogFrames, aggregateUsageSummary, readMainWindowUsage, buildScoreboard, modelPerfHint, qualityChangeHints \} from '\.\/usage\.mjs'/)
196
196
  const iSb = rpc.indexOf('d.usageSummary.scoreboard = buildScoreboard(d.tasks, args && args.range')
197
197
  const iMph = rpc.indexOf('var __mph = modelPerfHint(d.usageSummary.scoreboard)')
198
198
  assert.ok(iSb >= 0 && iMph > iSb, 'modelPerfHint 必须在 scoreboard 挂载之后现算')
199
- assert.match(rpc, /d\.healthHints = __rh\.hints\.concat\(computeHealthHints\(d\.tasks\)\)\.concat\(__mph \? \[__mph\] : \[\]\)/)
199
+ assert.match(rpc, /d\.healthHints = __rh\.hints\.concat\(computeHealthHints\(d\.tasks\)\)\.concat\(__qch\)\.concat\(__mph \? \[__mph\] : \[\]\)/)
200
200
  // usage.mjs:聚类规则表 / 聚类函数 / hint 阈值常量导出
201
201
  assert.match(usage, /export var REJECTION_CLUSTER_RULES = \[/)
202
202
  assert.match(usage, /export function clusterRejections\(texts\)/)