dsh-progress-union 0.6.3 → 0.7.0-rc.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.
@@ -1,190 +1,274 @@
1
- /**
2
- * Phase 4 验收:client 契约守卫。
3
- * 1) 客户端文件不得残留 board 旧命名空间/旧 API 调用(fork 改造回归);
4
- * 2) 客户端消费的两条路由形状(snapshot / status)由宿主实测钉住。
5
- */
6
- import assert from 'node:assert/strict'
7
- import fs from 'node:fs'
8
- import os from 'node:os'
9
- import path from 'node:path'
10
- import test from 'node:test'
11
-
12
- import { fileURLToPath } from 'node:url'
13
-
14
- process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
15
- const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
16
-
17
- // 必须用 fileURLToPath:`new URL(...).pathname` 在 Windows 得到 `/E:/...`(需去前导斜杠),
18
- // 但 Linux 的 `/` 是根目录,`.replace(/^[/]/,'')` 会把它变成相对路径 → CI 上 ENOENT。
19
- const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
20
- const packageFile = fileURLToPath(new URL('../package.json', import.meta.url))
21
-
22
- test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
23
- const src = fs.readFileSync(clientFile, 'utf8')
24
- assert.match(src, /id: 'dsh-progress-union'/)
25
- assert.match(src, /const API = '\/progress-union'/)
26
- assert.match(src, /STATUS_API = '\/dsh-progress\/status'/)
27
- assert.doesNotMatch(src, /fetch\(`\/progress-board/, '不得残留旧 API 前缀的直接调用')
28
- assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
29
- })
30
-
31
- test('迷你条暂停/继续按钮接线齐全(渲染 + 请求 + 状态门控)', () => {
32
- const src = fs.readFileSync(clientFile, 'utf8')
33
- // 渲染:两个按钮都在 dock actions 区
34
- assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-pause'/, '暂停按钮必须在')
35
- assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-resume'/, '继续按钮必须在')
36
- // 请求面:走 /progress-union/goal 控制路由
37
- assert.match(src, /fetch\(`\$\{API\}\/goal`/, '必须调用目标控制路由')
38
- assert.match(src, /action: 'pause'|onGoalControl\('pause'\)/, '暂停必须接线')
39
- assert.match(src, /onGoalControl\('resume'\)/, '继续必须接线')
40
- // 门控:只有目标 active 才给暂停,只有 paused/blocked 才给继续
41
- assert.match(src, /goalActive = goalPhase === 'active'/, '暂停按钮必须按 phase 门控')
42
- assert.match(src, /goalStopped = goalPhase === 'paused' \|\| goalPhase === 'blocked'/, '继续按钮必须按 phase 门控')
43
- // 按钮样式必须真的存在(否则是裸浏览器按钮):背景=主色实心,前景=宿主 on-color 令牌。
44
- assert.match(src, /\.pb-dock-goal-resume \{[^}]*background: var\(--dsw-alias-brand-primary\)/, '继续按钮需要有主色实心样式')
45
- assert.match(src, /\.pb-dock-goal-resume \{[^}]*color: var\(--dsw-alias-label-on-color/, '继续按钮前景必须用 on-color 令牌')
46
- })
47
-
48
- test('主色实心按钮的前景色不得用 bg-base(玻璃皮肤会把它设成 transparent)', () => {
49
- const src = fs.readFileSync(clientFile, 'utf8')
50
- // 事故:maid-atelier 皮肤在 body 上把 --dsw-alias-bg-base 设为 transparent,
51
- // 拿它当 color 会让「继续」渲染成透明字 → 看着像一块纯色块盖住了按钮。
52
- assert.doesNotMatch(src, /color:\s*var\(--dsw-alias-bg-base/, '--dsw-alias-bg-base 是页面底色语义,不能当前景色')
53
- assert.match(src, /\.pb-btn-primary \{[^}]*color: var\(--dsw-alias-label-on-color/, '主按钮前景必须用 on-color 令牌')
54
- // 选择态底板同样不能用 bg-base(透明后选中段会"消失")。
55
- assert.doesNotMatch(src, /\[data-on="true"\] \{[^}]*background: var\(--dsw-alias-bg-base/, '分段控件选中态不得用 bg-base 做底板')
56
- })
57
-
58
- test('目标文案区分「板目标」与宿主 goal,完成态不报时间面', () => {
59
- const src = fs.readFileSync(clientFile, 'utf8')
60
- // 官方 GoalBar 与 /progress-goal 是两套状态机,并排在同一 input dock:文案必须能分辨。
61
- assert.match(src, /goalPaused: '板目标已暂停'/, 'zh 文案需带「板目标」前缀')
62
- assert.match(src, /goalPaused: 'Board goal paused'/, 'en 文案需带 Board goal 前缀')
63
- assert.match(src, /独立于宿主的 \/goal/, '悬停提示需说明与宿主 /goal 的关系')
64
- assert.match(src, /const allDone = summary\.total > 0 && summary\.done === summary\.total/, '完成态需跳过时间面')
65
- })
66
-
67
- test('W1: 头部入口注册仍在,且带渲染兜底与分面隔离', () => {
68
- // 仓内文件是 CRLF:多行断言前先归一,否则 \n 永远匹配不到 \r\n。
69
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
70
- // 入口本体:槽位 + id + 顺序(5 = 排在宿主自带入口之后、其余插件之前,窄窗口不会被裁掉)
71
- assert.match(src, /name: 'conversation\.session\.header\.utilities'/, '头部工具区槽位注册必须在')
72
- assert.match(src, /id: 'progress-union-header'/, '头部入口 id 必须在')
73
- assert.match(src, /order: 5,/, '头部入口顺序必须提前到 5')
74
- // 渲染兜底:组件抛错只让这一枚消失,不拖垮整排 utilities
75
- assert.match(src, /class HeaderEntryBoundary extends React\.Component/, '头部入口必须有错误边界')
76
- assert.match(src, /getDerivedStateFromError/, '错误边界必须真的降级渲染')
77
- assert.match(src, /function ProgressHeaderButton\(props\) \{\n return h\(HeaderEntryBoundary/, '导出组件必须包在错误边界里')
78
- // 分面隔离:任一入口注册失败不得中止 apply(否则图标/迷你条/右栏页签一起消失)
79
- assert.match(src, /const safeEffect = \(label, register\) =>/, '必须有分面隔离助手')
80
- const safeCalls = src.match(/^\s+safeEffect\($/gm) || []
81
- assert.equal(safeCalls.length, 6, '六个入口面(设置×2 / 右栏类型 / 右栏面板 / 头部 / 迷你条)都必须经 safeEffect 注册')
82
- const bare = src.match(/ctx\.effect\(\s*\n\s*\(\) =>\s*\n\s*ctx\.(slots|sidebarRightTabs)/g) || []
83
- assert.equal(bare.length, 0, '不得残留裸 ctx.effect 入口注册')
84
- })
85
-
86
- test('W2: better-sidebar 页签是独立入口,内容仍是自有板子', () => {
87
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
88
- assert.match(src, /const BS_TAB_ID = 'dsh-progress-union:board'/, 'better-sidebar 页签 id 必须在')
89
- assert.doesNotMatch(src, /const BS_TAB_ID = 'progress-union'|const BS_TAB_ID = 'dsh-progress-union'\n/, '页签 id 不得与原生 kind 混用')
90
- // 服务可能晚于 apply 就绪 → 必须 deferred inject,不能一次性 ctx.get
91
- assert.match(src, /ctx\.inject\(\['betterSidebar'\], \(bs\) => \{/, '必须用 deferred inject 等待 betterSidebar')
92
- assert.match(src, /typeof service\.registerTab !== 'function'/, '调用前必须探测 registerTab')
93
- // 描述符字段齐全
94
- assert.match(src, /id: BS_TAB_ID,/)
95
- assert.match(src, /title: \(\) => t\('nav'\),/)
96
- assert.match(src, /description: \(\) => t\('bsDesc'\),/)
97
- assert.match(src, /icon: \(size\) => h\(ProgressNavIcon, \{ size: size \|\| 16 \}\)/)
98
- assert.match(src, /order: 120,/)
99
- assert.match(src, /single: true,/)
100
- // 内容是自有板子,且拿到当前会话
101
- assert.match(src, /h\(ProgressSidePanel, \{/, '页签正文必须是自有 ProgressSidePanel')
102
- assert.match(src, /sessionId: tabProps && tabProps\.scope \? tabProps\.scope\.sessionId : undefined/)
103
- // 不传 collapse / toggleFullscreen,避免 better-sidebar 里出现死按钮
104
- const block = src.slice(src.indexOf("ctx.inject(['betterSidebar']"), src.indexOf("'progress-union: better-sidebar tab'"))
105
- assert.doesNotMatch(block, /collapse:/, '不得向 better-sidebar 页签传 collapse')
106
- assert.doesNotMatch(block, /toggleFullscreen:/, '不得向 better-sidebar 页签传 toggleFullscreen')
107
- // 明确不复用 better-sidebar 的「任务管理」
108
- assert.doesNotMatch(block, /task.?manage|subagent|后台命令/iu, '不得复用 better-sidebar 的任务管理视图')
109
- })
110
-
111
- test('W2: better-sidebar 只是软依赖(未装者必须照常加载)', () => {
112
- const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'))
113
- const declared = pkg.dsh?.client?.inject ?? []
114
- assert.equal(declared.includes('dsh-better-sidebar'), false, 'dsh.client.inject 不得声明 dsh-better-sidebar')
115
- assert.equal('dsh-better-sidebar' in (pkg.dependencies ?? {}), false, 'dependencies 不得声明 dsh-better-sidebar')
116
- })
117
-
118
- test('S2: bsDesc 在 zh/en 两个字典里都存在', () => {
119
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
120
- assert.match(src, /bsDesc: '任务串联的进度板(不是 better-sidebar 的「任务管理」)'/, 'zh 文案必须在')
121
- assert.match(src, /bsDesc: 'Linked-task progress board \(not better-sidebar task manager\)'/, 'en 文案必须在')
122
- })
123
-
124
- test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
125
- const harness = createHarness()
126
- await harness.run()
127
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
128
- await harness.toolMap.get('progress_update').definition.execute(
129
- { changes: [{ title: '渲染截图', status: 'doing', current: '渲染第 7/24 张' }, { title: '合成音轨' }] },
130
- { agent: harness.agent },
131
- )
132
- harness.emit('turn/start', {})
133
- harness.emit('step/start', {})
134
-
135
- const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
136
- assert.equal(snap.ok, true)
137
- assert.equal(snap.enabled, true)
138
- assert.deepEqual(snap.items.map((i) => i.title), ['渲染截图', '合成音轨'])
139
- assert.equal(typeof snap.summary.percent, 'number')
140
- assert.equal('pendingUserChanges' in snap, true)
141
-
142
- const status = (await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })).json()
143
- assert.equal(status.ok, true)
144
- assert.equal(status.config.pollMs, 1000)
145
- assert.ok(status.task, 'status.task 必须存在(迷你条数据源)')
146
- assert.equal(String(status.task.id), String(SESSION))
147
- // 板开:阶段直接取板 items,不再走关键词猜测
148
- assert.deepEqual(status.task.stages, ['渲染截图', '合成音轨'])
149
- assert.equal(status.task.boardDriven, true)
150
- assert.equal(status.task.current, 0)
151
- assert.ok(Array.isArray(status.tasks))
152
- })
153
-
154
- test('W3: 板只住在右侧边栏——不再注册主区完整面板', () => {
155
- // 事故:主区面板没有收拢入口,点进去就回不到会话(进去出不来)。
156
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
157
- assert.match(src, /const openPanel = \(\) => ctx\.sidebarRight\.openTab\(RIGHT_TAB_KIND\)/, '头部/迷你条入口必须打开右栏页签')
158
- assert.match(src, /inject: \(\) => \(\{ openPanel, togglePanel \}\)/, '头部入口注入的必须是右栏开关(可见则收起,不可见则打开)')
159
- assert.doesNotMatch(src, /ctx\.slots\.inject\('main'/, '不得再注册主区完整面板')
160
- assert.doesNotMatch(src, /layout\.selectPanel/, '不得再切主区面板')
161
- assert.doesNotMatch(src, /function ProgressPanel\(/, '完整面板组件应已移除')
162
- })
163
-
164
- test('W4: 侧栏顶部不再画自带的 全面展开/收起/完整面板 按钮(交给右栏 chrome)', () => {
165
- // 事故:三个按钮都在,但 toggleFullscreen / collapse 在右栏页签里根本没注入(better-sidebar 里更没处传),
166
- // 点了没反应才是常态。右栏自身的 chrome 已经有全屏与关闭,不再重复造。
167
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
168
- assert.doesNotMatch(src, /props\.toggleFullscreen/, '不得再渲染自带的全屏按钮')
169
- assert.doesNotMatch(src, /props\.collapse/, '不得再渲染自带的收起按钮')
170
- assert.doesNotMatch(src, /t\('sideFull'\)|t\('sideHalf'\)|t\('sideCollapse'\)/, '三个死按钮的文案不得残留')
171
- assert.doesNotMatch(src, /toggleFullscreen/, '注入面不得再传全屏切换')
172
- })
173
-
174
- test('0.6.2:面板来源行只在 snapshot.restoredFrom 存在时渲染', () => {
175
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
176
- assert.match(src, /\.pb-side-restore \{/, '来源行样式缺失')
177
- assert.match(src, /sideRestore: '已从归档 v\{seq\} · rev \{revision\} 恢复,共 \{n\} 项'/, 'zh 文案缺失')
178
- assert.match(src, /sideRestore: 'Restored from archive/, 'en 文案缺失')
179
- assert.match(src, /snapshot\?\.restoredFrom\s*\n?\s*\? h\(/, '渲染必须由 restoredFrom 门控')
180
- assert.match(src, /replace\('\{seq\}', String\(snapshot\.restoredFrom\.seq\)\)/, 'seq 未注入')
181
- })
182
-
183
- test('0.6.3:提示卡与用量条间距成体系,且不再出现负 margin', () => {
184
- const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
185
- assert.doesNotMatch(src, /margin:\s*-4px/, '不得再有负上边距(用量条顶进提示卡的根因)')
186
- assert.match(src, /\.pb-llm \{[^}]*margin: 10px 0 12px/, '.pb-llm 下边距必须 12px')
187
- assert.doesNotMatch(src, /\.pb-llm \{[^}]*margin: 10px 0 0[;}]/, '旧的 0 下边距必须消失')
188
- assert.match(src, /\.pb-side > \.pb-usage \{[^}]*margin: 0 0 12px/, '用量条上边距必须归零')
189
- assert.match(src, /\.pb-side > \.pb-llm \+ \.pb-side-error \{ margin-top: 12px; \}/, '同类块相邻补 12px')
190
- })
1
+ /**
2
+ * Phase 4 验收:client 契约守卫。
3
+ * 1) 客户端文件不得残留 board 旧命名空间/旧 API 调用(fork 改造回归);
4
+ * 2) 客户端消费的两条路由形状(snapshot / status)由宿主实测钉住。
5
+ */
6
+ import assert from 'node:assert/strict'
7
+ import fs from 'node:fs'
8
+ import os from 'node:os'
9
+ import path from 'node:path'
10
+ import test from 'node:test'
11
+
12
+ import { fileURLToPath } from 'node:url'
13
+
14
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
15
+ const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
16
+
17
+ // 必须用 fileURLToPath:`new URL(...).pathname` 在 Windows 得到 `/E:/...`(需去前导斜杠),
18
+ // 但 Linux 的 `/` 是根目录,`.replace(/^[/]/,'')` 会把它变成相对路径 → CI 上 ENOENT。
19
+ const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
20
+ const packageFile = fileURLToPath(new URL('../package.json', import.meta.url))
21
+
22
+ test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
23
+ const src = fs.readFileSync(clientFile, 'utf8')
24
+ assert.match(src, /id: 'dsh-progress-union'/)
25
+ assert.match(src, /const API = '\/progress-union'/)
26
+ assert.match(src, /STATUS_API = '\/dsh-progress\/status'/)
27
+ assert.doesNotMatch(src, /fetch\(`\/progress-board/, '不得残留旧 API 前缀的直接调用')
28
+ assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
29
+ })
30
+
31
+ test('迷你条暂停/继续按钮接线齐全(渲染 + 请求 + 状态门控)', () => {
32
+ const src = fs.readFileSync(clientFile, 'utf8')
33
+ // 渲染:两个按钮都在 dock actions 区
34
+ assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-pause'/, '暂停按钮必须在')
35
+ assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-resume'/, '继续按钮必须在')
36
+ // 请求面:走 /progress-union/goal 控制路由
37
+ assert.match(src, /fetch\(`\$\{API\}\/goal`/, '必须调用目标控制路由')
38
+ assert.match(src, /action: 'pause'|onGoalControl\('pause'\)/, '暂停必须接线')
39
+ assert.match(src, /onGoalControl\('resume'\)/, '继续必须接线')
40
+ // 门控:只有目标 active 才给暂停,只有 paused/blocked 才给继续
41
+ assert.match(src, /goalActive = goalPhase === 'active'/, '暂停按钮必须按 phase 门控')
42
+ assert.match(src, /goalStopped = goalPhase === 'paused' \|\| goalPhase === 'blocked'/, '继续按钮必须按 phase 门控')
43
+ // 按钮样式必须真的存在(否则是裸浏览器按钮):背景=主色实心,前景=宿主 on-color 令牌。
44
+ assert.match(src, /\.pb-dock-goal-resume \{[^}]*background: var\(--dsw-alias-brand-primary\)/, '继续按钮需要有主色实心样式')
45
+ assert.match(src, /\.pb-dock-goal-resume \{[^}]*color: var\(--dsw-alias-label-on-color/, '继续按钮前景必须用 on-color 令牌')
46
+ })
47
+
48
+ test('主色实心按钮的前景色不得用 bg-base(玻璃皮肤会把它设成 transparent)', () => {
49
+ const src = fs.readFileSync(clientFile, 'utf8')
50
+ // 事故:maid-atelier 皮肤在 body 上把 --dsw-alias-bg-base 设为 transparent,
51
+ // 拿它当 color 会让「继续」渲染成透明字 → 看着像一块纯色块盖住了按钮。
52
+ assert.doesNotMatch(src, /color:\s*var\(--dsw-alias-bg-base/, '--dsw-alias-bg-base 是页面底色语义,不能当前景色')
53
+ assert.match(src, /\.pb-btn-primary \{[^}]*color: var\(--dsw-alias-label-on-color/, '主按钮前景必须用 on-color 令牌')
54
+ // 选择态底板同样不能用 bg-base(透明后选中段会"消失")。
55
+ assert.doesNotMatch(src, /\[data-on="true"\] \{[^}]*background: var\(--dsw-alias-bg-base/, '分段控件选中态不得用 bg-base 做底板')
56
+ })
57
+
58
+ test('目标文案区分「板目标」与宿主 goal,完成态不报时间面', () => {
59
+ const src = fs.readFileSync(clientFile, 'utf8')
60
+ // 官方 GoalBar 与 /progress-goal 是两套状态机,并排在同一 input dock:文案必须能分辨。
61
+ assert.match(src, /goalPaused: '板目标已暂停'/, 'zh 文案需带「板目标」前缀')
62
+ assert.match(src, /goalPaused: 'Board goal paused'/, 'en 文案需带 Board goal 前缀')
63
+ assert.match(src, /独立于宿主的 \/goal/, '悬停提示需说明与宿主 /goal 的关系')
64
+ assert.match(src, /const allDone = summary\.total > 0 && summary\.done === summary\.total/, '完成态需跳过时间面')
65
+ })
66
+
67
+ test('W1: 头部入口注册仍在,且带渲染兜底与分面隔离', () => {
68
+ // 仓内文件是 CRLF:多行断言前先归一,否则 \n 永远匹配不到 \r\n。
69
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
70
+ // 入口本体:槽位 + id + 顺序(5 = 排在宿主自带入口之后、其余插件之前,窄窗口不会被裁掉)
71
+ assert.match(src, /name: 'conversation\.session\.header\.utilities'/, '头部工具区槽位注册必须在')
72
+ assert.match(src, /id: 'progress-union-header'/, '头部入口 id 必须在')
73
+ assert.match(src, /order: 5,/, '头部入口顺序必须提前到 5')
74
+ // 渲染兜底:组件抛错只让这一枚消失,不拖垮整排 utilities
75
+ assert.match(src, /class HeaderEntryBoundary extends React\.Component/, '头部入口必须有错误边界')
76
+ assert.match(src, /getDerivedStateFromError/, '错误边界必须真的降级渲染')
77
+ assert.match(src, /function ProgressHeaderButton\(props\) \{\n return h\(HeaderEntryBoundary/, '导出组件必须包在错误边界里')
78
+ // 分面隔离:任一入口注册失败不得中止 apply(否则图标/迷你条/右栏页签一起消失)
79
+ assert.match(src, /const safeEffect = \(label, register\) =>/, '必须有分面隔离助手')
80
+ const safeCalls = src.match(/^\s+safeEffect\($/gm) || []
81
+ assert.equal(safeCalls.length, 6, '六个入口面(设置×2 / 右栏类型 / 右栏面板 / 头部 / 迷你条)都必须经 safeEffect 注册')
82
+ const bare = src.match(/ctx\.effect\(\s*\n\s*\(\) =>\s*\n\s*ctx\.(slots|sidebarRightTabs)/g) || []
83
+ assert.equal(bare.length, 0, '不得残留裸 ctx.effect 入口注册')
84
+ })
85
+
86
+ test('W2: better-sidebar 页签是独立入口,内容仍是自有板子', () => {
87
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
88
+ assert.match(src, /const BS_TAB_ID = 'dsh-progress-union:board'/, 'better-sidebar 页签 id 必须在')
89
+ assert.doesNotMatch(src, /const BS_TAB_ID = 'progress-union'|const BS_TAB_ID = 'dsh-progress-union'\n/, '页签 id 不得与原生 kind 混用')
90
+ // 服务可能晚于 apply 就绪 → 必须 deferred inject,不能一次性 ctx.get
91
+ assert.match(src, /ctx\.inject\(\['betterSidebar'\], \(bs\) => \{/, '必须用 deferred inject 等待 betterSidebar')
92
+ assert.match(src, /typeof service\.registerTab !== 'function'/, '调用前必须探测 registerTab')
93
+ // 描述符字段齐全
94
+ assert.match(src, /id: BS_TAB_ID,/)
95
+ assert.match(src, /title: \(\) => t\('nav'\),/)
96
+ assert.match(src, /description: \(\) => t\('bsDesc'\),/)
97
+ assert.match(src, /icon: \(size\) => h\(ProgressNavIcon, \{ size: size \|\| 16 \}\)/)
98
+ assert.match(src, /order: 120,/)
99
+ assert.match(src, /single: true,/)
100
+ // 内容是自有板子,且拿到当前会话
101
+ assert.match(src, /h\(ProgressSidePanel, \{/, '页签正文必须是自有 ProgressSidePanel')
102
+ assert.match(src, /sessionId: tabProps && tabProps\.scope \? tabProps\.scope\.sessionId : undefined/)
103
+ // 不传 collapse / toggleFullscreen,避免 better-sidebar 里出现死按钮
104
+ const block = src.slice(src.indexOf("ctx.inject(['betterSidebar']"), src.indexOf("'progress-union: better-sidebar tab'"))
105
+ assert.doesNotMatch(block, /collapse:/, '不得向 better-sidebar 页签传 collapse')
106
+ assert.doesNotMatch(block, /toggleFullscreen:/, '不得向 better-sidebar 页签传 toggleFullscreen')
107
+ // 明确不复用 better-sidebar 的「任务管理」
108
+ assert.doesNotMatch(block, /task.?manage|subagent|后台命令/iu, '不得复用 better-sidebar 的任务管理视图')
109
+ })
110
+
111
+ test('W2: better-sidebar 只是软依赖(未装者必须照常加载)', () => {
112
+ const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'))
113
+ const declared = pkg.dsh?.client?.inject ?? []
114
+ assert.equal(declared.includes('dsh-better-sidebar'), false, 'dsh.client.inject 不得声明 dsh-better-sidebar')
115
+ assert.equal('dsh-better-sidebar' in (pkg.dependencies ?? {}), false, 'dependencies 不得声明 dsh-better-sidebar')
116
+ })
117
+
118
+ test('S2: bsDesc 在 zh/en 两个字典里都存在', () => {
119
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
120
+ assert.match(src, /bsDesc: '任务串联的进度板(不是 better-sidebar 的「任务管理」)'/, 'zh 文案必须在')
121
+ assert.match(src, /bsDesc: 'Linked-task progress board \(not better-sidebar task manager\)'/, 'en 文案必须在')
122
+ })
123
+
124
+ test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
125
+ const harness = createHarness()
126
+ await harness.run()
127
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
128
+ await harness.toolMap.get('progress_update').definition.execute(
129
+ { changes: [{ title: '渲染截图', status: 'doing', current: '渲染第 7/24 张' }, { title: '合成音轨' }] },
130
+ { agent: harness.agent },
131
+ )
132
+ harness.emit('turn/start', {})
133
+ harness.emit('step/start', {})
134
+
135
+ const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
136
+ assert.equal(snap.ok, true)
137
+ assert.equal(snap.enabled, true)
138
+ assert.deepEqual(snap.items.map((i) => i.title), ['渲染截图', '合成音轨'])
139
+ assert.equal(typeof snap.summary.percent, 'number')
140
+ assert.equal('pendingUserChanges' in snap, true)
141
+
142
+ const status = (await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })).json()
143
+ assert.equal(status.ok, true)
144
+ assert.equal(status.config.pollMs, 1000)
145
+ assert.ok(status.task, 'status.task 必须存在(迷你条数据源)')
146
+ assert.equal(String(status.task.id), String(SESSION))
147
+ // 板开:阶段直接取板 items,不再走关键词猜测
148
+ assert.deepEqual(status.task.stages, ['渲染截图', '合成音轨'])
149
+ assert.equal(status.task.boardDriven, true)
150
+ assert.equal(status.task.current, 0)
151
+ assert.ok(Array.isArray(status.tasks))
152
+ })
153
+
154
+ test('W3: 板只住在右侧边栏——不再注册主区完整面板', () => {
155
+ // 事故:主区面板没有收拢入口,点进去就回不到会话(进去出不来)。
156
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
157
+ assert.match(src, /const openPanel = \(\) => ctx\.sidebarRight\.openTab\(RIGHT_TAB_KIND\)/, '头部/迷你条入口必须打开右栏页签')
158
+ assert.match(src, /inject: \(\) => \(\{ openPanel, togglePanel \}\)/, '头部入口注入的必须是右栏开关(可见则收起,不可见则打开)')
159
+ assert.doesNotMatch(src, /ctx\.slots\.inject\('main'/, '不得再注册主区完整面板')
160
+ assert.doesNotMatch(src, /layout\.selectPanel/, '不得再切主区面板')
161
+ assert.doesNotMatch(src, /function ProgressPanel\(/, '完整面板组件应已移除')
162
+ })
163
+
164
+ test('W4: 侧栏顶部不再画自带的 全面展开/收起/完整面板 按钮(交给右栏 chrome)', () => {
165
+ // 事故:三个按钮都在,但 toggleFullscreen / collapse 在右栏页签里根本没注入(better-sidebar 里更没处传),
166
+ // 点了没反应才是常态。右栏自身的 chrome 已经有全屏与关闭,不再重复造。
167
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
168
+ assert.doesNotMatch(src, /props\.toggleFullscreen/, '不得再渲染自带的全屏按钮')
169
+ assert.doesNotMatch(src, /props\.collapse/, '不得再渲染自带的收起按钮')
170
+ assert.doesNotMatch(src, /t\('sideFull'\)|t\('sideHalf'\)|t\('sideCollapse'\)/, '三个死按钮的文案不得残留')
171
+ assert.doesNotMatch(src, /toggleFullscreen/, '注入面不得再传全屏切换')
172
+ })
173
+
174
+ test('0.6.2:面板来源行只在 snapshot.restoredFrom 存在时渲染', () => {
175
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
176
+ assert.match(src, /\.pb-side-restore \{/, '来源行样式缺失')
177
+ assert.match(src, /sideRestore: '已从归档 v\{seq\} · rev \{revision\} 恢复,共 \{n\} 项'/, 'zh 文案缺失')
178
+ assert.match(src, /sideRestore: 'Restored from archive/, 'en 文案缺失')
179
+ assert.match(src, /snapshot\?\.restoredFrom\s*\n?\s*\? h\(/, '渲染必须由 restoredFrom 门控')
180
+ assert.match(src, /replace\('\{seq\}', String\(snapshot\.restoredFrom\.seq\)\)/, 'seq 未注入')
181
+ })
182
+
183
+ test('0.6.3:提示卡与用量条间距成体系,且不再出现负 margin', () => {
184
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
185
+ assert.doesNotMatch(src, /margin:\s*-4px/, '不得再有负上边距(用量条顶进提示卡的根因)')
186
+ assert.match(src, /\.pb-llm \{[^}]*margin: 10px 0 12px/, '.pb-llm 下边距必须 12px')
187
+ assert.doesNotMatch(src, /\.pb-llm \{[^}]*margin: 10px 0 0[;}]/, '旧的 0 下边距必须消失')
188
+ assert.match(src, /\.pb-side > \.pb-usage \{[^}]*margin: 0 0 12px/, '用量条上边距必须归零')
189
+ assert.match(src, /\.pb-side > \.pb-llm \+ \.pb-side-error \{ margin-top: 12px; \}/, '同类块相邻补 12px')
190
+ })
191
+
192
+ // ── 0.7.0 rc.2 / Phase 4:下载子进度条(R2 展示面)──────────────────────
193
+
194
+ // 把 client.js 里的 downloadRow 抠出来在 vm 外单跑一次:源码正则只能证明「写了」,
195
+ // 真调用才能证明「关板时返回 null、无真值时不吐假百分比」。
196
+ function loadDownloadRow() {
197
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
198
+ const start = src.indexOf('function downloadRow(dl, t) {')
199
+ assert.ok(start > 0, 'downloadRow 助手必须存在')
200
+ const end = src.indexOf('\n }\n', start)
201
+ assert.ok(end > start, 'downloadRow 函数体必须能定界')
202
+ // eslint-disable-next-line no-new-func
203
+ return new Function('h', 't', `${src.slice(start, end + 6)}\nreturn downloadRow`)(
204
+ (...args) => ({ __el: args }),
205
+ (key) => key,
206
+ )
207
+ }
208
+
209
+ test('rc.2:子条渲染门控——后端不下发 download 时整行不渲染', () => {
210
+ const downloadRow = loadDownloadRow()
211
+ const t = (k) => k
212
+ assert.equal(downloadRow(undefined, t), null, 'snapshot 无 download 键(关板/showSubBar=false/过期)必须不渲染')
213
+ assert.equal(downloadRow(null, t), null)
214
+ assert.equal(downloadRow({ active: false, basis: 'stdout', percent: 50 }, t), null, 'active=false 必须不渲染')
215
+ })
216
+
217
+ test('rc.2:真值档(stdout/board)画实际宽度并显示百分比', () => {
218
+ const downloadRow = loadDownloadRow()
219
+ const row = downloadRow({ active: true, basis: 'stdout', percent: 42.6, kind: 'install', target: 'zod', elapsedSec: 8 }, (k) => k)
220
+ assert.ok(row && row.__el, '子条必须产出元素')
221
+ const [, attrs, ...kids] = row.__el
222
+ assert.equal(attrs.className, 'pb-dock-dl')
223
+ assert.match(String(attrs.title), /dlInstall \u00b7 zod/, '悬停提示需带动作与目标')
224
+ const cls = (n) => (n && n.__el ? String(n.__el[1].className) : '')
225
+ const bar = kids.find((n) => cls(n).indexOf('pb-dock-dl-bar') === 0)
226
+ assert.ok(bar, '必须画进度条')
227
+ assert.equal(cls(bar), 'pb-dock-dl-bar', '有真值时不得加 indeterminate')
228
+ assert.equal(bar.__el[2].__el[1].style.width, '43%', '填充宽度取整百分比')
229
+ const pctNode = kids.find((n) => cls(n) === 'pb-dock-dl-pct')
230
+ assert.ok(pctNode && pctNode.__el[2] === '43%', '百分比文本只在真值档出现')
231
+ })
232
+
233
+ test('rc.2:elapsed 档禁假百分比,走 indeterminate 条纹 + 已用时长;后台加徽标', () => {
234
+ const downloadRow = loadDownloadRow()
235
+ const row = downloadRow({ active: true, basis: 'elapsed', kind: 'clone', target: 'repo.git', elapsedSec: 125, background: true }, (k) => k)
236
+ const [, , ...kids] = row.__el
237
+ const cls = (n) => (n && n.__el ? String(n.__el[1].className) : '')
238
+ const bar = kids.find((n) => cls(n).indexOf('pb-dock-dl-bar') === 0)
239
+ assert.equal(cls(bar), 'pb-dock-dl-bar indeterminate', '无真值必须走条纹档')
240
+ assert.equal(bar.__el[2].__el[1], undefined, '无真值不得写内联 style(假百分比)')
241
+ assert.equal(kids.some((n) => cls(n) === 'pb-dock-dl-pct'), false, '无真值不得出现百分比')
242
+ const badge = kids.find((n) => cls(n) === 'pb-badge-bg')
243
+ assert.ok(badge && badge.__el[2] === 'dlBackground', 'background=true 必须出徽标')
244
+ const time = kids.find((n) => cls(n) === 'pb-dock-dl-time')
245
+ assert.equal(time.__el[2], '2 dlMinUnit', '>=60s 换算成分钟')
246
+ })
247
+
248
+ test('rc.2:子条样式全走宿主令牌,且挂在主条行之后、展开区之前', () => {
249
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
250
+ const cssStart = src.indexOf('.pb-dock-dl {')
251
+ const cssEnd = src.indexOf('.pb-side {')
252
+ assert.ok(cssStart > 0 && cssEnd > cssStart, '子条样式块必须在侧栏样式之前')
253
+ const css = src.slice(cssStart, cssEnd)
254
+ assert.doesNotMatch(css, /#[0-9a-fA-F]{3,6}/, '子条样式不得硬编十六进制色')
255
+ assert.doesNotMatch(css, /rgba?\(/, '子条样式不得硬编 rgb 色(皮肤切换会失配)')
256
+ assert.match(css, /var\(--dsw-alias-brand-primary\)/, '填充色必须用主色令牌')
257
+ assert.match(css, /\.pb-badge-bg \{[^}]*var\(--dsw-alias-state-warn-primary\)/, '后台徽标必须用 warn 令牌')
258
+ assert.match(css, /@media \(prefers-reduced-motion: reduce\)/, '条纹动画必须尊重「减少动效」')
259
+ assert.match(src, /\.pb-dock-dl \{ margin-left: 0; \}/, '760px 段需去掉左缩进')
260
+ assert.match(src, /@media \(max-width: 520px\) \{\s*\.pb-dock-dl \{ display: none; \}/, '极窄屏整行收起')
261
+ const rowIdx = src.indexOf("{ className: 'pb-dock-row' }")
262
+ const dlIdx = src.indexOf('downloadRow(snapshot.download, t),')
263
+ const expIdx = src.indexOf('expanded\n ? h(', dlIdx)
264
+ assert.ok(rowIdx > 0 && rowIdx < dlIdx && dlIdx < expIdx, '子条必须渲染在主条行之后、展开列表之前')
265
+ })
266
+
267
+ test('rc.2:子条文案 zh/en 成对(本仓 client 只有内联 zh/en 两份字典)', () => {
268
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
269
+ const keys = ['dlDownload', 'dlInstall', 'dlClone', 'dlPull', 'dlUnnamed', 'dlBackground', 'dlSecUnit', 'dlMinUnit', 'dlBasisStdout', 'dlBasisBoard', 'dlBasisElapsed']
270
+ for (const k of keys) {
271
+ const hits = src.match(new RegExp(`\\n\\s+${k}: '[^']+',`, 'g')) || []
272
+ assert.equal(hits.length, 2, `${k} 必须在 zh/en 各出现一次(实得 ${hits.length})`)
273
+ }
274
+ })