dsh-progress-union 0.5.10-rc.1 → 0.5.13
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 +300 -254
- package/LICENSE +21 -21
- package/README.md +220 -220
- package/anchor.js +39 -39
- package/client.js +2947 -2909
- package/cordis.patch.yml +4 -4
- package/docs/slot-models-comparison.md +23 -23
- package/docs/slot-trail-fanout.md +31 -31
- package/docs/spirit-reference.md +38 -38
- package/dsh.plugin.json +1 -1
- package/icon.svg +7 -7
- package/index.js +3833 -3833
- package/package.json +1 -1
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +172 -162
- package/test/e2e.test.mjs +77 -77
- package/test/entry-toggle.test.mjs +216 -0
- package/test/goal-drive.test.mjs +17 -17
- package/test/harness.mjs +249 -249
- package/test/host.test.mjs +251 -251
- package/test/observer.test.mjs +170 -170
- package/test/settings.test.mjs +81 -81
- package/test/star-panel.test.mjs +151 -151
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
package/test/star-panel.test.mjs
CHANGED
|
@@ -1,151 +1,151 @@
|
|
|
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'].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
|
-
|
|
79
|
-
test('star 面板:渲染出 GitHub 仓库链接(各代通用)', () => {
|
|
80
|
-
const { mount } = runPanel('zh')
|
|
81
|
-
const links = find(mount, (e) => e.tagName === 'a' && /github\.com/.test(e.href || ''))
|
|
82
|
-
assert.ok(links.length >= 1, '至少一个仓库链接')
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('star 面板:10 语文案随 documentElement.lang 自选', () => {
|
|
86
|
-
const zh = find(runPanel('zh').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
87
|
-
const en = find(runPanel('en').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
88
|
-
const t = (arr) => arr.map((e) => e.textContent).join('|')
|
|
89
|
-
assert.notEqual(t(zh), t(en), 'zh 与 en 文案不同')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
if (GEN === 'v1') {
|
|
93
|
-
test('v1:★ CTA 只跳转不写键;× 才写 dismissed 并收起话术', () => {
|
|
94
|
-
const { mount, env } = runPanel('zh')
|
|
95
|
-
assert.equal(mount.className, 'dsh-star-row-s', 'v1 S 档行')
|
|
96
|
-
const cta = find(mount, (e) => e.className === 'dsh-star-cta')[0]
|
|
97
|
-
const hide = find(mount, (e) => e.className === 'dsh-star-hide')[0]
|
|
98
|
-
assert.ok(cta && hide, 'v1 应有 ★ 与 × 两个按钮')
|
|
99
|
-
cta.click()
|
|
100
|
-
assert.equal(env.localStorage.getItem(K1), null, '点 ★ 不写 dismissed')
|
|
101
|
-
hide.dispatch('click')
|
|
102
|
-
assert.equal(env.localStorage.getItem(K1), '1', '点 × 写 dismissed')
|
|
103
|
-
assert.ok(mount.parentNode === null || mount.className !== 'dsh-star-row-s', '× 后行被替换')
|
|
104
|
-
})
|
|
105
|
-
test('v1:已 dismissed → 只留中性链接行,无按钮', () => {
|
|
106
|
-
const { mount } = runPanel('zh', { [K1]: '1' })
|
|
107
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-cta').length, 0, 'dismissed 后无 ★')
|
|
108
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-hide').length, 0, 'dismissed 后无 ×')
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (GEN === 'v2') {
|
|
113
|
-
test('v2:纯链接一行页脚,无按钮;点 ⭐ 或 💬 即写 v2.dismissed 收敛', () => {
|
|
114
|
-
const { mount, env } = runPanel('zh')
|
|
115
|
-
assert.equal(mount.className, 'dsh-star-foot', 'v2 页脚行')
|
|
116
|
-
assert.equal(find(mount, (e) => e.tagName === 'button').length, 0, 'v2 无按钮')
|
|
117
|
-
const stars = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))
|
|
118
|
-
assert.ok(stars.length === 1, 'v2 一个 ⭐ 链接')
|
|
119
|
-
stars[0].click()
|
|
120
|
-
assert.equal(env.localStorage.getItem(K2), '1', '点 ⭐ 写 v2.dismissed')
|
|
121
|
-
})
|
|
122
|
-
test('v2:加载即清 v1 键、不迁值', () => {
|
|
123
|
-
const { env } = runPanel('zh', { [K1]: '1' })
|
|
124
|
-
assert.equal(env.localStorage.getItem(K1), null, 'v1 键被清掉')
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (GEN === 'v3') {
|
|
129
|
-
test('v3:两行页脚;⭐/💬 只跳转不收敛,只有「我已支持」写 v3.supported', () => {
|
|
130
|
-
const { mount, env } = runPanel('zh')
|
|
131
|
-
assert.equal(mount.className, 'dsh-star-foot', 'v3 页脚')
|
|
132
|
-
const btns = find(mount, (e) => e.className === 'dsh-star-support')
|
|
133
|
-
assert.equal(btns.length, 1, 'v3 一个「我已支持」按钮')
|
|
134
|
-
const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
|
|
135
|
-
star.click()
|
|
136
|
-
assert.equal(env.localStorage.getItem(K3), null, '点 ⭐ 不写 supported')
|
|
137
|
-
btns[0].dispatch('click')
|
|
138
|
-
assert.equal(env.localStorage.getItem(K3), '1', '按「我已支持」写 supported')
|
|
139
|
-
})
|
|
140
|
-
test('v3:加载即清 v1/v2 旧键、不迁值', () => {
|
|
141
|
-
const { env } = runPanel('zh', { [K1]: '1', [K2]: '1' })
|
|
142
|
-
assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
|
|
143
|
-
assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
|
|
144
|
-
})
|
|
145
|
-
test('v3:已 supported → 收敛态(仓库地址 + 💬 issue),无「我已支持」按钮', () => {
|
|
146
|
-
const { mount } = runPanel('zh', { [K3]: '1' })
|
|
147
|
-
assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v3 收敛态')
|
|
148
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-support').length, 0, '收敛后无按钮')
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
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'].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
|
+
|
|
79
|
+
test('star 面板:渲染出 GitHub 仓库链接(各代通用)', () => {
|
|
80
|
+
const { mount } = runPanel('zh')
|
|
81
|
+
const links = find(mount, (e) => e.tagName === 'a' && /github\.com/.test(e.href || ''))
|
|
82
|
+
assert.ok(links.length >= 1, '至少一个仓库链接')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('star 面板:10 语文案随 documentElement.lang 自选', () => {
|
|
86
|
+
const zh = find(runPanel('zh').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
87
|
+
const en = find(runPanel('en').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
88
|
+
const t = (arr) => arr.map((e) => e.textContent).join('|')
|
|
89
|
+
assert.notEqual(t(zh), t(en), 'zh 与 en 文案不同')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
if (GEN === 'v1') {
|
|
93
|
+
test('v1:★ CTA 只跳转不写键;× 才写 dismissed 并收起话术', () => {
|
|
94
|
+
const { mount, env } = runPanel('zh')
|
|
95
|
+
assert.equal(mount.className, 'dsh-star-row-s', 'v1 S 档行')
|
|
96
|
+
const cta = find(mount, (e) => e.className === 'dsh-star-cta')[0]
|
|
97
|
+
const hide = find(mount, (e) => e.className === 'dsh-star-hide')[0]
|
|
98
|
+
assert.ok(cta && hide, 'v1 应有 ★ 与 × 两个按钮')
|
|
99
|
+
cta.click()
|
|
100
|
+
assert.equal(env.localStorage.getItem(K1), null, '点 ★ 不写 dismissed')
|
|
101
|
+
hide.dispatch('click')
|
|
102
|
+
assert.equal(env.localStorage.getItem(K1), '1', '点 × 写 dismissed')
|
|
103
|
+
assert.ok(mount.parentNode === null || mount.className !== 'dsh-star-row-s', '× 后行被替换')
|
|
104
|
+
})
|
|
105
|
+
test('v1:已 dismissed → 只留中性链接行,无按钮', () => {
|
|
106
|
+
const { mount } = runPanel('zh', { [K1]: '1' })
|
|
107
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-cta').length, 0, 'dismissed 后无 ★')
|
|
108
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-hide').length, 0, 'dismissed 后无 ×')
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (GEN === 'v2') {
|
|
113
|
+
test('v2:纯链接一行页脚,无按钮;点 ⭐ 或 💬 即写 v2.dismissed 收敛', () => {
|
|
114
|
+
const { mount, env } = runPanel('zh')
|
|
115
|
+
assert.equal(mount.className, 'dsh-star-foot', 'v2 页脚行')
|
|
116
|
+
assert.equal(find(mount, (e) => e.tagName === 'button').length, 0, 'v2 无按钮')
|
|
117
|
+
const stars = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))
|
|
118
|
+
assert.ok(stars.length === 1, 'v2 一个 ⭐ 链接')
|
|
119
|
+
stars[0].click()
|
|
120
|
+
assert.equal(env.localStorage.getItem(K2), '1', '点 ⭐ 写 v2.dismissed')
|
|
121
|
+
})
|
|
122
|
+
test('v2:加载即清 v1 键、不迁值', () => {
|
|
123
|
+
const { env } = runPanel('zh', { [K1]: '1' })
|
|
124
|
+
assert.equal(env.localStorage.getItem(K1), null, 'v1 键被清掉')
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (GEN === 'v3') {
|
|
129
|
+
test('v3:两行页脚;⭐/💬 只跳转不收敛,只有「我已支持」写 v3.supported', () => {
|
|
130
|
+
const { mount, env } = runPanel('zh')
|
|
131
|
+
assert.equal(mount.className, 'dsh-star-foot', 'v3 页脚')
|
|
132
|
+
const btns = find(mount, (e) => e.className === 'dsh-star-support')
|
|
133
|
+
assert.equal(btns.length, 1, 'v3 一个「我已支持」按钮')
|
|
134
|
+
const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
|
|
135
|
+
star.click()
|
|
136
|
+
assert.equal(env.localStorage.getItem(K3), null, '点 ⭐ 不写 supported')
|
|
137
|
+
btns[0].dispatch('click')
|
|
138
|
+
assert.equal(env.localStorage.getItem(K3), '1', '按「我已支持」写 supported')
|
|
139
|
+
})
|
|
140
|
+
test('v3:加载即清 v1/v2 旧键、不迁值', () => {
|
|
141
|
+
const { env } = runPanel('zh', { [K1]: '1', [K2]: '1' })
|
|
142
|
+
assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
|
|
143
|
+
assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
|
|
144
|
+
})
|
|
145
|
+
test('v3:已 supported → 收敛态(仓库地址 + 💬 issue),无「我已支持」按钮', () => {
|
|
146
|
+
const { mount } = runPanel('zh', { [K3]: '1' })
|
|
147
|
+
assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v3 收敛态')
|
|
148
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-support').length, 0, '收敛后无按钮')
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
package/test/time.test.mjs
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 2 验收:时间引擎(事件层 + ETA 三档回落 + 协议收敛 + cooldown/stale)。
|
|
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, withClock } = 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
|
-
const tool = harness.toolMap.get('progress_update')
|
|
22
|
-
return tool.definition.execute(args, { agent: harness.agent })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function anchorOf(harness, atMs) {
|
|
26
|
-
return harness.provided.get('progressAnchor').get(SESSION, atMs)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
test('turn/start + step/start 驱动 steps/elapsed;无板无 todo 走 prior', async () => {
|
|
30
|
-
const harness = createHarness()
|
|
31
|
-
await harness.run()
|
|
32
|
-
harness.emit('turn/start', {})
|
|
33
|
-
for (let i = 0; i < 4; i++) harness.emit('step/start', {})
|
|
34
|
-
const started = anchorOf(harness).time.startedAt
|
|
35
|
-
assert.ok(started > 0)
|
|
36
|
-
const at = started + 60_000
|
|
37
|
-
const anchor = anchorOf(harness, at)
|
|
38
|
-
assert.equal(anchor.time.steps, 4)
|
|
39
|
-
assert.equal(anchor.time.elapsedSec, 60)
|
|
40
|
-
assert.equal(anchor.time.etaBasis, 'prior') // 临时 DSH_HOME 无学习样本
|
|
41
|
-
assert.equal(anchor.time.todoTotal, 0)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('board 档最优先:阶段取板、blocked 不计剩余', async () => {
|
|
45
|
-
const harness = await booted()
|
|
46
|
-
const added = await execUpdate(harness, {
|
|
47
|
-
changes: [
|
|
48
|
-
{ title: '甲', status: 'done' },
|
|
49
|
-
{ title: '乙', status: 'blocked', note: '等人确认' },
|
|
50
|
-
{ title: '丙', status: 'todo' },
|
|
51
|
-
],
|
|
52
|
-
})
|
|
53
|
-
harness.emit('turn/start', {})
|
|
54
|
-
const started = anchorOf(harness).time.startedAt
|
|
55
|
-
const at = started + 60_000 // elapsed 60s, done=1 → perItemSec=60, left=1(丙) → p50=60
|
|
56
|
-
const anchor = anchorOf(harness, at)
|
|
57
|
-
assert.equal(anchor.time.etaBasis, 'board')
|
|
58
|
-
assert.equal(anchor.time.elapsedSec, 60)
|
|
59
|
-
// p50=60 → remain=max(5,60-36)/60=0.4min → etaMin=max(0,round(.4))=0
|
|
60
|
-
assert.equal(anchor.time.etaMin, 0)
|
|
61
|
-
// inFlight 含 blocked(等人不是等时间,但要出现在锚点)
|
|
62
|
-
assert.deepEqual(anchor.board.inFlight.map((i) => i.status), ['blocked'])
|
|
63
|
-
assert.equal(anchor.board.summary.total, 3)
|
|
64
|
-
assert.equal(anchor.board.summary.done, 1)
|
|
65
|
-
void added
|
|
66
|
-
|
|
67
|
-
// /dsh-progress/status:板开时阶段直接取 items 标题(不再关键词猜测)
|
|
68
|
-
const res = await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })
|
|
69
|
-
const task = res.json().task
|
|
70
|
-
assert.deepEqual(task.stages, ['甲', '乙', '丙'])
|
|
71
|
-
assert.equal(task.boardDriven, true)
|
|
72
|
-
assert.equal(task.autoStage, false)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('todo 档:板关闭时用官方 todo 完成度', async () => {
|
|
76
|
-
const harness = createHarness()
|
|
77
|
-
await harness.run()
|
|
78
|
-
harness.emit('turn/start', {})
|
|
79
|
-
harness.emit('todo/write', { todos: [{ content: 'a', status: 'completed' }, { content: 'b', status: 'completed' }, { content: 'c', status: 'pending' }, { content: 'd', status: 'pending' }] })
|
|
80
|
-
const started = anchorOf(harness).time.startedAt
|
|
81
|
-
const at = started + 120_000 // perItemSec=60, left=2 → p50=120
|
|
82
|
-
const anchor = anchorOf(harness, at)
|
|
83
|
-
assert.equal(anchor.time.etaBasis, 'todo')
|
|
84
|
-
assert.equal(anchor.time.todoDone, 2)
|
|
85
|
-
assert.equal(anchor.time.todoTotal, 4)
|
|
86
|
-
// p50=120, elapsed=120 → max(5,120-72)=48s → etaMin=1
|
|
87
|
-
assert.equal(anchor.time.etaMin, 1)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('kickoff 冷却:全完成后一回合只推一次', async () => {
|
|
91
|
-
const harness = await booted()
|
|
92
|
-
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
|
|
93
|
-
const kickoff = harness.contexts.get('progress-union-kickoff')
|
|
94
|
-
const first = kickoff()
|
|
95
|
-
assert.match(first, /已全部完成/)
|
|
96
|
-
assert.equal(kickoff(), '', '60s 冷却内不得重复推')
|
|
97
|
-
void harness
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
test('stale:板开 13 分钟未更新 → anchor.time.staleMin ≥ 11', async () => {
|
|
101
|
-
const harness = await booted()
|
|
102
|
-
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing', current: '在做' }] })
|
|
103
|
-
const base = Date.now()
|
|
104
|
-
const anchor = anchorOf(harness, base + 13 * 60 * 1000)
|
|
105
|
-
assert.equal(anchor.time.staleMin, 13)
|
|
106
|
-
assert.equal(anchor.board.inFlight[0].status, 'doing')
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('单协议收敛:板开不注入文件上报协议,板关注入且 kind=plugin:dsh-progress-union', async () => {
|
|
110
|
-
const clock = withClock()
|
|
111
|
-
try {
|
|
112
|
-
// 板开
|
|
113
|
-
const on = await booted()
|
|
114
|
-
const preStep = on.agentHooks.find((h) => h.type === 'agent/pre-step')
|
|
115
|
-
assert.ok(preStep, 'agent/created 应装 pre-step 钩子')
|
|
116
|
-
const freshUser = { source: { kind: 'user' } }
|
|
117
|
-
const decision = { kind: 'enter', messages: [freshUser] }
|
|
118
|
-
const out = await preStep.handler({ messages: [freshUser] }, async () => decision)
|
|
119
|
-
assert.equal(out.messages.length, 1, '板开时不得追加协议消息')
|
|
120
|
-
|
|
121
|
-
// 板关(全新 harness 不启用)
|
|
122
|
-
const off = createHarness()
|
|
123
|
-
await off.run()
|
|
124
|
-
const preStepOff = off.agentHooks.find((h) => h.type === 'agent/pre-step')
|
|
125
|
-
const decisionOff = { kind: 'enter', messages: [{ source: { kind: 'user' } }] }
|
|
126
|
-
const outOff = await preStepOff.handler({ messages: [{ source: { kind: 'user' } }] }, async () => decisionOff)
|
|
127
|
-
assert.equal(outOff.messages.length, 2)
|
|
128
|
-
const injected = outOff.messages[1]
|
|
129
|
-
assert.equal(injected.source.kind, 'plugin:dsh-progress-union')
|
|
130
|
-
assert.match(injected.content[0].text, /dsh-progress/)
|
|
131
|
-
} finally {
|
|
132
|
-
clock.restore()
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
test('turn/end 收任务并学样本;结束后锚点时间层归零但不丢 steps', async () => {
|
|
137
|
-
const harness = createHarness()
|
|
138
|
-
await harness.run()
|
|
139
|
-
harness.emit('turn/start', {})
|
|
140
|
-
harness.emit('step/start', {})
|
|
141
|
-
harness.emit('step/start', {})
|
|
142
|
-
harness.emit('turn/end', {})
|
|
143
|
-
const anchor = anchorOf(harness, Date.now() + 3600_000)
|
|
144
|
-
assert.equal(anchor.time.startedAt, 0, '任务已结束不应再给进行中锚')
|
|
145
|
-
assert.equal(anchor.time.etaBasis, 'none')
|
|
146
|
-
assert.equal(anchor.time.elapsedSec, 0)
|
|
147
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 验收:时间引擎(事件层 + ETA 三档回落 + 协议收敛 + cooldown/stale)。
|
|
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, withClock } = 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
|
+
const tool = harness.toolMap.get('progress_update')
|
|
22
|
+
return tool.definition.execute(args, { agent: harness.agent })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function anchorOf(harness, atMs) {
|
|
26
|
+
return harness.provided.get('progressAnchor').get(SESSION, atMs)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('turn/start + step/start 驱动 steps/elapsed;无板无 todo 走 prior', async () => {
|
|
30
|
+
const harness = createHarness()
|
|
31
|
+
await harness.run()
|
|
32
|
+
harness.emit('turn/start', {})
|
|
33
|
+
for (let i = 0; i < 4; i++) harness.emit('step/start', {})
|
|
34
|
+
const started = anchorOf(harness).time.startedAt
|
|
35
|
+
assert.ok(started > 0)
|
|
36
|
+
const at = started + 60_000
|
|
37
|
+
const anchor = anchorOf(harness, at)
|
|
38
|
+
assert.equal(anchor.time.steps, 4)
|
|
39
|
+
assert.equal(anchor.time.elapsedSec, 60)
|
|
40
|
+
assert.equal(anchor.time.etaBasis, 'prior') // 临时 DSH_HOME 无学习样本
|
|
41
|
+
assert.equal(anchor.time.todoTotal, 0)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('board 档最优先:阶段取板、blocked 不计剩余', async () => {
|
|
45
|
+
const harness = await booted()
|
|
46
|
+
const added = await execUpdate(harness, {
|
|
47
|
+
changes: [
|
|
48
|
+
{ title: '甲', status: 'done' },
|
|
49
|
+
{ title: '乙', status: 'blocked', note: '等人确认' },
|
|
50
|
+
{ title: '丙', status: 'todo' },
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
harness.emit('turn/start', {})
|
|
54
|
+
const started = anchorOf(harness).time.startedAt
|
|
55
|
+
const at = started + 60_000 // elapsed 60s, done=1 → perItemSec=60, left=1(丙) → p50=60
|
|
56
|
+
const anchor = anchorOf(harness, at)
|
|
57
|
+
assert.equal(anchor.time.etaBasis, 'board')
|
|
58
|
+
assert.equal(anchor.time.elapsedSec, 60)
|
|
59
|
+
// p50=60 → remain=max(5,60-36)/60=0.4min → etaMin=max(0,round(.4))=0
|
|
60
|
+
assert.equal(anchor.time.etaMin, 0)
|
|
61
|
+
// inFlight 含 blocked(等人不是等时间,但要出现在锚点)
|
|
62
|
+
assert.deepEqual(anchor.board.inFlight.map((i) => i.status), ['blocked'])
|
|
63
|
+
assert.equal(anchor.board.summary.total, 3)
|
|
64
|
+
assert.equal(anchor.board.summary.done, 1)
|
|
65
|
+
void added
|
|
66
|
+
|
|
67
|
+
// /dsh-progress/status:板开时阶段直接取 items 标题(不再关键词猜测)
|
|
68
|
+
const res = await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })
|
|
69
|
+
const task = res.json().task
|
|
70
|
+
assert.deepEqual(task.stages, ['甲', '乙', '丙'])
|
|
71
|
+
assert.equal(task.boardDriven, true)
|
|
72
|
+
assert.equal(task.autoStage, false)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('todo 档:板关闭时用官方 todo 完成度', async () => {
|
|
76
|
+
const harness = createHarness()
|
|
77
|
+
await harness.run()
|
|
78
|
+
harness.emit('turn/start', {})
|
|
79
|
+
harness.emit('todo/write', { todos: [{ content: 'a', status: 'completed' }, { content: 'b', status: 'completed' }, { content: 'c', status: 'pending' }, { content: 'd', status: 'pending' }] })
|
|
80
|
+
const started = anchorOf(harness).time.startedAt
|
|
81
|
+
const at = started + 120_000 // perItemSec=60, left=2 → p50=120
|
|
82
|
+
const anchor = anchorOf(harness, at)
|
|
83
|
+
assert.equal(anchor.time.etaBasis, 'todo')
|
|
84
|
+
assert.equal(anchor.time.todoDone, 2)
|
|
85
|
+
assert.equal(anchor.time.todoTotal, 4)
|
|
86
|
+
// p50=120, elapsed=120 → max(5,120-72)=48s → etaMin=1
|
|
87
|
+
assert.equal(anchor.time.etaMin, 1)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('kickoff 冷却:全完成后一回合只推一次', async () => {
|
|
91
|
+
const harness = await booted()
|
|
92
|
+
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
|
|
93
|
+
const kickoff = harness.contexts.get('progress-union-kickoff')
|
|
94
|
+
const first = kickoff()
|
|
95
|
+
assert.match(first, /已全部完成/)
|
|
96
|
+
assert.equal(kickoff(), '', '60s 冷却内不得重复推')
|
|
97
|
+
void harness
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('stale:板开 13 分钟未更新 → anchor.time.staleMin ≥ 11', async () => {
|
|
101
|
+
const harness = await booted()
|
|
102
|
+
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing', current: '在做' }] })
|
|
103
|
+
const base = Date.now()
|
|
104
|
+
const anchor = anchorOf(harness, base + 13 * 60 * 1000)
|
|
105
|
+
assert.equal(anchor.time.staleMin, 13)
|
|
106
|
+
assert.equal(anchor.board.inFlight[0].status, 'doing')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('单协议收敛:板开不注入文件上报协议,板关注入且 kind=plugin:dsh-progress-union', async () => {
|
|
110
|
+
const clock = withClock()
|
|
111
|
+
try {
|
|
112
|
+
// 板开
|
|
113
|
+
const on = await booted()
|
|
114
|
+
const preStep = on.agentHooks.find((h) => h.type === 'agent/pre-step')
|
|
115
|
+
assert.ok(preStep, 'agent/created 应装 pre-step 钩子')
|
|
116
|
+
const freshUser = { source: { kind: 'user' } }
|
|
117
|
+
const decision = { kind: 'enter', messages: [freshUser] }
|
|
118
|
+
const out = await preStep.handler({ messages: [freshUser] }, async () => decision)
|
|
119
|
+
assert.equal(out.messages.length, 1, '板开时不得追加协议消息')
|
|
120
|
+
|
|
121
|
+
// 板关(全新 harness 不启用)
|
|
122
|
+
const off = createHarness()
|
|
123
|
+
await off.run()
|
|
124
|
+
const preStepOff = off.agentHooks.find((h) => h.type === 'agent/pre-step')
|
|
125
|
+
const decisionOff = { kind: 'enter', messages: [{ source: { kind: 'user' } }] }
|
|
126
|
+
const outOff = await preStepOff.handler({ messages: [{ source: { kind: 'user' } }] }, async () => decisionOff)
|
|
127
|
+
assert.equal(outOff.messages.length, 2)
|
|
128
|
+
const injected = outOff.messages[1]
|
|
129
|
+
assert.equal(injected.source.kind, 'plugin:dsh-progress-union')
|
|
130
|
+
assert.match(injected.content[0].text, /dsh-progress/)
|
|
131
|
+
} finally {
|
|
132
|
+
clock.restore()
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('turn/end 收任务并学样本;结束后锚点时间层归零但不丢 steps', async () => {
|
|
137
|
+
const harness = createHarness()
|
|
138
|
+
await harness.run()
|
|
139
|
+
harness.emit('turn/start', {})
|
|
140
|
+
harness.emit('step/start', {})
|
|
141
|
+
harness.emit('step/start', {})
|
|
142
|
+
harness.emit('turn/end', {})
|
|
143
|
+
const anchor = anchorOf(harness, Date.now() + 3600_000)
|
|
144
|
+
assert.equal(anchor.time.startedAt, 0, '任务已结束不应再给进行中锚')
|
|
145
|
+
assert.equal(anchor.time.etaBasis, 'none')
|
|
146
|
+
assert.equal(anchor.time.elapsedSec, 0)
|
|
147
|
+
})
|