dsh-progress-union 0.5.2 → 0.5.5-rc.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.
@@ -1,171 +1,171 @@
1
- /**
2
- * Phase 7 验收:观察者(辅助观察最近输出/清单;板滞后及时补与催办)。
3
- */
4
- import assert from 'node:assert/strict'
5
- import fs from 'node:fs'
6
- import os from 'node:os'
7
- import path from 'node:path'
8
- import test from 'node:test'
9
-
10
- process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
11
- const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
12
-
13
- async function booted() {
14
- const harness = createHarness()
15
- await harness.run()
16
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
17
- return harness
18
- }
19
-
20
- function execUpdate(harness, args) {
21
- return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
22
- }
23
-
24
- function observerText(harness) {
25
- const fn = harness.contexts.get('progress-union-observer')
26
- assert.ok(fn, 'progress-union-observer 上下文必须注册')
27
- return fn()
28
- }
29
-
30
- test('观察块:清单标记 + 最近输出 + 最近动作 + 官方 todo 行', async () => {
31
- const harness = await booted()
32
- await execUpdate(harness, {
33
- changes: [
34
- { title: '接口改造', status: 'done' },
35
- { title: '补集成测试', status: 'doing', current: '写 observer 用例', next: '跑全量' },
36
- { title: '发版', status: 'todo' },
37
- ],
38
- })
39
- harness.emit('assistant/message', { message: { content: [{ type: 'text', text: '接口改造已完成,接下来补测试。' }] } })
40
- harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'npm test' }) })
41
- harness.emit('todo/write', { todos: [
42
- { content: '接口改造', status: 'completed' },
43
- { content: '补集成测试', status: 'in_progress' },
44
- { content: '发版', status: 'pending' },
45
- ] })
46
-
47
- const text = observerText(harness)
48
- assert.match(text, /<progress-observer revision="1"/)
49
- assert.match(text, /\[x\] 接口改造/)
50
- assert.match(text, /\[~\] 补集成测试(0%) · 当前:写 observer 用例 · 下一步:跑全量/)
51
- assert.match(text, /\[ \] 发版/)
52
- assert.match(text, /最近输出:「接口改造已完成,接下来补测试。/)
53
- assert.match(text, /最近动作:Bash/)
54
- assert.match(text, /\[官方todo\] 完成 1\/3,未完:补集成测试、发版/)
55
- assert.doesNotMatch(text, /滞后/, '未超阈值不得催办')
56
- })
57
-
58
- test('滞后刚需:超 N 步未写板 → 催办出现;模型写板后消失', async () => {
59
- const harness = await booted()
60
- await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'doing' }] })
61
- for (let i = 0; i < 6; i++) harness.emit('step/start', {})
62
- const text = observerText(harness)
63
- assert.match(text, /⚠ 进度已滞后(6 步前)/)
64
- assert.match(text, /先调用 progress_update 同步再继续/)
65
-
66
- // 模型自己同步(无变化确认也算)→ 催办消失
67
- await execUpdate(harness, { changes: [] })
68
- assert.doesNotMatch(observerText(harness), /滞后/)
69
- })
70
-
71
- test('观察者自动补 current:事实性最近动作写入 doing 项(updatedBy=observer),不抵消催办', async () => {
72
- const harness = await booted()
73
- const added = await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
74
- const itemId = added.changed[0].id
75
- harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render --frames 900' }) })
76
- for (let i = 0; i < 6; i++) harness.emit('step/start', {})
77
- await flush()
78
-
79
- const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
80
- const item = snap.items.find((x) => x.id === itemId)
81
- assert.match(item.current, /^自动同步:Bash · command=render --frames 900/)
82
- assert.equal(item.updatedBy, 'observer')
83
- assert.equal(item.status, 'doing', '观察者不得改状态')
84
- assert.ok(snap.revision >= 2)
85
-
86
- // 自动补不重置\"模型同步\"计数:催办仍在(状态/百分比仍需模型确认)
87
- assert.match(observerText(harness), /⚠ 进度已滞后/)
88
- })
89
-
90
- test('progress_update 拉通道:返回 inFlight 明细 + time 字段', async () => {
91
- const harness = await booted()
92
- const r = await execUpdate(harness, {
93
- changes: [
94
- { title: '甲', status: 'done' },
95
- { title: '乙', status: 'doing', current: '做乙', next: '做丙' },
96
- { title: '丙', status: 'blocked', note: '等确认' },
97
- ],
98
- })
99
- assert.equal(r.inFlight.length, 2)
100
- assert.deepEqual(r.inFlight.map((x) => x.status), ['doing', 'blocked'])
101
- assert.equal(typeof r.time.etaBasis, 'string')
102
- assert.equal(typeof r.time.steps, 'number')
103
- assert.equal(typeof r.time.staleMin, 'number')
104
- })
105
-
106
- test('最近改动:带路径的工具调用入块,同路径去重、只留最近 4 个', async () => {
107
- const harness = await booted()
108
- await execUpdate(harness, { changes: [{ title: '改代码', status: 'doing' }] })
109
- const call = (file, tool = 'Edit') => harness.emit('tool/call', { name: tool, arguments: JSON.stringify({ file_path: file }) })
110
- call('E:\\proj\\src\\a.ts')
111
- call('E:\\proj\\src\\b.ts', 'Write')
112
- call('E:\\proj\\src\\a.ts') // 同路径去重,留最新
113
- call('E:\\proj\\src\\c.ts')
114
- call('E:\\proj\\src\\d.ts')
115
- call('E:\\proj\\src\\e.ts')
116
-
117
- const text = observerText(harness)
118
- const line = text.split('\n').find((l) => l.startsWith('最近改动:'))
119
- assert.ok(line, '最近改动行必须存在')
120
- assert.equal((line.match(/(/g) || []).length, 4, '最多 4 条')
121
- assert.doesNotMatch(line, /b\.ts/, '被后 4 条挤出(上限保留最近)')
122
- assert.match(line, /a\.ts(Edit)/, '同路径重写后保留最新一条')
123
- assert.equal((line.match(/a\.ts/g) || []).length, 1, '同路径只出现一次(去重)')
124
- })
125
-
126
- test('清单对比:todo 与板完成数漂移才出对比行(算术,非语义)', async () => {
127
- const harness = await booted()
128
- await execUpdate(harness, {
129
- changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }, { title: '丙', status: 'todo' }],
130
- })
131
- harness.emit('todo/write', { todos: [
132
- { content: '甲', status: 'completed' },
133
- { content: '乙', status: 'completed' },
134
- { content: '丙', status: 'pending' },
135
- ] })
136
- const drifted = observerText(harness)
137
- assert.match(drifted, /对比:官方 todo 完成 2\/3 · 板完成 1\/3(进度不一致/)
138
-
139
- // 对齐后不再出对比行
140
- await execUpdate(harness, { changes: [{ title: '乙', status: 'done' }] })
141
- assert.doesNotMatch(observerText(harness), /对比:/)
142
- })
143
-
144
- test('观察者自补的 current 在块里标注待确认', async () => {
145
- const harness = await booted()
146
- await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
147
- harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render' }) })
148
- for (let i = 0; i < 6; i++) harness.emit('step/start', {})
149
- await flush()
150
- assert.match(observerText(harness), /当前:自动同步:Bash · command=render(观察者补,待确认)/)
151
- })
152
-
153
- test('门控:关板/全完成/空板时观察块为空(0 token)', async () => {
154
- const harness = createHarness()
155
- await harness.run()
156
- assert.equal(observerText(harness), '', '未启用不得注入')
157
-
158
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
159
- assert.equal(observerText(harness), '', '空板不注入(kickoff 负责)')
160
-
161
- await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
162
- assert.equal(observerText(harness), '', '全完成不打扰')
163
- })
164
-
165
- test('可关:observer.enabled=false 时零注入', async () => {
166
- const harness = createHarness({ config: { observer: { enabled: false } } })
167
- await harness.run()
168
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
169
- await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
170
- assert.equal(observerText(harness), '')
1
+ /**
2
+ * Phase 7 验收:观察者(辅助观察最近输出/清单;板滞后及时补与催办)。
3
+ */
4
+ import assert from 'node:assert/strict'
5
+ import fs from 'node:fs'
6
+ import os from 'node:os'
7
+ import path from 'node:path'
8
+ import test from 'node:test'
9
+
10
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
11
+ const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
12
+
13
+ async function booted() {
14
+ const harness = createHarness()
15
+ await harness.run()
16
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
17
+ return harness
18
+ }
19
+
20
+ function execUpdate(harness, args) {
21
+ return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
22
+ }
23
+
24
+ function observerText(harness) {
25
+ const fn = harness.contexts.get('progress-union-observer')
26
+ assert.ok(fn, 'progress-union-observer 上下文必须注册')
27
+ return fn()
28
+ }
29
+
30
+ test('观察块:清单标记 + 最近输出 + 最近动作 + 官方 todo 行', async () => {
31
+ const harness = await booted()
32
+ await execUpdate(harness, {
33
+ changes: [
34
+ { title: '接口改造', status: 'done' },
35
+ { title: '补集成测试', status: 'doing', current: '写 observer 用例', next: '跑全量' },
36
+ { title: '发版', status: 'todo' },
37
+ ],
38
+ })
39
+ harness.emit('assistant/message', { message: { content: [{ type: 'text', text: '接口改造已完成,接下来补测试。' }] } })
40
+ harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'npm test' }) })
41
+ harness.emit('todo/write', { todos: [
42
+ { content: '接口改造', status: 'completed' },
43
+ { content: '补集成测试', status: 'in_progress' },
44
+ { content: '发版', status: 'pending' },
45
+ ] })
46
+
47
+ const text = observerText(harness)
48
+ assert.match(text, /<progress-observer revision="1"/)
49
+ assert.match(text, /\[x\] 接口改造/)
50
+ assert.match(text, /\[~\] 补集成测试(0%) · 当前:写 observer 用例 · 下一步:跑全量/)
51
+ assert.match(text, /\[ \] 发版/)
52
+ assert.match(text, /最近输出:「接口改造已完成,接下来补测试。/)
53
+ assert.match(text, /最近动作:Bash/)
54
+ assert.match(text, /\[官方todo\] 完成 1\/3,未完:补集成测试、发版/)
55
+ assert.doesNotMatch(text, /滞后/, '未超阈值不得催办')
56
+ })
57
+
58
+ test('滞后刚需:超 N 步未写板 → 催办出现;模型写板后消失', async () => {
59
+ const harness = await booted()
60
+ await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'doing' }] })
61
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
62
+ const text = observerText(harness)
63
+ assert.match(text, /⚠ 进度已滞后(6 步前)/)
64
+ assert.match(text, /先调用 progress_update 同步再继续/)
65
+
66
+ // 模型自己同步(无变化确认也算)→ 催办消失
67
+ await execUpdate(harness, { changes: [] })
68
+ assert.doesNotMatch(observerText(harness), /滞后/)
69
+ })
70
+
71
+ test('观察者自动补 current:事实性最近动作写入 doing 项(updatedBy=observer),不抵消催办', async () => {
72
+ const harness = await booted()
73
+ const added = await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
74
+ const itemId = added.changed[0].id
75
+ harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render --frames 900' }) })
76
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
77
+ await flush()
78
+
79
+ const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
80
+ const item = snap.items.find((x) => x.id === itemId)
81
+ assert.match(item.current, /^自动同步:Bash · command=render --frames 900/)
82
+ assert.equal(item.updatedBy, 'observer')
83
+ assert.equal(item.status, 'doing', '观察者不得改状态')
84
+ assert.ok(snap.revision >= 2)
85
+
86
+ // 自动补不重置\"模型同步\"计数:催办仍在(状态/百分比仍需模型确认)
87
+ assert.match(observerText(harness), /⚠ 进度已滞后/)
88
+ })
89
+
90
+ test('progress_update 拉通道:返回 inFlight 明细 + time 字段', async () => {
91
+ const harness = await booted()
92
+ const r = await execUpdate(harness, {
93
+ changes: [
94
+ { title: '甲', status: 'done' },
95
+ { title: '乙', status: 'doing', current: '做乙', next: '做丙' },
96
+ { title: '丙', status: 'blocked', note: '等确认' },
97
+ ],
98
+ })
99
+ assert.equal(r.inFlight.length, 2)
100
+ assert.deepEqual(r.inFlight.map((x) => x.status), ['doing', 'blocked'])
101
+ assert.equal(typeof r.time.etaBasis, 'string')
102
+ assert.equal(typeof r.time.steps, 'number')
103
+ assert.equal(typeof r.time.staleMin, 'number')
104
+ })
105
+
106
+ test('最近改动:带路径的工具调用入块,同路径去重、只留最近 4 个', async () => {
107
+ const harness = await booted()
108
+ await execUpdate(harness, { changes: [{ title: '改代码', status: 'doing' }] })
109
+ const call = (file, tool = 'Edit') => harness.emit('tool/call', { name: tool, arguments: JSON.stringify({ file_path: file }) })
110
+ call('E:\\proj\\src\\a.ts')
111
+ call('E:\\proj\\src\\b.ts', 'Write')
112
+ call('E:\\proj\\src\\a.ts') // 同路径去重,留最新
113
+ call('E:\\proj\\src\\c.ts')
114
+ call('E:\\proj\\src\\d.ts')
115
+ call('E:\\proj\\src\\e.ts')
116
+
117
+ const text = observerText(harness)
118
+ const line = text.split('\n').find((l) => l.startsWith('最近改动:'))
119
+ assert.ok(line, '最近改动行必须存在')
120
+ assert.equal((line.match(/(/g) || []).length, 4, '最多 4 条')
121
+ assert.doesNotMatch(line, /b\.ts/, '被后 4 条挤出(上限保留最近)')
122
+ assert.match(line, /a\.ts(Edit)/, '同路径重写后保留最新一条')
123
+ assert.equal((line.match(/a\.ts/g) || []).length, 1, '同路径只出现一次(去重)')
124
+ })
125
+
126
+ test('清单对比:todo 与板完成数漂移才出对比行(算术,非语义)', async () => {
127
+ const harness = await booted()
128
+ await execUpdate(harness, {
129
+ changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }, { title: '丙', status: 'todo' }],
130
+ })
131
+ harness.emit('todo/write', { todos: [
132
+ { content: '甲', status: 'completed' },
133
+ { content: '乙', status: 'completed' },
134
+ { content: '丙', status: 'pending' },
135
+ ] })
136
+ const drifted = observerText(harness)
137
+ assert.match(drifted, /对比:官方 todo 完成 2\/3 · 板完成 1\/3(进度不一致/)
138
+
139
+ // 对齐后不再出对比行
140
+ await execUpdate(harness, { changes: [{ title: '乙', status: 'done' }] })
141
+ assert.doesNotMatch(observerText(harness), /对比:/)
142
+ })
143
+
144
+ test('观察者自补的 current 在块里标注待确认', async () => {
145
+ const harness = await booted()
146
+ await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
147
+ harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render' }) })
148
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
149
+ await flush()
150
+ assert.match(observerText(harness), /当前:自动同步:Bash · command=render(观察者补,待确认)/)
151
+ })
152
+
153
+ test('门控:关板/全完成/空板时观察块为空(0 token)', async () => {
154
+ const harness = createHarness()
155
+ await harness.run()
156
+ assert.equal(observerText(harness), '', '未启用不得注入')
157
+
158
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
159
+ assert.equal(observerText(harness), '', '空板不注入(kickoff 负责)')
160
+
161
+ await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
162
+ assert.equal(observerText(harness), '', '全完成不打扰')
163
+ })
164
+
165
+ test('可关:observer.enabled=false 时零注入', async () => {
166
+ const harness = createHarness({ config: { observer: { enabled: false } } })
167
+ await harness.run()
168
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
169
+ await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
170
+ assert.equal(observerText(harness), '')
171
171
  })
