dsh-reconcile 0.1.2 → 0.1.4
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 +34 -5
- package/client.js +2 -1
- package/cordis.patch.yml +5 -1
- package/index.js +78 -4
- package/package.json +2 -1
- package/test/client-smoke.mjs +176 -0
- package/test/selfcheck.mjs +20 -1
package/README.md
CHANGED
|
@@ -66,11 +66,11 @@ DeepSeek Harness 插件:**先核事实、再决定问不问、收工对账**
|
|
|
66
66
|
|
|
67
67
|
## 安装
|
|
68
68
|
|
|
69
|
-
**从 npm 装(已发布 0.1.
|
|
69
|
+
**从 npm 装(已发布 0.1.3):**
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
72
|
dsh plugin --profile web add dsh-reconcile
|
|
73
|
-
dsh plugin --profile web add dsh-reconcile@0.1.
|
|
73
|
+
dsh plugin --profile web add dsh-reconcile@0.1.3 # 钉版本
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
npm 包页:<https://www.npmjs.com/package/dsh-reconcile>
|
|
@@ -135,11 +135,12 @@ TASK.evidence.json
|
|
|
135
135
|
## 自检(离线,不联网、不启宿主)
|
|
136
136
|
|
|
137
137
|
```sh
|
|
138
|
-
node test/selfcheck.mjs
|
|
138
|
+
node test/selfcheck.mjs # 82 项:打分表 / TASK.md / 三种证据判定 / 覆盖与防伪造 / 跨站 / 候选 / 客户端打分器对拍 / 作用域护栏
|
|
139
|
+
node test/client-smoke.mjs # 客户端冒烟:桩 React 里真渲染三个组件(抓「组件体引用未定义变量」这类运行时崩溃)
|
|
139
140
|
```
|
|
140
141
|
|
|
141
|
-
当前:**
|
|
142
|
-
evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项。
|
|
142
|
+
当前:**82/82 全绿**,客户端冒烟 **10/10 场景**通过。覆盖打分表 16 项、TASK.md 解析/回写 14 项、三种证据判定 16 项、
|
|
143
|
+
evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项、客户端打分器对拍 2 项、作用域护栏 1 项。
|
|
143
144
|
|
|
144
145
|
没有 `node` 的机器上,可以用 DSH 自带的 Electron 当 node:
|
|
145
146
|
|
|
@@ -148,6 +149,34 @@ $env:ELECTRON_RUN_AS_NODE='1'
|
|
|
148
149
|
& "$env:DSH_NODE_EXECUTABLE" test/selfcheck.mjs
|
|
149
150
|
```
|
|
150
151
|
|
|
152
|
+
### 写 `command` 证据时注意(Windows)
|
|
153
|
+
|
|
154
|
+
插件起命令走 `ctx.subprocess`,Windows 上落到 **PowerShell 5.1**:**不支持 `&&`**,写了会直接报
|
|
155
|
+
`ParentContainsErrorRecordException`。要串多条命令用分号,并把退出码显式传出去:
|
|
156
|
+
|
|
157
|
+
```yaml
|
|
158
|
+
# ✅ PowerShell 5.1 可移植
|
|
159
|
+
- [ ] A1 语法检查通过 | 证据: command `node --check index.js; if ($LASTEXITCODE -ne 0) { exit 1 }; node --check client.js`
|
|
160
|
+
# ❌ 5.1 里 && 不是连接符
|
|
161
|
+
- [ ] A1 语法检查通过 | 证据: command `node --check index.js && node --check client.js`
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 日志
|
|
165
|
+
|
|
166
|
+
关键路径都有结构化日志(`ctx.logger`,缺省降级到 `warn`,日志失败绝不影响主流程):
|
|
167
|
+
|
|
168
|
+
| 时机 | 级别 | 内容 |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `apply()` 结束 | info | `ready` —— 版本号、阈值、gateWrites/autoCheck/routes 开关 |
|
|
171
|
+
| 路由挂载成功 | info | `routes mounted (N)` + 路由路径列表 |
|
|
172
|
+
| `connection.fetch` 不可用 | warn | 面板按钮会退化成只读 |
|
|
173
|
+
| 每轮打分 | info | `scored` —— raw / band / 字数 / 是否写操作 |
|
|
174
|
+
| `probe_intent` | info | 候选数量;事实收集失败记 `probe facts failed` |
|
|
175
|
+
| 写操作被 gate 拦下 | info | `write gated` + 工具名 + 分值 |
|
|
176
|
+
| 收尾对账 | info | `auto-check start` / `auto-check skipped`(本轮模型已对过账) |
|
|
177
|
+
| `reconcile` 工具 | info/error | `reconcile start` / `reconcile done`(耗时、未达标数)/ `reconcile failed` |
|
|
178
|
+
| 卸载 | info | `disposed` + 跟踪的会话数 |
|
|
179
|
+
|
|
151
180
|
## 实测记录(在真实会话里跑过什么)
|
|
152
181
|
|
|
153
182
|
装到本机 Desktop profile 后,用一个真实的 git 工作区(`probe/demo-workspace`)跑过:
|
package/client.js
CHANGED
|
@@ -793,7 +793,8 @@ function formatScore(result) {
|
|
|
793
793
|
}, [draft, inputActions, sessionId])
|
|
794
794
|
|
|
795
795
|
if (!score) {
|
|
796
|
-
|
|
796
|
+
// 紧凑版没有「有文字」这个中间变量(那是输入框下方那个组件的),这里直接从 draft 现算
|
|
797
|
+
return String(draft ?? '').trim() !== ''
|
|
797
798
|
? h('span', { style: { color: T.muted, fontSize: 11 }, 'data-dsh-plugin': 'dsh-reconcile' }, `${t('scoreLabel')} …`)
|
|
798
799
|
: null
|
|
799
800
|
}
|
package/cordis.patch.yml
CHANGED
|
@@ -7,5 +7,9 @@
|
|
|
7
7
|
zeroTargetEscalation: true
|
|
8
8
|
deicticEscalation: true
|
|
9
9
|
logScores: true
|
|
10
|
-
|
|
10
|
+
scoreLogMode: threshold
|
|
11
|
+
# 写操作 gate 默认关(与 DEFAULT_CONFIG / README 一致)。
|
|
12
|
+
# 打开后:含糊度进 panel 档的写操作会先被挡住,直到 probe_intent action=ask 问过一次,
|
|
13
|
+
# 或用户下一条输入重新打分。
|
|
14
|
+
gateWrites: false
|
|
11
15
|
commandTimeoutMs: 120000
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import path from 'node:path'
|
|
12
12
|
import { readFile, writeFile, stat, readdir } from 'node:fs/promises'
|
|
13
|
+
import { readFileSync } from 'node:fs'
|
|
13
14
|
import { randomUUID, createHash } from 'node:crypto'
|
|
14
15
|
|
|
15
16
|
import { scoreRequest, formatScore, textSimilarity } from './src/ambiguity.js'
|
|
@@ -50,12 +51,43 @@ const WRITE_TOOLS = new Set([
|
|
|
50
51
|
|
|
51
52
|
export function apply(ctx, rawConfig = {}) {
|
|
52
53
|
const config = { ...DEFAULT_CONFIG, ...(rawConfig && typeof rawConfig === 'object' ? rawConfig : {}) }
|
|
54
|
+
|
|
55
|
+
/** 插件版本(读 package.json,避免和发布版本漂移);读不到就 unknown。 */
|
|
56
|
+
const PLUGIN_VERSION = (() => {
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version ?? 'unknown'
|
|
59
|
+
} catch {
|
|
60
|
+
return 'unknown'
|
|
61
|
+
}
|
|
62
|
+
})()
|
|
63
|
+
|
|
64
|
+
/** 统一日志:字段序列化失败、logger 抛错都不影响主流程。 */
|
|
65
|
+
const log = (level, message, fields) => {
|
|
66
|
+
let line = message
|
|
67
|
+
if (fields !== undefined) {
|
|
68
|
+
try { line = `${message} ${JSON.stringify(fields)}` } catch { line = `${message} [fields 无法序列化]` }
|
|
69
|
+
}
|
|
70
|
+
const logger = ctx.logger
|
|
71
|
+
const sink = logger?.[level] ?? logger?.info ?? logger?.warn
|
|
72
|
+
if (typeof sink !== 'function') return
|
|
73
|
+
try { sink.call(logger, `dsh-reconcile: ${line}`) } catch { /* 日志失败绝不影响主流程 */ }
|
|
74
|
+
}
|
|
53
75
|
/** sessionId -> { cwd, score, probe, verdict, headline, checkedAt, evidenceDigest, tampered } */
|
|
54
76
|
const state = new Map()
|
|
77
|
+
/** 内存镜像上限:宿主长跑时 session 会一直增,超出就丢最老的(重算即可,不丢真数据)。 */
|
|
78
|
+
const MAX_TRACKED_SESSIONS = 200
|
|
55
79
|
const stateOf = (sessionId) => {
|
|
56
80
|
const key = String(sessionId ?? '')
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
let entry = state.get(key)
|
|
82
|
+
if (!entry) {
|
|
83
|
+
if (state.size >= MAX_TRACKED_SESSIONS) {
|
|
84
|
+
const oldest = state.keys().next().value
|
|
85
|
+
if (oldest !== undefined) state.delete(oldest)
|
|
86
|
+
}
|
|
87
|
+
entry = { sessionId: key }
|
|
88
|
+
state.set(key, entry)
|
|
89
|
+
}
|
|
90
|
+
return entry
|
|
59
91
|
}
|
|
60
92
|
|
|
61
93
|
/* ------------------------------------------------------------------ */
|
|
@@ -230,6 +262,9 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
230
262
|
const agent = exec.agent
|
|
231
263
|
if (!agent) throw new Error('reconcile 需要在一个会话里调用')
|
|
232
264
|
const action = String(args?.action ?? 'status')
|
|
265
|
+
const startedAt = Date.now()
|
|
266
|
+
log('info', 'reconcile start', { action })
|
|
267
|
+
try {
|
|
233
268
|
if (action === 'status') {
|
|
234
269
|
const current = await uiState(agent)
|
|
235
270
|
return textResult([current])
|
|
@@ -268,6 +303,12 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
268
303
|
}
|
|
269
304
|
// check
|
|
270
305
|
const result = await runCheck(agent)
|
|
306
|
+
log('info', 'reconcile done', {
|
|
307
|
+
action, ms: Date.now() - startedAt,
|
|
308
|
+
ok: Boolean(result?.ok),
|
|
309
|
+
unmet: result?.summary?.unmet ?? null,
|
|
310
|
+
total: result?.summary?.total ?? null,
|
|
311
|
+
})
|
|
271
312
|
if (!result?.ok) {
|
|
272
313
|
return textResult([{ ok: false, code: result?.code, message: result?.message, warnings: result?.warnings ?? [] }])
|
|
273
314
|
}
|
|
@@ -279,6 +320,10 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
279
320
|
checkedAt: result.checkedAt,
|
|
280
321
|
evidencePath: rel(cwdOf(agent), result.evidencePath ?? ''),
|
|
281
322
|
}
|
|
323
|
+
} catch (error) {
|
|
324
|
+
log('error', 'reconcile failed', { action, ms: Date.now() - startedAt, error: String(error?.message ?? error) })
|
|
325
|
+
throw error
|
|
326
|
+
}
|
|
282
327
|
},
|
|
283
328
|
})
|
|
284
329
|
|
|
@@ -310,8 +355,15 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
310
355
|
? args.request
|
|
311
356
|
: (entry.lastUserText ?? '')
|
|
312
357
|
const io = ioFor(agent)
|
|
313
|
-
|
|
358
|
+
let facts
|
|
359
|
+
try {
|
|
360
|
+
facts = await collectFacts({ ...io, sessionPaths: () => sessionPathCounts(agent) })
|
|
361
|
+
} catch (error) {
|
|
362
|
+
log('warn', 'probe facts failed', { error: String(error?.message ?? error) })
|
|
363
|
+
throw error
|
|
364
|
+
}
|
|
314
365
|
const candidates = rankCandidates(request, facts)
|
|
366
|
+
log('info', 'probe', { request: request.slice(0, 60), candidates: candidates.length })
|
|
315
367
|
entry.probe = { request, candidates, at: new Date().toISOString(), facts: summarizeFacts(facts) }
|
|
316
368
|
const action = String(args?.action ?? 'probe')
|
|
317
369
|
if (action === 'probe') {
|
|
@@ -347,6 +399,9 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
347
399
|
agent,
|
|
348
400
|
signal: exec.signal,
|
|
349
401
|
})
|
|
402
|
+
// 模型按要求先问了 → 释放写操作 gate(下一轮用户输入会重新评估)
|
|
403
|
+
entry.gateReleased = true
|
|
404
|
+
log('info', 'probe asked, gate released', { candidates: candidates.length })
|
|
350
405
|
const item = answer?.answers?.find((a) => a.id === 'target')
|
|
351
406
|
const selected = item?.selected ?? []
|
|
352
407
|
const custom = item?.custom
|
|
@@ -455,7 +510,10 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
455
510
|
panelThreshold: config.panelThreshold,
|
|
456
511
|
})
|
|
457
512
|
entry.lastUserText = text
|
|
513
|
+
// 新的一轮用户输入意味着重新评估:上一轮的 gate 释放作废
|
|
514
|
+
entry.gateReleased = false
|
|
458
515
|
entry.score = { ...score, text, turn, at: new Date().toISOString(), line: formatScore(score) }
|
|
516
|
+
log('info', 'scored', { raw: score.raw, band: score.band, chars: score.chars, write: score.write })
|
|
459
517
|
entry.recentTexts = [...recent.slice(-3), text]
|
|
460
518
|
// 降噪:只有过提示线时才把分值写进会话日志;同一分数不重复灌。
|
|
461
519
|
const logMode = config.scoreLogMode ?? 'threshold'
|
|
@@ -515,6 +573,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
515
573
|
if (entry.gateReleased) return undefined
|
|
516
574
|
const toolName = String(exec.name ?? '')
|
|
517
575
|
if (!WRITE_TOOLS.has(toolName)) return undefined
|
|
576
|
+
log('info', 'write gated', { tool: toolName, raw: score.raw })
|
|
518
577
|
return {
|
|
519
578
|
reason: `交账:这条请求含糊度 ${score.raw}(${score.hits.map((h) => `${h.delta > 0 ? '+' : ''}${h.delta} ${h.label}`).join('、')}),先确认意图再动手。用 probe_intent 带候选问,或让用户直接给出目标。`,
|
|
520
579
|
}
|
|
@@ -535,10 +594,14 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
535
594
|
try {
|
|
536
595
|
const entry = stateOf(agent.session?.id)
|
|
537
596
|
// 模型这一轮自己刚对过账(3s 内),别再跑一遍命令
|
|
538
|
-
if (entry.lastCheckAt && Date.now() - entry.lastCheckAt < 3000)
|
|
597
|
+
if (entry.lastCheckAt && Date.now() - entry.lastCheckAt < 3000) {
|
|
598
|
+
log('info', 'auto-check skipped', { reason: 'model already checked this turn' })
|
|
599
|
+
return
|
|
600
|
+
}
|
|
539
601
|
const io = ioFor(agent)
|
|
540
602
|
const read = await readTask(io)
|
|
541
603
|
if (!read) return
|
|
604
|
+
log('info', 'auto-check start', { skipCommands: config.autoCheckCommands === false })
|
|
542
605
|
await runCheck(agent, { skipCommands: config.autoCheckCommands === false })
|
|
543
606
|
} catch (error) {
|
|
544
607
|
ctx.logger?.warn?.(`dsh-reconcile: 收尾对账失败:${error?.message ?? error}`)
|
|
@@ -742,6 +805,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
742
805
|
return () => { void dispose?.() }
|
|
743
806
|
}, 'dsh-reconcile: route ' + routePath)
|
|
744
807
|
}
|
|
808
|
+
log('info', `routes mounted (${routes.length})`, { paths: routes.map(([p]) => p) })
|
|
745
809
|
return true
|
|
746
810
|
}
|
|
747
811
|
|
|
@@ -753,7 +817,17 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
753
817
|
}
|
|
754
818
|
}
|
|
755
819
|
|
|
820
|
+
log('info', 'ready', {
|
|
821
|
+
version: PLUGIN_VERSION,
|
|
822
|
+
hintThreshold: config.hintThreshold,
|
|
823
|
+
panelThreshold: config.panelThreshold,
|
|
824
|
+
gateWrites: Boolean(config.gateWrites),
|
|
825
|
+
autoCheck: config.autoCheck !== false,
|
|
826
|
+
routes: config.routesEnabled !== false,
|
|
827
|
+
})
|
|
828
|
+
|
|
756
829
|
return () => {
|
|
830
|
+
log('info', 'disposed', { sessions: state.size })
|
|
757
831
|
state.clear()
|
|
758
832
|
}
|
|
759
833
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-reconcile",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "交账 — fact-first clarification, heuristic ambiguity scoring, and an evidence-backed end-of-task reconciliation ledger",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"scripts": {
|
|
51
51
|
"selfcheck": "node test/selfcheck.mjs",
|
|
52
|
+
"smoke": "node test/client-smoke.mjs",
|
|
52
53
|
"test": "node test/selfcheck.mjs"
|
|
53
54
|
},
|
|
54
55
|
"dsh": {
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端冒烟测试:在桩环境里执行 client.js 的 apply(),再把三个组件各渲染几遍。
|
|
3
|
+
*
|
|
4
|
+
* 存在的理由:`node --check` 只查语法,抓不到「组件体里引用了不存在的标识符」这种
|
|
5
|
+
* 运行时崩溃(上一轮 HeroHint 的 `hasText is not defined` 就是这样把面板打崩的)。
|
|
6
|
+
* 这里用最小 React 桩真正执行组件函数体,任何 ReferenceError / TypeError 都会让测试红。
|
|
7
|
+
*
|
|
8
|
+
* 不联网、不启宿主、不依赖 react 真包。
|
|
9
|
+
*/
|
|
10
|
+
import assert from 'node:assert/strict'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { readFileSync } from 'node:fs'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
|
|
15
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
16
|
+
const source = readFileSync(path.join(here, '..', 'client.js'), 'utf8')
|
|
17
|
+
|
|
18
|
+
/* ---------------------------- 最小 React 桩 ---------------------------- */
|
|
19
|
+
let styleCalls = 0
|
|
20
|
+
function createElement(type, props, ...children) {
|
|
21
|
+
return { type, props: props ?? {}, children }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class FakeComponent {
|
|
25
|
+
constructor(props) { this.props = props }
|
|
26
|
+
setState() {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let seeds = []
|
|
30
|
+
let seedIndex = 0
|
|
31
|
+
const React = {
|
|
32
|
+
Component: FakeComponent,
|
|
33
|
+
Fragment: 'Fragment',
|
|
34
|
+
createElement,
|
|
35
|
+
useState(initial) {
|
|
36
|
+
const seed = seeds[seedIndex++]
|
|
37
|
+
return [seed === undefined ? initial : seed, () => {}]
|
|
38
|
+
},
|
|
39
|
+
// 副作用一律不执行:录像请求、fetch、计时器都不该在冒烟里启动
|
|
40
|
+
useEffect() {},
|
|
41
|
+
useMemo(fn) { return fn() },
|
|
42
|
+
useRef(initial) { return { current: initial } },
|
|
43
|
+
useCallback(fn) { return fn },
|
|
44
|
+
useReducer(_reducer, initial) { return [initial, () => {}] },
|
|
45
|
+
}
|
|
46
|
+
const requireStub = (name) => {
|
|
47
|
+
if (name === 'react') return React
|
|
48
|
+
throw new Error(`冒烟测试不接受额外模块:${name}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* --------------------- 载入 client.js(捕获 load 定义) --------------------- */
|
|
52
|
+
let definition
|
|
53
|
+
const fakeWindow = { __ModuleLoader__: { load: (def) => { definition = def } } }
|
|
54
|
+
// eslint-disable-next-line no-new-func -- 这里就是要执行客户端模块本身
|
|
55
|
+
new Function('window', source)(fakeWindow)
|
|
56
|
+
assert.ok(definition, 'client.js 没有调用 window.__ModuleLoader__.load')
|
|
57
|
+
assert.equal(definition.id, 'dsh-reconcile', '模块 id 变了')
|
|
58
|
+
assert.equal(typeof definition.factory, 'function', 'load 里没有 factory')
|
|
59
|
+
|
|
60
|
+
/* --------------------------- 桩 ctx:捕获挂点 --------------------------- */
|
|
61
|
+
const registered = new Map()
|
|
62
|
+
const warnings = []
|
|
63
|
+
const fakeCtx = {
|
|
64
|
+
effect(fn) { fn(); return () => {} },
|
|
65
|
+
locale: { register: () => () => {} },
|
|
66
|
+
slots: {
|
|
67
|
+
inject(_name, callback) { callback() },
|
|
68
|
+
register(config, Component) { registered.set(config.name, Component); return () => {} },
|
|
69
|
+
},
|
|
70
|
+
logger: { info() {}, warn: (m) => warnings.push(String(m)), error() {} },
|
|
71
|
+
get() { return undefined },
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const exported = definition.factory(requireStub)
|
|
75
|
+
assert.equal(typeof exported?.apply, 'function', 'factory 没有返回 apply()')
|
|
76
|
+
exported.apply(fakeCtx)
|
|
77
|
+
|
|
78
|
+
/* ------------------------------ 断言:挂点 ------------------------------ */
|
|
79
|
+
const EXPECTED_SLOTS = ['conversation.chat.turnTail', 'conversation.composer.dock', 'conversation.hero.options']
|
|
80
|
+
for (const slot of EXPECTED_SLOTS) {
|
|
81
|
+
assert.ok(registered.has(slot), `没有注册 ${slot}`)
|
|
82
|
+
}
|
|
83
|
+
assert.equal(registered.size, EXPECTED_SLOTS.length, `挂了预期外的槽位:${[...registered.keys()].join(', ')}`)
|
|
84
|
+
|
|
85
|
+
/* ------------- 把 guarded 包一层拆开,拿到真正的组件函数 ------------- */
|
|
86
|
+
const innerOf = (component) => {
|
|
87
|
+
const el = component({})
|
|
88
|
+
// guarded(Comp) 返回 h(SlotBoundary, null, h(Comp, props));这里顺藤摸到内层元素
|
|
89
|
+
const child = (el?.children ?? [])[0] ?? el?.props?.children
|
|
90
|
+
return child?.type ?? null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* ------------------------------ 渲染若干场景 ------------------------------ */
|
|
94
|
+
const scoreObject = {
|
|
95
|
+
raw: 55, band: 'panel',
|
|
96
|
+
hits: [
|
|
97
|
+
{ id: 'deictic', label: '含指代词', delta: 18 },
|
|
98
|
+
{ id: 'noCriterion', label: '缺可判定标准', delta: 15 },
|
|
99
|
+
{ id: 'wideWrite', label: '写操作且目标文件数>3或不确定', delta: 12 },
|
|
100
|
+
],
|
|
101
|
+
escalations: [{ id: 'deicticReference', label: '指代 + 已达提示线' }],
|
|
102
|
+
line: '含糊度 55(+18 含指代词 · +15 缺可判定标准) → 弹面板',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const taskState = {
|
|
106
|
+
ok: true,
|
|
107
|
+
sessionId: 'session-smoke',
|
|
108
|
+
cwd: 'C:\\tmp',
|
|
109
|
+
task: {
|
|
110
|
+
slug: 'smoke', status: 'doing', ambiguity: 55,
|
|
111
|
+
goal: '让首页不再横向滚动', constraints: ['不动 Header 结构'],
|
|
112
|
+
items: [
|
|
113
|
+
{ id: 'A1', text: 'README 有安装节', evidenceKind: 'file' },
|
|
114
|
+
{ id: 'A2', text: '首页无横向滚动', evidenceKind: 'file' },
|
|
115
|
+
],
|
|
116
|
+
warnings: [],
|
|
117
|
+
},
|
|
118
|
+
verdict: {
|
|
119
|
+
ok: true, headline: '未达标:1 项', checkedAt: new Date().toISOString(),
|
|
120
|
+
summary: { total: 2, pass: 1, fail: 1, unverified: 0, unmet: 1, manual: 0, manualShare: 0 },
|
|
121
|
+
results: [
|
|
122
|
+
{ id: 'A1', text: 'README 有安装节', verdict: 'pass', evidence: { kind: 'file', path: 'README.md', line: 3 } },
|
|
123
|
+
{ id: 'A2', text: '首页无横向滚动', verdict: 'fail', reason: '文件里不含「minWidth: 0」', evidence: { kind: 'file', path: 'src/index.tsx' } },
|
|
124
|
+
],
|
|
125
|
+
warnings: [],
|
|
126
|
+
},
|
|
127
|
+
headline: '未达标:1 项',
|
|
128
|
+
needsSkeleton: false,
|
|
129
|
+
band: 'task',
|
|
130
|
+
score: scoreObject,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const propsFor = (draft) => ({
|
|
134
|
+
sessionId: 'session-smoke',
|
|
135
|
+
useInput: () => ({ draft, phase: 'plain' }),
|
|
136
|
+
inputActions: { setDraft() {} },
|
|
137
|
+
t: undefined,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const CASES = [
|
|
141
|
+
{ name: 'ScoreHint/空草稿', slot: 'conversation.composer.dock', draft: '', seed: [undefined] },
|
|
142
|
+
{ name: 'ScoreHint/含糊草稿(分数未到)', slot: 'conversation.composer.dock', draft: '改一下那个页面', seed: [undefined] },
|
|
143
|
+
{ name: 'ScoreHint/含糊草稿(面板档)', slot: 'conversation.composer.dock', draft: '改一下那个页面', seed: [scoreObject] },
|
|
144
|
+
{ name: 'ScoreHint/评分失败态', slot: 'conversation.composer.dock', draft: '改一下那个页面', seed: [undefined, undefined, undefined, undefined, 'unauthorized'] },
|
|
145
|
+
{ name: 'HeroHint/空草稿', slot: 'conversation.hero.options', draft: '', seed: [undefined] },
|
|
146
|
+
{ name: 'HeroHint/有草稿', slot: 'conversation.hero.options', draft: '帮我打开页面', seed: [undefined] },
|
|
147
|
+
{ name: 'HeroHint/有分数', slot: 'conversation.hero.options', draft: '改一下那个页面', seed: [scoreObject] },
|
|
148
|
+
{ name: 'ReconcileTail/无状态', slot: 'conversation.chat.turnTail', draft: '', seed: [undefined] },
|
|
149
|
+
{ name: 'ReconcileTail/完整状态', slot: 'conversation.chat.turnTail', draft: '', seed: [taskState] },
|
|
150
|
+
{ name: 'ReconcileTail/读取失败', slot: 'conversation.chat.turnTail', draft: '', seed: [undefined, false, false, 'not found'] },
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
let passed = 0
|
|
154
|
+
const failures = []
|
|
155
|
+
for (const testCase of CASES) {
|
|
156
|
+
seeds = testCase.seed
|
|
157
|
+
seedIndex = 0
|
|
158
|
+
try {
|
|
159
|
+
const guardedComponent = registered.get(testCase.slot)
|
|
160
|
+
const Component = innerOf(guardedComponent) ?? guardedComponent
|
|
161
|
+
assert.equal(typeof Component, 'function', `${testCase.name}: 拿不到组件函数`)
|
|
162
|
+
const out = Component(propsFor(testCase.draft))
|
|
163
|
+
assert.ok(out === null || typeof out === 'object', `${testCase.name}: 返回值既不是元素也不是 null(${typeof out})`)
|
|
164
|
+
passed++
|
|
165
|
+
} catch (error) {
|
|
166
|
+
failures.push(`${testCase.name}: ${error?.name ?? 'Error'}: ${error?.message ?? error}`)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (failures.length > 0) {
|
|
171
|
+
console.error('客户端冒烟失败:')
|
|
172
|
+
for (const failure of failures) console.error(' ✗ ' + failure)
|
|
173
|
+
process.exitCode = 1
|
|
174
|
+
} else {
|
|
175
|
+
console.log(`客户端冒烟:${passed}/${CASES.length} 场景渲染通过(槽位 ${registered.size} 个,无异常)`)
|
|
176
|
+
}
|
package/test/selfcheck.mjs
CHANGED
|
@@ -910,6 +910,25 @@ x
|
|
|
910
910
|
})
|
|
911
911
|
}
|
|
912
912
|
|
|
913
|
+
/* --------------------- 9. 客户端作用域静态护栏 --------------------- */
|
|
914
|
+
{
|
|
915
|
+
const src = readFileSync(new URL('../client.js', import.meta.url), 'utf8')
|
|
916
|
+
const startOf = (name) => src.indexOf('function ' + name)
|
|
917
|
+
const scoreStart = startOf('ScoreHint')
|
|
918
|
+
const heroStart = startOf('HeroHint')
|
|
919
|
+
test('客户端作用域:hasText 只出现在 ScoreHint 内(HeroHint 误用会白屏崩溃)', () => {
|
|
920
|
+
assert.ok(scoreStart > 0 && heroStart > scoreStart, '函数定位失败')
|
|
921
|
+
const scoreSlice = src.slice(scoreStart, heroStart)
|
|
922
|
+
const outside = src.split('\n').map((line, i) => ({ line, no: i + 1 }))
|
|
923
|
+
.filter(({ line }) => /\bhasText\b/.test(line) && !/^\s*(\/\/|\*)/.test(line))
|
|
924
|
+
.filter(({ no }) => {
|
|
925
|
+
const pos = src.split('\n').slice(0, no - 1).join('\n').length
|
|
926
|
+
return !(pos >= scoreStart && pos < heroStart)
|
|
927
|
+
})
|
|
928
|
+
assert.deepEqual(outside.map((o) => o.no), [], 'hasText 出现在 ScoreHint 之外:' + JSON.stringify(outside))
|
|
929
|
+
})
|
|
930
|
+
}
|
|
931
|
+
|
|
913
932
|
/* -------------------------------- 汇总 -------------------------------- */
|
|
914
933
|
const total = passed + failed
|
|
915
934
|
console.log(`\n自检:${passed}/${total} 通过${failed > 0 ? `,${failed} 失败` : ''}`)
|
|
@@ -919,4 +938,4 @@ if (failed > 0) {
|
|
|
919
938
|
}
|
|
920
939
|
process.exit(1)
|
|
921
940
|
}
|
|
922
|
-
console.log('全绿。覆盖:打分表 16 项 · TASK.md 解析/回写 14 项 · 证据判定 16 项 · 覆盖与防伪造 13 项 · 骨架与返工 4 项 · 跨站 8 项 · 候选排序 7 项 · 客户端打分器对拍 2 项')
|
|
941
|
+
console.log('全绿。覆盖:打分表 16 项 · TASK.md 解析/回写 14 项 · 证据判定 16 项 · 覆盖与防伪造 13 项 · 骨架与返工 4 项 · 跨站 8 项 · 候选排序 7 项 · 客户端打分器对拍 2 项 · 作用域护栏 1 项')
|