dsh-progress-union 0.5.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.5.2 (2026-11-29)
6
+
7
+ **fix(/progress-goal 自动续轮彻底不工作):`driveGoal` 拿不到 agent,每轮派发都抛 TypeError 被静默吞掉。**
8
+
9
+ 起因:用户报「已经用 /progress-goal 设了规则,还是没检查完成就中途停止」。回查 session-`3353b1ac`:`/progress-goal` 建目标成功(`Status: active` / `Activation: armed` / `Rounds: 0/256`),但此后**没有任何一轮被派发** —— 会话日志里没有一条 `<progress_goal_round>`,持久化状态里 `roundsStarted` 恒为 `0`,轮次预算却一直显示满额。
10
+
11
+ - **根因**:`driveGoal(state)` 第一行 `const { agent } = state` 期望拿到官方 driver 的 `DriverState`(其带 `agent` 字段),而本插件实际传入的是 `driveStateFor()` 的 live state —— `{ attempt, requested, run, stopping }`,**没有 `agent`**。于是 `String(agent.session?.id ?? agent.id)` 必然抛 `TypeError: Cannot read properties of undefined (reading 'session')`,而 `requestGoalDrive` 的 `catch` 原本是静默的 → 续轮驱动器从落地起就 100% 空转,表面一切正常(目标 active/armed),实际永不续轮。
12
+ - **fix**:`driveStateFor()` 在 live state 上带 `agent`(对齐官方 `DriverState` 形状),`driveGoal` 解构即得。
13
+ - **fix(可观测)**:`requestGoalDrive` 的单轮失败不再静默,改走 `ctx.logger.warn`(带 stack)——这正是本次事故「无日志、无报错、状态还像对的」的成因。
14
+ - **test(回归)**:新增 `test/goal-drive.test.mjs`(5 例)——idle 边沿必须派发一轮带 `plugin:progress-goal-goal` source 的续轮消息并落盘 `roundsStarted=1`、无目标时不派发、pre-step 身份栅栏放行自己/reject 伪造轮次、预算到顶转 blocked、官方目标 active 时让路。旧代码在本测试第一例即失败。
15
+ - **fix(侧栏排版)**:进度板侧栏头部里,副标题原本和标题同属左侧块、与右侧三个按钮同行;
16
+ 按钮 `flex: none` 把文字列压到约 8em,中文说明被折成每列 2~3 字(335px 侧栏实测截图)。
17
+ 改为 `.pb-side-sub` 脱离 `pb-side-head`、作为其兄弟节点独占整行(`max-width: none` + 自带 14px 下边距,
18
+ 接替旧 head 的 `margin-bottom`),可用宽度回到整个面板内容宽。新增 `test/layout-squeeze.test.mjs`(3 例)钉住契约。
19
+ - 全量 `npm test` **87/87** 绿。
20
+
21
+ ## 0.5.1 (2026-11-26)
22
+
23
+ **fix(头部图标反色):板样式改为 apply 阶段注入 document.head + 按钮内联兜底。**
24
+
25
+ 起因:深色主题下会话头部那枚进度板图标偶尔显示成「浅底深字」的反色块。
26
+
27
+ - 根因是样式到达时序,不是主题或配色:`.pb-header-btn` 的规则只在组件内 `h('style', null, CSS)` 里,而头部按钮 (`conversation.session.header.utilities`) 比侧栏面板 / dock 都先挂载;dock 在进度板为空时又提前 `return null`,连自己的 `<style>` 都不渲染 → 按钮先以浏览器默认 `<button>`(`ButtonFace` 底 + 1px 边框 + `ButtonText` 字)出场,碰巧打开过面板后才正常。
28
+ - **fix(全局注入)**:抽出 `ensureHeadStyle(id, css)`,`ensureUnionSettingsStyle` 复用;新增 `ensureUnionBoardStyle()`(id `dsh-progress-union-board-style`)在 `apply()` 内调用,板样式不再依赖任何组件挂载。
29
+ - **fix(内联兜底)**:`ProgressHeaderButton` 加 `HEADER_BTN_FALLBACK` 内联关键外壳(尺寸 / 透明底 / 无边框 / `label-secondary` 字色 / `appearance:none`)。因内联优先级高于样式表,hover 反馈改由 `useState` 驱动,不再依赖 `.pb-header-btn:hover`。
30
+ - 全量 `npm test` **79/79** 绿。
31
+
5
32
  ## 0.5.0 (2026-11-26)
