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
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 入口开关守卫(0.5.12):快捷入口在板已经展开时必须能把它连同右栏一起收起来。
|
|
3
|
+
*
|
|
4
|
+
* 现场两轮:0.5.10 点头部图标「没反应」(只 openTab);0.5.11 改成只折叠整栏,
|
|
5
|
+
* 于是用户再展开右栏发现板还在——「收起」并没有真的关掉板。契约:
|
|
6
|
+
* - 右栏正停在本板页签 → close(KIND) 模拟点页签上的 ×,再 toggleExpanded()
|
|
7
|
+
* 收起整栏;已自动折叠就不再翻回展开;不再 openTab;
|
|
8
|
+
* - 右栏展开但停在别的页签 → openTab()(把本板切到前台),不动展开态,不关别人;
|
|
9
|
+
* - better-sidebar 工作台停在本板 → closeTab(BS_TAB_ID)(软面,独立);
|
|
10
|
+
* - 板没在眼前 → openTab()。
|
|
11
|
+
* 判据全部是「问不出来就当没展开」,软面抛错不拖累宿主右栏那一路。
|
|
12
|
+
*/
|
|
13
|
+
import assert from 'node:assert/strict'
|
|
14
|
+
import fs from 'node:fs'
|
|
15
|
+
import test from 'node:test'
|
|
16
|
+
import vm from 'node:vm'
|
|
17
|
+
import { fileURLToPath } from 'node:url'
|
|
18
|
+
|
|
19
|
+
const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
20
|
+
const KIND = 'progress-union'
|
|
21
|
+
const BS_ID = 'dsh-progress-union:board'
|
|
22
|
+
|
|
23
|
+
function noop() {}
|
|
24
|
+
|
|
25
|
+
function requireStub(specifier) {
|
|
26
|
+
if (specifier === 'react') {
|
|
27
|
+
return {
|
|
28
|
+
createElement: (...args) => ({ __el: args }),
|
|
29
|
+
Fragment: 'fragment',
|
|
30
|
+
useState: (value) => [value, noop],
|
|
31
|
+
useEffect: noop,
|
|
32
|
+
useMemo: (factory) => factory(),
|
|
33
|
+
useCallback: (factory) => factory,
|
|
34
|
+
useRef: (value) => ({ current: value }),
|
|
35
|
+
Component: class {},
|
|
36
|
+
memo: (component) => component,
|
|
37
|
+
forwardRef: (component) => component,
|
|
38
|
+
createContext: () => ({ Provider: 'provider' }),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (specifier === 'react-dom') return { render: noop, createRoot: () => ({ render: noop, unmount: noop }) }
|
|
42
|
+
return { jsx: () => ({}), jsxs: () => ({}), Fragment: 'fragment' }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function materialize() {
|
|
46
|
+
const definitions = []
|
|
47
|
+
const storage = { getItem: () => null, setItem: noop, removeItem: noop }
|
|
48
|
+
const window = {
|
|
49
|
+
__ModuleLoader__: { load: (definition) => definitions.push(definition) },
|
|
50
|
+
localStorage: storage,
|
|
51
|
+
sessionStorage: storage,
|
|
52
|
+
addEventListener: noop,
|
|
53
|
+
removeEventListener: noop,
|
|
54
|
+
matchMedia: () => ({ matches: false, addEventListener: noop, removeEventListener: noop }),
|
|
55
|
+
location: { href: 'http://127.0.0.1/' },
|
|
56
|
+
navigator: { language: 'zh-CN' },
|
|
57
|
+
}
|
|
58
|
+
const document = {
|
|
59
|
+
createElement: () => ({ style: {}, setAttribute: noop, appendChild: noop, classList: { add: noop, remove: noop } }),
|
|
60
|
+
createTextNode: () => ({}),
|
|
61
|
+
head: { appendChild: noop, removeChild: noop },
|
|
62
|
+
body: { appendChild: noop, removeChild: noop },
|
|
63
|
+
documentElement: { dataset: {}, style: {} },
|
|
64
|
+
addEventListener: noop,
|
|
65
|
+
removeEventListener: noop,
|
|
66
|
+
querySelector: () => null,
|
|
67
|
+
querySelectorAll: () => [],
|
|
68
|
+
getElementById: () => null,
|
|
69
|
+
}
|
|
70
|
+
const sandbox = {
|
|
71
|
+
window,
|
|
72
|
+
document,
|
|
73
|
+
localStorage: storage,
|
|
74
|
+
sessionStorage: storage,
|
|
75
|
+
navigator: { language: 'zh-CN' },
|
|
76
|
+
fetch: () => Promise.resolve({ ok: true, json: () => Promise.resolve({}) }),
|
|
77
|
+
console,
|
|
78
|
+
setTimeout,
|
|
79
|
+
clearTimeout,
|
|
80
|
+
setInterval,
|
|
81
|
+
clearInterval,
|
|
82
|
+
queueMicrotask,
|
|
83
|
+
URL,
|
|
84
|
+
URLSearchParams,
|
|
85
|
+
TextEncoder,
|
|
86
|
+
TextDecoder,
|
|
87
|
+
CustomEvent: class { constructor(type, init) { this.type = type; this.detail = init && init.detail } },
|
|
88
|
+
Event: class { constructor(type) { this.type = type } },
|
|
89
|
+
crypto: { randomUUID: () => 'stub-uuid' },
|
|
90
|
+
}
|
|
91
|
+
sandbox.globalThis = sandbox
|
|
92
|
+
sandbox.self = sandbox
|
|
93
|
+
const context = vm.createContext(sandbox)
|
|
94
|
+
vm.runInContext(fs.readFileSync(clientFile, 'utf8'), context, { filename: 'client.js' })
|
|
95
|
+
return definitions
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function boot(options = {}) {
|
|
99
|
+
const calls = { openTab: [], toggleExpanded: 0, closeTab: [], close: [], headerEntries: [] }
|
|
100
|
+
const betterSidebar = options.betterSidebar
|
|
101
|
+
const ctx = {
|
|
102
|
+
effect: (fn) => {
|
|
103
|
+
const disposer = fn()
|
|
104
|
+
return typeof disposer === 'function' ? disposer : noop
|
|
105
|
+
},
|
|
106
|
+
get: () => undefined,
|
|
107
|
+
locale: { register: () => noop, bind: () => (key) => key },
|
|
108
|
+
slots: {
|
|
109
|
+
inject: (name, cb) => cb(),
|
|
110
|
+
register: (opts) => {
|
|
111
|
+
if (opts.name === 'conversation.session.header.utilities') calls.headerEntries.push(opts)
|
|
112
|
+
return noop
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
sidebarRight: {
|
|
116
|
+
openTab: (kind) => calls.openTab.push(kind),
|
|
117
|
+
focus: noop,
|
|
118
|
+
active: () => options.active,
|
|
119
|
+
isExpanded: () => options.expanded === true,
|
|
120
|
+
toggleExpanded: () => { calls.toggleExpanded += 1 },
|
|
121
|
+
close: (kind) => calls.close.push(kind),
|
|
122
|
+
},
|
|
123
|
+
sidebarRightTabs: { register: () => noop },
|
|
124
|
+
sessions: { binding: () => undefined },
|
|
125
|
+
inject: (deps, cb) => {
|
|
126
|
+
if (Array.isArray(deps) && deps.includes('betterSidebar') && betterSidebar) {
|
|
127
|
+
cb({ betterSidebar, effect: (fn) => fn() })
|
|
128
|
+
}
|
|
129
|
+
return noop
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
const exported = materialize()[0].factory(requireStub)
|
|
133
|
+
exported.apply(ctx)
|
|
134
|
+
const header = calls.headerEntries[0]
|
|
135
|
+
assert.ok(header, '头部入口必须注册')
|
|
136
|
+
return { calls, header }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
test('头部入口注入开关本身,而不是只会打开的 openTab', () => {
|
|
140
|
+
const { header } = boot({})
|
|
141
|
+
const injected = header.inject()
|
|
142
|
+
assert.equal(typeof injected.togglePanel, 'function', '头部入口必须拿到 togglePanel')
|
|
143
|
+
assert.equal(typeof injected.openPanel, 'function', '保留 openPanel 作为兜底')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('板已在右栏展开:先模拟点掉页签上的 ×,再收起整栏,不再重复 openTab', () => {
|
|
147
|
+
const { calls, header } = boot({ expanded: true, active: { id: 'dsh-progress-union', kind: KIND } })
|
|
148
|
+
header.inject().togglePanel()
|
|
149
|
+
assert.deepEqual(calls.close, [KIND], '必须像点 × 一样把本板页签关掉(否则下次展开又看见它)')
|
|
150
|
+
assert.equal(calls.toggleExpanded, 1, '收起整栏')
|
|
151
|
+
assert.deepEqual(calls.openTab, [], '可见时不得再开一次')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('板是活动页签但右栏已折叠:入口只关页签,不反手展开整栏', () => {
|
|
155
|
+
const { calls, header } = boot({ expanded: false, active: { id: 'dsh-progress-union', kind: KIND } })
|
|
156
|
+
header.inject().togglePanel()
|
|
157
|
+
assert.deepEqual(calls.close, [KIND], '板还在页签里就要关掉')
|
|
158
|
+
assert.equal(calls.toggleExpanded, 0, '已折叠时不得再 toggle(会翻回展开)')
|
|
159
|
+
assert.deepEqual(calls.openTab, [], '不得再开一次')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('右栏停在别的页签:入口把本板切到前台,不动展开态', () => {
|
|
163
|
+
const { calls, header } = boot({ expanded: true, active: { id: 'files', kind: 'files' } })
|
|
164
|
+
header.inject().togglePanel()
|
|
165
|
+
assert.deepEqual(calls.openTab, [KIND])
|
|
166
|
+
assert.deepEqual(calls.close, [], '别的页签展开时不得关掉本板页签')
|
|
167
|
+
assert.equal(calls.toggleExpanded, 0, '别的页签展开时不得整栏收起')
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('右栏收起时:入口打开本板', () => {
|
|
171
|
+
const { calls, header } = boot({ expanded: false, active: undefined })
|
|
172
|
+
header.inject().togglePanel()
|
|
173
|
+
assert.deepEqual(calls.openTab, [KIND])
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
test('better-sidebar 工作台停在本板:入口收起那一面(软依赖,不误伤右栏)', () => {
|
|
177
|
+
const betterSidebar = {
|
|
178
|
+
registerTab: () => noop,
|
|
179
|
+
getSnapshot: () => ({
|
|
180
|
+
state: { bottomOpen: true, bottomSplits: { kind: 'leaf', tabs: [{ id: BS_ID }], active: BS_ID } },
|
|
181
|
+
}),
|
|
182
|
+
closeTab: (id) => { closeCalls.push(id) },
|
|
183
|
+
}
|
|
184
|
+
const closeCalls = []
|
|
185
|
+
const { calls, header } = boot({ expanded: true, active: { id: 'files', kind: 'files' }, betterSidebar })
|
|
186
|
+
header.inject().togglePanel()
|
|
187
|
+
assert.deepEqual(closeCalls, [BS_ID], '工作台上的本板必须被关掉')
|
|
188
|
+
assert.deepEqual(calls.close, [], '不得顺手关掉宿主右栏的页签')
|
|
189
|
+
assert.equal(calls.toggleExpanded, 0, '不得顺手收起宿主右栏')
|
|
190
|
+
assert.deepEqual(calls.openTab, [], '收起后不得再开一次')
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('better-sidebar 工作台收起/停在别的页签:入口回到宿主右栏那一路', () => {
|
|
194
|
+
for (const state of [
|
|
195
|
+
{ bottomOpen: false, bottomSplits: { kind: 'leaf', tabs: [{ id: BS_ID }], active: BS_ID } },
|
|
196
|
+
{ bottomOpen: true, bottomSplits: { kind: 'leaf', tabs: [{ id: 'editor:a.js' }], active: 'editor:a.js' } },
|
|
197
|
+
]) {
|
|
198
|
+
const closeCalls = []
|
|
199
|
+
const betterSidebar = { registerTab: () => noop, getSnapshot: () => ({ state }), closeTab: (id) => closeCalls.push(id) }
|
|
200
|
+
const { calls, header } = boot({ expanded: false, betterSidebar })
|
|
201
|
+
header.inject().togglePanel()
|
|
202
|
+
assert.deepEqual(closeCalls, [], '不该关别的东西')
|
|
203
|
+
assert.deepEqual(calls.openTab, [KIND], '仍要能打开宿主右栏的本板')
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
test('better-sidebar 半面抛错:入口不哑,回落到宿主右栏', () => {
|
|
208
|
+
const betterSidebar = {
|
|
209
|
+
registerTab: () => noop,
|
|
210
|
+
getSnapshot: () => { throw new Error('boom') },
|
|
211
|
+
closeTab: () => { throw new Error('boom') },
|
|
212
|
+
}
|
|
213
|
+
const { calls, header } = boot({ expanded: false, betterSidebar })
|
|
214
|
+
header.inject().togglePanel()
|
|
215
|
+
assert.deepEqual(calls.openTab, [KIND])
|
|
216
|
+
})
|
package/test/goal-drive.test.mjs
CHANGED
|
@@ -176,23 +176,23 @@ test('重启自愈:armed 目标在会话重新挂载时自动补点火(无
|
|
|
176
176
|
assert.equal(restarted.agent.followups[0].source.round, 2)
|
|
177
177
|
})
|
|
178
178
|
|
|
179
|
-
test('重启自愈:上一次进程遗留的排队轮次被清掉并重排(否则它既不跑又挡新轮)', async () => {
|
|
180
|
-
const h = await booted()
|
|
181
|
-
await update(h, [{ title: 't1', status: 'doing' }])
|
|
182
|
-
await goalCmd(h, '目标S')
|
|
183
|
-
const stranded = h.claim(h.agent.followups[0]) // 崩在「已排队、未执行」之间
|
|
184
|
-
|
|
185
|
-
// 用同一份持久化记录重开宿主:attempt 空,但 inbox 里还留着上一轮
|
|
186
|
-
const restarted = await booted({}, { seed: h.records })
|
|
187
|
-
restarted.agent.inbox.nextTurn.push(stranded)
|
|
188
|
-
await new Promise((resolve) => setTimeout(resolve, 2800))
|
|
189
|
-
|
|
190
|
-
assert.equal(restarted.agent.followups.length, 1, '重启后必须重排一轮')
|
|
191
|
-
assert.equal(restarted.agent.inbox.nextTurn.includes(stranded), false, '孤儿轮次必须被撤掉')
|
|
192
|
-
assert.equal(restarted.agent.inbox.nextTurn.length, 1)
|
|
193
|
-
assert.notEqual(restarted.agent.inbox.nextTurn[0].id, stranded.id)
|
|
194
|
-
})
|
|
195
|
-
|
|
179
|
+
test('重启自愈:上一次进程遗留的排队轮次被清掉并重排(否则它既不跑又挡新轮)', async () => {
|
|
180
|
+
const h = await booted()
|
|
181
|
+
await update(h, [{ title: 't1', status: 'doing' }])
|
|
182
|
+
await goalCmd(h, '目标S')
|
|
183
|
+
const stranded = h.claim(h.agent.followups[0]) // 崩在「已排队、未执行」之间
|
|
184
|
+
|
|
185
|
+
// 用同一份持久化记录重开宿主:attempt 空,但 inbox 里还留着上一轮
|
|
186
|
+
const restarted = await booted({}, { seed: h.records })
|
|
187
|
+
restarted.agent.inbox.nextTurn.push(stranded)
|
|
188
|
+
await new Promise((resolve) => setTimeout(resolve, 2800))
|
|
189
|
+
|
|
190
|
+
assert.equal(restarted.agent.followups.length, 1, '重启后必须重排一轮')
|
|
191
|
+
assert.equal(restarted.agent.inbox.nextTurn.includes(stranded), false, '孤儿轮次必须被撤掉')
|
|
192
|
+
assert.equal(restarted.agent.inbox.nextTurn.length, 1)
|
|
193
|
+
assert.notEqual(restarted.agent.inbox.nextTurn[0].id, stranded.id)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
196
|
test('resume 接受 active:重新武装 + 点火', async () => {
|
|
197
197
|
const h = await booted()
|
|
198
198
|
await update(h, [{ title: 't1', status: 'doing' }])
|