dsh-soul 0.7.0 → 0.7.2
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/LICENSE +21 -0
- package/README.md +32 -19
- package/README_EN.md +36 -19
- package/assets/personas/custom-placeholder.webp +0 -0
- package/assets/personas/placeholder.svg +16 -0
- package/assets/personas//344/270/245/346/240/274/344/273/243/347/240/201/345/256/241/351/230/205/350/200/205.webp +0 -0
- package/assets/personas//345/244/264/350/204/221/351/243/216/346/232/264/344/274/231/344/274/264.webp +0 -0
- package/assets/personas//346/225/231/345/255/246/345/236/213/350/256/262/350/247/243/350/200/205.webp +0 -0
- package/assets/personas//346/236/201/347/256/200/344/270/273/344/271/211/350/200/205.webp +0 -0
- package/assets/personas//350/207/252/351/251/261/345/236/213/345/215/217/344/275/234/350/200/205.webp +0 -0
- package/assets/personas//350/213/217/346/240/274/346/213/211/345/272/225/345/274/217/346/217/220/351/227/256/350/200/205.webp +0 -0
- package/assets/personas//350/265/204/346/267/261/346/236/266/346/236/204/345/270/210.webp +0 -0
- package/client/index.mjs +1169 -214
- package/index.mjs +732 -85
- package/lib/config.mjs +42 -6
- package/lib/injection.mjs +2 -2
- package/lib/personas.mjs +62 -25
- package/lib/store.mjs +125 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +13 -2
- package/scripts/lib/skip-report.mjs +73 -0
- package/scripts/verify-client.mjs +1319 -0
- package/scripts/verify-compat.mjs +58 -9
- package/scripts/verify-config.mjs +2116 -44
- package/scripts/verify-e2e-prompt.mjs +627 -0
- package/scripts/verify-live-prompt.mjs +445 -0
- package/scripts/verify-nav-icon.mjs +35 -7
- package/scripts/verify-store.mjs +310 -0
- package/scripts/verify-trail.mjs +21 -8
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// scripts/verify-store.mjs — 配置持久化层行为自检(真实文件系统)
|
|
2
|
+
//
|
|
3
|
+
// 与 verify-config.mjs 分工:那边做纯函数与源文本契约,这里在**真实磁盘上**
|
|
4
|
+
// 跑 lib/store.mjs,验证「读写出错时到底发生了什么」。两类失败必须被区分:
|
|
5
|
+
//
|
|
6
|
+
// - 文件不存在 → 首次运行,回退默认值是正常的,允许写入;
|
|
7
|
+
// - 文件损坏 → 回退默认值只是「让插件还能用」,**绝不允许把这份默认值写回磁盘**,
|
|
8
|
+
// 否则用户的自定义指令与预设库会被静默清空。
|
|
9
|
+
//
|
|
10
|
+
// 零依赖,直接 `node scripts/verify-store.mjs` 运行。
|
|
11
|
+
|
|
12
|
+
import assert from 'node:assert/strict'
|
|
13
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
14
|
+
import { tmpdir } from 'node:os'
|
|
15
|
+
import { join } from 'node:path'
|
|
16
|
+
import {
|
|
17
|
+
configWriteRefusal,
|
|
18
|
+
corruptBackupPath,
|
|
19
|
+
describeConfigFailure,
|
|
20
|
+
moveAsideConfigFile,
|
|
21
|
+
readConfigFile,
|
|
22
|
+
writeConfigFile
|
|
23
|
+
} from '../lib/store.mjs'
|
|
24
|
+
import { assertCount, skipNote } from './lib/skip-report.mjs'
|
|
25
|
+
|
|
26
|
+
const root = mkdtempSync(join(tmpdir(), 'dsh-soul-store-'))
|
|
27
|
+
let seq = 0
|
|
28
|
+
function freshPath(label = 'config') {
|
|
29
|
+
seq += 1
|
|
30
|
+
return join(root, `${label}-${seq}.json`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 本机是否提供 inode。`writeConfigFile` 用「临时文件 + rename」落盘,而 rename 会替换
|
|
34
|
+
// 目录项 ⇒ 覆盖前后 inode 不同;这是区分它和「原地截断重写」最直接的判据。少数平台上
|
|
35
|
+
// `statSync().ino` 恒为 0(不提供该信息),此时那一条断言无条件执行 —— 走 skipNote
|
|
36
|
+
// 如实报告,并在 --strict 下算失败(而不是静默不跑)。
|
|
37
|
+
const inodeSupported = detectInodeSupport()
|
|
38
|
+
function detectInodeSupport() {
|
|
39
|
+
try {
|
|
40
|
+
const probe = join(root, 'inode-probe.json')
|
|
41
|
+
writeFileSync(probe, '{}', 'utf8')
|
|
42
|
+
return statSync(probe).ino !== 0
|
|
43
|
+
} catch {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 基线运行应跑出的检查数;不提供 inode 时那条判据不执行,声明值随之减一。
|
|
49
|
+
const EXPECTED_ASSERTIONS = inodeSupported ? 18 : 17
|
|
50
|
+
|
|
51
|
+
let strictOk = true
|
|
52
|
+
|
|
53
|
+
let passed = 0
|
|
54
|
+
async function check(name, fn) {
|
|
55
|
+
// fn 返回 false 表示「这一项本次未执行,且已在内部用 skipNote 说明过」⇒ 不计入 passed。
|
|
56
|
+
let counted
|
|
57
|
+
try {
|
|
58
|
+
counted = await fn()
|
|
59
|
+
} catch (error) {
|
|
60
|
+
// 同 verify-client:失败时点名用例,否则只有一个孤零零的 AssertionError。
|
|
61
|
+
// `stack` 与 `message` 都要改 —— 未捕获错误打印的是 stack,首行在构造时已写死。
|
|
62
|
+
error.message = `【${name}】${error.message}`
|
|
63
|
+
error.stack = `【${name}】${error.stack}`
|
|
64
|
+
throw error
|
|
65
|
+
}
|
|
66
|
+
if (counted === false) return
|
|
67
|
+
passed++
|
|
68
|
+
console.log(` ✓ ${name}`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
process.on('exit', () => {
|
|
72
|
+
try {
|
|
73
|
+
rmSync(root, { recursive: true, force: true })
|
|
74
|
+
} catch {
|
|
75
|
+
// 临时目录清理失败不影响结论
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// 一份「被截断的 JSON」——模拟写到一半进程被杀留下的残骸
|
|
80
|
+
const BROKEN = '{\n "enabled": true,\n "customInstructions": "讲重点"'
|
|
81
|
+
const BROKEN_RECOVERABLE = JSON.stringify({ enabled: false, nickname: '小明', personas: { 老张: { style: 'roast' } } })
|
|
82
|
+
|
|
83
|
+
console.log('readConfigFile')
|
|
84
|
+
|
|
85
|
+
await check('文件不存在 → 走「不存在」路径,不算失败,允许写入', async () => {
|
|
86
|
+
const p = freshPath()
|
|
87
|
+
const r = await readConfigFile(p)
|
|
88
|
+
assert.equal(r.exists, false, 'exists 应为 false')
|
|
89
|
+
assert.equal(r.value, null)
|
|
90
|
+
assert.equal(r.failure, null, '文件不存在不是错误(否则首次运行就无法保存)')
|
|
91
|
+
assert.equal(configWriteRefusal(r.failure, p), null, '首次运行必须允许写入')
|
|
92
|
+
assert.equal(describeConfigFailure(r.failure), null)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
await check('合法 JSON → 原样解析,不产生失败记录', async () => {
|
|
96
|
+
const p = freshPath()
|
|
97
|
+
writeFileSync(p, BROKEN_RECOVERABLE, 'utf8')
|
|
98
|
+
const r = await readConfigFile(p)
|
|
99
|
+
assert.equal(r.exists, true)
|
|
100
|
+
assert.deepEqual(r.value, { enabled: false, nickname: '小明', personas: { 老张: { style: 'roast' } } })
|
|
101
|
+
assert.equal(r.failure, null)
|
|
102
|
+
assert.equal(configWriteRefusal(r.failure, p), null, '正常文件必须允许写入')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
await check('损坏 JSON → 报告 invalid-json,并另存 .corrupt 备份(逐字节一致)', async () => {
|
|
106
|
+
const p = freshPath()
|
|
107
|
+
writeFileSync(p, BROKEN, 'utf8')
|
|
108
|
+
const r = await readConfigFile(p)
|
|
109
|
+
assert.equal(r.exists, true, '损坏的文件依然「存在」,不能与不存在混为一谈')
|
|
110
|
+
assert.equal(r.value, null)
|
|
111
|
+
assert.equal(r.failure.code, 'invalid-json')
|
|
112
|
+
assert.equal(r.failure.backupPath, corruptBackupPath(p), '应备份到 <文件>.corrupt')
|
|
113
|
+
assert.equal(
|
|
114
|
+
readFileSync(r.failure.backupPath, 'utf8'),
|
|
115
|
+
BROKEN,
|
|
116
|
+
'备份必须与损坏文件逐字节一致,否则用户找不回内容'
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
await check('损坏 JSON 的失败说明里同时包含原因与备份位置', async () => {
|
|
121
|
+
const p = freshPath()
|
|
122
|
+
writeFileSync(p, BROKEN, 'utf8')
|
|
123
|
+
const { failure } = await readConfigFile(p)
|
|
124
|
+
const text = describeConfigFailure(failure)
|
|
125
|
+
assert.ok(text.includes('JSON'), `说明里应点明 JSON 解析失败:${text}`)
|
|
126
|
+
assert.ok(text.includes(corruptBackupPath(p)), `说明里应给出备份路径:${text}`)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
await check('读取报错(非 ENOENT)→ 报告 unreadable,而不是伪装成「文件不存在」', async () => {
|
|
130
|
+
// 目录当文件读:各平台都会报错(Windows EISDIR / EPERM,POSIX EISDIR)。
|
|
131
|
+
// 这条路径的意义是:任何读盘异常都不能被吞成「空配置」,否则后续保存会覆盖。
|
|
132
|
+
const dir = join(root, 'a-directory.json')
|
|
133
|
+
mkdirSync(dir)
|
|
134
|
+
const r = await readConfigFile(dir)
|
|
135
|
+
assert.equal(r.exists, true)
|
|
136
|
+
assert.equal(r.value, null)
|
|
137
|
+
assert.equal(r.failure.code, 'unreadable')
|
|
138
|
+
assert.ok(configWriteRefusal(r.failure, dir), '读不出来时同样必须拒绝写入')
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
await check('备份失败(.corrupt 位置被占)不影响读取结果,只是没有备份路径', async () => {
|
|
142
|
+
const p = freshPath()
|
|
143
|
+
writeFileSync(p, BROKEN, 'utf8')
|
|
144
|
+
mkdirSync(corruptBackupPath(p)) // 让 copyFile 失败
|
|
145
|
+
const r = await readConfigFile(p)
|
|
146
|
+
assert.equal(r.failure.code, 'invalid-json', '备份是尽力而为,失败不能改变「配置损坏」这个事实')
|
|
147
|
+
assert.equal(r.failure.backupPath, null)
|
|
148
|
+
assert.ok(describeConfigFailure(r.failure).length > 0, '没有备份也要给出可读说明')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
console.log('\nconfigWriteRefusal')
|
|
152
|
+
|
|
153
|
+
await check('拒绝写入的判定只由「有没有 failure」决定(判定力边界)', async () => {
|
|
154
|
+
const target = join(root, 'config.json')
|
|
155
|
+
assert.equal(configWriteRefusal(null, target), null, '无失败必须允许写入')
|
|
156
|
+
assert.equal(configWriteRefusal(undefined, target), null)
|
|
157
|
+
const msg = configWriteRefusal({ message: '配置文件不是合法的 JSON', backupPath: null }, target)
|
|
158
|
+
assert.ok(msg && msg.includes('配置文件不是合法的 JSON'), '必须原样带上失败原因')
|
|
159
|
+
assert.ok(msg.includes(target), '必须告知用户在哪个文件上恢复')
|
|
160
|
+
const withBackup = configWriteRefusal({ message: 'M', backupPath: `${target}.corrupt` }, target)
|
|
161
|
+
assert.ok(withBackup.includes(`${target}.corrupt`), '有备份时必须告知备份位置')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
console.log('\nR3:损坏的配置不会被静默覆盖')
|
|
165
|
+
|
|
166
|
+
await check('损坏配置 + 尝试保存 → 写入被拒,原文件逐字节未变', async () => {
|
|
167
|
+
const p = freshPath()
|
|
168
|
+
writeFileSync(p, BROKEN, 'utf8')
|
|
169
|
+
const before = readFileSync(p)
|
|
170
|
+
|
|
171
|
+
// 复刻 index.mjs 的接线:读 → 判断能否写 → 不能写就不写。
|
|
172
|
+
// 这里刻意把「保存」也真的执行一遍(而不是只断言 refusal 非空),
|
|
173
|
+
// 否则测不出「拒绝之后文件有没有被动过」。
|
|
174
|
+
const { failure } = await readConfigFile(p)
|
|
175
|
+
const refusal = configWriteRefusal(failure, p)
|
|
176
|
+
assert.ok(refusal, '损坏时必须拒绝写入')
|
|
177
|
+
if (!refusal) {
|
|
178
|
+
await writeConfigFile(p, { enabled: true, nickname: '(默认值)' })
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
assert.ok(before.equals(readFileSync(p)), '被拒的保存不得改动原文件一个字节')
|
|
182
|
+
assert.ok(before.equals(readFileSync(corruptBackupPath(p))), '备份也应保持为损坏前的原文')
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
await check('用户修好文件后读取恢复正常(失败状态不粘住)', async () => {
|
|
186
|
+
const p = freshPath()
|
|
187
|
+
writeFileSync(p, BROKEN, 'utf8')
|
|
188
|
+
const broken = await readConfigFile(p)
|
|
189
|
+
assert.equal(broken.failure.code, 'invalid-json')
|
|
190
|
+
|
|
191
|
+
writeFileSync(p, BROKEN_RECOVERABLE, 'utf8') // 用户手动修复
|
|
192
|
+
const fixed = await readConfigFile(p)
|
|
193
|
+
assert.equal(fixed.failure, null, '修好之后必须回到正常路径(不能一直拒绝写入)')
|
|
194
|
+
assert.deepEqual(fixed.value.nickname, '小明')
|
|
195
|
+
assert.equal(configWriteRefusal(fixed.failure, p), null)
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
console.log('\nwriteConfigFile')
|
|
199
|
+
|
|
200
|
+
await check('原子写:内容完整(格式化 JSON),且不残留临时文件', async () => {
|
|
201
|
+
const p = freshPath()
|
|
202
|
+
await writeConfigFile(p, { enabled: true, nickname: '小明' })
|
|
203
|
+
assert.equal(existsSync(`${p}.tmp`), false, '写入完成后不应残留 .tmp(否则说明没走 rename)')
|
|
204
|
+
assert.equal(readFileSync(p, 'utf8'), JSON.stringify({ enabled: true, nickname: '小明' }, null, 2))
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
await check('原子写:以 rename 替换(覆盖前后 inode 不同)', async () => {
|
|
208
|
+
const p = freshPath()
|
|
209
|
+
await writeConfigFile(p, { a: 1 })
|
|
210
|
+
const first = statSync(p).ino
|
|
211
|
+
await writeConfigFile(p, { a: 2 })
|
|
212
|
+
const second = statSync(p).ino
|
|
213
|
+
assert.deepEqual(JSON.parse(readFileSync(p, 'utf8')), { a: 2 }, '覆盖后的内容必须是新的')
|
|
214
|
+
if (!inodeSupported) {
|
|
215
|
+
strictOk = skipNote(
|
|
216
|
+
'verify-store(rename 替换的 inode 判据)',
|
|
217
|
+
1,
|
|
218
|
+
'本平台不提供 inode(statSync().ino 恒为 0)',
|
|
219
|
+
'在提供 inode 的文件系统上重跑'
|
|
220
|
+
) && strictOk
|
|
221
|
+
return false
|
|
222
|
+
}
|
|
223
|
+
assert.notEqual(first, second, '覆盖应通过 rename 换掉目录项,而不是原地截断重写')
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
await check('上次中断残留的 .tmp 会被下一次写入清理', async () => {
|
|
227
|
+
const p = freshPath()
|
|
228
|
+
writeFileSync(`${p}.tmp`, '{"half":', 'utf8') // 模拟上次写到一半被杀
|
|
229
|
+
await writeConfigFile(p, { b: 2 })
|
|
230
|
+
assert.equal(existsSync(`${p}.tmp`), false)
|
|
231
|
+
assert.deepEqual(JSON.parse(readFileSync(p, 'utf8')), { b: 2 })
|
|
232
|
+
assert.equal(readFileSync(p, 'utf8').includes('half'), false, '不得把残留内容带进新文件')
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
await check('目标目录不存在时会自动创建(多级)', async () => {
|
|
236
|
+
const p = join(root, 'nested', 'deep', 'config.json')
|
|
237
|
+
await writeConfigFile(p, { c: 3 })
|
|
238
|
+
assert.deepEqual(JSON.parse(readFileSync(p, 'utf8')), { c: 3 })
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
await check('正常闭环:不存在 → 写入 → 再读回,全程无失败记录', async () => {
|
|
242
|
+
const p = freshPath()
|
|
243
|
+
const missing = await readConfigFile(p)
|
|
244
|
+
assert.equal(missing.exists, false)
|
|
245
|
+
assert.equal(configWriteRefusal(missing.failure, p), null)
|
|
246
|
+
|
|
247
|
+
await writeConfigFile(p, { enabled: false, occupation: '工程师' })
|
|
248
|
+
const back = await readConfigFile(p)
|
|
249
|
+
assert.equal(back.failure, null)
|
|
250
|
+
assert.deepEqual(back.value, { enabled: false, occupation: '工程师' })
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
// ---------- moveAsideConfigFile:损坏配置的逃生口(重置)----------
|
|
254
|
+
|
|
255
|
+
await check('移开损坏配置:原路径不再存在,备份逐字节一致,读取回到「首次运行」分支', async () => {
|
|
256
|
+
const p = freshPath('moveaside')
|
|
257
|
+
const damaged = '{"enabled": true, "nickname": "小' // 截断的 JSON
|
|
258
|
+
writeFileSync(p, damaged, 'utf8')
|
|
259
|
+
|
|
260
|
+
// 先确认它就是「损坏」状态(否则后面的断言没有意义)
|
|
261
|
+
const broken = await readConfigFile(p)
|
|
262
|
+
assert.equal(broken.failure?.code, 'invalid-json')
|
|
263
|
+
|
|
264
|
+
const target = await moveAsideConfigFile(p)
|
|
265
|
+
assert.equal(target, corruptBackupPath(p), '备份路径应为 <file>.corrupt')
|
|
266
|
+
assert.equal(existsSync(p), false, '原文件必须被移走——只复制不移开的话,重置仍会被判定为损坏而拒绝')
|
|
267
|
+
assert.equal(readFileSync(target, 'utf8'), damaged, '备份必须逐字节一致')
|
|
268
|
+
|
|
269
|
+
const after = await readConfigFile(p)
|
|
270
|
+
assert.equal(after.exists, false, '移开后应回到「文件不存在」分支')
|
|
271
|
+
assert.equal(after.failure, null, '移开后不得再报告失败')
|
|
272
|
+
assert.equal(configWriteRefusal(after.failure, p), null, '移开后必须允许写入,否则重置依然被拒')
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
await check('移开后可以正常写入新配置(重置真正落盘)', async () => {
|
|
276
|
+
const p = freshPath('moveaside-write')
|
|
277
|
+
writeFileSync(p, 'not json at all', 'utf8')
|
|
278
|
+
const target = await moveAsideConfigFile(p)
|
|
279
|
+
assert.ok(target)
|
|
280
|
+
|
|
281
|
+
await writeConfigFile(p, { enabled: true })
|
|
282
|
+
const back = await readConfigFile(p)
|
|
283
|
+
assert.equal(back.failure, null)
|
|
284
|
+
assert.deepEqual(back.value, { enabled: true })
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
await check('文件不存在时移开返回 null,且不制造任何残留', async () => {
|
|
288
|
+
const p = freshPath('moveaside-missing')
|
|
289
|
+
assert.equal(await moveAsideConfigFile(p), null)
|
|
290
|
+
assert.equal(existsSync(p), false)
|
|
291
|
+
assert.equal(existsSync(corruptBackupPath(p)), false, '不该凭空造出备份文件')
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
await check('已有旧备份时会被本次内容覆盖(避免保留一份更早的损坏副本)', async () => {
|
|
295
|
+
const p = freshPath('moveaside-overwrite')
|
|
296
|
+
writeFileSync(corruptBackupPath(p), 'older backup', 'utf8')
|
|
297
|
+
writeFileSync(p, 'newer damaged', 'utf8')
|
|
298
|
+
|
|
299
|
+
const target = await moveAsideConfigFile(p)
|
|
300
|
+
assert.equal(readFileSync(target, 'utf8'), 'newer damaged', '备份应反映最近一次被丢弃的内容')
|
|
301
|
+
assert.equal(existsSync(p), false)
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
if (!assertCount('verify-store', passed, EXPECTED_ASSERTIONS)) process.exit(1)
|
|
305
|
+
if (!strictOk) {
|
|
306
|
+
console.log('结果:有断言未执行(--strict 模式下按失败处理)。')
|
|
307
|
+
process.exit(1)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
console.log(`\n全部通过:${passed} 项检查`)
|
package/scripts/verify-trail.mjs
CHANGED
|
@@ -33,12 +33,17 @@ import os from 'node:os'
|
|
|
33
33
|
import path from 'node:path'
|
|
34
34
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
35
35
|
import { spawnSync } from 'node:child_process'
|
|
36
|
+
import { assertCount, skipExit } from './lib/skip-report.mjs'
|
|
36
37
|
|
|
37
38
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
38
39
|
const ROOT = path.resolve(__dirname, '..')
|
|
39
40
|
const CLIENT_FILE = path.join(ROOT, 'client', 'index.mjs')
|
|
40
41
|
const TRIALS = 60
|
|
41
42
|
|
|
43
|
+
// 本脚本要跑多少项断言。跳过的提示与 --strict 的判定都依赖它,
|
|
44
|
+
// 由 report() 在真正跑完时校验(改了模型列表忘改这里 → 跑得起来的那次会失败)。
|
|
45
|
+
const EXPECTED_ASSERTIONS = 11
|
|
46
|
+
|
|
42
47
|
function parseArgs(argv) {
|
|
43
48
|
const opts = { chrome: null, keep: false, emit: null, dump: null }
|
|
44
49
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -272,7 +277,9 @@ document.getElementById('RESULT').textContent = JSON.stringify(results)
|
|
|
272
277
|
|
|
273
278
|
function extract() {
|
|
274
279
|
const src = fs.readFileSync(CLIENT_FILE, 'utf8')
|
|
275
|
-
|
|
280
|
+
// 终点必须锚在**代码**上,不能锚在注释文案上:此前用的是「\n\n // 颜色容错」,
|
|
281
|
+
// 于是仅改写那句注释(零行为变化)就会让本脚本假失败 —— 变异实验实测过。
|
|
282
|
+
const consts = slice(src, ' const TRAIL_DASH = 12', '\n function safeTrailColor(')
|
|
276
283
|
const renderer = slice(src, ' function createSvgNode(', '\n var SoulController = class')
|
|
277
284
|
for (const needle of ['TRAIL_PAD', 'TRAIL_MAX_SIDE']) {
|
|
278
285
|
if (!consts.includes(needle)) throw new Error(`常量块缺少 ${needle},请更新本脚本的切片标记`)
|
|
@@ -306,6 +313,7 @@ function report(checks) {
|
|
|
306
313
|
if (check.detail) console.log(` ${check.detail}`)
|
|
307
314
|
}
|
|
308
315
|
console.log('')
|
|
316
|
+
if (!assertCount('verify-trail', checks.length, EXPECTED_ASSERTIONS)) process.exit(1)
|
|
309
317
|
if (failed === 0) {
|
|
310
318
|
console.log(`结果:通过(${checks.length} 项)。`)
|
|
311
319
|
process.exit(0)
|
|
@@ -338,9 +346,12 @@ function main() {
|
|
|
338
346
|
|
|
339
347
|
const browser = findBrowser(opts.chrome)
|
|
340
348
|
if (!browser) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
349
|
+
skipExit(
|
|
350
|
+
'verify-trail(输入框光轨回归)',
|
|
351
|
+
EXPECTED_ASSERTIONS,
|
|
352
|
+
'未找到 Chrome / Edge',
|
|
353
|
+
'--chrome <路径> 或 CHROME_PATH 指定浏览器;或两段式:--emit <页面> → 手动 dump-dom → --dump <文件>'
|
|
354
|
+
)
|
|
344
355
|
}
|
|
345
356
|
console.log(` 浏览器:${browser}`)
|
|
346
357
|
console.log('')
|
|
@@ -381,10 +392,12 @@ function main() {
|
|
|
381
392
|
}
|
|
382
393
|
|
|
383
394
|
if (skip) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
395
|
+
skipExit(
|
|
396
|
+
'verify-trail(输入框光轨回归)',
|
|
397
|
+
EXPECTED_ASSERTIONS,
|
|
398
|
+
skip,
|
|
399
|
+
'两段式:--emit <页面> 产出页面 → 手动 dump-dom → --dump <文件> 交回本脚本判定'
|
|
400
|
+
)
|
|
388
401
|
}
|
|
389
402
|
|
|
390
403
|
const match = stdout.match(/<pre id="RESULT"[^>]*>([\s\S]*?)<\/pre>/)
|