6
33
 
7
34
  **plan 文档(spec/tasks/checklist)喂给任务管理 LLM + PTC 通道容错。**
package/client.js CHANGED
@@ -693,10 +693,11 @@ window.__ModuleLoader__.load({
693
693
  color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-base);
694
694
  font-family: inherit; font-size: 13px; line-height: 1.45;
695
695
  }
696
- .pb-side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
696
+ .pb-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
697
697
  .pb-side-head-actions { display: flex; align-items: center; gap: 4px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
698
698
  .pb-side-title { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
699
- .pb-side-sub { margin: 3px 0 0; color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1.4; }
699
+ /* 副标题单独占满整行:窄栏里不再被右侧按钮挤成竖排,而是用到按钮下方的空白铺开 */
700
+ .pb-side-sub { margin: 5px 0 14px; color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1.4; max-width: none; }
700
701
  .pb-side-section { margin-top: 15px; }
701
702
  .pb-side-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; color: var(--dsw-alias-label-secondary); font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
702
703
  .pb-side-card { border: 1px solid var(--dsw-alias-border-l1); border-radius: 9px; background: var(--dsw-alias-bg-layer-1); padding: 9px 10px; }
@@ -837,15 +838,53 @@ window.__ModuleLoader__.load({
837
838
  )
838
839
  }
839
840
 
841
+ /*
842
+ * 内联兜底:.pb-header-btn 的样式来自插件 CSS,而这段 CSS 只在面板挂载时
843
+ * 才进 DOM。头部按钮比面板先出现,没有兜底就会露出浏览器默认按钮
844
+ * (浅底 + 边框 = 深色头部上的反色块)。这里把「不依赖样式表」的那层
845
+ * 关键外壳写成内联 style 兜底;全局注入(ensureUnionBoardStyle)是主路径,
846
+ * 两端任一到位都不会再露出默认按钮。
847
+ */
848
+ const HEADER_BTN_FALLBACK = {
849
+ display: 'inline-flex',
850
+ alignItems: 'center',
851
+ justifyContent: 'center',
852
+ width: 28,
853
+ height: 28,
854
+ padding: 0,
855
+ border: '1px solid transparent',
856
+ borderRadius: 6,
857
+ background: 'transparent',
858
+ color: 'var(--dsw-alias-label-secondary, currentColor)',
859
+ cursor: 'pointer',
860
+ lineHeight: 1,
861
+ boxShadow: 'none',
862
+ appearance: 'none',
863
+ WebkitAppearance: 'none',
864
+ font: 'inherit',
865
+ }
866
+
840
867
  function ProgressHeaderButton(props) {
841
868
  const t = makeT(props)
869
+ // 内联样式优先级高于样式表,hover 变色只能自己管:样式表没到场也要有反馈。
870
+ const [hovered, setHovered] = useState(false)
871
+ const style = hovered
872
+ ? {
873
+ ...HEADER_BTN_FALLBACK,
874
+ background: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,.16))',
875
+ color: 'var(--dsw-alias-label-primary, currentColor)',
876
+ }
877
+ : HEADER_BTN_FALLBACK
842
878
  return h(
843
879
  'button',
844
880
  {
845
881
  type: 'button',
846
882
  className: 'pb-header-btn',
883
+ style,
847
884
  title: t('nav'),
848
885
  'aria-label': t('nav'),
886
+ onMouseEnter: () => setHovered(true),
887
+ onMouseLeave: () => setHovered(false),
849
888
  onClick: () => {
850
889
  try {
851
890
  props.openPanel?.()
@@ -1681,19 +1720,43 @@ window.__ModuleLoader__.load({
1681
1720
  .dsu-empty { padding: 12px 14px; border-radius: 10px; border: 1px dashed var(--dsw-alias-border-l1, rgba(128,128,128,.35)); font-size: 12px; line-height: 1.6; opacity: .8; }
1682
1721
  `
1683
1722
 
1684
- function ensureUnionSettingsStyle() {
1723
+ /**
1724
+ * 把一段 CSS 挂到 document.head(幂等)。
1725
+ *
1726
+ * 组件内的 `h('style', null, CSS)` 只覆盖「该组件自己渲染出来的子树」:
1727
+ * - 会话头部工具区(conversation.session.header.utilities)比面板先挂载;
1728
+ * - 输入框 dock 在进度板为空时会提前 return,连自己的 <style> 都不渲染。
1729
+ * 两处都可能出现「样式还没到、节点已经画出来」,于是退化成浏览器默认按钮
1730
+ * (浅底 ButtonFace + 1px 边框 + 深色 ButtonText),在深色头部上就是反色块。
1731
+ * 头部图标那枚 .pb-header-btn 正踩在这个时序里。
1732
+ */
1733
+ function ensureHeadStyle(id, css) {
1685
1734
  try {
1686
1735
  if (typeof document === 'undefined') return
1687
- if (document.getElementById(SETTINGS_STYLE_ID)) return
1736
+ if (document.getElementById(id)) return
1688
1737
  const el = document.createElement('style')
1689
- el.id = SETTINGS_STYLE_ID
1690
- el.textContent = SETTINGS_CSS
1738
+ el.id = id
1739
+ el.textContent = css
1691
1740
  document.head.appendChild(el)
1692
1741
  } catch (_error) {
1693
1742
  // 无 DOM(SSR / 测试环境)时静默跳过
1694
1743
  }
1695
1744
  }
1696
1745
 
1746
+ function ensureUnionSettingsStyle() {
1747
+ ensureHeadStyle(SETTINGS_STYLE_ID, SETTINGS_CSS)
1748
+ }
1749
+
1750
+ const BOARD_STYLE_ID = 'dsh-progress-union-board-style'
1751
+
1752
+ /**
1753
+ * 进度板 / dock / 头部按钮共用的那套 CSS,必须在 apply() 时就进 head,
1754
+ * 不能等某个组件挂载——否则头部图标先画出来就是无样式默认按钮。
1755
+ */
1756
+ function ensureUnionBoardStyle() {
1757
+ ensureHeadStyle(BOARD_STYLE_ID, CSS)
1758
+ }
1759
+
1697
1760
  function SettingsSwitch(props) {
1698
1761
  return h(
1699
1762
  'span',
@@ -1985,7 +2048,7 @@ window.__ModuleLoader__.load({
1985
2048
  status ? h('span', { className: 'dsu-hint' }, status) : null,
1986
2049
  ),
1987
2050
  )
1988
- }
2051
+ }
1989
2052
  function ProgressSidePanel(props) {
1990
2053
  const t = makeT(props)
1991
2054
  const { sessionId } = props
@@ -2108,12 +2171,7 @@ window.__ModuleLoader__.load({
2108
2171
  h(
2109
2172
  'div',
2110
2173
  { className: 'pb-side-head' },
2111
- h(
2112
- 'div',
2113
- null,
2114
- h('h2', { className: 'pb-side-title' }, t('nav')),
2115
- h('p', { className: 'pb-side-sub' }, t('subtitle')),
2116
- ),
2174
+ h('h2', { className: 'pb-side-title' }, t('nav')),
2117
2175
  h(
2118
2176
  'div',
2119
2177
  { className: 'pb-side-head-actions' },
@@ -2138,6 +2196,7 @@ window.__ModuleLoader__.load({
2138
2196
  h('button', { type: 'button', className: 'pb-btn', onClick: collapse }, t('sideCollapse')),
2139
2197
  ),
2140
2198
  ),
2199
+ h('p', { className: 'pb-side-sub' }, t('subtitle')),
2141
2200
  readError ? h('div', { className: 'pb-side-error' }, `${t('readError')}${readError}`) : null,
2142
2201
  h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t }),
2143
2202
  actionError ? h('div', { className: 'pb-side-error' }, `${t('saveError')}${actionError}`) : null,
@@ -2714,6 +2773,9 @@ window.__ModuleLoader__.load({
2714
2773
  // 卡内自己订阅句柄并重取 scope,所以两个座位都可以先注空 prop。
2715
2774
  bindUnionConfigForms(ctx)
2716
2775
  ensureUnionSettingsStyle()
2776
+ // 板样式(含头部按钮 .pb-header-btn)同样要在 apply 阶段就进 head:
2777
+ // 头部图标比侧栏面板 / dock 都早挂载,晚一步就是反色默认按钮。
2778
+ ensureUnionBoardStyle()
2717
2779
  const registerSettingsSeat = (seat, options) =>
2718
2780
  ctx.slots.inject(seat, () =>
2719
2781
  ctx.slots.register(
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "main": "./index.js",
5
5
  "description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),并向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面)。",
6
6
  "engines": {
package/index.js CHANGED
@@ -1696,7 +1696,8 @@ export async function apply(ctx, config) {
1696
1696
  function driveStateFor(agent) {
1697
1697
  let s = goalDrives.get(agent)
1698
1698
  if (!s) {
1699
- s = { attempt: undefined, requested: false, run: undefined, stopping: false }
1699
+ // agent 必须存在 live state 上:driveGoal(state) 从这里取 agent(对齐官方 DriverState)。
1700
+ s = { agent, attempt: undefined, requested: false, run: undefined, stopping: false }
1700
1701
  goalDrives.set(agent, s)
1701
1702
  }
1702
1703
  return s
@@ -1800,8 +1801,11 @@ export async function apply(ctx, config) {
1800
1801
  state.requested = false
1801
1802
  try {
1802
1803
  await driveGoal(state)
1803
- } catch (_err) {
1804
- // 单轮失败静默,不阻断后续
1804
+ } catch (err) {
1805
+ // 单轮失败不阻断后续,但必须留痕:静默吞掉会让「设了目标却不续轮」无从排查。
1806
+ try {
1807
+ ctx.logger?.warn?.(`progress-union: goal round drive failed: ${err instanceof Error ? err.stack || err.message : String(err)}`)
1808
+ } catch (_logErr) {}
1805
1809
  }
1806
1810
  }
1807
1811
  })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
6
6
  "license": "MIT",
@@ -0,0 +1,127 @@
1
+ /**
2
+ * /progress-goal 自动续轮驱动器验收(回归 session-3353b1ac 的「设了目标却不续轮」):
3
+ * - agent/status idle → 必须经 agent.followup 派发一轮带自有 source 的续轮消息;
4
+ * - driveGoal 必须拿到 agent(driveStateFor 的 live state 带 agent),否则 TypeError 被静默吞掉;
5
+ * - pre-step 身份栅栏:自己派发的轮次放行,伪造/过期轮次 reject;
6
+ * - 预算到顶转 blocked;官方目标 active 时让路不排队。
7
+ */
8
+ import assert from 'node:assert/strict'
9
+ import fs from 'node:fs'
10
+ import os from 'node:os'
11
+ import path from 'node:path'
12
+ import test from 'node:test'
13
+
14
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-goal-drive-'))
15
+ const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
16
+
17
+ const GOAL_SOURCE_KIND = 'plugin:progress-goal-goal'
18
+
19
+ async function booted(config = {}) {
20
+ const harness = createHarness({ config })
21
+ await harness.run()
22
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
23
+ return harness
24
+ }
25
+
26
+ function cmd(harness, input) {
27
+ return harness.commandMap.get('progress-goal').handler({ agent: harness.agent, rawInput: input })
28
+ }
29
+
30
+ function update(harness, changes) {
31
+ return harness.toolMap.get('progress_update').definition.execute({ changes }, { agent: harness.agent })
32
+ }
33
+
34
+ /** 宿主在回合收尾时把 agent 状态翻到 idle;插件在该边沿派发下一轮。 */
35
+ async function idle(harness) {
36
+ for (const listener of harness.listeners.filter((l) => l.type === 'agent/status')) {
37
+ listener.handler({ agent: harness.agent, status: 'idle' })
38
+ }
39
+ await flush()
40
+ await new Promise((resolve) => setTimeout(resolve, 10))
41
+ }
42
+
43
+ async function snapshotOf(harness) {
44
+ const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
45
+ return res.json()
46
+ }
47
+
48
+ async function preStep(harness, message) {
49
+ const hook = harness.agentHooks.find((h) => h.type === 'agent/pre-step')
50
+ assert.ok(hook, 'pre-step hook 必须已安装')
51
+ return hook.handler(
52
+ { turn: 1, step: 1, messages: [message] },
53
+ async () => ({ kind: 'enter', messages: [message] }),
54
+ )
55
+ }
56
+
57
+ test('idle 派发一轮续轮消息(回归:driveGoal 拿不到 agent)', async () => {
58
+ const h = await booted()
59
+ await update(h, [{ title: 't1', status: 'doing', percent: 40 }])
60
+ await cmd(h, '把活干完')
61
+ assert.equal(h.agent.followups.length, 0)
62
+
63
+ await idle(h)
64
+
65
+ assert.equal(h.agent.followups.length, 1, 'idle 必须派发一轮')
66
+ const message = h.agent.followups[0]
67
+ assert.equal(message.role, 'user')
68
+ assert.equal(message.source.kind, GOAL_SOURCE_KIND)
69
+ assert.equal(message.source.round, 1)
70
+ assert.equal(typeof message.source.goalId, 'string')
71
+ assert.match(message.content[0].text, /<progress_goal_round>/)
72
+ assert.match(message.content[0].text, /Objective: "把活干完"/)
73
+ assert.match(message.content[0].text, /Round: 1\/256/)
74
+ assert.match(message.content[0].text, /progress_goal_report/, '续轮消息必须交代收尾/受阻的上报口径')
75
+
76
+ const snap = await snapshotOf(h)
77
+ assert.equal(snap.goal.roundsStarted, 1, '轮次计数必须落盘,避免重复派发')
78
+ assert.equal(snap.goal.phase, 'active')
79
+ })
80
+
81
+ test('没有目标时 idle 不派发、不抛错', async () => {
82
+ const h = await booted()
83
+ await idle(h)
84
+ assert.equal(h.agent.followups.length, 0)
85
+ })
86
+
87
+ test('pre-step 身份栅栏:自己的轮次放行,伪造/过期轮次 reject', async () => {
88
+ const h = await booted()
89
+ await update(h, [{ title: 't1', status: 'doing' }])
90
+ await cmd(h, '目标X')
91
+ await idle(h)
92
+ const message = h.agent.followups[0]
93
+
94
+ const decision = await preStep(h, message)
95
+ assert.equal(decision.kind, 'enter', '插件自己派发的轮次必须放行')
96
+
97
+ // 伪造:round 对不上当前 roundsStarted
98
+ const forged = { ...message, id: 'forged', source: { ...message.source, round: 99 } }
99
+ const rejected = await preStep(h, forged)
100
+ assert.equal(rejected.kind, 'reject')
101
+ })
102
+
103
+ test('预算到顶转 blocked,不再派发', async () => {
104
+ const h = await booted()
105
+ await update(h, [{ title: 't1', status: 'doing' }])
106
+ await cmd(h, '目标Y')
107
+ await cmd(h, 'budget 1')
108
+
109
+ await idle(h)
110
+ assert.equal(h.agent.followups.length, 1)
111
+
112
+ await idle(h)
113
+ assert.equal(h.agent.followups.length, 1, '预算用尽后不得再派发')
114
+ const snap = await snapshotOf(h)
115
+ assert.equal(snap.goal.phase, 'blocked')
116
+ assert.match(snap.goal.blockedReason, /预算上限 1 轮/)
117
+ })
118
+
119
+ test('官方目标 active 时让路:不排队', async () => {
120
+ const h = await booted()
121
+ await update(h, [{ title: 't1', status: 'doing' }])
122
+ await cmd(h, '目标Z')
123
+ const original = h.ctx.get.bind(h.ctx)
124
+ h.ctx.get = (name) => (name === 'goals' ? { get: () => ({ phase: 'active', activation: 'armed' }) } : original(name))
125
+ await idle(h)
126
+ assert.equal(h.agent.followups.length, 0, '官方目标在跑时不得抢轮')
127
+ })
package/test/harness.mjs CHANGED
@@ -61,8 +61,12 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
61
61
  const systemPrompt = {}
62
62
 
63
63
  const appends = []
64
+ const followups = []
64
65
  const agent = {
65
66
  id: SESSION,
67
+ // /progress-goal 续轮驱动器经 agent.followup 排队;这里记录被派发的轮次消息。
68
+ followups,
69
+ followup(message) { followups.push(message) },
66
70
  // v0.3.0:todo 镜像写通道。默认记录调用;测试可覆写 append 注入失败。
67
71
  // v0.5.0:cwd 放在 session **顶层**(实测 shape,不是 header.cwd)——plan 扫描靠它。
68
72
  session: {
@@ -140,6 +144,7 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
140
144
  config,
141
145
  agent,
142
146
  appends,
147
+ followups,
143
148
  records,
144
149
  routes,
145
150
  toolMap,
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 窄栏布局回归:进度板副标题在 335px 侧栏里不得被按钮挤成竖排。
3
+ * 起因:截图里 .pb-side-head 是 flex 行,左侧标题+副标题块与三个按钮同行,
4
+ * 按钮 flex:none 把文字列压到约 8em,中文说明被折成每列 2~3 字。
5
+ * 契约:副标题必须是按钮下方独占整行的块,可用宽度接近整个面板内容宽度。
6
+ */
7
+ import { test } from 'node:test'
8
+ import assert from 'node:assert/strict'
9
+ import { readFileSync } from 'node:fs'
10
+ import { fileURLToPath } from 'node:url'
11
+
12
+ const root = fileURLToPath(new URL('..', import.meta.url))
13
+ const client = readFileSync(root + 'client.js', 'utf8')
14
+
15
+ function rule(selector) {
16
+ const i = client.indexOf(selector + ' {')
17
+ assert.notEqual(i, -1, `样式里找不到规则:${selector}`)
18
+ return client.slice(i, client.indexOf('}', i))
19
+ }
20
+
21
+ test('副标题是 pb-side-head 的兄弟节点,不再嵌在左侧标题块里', () => {
22
+ // 重构后:head 内有 h2 + actions,随后紧跟独立的 <p class="pb-side-sub">
23
+ const headMarker = "{ className: 'pb-side-head' }"
24
+ const headPos = client.indexOf(headMarker)
25
+ assert.notEqual(headPos, -1, '找不到 pb-side-head 渲染块')
26
+ // pb-side-head 的收尾:actions 的 ) 之后是 head div 的 ), 再下一行是副标题 <p>
27
+ const subPos = client.indexOf("h('p', { className: 'pb-side-sub' }", headPos)
28
+ assert.notEqual(subPos, -1, '副标题应渲染在 pb-side-head 之后,作为独占一行的兄弟节点')
29
+ const headBlock = client.slice(headPos, subPos)
30
+ assert.equal(headBlock.includes("className: 'pb-side-sub'"), false,
31
+ 'pb-side-head 内部不得再包含副标题(否则仍与按钮同行被挤压)')
32
+ // 副标题紧邻 head 结束(中间只有 actions 的闭合括号),确认不是嵌在别的容器里
33
+ const gap = headBlock.slice(headBlock.lastIndexOf('),'))
34
+ assert.ok(gap.length < 40, `副标题应紧跟 head 容器收尾,实际间隔:${JSON.stringify(gap)}`)
35
+ })
36
+
37
+ test('pb-side-head 只是标题+按钮的一行,副标题样式整行可用', () => {
38
+ const head = rule('.pb-side-head')
39
+ assert.match(head, /display:\s*flex/, 'header 仍是 flex 行')
40
+ assert.equal(/pb-side-sub/.test(head), false)
41
+
42
+ const sub = rule('.pb-side-sub')
43
+ assert.match(sub, /max-width:\s*none/, '副标题不得有窄 max-width 限制')
44
+ assert.match(sub, /margin:\s*[^;]*14px/, '副标题自带下边距,取代旧 head 的 margin-bottom')
45
+ })
46
+
47
+ test('窄栏几何:335px 面板里副标题可用宽度 >= 元素宽度的 90%', () => {
48
+ // 复现截图 335px 面板(左右各 14px padding + 2px 边框),按钮组约 168px。
49
+ // 旧布局:副标题在左侧块内 => 可用宽 ≈ 305 - 168 - 8 ≈ 129px(≈ 竖排 2-3 字)。
50
+ // 新布局:副标题独占一行 => 可用宽 = 305px(按钮下方也能铺文字)。
51
+ const panel = 335
52
+ const padding = 14 * 2
53
+ const borders = 2
54
+ const inner = panel - padding - borders // 293
55
+ const buttons = 168 // Agent 更新:开 + 全面展开 + 收起,实测约 56+52+40 + gaps
56
+ const oldWidth = inner - buttons - 8
57
+ const newWidth = inner
58
+ assert.ok(oldWidth < inner * 0.5, `旧布局应明显受限,实测 ${oldWidth}px`)
59
+ assert.ok(newWidth >= inner * 0.9, `新副标题应占满整行,实测 ${newWidth}px`)
60
+ // 中文 11px 字约 11px 宽 => 293px 一行约可放 24+ 字;旧布局只能 10 字左右。
61
+ const charsPerLineNew = Math.floor(newWidth / 11)
62
+ const charsPerLineOld = Math.floor(oldWidth / 11)
63
+ assert.ok(charsPerLineNew >= charsPerLineOld * 2,
64
+ '副标题每行可容纳字数应至少翻倍,才不会被挤成竖排')
65
+ })