dsh-ris-ide 1.8.2 → 1.8.3
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/lib/client.js +258 -26
- package/lib/index.js +169 -16
- package/lib/redirector.js +34 -2
- package/lib/risd/lifecycle.js +50 -12
- package/lib/risd/ping.js +136 -17
- package/lib/risd/server.js +122 -15
- package/lib/risd/ui.js +74 -22
- package/package.json +1 -1
- package/test/client-viewer.test.mjs +82 -0
- package/test/host-tail.test.mjs +71 -1
- package/test/proxy.test.mjs +27 -10
- package/test/redirector.test.mjs +30 -0
- package/test/risd-api.test.mjs +2 -1
- package/test/risd-cli-home.test.mjs +41 -4
- package/test/risd-follow-start.test.mjs +9 -8
- package/test/risd-lifecycle.test.mjs +195 -50
- package/test/risd-ping.test.mjs +77 -1
- package/test/risd-ui.test.mjs +36 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
// Lifecycle settings:
|
|
2
|
-
// Defaults must preserve the behaviour that existed before the
|
|
3
|
-
// follows dsh, everything else stops with the daemon),
|
|
4
|
-
// must
|
|
1
|
+
// Lifecycle settings: each resource has a start half and a stop half for "follows
|
|
2
|
+
// dsh" (m03397). Defaults must preserve the behaviour that existed before the
|
|
3
|
+
// setting (proxy follows dsh, everything else stops with the daemon), a legacy
|
|
4
|
+
// `followDsh` file must migrate to both halves, and a broken policy file must never
|
|
5
|
+
// take the daemon down.
|
|
5
6
|
import assert from 'node:assert/strict'
|
|
6
7
|
import test from 'node:test'
|
|
7
|
-
import { chmodSync, existsSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
8
10
|
import { join } from 'node:path'
|
|
9
11
|
|
|
10
12
|
import {
|
|
@@ -15,48 +17,88 @@ import {
|
|
|
15
17
|
readLifecycle,
|
|
16
18
|
writeLifecycle,
|
|
17
19
|
} from '../lib/risd/lifecycle.js'
|
|
18
|
-
import { makeHome, removeHome, sleep, startRisdProcess } from './risd-helpers.mjs'
|
|
20
|
+
import { api, makeHome, removeHome, sleep, startRisdProcess } from './risd-helpers.mjs'
|
|
21
|
+
import { HAS_BASH, skipWithout } from './helpers/cmd.mjs'
|
|
19
22
|
|
|
20
23
|
test('defaults match the behaviour from before the setting existed', () => {
|
|
21
24
|
const { value, errors } = normalizeLifecycle({})
|
|
22
25
|
assert.deepEqual(errors, [])
|
|
23
26
|
assert.deepEqual(value, LIFECYCLE_DEFAULTS)
|
|
24
|
-
assert.equal(value.daemon.
|
|
25
|
-
assert.equal(value.
|
|
26
|
-
assert.equal(value.
|
|
27
|
-
assert.equal(value.
|
|
28
|
-
assert.equal(value.
|
|
27
|
+
assert.equal(value.daemon.startWithDsh, true, 'the daemon start half is forced on')
|
|
28
|
+
assert.equal(value.daemon.stopWithDsh, true, 'an idle daemon retires by default')
|
|
29
|
+
assert.equal(value.proxy.startWithDsh, true, 'the proxy follows dsh out of the box')
|
|
30
|
+
assert.equal(value.proxy.stopWithDsh, true)
|
|
31
|
+
assert.equal(value.programs.startWithDsh, false, 'opening dsh must not restore JVMs by default')
|
|
32
|
+
assert.equal(value.programs.stopWithDsh, false, 'closing the last dsh must not stop JVMs by default')
|
|
33
|
+
assert.equal(value.debug.stopWithDsh, false)
|
|
34
|
+
assert.equal('startWithDsh' in value.debug, false, 'a debug session has nothing to auto-start')
|
|
29
35
|
})
|
|
30
36
|
|
|
31
|
-
test('
|
|
32
|
-
|
|
37
|
+
test('a legacy followDsh file migrates to both halves, and typos are rejected', () => {
|
|
38
|
+
// Files written before m03397 carry one knob per resource. Both halves took it, so
|
|
39
|
+
// reading the old file must keep the old behaviour exactly.
|
|
40
|
+
const legacy = normalizeLifecycle({ daemon: { followDsh: false }, proxy: { followDsh: false }, programs: { followDsh: true }, debug: { followDsh: true } })
|
|
41
|
+
assert.deepEqual(legacy.errors, [])
|
|
42
|
+
assert.equal(legacy.value.daemon.startWithDsh, true, 'the daemon start half is forced on')
|
|
43
|
+
assert.equal(legacy.value.daemon.stopWithDsh, false)
|
|
44
|
+
assert.equal(legacy.value.proxy.startWithDsh, false)
|
|
45
|
+
assert.equal(legacy.value.proxy.stopWithDsh, false)
|
|
46
|
+
assert.equal(legacy.value.programs.startWithDsh, true)
|
|
47
|
+
assert.equal(legacy.value.programs.stopWithDsh, true)
|
|
48
|
+
assert.equal(legacy.value.debug.stopWithDsh, true, 'debug only has a stop half')
|
|
49
|
+
assert.equal('startWithDsh' in legacy.value.debug, false)
|
|
33
50
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
assert.
|
|
51
|
+
// An explicit half in the same payload wins over the legacy knob (a caller can
|
|
52
|
+
// move one half without rewriting the file).
|
|
53
|
+
const mixed = normalizeLifecycle({ proxy: { followDsh: false, startWithDsh: true } })
|
|
54
|
+
assert.deepEqual(mixed.errors, [])
|
|
55
|
+
assert.equal(mixed.value.proxy.startWithDsh, true)
|
|
56
|
+
assert.equal(mixed.value.proxy.stopWithDsh, false, 'the legacy value still fills the other half')
|
|
38
57
|
|
|
39
|
-
|
|
40
|
-
const unknown = normalizeLifecycle({ proxy: { startWithDsh: true } })
|
|
41
|
-
assert.equal(unknown.changed, false)
|
|
42
|
-
assert.match(unknown.errors.join(';'), /proxy\.startWithDsh 不是可配置项(只能配置 followDsh)/)
|
|
43
|
-
|
|
44
|
-
const bad = normalizeLifecycle({ proxy: { followDsh: 'yes' } })
|
|
58
|
+
const bad = normalizeLifecycle({ proxy: { stopWithDsh: 'yes' } })
|
|
45
59
|
assert.equal(bad.changed, false)
|
|
46
|
-
assert.match(bad.errors.join(';'), /proxy\.
|
|
60
|
+
assert.match(bad.errors.join(';'), /proxy\.stopWithDsh 必须是 true\/false/)
|
|
47
61
|
|
|
48
62
|
// A partial save over what is in force keeps the value.
|
|
49
63
|
const current = normalizeLifecycle({ proxy: { followDsh: false } }).value
|
|
50
|
-
const merged = normalizeLifecycle(mergeLifecycle(current, { programs: {
|
|
51
|
-
assert.equal(merged.proxy.
|
|
52
|
-
assert.equal(merged.programs.
|
|
64
|
+
const merged = normalizeLifecycle(mergeLifecycle(current, { programs: { stopWithDsh: true } })).value
|
|
65
|
+
assert.equal(merged.proxy.stopWithDsh, false)
|
|
66
|
+
assert.equal(merged.programs.stopWithDsh, true)
|
|
67
|
+
assert.equal(merged.programs.startWithDsh, false)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('the halves a resource cannot have are rejected, not silently dropped', () => {
|
|
71
|
+
// The daemon's start half is forced (a plugin must be able to ask for a daemon).
|
|
72
|
+
const forcedStart = normalizeLifecycle({ daemon: { startWithDsh: false } })
|
|
73
|
+
assert.equal(forcedStart.changed, false)
|
|
74
|
+
assert.match(forcedStart.errors.join(';'), /daemon\.startWithDsh 不可配置/)
|
|
75
|
+
|
|
76
|
+
// A debug session belongs to a page: there is no auto-start to switch.
|
|
77
|
+
const debugStart = normalizeLifecycle({ debug: { startWithDsh: true } })
|
|
78
|
+
assert.equal(debugStart.changed, false)
|
|
79
|
+
assert.match(debugStart.errors.join(';'), /debug\.startWithDsh 不是可配置项(只能配置 stopWithDsh)/)
|
|
80
|
+
|
|
81
|
+
// Following the daemon stays forced (m07741).
|
|
82
|
+
const forced = normalizeLifecycle({ proxy: { startWithDsh: true, followDaemon: false }, programs: { followDaemon: false } })
|
|
83
|
+
assert.equal(forced.changed, false)
|
|
84
|
+
assert.equal(forced.errors.length, 2)
|
|
85
|
+
assert.match(forced.errors.join(';'), /proxy\.followDaemon 不再支持:所有资源强制跟随 daemon/)
|
|
86
|
+
assert.equal('followDaemon' in forced.value.proxy, false)
|
|
87
|
+
assert.equal('followDaemon' in forced.value.programs, false)
|
|
88
|
+
|
|
89
|
+
const bad = normalizeLifecycle({ proxy: { startWithDsh: 'yes' }, debug: 'nope' })
|
|
90
|
+
assert.equal(bad.changed, false)
|
|
91
|
+
assert.equal(bad.errors.length, 2)
|
|
92
|
+
assert.match(bad.errors.join(';'), /proxy\.startWithDsh 必须是 true\/false/)
|
|
93
|
+
assert.match(bad.errors.join(';'), /debug 必须是对象/)
|
|
53
94
|
})
|
|
54
95
|
|
|
55
96
|
test('partial input keeps the untouched defaults and rejects non-booleans', () => {
|
|
56
|
-
const partial = normalizeLifecycle({ programs: {
|
|
97
|
+
const partial = normalizeLifecycle({ programs: { stopWithDsh: true } })
|
|
57
98
|
assert.deepEqual(partial.errors, [])
|
|
58
|
-
assert.equal(partial.value.programs.
|
|
59
|
-
assert.equal(partial.value.
|
|
99
|
+
assert.equal(partial.value.programs.stopWithDsh, true)
|
|
100
|
+
assert.equal(partial.value.programs.startWithDsh, false, 'the other half keeps its default')
|
|
101
|
+
assert.equal(partial.value.proxy.stopWithDsh, true)
|
|
60
102
|
|
|
61
103
|
// Following the daemon is forced (m07741): the old key is rejected, not stored.
|
|
62
104
|
const forced = normalizeLifecycle({ proxy: { followDsh: true, followDaemon: false }, programs: { followDaemon: false } })
|
|
@@ -76,21 +118,22 @@ test('partial input keeps the untouched defaults and rejects non-booleans', () =
|
|
|
76
118
|
test('a partial save merges over the policy in force', () => {
|
|
77
119
|
// POST /v1/config used to normalize the body alone, so saving one checkbox reset
|
|
78
120
|
// the other three resources to their defaults (review A2-P2-1).
|
|
79
|
-
const current = normalizeLifecycle({ proxy: {
|
|
80
|
-
const merged = normalizeLifecycle(mergeLifecycle(current, { programs: {
|
|
81
|
-
assert.equal(merged.programs.
|
|
82
|
-
assert.equal(merged.
|
|
83
|
-
assert.equal(merged.
|
|
84
|
-
assert.equal(merged.
|
|
121
|
+
const current = normalizeLifecycle({ proxy: { stopWithDsh: false }, debug: { stopWithDsh: true } }).value
|
|
122
|
+
const merged = normalizeLifecycle(mergeLifecycle(current, { programs: { startWithDsh: true } })).value
|
|
123
|
+
assert.equal(merged.programs.startWithDsh, true, 'the submitted half changed')
|
|
124
|
+
assert.equal(merged.programs.stopWithDsh, false, 'the sibling half kept its default')
|
|
125
|
+
assert.equal(merged.proxy.stopWithDsh, false, 'the untouched resource kept its value')
|
|
126
|
+
assert.equal(merged.debug.stopWithDsh, true, 'the untouched resource kept its value')
|
|
127
|
+
assert.equal(merged.daemon.stopWithDsh, true)
|
|
85
128
|
})
|
|
86
129
|
|
|
87
130
|
test('unknown resources and keys are rejected instead of silently saved', () => {
|
|
88
|
-
const unknownResource = normalizeLifecycle({ engine: {
|
|
131
|
+
const unknownResource = normalizeLifecycle({ engine: { startWithDsh: true } })
|
|
89
132
|
assert.equal(unknownResource.changed, false)
|
|
90
133
|
assert.match(unknownResource.errors.join(';'), /engine 不是生命周期资源/)
|
|
91
134
|
assert.equal('engine' in unknownResource.value, false)
|
|
92
135
|
|
|
93
|
-
const unknownKey = normalizeLifecycle({ proxy: {
|
|
136
|
+
const unknownKey = normalizeLifecycle({ proxy: { startWithDsh: true, keepAlive: true } })
|
|
94
137
|
assert.equal(unknownKey.changed, false)
|
|
95
138
|
assert.match(unknownKey.errors.join(';'), /proxy\.keepAlive 不是可配置项/)
|
|
96
139
|
})
|
|
@@ -113,16 +156,18 @@ test('a missing file reads as defaults; a broken file still yields defaults', ()
|
|
|
113
156
|
test('write persists atomically with 0600 and reads back', () => {
|
|
114
157
|
const home = makeHome('risd-life-')
|
|
115
158
|
try {
|
|
116
|
-
const written = writeLifecycle(home, { programs: {
|
|
159
|
+
const written = writeLifecycle(home, { programs: { startWithDsh: true } })
|
|
117
160
|
assert.deepEqual(written.errors, [])
|
|
118
|
-
assert.equal(written.value.programs.
|
|
161
|
+
assert.equal(written.value.programs.startWithDsh, true)
|
|
162
|
+
assert.equal(written.value.programs.stopWithDsh, false)
|
|
119
163
|
const path = lifecyclePath(home)
|
|
120
164
|
assert.ok(existsSync(path))
|
|
121
165
|
assert.equal(statSync(path).mode & 0o777, 0o600)
|
|
122
166
|
const parsed = JSON.parse(readFileSync(path, 'utf8'))
|
|
123
|
-
assert.equal(parsed.programs.
|
|
167
|
+
assert.equal(parsed.programs.startWithDsh, true)
|
|
124
168
|
const again = readLifecycle(home)
|
|
125
|
-
assert.equal(again.value.proxy.
|
|
169
|
+
assert.equal(again.value.proxy.startWithDsh, true)
|
|
170
|
+
assert.equal(again.value.proxy.stopWithDsh, true)
|
|
126
171
|
} finally { removeHome(home) }
|
|
127
172
|
})
|
|
128
173
|
|
|
@@ -139,26 +184,29 @@ test('POST /v1/config stores the policy and GET /v1/config returns it', async ()
|
|
|
139
184
|
const saved = await fetch(`http://127.0.0.1:${port}/v1/config`, {
|
|
140
185
|
method: 'POST',
|
|
141
186
|
headers,
|
|
142
|
-
body: JSON.stringify({ lifecycle: { daemon: {
|
|
187
|
+
body: JSON.stringify({ lifecycle: { daemon: { stopWithDsh: false }, programs: { stopWithDsh: true, startWithDsh: true } } }),
|
|
143
188
|
})
|
|
144
189
|
assert.equal(saved.status, 200)
|
|
145
190
|
const savedBody = await saved.json()
|
|
146
191
|
assert.equal(savedBody.ok, true)
|
|
147
|
-
assert.equal(savedBody.lifecycle.daemon.
|
|
148
|
-
assert.equal(savedBody.lifecycle.
|
|
192
|
+
assert.equal(savedBody.lifecycle.daemon.stopWithDsh, false)
|
|
193
|
+
assert.equal(savedBody.lifecycle.daemon.startWithDsh, true, 'the forced half stays on')
|
|
194
|
+
assert.equal(savedBody.lifecycle.programs.stopWithDsh, true)
|
|
195
|
+
assert.equal(savedBody.lifecycle.programs.startWithDsh, true)
|
|
149
196
|
assert.equal(existsSync(join(home, 'risd-lifecycle.json')), true)
|
|
150
197
|
|
|
151
198
|
const after = await (await fetch(`http://127.0.0.1:${port}/v1/config`, { headers })).json()
|
|
152
|
-
assert.equal(after.lifecycle.daemon.
|
|
153
|
-
assert.equal(after.lifecycle.programs.
|
|
199
|
+
assert.equal(after.lifecycle.daemon.stopWithDsh, false)
|
|
200
|
+
assert.equal(after.lifecycle.programs.stopWithDsh, true)
|
|
201
|
+
assert.equal(after.lifecycle.programs.startWithDsh, true)
|
|
154
202
|
|
|
155
203
|
const bad = await fetch(`http://127.0.0.1:${port}/v1/config`, {
|
|
156
204
|
method: 'POST',
|
|
157
205
|
headers,
|
|
158
|
-
body: JSON.stringify({ lifecycle: { proxy: {
|
|
206
|
+
body: JSON.stringify({ lifecycle: { proxy: { stopWithDsh: 'true' } } }),
|
|
159
207
|
})
|
|
160
208
|
assert.equal(bad.status, 400)
|
|
161
|
-
assert.match((await bad.json()).message, /
|
|
209
|
+
assert.match((await bad.json()).message, /proxy\.stopWithDsh 必须是 true\/false/)
|
|
162
210
|
|
|
163
211
|
const forced = await fetch(`http://127.0.0.1:${port}/v1/config`, {
|
|
164
212
|
method: 'POST',
|
|
@@ -167,6 +215,23 @@ test('POST /v1/config stores the policy and GET /v1/config returns it', async ()
|
|
|
167
215
|
})
|
|
168
216
|
assert.equal(forced.status, 400)
|
|
169
217
|
assert.match((await forced.json()).message, /followDaemon 不再支持/)
|
|
218
|
+
|
|
219
|
+
// The daemon's start half cannot be switched off, and the debug start half does
|
|
220
|
+
// not exist: both are refused with their own message.
|
|
221
|
+
const forcedStart = await fetch(`http://127.0.0.1:${port}/v1/config`, {
|
|
222
|
+
method: 'POST',
|
|
223
|
+
headers,
|
|
224
|
+
body: JSON.stringify({ lifecycle: { daemon: { startWithDsh: false } } }),
|
|
225
|
+
})
|
|
226
|
+
assert.equal(forcedStart.status, 400)
|
|
227
|
+
assert.match((await forcedStart.json()).message, /daemon\.startWithDsh 不可配置/)
|
|
228
|
+
const debugStart = await fetch(`http://127.0.0.1:${port}/v1/config`, {
|
|
229
|
+
method: 'POST',
|
|
230
|
+
headers,
|
|
231
|
+
body: JSON.stringify({ lifecycle: { debug: { startWithDsh: true } } }),
|
|
232
|
+
})
|
|
233
|
+
assert.equal(debugStart.status, 400)
|
|
234
|
+
assert.match((await debugStart.json()).message, /debug\.startWithDsh 不是可配置项/)
|
|
170
235
|
} finally {
|
|
171
236
|
await daemon.stop()
|
|
172
237
|
await sleep(100)
|
|
@@ -190,7 +255,7 @@ test('POST /v1/config rejects unknown resources, keys and non-object resources (
|
|
|
190
255
|
})
|
|
191
256
|
const cases = [
|
|
192
257
|
[{ engine: { followDsh: true } }, /engine 不是生命周期资源/],
|
|
193
|
-
[{ proxy: {
|
|
258
|
+
[{ proxy: { startWithDsh: true, keepAlive: true } }, /proxy\.keepAlive 不是可配置项/],
|
|
194
259
|
[{ daemon: { followDaemon: false } }, /daemon\.followDaemon 不再支持/],
|
|
195
260
|
[{ proxy: true }, /proxy 必须是对象/],
|
|
196
261
|
[null, /lifecycle 必须是对象/],
|
|
@@ -233,3 +298,83 @@ test('a broken lifecycle file is reported by GET /v1/config (review A3-P2-8)', a
|
|
|
233
298
|
}
|
|
234
299
|
})
|
|
235
300
|
|
|
301
|
+
|
|
302
|
+
/** A workspace with one custom program row (the shape the panel writes). */
|
|
303
|
+
function makeProgramWorkspace() {
|
|
304
|
+
const workspace = mkdtempSync(join(tmpdir(), 'risd-life-restore-'))
|
|
305
|
+
mkdirSync(join(workspace, '.dsh-ris-ide'), { recursive: true })
|
|
306
|
+
writeFileSync(join(workspace, '.dsh-ris-ide', 'config.json'), `${JSON.stringify({
|
|
307
|
+
version: 1,
|
|
308
|
+
defaults: {},
|
|
309
|
+
programs: [{
|
|
310
|
+
id: 'demo',
|
|
311
|
+
name: 'demo',
|
|
312
|
+
kind: 'custom',
|
|
313
|
+
dir: workspace,
|
|
314
|
+
relDir: '.',
|
|
315
|
+
project: '',
|
|
316
|
+
logName: 'demo',
|
|
317
|
+
startCommand: `${JSON.stringify(process.execPath)} -e "setInterval(() => {}, 60000)"`,
|
|
318
|
+
stopGraceMs: 3000,
|
|
319
|
+
}],
|
|
320
|
+
}, null, 2)}\n`, 'utf8')
|
|
321
|
+
return workspace
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
test('the programs start half restores what the last daemon left running (m03397)', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
|
|
325
|
+
const home = makeHome('risd-life-')
|
|
326
|
+
const workspace = makeProgramWorkspace()
|
|
327
|
+
let daemon
|
|
328
|
+
try {
|
|
329
|
+
writeLifecycle(home, { programs: { startWithDsh: true } })
|
|
330
|
+
// A previous daemon recorded this program as live and then went away (crash,
|
|
331
|
+
// reboot, kill -9): the snapshot is the only memory of it.
|
|
332
|
+
writeFileSync(join(home, 'risd-programs-last.json'), `${JSON.stringify({
|
|
333
|
+
at: new Date().toISOString(),
|
|
334
|
+
programs: [{ cwd: workspace, id: 'demo', dir: join(workspace, 'logs') }],
|
|
335
|
+
})}\n`, { mode: 0o600 })
|
|
336
|
+
daemon = await startRisdProcess({ home })
|
|
337
|
+
const lease = await api(daemon.state, '/v1/leases', { method: 'POST', body: { ownerPid: process.pid, cwd: workspace } })
|
|
338
|
+
assert.equal(lease.status, 200, JSON.stringify(lease.body))
|
|
339
|
+
const deadline = Date.now() + 5000
|
|
340
|
+
let demo
|
|
341
|
+
while (Date.now() < deadline) {
|
|
342
|
+
const listed = await api(daemon.state, `/v1/programs?cwd=${encodeURIComponent(workspace)}`)
|
|
343
|
+
demo = listed.body.programs.find((row) => row.id === 'demo')
|
|
344
|
+
if (demo !== undefined && demo.running !== null && demo.running !== undefined && demo.running.alive === true) break
|
|
345
|
+
await sleep(100)
|
|
346
|
+
}
|
|
347
|
+
assert.equal(demo?.running?.alive, true, 'the program the snapshot remembered runs again')
|
|
348
|
+
} finally {
|
|
349
|
+
if (daemon !== undefined) await daemon.stop()
|
|
350
|
+
await sleep(100)
|
|
351
|
+
removeHome(home)
|
|
352
|
+
rmSync(workspace, { recursive: true, force: true })
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
test('the programs start half stays quiet when it is off', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
|
|
357
|
+
const home = makeHome('risd-life-')
|
|
358
|
+
const workspace = makeProgramWorkspace()
|
|
359
|
+
let daemon
|
|
360
|
+
try {
|
|
361
|
+
// Default policy: programs do NOT follow dsh, so a stale snapshot must not start
|
|
362
|
+
// anything behind the user's back.
|
|
363
|
+
writeFileSync(join(home, 'risd-programs-last.json'), `${JSON.stringify({
|
|
364
|
+
at: new Date().toISOString(),
|
|
365
|
+
programs: [{ cwd: workspace, id: 'demo', dir: join(workspace, 'logs') }],
|
|
366
|
+
})}\n`, { mode: 0o600 })
|
|
367
|
+
daemon = await startRisdProcess({ home })
|
|
368
|
+
await api(daemon.state, '/v1/leases', { method: 'POST', body: { ownerPid: process.pid, cwd: workspace } })
|
|
369
|
+
await sleep(600)
|
|
370
|
+
const listed = await api(daemon.state, `/v1/programs?cwd=${encodeURIComponent(workspace)}`)
|
|
371
|
+
const demo = listed.body.programs.find((row) => row.id === 'demo')
|
|
372
|
+
assert.ok(demo !== undefined)
|
|
373
|
+
assert.notEqual(demo.running?.alive, true, 'nothing was restored while the start half is off')
|
|
374
|
+
} finally {
|
|
375
|
+
if (daemon !== undefined) await daemon.stop()
|
|
376
|
+
await sleep(100)
|
|
377
|
+
removeHome(home)
|
|
378
|
+
rmSync(workspace, { recursive: true, force: true })
|
|
379
|
+
}
|
|
380
|
+
})
|
package/test/risd-ping.test.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import assert from 'node:assert/strict'
|
|
|
5
5
|
import { createServer } from 'node:net'
|
|
6
6
|
import test from 'node:test'
|
|
7
7
|
|
|
8
|
-
import { pingSocks } from '../lib/risd/ping.js'
|
|
8
|
+
import { pingSocks, probeTarget } from '../lib/risd/ping.js'
|
|
9
9
|
|
|
10
10
|
/** A server that answers the SOCKS5 greeting with `reply`. */
|
|
11
11
|
function fakeServer(reply) {
|
|
@@ -97,3 +97,79 @@ test('a peer that accepts then closes without answering is reported immediately
|
|
|
97
97
|
}
|
|
98
98
|
})
|
|
99
99
|
|
|
100
|
+
|
|
101
|
+
/** A SOCKS5 server that answers the greeting and then the CONNECT request. */
|
|
102
|
+
function fakeSocksWithConnect(connectReply) {
|
|
103
|
+
return new Promise((resolve) => {
|
|
104
|
+
const server = createServer((socket) => {
|
|
105
|
+
let requests = 0
|
|
106
|
+
socket.on('data', () => {
|
|
107
|
+
requests += 1
|
|
108
|
+
if (requests === 1) socket.write(Buffer.from([0x05, 0x00]))
|
|
109
|
+
else socket.write(connectReply)
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
server.listen(0, '127.0.0.1', () => resolve({ server, port: server.address().port }))
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const CONNECT_OK = Buffer.from([0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
|
117
|
+
|
|
118
|
+
test('a SOCKS5 server that forwards the probe destination is reported as usable (m03429)', async () => {
|
|
119
|
+
const { server, port } = await fakeSocksWithConnect(CONNECT_OK)
|
|
120
|
+
try {
|
|
121
|
+
const result = await pingSocks({ host: '127.0.0.1', port, target: { host: 'git.example.com', port: 443 }, timeoutMs: 1500 })
|
|
122
|
+
assert.equal(result.ok, true)
|
|
123
|
+
assert.equal(result.socks, true)
|
|
124
|
+
assert.equal(result.usable, true)
|
|
125
|
+
assert.deepEqual(result.target, { host: 'git.example.com', port: 443 })
|
|
126
|
+
} finally {
|
|
127
|
+
server.close()
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('a greeting that passes but cannot forward is NOT usable (m03429)', async () => {
|
|
132
|
+
// rep=5 is SOCKS5 "connection refused": the handshake works, the tunnel does not.
|
|
133
|
+
const refused = Buffer.from([0x05, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
|
134
|
+
const { server, port } = await fakeSocksWithConnect(refused)
|
|
135
|
+
try {
|
|
136
|
+
const result = await pingSocks({ host: '127.0.0.1', port, target: { host: 'git.example.com', port: 5432 }, timeoutMs: 1500 })
|
|
137
|
+
assert.equal(result.ok, false)
|
|
138
|
+
assert.equal(result.socks, true)
|
|
139
|
+
assert.equal(result.usable, false)
|
|
140
|
+
assert.match(result.error, /握手正常,但无法转发到 git\.example\.com:5432/)
|
|
141
|
+
assert.match(result.error, /拒绝/)
|
|
142
|
+
} finally {
|
|
143
|
+
server.close()
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('without a target the probe reports the greeting only, never a fake verdict (m03429)', async () => {
|
|
148
|
+
const { server, port } = await fakeServer(Buffer.from([0x05, 0x00]))
|
|
149
|
+
try {
|
|
150
|
+
const result = await pingSocks({ host: '127.0.0.1', port, timeoutMs: 1500 })
|
|
151
|
+
assert.equal(result.ok, true)
|
|
152
|
+
assert.equal(result.socks, true)
|
|
153
|
+
assert.equal(result.usable, null)
|
|
154
|
+
assert.equal(result.target, null)
|
|
155
|
+
} finally {
|
|
156
|
+
server.close()
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('the probe target comes from a concrete shadow, else from a literal rule (m03429)', () => {
|
|
161
|
+
assert.deepEqual(probeTarget({ shadows: [{ host: '10.0.0.9', port: 1521 }], rules: [] }), { host: '10.0.0.9', port: 1521 })
|
|
162
|
+
assert.deepEqual(probeTarget({
|
|
163
|
+
shadows: [],
|
|
164
|
+
rules: [
|
|
165
|
+
{ enabled: true, hosts: '10.0.0.*', ports: '80' },
|
|
166
|
+
{ enabled: true, hosts: 'git.example.com,10.0.0.8', ports: '443, 8443' },
|
|
167
|
+
],
|
|
168
|
+
}), { host: 'git.example.com', port: 443 })
|
|
169
|
+
// A wildcard port and a wildcard host cannot be dialled; guessing would turn a
|
|
170
|
+
// healthy tunnel into a false alarm.
|
|
171
|
+
assert.equal(probeTarget({ shadows: [], rules: [{ enabled: true, hosts: 'git.example.com', ports: '*' }] }), null)
|
|
172
|
+
assert.equal(probeTarget({ shadows: [], rules: [{ enabled: true, hosts: '*', ports: '80' }] }), null)
|
|
173
|
+
assert.equal(probeTarget({ shadows: [], rules: [{ enabled: false, hosts: 'git.example.com', ports: '443' }] }), null)
|
|
174
|
+
assert.equal(probeTarget(null), null)
|
|
175
|
+
})
|
package/test/risd-ui.test.mjs
CHANGED
|
@@ -168,6 +168,16 @@ test('the IDE tab drops the toolbar and names workspaces by folder', async () =>
|
|
|
168
168
|
assert.match(html, /el\('bridge-fix'\)\.onclick = fixBridge/)
|
|
169
169
|
assert.match(html, /function paintBridgeFix/, 'state decides the label: start vs restart')
|
|
170
170
|
assert.match(html, /interactive: true/, 'only a click may raise the elevation prompt')
|
|
171
|
+
// m05590: "启动引擎" must not raise a password dialog. Elevation is its own click
|
|
172
|
+
// (the component card's 「启动系统层拦截」), so the engine button carries no flag.
|
|
173
|
+
const fixBridgeAt = html.indexOf('function fixBridge()')
|
|
174
|
+
const engineToggleAt = html.indexOf('function toggleProxyEngine()')
|
|
175
|
+
assert.ok(fixBridgeAt > 0 && engineToggleAt > fixBridgeAt, 'both click handlers are present')
|
|
176
|
+
assert.match(html.slice(fixBridgeAt, engineToggleAt), /interactive: true/, 'the elevation click is the one that asks for a password')
|
|
177
|
+
const engineBlock = html.slice(engineToggleAt, html.indexOf("el('engine-toggle').onclick", engineToggleAt))
|
|
178
|
+
assert.ok(engineBlock.length > 0, 'the engine toggle block is bounded')
|
|
179
|
+
assert.doesNotMatch(engineBlock, /interactive/, 'starting or stopping the engine never passes interactive (m05590)')
|
|
180
|
+
assert.match(html, /button\.textContent = running \? '停止' : '启动引擎'/, 'the button says it starts the engine, not the whole stack')
|
|
171
181
|
assert.doesNotMatch(html, /proxy-start-with-dsh/, 'the follow-dsh lifecycle checkbox is the only policy (m13950)')
|
|
172
182
|
assert.match(html, /dsh 接入时启动引擎/, 'the lifecycle row describes both halves of following dsh')
|
|
173
183
|
// The elevation note lives in the component card and clears itself (m12923).
|
|
@@ -316,9 +326,22 @@ test('the overview offers lifecycle settings for daemon, proxy, programs and deb
|
|
|
316
326
|
assert.match(page.text, /var queued = lifecycleQueued === true;/)
|
|
317
327
|
assert.match(page.text, /queued === true \? Promise\.resolve\(\) : loadLifecycle\(\)/)
|
|
318
328
|
assert.equal(page.text.includes('followDaemon'), false, 'following the daemon is forced, not configurable')
|
|
319
|
-
|
|
329
|
+
// Two switches per row (m03397): the start half and the stop half answer different
|
|
330
|
+
// questions, so they are separate checkboxes with their own column.
|
|
331
|
+
for (const key of ['daemon.startWithDsh', 'daemon.stopWithDsh', 'proxy.startWithDsh', 'proxy.stopWithDsh',
|
|
332
|
+
'programs.startWithDsh', 'programs.stopWithDsh', 'debug.startWithDsh', 'debug.stopWithDsh']) {
|
|
320
333
|
assert.ok(page.text.includes(`data-life="${key}"`), `missing checkbox ${key}`)
|
|
321
334
|
}
|
|
335
|
+
assert.match(page.text, /跟随 dsh 启动/)
|
|
336
|
+
assert.match(page.text, /跟随 dsh 停止/)
|
|
337
|
+
// The forced daemon start is checked and disabled; a debug session has nothing to
|
|
338
|
+
// auto-start, so its start cell is disabled too.
|
|
339
|
+
assert.match(page.text, /data-life="daemon\.startWithDsh" checked disabled/)
|
|
340
|
+
assert.match(page.text, /data-life="debug\.startWithDsh" disabled/)
|
|
341
|
+
// The retired sentence about the daemon being forced is gone from the page.
|
|
342
|
+
assert.equal(/所有资源强制跟随 daemon/.test(page.text), false)
|
|
343
|
+
// A disabled half is not part of the payload (the server rejects unknown halves).
|
|
344
|
+
assert.match(page.text, /if \(box\.disabled === true\) return;/)
|
|
322
345
|
assert.match(page.text, /loadLifecycle/)
|
|
323
346
|
assert.match(page.text, /v1\/config/)
|
|
324
347
|
})
|
|
@@ -761,3 +784,15 @@ test('the drift path confirms unsaved lifecycle settings too', async () => {
|
|
|
761
784
|
const restart = source.slice(source.indexOf('function restartDaemonThenReload()'), source.indexOf('function reloadPage()'))
|
|
762
785
|
assert.match(restart, /lifecycleDirty === true && window\.confirm\('生命周期设置还没保存,重启并刷新会丢失'\)/)
|
|
763
786
|
})
|
|
787
|
+
|
|
788
|
+
test('the IDE pane keeps its own workspace when dsh switches (m04873)', async () => {
|
|
789
|
+
const source = readFileSync(new URL('../lib/risd/ui.js', import.meta.url), 'utf8')
|
|
790
|
+
// dsh switching workspace changes /v1/dsh; the embedded IDE must not follow it,
|
|
791
|
+
// and this page must not drag the dsh sidebar console along either.
|
|
792
|
+
assert.match(source, /function pickIdeWindow\(windows\)/)
|
|
793
|
+
assert.match(source, /return \{ cwd: preferred, live: false, active: false \}/)
|
|
794
|
+
assert.match(source, /if \(!win && cwd\) win = \{ cwd: cwd, live: false, active: false \}/)
|
|
795
|
+
const load = source.slice(source.indexOf('function loadIde()'), source.indexOf('function refreshIdeWindows()'))
|
|
796
|
+
assert.match(load, /var selected = pickIdeWindow\(windows\)/)
|
|
797
|
+
assert.doesNotMatch(load, /windows\.filter\(function \(win\) \{ return win\.live !== false; \}\)\[0\] \|\| windows\[0\]/)
|
|
798
|
+
})
|