dsh-progress-union 0.9.0 → 0.9.1
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/CHANGELOG.md +628 -628
- package/LICENSE +21 -21
- package/README.md +395 -395
- package/anchor.js +39 -39
- package/client.js +3828 -3828
- package/cordis.patch.yml +4 -4
- package/docs/slot-models-comparison.md +23 -23
- package/docs/slot-trail-fanout.md +31 -31
- package/docs/spirit-reference.md +38 -38
- package/dsh.plugin.json +1 -1
- package/icon.svg +7 -7
- package/index.js +6165 -6119
- package/package.json +16 -6
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +479 -479
- package/test/download-classify.test.mjs +284 -284
- package/test/e2e.test.mjs +77 -77
- package/test/goal-drive.test.mjs +17 -17
- package/test/harness.mjs +249 -249
- package/test/host.test.mjs +251 -251
- package/test/major-change-notice.test.mjs +174 -174
- package/test/observer.test.mjs +170 -170
- package/test/ops.test.mjs +638 -638
- package/test/parse-progress.test.mjs +78 -78
- package/test/restore-hydrate.test.mjs +185 -185
- package/test/settings.test.mjs +253 -253
- package/test/star-panel.test.mjs +181 -181
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
- package/test/tool-gloss.test.mjs +137 -137
package/test/settings.test.mjs
CHANGED
|
@@ -1,254 +1,254 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置面契约守卫(2026-11-26 事故回归)。
|
|
3
|
-
*
|
|
4
|
-
* 1) 设置页字段表单靠 **schema 叶子** 的 `.volatile()` 标记生成:整对象标 volatile
|
|
5
|
-
* 时一个字段都不渲染(客户端也就看不到任何可编辑项)。这里逐叶子断言标记存在。
|
|
6
|
-
* 2) 客户端必须把设置卡注册到 `settings.section` 槽,并通过宿主 `configForms`
|
|
7
|
-
* 句柄读写——否则「bundle 页 / 设置页」都没有配置入口。
|
|
8
|
-
*/
|
|
9
|
-
import assert from 'node:assert/strict'
|
|
10
|
-
import fs from 'node:fs'
|
|
11
|
-
import os from 'node:os'
|
|
12
|
-
import path from 'node:path'
|
|
13
|
-
import test from 'node:test'
|
|
14
|
-
import { fileURLToPath } from 'node:url'
|
|
15
|
-
|
|
16
|
-
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
17
|
-
const { Config } = await import('../index.js')
|
|
18
|
-
|
|
19
|
-
/** 递归收集点分键 → 是否带 volatile 标记。 */
|
|
20
|
-
function volatileLeaves(node, prefix = '', out = {}) {
|
|
21
|
-
const inner = node && (node.dict || node.inner)
|
|
22
|
-
if (!inner || typeof inner !== 'object') return out
|
|
23
|
-
for (const [key, child] of Object.entries(inner)) {
|
|
24
|
-
const dotted = prefix ? `${prefix}.${key}` : key
|
|
25
|
-
const meta = (child && child.meta) || {}
|
|
26
|
-
const nested = child && (child.dict || child.inner)
|
|
27
|
-
if (nested && typeof nested === 'object') volatileLeaves(child, dotted, out)
|
|
28
|
-
else out[dotted] = meta.volatile !== undefined
|
|
29
|
-
}
|
|
30
|
-
return out
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test('Config:assistant / observer 的每个叶子都带 volatile(否则设置页不生成字段)', () => {
|
|
34
|
-
const leaves = volatileLeaves(Config)
|
|
35
|
-
const expected = [
|
|
36
|
-
'protocolHint',
|
|
37
|
-
'assistant.mode',
|
|
38
|
-
'assistant.provider',
|
|
39
|
-
'assistant.model',
|
|
40
|
-
'assistant.baseUrl',
|
|
41
|
-
'assistant.apiKey',
|
|
42
|
-
'assistant.authority',
|
|
43
|
-
'assistant.minIntervalMs',
|
|
44
|
-
'assistant.autoApply',
|
|
45
|
-
'observer.enabled',
|
|
46
|
-
'observer.maxIdleSteps',
|
|
47
|
-
'observer.maxIdleMs',
|
|
48
|
-
'observer.autoSyncCurrent',
|
|
49
|
-
'observer.autoSyncThrottleMs',
|
|
50
|
-
'observer.maxItems',
|
|
51
|
-
'todoSync',
|
|
52
|
-
'todo.maxReconcileIntervalMs',
|
|
53
|
-
'todo.mirrorThrottleMs',
|
|
54
|
-
// v0.7.0 新增面:漏一个叶子就不会出现在宿主表单里,也不会热生效。
|
|
55
|
-
'download.enabled',
|
|
56
|
-
'download.ttlMs',
|
|
57
|
-
'download.showSubBar',
|
|
58
|
-
'download.markBackground',
|
|
59
|
-
'toolGloss.enabled',
|
|
60
|
-
'toolGloss.softNarrate',
|
|
61
|
-
'toolGloss.maxLen',
|
|
62
|
-
'notifyMajorChanges',
|
|
63
|
-
'ops.enabled',
|
|
64
|
-
]
|
|
65
|
-
for (const key of expected) {
|
|
66
|
-
assert.ok(key in leaves, `缺少配置键 ${key}`)
|
|
67
|
-
assert.equal(leaves[key], true, `${key} 必须是叶子级 .volatile()`)
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('Config:外层对象不得自己标 volatile(嵌套 volatile 会被宿主拒绝)', () => {
|
|
72
|
-
for (const key of ['assistant', 'observer', 'todo']) {
|
|
73
|
-
const node = (Config.dict || Config.inner || {})[key]
|
|
74
|
-
assert.ok(node, `缺少 ${key} 节点`)
|
|
75
|
-
assert.equal((node.meta || {}).volatile, undefined, `${key} 这层不能标 volatile`)
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('客户端:设置卡双座位(settings.section + plugins.bundle.config)且走 configForms 句柄', () => {
|
|
80
|
-
// fileURLToPath:跨平台取文件路径。`new URL(...).pathname` 在 Linux 上会被
|
|
81
|
-
// `.replace(/^[/]/,'')` 误伤成相对路径(CI 上 ENOENT,本地 Windows 永不暴露)。
|
|
82
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
83
|
-
const src = fs.readFileSync(file, 'utf8')
|
|
84
|
-
assert.match(src, /registerSettingsSeat\('settings\.section'/, '必须注册 settings.section 槽')
|
|
85
|
-
assert.match(src, /id: 'dsh-progress-union'/, '分节 id 必须固定')
|
|
86
|
-
assert.match(src, /registerSettingsSeat\('plugins\.bundle\.config'/, 'bundle 详情页也要有配置卡(keyed by 包名)')
|
|
87
|
-
assert.match(src, /key: 'dsh-progress-union'/, 'bundle 座位 key 必须是包名')
|
|
88
|
-
assert.match(src, /configForms/, '必须经宿主 configForms 读写配置')
|
|
89
|
-
assert.match(src, /function ProgressUnionSettings\(/, '设置卡组件必须在')
|
|
90
|
-
assert.match(src, /scope\.subscribe/, '设置卡要订阅句柄快照')
|
|
91
|
-
assert.match(src, /function ensureUnionSettingsStyle\(/, '样式要注入 document.head,否则设置页里裸奔')
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* v0.7.5 真机回灌:0.7.2 就把 ops.enabled 做成了「整块开关」,但设置卡只渲染
|
|
96
|
-
* assistant/observer/todo 三组——宿主不会为外部插件另生成通用表单,于是这个开关
|
|
97
|
-
* 根本没有用户可达的入口(实测:两个座位都是那 4 组 10 个控件,搜不到 ops)。
|
|
98
|
-
* download 组、toolGloss 组、notifyMajorChanges 同病。这里钉住「有 volatile 就必须有表单」。
|
|
99
|
-
*/
|
|
100
|
-
test('设置卡:v0.7.0 四组开关真的有表单入口(不能只存 schema)', () => {
|
|
101
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
102
|
-
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
103
|
-
for (const call of [
|
|
104
|
-
"switchInput('download', download, 'enabled'",
|
|
105
|
-
"switchInput('download', download, 'showSubBar'",
|
|
106
|
-
"switchInput('download', download, 'markBackground'",
|
|
107
|
-
"numberInput('download', 'ttlMs'",
|
|
108
|
-
"switchInput('toolGloss', toolGloss, 'enabled'",
|
|
109
|
-
"switchInput('toolGloss', toolGloss, 'softNarrate'",
|
|
110
|
-
"numberInput('toolGloss', 'maxLen'",
|
|
111
|
-
"switchInput('ops', ops, 'enabled'",
|
|
112
|
-
"commit('notifyMajorChanges', v)",
|
|
113
|
-
]) {
|
|
114
|
-
assert.ok(src.includes(call), `设置卡缺少表单接线:${call}`)
|
|
115
|
-
}
|
|
116
|
-
// 读值必须按组路由(旧实现写死三元,新组会全读到 observer 的桶里去)。
|
|
117
|
-
assert.match(src, /const buckets = \{ assistant, observer, todo, download, toolGloss, ops \}/, 'readField 需要组查表')
|
|
118
|
-
assert.match(src, /\(buckets\[group\] \|\| observer\)\[key\]/, 'readField 必须走组查表取值')
|
|
119
|
-
// 保存通道也得把新组写回去(不写 = 拨了开关但从未落盘,看着像“配置不下发”)。
|
|
120
|
-
for (const line of [
|
|
121
|
-
"const canMutate = () => Boolean(scope) && typeof scope.mutate === 'function'",
|
|
122
|
-
'const writeOps = async (ops) => {',
|
|
123
|
-
"if (canMutate()) return void writeOps([{ op: 'set', path: [group, key], value: next }])",
|
|
124
|
-
"await writeOps(keys.map((key) => ({ op: 'set', path: [group, key], value: draft[group][key] })))",
|
|
125
|
-
]) {
|
|
126
|
-
assert.ok(src.includes(line), `写面缺少叶路径接线:${line}`)
|
|
127
|
-
}
|
|
128
|
-
for (const dead of [
|
|
129
|
-
"await commit('ops', { ...ops, ...draft.ops })",
|
|
130
|
-
"await commit('download', { ...download, ...draft.download })",
|
|
131
|
-
"await commit('assistant', { ...assistant, ...draft.assistant })",
|
|
132
|
-
]) {
|
|
133
|
-
assert.ok(!src.includes(dead), `嵌套组不得再整对象铺回(会被 settings/rejected 拒):${dead}`)
|
|
134
|
-
}
|
|
135
|
-
// 双语齐(本插件只注册 zh/en,其余语种按设计回退英文)
|
|
136
|
-
assert.equal((src.match(/setOpsEnabled:/g) || []).length, 2, 'setOpsEnabled 需 zh/en 两份')
|
|
137
|
-
assert.equal((src.match(/setDlEnabled:/g) || []).length, 2, 'setDlEnabled 需 zh/en 两份')
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* v0.7.6 真机回灌:设置卡此前把嵌套组整对象铺回(scope.set('ops', {...})),
|
|
142
|
-
* 而宿主 ConfigForm.set 只接受顶层标量、Config 的 volatile 又是逐叶子标的,
|
|
143
|
-
* 于是每一次组写都被 settings/rejected 拒(Config field "ops" is not volatile)。
|
|
144
|
-
* 这条把“设置卡实际写的每条路径 ∈ volatile 叶子”钉成回归闸。
|
|
145
|
-
*/
|
|
146
|
-
test('设置卡:每条写路径必须是 Config 里的 volatile 叶子', () => {
|
|
147
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
148
|
-
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
149
|
-
const leaves = volatileLeaves(Config)
|
|
150
|
-
const paths = new Set()
|
|
151
|
-
for (const m of src.matchAll(/(?:switchInput|segmentInput)\('(\w+)',\s*\w+,\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
152
|
-
for (const m of src.matchAll(/(?:numberInput|textInput|secretInput)\('(\w+)',\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
153
|
-
// v0.8.1:路由链编辑器直接拼 mutate 的 path 字面量,这类写点以前扫不到——
|
|
154
|
-
// 不补上就等于开了个绕过本闸的后门(新写点必须同样落在 volatile 叶子上)。
|
|
155
|
-
for (const m of src.matchAll(/path:\s*\['(\w+)',\s*'(\w+)'\]/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
156
|
-
for (const m of src.matchAll(/void commit\('(\w+)'/g)) paths.add(m[1])
|
|
157
|
-
assert.ok(paths.size >= 27, `扫到的写路径只有 ${paths.size} 条,正则可能失效`)
|
|
158
|
-
for (const p of [...paths].sort()) {
|
|
159
|
-
assert.ok(p in leaves, `设置卡要写 ${p},但 Config 里没这个键`)
|
|
160
|
-
assert.equal(leaves[p], true, `设置卡要写 ${p},但它不是 volatile 叶子 → 宿主 settings/rejected`)
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* v0.8.1:降级链从「只能手写 yml」改成面板可编。本闸钉住四件事:
|
|
166
|
-
* fallbacks 必须是 volatile 叶子(否则编辑器拨了不落盘);整链一次提交
|
|
167
|
-
* 三个键;不得再开整组铺回的分支;目录拉不到时要能降级手输。
|
|
168
|
-
*/
|
|
169
|
-
test('v0.8.1:路由链编辑器的写面与降级形态', () => {
|
|
170
|
-
const leaves = volatileLeaves(Config)
|
|
171
|
-
assert.equal(leaves['ops.fallbacks'], true, 'ops.fallbacks 必须是 volatile 叶子,否则面板编不了链')
|
|
172
|
-
assert.equal(leaves['ops'], undefined, 'ops 节本身不得被标 volatile(嵌套 volatile 宿主直接拒)')
|
|
173
|
-
|
|
174
|
-
const src = fs.readFileSync(fileURLToPath(new URL('../client.js', import.meta.url)), 'utf8').replace(/\r\n/g, '\n')
|
|
175
|
-
for (const key of ['routeProvider', 'routeModel', 'fallbacks']) {
|
|
176
|
-
assert.ok(src.includes(`path: ['ops', '${key}']`), `整链提交必须含 ${key} 这一键,不留半截状态`)
|
|
177
|
-
}
|
|
178
|
-
assert.ok(!/void commit\('ops'/.test(src), '嵌套组不得整组铺回(0.7.5 实测会被 settings/rejected 拒)')
|
|
179
|
-
assert.match(src, /fetch\(`\$\{API\}\/ops\/catalog`/, '编辑器必须从宿主目录拉 provider/模型')
|
|
180
|
-
assert.match(src, /bucket\.modelsAvailable === true/, '该家不供模型清单时要降级为手输,不能给一个填不了的空下拉')
|
|
181
|
-
// 真机 0.8.1 实测:手输框只挂 onBlur 不挂 onChange 时,React 把字段当只读,
|
|
182
|
-
// 下一次重渲染就把刚打的字抹回空串(blur 后读回 value=''、链也不动)。
|
|
183
|
-
const manualHandlers = src.match(/placeholder: t\('setOpsChain(?:Provider|Model)Manual'\),\s*\n\s*onChange:/g) || []
|
|
184
|
-
assert.equal(manualHandlers.length, 2, '两个手输框都必须带 onChange(打字走本地草稿,blur 才提交)')
|
|
185
|
-
assert.match(src, /const editRow = \(index, key, value\) => \{\s*setDraft\(/, '打字只写本地草稿,不能逐字符落盘')
|
|
186
|
-
// 预览行必须跟快照重取:只挂 tick 时重取与写盘并发,拿到的是写前快照
|
|
187
|
-
assert.match(src, /\}, \[tick, storedSig\]\)/, '目录重取要同时跟 tick 与快照签名')
|
|
188
|
-
assert.match(src, /rows\.length >= maxChain/, '添加按钮到链长上限要禁用')
|
|
189
|
-
assert.match(src, /const move = \(index, delta\) =>/, '行序必须能在面板调(降级链语义就是顺序)')
|
|
190
|
-
assert.match(src, /chainRowsOf\(props\.ops\)/, '行初值必须从已存配置回显,不能从空表开始')
|
|
191
|
-
assert.ok(!src.includes('setOpsFallbackNote'), '「fallbacks 只能改 yml」的旧说法必须从文案里消失')
|
|
192
|
-
// v0.8.3 真机反馈:用户滚遍设置页后判定「没有主+fallback」——实为卡片默认折叠把编辑器藏了。
|
|
193
|
-
// SettingsCard 的默认值是 `defaultOpen !== false`,即省略才展开;这里钉住不得再写 false。
|
|
194
|
-
assert.match(src, /title: t\('setOpsGroup'\), badge: t\('setOpsBadge'\), hint: t\('setOpsHint'\) \}/, '路由链卡必须默认展开(省略 defaultOpen)')
|
|
195
|
-
assert.ok(!/setOpsGroup'[^}]*defaultOpen: false/.test(src), 'ops 卡不得再默认折叠,主+fallback 要一眼可见')
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* v0.8.4 真机回灌:取消折叠只是第一步——卡仍在第 4 张,不滚就看不到;
|
|
200
|
-
* 而 provider 输入框的占位符写的是宿主并不存在的 `local-35b`,用户会把
|
|
201
|
-
* 灰色占位当已存值(本轮我就误判过一次),而 registered + 空 provider
|
|
202
|
-
* 会让 assistantReady() 直接返回 false,观察者静默不跑。
|
|
203
|
-
*/
|
|
204
|
-
test('设置页:路由链卡排第一,且占位符不误导、未填全要给警示', () => {
|
|
205
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
206
|
-
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
207
|
-
const iOps = src.indexOf("title: t('setOpsGroup')")
|
|
208
|
-
const iLlm = src.indexOf("title: t('setLlmGroup')")
|
|
209
|
-
const iObs = src.indexOf("title: t('setObserverGroup')")
|
|
210
|
-
assert.ok(iOps > 0 && iOps < iLlm && iLlm < iObs, `渲染顺序必须是 ops→LLM→观察者(实得 ops=${iOps} llm=${iLlm} obs=${iObs})`)
|
|
211
|
-
assert.ok(!src.includes("'local-35b'"), 'provider 占位符不得写宿主不存在的 local-35b')
|
|
212
|
-
assert.match(src, /textInput\('assistant', 'provider', '', 'local-35'\)/, '占位符要用宿主真实注册键 local-35')
|
|
213
|
-
assert.match(src, /mode === 'registered' && \(!String\(readField\('assistant', 'provider', ''\)\)\.trim\(\)/, 'registered 但 provider/model 未填全时必须给警示行')
|
|
214
|
-
assert.match(src, /className: 'dsu-warn-line'/, '警示行要有独立样式(沿用既有琥珀档位,不发明令牌)')
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* v0.9.0 真机反馈:换 provider 后 model 仍是上一个 provider 的值,配出
|
|
219
|
-
* provider/model 错配串(调用必失败)。写面闸:provider 的 onChange 不得再走
|
|
220
|
-
* 单字段 patchRow,必须走会同时处理 model 的 pickProviderRow。
|
|
221
|
-
*/
|
|
222
|
-
test('链编辑器:换 provider 必须同时处理 model(预填或清空,不得留旧值)', () => {
|
|
223
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
224
|
-
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
225
|
-
assert.ok(!/patchRow\(index, 'provider'/.test(src), "provider 切换不得再走单字段 patchRow(会留下上一个 provider 的 model)")
|
|
226
|
-
assert.match(src, /onChange: \(e\) => pickProviderRow\(index, e\.target\.value\)/, 'provider 下拉必须走 pickProviderRow')
|
|
227
|
-
assert.match(src, /const pickProviderRow = \(index, value\) => \{[\s\S]{0,400}?model: nextModel/, 'pickProviderRow 必须同时写 model')
|
|
228
|
-
assert.match(src, /held && list\.some\(\(m\) => m\.id === held\) \? held : \(list\.length \? list\[0\]\.id : ''\)/, '保留条件:新 provider 清单里有则留,否则预填第一个,拿不到清单则清空')
|
|
229
|
-
assert.match(src, /const models = modelsOf\(row\.provider\)/, '行内模型清单与预填逻辑共用同一个源,不能两套口径')
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* v0.7.7 真机回灌:0.7.6 修好写面后,页脚出现「已保存」与「有未保存的改动」并存
|
|
234
|
-
* —— 开关拨完即落盘,但乐观草稿仍按「键存在」计脏。脏位必须按值比对。
|
|
235
|
-
*/
|
|
236
|
-
test('设置卡:拨完即落盘的开关不再留脏(脏位按值比对)', () => {
|
|
237
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
238
|
-
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
239
|
-
assert.match(src, /const dirtyKeys = \(group\) => \{\s*const bucket = buckets\[group\] \|\| \{\}/, 'dirtyKeys 需要拿存储桶做值比对')
|
|
240
|
-
assert.match(src, /\.filter\(\(key\) => draft\[group\]\[key\] !== bucket\[key\]\)/, '脏键必须按「草稿值 ≠ 存值」过滤')
|
|
241
|
-
assert.match(src, /const scalarDirty = \(key\) => Object\.prototype\.hasOwnProperty\.call\(draft, key\) && draft\[key\] !== value\[key\]/, '顶层标量同样按值判脏')
|
|
242
|
-
assert.match(src, /scalarDirty\('todoSync'\) \|\| scalarDirty\('notifyMajorChanges'\)/, 'hasDirty 不得再用「键存在即脏」')
|
|
243
|
-
assert.ok(!src.includes('const dirtyKeys = (group) => Object.keys(draft[group] || {})'), '旧的按键存在判脏必须移除')
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('ops 块开关位定期重探,不钉在首帧(热生效无需重挂载)', () => {
|
|
247
|
-
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
248
|
-
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
249
|
-
assert.match(src, /const OPS_POLL_MS = \d+/, '需要有重探间隔常量')
|
|
250
|
-
assert.match(src, /setInterval\(probe, OPS_POLL_MS\)/, '必须真的定时重探 providers 面')
|
|
251
|
-
assert.match(src, /if \(data\.disabled\) \{[\s\S]{0,80}?setOff\(true\)[\s\S]{0,40}?return[\s\S]{0,120}?setOff\(false\)/, '关掉要隐块,改回开要自动复现(不能只置 true)')
|
|
252
|
-
assert.match(src, /if \(primed\.current\) return/, '默认 provider/model 只在首次回填,不覆用户手选')
|
|
253
|
-
assert.match(src, /clearInterval\(timer\)/, '卸载必须收定时器')
|
|
1
|
+
/**
|
|
2
|
+
* 设置面契约守卫(2026-11-26 事故回归)。
|
|
3
|
+
*
|
|
4
|
+
* 1) 设置页字段表单靠 **schema 叶子** 的 `.volatile()` 标记生成:整对象标 volatile
|
|
5
|
+
* 时一个字段都不渲染(客户端也就看不到任何可编辑项)。这里逐叶子断言标记存在。
|
|
6
|
+
* 2) 客户端必须把设置卡注册到 `settings.section` 槽,并通过宿主 `configForms`
|
|
7
|
+
* 句柄读写——否则「bundle 页 / 设置页」都没有配置入口。
|
|
8
|
+
*/
|
|
9
|
+
import assert from 'node:assert/strict'
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import test from 'node:test'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
15
|
+
|
|
16
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
17
|
+
const { Config } = await import('../index.js')
|
|
18
|
+
|
|
19
|
+
/** 递归收集点分键 → 是否带 volatile 标记。 */
|
|
20
|
+
function volatileLeaves(node, prefix = '', out = {}) {
|
|
21
|
+
const inner = node && (node.dict || node.inner)
|
|
22
|
+
if (!inner || typeof inner !== 'object') return out
|
|
23
|
+
for (const [key, child] of Object.entries(inner)) {
|
|
24
|
+
const dotted = prefix ? `${prefix}.${key}` : key
|
|
25
|
+
const meta = (child && child.meta) || {}
|
|
26
|
+
const nested = child && (child.dict || child.inner)
|
|
27
|
+
if (nested && typeof nested === 'object') volatileLeaves(child, dotted, out)
|
|
28
|
+
else out[dotted] = meta.volatile !== undefined
|
|
29
|
+
}
|
|
30
|
+
return out
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
test('Config:assistant / observer 的每个叶子都带 volatile(否则设置页不生成字段)', () => {
|
|
34
|
+
const leaves = volatileLeaves(Config)
|
|
35
|
+
const expected = [
|
|
36
|
+
'protocolHint',
|
|
37
|
+
'assistant.mode',
|
|
38
|
+
'assistant.provider',
|
|
39
|
+
'assistant.model',
|
|
40
|
+
'assistant.baseUrl',
|
|
41
|
+
'assistant.apiKey',
|
|
42
|
+
'assistant.authority',
|
|
43
|
+
'assistant.minIntervalMs',
|
|
44
|
+
'assistant.autoApply',
|
|
45
|
+
'observer.enabled',
|
|
46
|
+
'observer.maxIdleSteps',
|
|
47
|
+
'observer.maxIdleMs',
|
|
48
|
+
'observer.autoSyncCurrent',
|
|
49
|
+
'observer.autoSyncThrottleMs',
|
|
50
|
+
'observer.maxItems',
|
|
51
|
+
'todoSync',
|
|
52
|
+
'todo.maxReconcileIntervalMs',
|
|
53
|
+
'todo.mirrorThrottleMs',
|
|
54
|
+
// v0.7.0 新增面:漏一个叶子就不会出现在宿主表单里,也不会热生效。
|
|
55
|
+
'download.enabled',
|
|
56
|
+
'download.ttlMs',
|
|
57
|
+
'download.showSubBar',
|
|
58
|
+
'download.markBackground',
|
|
59
|
+
'toolGloss.enabled',
|
|
60
|
+
'toolGloss.softNarrate',
|
|
61
|
+
'toolGloss.maxLen',
|
|
62
|
+
'notifyMajorChanges',
|
|
63
|
+
'ops.enabled',
|
|
64
|
+
]
|
|
65
|
+
for (const key of expected) {
|
|
66
|
+
assert.ok(key in leaves, `缺少配置键 ${key}`)
|
|
67
|
+
assert.equal(leaves[key], true, `${key} 必须是叶子级 .volatile()`)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('Config:外层对象不得自己标 volatile(嵌套 volatile 会被宿主拒绝)', () => {
|
|
72
|
+
for (const key of ['assistant', 'observer', 'todo']) {
|
|
73
|
+
const node = (Config.dict || Config.inner || {})[key]
|
|
74
|
+
assert.ok(node, `缺少 ${key} 节点`)
|
|
75
|
+
assert.equal((node.meta || {}).volatile, undefined, `${key} 这层不能标 volatile`)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('客户端:设置卡双座位(settings.section + plugins.bundle.config)且走 configForms 句柄', () => {
|
|
80
|
+
// fileURLToPath:跨平台取文件路径。`new URL(...).pathname` 在 Linux 上会被
|
|
81
|
+
// `.replace(/^[/]/,'')` 误伤成相对路径(CI 上 ENOENT,本地 Windows 永不暴露)。
|
|
82
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
83
|
+
const src = fs.readFileSync(file, 'utf8')
|
|
84
|
+
assert.match(src, /registerSettingsSeat\('settings\.section'/, '必须注册 settings.section 槽')
|
|
85
|
+
assert.match(src, /id: 'dsh-progress-union'/, '分节 id 必须固定')
|
|
86
|
+
assert.match(src, /registerSettingsSeat\('plugins\.bundle\.config'/, 'bundle 详情页也要有配置卡(keyed by 包名)')
|
|
87
|
+
assert.match(src, /key: 'dsh-progress-union'/, 'bundle 座位 key 必须是包名')
|
|
88
|
+
assert.match(src, /configForms/, '必须经宿主 configForms 读写配置')
|
|
89
|
+
assert.match(src, /function ProgressUnionSettings\(/, '设置卡组件必须在')
|
|
90
|
+
assert.match(src, /scope\.subscribe/, '设置卡要订阅句柄快照')
|
|
91
|
+
assert.match(src, /function ensureUnionSettingsStyle\(/, '样式要注入 document.head,否则设置页里裸奔')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* v0.7.5 真机回灌:0.7.2 就把 ops.enabled 做成了「整块开关」,但设置卡只渲染
|
|
96
|
+
* assistant/observer/todo 三组——宿主不会为外部插件另生成通用表单,于是这个开关
|
|
97
|
+
* 根本没有用户可达的入口(实测:两个座位都是那 4 组 10 个控件,搜不到 ops)。
|
|
98
|
+
* download 组、toolGloss 组、notifyMajorChanges 同病。这里钉住「有 volatile 就必须有表单」。
|
|
99
|
+
*/
|
|
100
|
+
test('设置卡:v0.7.0 四组开关真的有表单入口(不能只存 schema)', () => {
|
|
101
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
102
|
+
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
103
|
+
for (const call of [
|
|
104
|
+
"switchInput('download', download, 'enabled'",
|
|
105
|
+
"switchInput('download', download, 'showSubBar'",
|
|
106
|
+
"switchInput('download', download, 'markBackground'",
|
|
107
|
+
"numberInput('download', 'ttlMs'",
|
|
108
|
+
"switchInput('toolGloss', toolGloss, 'enabled'",
|
|
109
|
+
"switchInput('toolGloss', toolGloss, 'softNarrate'",
|
|
110
|
+
"numberInput('toolGloss', 'maxLen'",
|
|
111
|
+
"switchInput('ops', ops, 'enabled'",
|
|
112
|
+
"commit('notifyMajorChanges', v)",
|
|
113
|
+
]) {
|
|
114
|
+
assert.ok(src.includes(call), `设置卡缺少表单接线:${call}`)
|
|
115
|
+
}
|
|
116
|
+
// 读值必须按组路由(旧实现写死三元,新组会全读到 observer 的桶里去)。
|
|
117
|
+
assert.match(src, /const buckets = \{ assistant, observer, todo, download, toolGloss, ops \}/, 'readField 需要组查表')
|
|
118
|
+
assert.match(src, /\(buckets\[group\] \|\| observer\)\[key\]/, 'readField 必须走组查表取值')
|
|
119
|
+
// 保存通道也得把新组写回去(不写 = 拨了开关但从未落盘,看着像“配置不下发”)。
|
|
120
|
+
for (const line of [
|
|
121
|
+
"const canMutate = () => Boolean(scope) && typeof scope.mutate === 'function'",
|
|
122
|
+
'const writeOps = async (ops) => {',
|
|
123
|
+
"if (canMutate()) return void writeOps([{ op: 'set', path: [group, key], value: next }])",
|
|
124
|
+
"await writeOps(keys.map((key) => ({ op: 'set', path: [group, key], value: draft[group][key] })))",
|
|
125
|
+
]) {
|
|
126
|
+
assert.ok(src.includes(line), `写面缺少叶路径接线:${line}`)
|
|
127
|
+
}
|
|
128
|
+
for (const dead of [
|
|
129
|
+
"await commit('ops', { ...ops, ...draft.ops })",
|
|
130
|
+
"await commit('download', { ...download, ...draft.download })",
|
|
131
|
+
"await commit('assistant', { ...assistant, ...draft.assistant })",
|
|
132
|
+
]) {
|
|
133
|
+
assert.ok(!src.includes(dead), `嵌套组不得再整对象铺回(会被 settings/rejected 拒):${dead}`)
|
|
134
|
+
}
|
|
135
|
+
// 双语齐(本插件只注册 zh/en,其余语种按设计回退英文)
|
|
136
|
+
assert.equal((src.match(/setOpsEnabled:/g) || []).length, 2, 'setOpsEnabled 需 zh/en 两份')
|
|
137
|
+
assert.equal((src.match(/setDlEnabled:/g) || []).length, 2, 'setDlEnabled 需 zh/en 两份')
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* v0.7.6 真机回灌:设置卡此前把嵌套组整对象铺回(scope.set('ops', {...})),
|
|
142
|
+
* 而宿主 ConfigForm.set 只接受顶层标量、Config 的 volatile 又是逐叶子标的,
|
|
143
|
+
* 于是每一次组写都被 settings/rejected 拒(Config field "ops" is not volatile)。
|
|
144
|
+
* 这条把“设置卡实际写的每条路径 ∈ volatile 叶子”钉成回归闸。
|
|
145
|
+
*/
|
|
146
|
+
test('设置卡:每条写路径必须是 Config 里的 volatile 叶子', () => {
|
|
147
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
148
|
+
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
149
|
+
const leaves = volatileLeaves(Config)
|
|
150
|
+
const paths = new Set()
|
|
151
|
+
for (const m of src.matchAll(/(?:switchInput|segmentInput)\('(\w+)',\s*\w+,\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
152
|
+
for (const m of src.matchAll(/(?:numberInput|textInput|secretInput)\('(\w+)',\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
153
|
+
// v0.8.1:路由链编辑器直接拼 mutate 的 path 字面量,这类写点以前扫不到——
|
|
154
|
+
// 不补上就等于开了个绕过本闸的后门(新写点必须同样落在 volatile 叶子上)。
|
|
155
|
+
for (const m of src.matchAll(/path:\s*\['(\w+)',\s*'(\w+)'\]/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
156
|
+
for (const m of src.matchAll(/void commit\('(\w+)'/g)) paths.add(m[1])
|
|
157
|
+
assert.ok(paths.size >= 27, `扫到的写路径只有 ${paths.size} 条,正则可能失效`)
|
|
158
|
+
for (const p of [...paths].sort()) {
|
|
159
|
+
assert.ok(p in leaves, `设置卡要写 ${p},但 Config 里没这个键`)
|
|
160
|
+
assert.equal(leaves[p], true, `设置卡要写 ${p},但它不是 volatile 叶子 → 宿主 settings/rejected`)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* v0.8.1:降级链从「只能手写 yml」改成面板可编。本闸钉住四件事:
|
|
166
|
+
* fallbacks 必须是 volatile 叶子(否则编辑器拨了不落盘);整链一次提交
|
|
167
|
+
* 三个键;不得再开整组铺回的分支;目录拉不到时要能降级手输。
|
|
168
|
+
*/
|
|
169
|
+
test('v0.8.1:路由链编辑器的写面与降级形态', () => {
|
|
170
|
+
const leaves = volatileLeaves(Config)
|
|
171
|
+
assert.equal(leaves['ops.fallbacks'], true, 'ops.fallbacks 必须是 volatile 叶子,否则面板编不了链')
|
|
172
|
+
assert.equal(leaves['ops'], undefined, 'ops 节本身不得被标 volatile(嵌套 volatile 宿主直接拒)')
|
|
173
|
+
|
|
174
|
+
const src = fs.readFileSync(fileURLToPath(new URL('../client.js', import.meta.url)), 'utf8').replace(/\r\n/g, '\n')
|
|
175
|
+
for (const key of ['routeProvider', 'routeModel', 'fallbacks']) {
|
|
176
|
+
assert.ok(src.includes(`path: ['ops', '${key}']`), `整链提交必须含 ${key} 这一键,不留半截状态`)
|
|
177
|
+
}
|
|
178
|
+
assert.ok(!/void commit\('ops'/.test(src), '嵌套组不得整组铺回(0.7.5 实测会被 settings/rejected 拒)')
|
|
179
|
+
assert.match(src, /fetch\(`\$\{API\}\/ops\/catalog`/, '编辑器必须从宿主目录拉 provider/模型')
|
|
180
|
+
assert.match(src, /bucket\.modelsAvailable === true/, '该家不供模型清单时要降级为手输,不能给一个填不了的空下拉')
|
|
181
|
+
// 真机 0.8.1 实测:手输框只挂 onBlur 不挂 onChange 时,React 把字段当只读,
|
|
182
|
+
// 下一次重渲染就把刚打的字抹回空串(blur 后读回 value=''、链也不动)。
|
|
183
|
+
const manualHandlers = src.match(/placeholder: t\('setOpsChain(?:Provider|Model)Manual'\),\s*\n\s*onChange:/g) || []
|
|
184
|
+
assert.equal(manualHandlers.length, 2, '两个手输框都必须带 onChange(打字走本地草稿,blur 才提交)')
|
|
185
|
+
assert.match(src, /const editRow = \(index, key, value\) => \{\s*setDraft\(/, '打字只写本地草稿,不能逐字符落盘')
|
|
186
|
+
// 预览行必须跟快照重取:只挂 tick 时重取与写盘并发,拿到的是写前快照
|
|
187
|
+
assert.match(src, /\}, \[tick, storedSig\]\)/, '目录重取要同时跟 tick 与快照签名')
|
|
188
|
+
assert.match(src, /rows\.length >= maxChain/, '添加按钮到链长上限要禁用')
|
|
189
|
+
assert.match(src, /const move = \(index, delta\) =>/, '行序必须能在面板调(降级链语义就是顺序)')
|
|
190
|
+
assert.match(src, /chainRowsOf\(props\.ops\)/, '行初值必须从已存配置回显,不能从空表开始')
|
|
191
|
+
assert.ok(!src.includes('setOpsFallbackNote'), '「fallbacks 只能改 yml」的旧说法必须从文案里消失')
|
|
192
|
+
// v0.8.3 真机反馈:用户滚遍设置页后判定「没有主+fallback」——实为卡片默认折叠把编辑器藏了。
|
|
193
|
+
// SettingsCard 的默认值是 `defaultOpen !== false`,即省略才展开;这里钉住不得再写 false。
|
|
194
|
+
assert.match(src, /title: t\('setOpsGroup'\), badge: t\('setOpsBadge'\), hint: t\('setOpsHint'\) \}/, '路由链卡必须默认展开(省略 defaultOpen)')
|
|
195
|
+
assert.ok(!/setOpsGroup'[^}]*defaultOpen: false/.test(src), 'ops 卡不得再默认折叠,主+fallback 要一眼可见')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* v0.8.4 真机回灌:取消折叠只是第一步——卡仍在第 4 张,不滚就看不到;
|
|
200
|
+
* 而 provider 输入框的占位符写的是宿主并不存在的 `local-35b`,用户会把
|
|
201
|
+
* 灰色占位当已存值(本轮我就误判过一次),而 registered + 空 provider
|
|
202
|
+
* 会让 assistantReady() 直接返回 false,观察者静默不跑。
|
|
203
|
+
*/
|
|
204
|
+
test('设置页:路由链卡排第一,且占位符不误导、未填全要给警示', () => {
|
|
205
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
206
|
+
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
207
|
+
const iOps = src.indexOf("title: t('setOpsGroup')")
|
|
208
|
+
const iLlm = src.indexOf("title: t('setLlmGroup')")
|
|
209
|
+
const iObs = src.indexOf("title: t('setObserverGroup')")
|
|
210
|
+
assert.ok(iOps > 0 && iOps < iLlm && iLlm < iObs, `渲染顺序必须是 ops→LLM→观察者(实得 ops=${iOps} llm=${iLlm} obs=${iObs})`)
|
|
211
|
+
assert.ok(!src.includes("'local-35b'"), 'provider 占位符不得写宿主不存在的 local-35b')
|
|
212
|
+
assert.match(src, /textInput\('assistant', 'provider', '', 'local-35'\)/, '占位符要用宿主真实注册键 local-35')
|
|
213
|
+
assert.match(src, /mode === 'registered' && \(!String\(readField\('assistant', 'provider', ''\)\)\.trim\(\)/, 'registered 但 provider/model 未填全时必须给警示行')
|
|
214
|
+
assert.match(src, /className: 'dsu-warn-line'/, '警示行要有独立样式(沿用既有琥珀档位,不发明令牌)')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* v0.9.0 真机反馈:换 provider 后 model 仍是上一个 provider 的值,配出
|
|
219
|
+
* provider/model 错配串(调用必失败)。写面闸:provider 的 onChange 不得再走
|
|
220
|
+
* 单字段 patchRow,必须走会同时处理 model 的 pickProviderRow。
|
|
221
|
+
*/
|
|
222
|
+
test('链编辑器:换 provider 必须同时处理 model(预填或清空,不得留旧值)', () => {
|
|
223
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
224
|
+
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
225
|
+
assert.ok(!/patchRow\(index, 'provider'/.test(src), "provider 切换不得再走单字段 patchRow(会留下上一个 provider 的 model)")
|
|
226
|
+
assert.match(src, /onChange: \(e\) => pickProviderRow\(index, e\.target\.value\)/, 'provider 下拉必须走 pickProviderRow')
|
|
227
|
+
assert.match(src, /const pickProviderRow = \(index, value\) => \{[\s\S]{0,400}?model: nextModel/, 'pickProviderRow 必须同时写 model')
|
|
228
|
+
assert.match(src, /held && list\.some\(\(m\) => m\.id === held\) \? held : \(list\.length \? list\[0\]\.id : ''\)/, '保留条件:新 provider 清单里有则留,否则预填第一个,拿不到清单则清空')
|
|
229
|
+
assert.match(src, /const models = modelsOf\(row\.provider\)/, '行内模型清单与预填逻辑共用同一个源,不能两套口径')
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* v0.7.7 真机回灌:0.7.6 修好写面后,页脚出现「已保存」与「有未保存的改动」并存
|
|
234
|
+
* —— 开关拨完即落盘,但乐观草稿仍按「键存在」计脏。脏位必须按值比对。
|
|
235
|
+
*/
|
|
236
|
+
test('设置卡:拨完即落盘的开关不再留脏(脏位按值比对)', () => {
|
|
237
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
238
|
+
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
239
|
+
assert.match(src, /const dirtyKeys = \(group\) => \{\s*const bucket = buckets\[group\] \|\| \{\}/, 'dirtyKeys 需要拿存储桶做值比对')
|
|
240
|
+
assert.match(src, /\.filter\(\(key\) => draft\[group\]\[key\] !== bucket\[key\]\)/, '脏键必须按「草稿值 ≠ 存值」过滤')
|
|
241
|
+
assert.match(src, /const scalarDirty = \(key\) => Object\.prototype\.hasOwnProperty\.call\(draft, key\) && draft\[key\] !== value\[key\]/, '顶层标量同样按值判脏')
|
|
242
|
+
assert.match(src, /scalarDirty\('todoSync'\) \|\| scalarDirty\('notifyMajorChanges'\)/, 'hasDirty 不得再用「键存在即脏」')
|
|
243
|
+
assert.ok(!src.includes('const dirtyKeys = (group) => Object.keys(draft[group] || {})'), '旧的按键存在判脏必须移除')
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('ops 块开关位定期重探,不钉在首帧(热生效无需重挂载)', () => {
|
|
247
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
248
|
+
const src = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n')
|
|
249
|
+
assert.match(src, /const OPS_POLL_MS = \d+/, '需要有重探间隔常量')
|
|
250
|
+
assert.match(src, /setInterval\(probe, OPS_POLL_MS\)/, '必须真的定时重探 providers 面')
|
|
251
|
+
assert.match(src, /if \(data\.disabled\) \{[\s\S]{0,80}?setOff\(true\)[\s\S]{0,40}?return[\s\S]{0,120}?setOff\(false\)/, '关掉要隐块,改回开要自动复现(不能只置 true)')
|
|
252
|
+
assert.match(src, /if \(primed\.current\) return/, '默认 provider/model 只在首次回填,不覆用户手选')
|
|
253
|
+
assert.match(src, /clearInterval\(timer\)/, '卸载必须收定时器')
|
|
254
254
|
})
|