dsh-agent-board 1.7.4 → 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.
- package/README.md +39 -14
- package/index.mjs +9 -1
- package/lib/client/board-list.js +37 -26
- package/lib/client/dashboard.js +407 -67
- package/lib/client/kernel.js +23 -10
- package/lib/client/task-detail.js +21 -2
- package/lib/client.js +488 -105
- package/lib/core.mjs +202 -8
- package/lib/dispatch.mjs +54 -7
- package/lib/health.mjs +68 -1
- package/lib/rpc.mjs +86 -16
- package/lib/usage.mjs +608 -0
- package/package.json +2 -2
- package/test/core.test.mjs +648 -70
- package/test/headless-smoke.test.mjs +209 -0
- package/test/helpers/mock-ctx.mjs +327 -0
- package/test/integration.test.mjs +543 -0
- package/test/quality-alert-digest.test.mjs +128 -0
- package/test/runtime-health.test.mjs +158 -0
- package/test/scoreboard-client.test.mjs +106 -0
- package/test/scoreboard-trends-client.test.mjs +104 -0
- package/test/scoreboard.test.mjs +271 -0
- package/test/scorecard-clusters.test.mjs +225 -0
- package/test/scorecard-data.test.mjs +214 -0
- package/test/usage-mainwindow.test.mjs +7 -5
- package/test/user-guide-client.test.mjs +79 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// dsh-agent-board — 记分卡卡2 host 聚合底座单测(test/scoreboard.test.mjs,task-muxhtgh9)
|
|
2
|
+
// 覆盖(对应任务断言①~⑥ + 接线):
|
|
3
|
+
// ① 七指标各一条数值正确性——模型×角色×规模段桶:有效token(均值+总额)/耗时(中位+P90)/驳回率/
|
|
4
|
+
// 一次通过率/超时率/续跑率/缓存命中率
|
|
5
|
+
// ② 样本不足标记——桶内 runs<5 标 insufficient:true;恰好 5 条不标
|
|
6
|
+
// ③ 趋势 rollup byDay 正确——一次通过率 byDay / 卡时长四桶 / 超时率走势 byDay / 续跑成功率
|
|
7
|
+
// ④ 增量缓存命中零重算——(taskCount, 最新落定时刻) 不变时改字段值结果逐字不变;新 run 落地即重算
|
|
8
|
+
// ⑤ 范围裁剪——与 usageSummary 同一 range 口径(run 日落点两端闭区间);空范围=无范围(parity)
|
|
9
|
+
// ⑥ 老数据缺字段退化不炸——无 model/endedAt/usage/runs/messages 各形态 + fs 全炸纯函数照跑
|
|
10
|
+
// ⑦ host 接线(源码级)——get-tasks 挂载 scoreboard / 缓存并列在 state / index 兼容 re-export
|
|
11
|
+
import { test } from 'node:test'
|
|
12
|
+
import assert from 'node:assert/strict'
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import { readFileSync } from 'node:fs'
|
|
15
|
+
import { buildScoreboard, SCOREBOARD_MIN_SAMPLE } from '../index.mjs'
|
|
16
|
+
import { localDayKey } from '../lib/usage.mjs'
|
|
17
|
+
|
|
18
|
+
// 本地构造时刻 → ISO 串(round-trip 经 dayKeyOf 仍落原本地日,与机器时区无关)
|
|
19
|
+
function isoOf(y, m, d, h, mi) { return new Date(y, m - 1, d, h, mi || 0, 0).toISOString() }
|
|
20
|
+
function dayOf(y, m, d) { return localDayKey(new Date(y, m - 1, d, 12)) }
|
|
21
|
+
function U(inp, outp, cr, cw) { return { input: inp, output: outp, cacheRead: cr, cacheWrite: cw, total: inp + outp + cr + cw } }
|
|
22
|
+
|
|
23
|
+
const D0 = dayOf(2026, 10, 5) // 老卡/跨天日
|
|
24
|
+
const D1 = dayOf(2026, 10, 6) // 主场景日
|
|
25
|
+
|
|
26
|
+
// 标准夹具(每次调用全新对象——测试间互不污染):
|
|
27
|
+
// tA:resolved 一次通过(rejectCount 缺省);runs = w1(worker m/a, d1 10min) + v1(verifier m/v, 5min)
|
|
28
|
+
// tB:resolved 被驳过一次(rejectCount 1,驳回消息 d1 11:45 归因 w2);runs = w2(timeout 30min) + w3(resume completed 5min)
|
|
29
|
+
// tC:老卡(direct 档直落 resolvedAt;run 无 model/endedAt/usage;usage 只有 total → 规模兜底 small)
|
|
30
|
+
// tD:pending 无 runs 无 usage(零贡献不炸)
|
|
31
|
+
function mkTasks() {
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
id: 'tA', title: 'A', status: 'resolved', createdAt: isoOf(2026, 10, 6, 9), verifiedAt: isoOf(2026, 10, 6, 13),
|
|
35
|
+
usage: { input: 100, output: 50, cacheRead: 1000, cacheWrite: 10, total: 1160 }, // 有效 160 → small
|
|
36
|
+
runs: [
|
|
37
|
+
{ role: 'worker', id: 'w1', at: isoOf(2026, 10, 6, 10), endedAt: isoOf(2026, 10, 6, 10, 10), model: 'm/a', outcome: 'completed', usage: U(100, 50, 1000, 10) },
|
|
38
|
+
{ role: 'verifier', id: 'v1', at: isoOf(2026, 10, 6, 10, 20), endedAt: isoOf(2026, 10, 6, 10, 25), model: 'm/v', outcome: 'completed', usage: U(50, 20, 500, 5) },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'tB', title: 'B', status: 'resolved', createdAt: isoOf(2026, 10, 5, 22), verifiedAt: isoOf(2026, 10, 6, 14),
|
|
43
|
+
rejectCount: 1,
|
|
44
|
+
messages: [{ kind: 'rejection', text: '验收驳回 · 自测没过', at: isoOf(2026, 10, 6, 11, 45), by: 'v2' }],
|
|
45
|
+
usage: { input: 300, output: 150, cacheRead: 3000, cacheWrite: 30, total: 3480 }, // 有效 480 → small
|
|
46
|
+
runs: [
|
|
47
|
+
{ role: 'worker', id: 'w2', at: isoOf(2026, 10, 6, 11), endedAt: isoOf(2026, 10, 6, 11, 30), model: 'm/a', outcome: 'timeout/error', usage: U(200, 100, 3000, 20) },
|
|
48
|
+
{ role: 'worker', id: 'w3', at: isoOf(2026, 10, 6, 12), endedAt: isoOf(2026, 10, 6, 12, 5), model: 'm/a', outcome: 'completed', resume: true, usage: U(100, 50, 0, 10) },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'tC', title: 'C', status: 'resolved', createdAt: isoOf(2026, 10, 5, 17, 50), resolvedAt: isoOf(2026, 10, 5, 18),
|
|
53
|
+
usage: { total: 500, updatedAt: isoOf(2026, 10, 5, 18) }, // 老形态只有 total → 兜底 small
|
|
54
|
+
runs: [{ role: 'worker', id: 'old-1', at: isoOf(2026, 10, 5, 9), outcome: 'completed' }], // 无 model/endedAt/usage
|
|
55
|
+
},
|
|
56
|
+
{ id: 'tD', title: 'D', status: 'pending' },
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
function bucketOf(sb, model, role, size) {
|
|
60
|
+
const b = sb.buckets.filter(function (x) { return x.model === model && x.role === role && x.size === size })
|
|
61
|
+
return b.length ? b[0] : null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ===== ① 七指标数值正确性 =====
|
|
65
|
+
test('卡2①:七指标——m/a×worker×small 桶逐条数值核对(有效token/耗时/驳回率/一次通过率/超时率/续跑率/缓存命中率)', () => {
|
|
66
|
+
const sb = buildScoreboard(mkTasks())
|
|
67
|
+
const b = bucketOf(sb, 'm/a', 'worker', 'small')
|
|
68
|
+
assert.ok(b, 'm/a|worker|small 桶必须存在')
|
|
69
|
+
assert.equal(b.runs, 3) // w1 + w2 + w3(老 run 无模型不进桶)
|
|
70
|
+
// ① 有效 token:总额 160+320+160=640,均值 round(640/3)=213
|
|
71
|
+
assert.equal(b.effSum, 640)
|
|
72
|
+
assert.equal(b.effAvg, 213)
|
|
73
|
+
// ② 耗时:durs [600000, 1800000, 300000] → 中位 600000(10min),P90 最近秩 = 1800000(30min)
|
|
74
|
+
assert.equal(b.durMedianMs, 600000)
|
|
75
|
+
assert.equal(b.durP90Ms, 1800000)
|
|
76
|
+
// ③ 驳回率:tB 驳回消息 11:45 归因到 w2(11:00 ≤ 11:45 < w3 12:00)→ 1/3
|
|
77
|
+
assert.equal(b.rejected, 1)
|
|
78
|
+
assert.equal(b.rejectRate, 1 / 3)
|
|
79
|
+
// ④ 一次通过率:桶内 resolved = tA + tB;tA rejectCount 缺省=0 → firstPass 1/2
|
|
80
|
+
assert.equal(b.resolved, 2)
|
|
81
|
+
assert.equal(b.firstPass, 1)
|
|
82
|
+
assert.equal(b.firstPassRate, 0.5)
|
|
83
|
+
// ⑤ 超时率:w2 outcome='timeout/error' → 1/3
|
|
84
|
+
assert.equal(b.timeouts, 1)
|
|
85
|
+
assert.equal(b.timeoutRate, 1 / 3)
|
|
86
|
+
// ⑥ 续跑率:w3 resume:true → 1/3
|
|
87
|
+
assert.equal(b.resumes, 1)
|
|
88
|
+
assert.equal(b.resumeRate, 1 / 3)
|
|
89
|
+
// ⑦ 缓存命中率:cr 1000+3000+0=4000 / (inp 400 + cr 4000) = 4000/4400
|
|
90
|
+
assert.ok(Math.abs(b.cacheHitRate - 4000 / 4400) < 1e-12)
|
|
91
|
+
assert.equal(b.insufficient, true) // 3 < 5 → 样本护栏
|
|
92
|
+
// verifier 桶同轮核对(角色分桶 + 一次通过率按桶归属:tA 在 m/v 桶也是 firstPass)
|
|
93
|
+
const bv = bucketOf(sb, 'm/v', 'verifier', 'small')
|
|
94
|
+
assert.ok(bv, 'm/v|verifier|small 桶必须存在')
|
|
95
|
+
assert.equal(bv.runs, 1)
|
|
96
|
+
assert.equal(bv.effSum, 75)
|
|
97
|
+
assert.equal(bv.durMedianMs, 300000)
|
|
98
|
+
assert.equal(bv.durP90Ms, 300000) // 单样本 P90=自身
|
|
99
|
+
assert.equal(bv.rejected, 0)
|
|
100
|
+
assert.equal(bv.firstPassRate, 1)
|
|
101
|
+
assert.equal(bv.timeoutRate, 0)
|
|
102
|
+
assert.equal(bv.resumeRate, 0)
|
|
103
|
+
assert.ok(Math.abs(bv.cacheHitRate - 500 / 550) < 1e-12)
|
|
104
|
+
assert.equal(bv.insufficient, true)
|
|
105
|
+
// meta 诊断:老 run 缺模型如实计数,不硬塞桶
|
|
106
|
+
assert.equal(sb.meta.tasks, 4)
|
|
107
|
+
assert.equal(sb.meta.runsSettled, 5)
|
|
108
|
+
assert.equal(sb.meta.bucketed, 4)
|
|
109
|
+
assert.equal(sb.meta.noModel, 1)
|
|
110
|
+
assert.equal(sb.meta.noSize, 0)
|
|
111
|
+
assert.equal(sb.meta.roleOther, 0)
|
|
112
|
+
assert.equal(sb.meta.rejUnattributed, 0)
|
|
113
|
+
// 排序稳定:有效总额降序(m/a 640 在 m/v 75 前)
|
|
114
|
+
assert.equal(sb.buckets[0].model, 'm/a')
|
|
115
|
+
assert.equal(sb.buckets[1].model, 'm/v')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
// ===== ② 样本不足标记边界 =====
|
|
119
|
+
test('卡2②:样本护栏——桶内恰好 5 条不标 insufficient,4 条标', () => {
|
|
120
|
+
assert.equal(SCOREBOARD_MIN_SAMPLE, 5)
|
|
121
|
+
function mkN(n) {
|
|
122
|
+
const runs = []
|
|
123
|
+
for (let i = 0; i < n; i++) {
|
|
124
|
+
runs.push({ role: 'worker', id: 'r' + i, at: isoOf(2026, 10, 6, 10, i), endedAt: isoOf(2026, 10, 6, 10, i + 1), model: 'm/b', outcome: 'completed', usage: U(10, 10, 0, 0) })
|
|
125
|
+
}
|
|
126
|
+
return [{ id: 'tE', status: 'resolved', createdAt: isoOf(2026, 10, 6, 9), verifiedAt: isoOf(2026, 10, 6, 11), usage: { input: 10 * n, output: 10 * n, cacheWrite: 0, total: 20 * n }, runs: runs }]
|
|
127
|
+
}
|
|
128
|
+
const b5 = bucketOf(buildScoreboard(mkN(5)), 'm/b', 'worker', 'small')
|
|
129
|
+
assert.equal(b5.runs, 5)
|
|
130
|
+
assert.equal(b5.insufficient, false)
|
|
131
|
+
const b4 = bucketOf(buildScoreboard(mkN(4)), 'm/b', 'worker', 'small')
|
|
132
|
+
assert.equal(b4.runs, 4)
|
|
133
|
+
assert.equal(b4.insufficient, true)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// ===== ③ 趋势 rollup byDay =====
|
|
137
|
+
test('卡2③:全局趋势——一次通过率 byDay / 卡时长四桶 / 超时率走势 byDay / 续跑成功率', () => {
|
|
138
|
+
const sb = buildScoreboard(mkTasks())
|
|
139
|
+
const tr = sb.trends
|
|
140
|
+
// 一次通过率 byDay(resolved 任务按落定日;rejectCount=0 计 firstPass):
|
|
141
|
+
// D0: tC(resolvedAt 直落,rejectCount 缺省)→ 1/1;D1: tA(过) + tB(驳过) → 1/2
|
|
142
|
+
assert.deepEqual(tr.firstPassByDay[D0], { resolved: 1, firstPass: 1 })
|
|
143
|
+
assert.deepEqual(tr.firstPassByDay[D1], { resolved: 2, firstPass: 1 })
|
|
144
|
+
// 卡时长分布(createdAt→落定):tA 4h 与 tB 16h → gt60m;tC 10min 整 → m10to30(含端归中同哲学)
|
|
145
|
+
assert.deepEqual(tr.durationBuckets, { lt10m: 0, m10to30: 1, m30to60: 0, gt60m: 2 })
|
|
146
|
+
// 超时率走势 byDay(run.at 日落点,全角色全模型):D1 四 run 1 超时;D0 老 run 1 条 0 超时
|
|
147
|
+
assert.deepEqual(tr.timeoutByDay[D1], { runs: 4, timeout: 1 })
|
|
148
|
+
assert.deepEqual(tr.timeoutByDay[D0], { runs: 1, timeout: 0 })
|
|
149
|
+
// 续跑成功率:w3 resume 且 completed → 1/1
|
|
150
|
+
assert.deepEqual(tr.resume, { runs: 1, completed: 1, rate: 1 })
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// ===== ④ 增量缓存命中零重算 =====
|
|
154
|
+
test('卡2④:增量缓存——(taskCount, 最新落定时刻) 不变命中即零重算;新 run 落地戳变即重算', () => {
|
|
155
|
+
const slot = {}
|
|
156
|
+
const tasks = mkTasks()
|
|
157
|
+
const r1 = buildScoreboard(tasks, null, slot)
|
|
158
|
+
assert.ok(slot.recs, '首轮后缓存槽应持有归一化记录')
|
|
159
|
+
// 命中证明:改掉 w1 的 model 与 tA 的 title(不改任何时间戳、不加任务)——
|
|
160
|
+
// 若提取层重算,桶键会变成 m/changed;结果逐字不变 = 零重算的硬证据
|
|
161
|
+
tasks[0].title = 'A(改名)'
|
|
162
|
+
tasks[0].runs[0].model = 'm/changed'
|
|
163
|
+
const r2 = buildScoreboard(tasks, null, slot)
|
|
164
|
+
assert.deepEqual(r2, r1)
|
|
165
|
+
assert.equal(bucketOf(r2, 'm/a', 'worker', 'small').runs, 3)
|
|
166
|
+
assert.equal(slot.recs.runRecs[0].model, 'm/a') // 缓存记录保持旧值(命中未重扫)
|
|
167
|
+
// 范围请求同样吃缓存(裁剪在装配层现算,不触发重提取)
|
|
168
|
+
const r2r = buildScoreboard(tasks, { from: D1, to: D1 }, slot)
|
|
169
|
+
assert.equal(bucketOf(r2r, 'm/a', 'worker', 'small').runs, 3)
|
|
170
|
+
// 新 run 落地(时间戳前进)→ 戳变 → 重算反映新数据(w1 此时已是 m/changed → 也如实分桶)
|
|
171
|
+
const slot2 = {}
|
|
172
|
+
const tasks2 = mkTasks()
|
|
173
|
+
const r3 = buildScoreboard(tasks2, null, slot2)
|
|
174
|
+
tasks2[0].runs.push({ role: 'worker', id: 'w4', at: isoOf(2026, 10, 6, 15), endedAt: isoOf(2026, 10, 6, 15, 10), model: 'm/a', outcome: 'completed', usage: U(10, 10, 0, 0) })
|
|
175
|
+
const r4 = buildScoreboard(tasks2, null, slot2)
|
|
176
|
+
const b4 = bucketOf(r4, 'm/a', 'worker', 'small')
|
|
177
|
+
assert.equal(b4.runs, 4)
|
|
178
|
+
assert.equal(b4.effSum, 660)
|
|
179
|
+
assert.equal(b4.effAvg, 165)
|
|
180
|
+
assert.ok(!deepEq(r4, r3), '时间戳前进后必须重算,不得复用旧结果')
|
|
181
|
+
// 无 cacheStore(undefined)兜底:每次全量提取,不炸
|
|
182
|
+
assert.equal(bucketOf(buildScoreboard(mkTasks()), 'm/a', 'worker', 'small').runs, 3)
|
|
183
|
+
})
|
|
184
|
+
function deepEq(a, b) { try { assert.deepEqual(a, b); return true } catch (_) { return false } }
|
|
185
|
+
|
|
186
|
+
// ===== ⑤ 范围裁剪 =====
|
|
187
|
+
test('卡2⑤:范围裁剪——run 日落点两端闭区间;驳回随被裁 run 一起裁;空范围=无范围(parity)', () => {
|
|
188
|
+
const slot = {}
|
|
189
|
+
const tasks = mkTasks()
|
|
190
|
+
// 只留 D1:桶不变(w1/v1/w2/w3 全在 D1);老 run(D0)被裁 → bucketed 4→4、noModel 0
|
|
191
|
+
const r1 = buildScoreboard(tasks, { from: D1, to: D1 }, slot)
|
|
192
|
+
assert.equal(bucketOf(r1, 'm/a', 'worker', 'small').runs, 3)
|
|
193
|
+
assert.equal(bucketOf(r1, 'm/a', 'worker', 'small').rejected, 1) // 驳回的 rDay=D1 在范围内
|
|
194
|
+
assert.equal(r1.meta.noModel, 0) // D0 老 run 被裁后不再计入诊断
|
|
195
|
+
assert.deepEqual(r1.trends.firstPassByDay, { [D1]: { resolved: 2, firstPass: 1 } }) // tC(D0 落定)被裁
|
|
196
|
+
assert.deepEqual(r1.trends.durationBuckets, { lt10m: 0, m10to30: 0, m30to60: 0, gt60m: 2 })
|
|
197
|
+
assert.deepEqual(r1.trends.timeoutByDay, { [D1]: { runs: 4, timeout: 1 } })
|
|
198
|
+
assert.deepEqual(r1.trends.resume, { runs: 1, completed: 1, rate: 1 })
|
|
199
|
+
// 只留 D0:m/a 桶整条消失(桶内 run 全在 D1);老 run 无模型 → buckets 空
|
|
200
|
+
const r0 = buildScoreboard(tasks, { from: D0, to: D0 }, slot)
|
|
201
|
+
assert.equal(r0.buckets.length, 0)
|
|
202
|
+
assert.deepEqual(r0.trends.firstPassByDay, { [D0]: { resolved: 1, firstPass: 1 } })
|
|
203
|
+
assert.deepEqual(r0.trends.durationBuckets, { lt10m: 0, m10to30: 1, m30to60: 0, gt60m: 0 })
|
|
204
|
+
assert.deepEqual(r0.trends.timeoutByDay, { [D0]: { runs: 1, timeout: 0 } })
|
|
205
|
+
assert.deepEqual(r0.trends.resume, { runs: 0, completed: 0, rate: null }) // w3(D1)被裁
|
|
206
|
+
// 空范围与不传等价(parity,与 aggregateUsageSummary 同一约定)
|
|
207
|
+
const all = buildScoreboard(tasks, null, slot)
|
|
208
|
+
assert.deepEqual(buildScoreboard(tasks, { from: '', to: '' }, slot), all)
|
|
209
|
+
// 缓存里存的是未裁剪归一化记录:范围请求之后再读全量仍正确(裁剪不毁缓存)
|
|
210
|
+
assert.equal(bucketOf(buildScoreboard(tasks, null, slot), 'm/a', 'worker', 'small').runs, 3)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// ===== ⑥ 老数据缺字段退化不炸 + 纯函数零 IO =====
|
|
214
|
+
test('卡2⑥:老数据退化——无 outcome/无 at/无 runs/无 messages/脏条目 全形态不炸,如实计数不伪造', () => {
|
|
215
|
+
const junk = [
|
|
216
|
+
null, 'garbage', // 脏任务条目
|
|
217
|
+
{ id: 'j1', runs: [{ role: 'worker', id: 'r-fly', at: isoOf(2026, 10, 6, 8), outcome: 'running' }] }, // 在飞:不算缺字段,不进指标
|
|
218
|
+
{ id: 'j2', runs: [{ role: 'worker', id: 'r-noat', outcome: 'completed', model: 'm/c' }] }, // 无 at:进桶(无范围)但不进 byDay
|
|
219
|
+
{ id: 'j3', messages: [{ kind: 'rejection', text: 'x', at: isoOf(2026, 10, 6, 9) }] }, // 有驳回无 runs → 归因 null
|
|
220
|
+
{ id: 'j4', runs: 'not-an-array', messages: { 0: 'x' } }, // 字段形态全错
|
|
221
|
+
{ id: 'j5', status: 'resolved' }, // resolved 但无落定时刻/createdAt → resolvedDay '' 卡时长 null
|
|
222
|
+
]
|
|
223
|
+
const sb = buildScoreboard(junk)
|
|
224
|
+
assert.equal(sb.meta.runsSettled, 1) // 只有 r-noat 已落定
|
|
225
|
+
assert.equal(sb.meta.rejUnattributed, 1) // j3 的驳回无 run 可归
|
|
226
|
+
const b = bucketOf(sb, 'm/c', 'worker', 'small') // j2 无 usage → 规模不可知?不对——无 usage 任务 size=null
|
|
227
|
+
assert.equal(b, null) // j2 任务无 usage → size null → 不进桶(noSize=1)
|
|
228
|
+
assert.equal(sb.meta.noSize, 1)
|
|
229
|
+
assert.deepEqual(sb.trends.timeoutByDay, {}) // 无 at → 无日落点 → 不进 byDay
|
|
230
|
+
assert.deepEqual(sb.trends.resume, { runs: 0, completed: 0, rate: null })
|
|
231
|
+
assert.deepEqual(sb.trends.firstPassByDay, {}) // j5 resolvedDay '' 不入 byDay
|
|
232
|
+
// 范围下同样不炸(无日落点的已落定 run 被裁,宁可漏不错)
|
|
233
|
+
const sr = buildScoreboard(junk, { from: D1, to: D1 })
|
|
234
|
+
assert.equal(sr.meta.runsSettled, 1)
|
|
235
|
+
assert.equal(sr.buckets.length, 0)
|
|
236
|
+
// 纯函数零 IO:fs 门面全部打爆后照跑(与卡1④同一纪律)
|
|
237
|
+
const orig = {}
|
|
238
|
+
for (const k of ['readFileSync', 'readdirSync', 'statSync', 'openSync', 'readSync', 'existsSync']) {
|
|
239
|
+
orig[k] = fs[k]
|
|
240
|
+
fs[k] = function () { throw new Error('IO 触碰:' + k) }
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const b2 = bucketOf(buildScoreboard(mkTasks()), 'm/a', 'worker', 'small')
|
|
244
|
+
assert.equal(b2.runs, 3)
|
|
245
|
+
assert.equal(b2.effSum, 640)
|
|
246
|
+
} finally {
|
|
247
|
+
for (const k2 of Object.keys(orig)) fs[k2] = orig[k2]
|
|
248
|
+
}
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
// ===== ⑦ host 接线(源码级断言)=====
|
|
252
|
+
test('卡2⑦:接线——get-tasks 挂载 scoreboard / 缓存并列在 state / index 兼容 re-export / 纯 host 不碰 client', () => {
|
|
253
|
+
const rpc = readFileSync(new URL('../lib/rpc.mjs', import.meta.url), 'utf8')
|
|
254
|
+
const usage = readFileSync(new URL('../lib/usage.mjs', import.meta.url), 'utf8')
|
|
255
|
+
const idx = readFileSync(new URL('../index.mjs', import.meta.url), 'utf8')
|
|
256
|
+
// get-tasks:scoreboard 挂在 usageSummary 上(聚合之后),带同一 range 口径 + 增量缓存槽
|
|
257
|
+
const iAgg = rpc.indexOf('d.usageSummary = aggregateUsageSummary(d.tasks, args && args.range)')
|
|
258
|
+
const iSb = rpc.indexOf('d.usageSummary.scoreboard = buildScoreboard(d.tasks, args && args.range')
|
|
259
|
+
assert.ok(iAgg >= 0 && iSb > iAgg, 'scoreboard 必须在 aggregateUsageSummary 之后挂载')
|
|
260
|
+
assert.match(rpc, /state\.scoreboardCache\[sid\] \|\| \(state\.scoreboardCache\[sid\] = \{\}\)/)
|
|
261
|
+
assert.match(rpc, /if \(!state\.scoreboardCache\) state\.scoreboardCache = \{\}/) // 测试桩就地补(与 mainWindowUsageCache 同例)
|
|
262
|
+
// 缓存本体在共享 state(与 mainWindow 尾读缓存并列)
|
|
263
|
+
assert.match(idx, /scoreboardCache: \{\}/)
|
|
264
|
+
// 聚合本体在 usage.mjs;样本护栏常量导出
|
|
265
|
+
assert.match(usage, /export function buildScoreboard\(tasks, range, cacheStore\)/)
|
|
266
|
+
assert.match(usage, /export var SCOREBOARD_MIN_SAMPLE = 5/)
|
|
267
|
+
// 兼容 re-export:单测与卡3 客户端对接从 index.mjs 直取
|
|
268
|
+
assert.match(idx, /buildScoreboard, SCOREBOARD_MIN_SAMPLE/)
|
|
269
|
+
// 范围裁剪复用同一 dayInRange/rangeOn(与 usageSummary 同一 range 口径的硬保证)
|
|
270
|
+
assert.match(usage, /dayInRange\(q\.day, range\)/)
|
|
271
|
+
})
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// dsh-agent-board — 记分卡卡5 驳回聚类 + 约定建议 + 按表现荐模型 hint 单测(test/scorecard-clusters.test.mjs,task-muxhu1zv)
|
|
2
|
+
// 覆盖(对应任务断言①~④ + 接线):
|
|
3
|
+
// ① 聚类规则法正确性——5 类驳回文本各 3 条 → Top3 正确(并列按规则表顺序)+ 占比 20%;
|
|
4
|
+
// 区分度 case(5/4/3/2/1)Top3 顺序与 pct;未匹配文本进 other 兜底桶
|
|
5
|
+
// ② 建议文本结构化——suggestion 形如「驳回 Top1『…』占 N%——建议…」逐字核对
|
|
6
|
+
// ③ 荐模型 hint 阈值边界——runs 9/10、通过率 89%/90%、effGap 恰好 30% 不亮 / 31% 亮、
|
|
7
|
+
// 单模型无对比不亮、verifier/large 桶不计入
|
|
8
|
+
// ④ 无驳回/无数据不炸——空/脏输入全形态返回空结果或 null,绝不抛错
|
|
9
|
+
// ⑤ 接线(源码级 + 端到端)——buildScoreboard 挂 rejectionClusters(范围按驳回消息日落点裁剪)/
|
|
10
|
+
// rpc healthHints 拼 modelPerfHint / index re-export / client 组件与产物 / README 双份
|
|
11
|
+
import { test } from 'node:test'
|
|
12
|
+
import assert from 'node:assert/strict'
|
|
13
|
+
import { readFileSync } from 'node:fs'
|
|
14
|
+
import { buildScoreboard, clusterRejections, REJECTION_CLUSTER_RULES, modelPerfHint, MODEL_HINT_MIN_RUNS, MODEL_HINT_MIN_PASS, MODEL_HINT_EFF_GAP } from '../index.mjs'
|
|
15
|
+
import { localDayKey } from '../lib/usage.mjs'
|
|
16
|
+
|
|
17
|
+
function isoOf(y, m, d, h, mi) { return new Date(y, m - 1, d, h, mi || 0, 0).toISOString() }
|
|
18
|
+
function dayOf(y, m, d) { return localDayKey(new Date(y, m - 1, d, 12)) }
|
|
19
|
+
const D0 = dayOf(2026, 10, 5)
|
|
20
|
+
const D1 = dayOf(2026, 10, 6)
|
|
21
|
+
|
|
22
|
+
// 五类驳回文本(与规则表类目一一对应;形态仿 rejectionText 产物「验收驳回 · <summary>」)
|
|
23
|
+
const REJ_TEXTS = {
|
|
24
|
+
'acceptance-skipped': '验收驳回 · 验收脚本未实跑——上报前必须逐字粘贴真实输出',
|
|
25
|
+
'readme-stale': '验收驳回 · README 未同步(行为变了文档没跟)',
|
|
26
|
+
'scope-creep': '验收驳回 · 范围越界:改了 touches 声明外的文件',
|
|
27
|
+
'assertion-missing': '验收驳回 · 断言①缺失单测锁定',
|
|
28
|
+
'artifact-stale': '验收驳回 · 产物未重组装(lib/client.js 还是旧的)',
|
|
29
|
+
}
|
|
30
|
+
// 构造 texts:{ 类目id: 条数 }(按对象键序铺开)
|
|
31
|
+
function mkTexts(plan) {
|
|
32
|
+
const out = []
|
|
33
|
+
for (const id of Object.keys(plan)) for (let i = 0; i < plan[id]; i++) out.push(REJ_TEXTS[id] + ' #' + i)
|
|
34
|
+
return out
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ===== ① 聚类规则法正确性 =====
|
|
38
|
+
test('卡5①a:5 类驳回各 3 条 → Top3 = 规则表前三类(并列按表序),占比各 20%,其余进 restCount', () => {
|
|
39
|
+
const r = clusterRejections(mkTexts({ 'acceptance-skipped': 3, 'readme-stale': 3, 'scope-creep': 3, 'assertion-missing': 3, 'artifact-stale': 3 }))
|
|
40
|
+
assert.equal(r.total, 15)
|
|
41
|
+
assert.equal(r.top.length, 3)
|
|
42
|
+
// 五类并列 3 条:Top3 取规则表顺序前三(acceptance → readme → scope)
|
|
43
|
+
assert.deepEqual(r.top.map(function (c) { return c.id }), ['acceptance-skipped', 'readme-stale', 'scope-creep'])
|
|
44
|
+
for (const c of r.top) {
|
|
45
|
+
assert.equal(c.count, 3)
|
|
46
|
+
assert.equal(c.pct, 20) // 3/15 = 20%
|
|
47
|
+
assert.equal(c.samples.length, 3) // 代表原文 ≤3 条
|
|
48
|
+
}
|
|
49
|
+
assert.equal(r.restCount, 2) // assertion/artifact 两类未进 Top3
|
|
50
|
+
assert.equal(r.otherCount, 0)
|
|
51
|
+
})
|
|
52
|
+
test('卡5①b:区分度 5/4/3/2/1 → Top3 按 count 降序,pct 逐条核对;未匹配文本进 other 桶', () => {
|
|
53
|
+
const texts = mkTexts({ 'acceptance-skipped': 5, 'readme-stale': 4, 'scope-creep': 3, 'assertion-missing': 2, 'artifact-stale': 1 })
|
|
54
|
+
texts.push('验收驳回 · 完全模板外的奇葩原因') // other
|
|
55
|
+
const r = clusterRejections(texts)
|
|
56
|
+
assert.equal(r.total, 16)
|
|
57
|
+
assert.deepEqual(r.top.map(function (c) { return c.id }), ['acceptance-skipped', 'readme-stale', 'scope-creep'])
|
|
58
|
+
assert.equal(r.top[0].pct, 31) // 5/16 = 31.25% → 31
|
|
59
|
+
assert.equal(r.top[1].pct, 25) // 4/16 = 25%
|
|
60
|
+
assert.equal(r.top[2].pct, 19) // 3/16 = 18.75% → 19
|
|
61
|
+
assert.equal(r.otherCount, 1)
|
|
62
|
+
assert.equal(r.restCount, 3) // assertion/artifact/other 未进 Top3
|
|
63
|
+
// 规则表常量形态:5 类种子类目 + 每条带 id/label/re/advice
|
|
64
|
+
assert.equal(REJECTION_CLUSTER_RULES.length, 5)
|
|
65
|
+
for (const rule of REJECTION_CLUSTER_RULES) {
|
|
66
|
+
assert.ok(rule.id && rule.label && rule.re instanceof RegExp && typeof rule.advice === 'string' && rule.advice.length > 0)
|
|
67
|
+
}
|
|
68
|
+
// 首命中归类:同时命中两类关键词的文本只归优先级更高者(占比分母守恒,Σcount = total)
|
|
69
|
+
const mixed = clusterRejections(['验收驳回 · 验收脚本没跑,README 也没同步'])
|
|
70
|
+
assert.equal(mixed.total, 1)
|
|
71
|
+
assert.equal(mixed.top[0].id, 'acceptance-skipped') // 「没跑」先命中(规则表第一位)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
// ===== ② 建议文本结构化 =====
|
|
75
|
+
test('卡5②:suggestion 结构化——「驳回 TopN『label』占 pct%——建议<类目 advice>」逐字核对', () => {
|
|
76
|
+
const r = clusterRejections(mkTexts({ 'acceptance-skipped': 2, 'readme-stale': 1 }))
|
|
77
|
+
assert.equal(r.top[0].suggestion, '驳回 Top1『验收脚本未实跑』占 67%——建议在派发约定/Worker prompt 补一条:上报前必须逐字粘贴验收脚本真实输出(未通过不得上报完成)')
|
|
78
|
+
assert.equal(r.top[1].suggestion, '驳回 Top2『README 未同步』占 33%——建议在派发约定补一条:行为/口径/界面变化必须同步 README 双份并逐字一致(npm run sync-readme)')
|
|
79
|
+
// other 桶也有通用建议文案(人工归纳入口)
|
|
80
|
+
const ro = clusterRejections(['验收驳回 · 模板外原因'])
|
|
81
|
+
assert.equal(ro.top[0].id, 'other')
|
|
82
|
+
assert.match(ro.top[0].suggestion, /^驳回 Top1『其他(未匹配规则)』占 100%——建议人工归纳该类驳回的共性/)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// ===== ③ 荐模型 hint 阈值边界 =====
|
|
86
|
+
// 构造 scoreboard bucket(modelPerfHint 只读 model/role/size/runs/resolved/firstPass/effSum/effCount)
|
|
87
|
+
function bk(model, role, size, runs, resolved, firstPass, effAvg) {
|
|
88
|
+
return { model: model, role: role, size: size, runs: runs, resolved: resolved, firstPass: firstPass, effSum: effAvg * runs, effCount: runs }
|
|
89
|
+
}
|
|
90
|
+
// 基准亮例:m/a 中小卡合并 runs=10、通过率 9/10=90%、effAvg 690;m/b runs=10、100%、effAvg 1000(差距 31%)
|
|
91
|
+
function sbBase() {
|
|
92
|
+
return { buckets: [
|
|
93
|
+
bk('m/a', 'worker', 'small', 6, 6, 5, 690),
|
|
94
|
+
bk('m/a', 'worker', 'medium', 4, 4, 4, 690),
|
|
95
|
+
bk('m/b', 'worker', 'small', 10, 10, 10, 1000),
|
|
96
|
+
] }
|
|
97
|
+
}
|
|
98
|
+
test('卡5③a:荐模型 hint 亮例——中小卡 worker 合并判定 + 文案逐项(模型/通过率/有效均值/差距)', () => {
|
|
99
|
+
assert.equal(MODEL_HINT_MIN_RUNS, 10)
|
|
100
|
+
assert.equal(MODEL_HINT_MIN_PASS, 0.9)
|
|
101
|
+
assert.equal(MODEL_HINT_EFF_GAP, 0.3)
|
|
102
|
+
const h = modelPerfHint(sbBase())
|
|
103
|
+
assert.ok(h, '满足全部阈值必须亮')
|
|
104
|
+
assert.equal(h.level, 'warn') // 黄条
|
|
105
|
+
assert.ok(h.text.indexOf('模型 m/a 在中小卡表现最优') === 0)
|
|
106
|
+
assert.ok(h.text.indexOf('通过率 90%') >= 0)
|
|
107
|
+
assert.ok(h.text.indexOf('有效均值 690') >= 0)
|
|
108
|
+
assert.ok(h.text.indexOf('较其他合格模型低 31%') >= 0) // (1000-690)/1000 = 31%
|
|
109
|
+
assert.ok(h.text.indexOf('建议设为默认 workerModel') >= 0)
|
|
110
|
+
})
|
|
111
|
+
test('卡5③b:阈值边界——runs 9 不亮 / 恰好 10 亮;通过率 89% 不亮 / 恰好 90% 亮;effGap 恰好 30% 不亮 / 31% 亮', () => {
|
|
112
|
+
// runs 9(中小卡合并后仍差 1)→ null
|
|
113
|
+
const s9 = sbBase(); s9.buckets[1] = bk('m/a', 'worker', 'medium', 3, 3, 3, 690) // 6+3=9
|
|
114
|
+
assert.equal(modelPerfHint(s9), null)
|
|
115
|
+
// runs 恰好 10 → 亮(sbBase 已是 10,③a 已证)
|
|
116
|
+
// 通过率 89%(resolved=100, firstPass=89)→ null
|
|
117
|
+
const s89 = { buckets: [bk('m/a', 'worker', 'small', 100, 100, 89, 690), bk('m/b', 'worker', 'small', 10, 10, 10, 1000)] }
|
|
118
|
+
assert.equal(modelPerfHint(s89), null)
|
|
119
|
+
// 通过率恰好 90%(firstPass=9, resolved=10)→ 亮(sbBase 即此形态)
|
|
120
|
+
// effGap 恰好 30%(700 vs 1000 → (1000-700)/1000 = 0.3,严格 > 不成立)→ null
|
|
121
|
+
const s30 = { buckets: [bk('m/a', 'worker', 'small', 10, 10, 9, 700), bk('m/b', 'worker', 'small', 10, 10, 10, 1000)] }
|
|
122
|
+
assert.equal(modelPerfHint(s30), null)
|
|
123
|
+
// effGap 31%(690 vs 1000)→ 亮
|
|
124
|
+
const s31 = { buckets: [bk('m/a', 'worker', 'small', 10, 10, 9, 690), bk('m/b', 'worker', 'small', 10, 10, 10, 1000)] }
|
|
125
|
+
assert.ok(modelPerfHint(s31))
|
|
126
|
+
})
|
|
127
|
+
test('卡5③c:对比与口径边界——单模型合格不亮(无对比对象);verifier/large 桶不计入;effAvg 不可知不判', () => {
|
|
128
|
+
// 只有一个合格模型(m/b runs 不足 10)→ null
|
|
129
|
+
const s1 = { buckets: [bk('m/a', 'worker', 'small', 10, 10, 10, 500), bk('m/b', 'worker', 'small', 5, 5, 5, 2000)] }
|
|
130
|
+
assert.equal(modelPerfHint(s1), null)
|
|
131
|
+
// m/a 的数据全在 verifier 桶 → worker 桶无候选 → null
|
|
132
|
+
const sv = { buckets: [bk('m/a', 'verifier', 'small', 20, 20, 20, 500), bk('m/b', 'worker', 'small', 10, 10, 10, 1000)] }
|
|
133
|
+
assert.equal(modelPerfHint(sv), null)
|
|
134
|
+
// large 桶不计入中小卡判定(m/a 只有 large 达标)→ null
|
|
135
|
+
const sl = { buckets: [bk('m/a', 'worker', 'large', 20, 20, 20, 500), bk('m/b', 'worker', 'small', 10, 10, 10, 1000)] }
|
|
136
|
+
assert.equal(modelPerfHint(sl), null)
|
|
137
|
+
// 通过率不可知(resolved=0)不判;有效均值不可知(effCount=0)不判
|
|
138
|
+
assert.equal(modelPerfHint({ buckets: [bk('m/a', 'worker', 'small', 10, 0, 0, 500), bk('m/b', 'worker', 'small', 10, 10, 10, 1000)] }), null)
|
|
139
|
+
const se = sbBase(); se.buckets[0].effCount = 0; se.buckets[1].effCount = 0 // m/a 均值不可知
|
|
140
|
+
assert.equal(modelPerfHint(se), null)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// ===== ④ 无驳回/无数据不炸 =====
|
|
144
|
+
test('卡5④:空/脏输入全形态不炸——空数组/非数组/空文本/null 字段', () => {
|
|
145
|
+
assert.deepEqual(clusterRejections([]), { total: 0, top: [], otherCount: 0, restCount: 0 })
|
|
146
|
+
assert.deepEqual(clusterRejections(null), { total: 0, top: [], otherCount: 0, restCount: 0 })
|
|
147
|
+
assert.deepEqual(clusterRejections('garbage'), { total: 0, top: [], otherCount: 0, restCount: 0 })
|
|
148
|
+
// 空文本/空白文本不算样本(不稀释占比)
|
|
149
|
+
assert.equal(clusterRejections(['', ' ', null, undefined]).total, 0)
|
|
150
|
+
// hint:null / 缺 buckets / 空 buckets → null
|
|
151
|
+
assert.equal(modelPerfHint(null), null)
|
|
152
|
+
assert.equal(modelPerfHint({}), null)
|
|
153
|
+
assert.equal(modelPerfHint({ buckets: [] }), null)
|
|
154
|
+
assert.equal(modelPerfHint({ buckets: 'garbage' }), null)
|
|
155
|
+
// 脏 bucket 条目(null/缺字段)不炸
|
|
156
|
+
assert.equal(modelPerfHint({ buckets: [null, { model: 'x' }, 'garbage'] }), null)
|
|
157
|
+
// 全空看板端到端:scoreboard 带 rejectionClusters 空形态
|
|
158
|
+
const sb = buildScoreboard([])
|
|
159
|
+
assert.deepEqual(sb.rejectionClusters, { total: 0, top: [], otherCount: 0, restCount: 0 })
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
// ===== ⑤ 接线:buildScoreboard 端到端(驳回消息 → rejectionClusters)+ 范围裁剪 =====
|
|
163
|
+
test('卡5⑤a:buildScoreboard 挂 rejectionClusters——驳回文本随 rejRec 进聚类;范围按驳回消息自身日落点裁剪', () => {
|
|
164
|
+
const tasks = [
|
|
165
|
+
{
|
|
166
|
+
id: 'tR1', title: 'R1', status: 'resolved', createdAt: isoOf(2026, 10, 6, 9), verifiedAt: isoOf(2026, 10, 6, 15),
|
|
167
|
+
rejectCount: 2,
|
|
168
|
+
messages: [
|
|
169
|
+
{ kind: 'rejection', text: '验收驳回 · 验收脚本未实跑', at: isoOf(2026, 10, 6, 11), by: 'v1' },
|
|
170
|
+
{ kind: 'rejection', text: '验收驳回 · README 未同步', at: isoOf(2026, 10, 5, 18), by: 'v2' }, // D0 的驳回
|
|
171
|
+
],
|
|
172
|
+
usage: { input: 100, output: 50, cacheWrite: 10, total: 1160 },
|
|
173
|
+
runs: [{ role: 'worker', id: 'w1', at: isoOf(2026, 10, 6, 10), endedAt: isoOf(2026, 10, 6, 10, 10), model: 'm/a', outcome: 'completed', usage: { input: 100, output: 50, cacheRead: 1000, cacheWrite: 10, total: 1160 } }],
|
|
174
|
+
},
|
|
175
|
+
]
|
|
176
|
+
const sb = buildScoreboard(tasks)
|
|
177
|
+
assert.equal(sb.rejectionClusters.total, 2)
|
|
178
|
+
assert.equal(sb.rejectionClusters.top.length, 2)
|
|
179
|
+
assert.equal(sb.rejectionClusters.top[0].id, 'acceptance-skipped') // 并列 1 条按规则表序
|
|
180
|
+
assert.equal(sb.rejectionClusters.top[1].id, 'readme-stale')
|
|
181
|
+
// 范围只留 D1:D0 的 README 驳回被裁(按驳回消息自身日落点,与 run 归因独立)
|
|
182
|
+
const sr = buildScoreboard(tasks, { from: D1, to: D1 })
|
|
183
|
+
assert.equal(sr.rejectionClusters.total, 1)
|
|
184
|
+
assert.equal(sr.rejectionClusters.top[0].id, 'acceptance-skipped')
|
|
185
|
+
// 无驳回任务的看板:空形态不炸
|
|
186
|
+
assert.equal(buildScoreboard([{ id: 'x', status: 'pending' }]).rejectionClusters.total, 0)
|
|
187
|
+
})
|
|
188
|
+
test('卡5⑤b:接线(源码级)——rpc healthHints 拼 modelPerfHint / index re-export / client 组件与产物 / README 双份', () => {
|
|
189
|
+
const rpc = readFileSync(new URL('../lib/rpc.mjs', import.meta.url), 'utf8')
|
|
190
|
+
const usage = readFileSync(new URL('../lib/usage.mjs', import.meta.url), 'utf8')
|
|
191
|
+
const idx = readFileSync(new URL('../index.mjs', import.meta.url), 'utf8')
|
|
192
|
+
const dash = readFileSync(new URL('../lib/client/dashboard.js', import.meta.url), 'utf8')
|
|
193
|
+
const built = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
194
|
+
// host:modelPerfHint 从 usage.mjs import;scoreboard 就位后现算;拼在 computeHealthHints 结果尾部
|
|
195
|
+
assert.match(rpc, /import \{ findRunLog, readLogBytes, readLogFrames, aggregateUsageSummary, readMainWindowUsage, buildScoreboard, modelPerfHint, qualityChangeHints \} from '\.\/usage\.mjs'/)
|
|
196
|
+
const iSb = rpc.indexOf('d.usageSummary.scoreboard = buildScoreboard(d.tasks, args && args.range')
|
|
197
|
+
const iMph = rpc.indexOf('var __mph = modelPerfHint(d.usageSummary.scoreboard)')
|
|
198
|
+
assert.ok(iSb >= 0 && iMph > iSb, 'modelPerfHint 必须在 scoreboard 挂载之后现算')
|
|
199
|
+
assert.match(rpc, /d\.healthHints = __rh\.hints\.concat\(computeHealthHints\(d\.tasks\)\)\.concat\(__qch\)\.concat\(__mph \? \[__mph\] : \[\]\)/)
|
|
200
|
+
// usage.mjs:聚类规则表 / 聚类函数 / hint 阈值常量导出
|
|
201
|
+
assert.match(usage, /export var REJECTION_CLUSTER_RULES = \[/)
|
|
202
|
+
assert.match(usage, /export function clusterRejections\(texts\)/)
|
|
203
|
+
assert.match(usage, /export function modelPerfHint\(sb\)/)
|
|
204
|
+
assert.match(usage, /export var MODEL_HINT_MIN_RUNS = 10/)
|
|
205
|
+
// index 兼容 re-export
|
|
206
|
+
assert.match(idx, /clusterRejections, REJECTION_CLUSTER_RULES, modelPerfHint, MODEL_HINT_MIN_RUNS, MODEL_HINT_MIN_PASS, MODEL_HINT_EFF_GAP/)
|
|
207
|
+
// client:组件 + 锚 id + 复制按钮 + 挂载在 QualityTrends 正下方
|
|
208
|
+
assert.match(dash, /function RejectionClusters\(props\)/)
|
|
209
|
+
assert.match(dash, /id: 'tskb-rejection-clusters'/)
|
|
210
|
+
assert.match(dash, /navigator\.clipboard\.writeText\(text\)/)
|
|
211
|
+
assert.ok(dash.indexOf('复制约定建议') >= 0)
|
|
212
|
+
const iQt = dash.indexOf("React.createElement(QualityTrends, { sb: (state.usageSummary && state.usageSummary.scoreboard) || null })")
|
|
213
|
+
const iRc = dash.indexOf("React.createElement(RejectionClusters, { sb: (state.usageSummary && state.usageSummary.scoreboard) || null })")
|
|
214
|
+
assert.ok(iQt >= 0 && iRc > iQt, 'RejectionClusters 必须挂在 QualityTrends 正下方')
|
|
215
|
+
// 产物重组装:关键标记在 lib/client.js
|
|
216
|
+
for (const m of ['function RejectionClusters(props)', 'tskb-rejection-clusters', '复制约定建议', '暂无驳回记录']) {
|
|
217
|
+
assert.ok(built.indexOf(m) >= 0, 'client.js 缺标记:' + m + '(需 npm run build-client 重组装)')
|
|
218
|
+
}
|
|
219
|
+
// README 双份:逐字一致 + 含驳回聚类与荐模型 hint 说明
|
|
220
|
+
const r1 = readFileSync(new URL('../../../README.md', import.meta.url), 'utf8')
|
|
221
|
+
const r2 = readFileSync(new URL('../README.md', import.meta.url), 'utf8')
|
|
222
|
+
assert.equal(r1, r2, 'README 双份必须逐字一致(npm run sync-readme)')
|
|
223
|
+
assert.ok(r1.indexOf('驳回聚类') >= 0, 'README 缺「驳回聚类」说明')
|
|
224
|
+
assert.ok(r1.indexOf('workerModel') >= 0, 'README 缺荐模型 hint 说明')
|
|
225
|
+
})
|