@@ -1,82 +1,82 @@
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
- ]
55
- for (const key of expected) {
56
- assert.ok(key in leaves, `缺少配置键 ${key}`)
57
- assert.equal(leaves[key], true, `${key} 必须是叶子级 .volatile()`)
58
- }
59
- })
60
-
61
- test('Config:外层对象不得自己标 volatile(嵌套 volatile 会被宿主拒绝)', () => {
62
- for (const key of ['assistant', 'observer', 'todo']) {
63
- const node = (Config.dict || Config.inner || {})[key]
64
- assert.ok(node, `缺少 ${key} 节点`)
65
- assert.equal((node.meta || {}).volatile, undefined, `${key} 这层不能标 volatile`)
66
- }
67
- })
68
-
69
- test('客户端:设置卡双座位(settings.section + plugins.bundle.config)且走 configForms 句柄', () => {
70
- // fileURLToPath:跨平台取文件路径。`new URL(...).pathname` 在 Linux 上会被
71
- // `.replace(/^[/]/,'')` 误伤成相对路径(CI 上 ENOENT,本地 Windows 永不暴露)。
72
- const file = fileURLToPath(new URL('../client.js', import.meta.url))
73
- const src = fs.readFileSync(file, 'utf8')
74
- assert.match(src, /registerSettingsSeat\('settings\.section'/, '必须注册 settings.section 槽')
75
- assert.match(src, /id: 'dsh-progress-union'/, '分节 id 必须固定')
76
- assert.match(src, /registerSettingsSeat\('plugins\.bundle\.config'/, 'bundle 详情页也要有配置卡(keyed by 包名)')
77
- assert.match(src, /key: 'dsh-progress-union'/, 'bundle 座位 key 必须是包名')
78
- assert.match(src, /configForms/, '必须经宿主 configForms 读写配置')
79
- assert.match(src, /function ProgressUnionSettings\(/, '设置卡组件必须在')
80
- assert.match(src, /scope\.subscribe/, '设置卡要订阅句柄快照')
81
- assert.match(src, /function ensureUnionSettingsStyle\(/, '样式要注入 document.head,否则设置页里裸奔')
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
+ ]
55
+ for (const key of expected) {
56
+ assert.ok(key in leaves, `缺少配置键 ${key}`)
57
+ assert.equal(leaves[key], true, `${key} 必须是叶子级 .volatile()`)
58
+ }
59
+ })
60
+
61
+ test('Config:外层对象不得自己标 volatile(嵌套 volatile 会被宿主拒绝)', () => {
62
+ for (const key of ['assistant', 'observer', 'todo']) {
63
+ const node = (Config.dict || Config.inner || {})[key]
64
+ assert.ok(node, `缺少 ${key} 节点`)
65
+ assert.equal((node.meta || {}).volatile, undefined, `${key} 这层不能标 volatile`)
66
+ }
67
+ })
68
+
69
+ test('客户端:设置卡双座位(settings.section + plugins.bundle.config)且走 configForms 句柄', () => {
70
+ // fileURLToPath:跨平台取文件路径。`new URL(...).pathname` 在 Linux 上会被
71
+ // `.replace(/^[/]/,'')` 误伤成相对路径(CI 上 ENOENT,本地 Windows 永不暴露)。
72
+ const file = fileURLToPath(new URL('../client.js', import.meta.url))
73
+ const src = fs.readFileSync(file, 'utf8')
74
+ assert.match(src, /registerSettingsSeat\('settings\.section'/, '必须注册 settings.section 槽')
75
+ assert.match(src, /id: 'dsh-progress-union'/, '分节 id 必须固定')
76
+ assert.match(src, /registerSettingsSeat\('plugins\.bundle\.config'/, 'bundle 详情页也要有配置卡(keyed by 包名)')
77
+ assert.match(src, /key: 'dsh-progress-union'/, 'bundle 座位 key 必须是包名')
78
+ assert.match(src, /configForms/, '必须经宿主 configForms 读写配置')
79
+ assert.match(src, /function ProgressUnionSettings\(/, '设置卡组件必须在')
80
+ assert.match(src, /scope\.subscribe/, '设置卡要订阅句柄快照')
81
+ assert.match(src, /function ensureUnionSettingsStyle\(/, '样式要注入 document.head,否则设置页里裸奔')
82
82
  })