dsh-ris-ide 1.8.0 → 1.8.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.
- package/README.md +5 -3
- package/bin/risd.mjs +14 -17
- package/lib/client.js +400 -93
- package/lib/debug/vendor/README.md +14 -0
- package/lib/debug/vendor/jdwp/client.js +9 -4
- package/lib/debug/vendor/src/jdwp/client.ts +12 -5
- package/lib/index.js +794 -48
- package/lib/proxybridge-bundle.js +1 -1
- package/lib/proxybridge-health.js +206 -0
- package/lib/redirector.js +1181 -90
- package/lib/risd/lifecycle.js +9 -3
- package/lib/risd/server.js +762 -26
- package/lib/risd/ui.js +419 -98
- package/lib/risd-client.js +4 -1
- package/lib/startup.js +27 -7
- package/package.json +2 -2
- package/test/client-viewer.test.mjs +299 -120
- package/test/clipboard.test.mjs +259 -0
- package/test/debug-engine.test.mjs +3 -1
- package/test/dsh-origin.test.mjs +4 -11
- package/test/dsh-window-refresh.test.mjs +166 -1
- package/test/harness.test.mjs +1 -1
- package/test/helpers/cmd.mjs +29 -0
- package/test/helpers/tgz.mjs +71 -0
- package/test/host-search.test.mjs +18 -11
- package/test/host-tail.test.mjs +119 -24
- package/test/proxy-route.test.mjs +61 -0
- package/test/proxy-window.test.mjs +5 -0
- package/test/proxy.test.mjs +13 -1
- package/test/proxybridge-bundle.test.mjs +1 -59
- package/test/proxybridge-health.test.mjs +116 -0
- package/test/redirector-bundle.test.mjs +21 -67
- package/test/redirector.test.mjs +395 -5
- package/test/risd-api.test.mjs +114 -17
- package/test/risd-bridge-degrade.test.mjs +3 -29
- package/test/risd-engine.test.mjs +13 -50
- package/test/risd-entry.test.mjs +0 -37
- package/test/risd-follow-start.test.mjs +101 -0
- package/test/risd-git.test.mjs +7 -5
- package/test/risd-handoff.test.mjs +6 -50
- package/test/risd-helpers.mjs +150 -3
- package/test/risd-host-p2.test.mjs +2 -30
- package/test/risd-lifecycle.test.mjs +25 -0
- package/test/risd-programs.test.mjs +4 -34
- package/test/risd-restart.test.mjs +104 -0
- package/test/risd-review-p2.test.mjs +0 -13
- package/test/risd-shutdown.test.mjs +5 -38
- package/test/risd-teardown.test.mjs +8 -27
- package/test/risd-ui.test.mjs +322 -4
- package/test/risd-write.test.mjs +2 -1
- package/test/startup-reconcile.test.mjs +44 -8
- package/test/proxy-restart.test.mjs +0 -37
|
@@ -12,8 +12,8 @@ import { createServer } from 'node:http'
|
|
|
12
12
|
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
13
13
|
import { tmpdir } from 'node:os'
|
|
14
14
|
import { join } from 'node:path'
|
|
15
|
-
import { Readable } from 'node:stream'
|
|
16
15
|
import test from 'node:test'
|
|
16
|
+
import { fakeReq, fakeRes, risdBridge } from './risd-helpers.mjs'
|
|
17
17
|
|
|
18
18
|
const home = mkdtempSync(join(tmpdir(), 'risd-host-p2-'))
|
|
19
19
|
const workspace = mkdtempSync(join(tmpdir(), 'risd-host-p2-ws-'))
|
|
@@ -22,26 +22,6 @@ process.env.DSH_RIS_IDE_PROXY_HOME = home
|
|
|
22
22
|
const { __test } = await import('../lib/index.js')
|
|
23
23
|
const { RISD_API_VERSION } = await import('../lib/risd/state.js')
|
|
24
24
|
|
|
25
|
-
function fakeRes() {
|
|
26
|
-
return {
|
|
27
|
-
status: 0,
|
|
28
|
-
chunks: [],
|
|
29
|
-
writeHead(status) { this.status = status },
|
|
30
|
-
write(chunk) { this.chunks.push(String(chunk)); return true },
|
|
31
|
-
end(chunk) { if (chunk !== undefined) this.chunks.push(String(chunk)) },
|
|
32
|
-
json() { return JSON.parse(this.chunks.join('')) },
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function fakeReq(method, url, body) {
|
|
37
|
-
const chunks = body === undefined ? [] : [Buffer.from(JSON.stringify(body))]
|
|
38
|
-
const req = Readable.from(chunks)
|
|
39
|
-
req.method = method
|
|
40
|
-
req.url = url
|
|
41
|
-
req.headers = { host: '127.0.0.1:3080', 'content-type': 'application/json' }
|
|
42
|
-
return req
|
|
43
|
-
}
|
|
44
|
-
|
|
45
25
|
/** A fake daemon that answers /v1/health and hands every other request to `reply`. */
|
|
46
26
|
async function fakeDaemon(reply) {
|
|
47
27
|
const server = createServer((req, res) => {
|
|
@@ -69,15 +49,7 @@ async function stopServer(server) {
|
|
|
69
49
|
}
|
|
70
50
|
|
|
71
51
|
function setBridge(url, port) {
|
|
72
|
-
__test.setRisdBridge({
|
|
73
|
-
mode: 'auto',
|
|
74
|
-
state: { url, token: 'token-x', apiVersion: RISD_API_VERSION, port },
|
|
75
|
-
leaseId: 'lease-x',
|
|
76
|
-
pending: null,
|
|
77
|
-
warnedAt: 0,
|
|
78
|
-
degraded: false,
|
|
79
|
-
lastProbeAt: Date.now(),
|
|
80
|
-
})
|
|
52
|
+
__test.setRisdBridge(risdBridge({ url, port }))
|
|
81
53
|
}
|
|
82
54
|
|
|
83
55
|
const ctx = { sessions: { get: () => ({ header: { cwd: workspace } }) } }
|
|
@@ -25,6 +25,31 @@ test('defaults match the behaviour from before the setting existed', () => {
|
|
|
25
25
|
assert.equal(value.proxy.followDsh, true)
|
|
26
26
|
assert.equal(value.programs.followDsh, false, 'closing the last dsh must not stop JVMs by default')
|
|
27
27
|
assert.equal(value.debug.followDsh, false)
|
|
28
|
+
assert.equal(value.proxy.followDsh, true, 'the proxy follows dsh out of the box')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('start and stop read the same followDsh knob, and typos are rejected', () => {
|
|
32
|
+
assert.equal(LIFECYCLE_DEFAULTS.proxy.followDsh, true, 'the proxy follows dsh by default')
|
|
33
|
+
|
|
34
|
+
const off = normalizeLifecycle({ proxy: { followDsh: false } })
|
|
35
|
+
assert.deepEqual(off.errors, [])
|
|
36
|
+
assert.equal(off.value.proxy.followDsh, false)
|
|
37
|
+
assert.equal('startWithDsh' in off.value.proxy, false, 'there is no second auto-start switch (m13950)')
|
|
38
|
+
|
|
39
|
+
// The old separate knob is a typo now, not a silently saved setting.
|
|
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' } })
|
|
45
|
+
assert.equal(bad.changed, false)
|
|
46
|
+
assert.match(bad.errors.join(';'), /proxy\.followDsh 必须是 true\/false/)
|
|
47
|
+
|
|
48
|
+
// A partial save over what is in force keeps the value.
|
|
49
|
+
const current = normalizeLifecycle({ proxy: { followDsh: false } }).value
|
|
50
|
+
const merged = normalizeLifecycle(mergeLifecycle(current, { programs: { followDsh: true } })).value
|
|
51
|
+
assert.equal(merged.proxy.followDsh, false)
|
|
52
|
+
assert.equal(merged.programs.followDsh, true)
|
|
28
53
|
})
|
|
29
54
|
|
|
30
55
|
test('partial input keeps the untouched defaults and rejects non-booleans', () => {
|
|
@@ -3,45 +3,15 @@
|
|
|
3
3
|
// started here keeps running after dsh exits and is visible from another dsh.
|
|
4
4
|
import assert from 'node:assert/strict'
|
|
5
5
|
import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs'
|
|
6
|
-
import { request } from 'node:http'
|
|
7
6
|
import { tmpdir } from 'node:os'
|
|
8
7
|
import { join } from 'node:path'
|
|
9
8
|
import { after, before, test } from 'node:test'
|
|
10
|
-
import { sleep } from './risd-helpers.mjs'
|
|
11
|
-
import {
|
|
9
|
+
import { api, sleep, startRisdProcess } from './risd-helpers.mjs'
|
|
10
|
+
import { HAS_BASH, skipWithout } from './helpers/cmd.mjs'
|
|
12
11
|
|
|
13
12
|
let daemon
|
|
14
13
|
let workspace
|
|
15
14
|
|
|
16
|
-
function api(state, path, { method = 'GET', body } = {}) {
|
|
17
|
-
return new Promise((resolve) => {
|
|
18
|
-
const payload = body === undefined ? '' : JSON.stringify(body)
|
|
19
|
-
const req = request({
|
|
20
|
-
host: '127.0.0.1',
|
|
21
|
-
port: state.port,
|
|
22
|
-
path,
|
|
23
|
-
method,
|
|
24
|
-
timeout: 8000,
|
|
25
|
-
headers: Object.assign(
|
|
26
|
-
{ authorization: `Bearer ${state.token}`, 'x-risd-api-version': '1' },
|
|
27
|
-
payload === '' ? {} : { 'content-type': 'application/json', 'content-length': Buffer.byteLength(payload) },
|
|
28
|
-
),
|
|
29
|
-
}, (res) => {
|
|
30
|
-
let text = ''
|
|
31
|
-
res.setEncoding('utf8')
|
|
32
|
-
res.on('data', (chunk) => { text += chunk })
|
|
33
|
-
res.on('end', () => {
|
|
34
|
-
let parsed = null
|
|
35
|
-
try { parsed = JSON.parse(text) } catch { parsed = null }
|
|
36
|
-
resolve({ status: res.statusCode, body: parsed })
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
req.on('error', (error) => resolve({ status: 0, body: { error: String(error?.message) } }))
|
|
40
|
-
if (payload !== '') req.write(payload)
|
|
41
|
-
req.end()
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
15
|
before(async () => {
|
|
46
16
|
workspace = mkdtempSync(join(tmpdir(), 'risd-programs-ws-'))
|
|
47
17
|
mkdirSync(join(workspace, '.dsh-ris-ide'), { recursive: true })
|
|
@@ -80,7 +50,7 @@ test('GET /v1/programs lists the panel rows from the daemon', async () => {
|
|
|
80
50
|
assert.equal(res.body.dir, join(workspace, 'logs'))
|
|
81
51
|
})
|
|
82
52
|
|
|
83
|
-
test('start, stop and restart a program from the daemon', async () => {
|
|
53
|
+
test('start, stop and restart a program from the daemon', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
|
|
84
54
|
const started = await api(daemon.state, '/v1/programs', { method: 'POST', body: { cwd: workspace, action: 'start', id: 'demo' } })
|
|
85
55
|
assert.equal(started.status, 200)
|
|
86
56
|
assert.equal(started.body.ok, true)
|
|
@@ -121,7 +91,7 @@ test('log reads page by byte offset for a follower', async () => {
|
|
|
121
91
|
assert.ok(follow.body.nextOffset > offset)
|
|
122
92
|
})
|
|
123
93
|
|
|
124
|
-
test('an unknown program is a 404 with a readable message', async () => {
|
|
94
|
+
test('an unknown program is a 404 with a readable message', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
|
|
125
95
|
const res = await api(daemon.state, '/v1/programs', { method: 'POST', body: { cwd: workspace, action: 'start', id: 'nope' } })
|
|
126
96
|
assert.equal(res.status, 404)
|
|
127
97
|
assert.equal(res.body.ok, false)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon restart helpers (review A4-P2-5/P2-6/P2-7).
|
|
3
|
+
*
|
|
4
|
+
* `POST /v1/restart` cannot be exercised end-to-end from a unit test without
|
|
5
|
+
* replacing the real daemon, so the two pieces that carry the behaviour are tested
|
|
6
|
+
* directly: the successor argv (port + pid identity) and the wait that keeps a
|
|
7
|
+
* successor from stealing the port or waiting on a reused pid.
|
|
8
|
+
*/
|
|
9
|
+
import assert from 'node:assert/strict'
|
|
10
|
+
import test from 'node:test'
|
|
11
|
+
import { spawn } from 'node:child_process'
|
|
12
|
+
import { __test, readStartTime, successorArgs, waitForPidExit } from '../lib/risd/server.js'
|
|
13
|
+
|
|
14
|
+
/** Spawn a detached-ish node child that lives for `ms`; returns {child, done}. */
|
|
15
|
+
function liveChild(ms) {
|
|
16
|
+
const child = spawn(process.execPath, ['-e', `setTimeout(() => {}, ${ms})`], { stdio: 'ignore' })
|
|
17
|
+
const done = new Promise((resolve) => child.once('exit', resolve))
|
|
18
|
+
return { child, done }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test('the successor keeps the port the daemon actually bound and the pid identity (A4-P2-6/A4-P2-5)', () => {
|
|
22
|
+
const argv = successorArgs({ pid: 4321, port: 11082, startTime: '987654' })
|
|
23
|
+
assert.equal(argv[1], 'serve', 'the CLI is asked to serve')
|
|
24
|
+
assert.deepEqual(argv.slice(2, 4), ['--wait-pid', '4321'], 'it waits for this daemon pid')
|
|
25
|
+
assert.deepEqual(argv.slice(argv.indexOf('--port'), argv.indexOf('--port') + 2), ['--port', '11082'], 'it binds the same port, not the default')
|
|
26
|
+
assert.deepEqual(argv.slice(argv.indexOf('--wait-start'), argv.indexOf('--wait-start') + 2), ['--wait-start', '987654'], 'it carries the start time that proves the pid identity')
|
|
27
|
+
|
|
28
|
+
const defaulted = successorArgs({ pid: 7, port: 0, startTime: '' })
|
|
29
|
+
assert.equal(defaulted.includes('--port'), false, 'port 0 means "let the OS choose", never --port 0')
|
|
30
|
+
assert.equal(defaulted.includes('--wait-start'), false, 'no start time on platforms without /proc')
|
|
31
|
+
assert.deepEqual(defaulted.slice(2, 4), ['--wait-pid', '7'])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('waitForPidExit resolves as soon as the predecessor exits', async (t) => {
|
|
35
|
+
const { child, done } = liveChild(400)
|
|
36
|
+
t.after(() => child.kill('SIGKILL'))
|
|
37
|
+
const startedAt = Date.now()
|
|
38
|
+
const result = await waitForPidExit(child.pid, 5000)
|
|
39
|
+
const elapsed = Date.now() - startedAt
|
|
40
|
+
assert.deepEqual(result, { ok: true, timedOut: false })
|
|
41
|
+
assert.ok(elapsed >= 50, `waited at least one poll tick (${elapsed}ms)`)
|
|
42
|
+
await done
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('a reused pid is treated as exited instead of waited on (A4-P2-5)', async (t) => {
|
|
46
|
+
if (process.platform !== 'linux') return t.skip('start times come from /proc')
|
|
47
|
+
const { child } = liveChild(10_000)
|
|
48
|
+
t.after(() => child.kill('SIGKILL'))
|
|
49
|
+
const startedAt = Date.now()
|
|
50
|
+
// '1' is a valid-looking start time but cannot match this fresh child.
|
|
51
|
+
const result = await waitForPidExit(child.pid, 5000, '1')
|
|
52
|
+
const elapsed = Date.now() - startedAt
|
|
53
|
+
assert.deepEqual(result, { ok: true, timedOut: false }, 'a different start time proves the old process is gone')
|
|
54
|
+
assert.ok(elapsed < 1500, `did not wait for the unrelated process to exit (${elapsed}ms)`)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('a live pid with the matching start time makes waitForPidExit time out (A4-P2-5)', async (t) => {
|
|
58
|
+
if (process.platform !== 'linux') return t.skip('start times come from /proc')
|
|
59
|
+
const startTime = readStartTime(process.pid)
|
|
60
|
+
assert.match(startTime, /^\d+$/, '/proc/<pid>/stat exposes a numeric start time')
|
|
61
|
+
const startedAt = Date.now()
|
|
62
|
+
const result = await waitForPidExit(process.pid, 150, startTime)
|
|
63
|
+
const elapsed = Date.now() - startedAt
|
|
64
|
+
assert.deepEqual(result, { ok: false, timedOut: true })
|
|
65
|
+
assert.ok(elapsed >= 150, `honoured the deadline (${elapsed}ms)`)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('without a start time the wait falls back to kill(0) and still times out', async (t) => {
|
|
69
|
+
const { child } = liveChild(10_000)
|
|
70
|
+
t.after(() => child.kill('SIGKILL'))
|
|
71
|
+
const result = await waitForPidExit(child.pid, 200, '')
|
|
72
|
+
assert.deepEqual(result, { ok: false, timedOut: true })
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('a failed successor spawn clears restarting so a retry can work (A4-P2-7)', (t) => {
|
|
76
|
+
const original = __test.restartHooks.spawn
|
|
77
|
+
t.after(() => { __test.restartHooks.spawn = original; __test.setRestarting(false) })
|
|
78
|
+
__test.restartHooks.spawn = () => { throw new Error('spawn EACCES') }
|
|
79
|
+
__test.setRestarting(true)
|
|
80
|
+
const child = __test.spawnRestartSuccessor(11082)
|
|
81
|
+
assert.equal(child, null)
|
|
82
|
+
assert.equal(__test.isRestarting(), false, 'the next POST must be able to try again')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('the spawned successor carries the live port and a dying child clears restarting (A4-P2-6/A4-P2-7)', (t) => {
|
|
86
|
+
const original = __test.restartHooks.spawn
|
|
87
|
+
const handlers = {}
|
|
88
|
+
const fake = { unref() {}, once(event, fn) { handlers[event] = fn; return this } }
|
|
89
|
+
const calls = []
|
|
90
|
+
t.after(() => { __test.restartHooks.spawn = original; __test.setRestarting(false) })
|
|
91
|
+
__test.restartHooks.spawn = (...args) => { calls.push(args); return fake }
|
|
92
|
+
__test.setRestarting(true)
|
|
93
|
+
assert.equal(__test.spawnRestartSuccessor(11082), fake)
|
|
94
|
+
assert.equal(__test.isRestarting(), true, 'a pending successor keeps the restart flag set')
|
|
95
|
+
const argv = calls[0][1]
|
|
96
|
+
assert.equal(argv[1], 'serve')
|
|
97
|
+
assert.ok(argv.includes('--wait-pid'), 'the successor waits for this pid')
|
|
98
|
+
assert.deepEqual(argv.slice(argv.indexOf('--port'), argv.indexOf('--port') + 2), ['--port', '11082'], 'the successor binds the port this daemon actually bound')
|
|
99
|
+
handlers.error(new Error('ENOENT'))
|
|
100
|
+
assert.equal(__test.isRestarting(), false, 'a spawn error must not leave the daemon marked as restarting')
|
|
101
|
+
__test.setRestarting(true)
|
|
102
|
+
handlers.exit(3, null)
|
|
103
|
+
assert.equal(__test.isRestarting(), false, 'a successor exiting non-zero must not leave the daemon marked as restarting')
|
|
104
|
+
})
|
|
@@ -82,19 +82,6 @@ test('an oversized body gets a 413 answer instead of a broken socket (A-P2-6)',
|
|
|
82
82
|
}
|
|
83
83
|
})
|
|
84
84
|
|
|
85
|
-
test('/v1/config reports real values only (A-P2-3)', async () => {
|
|
86
|
-
const started = await startRisdProcess({ home: home() })
|
|
87
|
-
try {
|
|
88
|
-
const response = await httpJson(started.state.port, '/v1/config', { token: started.state.token })
|
|
89
|
-
assert.equal(response.status, 200)
|
|
90
|
-
assert.equal(response.body.idleExitMs, 10 * 60 * 1000)
|
|
91
|
-
assert.equal(response.body.engineRestart, undefined)
|
|
92
|
-
assert.ok(response.body.lifecycle)
|
|
93
|
-
} finally {
|
|
94
|
-
await started.stop()
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
85
|
test('/v1/dsh ignores windows whose url is not a loopback http(s) origin (A-P2-10)', async () => {
|
|
99
86
|
const dir = home()
|
|
100
87
|
const started = await startRisdProcess({ home: dir })
|
|
@@ -6,48 +6,15 @@
|
|
|
6
6
|
// by risd-handoff.test.mjs — it must keep them alive.
|
|
7
7
|
import assert from 'node:assert/strict'
|
|
8
8
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
9
|
-
import { request } from 'node:http'
|
|
10
9
|
import { tmpdir } from 'node:os'
|
|
11
10
|
import { join } from 'node:path'
|
|
12
11
|
import { after, before, test } from 'node:test'
|
|
13
|
-
import { sleep, startRisdProcess } from './risd-helpers.mjs'
|
|
12
|
+
import { api, pidAlive, sleep, startRisdProcess } from './risd-helpers.mjs'
|
|
13
|
+
import { HAS_BASH, skipWithout } from './helpers/cmd.mjs'
|
|
14
14
|
|
|
15
15
|
let daemon
|
|
16
16
|
let workspace
|
|
17
17
|
|
|
18
|
-
function api(state, path, { method = 'GET', body } = {}) {
|
|
19
|
-
return new Promise((resolve) => {
|
|
20
|
-
const payload = body === undefined ? '' : JSON.stringify(body)
|
|
21
|
-
const req = request({
|
|
22
|
-
host: '127.0.0.1',
|
|
23
|
-
port: state.port,
|
|
24
|
-
path,
|
|
25
|
-
method,
|
|
26
|
-
timeout: 8000,
|
|
27
|
-
headers: Object.assign(
|
|
28
|
-
{ authorization: `Bearer ${state.token}`, 'x-risd-api-version': '1' },
|
|
29
|
-
payload === '' ? {} : { 'content-type': 'application/json', 'content-length': Buffer.byteLength(payload) },
|
|
30
|
-
),
|
|
31
|
-
}, (res) => {
|
|
32
|
-
let text = ''
|
|
33
|
-
res.setEncoding('utf8')
|
|
34
|
-
res.on('data', (chunk) => { text += chunk })
|
|
35
|
-
res.on('end', () => {
|
|
36
|
-
let parsed = null
|
|
37
|
-
try { parsed = JSON.parse(text) } catch { parsed = null }
|
|
38
|
-
resolve({ status: res.statusCode, body: parsed })
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
req.on('error', (error) => resolve({ status: 0, body: { error: String(error?.message) } }))
|
|
42
|
-
if (payload !== '') req.write(payload)
|
|
43
|
-
req.end()
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function alive(pid) {
|
|
48
|
-
try { process.kill(pid, 0); return true } catch { return false }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
18
|
before(async () => {
|
|
52
19
|
workspace = mkdtempSync(join(tmpdir(), 'risd-shutdown-ws-'))
|
|
53
20
|
mkdirSync(join(workspace, '.dsh-ris-ide'), { recursive: true })
|
|
@@ -74,7 +41,7 @@ after(async () => {
|
|
|
74
41
|
if (workspace !== undefined) rmSync(workspace, { recursive: true, force: true })
|
|
75
42
|
})
|
|
76
43
|
|
|
77
|
-
test('shutdown stops the programs it supervises before exiting', async () => {
|
|
44
|
+
test('shutdown stops the programs it supervises before exiting', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
|
|
78
45
|
const started = await api(daemon.state, '/v1/programs', {
|
|
79
46
|
method: 'POST',
|
|
80
47
|
body: { cwd: workspace, action: 'start', id: 'demo' },
|
|
@@ -82,7 +49,7 @@ test('shutdown stops the programs it supervises before exiting', async () => {
|
|
|
82
49
|
assert.equal(started.status, 200, JSON.stringify(started.body))
|
|
83
50
|
const pid = started.body.pid
|
|
84
51
|
assert.ok(Number.isInteger(pid) && pid > 0, 'the start result carries the wrapper pid')
|
|
85
|
-
assert.equal(
|
|
52
|
+
assert.equal(pidAlive(pid), true, 'the program is running')
|
|
86
53
|
|
|
87
54
|
const shutdown = await api(daemon.state, '/v1/shutdown', { method: 'POST', body: { reason: 'test' } })
|
|
88
55
|
assert.equal(shutdown.status, 200)
|
|
@@ -90,7 +57,7 @@ test('shutdown stops the programs it supervises before exiting', async () => {
|
|
|
90
57
|
// Give the wrapper's TERM grace a moment, then require the process to be gone.
|
|
91
58
|
let gone = false
|
|
92
59
|
for (let attempt = 0; attempt < 60; attempt += 1) {
|
|
93
|
-
if (!
|
|
60
|
+
if (!pidAlive(pid)) { gone = true; break }
|
|
94
61
|
await sleep(200)
|
|
95
62
|
}
|
|
96
63
|
assert.equal(gone, true, 'stopping the daemon must not leave the program behind')
|
|
@@ -5,44 +5,25 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import assert from 'node:assert/strict'
|
|
7
7
|
import test from 'node:test'
|
|
8
|
-
import { existsSync, mkdtempSync, rmSync
|
|
8
|
+
import { existsSync, mkdtempSync, rmSync } from 'node:fs'
|
|
9
9
|
import { tmpdir } from 'node:os'
|
|
10
10
|
import { join } from 'node:path'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function headers(state) {
|
|
15
|
-
return { authorization: `Bearer ${state.token}`, 'x-risd-api-version': String(RISD_API_VERSION), 'content-type': 'application/json' }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Teardown is 300ms debounce + engine stop (5s grace) + bridge/git attempts; on a
|
|
19
|
-
// loaded machine (full suite, four files in parallel) that can exceed 8s even when
|
|
20
|
-
// the behaviour is correct, so the waits are generous on purpose.
|
|
21
|
-
async function waitFor(fn, timeoutMs = 15000) {
|
|
22
|
-
const deadline = Date.now() + timeoutMs
|
|
23
|
-
while (Date.now() < deadline) {
|
|
24
|
-
if (await fn()) return true
|
|
25
|
-
await sleep(120)
|
|
26
|
-
}
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
11
|
+
// The waits are deliberately generous: teardown is 300ms debounce + engine stop
|
|
12
|
+
// (5s grace) + bridge/git attempts, so `waitFor`'s 15s default is the floor.
|
|
13
|
+
import { makeHome, pickPort, removeHome, risdHeaders, sleep, startRisdProcess, waitFor, writeEngineFixture } from './risd-helpers.mjs'
|
|
29
14
|
|
|
30
15
|
async function startFixture(t) {
|
|
31
16
|
const home = makeHome('risd-teardown-')
|
|
32
17
|
const cwd = mkdtempSync(join(tmpdir(), 'risd-teardown-ws-'))
|
|
33
|
-
const port =
|
|
34
|
-
|
|
35
|
-
socks: { host: '127.0.0.1', port: 1, dbPort: 0, redisPort: 0 },
|
|
36
|
-
listenPort: port,
|
|
37
|
-
rules: [{ id: 'rule-1', program: 'java', hosts: ['127.0.0.1'], ports: ['443'], enabled: true, shadow: false, source: 'user', workspace: cwd }],
|
|
38
|
-
}))
|
|
18
|
+
const port = pickPort()
|
|
19
|
+
writeEngineFixture(home, port, { workspace: cwd })
|
|
39
20
|
const daemon = await startRisdProcess({ home, env: { DSH_RIS_IDE_PROXY_HOME: home } })
|
|
40
21
|
t.after(async () => {
|
|
41
22
|
await daemon.stop()
|
|
42
23
|
removeHome(home)
|
|
43
24
|
rmSync(cwd, { recursive: true, force: true })
|
|
44
25
|
})
|
|
45
|
-
const h =
|
|
26
|
+
const h = risdHeaders(daemon.state)
|
|
46
27
|
const startEngine = async () => {
|
|
47
28
|
const res = await fetch(`${daemon.state.url}/v1/engine`, { method: 'POST', headers: h, body: JSON.stringify({ action: 'start', cwd }) })
|
|
48
29
|
return res.json()
|
|
@@ -79,7 +60,7 @@ test('a dead owner is swept and then the engine is torn down', async (t) => {
|
|
|
79
60
|
|
|
80
61
|
const orphan = (await import('node:child_process')).spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore' })
|
|
81
62
|
t.after(() => orphan.kill('SIGKILL'))
|
|
82
|
-
const h =
|
|
63
|
+
const h = risdHeaders(fx.daemon.state)
|
|
83
64
|
await fetch(`${fx.daemon.state.url}/v1/leases`, { method: 'POST', headers: h, body: JSON.stringify({ ownerPid: orphan.pid, sessionId: 'gone', cwd: fx.cwd }) })
|
|
84
65
|
orphan.kill('SIGKILL')
|
|
85
66
|
|