dsh-ris-ide 1.7.0 → 1.7.1
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/README.md +3 -3
- package/lib/client.js +729 -77
- package/lib/index.js +1091 -49
- package/lib/standalone/window.html +89 -14
- package/package.json +1 -1
- package/skills/dsh-ris-ide-debug/SKILL.md +2 -2
- package/test/client-viewer.test.mjs +297 -29
- package/test/clipboard.test.mjs +254 -0
- package/test/host-tail.test.mjs +136 -21
- package/test/windows.test.mjs +198 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standalone IDE window across a `dsh web` restart.
|
|
3
|
+
*
|
|
4
|
+
* The window page is never reloaded by a restart, so it must (a) stay registered
|
|
5
|
+
* with the host without any stored state — its stream IS the registration — and
|
|
6
|
+
* (b) follow the session the workspace is on now, because the id in its URL died
|
|
7
|
+
* with the old host. The DSH page, in turn, must find that window instead of
|
|
8
|
+
* opening a second one. These tests pin the registry contract, the session lookup
|
|
9
|
+
* and the client-side wiring (a real window belongs to the developer's desktop,
|
|
10
|
+
* not to CI).
|
|
11
|
+
*/
|
|
12
|
+
import { test } from 'node:test'
|
|
13
|
+
import assert from 'node:assert/strict'
|
|
14
|
+
import { createServer } from 'node:http'
|
|
15
|
+
import { readFile } from 'node:fs/promises'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
|
|
18
|
+
import { __test } from '../lib/index.js'
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
WINDOWS_PATH,
|
|
22
|
+
listIdeWindows,
|
|
23
|
+
liveSessionFor,
|
|
24
|
+
ideWindowOpened,
|
|
25
|
+
ideWindowClosed,
|
|
26
|
+
serveWindows,
|
|
27
|
+
} = __test
|
|
28
|
+
|
|
29
|
+
const clientSource = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
30
|
+
const hostSource = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
|
|
31
|
+
const windowHtml = await readFile(new URL('../lib/standalone/window.html', import.meta.url), 'utf8')
|
|
32
|
+
|
|
33
|
+
function serve(handler) {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
const server = createServer((req, res) => { void handler(req, res) })
|
|
36
|
+
server.listen(0, '127.0.0.1', () => resolve(server))
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function addressOf(server) {
|
|
41
|
+
const info = server.address()
|
|
42
|
+
return `http://127.0.0.1:${info.port}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
test('the window route is one GET under the plugin prefix', () => {
|
|
46
|
+
assert.equal(WINDOWS_PATH, '/dsh-ris-ide/windows')
|
|
47
|
+
assert.equal(typeof serveWindows, 'function')
|
|
48
|
+
const source = clientSource
|
|
49
|
+
assert.match(source, /routeUrl\('dsh-ris-ide\/windows'\)/, 'the client asks the host before opening a window')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('a window is alive while its stream is open, and known by its name', () => {
|
|
53
|
+
const name = 'name:test-alive-window'
|
|
54
|
+
ideWindowOpened(name, { name: 'test-alive-window', cwd: '/tmp/test-alive-window', sessionId: 's1' })
|
|
55
|
+
const live = listIdeWindows({ name: 'test-alive-window' })
|
|
56
|
+
assert.equal(live.length, 1)
|
|
57
|
+
assert.equal(live[0].alive, true, 'an open stream means the window is there')
|
|
58
|
+
assert.equal(live[0].sessionId, 's1')
|
|
59
|
+
ideWindowClosed(name)
|
|
60
|
+
const idle = listIdeWindows({ name: 'test-alive-window' })
|
|
61
|
+
assert.equal(idle.length, 1, 'the entry survives a short disconnect (a reload)')
|
|
62
|
+
assert.equal(idle[0].alive, false)
|
|
63
|
+
assert.equal(listIdeWindows({ name: 'no-such-window' }).length, 0)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('two streams of one window count twice, so one close does not end it', () => {
|
|
67
|
+
const name = 'name:test-two-streams'
|
|
68
|
+
ideWindowOpened(name, { name: 'test-two-streams', cwd: '/tmp/test-two-streams', sessionId: 's2' })
|
|
69
|
+
ideWindowOpened(name, { name: 'test-two-streams', cwd: '/tmp/test-two-streams', sessionId: 's2' })
|
|
70
|
+
ideWindowClosed(name)
|
|
71
|
+
assert.equal(listIdeWindows({ name: 'test-two-streams' })[0].alive, true, 'the second stream still holds it')
|
|
72
|
+
ideWindowClosed(name)
|
|
73
|
+
assert.equal(listIdeWindows({ name: 'test-two-streams' })[0].alive, false)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('windows without a name fall back to their workspace as the key', () => {
|
|
77
|
+
const cwd = join('/tmp', 'test-unnamed-window')
|
|
78
|
+
const name = 'cwd:' + cwd
|
|
79
|
+
ideWindowOpened(name, { cwd, sessionId: 's3' })
|
|
80
|
+
const found = listIdeWindows({ cwd })
|
|
81
|
+
assert.equal(found.length, 1)
|
|
82
|
+
assert.equal(found[0].alive, true)
|
|
83
|
+
assert.equal(found[0].name, '')
|
|
84
|
+
ideWindowClosed(name)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('the workspace session is the newest live one in that cwd', () => {
|
|
88
|
+
const cwd = '/tmp/test-session-workspace'
|
|
89
|
+
const ctx = {
|
|
90
|
+
sessions: {
|
|
91
|
+
list: () => [
|
|
92
|
+
{ id: 'old', header: { cwd } },
|
|
93
|
+
{ id: 'other', header: { cwd: '/tmp/elsewhere' } },
|
|
94
|
+
{ id: 'new', header: { cwd } },
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
assert.deepEqual(liveSessionFor(ctx, cwd), { id: 'new' }, 'the newest session wins')
|
|
99
|
+
assert.equal(liveSessionFor(ctx, '/tmp/nothing-here'), null)
|
|
100
|
+
assert.deepEqual(liveSessionFor(ctx, '/tmp/test-session-workspace/sub/program'), { id: 'new' },
|
|
101
|
+
'the IDE is workspace-level: a window inside a program folder still follows the workspace session')
|
|
102
|
+
assert.deepEqual(liveSessionFor({ sessions: { list: () => [{ id: 'outer', header: { cwd: '/tmp' } }] } }, '/tmp/elsewhere/x'), { id: 'outer' },
|
|
103
|
+
'an ancestor session is better than nothing')
|
|
104
|
+
assert.equal(liveSessionFor(undefined, cwd), null, 'a host without the service answers nothing')
|
|
105
|
+
assert.equal(liveSessionFor({ sessions: { list: () => { throw new Error('detached') } } }, cwd), null)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('the windows route answers the registry, and rejects a relative cwd', async () => {
|
|
109
|
+
const ctx = {
|
|
110
|
+
sessions: { list: () => [{ id: 'live-1', header: { cwd: '/tmp/test-route-workspace' } }] },
|
|
111
|
+
}
|
|
112
|
+
const server = await serve((req, res) => serveWindows(ctx, req, res))
|
|
113
|
+
try {
|
|
114
|
+
const base = addressOf(server)
|
|
115
|
+
const ok = await fetch(base + WINDOWS_PATH + '?name=name%3Atest-route-window&cwd=' + encodeURIComponent('/tmp/test-route-workspace'))
|
|
116
|
+
assert.equal(ok.status, 200)
|
|
117
|
+
const payload = await ok.json()
|
|
118
|
+
assert.equal(payload.ok, true)
|
|
119
|
+
assert.ok(Array.isArray(payload.windows))
|
|
120
|
+
assert.deepEqual(payload.session, { id: 'live-1' }, 'the route also names the live session of that cwd')
|
|
121
|
+
|
|
122
|
+
const bad = await fetch(base + WINDOWS_PATH + '?cwd=relative%2Fpath')
|
|
123
|
+
assert.equal(bad.status, 400)
|
|
124
|
+
assert.match((await bad.json()).message, /absolute workspace path/)
|
|
125
|
+
|
|
126
|
+
const unnamed = await fetch(base + WINDOWS_PATH)
|
|
127
|
+
assert.equal(unnamed.status, 200)
|
|
128
|
+
assert.equal((await unnamed.json()).session, null, 'no cwd, no session lookup')
|
|
129
|
+
} finally {
|
|
130
|
+
// fetch keeps its socket alive, and a plain close() would wait for it.
|
|
131
|
+
server.closeAllConnections?.()
|
|
132
|
+
server.close()
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('the standalone window registers itself and follows the live session', () => {
|
|
137
|
+
assert.match(clientSource, /url\.searchParams\.set\('window', '1'\)/, 'the stream says it is a window')
|
|
138
|
+
assert.match(clientSource, /url\.searchParams\.set\('wname', window\.__dshRisIdeWindowName\)/, 'and which window it is')
|
|
139
|
+
assert.match(clientSource, /window\.__dshRisIdeWindowName = typeof opts\.windowName === 'string' \? opts\.windowName : ''/)
|
|
140
|
+
assert.match(clientSource, /function StandaloneWindow\(props\)/, 'the window root owns the scope')
|
|
141
|
+
assert.match(clientSource, /topics: \['hello'\]/, 'it listens for the host hello frame')
|
|
142
|
+
assert.match(clientSource, /if \(mine !== null && mine\.live === true\) return/, 'a live session id is kept, a dead one is replaced')
|
|
143
|
+
assert.match(clientSource, /setSessionId\(live\)/)
|
|
144
|
+
assert.match(windowHtml, /windowName: params\.get\('wname'\) \|\| ''/, 'the page hands its name to the panel')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('clicking the IDE button closes the old window and opens a fresh one', () => {
|
|
148
|
+
assert.match(clientSource, /async function openStandaloneWindow\(options\)/)
|
|
149
|
+
assert.match(clientSource, /var state = await standaloneWindowState\(windowName, windowCwd\)/, 'the registry is asked before opening')
|
|
150
|
+
// Registration must not depend on which topics the first stream asks for: a
|
|
151
|
+
// window that only listens for `hello` still has to appear in the registry.
|
|
152
|
+
assert.match(hostSource, /const rawWindowCwd = isIdeWindow \? \(url\.searchParams\.get\('cwd'\) \?\? ''\)\.trim\(\) : ''/, 'the window registers from its cwd parameter')
|
|
153
|
+
assert.match(hostSource, /session: helloCwd === undefined \? null : liveSessionFor\(ctx, helloCwd\)/, 'the hello session follows the same cwd')
|
|
154
|
+
// A dropped stream must release its registration from BOTH paths: an aborted
|
|
155
|
+
// connection reports 'error' and 'close', and a window left "alive" forever
|
|
156
|
+
// would make the next IDE-button click wait out a pointless close handshake.
|
|
157
|
+
assert.match(hostSource, /let windowSettled = false/, 'the registration settles exactly once')
|
|
158
|
+
assert.match(hostSource, /const settleWindow = \(\) => \{[\s\S]{0,240}?ideWindowClosed\(windowKey\)/, 'and it is what decrements the stream count')
|
|
159
|
+
assert.match(hostSource, /res\.on\('error', \(\) => \{[\s\S]{0,400}?settleWindow\(\)/, 'an errored stream frees the window too')
|
|
160
|
+
assert.match(clientSource, /if \(state\.exists === true && state\.alive === true\) \{/, 'only a LIVE window is asked to close')
|
|
161
|
+
assert.match(clientSource, /await requestStandaloneWindowClose\(windowName\)/, 'a dead registration cannot block the next open')
|
|
162
|
+
assert.match(clientSource, /channel\.postMessage\(\{ type: 'close' \}\)/, 'the old window is told to close itself')
|
|
163
|
+
assert.match(clientSource, /if \(state\.alive !== true\) \{ release\(\); resolve\(true\); return \}/, 'the handshake waits for the stream to go')
|
|
164
|
+
assert.match(clientSource, /window\.open\(url\.href, windowName, features\)/, 'the new window is opened directly (no blank popup)')
|
|
165
|
+
assert.doesNotMatch(clientSource, /window\.open\('', windowName, features\)/, 'no blank popup that has to be closed again')
|
|
166
|
+
assert.doesNotMatch(clientSource, /settleStandaloneWindow/)
|
|
167
|
+
assert.match(windowHtml, /function closeForOpener\(\)/, 'the window can close itself on request')
|
|
168
|
+
assert.match(windowHtml, /if \(data\.type === 'close'\) \{/, 'the lock holder obeys the close request')
|
|
169
|
+
assert.match(windowHtml, /function takeover\(\)/, 'the blocked window offers "close the old one and open here"')
|
|
170
|
+
assert.match(windowHtml, /关闭旧窗口,在这里打开/)
|
|
171
|
+
// A window that takes the lock over (or sits on the blocked notice) must install
|
|
172
|
+
// the same channel hooks as one that claimed it on load - otherwise the DSH page's
|
|
173
|
+
// close request is never heard and the NEXT click of the IDE button is stuck.
|
|
174
|
+
assert.match(windowHtml, /function startHere\(\) \{\n claim\.blocked = false\n \/\/ The window that ends up running[\s\S]{0,400}?becomeHolder\(\)/, 'every boot route installs the close/focus hooks on the window that ends up running')
|
|
175
|
+
assert.match(windowHtml, /showBlocked\(\)\n becomeHolder\(\)/, 'the blocked notice listens for close as well')
|
|
176
|
+
assert.match(windowHtml, /else if \(data\.type === 'close'\) closeForOpener\(\)/, 'the lock holder obeys the close request')
|
|
177
|
+
assert.match(windowHtml, /if \(data\.type === 'close'\) \{\n\s+\/\/ The DSH page wants a fresh window/, 'the no-Web-Locks fallback obeys it too')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('each workspace gets its own window (and its own close handshake)', () => {
|
|
181
|
+
assert.match(clientSource, /function standaloneWindowName\(cwd\) \{\n return WINDOW_NAME \+ '-' \+ standaloneWindowKey\(cwd\)/, 'the window name is derived from the workspace cwd, not from the session')
|
|
182
|
+
assert.doesNotMatch(clientSource, /standaloneWindowName\(sessionId\)/, 'a session id never names a window')
|
|
183
|
+
assert.match(clientSource, /var windowName = standaloneWindowName\(windowCwd !== undefined \? windowCwd : cwd\)/, 'the window follows the workspace, not the panel\'s subdirectory')
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('a restarted host makes every pane drop its stale error and re-read', () => {
|
|
187
|
+
assert.match(clientSource, /var hadFailure = false/, 'a broken stream is remembered')
|
|
188
|
+
assert.match(clientSource, /hadFailure = true/, 'the error handler marks the outage')
|
|
189
|
+
assert.match(clientSource, /if \(recovered === true\) announceRecovery\(\)/, 'the next open is a recovery')
|
|
190
|
+
assert.match(clientSource, /function announceRecovery\(\)/, 'recovery is broadcast once per outage')
|
|
191
|
+
assert.match(clientSource, /hostRecovered: function \(handler\)/, 'panes subscribe to recovery')
|
|
192
|
+
assert.match(clientSource, /function useHostRecovery\(callback\)/, 'one hook for the panes')
|
|
193
|
+
assert.match(clientSource, /useHostRecovery\(function \(\) \{ setError\(undefined\); void recoverTree\(\) \}\)/, 'the tree clears its banner and re-reads')
|
|
194
|
+
assert.match(clientSource, /useHostRecovery\(function \(\) \{ void refresh\(\) \}\)/, 'the log tail re-reads')
|
|
195
|
+
assert.match(clientSource, /useHostRecovery\(function \(\) \{ void refresh\(false\) \}\)/, 'the program console re-reads')
|
|
196
|
+
assert.match(clientSource, /doc\.kind !== 'error'/, 'only documents that failed are retried (edits are kept)')
|
|
197
|
+
assert.match(clientSource, /setError\(undefined\)\n return true/, 'a successful background read also clears the tree banner')
|
|
198
|
+
})
|