dsh-progress-union 0.6.1 → 0.6.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,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
  })
@@ -1,181 +1,181 @@
1
- // star 面板内联实现的行为契约测试(v1→v2→v3 阶梯,_tools/star-row 计划)。
2
- // 无 jsdom:手写最小 DOM,从 client.js 抽出 __STAR_INLINE 块直接执行,按当前 STAR_GEN 断言。
3
- import { test } from 'node:test'
4
- import assert from 'node:assert/strict'
5
- import { readFileSync } from 'node:fs'
6
- import { join, dirname } from 'node:path'
7
- import { fileURLToPath } from 'node:url'
8
-
9
- const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
10
- const src = readFileSync(join(ROOT, 'client.js'), 'utf8')
11
- const begin = src.indexOf('/* __STAR_INLINE_BEGIN__')
12
- const endMark = src.indexOf('/* __STAR_INLINE_END__')
13
- assert.ok(begin >= 0 && endMark > begin, 'client.js 应含内联 star 面板块')
14
- const end = src.indexOf('*/', endMark) + 2 // 含收尾注释,避免残留未闭合 /*
15
- const block = src.slice(begin, end)
16
- const GEN = (block.match(/var STAR_GEN = "([^"]*)";/) || [])[1]
17
- const NS = (block.match(/var STAR_NS = "([^"]*)";/) || [])[1]
18
- assert.ok(['v1', 'v2', 'v3', 'v4'].includes(GEN), 'STAR_GEN 合法: ' + GEN)
19
- assert.equal(NS, 'progress-union', 'STAR_NS 固定为 im-union')
20
-
21
- // ── 最小 DOM ──
22
- class El {
23
- constructor(tag) {
24
- this.tagName = tag; this.children = []; this.parentNode = null
25
- this.className = ''; this.textContent = ''; this.attrs = {}; this.dataset = {}
26
- this._listeners = {}; this.style = {}; this.type = ''; this.title = ''
27
- }
28
- get firstChild() { return this.children[0] || null }
29
- appendChild(c) { c.parentNode = this; this.children.push(c); return c }
30
- removeChild(c) { this.children = this.children.filter((x) => x !== c); c.parentNode = null; return c }
31
- replaceChild(nu, old) {
32
- const i = this.children.indexOf(old); if (i < 0) throw new Error('replaceChild: 非子节点')
33
- old.parentNode = null; nu.parentNode = this; this.children[i] = nu; return old
34
- }
35
- setAttribute(k, v) { this.attrs[k] = v }
36
- getAttribute(k) { return this.attrs[k] }
37
- addEventListener(ev, fn) { (this._listeners[ev] = this._listeners[ev] || []).push(fn) }
38
- dispatch(ev) { for (const fn of this._listeners[ev] || []) fn({ preventDefault() {}, stopPropagation() {} }) }
39
- set href(v) { this.attrs.href = v } get href() { return this.attrs.href }
40
- set target(v) { this.attrs.target = v } get target() { return this.attrs.target }
41
- set rel(v) { this.attrs.rel = v } get rel() { return this.attrs.rel }
42
- // 锚点点击 = 打开仓库页(测试里只记一笔,真正跳转由浏览器负责)
43
- click() { this.dispatch('click'); this._clicked = true }
44
- }
45
- function makeEnv(lang) {
46
- const store = {}
47
- const head = new El('head'); const documentElement = { lang: lang || 'zh' }
48
- const ids = {}
49
- const document = {
50
- documentElement,
51
- head: { appendChild(c) { if (c.attrs && c.attrs.id) ids[c.attrs.id] = c; head.children.push(c) } },
52
- createElement(t) { return new El(t) },
53
- createElementNS(_ns, t) { return new El(t) },
54
- getElementById(id) { return ids[id] || null },
55
- }
56
- const localStorage = {
57
- getItem(k) { return Object.prototype.hasOwnProperty.call(store, k) ? store[k] : null },
58
- setItem(k, v) { store[k] = String(v) },
59
- removeItem(k) { delete store[k] },
60
- _store: store,
61
- }
62
- return { window: {}, document, localStorage }
63
- }
64
- function runPanel(lang, seedStore) {
65
- const env = makeEnv(lang)
66
- if (seedStore) Object.assign(env.localStorage._store, seedStore)
67
- const fn = new Function('window', 'document', 'localStorage', block + '\nreturn window.__StarPanel;')
68
- const panel = fn(env.window, env.document, env.localStorage)
69
- return { panel, env, mount: panel.mount(env.document) }
70
- }
71
- function find(el, pred, out = []) {
72
- for (const c of el.children || []) { if (pred(c)) out.push(c); find(c, pred, out) }
73
- return out
74
- }
75
- const K1 = 'dsh.star.progress-union.dismissed'
76
- const K2 = 'dsh.star.progress-union.v2.dismissed'
77
- const K3 = 'dsh.star.progress-union.v3.supported'
78
- const K4 = 'dsh.star.progress-union.v4.supported'
79
-
80
- test('star 面板:渲染出 GitHub 仓库链接(各代通用)', () => {
81
- const { mount } = runPanel('zh')
82
- const links = find(mount, (e) => e.tagName === 'a' && /github\.com/.test(e.href || ''))
83
- assert.ok(links.length >= 1, '至少一个仓库链接')
84
- })
85
-
86
- test('star 面板:10 语文案随 documentElement.lang 自选', () => {
87
- const zh = find(runPanel('zh').mount, (e) => e.textContent && e.textContent.length > 1)
88
- const en = find(runPanel('en').mount, (e) => e.textContent && e.textContent.length > 1)
89
- const t = (arr) => arr.map((e) => e.textContent).join('|')
90
- assert.notEqual(t(zh), t(en), 'zh 与 en 文案不同')
91
- })
92
-
93
- if (GEN === 'v1') {
94
- test('v1:★ CTA 只跳转不写键;× 才写 dismissed 并收起话术', () => {
95
- const { mount, env } = runPanel('zh')
96
- assert.equal(mount.className, 'dsh-star-row-s', 'v1 S 档行')
97
- const cta = find(mount, (e) => e.className === 'dsh-star-cta')[0]
98
- const hide = find(mount, (e) => e.className === 'dsh-star-hide')[0]
99
- assert.ok(cta && hide, 'v1 应有 ★ 与 × 两个按钮')
100
- cta.click()
101
- assert.equal(env.localStorage.getItem(K1), null, '点 ★ 不写 dismissed')
102
- hide.dispatch('click')
103
- assert.equal(env.localStorage.getItem(K1), '1', '点 × 写 dismissed')
104
- assert.ok(mount.parentNode === null || mount.className !== 'dsh-star-row-s', '× 后行被替换')
105
- })
106
- test('v1:已 dismissed → 只留中性链接行,无按钮', () => {
107
- const { mount } = runPanel('zh', { [K1]: '1' })
108
- assert.equal(find(mount, (e) => e.className === 'dsh-star-cta').length, 0, 'dismissed 后无 ★')
109
- assert.equal(find(mount, (e) => e.className === 'dsh-star-hide').length, 0, 'dismissed 后无 ×')
110
- })
111
- }
112
-
113
- if (GEN === 'v2') {
114
- test('v2:纯链接一行页脚,无按钮;点 ⭐ 或 💬 即写 v2.dismissed 收敛', () => {
115
- const { mount, env } = runPanel('zh')
116
- assert.equal(mount.className, 'dsh-star-foot', 'v2 页脚行')
117
- assert.equal(find(mount, (e) => e.tagName === 'button').length, 0, 'v2 无按钮')
118
- const stars = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))
119
- assert.ok(stars.length === 1, 'v2 一个 ⭐ 链接')
120
- stars[0].click()
121
- assert.equal(env.localStorage.getItem(K2), '1', '点 ⭐ 写 v2.dismissed')
122
- })
123
- test('v2:加载即清 v1 键、不迁值', () => {
124
- const { env } = runPanel('zh', { [K1]: '1' })
125
- assert.equal(env.localStorage.getItem(K1), null, 'v1 键被清掉')
126
- })
127
- }
128
-
129
- if (GEN === 'v3') {
130
- test('v3:两行页脚;⭐/💬 只跳转不收敛,只有「我已支持」写 v3.supported', () => {
131
- const { mount, env } = runPanel('zh')
132
- assert.equal(mount.className, 'dsh-star-foot', 'v3 页脚')
133
- const btns = find(mount, (e) => e.className === 'dsh-star-support')
134
- assert.equal(btns.length, 1, 'v3 一个「我已支持」按钮')
135
- const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
136
- star.click()
137
- assert.equal(env.localStorage.getItem(K3), null, '点 ⭐ 不写 supported')
138
- btns[0].dispatch('click')
139
- assert.equal(env.localStorage.getItem(K3), '1', '按「我已支持」写 supported')
140
- })
141
- test('v3:加载即清 v1/v2 旧键、不迁值', () => {
142
- const { env } = runPanel('zh', { [K1]: '1', [K2]: '1' })
143
- assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
144
- assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
145
- })
146
- test('v3:已 supported → 收敛态(仓库地址 + 💬 issue),无「我已支持」按钮', () => {
147
- const { mount } = runPanel('zh', { [K3]: '1' })
148
- assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v3 收敛态')
149
- assert.equal(find(mount, (e) => e.className === 'dsh-star-support').length, 0, '收敛后无按钮')
150
- })
151
- }
152
-
153
- if (GEN === 'v4') {
154
- test('v4:三动作统一描边胶囊 dsh-star-btn;⭐/💬 只跳转不收敛,只有「我已支持」写 v4.supported', () => {
155
- const { mount, env } = runPanel('zh')
156
- assert.equal(mount.className, 'dsh-star-foot', 'v4 页脚')
157
- const isBtn = (e) => (e.className || '').split(' ').includes('dsh-star-btn')
158
- const caps = find(mount, isBtn)
159
- assert.equal(caps.length, 3, 'v4 三个动作都是胶囊:⭐ / 我已支持 / 💬')
160
- const sup = find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support')
161
- assert.equal(sup.length, 1, 'v4 一个「我已支持」胶囊按钮')
162
- const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
163
- assert.ok(isBtn(star), '⭐ 是胶囊链接')
164
- star.click()
165
- assert.equal(env.localStorage.getItem(K4), null, '点 ⭐ 不写 supported')
166
- sup[0].dispatch('click')
167
- assert.equal(env.localStorage.getItem(K4), '1', '按「我已支持」写 v4.supported')
168
- })
169
- test('v4:加载即清 v3/v2/v1 三旧键、不迁值', () => {
170
- const { env } = runPanel('zh', { [K1]: '1', [K2]: '1', [K3]: '1' })
171
- assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
172
- assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
173
- assert.equal(env.localStorage.getItem(K3), null, 'v3 键清')
174
- })
175
- test('v4:已 supported → 收敛态(仓库地址 + 💬),无「我已支持」按钮', () => {
176
- const { mount } = runPanel('zh', { [K4]: '1' })
177
- assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v4 收敛态')
178
- assert.equal(find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support').length, 0, '收敛后无按钮')
179
- })
180
- }
181
-
1
+ // star 面板内联实现的行为契约测试(v1→v2→v3 阶梯,_tools/star-row 计划)。
2
+ // 无 jsdom:手写最小 DOM,从 client.js 抽出 __STAR_INLINE 块直接执行,按当前 STAR_GEN 断言。
3
+ import { test } from 'node:test'
4
+ import assert from 'node:assert/strict'
5
+ import { readFileSync } from 'node:fs'
6
+ import { join, dirname } from 'node:path'
7
+ import { fileURLToPath } from 'node:url'
8
+
9
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
10
+ const src = readFileSync(join(ROOT, 'client.js'), 'utf8')
11
+ const begin = src.indexOf('/* __STAR_INLINE_BEGIN__')
12
+ const endMark = src.indexOf('/* __STAR_INLINE_END__')
13
+ assert.ok(begin >= 0 && endMark > begin, 'client.js 应含内联 star 面板块')
14
+ const end = src.indexOf('*/', endMark) + 2 // 含收尾注释,避免残留未闭合 /*
15
+ const block = src.slice(begin, end)
16
+ const GEN = (block.match(/var STAR_GEN = "([^"]*)";/) || [])[1]
17
+ const NS = (block.match(/var STAR_NS = "([^"]*)";/) || [])[1]
18
+ assert.ok(['v1', 'v2', 'v3', 'v4'].includes(GEN), 'STAR_GEN 合法: ' + GEN)
19
+ assert.equal(NS, 'progress-union', 'STAR_NS 固定为 im-union')
20
+
21
+ // ── 最小 DOM ──
22
+ class El {
23
+ constructor(tag) {
24
+ this.tagName = tag; this.children = []; this.parentNode = null
25
+ this.className = ''; this.textContent = ''; this.attrs = {}; this.dataset = {}
26
+ this._listeners = {}; this.style = {}; this.type = ''; this.title = ''
27
+ }
28
+ get firstChild() { return this.children[0] || null }
29
+ appendChild(c) { c.parentNode = this; this.children.push(c); return c }
30
+ removeChild(c) { this.children = this.children.filter((x) => x !== c); c.parentNode = null; return c }
31
+ replaceChild(nu, old) {
32
+ const i = this.children.indexOf(old); if (i < 0) throw new Error('replaceChild: 非子节点')
33
+ old.parentNode = null; nu.parentNode = this; this.children[i] = nu; return old
34
+ }
35
+ setAttribute(k, v) { this.attrs[k] = v }
36
+ getAttribute(k) { return this.attrs[k] }
37
+ addEventListener(ev, fn) { (this._listeners[ev] = this._listeners[ev] || []).push(fn) }
38
+ dispatch(ev) { for (const fn of this._listeners[ev] || []) fn({ preventDefault() {}, stopPropagation() {} }) }
39
+ set href(v) { this.attrs.href = v } get href() { return this.attrs.href }
40
+ set target(v) { this.attrs.target = v } get target() { return this.attrs.target }
41
+ set rel(v) { this.attrs.rel = v } get rel() { return this.attrs.rel }
42
+ // 锚点点击 = 打开仓库页(测试里只记一笔,真正跳转由浏览器负责)
43
+ click() { this.dispatch('click'); this._clicked = true }
44
+ }
45
+ function makeEnv(lang) {
46
+ const store = {}
47
+ const head = new El('head'); const documentElement = { lang: lang || 'zh' }
48
+ const ids = {}
49
+ const document = {
50
+ documentElement,
51
+ head: { appendChild(c) { if (c.attrs && c.attrs.id) ids[c.attrs.id] = c; head.children.push(c) } },
52
+ createElement(t) { return new El(t) },
53
+ createElementNS(_ns, t) { return new El(t) },
54
+ getElementById(id) { return ids[id] || null },
55
+ }
56
+ const localStorage = {
57
+ getItem(k) { return Object.prototype.hasOwnProperty.call(store, k) ? store[k] : null },
58
+ setItem(k, v) { store[k] = String(v) },
59
+ removeItem(k) { delete store[k] },
60
+ _store: store,
61
+ }
62
+ return { window: {}, document, localStorage }
63
+ }
64
+ function runPanel(lang, seedStore) {
65
+ const env = makeEnv(lang)
66
+ if (seedStore) Object.assign(env.localStorage._store, seedStore)
67
+ const fn = new Function('window', 'document', 'localStorage', block + '\nreturn window.__StarPanel;')
68
+ const panel = fn(env.window, env.document, env.localStorage)
69
+ return { panel, env, mount: panel.mount(env.document) }
70
+ }
71
+ function find(el, pred, out = []) {
72
+ for (const c of el.children || []) { if (pred(c)) out.push(c); find(c, pred, out) }
73
+ return out
74
+ }
75
+ const K1 = 'dsh.star.progress-union.dismissed'
76
+ const K2 = 'dsh.star.progress-union.v2.dismissed'
77
+ const K3 = 'dsh.star.progress-union.v3.supported'
78
+ const K4 = 'dsh.star.progress-union.v4.supported'
79
+
80
+ test('star 面板:渲染出 GitHub 仓库链接(各代通用)', () => {
81
+ const { mount } = runPanel('zh')
82
+ const links = find(mount, (e) => e.tagName === 'a' && /github\.com/.test(e.href || ''))
83
+ assert.ok(links.length >= 1, '至少一个仓库链接')
84
+ })
85
+
86
+ test('star 面板:10 语文案随 documentElement.lang 自选', () => {
87
+ const zh = find(runPanel('zh').mount, (e) => e.textContent && e.textContent.length > 1)
88
+ const en = find(runPanel('en').mount, (e) => e.textContent && e.textContent.length > 1)
89
+ const t = (arr) => arr.map((e) => e.textContent).join('|')
90
+ assert.notEqual(t(zh), t(en), 'zh 与 en 文案不同')
91
+ })
92
+
93
+ if (GEN === 'v1') {
94
+ test('v1:★ CTA 只跳转不写键;× 才写 dismissed 并收起话术', () => {
95
+ const { mount, env } = runPanel('zh')
96
+ assert.equal(mount.className, 'dsh-star-row-s', 'v1 S 档行')
97
+ const cta = find(mount, (e) => e.className === 'dsh-star-cta')[0]
98
+ const hide = find(mount, (e) => e.className === 'dsh-star-hide')[0]
99
+ assert.ok(cta && hide, 'v1 应有 ★ 与 × 两个按钮')
100
+ cta.click()
101
+ assert.equal(env.localStorage.getItem(K1), null, '点 ★ 不写 dismissed')
102
+ hide.dispatch('click')
103
+ assert.equal(env.localStorage.getItem(K1), '1', '点 × 写 dismissed')
104
+ assert.ok(mount.parentNode === null || mount.className !== 'dsh-star-row-s', '× 后行被替换')
105
+ })
106
+ test('v1:已 dismissed → 只留中性链接行,无按钮', () => {
107
+ const { mount } = runPanel('zh', { [K1]: '1' })
108
+ assert.equal(find(mount, (e) => e.className === 'dsh-star-cta').length, 0, 'dismissed 后无 ★')
109
+ assert.equal(find(mount, (e) => e.className === 'dsh-star-hide').length, 0, 'dismissed 后无 ×')
110
+ })
111
+ }
112
+
113
+ if (GEN === 'v2') {
114
+ test('v2:纯链接一行页脚,无按钮;点 ⭐ 或 💬 即写 v2.dismissed 收敛', () => {
115
+ const { mount, env } = runPanel('zh')
116
+ assert.equal(mount.className, 'dsh-star-foot', 'v2 页脚行')
117
+ assert.equal(find(mount, (e) => e.tagName === 'button').length, 0, 'v2 无按钮')
118
+ const stars = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))
119
+ assert.ok(stars.length === 1, 'v2 一个 ⭐ 链接')
120
+ stars[0].click()
121
+ assert.equal(env.localStorage.getItem(K2), '1', '点 ⭐ 写 v2.dismissed')
122
+ })
123
+ test('v2:加载即清 v1 键、不迁值', () => {
124
+ const { env } = runPanel('zh', { [K1]: '1' })
125
+ assert.equal(env.localStorage.getItem(K1), null, 'v1 键被清掉')
126
+ })
127
+ }
128
+
129
+ if (GEN === 'v3') {
130
+ test('v3:两行页脚;⭐/💬 只跳转不收敛,只有「我已支持」写 v3.supported', () => {
131
+ const { mount, env } = runPanel('zh')
132
+ assert.equal(mount.className, 'dsh-star-foot', 'v3 页脚')
133
+ const btns = find(mount, (e) => e.className === 'dsh-star-support')
134
+ assert.equal(btns.length, 1, 'v3 一个「我已支持」按钮')
135
+ const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
136
+ star.click()
137
+ assert.equal(env.localStorage.getItem(K3), null, '点 ⭐ 不写 supported')
138
+ btns[0].dispatch('click')
139
+ assert.equal(env.localStorage.getItem(K3), '1', '按「我已支持」写 supported')
140
+ })
141
+ test('v3:加载即清 v1/v2 旧键、不迁值', () => {
142
+ const { env } = runPanel('zh', { [K1]: '1', [K2]: '1' })
143
+ assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
144
+ assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
145
+ })
146
+ test('v3:已 supported → 收敛态(仓库地址 + 💬 issue),无「我已支持」按钮', () => {
147
+ const { mount } = runPanel('zh', { [K3]: '1' })
148
+ assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v3 收敛态')
149
+ assert.equal(find(mount, (e) => e.className === 'dsh-star-support').length, 0, '收敛后无按钮')
150
+ })
151
+ }
152
+
153
+ if (GEN === 'v4') {
154
+ test('v4:三动作统一描边胶囊 dsh-star-btn;⭐/💬 只跳转不收敛,只有「我已支持」写 v4.supported', () => {
155
+ const { mount, env } = runPanel('zh')
156
+ assert.equal(mount.className, 'dsh-star-foot', 'v4 页脚')
157
+ const isBtn = (e) => (e.className || '').split(' ').includes('dsh-star-btn')
158
+ const caps = find(mount, isBtn)
159
+ assert.equal(caps.length, 3, 'v4 三个动作都是胶囊:⭐ / 我已支持 / 💬')
160
+ const sup = find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support')
161
+ assert.equal(sup.length, 1, 'v4 一个「我已支持」胶囊按钮')
162
+ const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
163
+ assert.ok(isBtn(star), '⭐ 是胶囊链接')
164
+ star.click()
165
+ assert.equal(env.localStorage.getItem(K4), null, '点 ⭐ 不写 supported')
166
+ sup[0].dispatch('click')
167
+ assert.equal(env.localStorage.getItem(K4), '1', '按「我已支持」写 v4.supported')
168
+ })
169
+ test('v4:加载即清 v3/v2/v1 三旧键、不迁值', () => {
170
+ const { env } = runPanel('zh', { [K1]: '1', [K2]: '1', [K3]: '1' })
171
+ assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
172
+ assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
173
+ assert.equal(env.localStorage.getItem(K3), null, 'v3 键清')
174
+ })
175
+ test('v4:已 supported → 收敛态(仓库地址 + 💬),无「我已支持」按钮', () => {
176
+ const { mount } = runPanel('zh', { [K4]: '1' })
177
+ assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v4 收敛态')
178
+ assert.equal(find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support').length, 0, '收敛后无按钮')
179
+ })
180
+ }
181
+