dsh-ris-ide 1.8.1 → 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/README.md +2 -2
- package/lib/client.js +569 -98
- 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 +963 -64
- package/lib/redirector.js +76 -4
- package/lib/risd/lifecycle.js +54 -10
- package/lib/risd/ping.js +136 -17
- package/lib/risd/server.js +424 -22
- package/lib/risd/ui.js +218 -129
- package/lib/risd-client.js +4 -1
- package/lib/startup.js +27 -7
- package/package.json +2 -2
- package/test/client-viewer.test.mjs +268 -93
- 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 +190 -25
- package/test/proxy-route.test.mjs +61 -0
- package/test/proxy-window.test.mjs +5 -0
- package/test/proxy.test.mjs +40 -11
- package/test/proxybridge-bundle.test.mjs +1 -59
- package/test/redirector-bundle.test.mjs +21 -67
- package/test/redirector.test.mjs +71 -4
- package/test/risd-api.test.mjs +83 -29
- package/test/risd-bridge-degrade.test.mjs +3 -29
- package/test/risd-cli-home.test.mjs +41 -4
- package/test/risd-engine.test.mjs +13 -50
- package/test/risd-entry.test.mjs +0 -37
- package/test/risd-follow-start.test.mjs +102 -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 +203 -33
- package/test/risd-ping.test.mjs +77 -1
- package/test/risd-programs.test.mjs +4 -34
- 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 +205 -14
- package/test/risd-write.test.mjs +2 -1
- package/test/startup-reconcile.test.mjs +44 -8
- package/test/proxy-restart.test.mjs +0 -39
|
@@ -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)
|
|
@@ -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
|
|
package/test/risd-ui.test.mjs
CHANGED
|
@@ -163,9 +163,23 @@ test('the IDE tab drops the toolbar and names workspaces by folder', async () =>
|
|
|
163
163
|
assert.match(html, /\.then\(function \(\) \{ return loadHealth\(true\); \}\)/, 'a toggle re-probes health (engine state changed)')
|
|
164
164
|
assert.match(html, /代理引擎已停止,系统层拦截仍在运行/, 'engine stopped + bridge running is called out')
|
|
165
165
|
assert.match(html, /function stopStrayBridge/, 'the stray bridge can be stopped from the card')
|
|
166
|
-
assert.match(html, /id="bridge-
|
|
167
|
-
assert.match(html, /function
|
|
168
|
-
assert.match(html, /el\('bridge-
|
|
166
|
+
assert.match(html, /id="bridge-fix" hidden/, 'the card owns the single enforcement button (m13910)')
|
|
167
|
+
assert.match(html, /function fixBridge/, 'the attempt reports sudo/pkexec outcome in the banner')
|
|
168
|
+
assert.match(html, /el\('bridge-fix'\)\.onclick = fixBridge/)
|
|
169
|
+
assert.match(html, /function paintBridgeFix/, 'state decides the label: start vs restart')
|
|
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')
|
|
181
|
+
assert.doesNotMatch(html, /proxy-start-with-dsh/, 'the follow-dsh lifecycle checkbox is the only policy (m13950)')
|
|
182
|
+
assert.match(html, /dsh 接入时启动引擎/, 'the lifecycle row describes both halves of following dsh')
|
|
169
183
|
// The elevation note lives in the component card and clears itself (m12923).
|
|
170
184
|
assert.match(html, /id="bridge-elevate-note"/, 'the component card owns the elevation note')
|
|
171
185
|
assert.match(html, /function renderElevateNote\(health\)/)
|
|
@@ -185,7 +199,10 @@ test('the IDE tab drops the toolbar and names workspaces by folder', async () =>
|
|
|
185
199
|
assert.match(html, /function refreshPing/, 'the chip is refreshed, not written once')
|
|
186
200
|
assert.match(html, /setInterval\(refreshPing, 10000\)/, 'probing is periodic')
|
|
187
201
|
assert.match(html, /queuePing/, 'editing host/port re-probes before saving')
|
|
188
|
-
assert.match(html, /function workspaceLabel/, '
|
|
202
|
+
assert.match(html, /function workspaceLabel/, 'one label helper decides what a workspace is called')
|
|
203
|
+
assert.match(html, /typeof win\.title === 'string'/, 'the dsh sidebar title wins when the host resolved one (m13800)')
|
|
204
|
+
assert.match(html, /function workspacePathLabel/, 'the folder name stays as the fallback for an older host')
|
|
205
|
+
assert.match(html, /\|' \+ \(typeof win\.title === 'string' \? win\.title : ''\)/, 'a rename alone must repaint the panel')
|
|
189
206
|
assert.match(html, /parts\.slice\(-2\)\.join\('\/'\)/, 'collisions use the parent folder')
|
|
190
207
|
assert.match(html, /focusIdeFrame\(\)/, 'outside clicks send focus back into the iframe')
|
|
191
208
|
})
|
|
@@ -209,9 +226,11 @@ test('the proxy tab edits global rules without a workspace picker', async () =>
|
|
|
209
226
|
const html = page.text
|
|
210
227
|
assert.doesNotMatch(html, /id="proxy-cwd"/, 'rules are machine-wide: no workspace input')
|
|
211
228
|
assert.match(html, /全局规则:按机器生效、不区分工作区/)
|
|
212
|
-
assert.
|
|
229
|
+
assert.doesNotMatch(html, /id="bridge-restart"/, 'the merge moved the restart into the component card (m13910)')
|
|
213
230
|
assert.match(html, /为什么要重启/, 'its tooltip explains the reason')
|
|
214
231
|
assert.match(html, /setBridgeStale/)
|
|
232
|
+
assert.match(html, /bridgeStaleReason/, 'the stale reason is state, not a hidden input')
|
|
233
|
+
assert.match(html, /保存不会启动它/, 'a save names the start button instead of starting the engine')
|
|
215
234
|
})
|
|
216
235
|
|
|
217
236
|
test('the overview stop button is just 停止', async () => {
|
|
@@ -295,11 +314,34 @@ test('the overview offers lifecycle settings for daemon, proxy, programs and deb
|
|
|
295
314
|
const page = await call(daemon.state, '/ui', { token: null })
|
|
296
315
|
assert.equal(page.status, 200)
|
|
297
316
|
assert.match(page.text, /生命周期/)
|
|
298
|
-
|
|
317
|
+
// Toggling is the save (m13960): no button, no second confirmation step.
|
|
318
|
+
assert.doesNotMatch(page.text, /id="lifecycle-save"/)
|
|
319
|
+
assert.match(page.text, /勾选即自动保存/)
|
|
320
|
+
assert.match(page.text, /el\('lifecycle-rows'\)\.addEventListener\('change', scheduleLifecycleSave\)/)
|
|
321
|
+
assert.match(page.text, /function scheduleLifecycleSave\(\)/)
|
|
322
|
+
assert.match(page.text, /function saveLifecycle\(auto\)/)
|
|
323
|
+
assert.match(page.text, /已自动保存/)
|
|
324
|
+
// A toggle that lands mid-POST must not be undone by refilling the form from the
|
|
325
|
+
// daemon's (older) answer: the queued save carries it instead.
|
|
326
|
+
assert.match(page.text, /var queued = lifecycleQueued === true;/)
|
|
327
|
+
assert.match(page.text, /queued === true \? Promise\.resolve\(\) : loadLifecycle\(\)/)
|
|
299
328
|
assert.equal(page.text.includes('followDaemon'), false, 'following the daemon is forced, not configurable')
|
|
300
|
-
|
|
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']) {
|
|
301
333
|
assert.ok(page.text.includes(`data-life="${key}"`), `missing checkbox ${key}`)
|
|
302
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;/)
|
|
303
345
|
assert.match(page.text, /loadLifecycle/)
|
|
304
346
|
assert.match(page.text, /v1\/config/)
|
|
305
347
|
})
|
|
@@ -398,6 +440,136 @@ test('GET /v1/dsh greys the IDE tab out when no window is live', async () => {
|
|
|
398
440
|
assert.match(String(res.body.reason), /dsh 未运行/)
|
|
399
441
|
})
|
|
400
442
|
|
|
443
|
+
test('a sidebar snapshot with no remembered window still enables the IDE (m00186)', async () => {
|
|
444
|
+
// The plugin now publishes the sidebar (titles + sessions + origin) on its refresh
|
|
445
|
+
// tick even when dsh never served the IDE panel, so `windows` can legitimately be
|
|
446
|
+
// empty while the document proves dsh is alive. The page must offer every workspace
|
|
447
|
+
// instead of greying the tab out — switching workspaces is exactly what it is for.
|
|
448
|
+
const now = new Date().toISOString()
|
|
449
|
+
writeFileSync(join(daemon.home, 'dsh-window.json'), `${JSON.stringify({
|
|
450
|
+
windows: [],
|
|
451
|
+
workspaces: [
|
|
452
|
+
{ cwd: '/tmp/ws-a', title: 'alpha', sessionId: 's-a', active: true },
|
|
453
|
+
{ cwd: '/tmp/ws-b', title: 'beta', sessionId: '', active: false },
|
|
454
|
+
],
|
|
455
|
+
url: 'http://127.0.0.1:3080',
|
|
456
|
+
at: now,
|
|
457
|
+
})}\n`)
|
|
458
|
+
const res = await call(daemon.state, '/v1/dsh')
|
|
459
|
+
assert.equal(res.status, 200)
|
|
460
|
+
assert.equal(res.body.available, true, 'the sidebar snapshot is proof dsh is running')
|
|
461
|
+
assert.deepEqual(res.body.windows.map((row) => [row.cwd, row.title, row.live]), [
|
|
462
|
+
['/tmp/ws-a', 'alpha', true],
|
|
463
|
+
['/tmp/ws-b', 'beta', true],
|
|
464
|
+
], 'both workspaces are selectable, in the sidebar order')
|
|
465
|
+
assert.deepEqual(res.body.windows.map((row) => row.source), ['workspace', 'workspace'])
|
|
466
|
+
assert.equal(res.body.windows[0].sessionId, 's-a')
|
|
467
|
+
assert.equal(res.body.windows[1].sessionId, '', 'no session → the window page boots on the cwd')
|
|
468
|
+
assert.deepEqual(res.body.windows.map((row) => row.active), [true, false], 'a workspace without a live session is still listed')
|
|
469
|
+
assert.equal(res.body.url, 'http://127.0.0.1:3080')
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
test('the unavailable hint no longer asks the user to open the IDE panel first (m00186)', async () => {
|
|
473
|
+
// The old note told the user to open the RIS-IDE panel once — that request was the
|
|
474
|
+
// write which happened to seed dsh-window.json. The refresh tick publishes the
|
|
475
|
+
// sidebar by itself now, so promising it would be misleading.
|
|
476
|
+
const page = await call(daemon.state, '/ui', { token: null })
|
|
477
|
+
assert.match(page.text, /启动 dsh(工作区在 dsh 侧栏里)后,这里会自动可用/)
|
|
478
|
+
assert.doesNotMatch(page.text, /打开一次 RIS-IDE 面板/)
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
test('a workspace without a live session stays selectable, labelled 无会话 (m00186)', async () => {
|
|
482
|
+
// Switching workspaces is what the panel is for. A dsh workspace whose session is
|
|
483
|
+
// gone still opens: the window page boots on the cwd when it cannot resolve the
|
|
484
|
+
// session, so the row must not be hidden or disabled.
|
|
485
|
+
const probe = await pageProbe()
|
|
486
|
+
const windows = [
|
|
487
|
+
{ cwd: '/tmp/ws-a', title: 'alpha', sessionId: 's-a', url: 'http://127.0.0.1:3080', live: true, active: true },
|
|
488
|
+
{ cwd: '/tmp/ws-b', title: 'beta', sessionId: '', url: 'http://127.0.0.1:3080', live: true, active: false },
|
|
489
|
+
]
|
|
490
|
+
probe.page.renderIde(windows, windows[0])
|
|
491
|
+
const list = probe.el('ide-ws-list').innerHTML
|
|
492
|
+
assert.match(list, /data-cwd="\/tmp\/ws-a"/, 'the live workspace is a button')
|
|
493
|
+
assert.match(list, /data-cwd="\/tmp\/ws-b"/, 'the sessionless workspace is a button too')
|
|
494
|
+
assert.match(list, /alpha/)
|
|
495
|
+
assert.match(list, /beta(无会话)/, 'the label says why it may not resume')
|
|
496
|
+
assert.match(probe.el('ide-frame').src, /cwd=%2Ftmp%2Fws-a&sessionId=s-a/)
|
|
497
|
+
// Selecting the sessionless row must still produce a loadable window URL.
|
|
498
|
+
probe.page.selectIdeWindow(windows, '/tmp/ws-b')
|
|
499
|
+
const src = probe.el('ide-frame').src
|
|
500
|
+
assert.match(src, /cwd=%2Ftmp%2Fws-b/, 'boots on the cwd')
|
|
501
|
+
assert.doesNotMatch(src, /sessionId=/, 'no session to name: the host resolves the cwd instead')
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
test('the unavailable hint names the workspaces dsh did report (m00186)', async () => {
|
|
505
|
+
const probe = await pageProbe()
|
|
506
|
+
probe.page.ideUnavailable({ reason: 'dsh 正在启动', knownWorkspaces: 3 })
|
|
507
|
+
const html = probe.el('ide-msg').innerHTML
|
|
508
|
+
assert.match(html, /IDE 不可用:dsh 正在启动/)
|
|
509
|
+
assert.match(html, /已发现 3 个 dsh 工作区/, 'a count separates "starting" from "not installed"')
|
|
510
|
+
// No count → no dangling parenthesis when the host reported nothing at all.
|
|
511
|
+
probe.page.ideUnavailable({ reason: 'dsh 未运行' })
|
|
512
|
+
assert.doesNotMatch(probe.el('ide-msg').innerHTML, /已发现/)
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
test('GET /v1/dsh mirrors the dsh sidebar: every workspace, labelled by its title (m13800)', async () => {
|
|
516
|
+
// The plugin writes the sidebar snapshot next to the remembered windows. A workspace
|
|
517
|
+
// nobody opened the IDE for still belongs on the page, in the sidebar's own order,
|
|
518
|
+
// and the label is the dsh title — which is exactly what a rename changes.
|
|
519
|
+
const now = new Date().toISOString()
|
|
520
|
+
writeFileSync(join(daemon.home, 'dsh-window.json'), `${JSON.stringify({
|
|
521
|
+
windows: [
|
|
522
|
+
{ url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-a', sessionId: 's-a', title: 'alpha', at: now },
|
|
523
|
+
],
|
|
524
|
+
workspaces: [
|
|
525
|
+
{ cwd: '/tmp/ws-a', title: 'alpha', sessionId: 's-a' },
|
|
526
|
+
{ cwd: '/tmp/ws-b', title: 'beta', sessionId: '' },
|
|
527
|
+
],
|
|
528
|
+
url: 'http://127.0.0.1:3080',
|
|
529
|
+
at: now,
|
|
530
|
+
})}\n`)
|
|
531
|
+
const res = await call(daemon.state, '/v1/dsh')
|
|
532
|
+
assert.equal(res.status, 200)
|
|
533
|
+
assert.equal(res.body.available, true)
|
|
534
|
+
assert.deepEqual(res.body.windows.map((row) => [row.cwd, row.title, row.live]), [
|
|
535
|
+
['/tmp/ws-a', 'alpha', true],
|
|
536
|
+
['/tmp/ws-b', 'beta', true],
|
|
537
|
+
], 'sidebar order wins and both rows are selectable')
|
|
538
|
+
assert.equal(res.body.windows[1].source, 'workspace', 'a workspace without a window is not a remembered window')
|
|
539
|
+
assert.equal(res.body.windows[1].url, 'http://127.0.0.1:3080', 'the document origin carries it')
|
|
540
|
+
assert.equal(res.body.url, 'http://127.0.0.1:3080')
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
test('GET /v1/dsh re-labels a renamed workspace without losing it (m13800)', async () => {
|
|
544
|
+
// Rename = title change only: the path is the identity, so the same row comes back
|
|
545
|
+
// with the new label — the page must not fall back to the folder name.
|
|
546
|
+
const now = new Date().toISOString()
|
|
547
|
+
writeFileSync(join(daemon.home, 'dsh-window.json'), `${JSON.stringify({
|
|
548
|
+
windows: [{ url: 'http://127.0.0.1:3080', cwd: '/srv/apps/dzjg/workspace', sessionId: 's-a', title: 'dzjg-new', at: now }],
|
|
549
|
+
workspaces: [{ cwd: '/srv/apps/dzjg/workspace', title: 'dzjg-new', sessionId: 's-a' }],
|
|
550
|
+
url: 'http://127.0.0.1:3080',
|
|
551
|
+
at: now,
|
|
552
|
+
})}\n`)
|
|
553
|
+
const res = await call(daemon.state, '/v1/dsh')
|
|
554
|
+
assert.equal(res.body.windows.length, 1)
|
|
555
|
+
assert.equal(res.body.windows[0].cwd, '/srv/apps/dzjg/workspace', 'the path is untouched')
|
|
556
|
+
assert.equal(res.body.windows[0].title, 'dzjg-new')
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
test('GET /v1/dsh drops a stale sidebar snapshot but keeps fresh windows (m13800)', async () => {
|
|
560
|
+
// The snapshot is only good while its writer is alive: 8 days after the last answer
|
|
561
|
+
// the workspace list is gone, while the remembered window follows its own TTL.
|
|
562
|
+
const old = new Date(Date.now() - 8 * 24 * 3600_000).toISOString()
|
|
563
|
+
writeFileSync(join(daemon.home, 'dsh-window.json'), `${JSON.stringify({
|
|
564
|
+
windows: [{ url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-a', sessionId: 's-a', title: 'alpha', at: new Date().toISOString() }],
|
|
565
|
+
workspaces: [{ cwd: '/tmp/ws-a', title: 'alpha' }, { cwd: '/tmp/ws-gone', title: 'gone' }],
|
|
566
|
+
url: 'http://127.0.0.1:3080',
|
|
567
|
+
at: old,
|
|
568
|
+
})}\n`)
|
|
569
|
+
const res = await call(daemon.state, '/v1/dsh')
|
|
570
|
+
assert.deepEqual(res.body.windows.map((row) => row.cwd), ['/tmp/ws-a'])
|
|
571
|
+
})
|
|
572
|
+
|
|
401
573
|
test('the API is still authenticated (the page just carries the token)', async () => {
|
|
402
574
|
const res = await call(daemon.state, '/v1/workspaces', { token: null })
|
|
403
575
|
assert.equal(res.status, 401)
|
|
@@ -525,7 +697,7 @@ function loadPageProbe(script) {
|
|
|
525
697
|
}
|
|
526
698
|
const patched = script.replace(
|
|
527
699
|
/\}\)\(\);\s*$/,
|
|
528
|
-
'; globalThis.__pageProbe = { state: state, renderHealth: renderHealth, stopStrayBridge: stopStrayBridge, driftSaveThenReload: driftSaveThenReload }; })();',
|
|
700
|
+
'; globalThis.__pageProbe = { state: state, renderHealth: renderHealth, stopStrayBridge: stopStrayBridge, driftSaveThenReload: driftSaveThenReload, paintBridgeFix: paintBridgeFix, fixBridge: fixBridge, renderIde: renderIde, ideUnavailable: ideUnavailable, selectIdeWindow: selectIdeWindow }; })();',
|
|
529
701
|
)
|
|
530
702
|
const run = new Function('document', 'window', 'localStorage', 'fetch', 'setInterval', 'clearInterval', 'setTimeout', 'location', patched)
|
|
531
703
|
run(document, win, storage, fetch, () => 0, () => {}, () => 0, win.location)
|
|
@@ -543,10 +715,10 @@ async function pageProbe() {
|
|
|
543
715
|
}
|
|
544
716
|
}
|
|
545
717
|
|
|
546
|
-
test('the
|
|
718
|
+
test('the enforcement button stays disabled while a request is in flight', async () => {
|
|
547
719
|
const probe = await pageProbe()
|
|
548
720
|
probe.page.state.stopBusy = true
|
|
549
|
-
probe.page.state.
|
|
721
|
+
probe.page.state.fixBusy = true
|
|
550
722
|
probe.page.renderHealth({
|
|
551
723
|
ok: true,
|
|
552
724
|
engineRunning: true,
|
|
@@ -555,10 +727,10 @@ test('the health card keeps its buttons disabled while a request is in flight',
|
|
|
555
727
|
stray: { linux: true, windows: false },
|
|
556
728
|
})
|
|
557
729
|
assert.equal(probe.el('bridge-health-stop').disabled, true, 'the stop button stays disabled')
|
|
558
|
-
assert.equal(probe.el('bridge-
|
|
730
|
+
assert.equal(probe.el('bridge-fix').disabled, true, 'the enforcement button stays disabled')
|
|
559
731
|
|
|
560
732
|
probe.page.state.stopBusy = false
|
|
561
|
-
probe.page.state.
|
|
733
|
+
probe.page.state.fixBusy = false
|
|
562
734
|
probe.page.renderHealth({
|
|
563
735
|
ok: true,
|
|
564
736
|
engineRunning: true,
|
|
@@ -567,8 +739,15 @@ test('the health card keeps its buttons disabled while a request is in flight',
|
|
|
567
739
|
stray: { linux: false, windows: false },
|
|
568
740
|
})
|
|
569
741
|
assert.equal(probe.el('bridge-health-stop').disabled, false, 'idle renders re-enable the stop button')
|
|
570
|
-
assert.equal(probe.el('bridge-
|
|
571
|
-
assert.equal(probe.el('bridge-
|
|
742
|
+
assert.equal(probe.el('bridge-fix').disabled, false, 'idle renders re-enable the enforcement button')
|
|
743
|
+
assert.equal(probe.el('bridge-fix').textContent, '启动系统层拦截(可能提权)', 'a missing side starts')
|
|
744
|
+
|
|
745
|
+
// A stale reload wins over the missing side: the click must stop the old profile
|
|
746
|
+
// before it starts the new one, so the label says restart (m13910).
|
|
747
|
+
probe.page.state.bridgeStaleReason = '规则未重载'
|
|
748
|
+
probe.page.paintBridgeFix()
|
|
749
|
+
assert.equal(probe.el('bridge-fix').textContent, '重启系统层拦截(可能提权)')
|
|
750
|
+
assert.match(probe.el('bridge-fix').title, /为什么要重启/)
|
|
572
751
|
})
|
|
573
752
|
|
|
574
753
|
test('a second click while a health action is in flight is ignored', async () => {
|
|
@@ -605,3 +784,15 @@ test('the drift path confirms unsaved lifecycle settings too', async () => {
|
|
|
605
784
|
const restart = source.slice(source.indexOf('function restartDaemonThenReload()'), source.indexOf('function reloadPage()'))
|
|
606
785
|
assert.match(restart, /lifecycleDirty === true && window\.confirm\('生命周期设置还没保存,重启并刷新会丢失'\)/)
|
|
607
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
|
+
})
|
package/test/risd-write.test.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import { RISD_API_VERSION } from '../lib/risd/state.js'
|
|
|
17
17
|
import { readProxyConfig } from '../lib/proxy.js'
|
|
18
18
|
import { risdConfigRevision } from '../lib/risd/view.js'
|
|
19
19
|
import { makeHome, removeHome, startRisdProcess } from './risd-helpers.mjs'
|
|
20
|
+
import { HAS_GIT, skipWithout } from './helpers/cmd.mjs'
|
|
20
21
|
|
|
21
22
|
const FIXTURE = {
|
|
22
23
|
socks: { host: 'proxy.example.com', port: 10080 },
|
|
@@ -130,7 +131,7 @@ test('injection is the same object the engine would inject (direct vs allow-list
|
|
|
130
131
|
assert.equal((await missing.json()).injection, null, 'no enabled rule for node → nothing injected')
|
|
131
132
|
})
|
|
132
133
|
|
|
133
|
-
test('a save re-points the scoped git entry instead of hiding the old host', async (t) => {
|
|
134
|
+
test('a save re-points the scoped git entry instead of hiding the old host', { skip: skipWithout(HAS_GIT, 'git') }, async (t) => {
|
|
134
135
|
const home = makeHome('risd-git-save-')
|
|
135
136
|
const gitconfig = join(home, 'gitconfig')
|
|
136
137
|
writeFileSync(gitconfig, '')
|
|
@@ -9,11 +9,24 @@ import { tmpdir } from 'node:os'
|
|
|
9
9
|
import { join } from 'node:path'
|
|
10
10
|
import { after, before, test } from 'node:test'
|
|
11
11
|
import { reconcileStartupLeftovers } from '../lib/startup.js'
|
|
12
|
+
import { HAS_GIT, skipWithout } from './helpers/cmd.mjs'
|
|
12
13
|
|
|
13
14
|
let root
|
|
14
15
|
let home
|
|
15
16
|
let gitConfig
|
|
16
17
|
|
|
18
|
+
// The bridge probes are injected, never real: `redirectorStatusCached()` spawns
|
|
19
|
+
// PowerShell on WSL (seconds) and answers differently depending on whether the
|
|
20
|
+
// developer's own bridge is running, and `restoreWindowsService()` really runs
|
|
21
|
+
// `Set-Service`/`Start-Service`. A test that let both run was slow, flaky, and
|
|
22
|
+
// could restart the machine's ProxyBridgeSvc.
|
|
23
|
+
const idleBridge = { status: () => ({ running: false }), restore: () => ({ restored: false, reason: '未停止过服务' }) }
|
|
24
|
+
|
|
25
|
+
/** Reconcile with the bridge probes stubbed; `extra` overrides them per test. */
|
|
26
|
+
function reconcile(extra = {}) {
|
|
27
|
+
return reconcileStartupLeftovers(Object.assign({}, idleBridge, extra))
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
function git(args) {
|
|
18
31
|
const res = spawnSync('git', args, { encoding: 'utf8', env: process.env })
|
|
19
32
|
assert.equal(res.status, 0, `git ${args.join(' ')}: ${res.stderr}`)
|
|
@@ -49,27 +62,27 @@ after(() => {
|
|
|
49
62
|
})
|
|
50
63
|
|
|
51
64
|
test('a clean machine is a no-op', async () => {
|
|
52
|
-
const result = await
|
|
65
|
+
const result = await reconcile()
|
|
53
66
|
assert.equal(result.ok, true)
|
|
54
67
|
assert.deepEqual(result.notes, [])
|
|
55
68
|
})
|
|
56
69
|
|
|
57
|
-
test('a git entry from a dead engine is removed (it is ours)', async () => {
|
|
70
|
+
test('a git entry from a dead engine is removed (it is ours)', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
|
|
58
71
|
const key = 'http.https://git.example.com/.proxy'
|
|
59
72
|
const value = 'socks5h://10.0.0.1:1080'
|
|
60
73
|
writeGitState({ key, host: 'git.example.com', value })
|
|
61
74
|
git(['config', '--global', key, value])
|
|
62
|
-
const result = await
|
|
75
|
+
const result = await reconcile()
|
|
63
76
|
assert.ok(result.notes.some((note) => /git 代理/.test(note)), result.notes.join('; '))
|
|
64
77
|
assert.equal(gitGet(key), '')
|
|
65
78
|
assert.equal(existsSync(join(home, 'git-proxy.json')), false, 'state file is gone')
|
|
66
79
|
})
|
|
67
80
|
|
|
68
|
-
test('a foreign git value is left alone', async () => {
|
|
81
|
+
test('a foreign git value is left alone', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
|
|
69
82
|
const key = 'http.https://other.example.com/.proxy'
|
|
70
83
|
writeGitState({ key, host: 'other.example.com', value: 'socks5h://10.0.0.1:1080' })
|
|
71
84
|
git(['config', '--global', key, 'http://corp-proxy:3128'])
|
|
72
|
-
const result = await
|
|
85
|
+
const result = await reconcile()
|
|
73
86
|
assert.ok(result.notes.some((note) => /保留了/.test(note)), result.notes.join('; '))
|
|
74
87
|
assert.equal(gitGet(key), 'http://corp-proxy:3128')
|
|
75
88
|
})
|
|
@@ -77,7 +90,7 @@ test('a foreign git value is left alone', async () => {
|
|
|
77
90
|
test('a stale pidfile and a dead risd.json are cleared', async () => {
|
|
78
91
|
writeFileSync(join(home, 'proxy.pid'), '999999\n', 'utf8')
|
|
79
92
|
writeFileSync(join(home, 'risd.json'), `${JSON.stringify({ pid: 999999, port: 1, token: 'x', apiVersion: 1 })}\n`, 'utf8')
|
|
80
|
-
const result = await
|
|
93
|
+
const result = await reconcile()
|
|
81
94
|
assert.equal(existsSync(join(home, 'proxy.pid')), false, 'stale pidfile removed')
|
|
82
95
|
assert.equal(existsSync(join(home, 'risd.json')), false, 'dead daemon state removed')
|
|
83
96
|
assert.ok(result.notes.length >= 2, result.notes.join('; '))
|
|
@@ -89,12 +102,35 @@ test('a parked ProxyBridgeSvc is restored and its state cleared', async () => {
|
|
|
89
102
|
writeFileSync(join(dir, 'proxybridge-service.json'), `${JSON.stringify({
|
|
90
103
|
at: Date.now(), stoppedByUs: true, originalStartType: 'Automatic', parkedOnManual: true,
|
|
91
104
|
})}\n`, 'utf8')
|
|
92
|
-
|
|
105
|
+
let restores = 0
|
|
106
|
+
const result = await reconcile({ restore: () => { restores += 1; return { restored: true } } })
|
|
107
|
+
assert.equal(restores, 1, 'a parked service is restored exactly once')
|
|
93
108
|
assert.ok(result.notes.some((note) => /ProxyBridgeSvc/.test(note)), result.notes.join('; '))
|
|
94
109
|
assert.equal(existsSync(join(dir, 'proxybridge-service.json')), false, 'service state cleared')
|
|
95
110
|
})
|
|
96
111
|
|
|
97
|
-
test('
|
|
112
|
+
test('a parked service is left alone while the bridge is still running', async () => {
|
|
113
|
+
// The restore only makes sense after a reboot: a bridge that is up right now owns
|
|
114
|
+
// the service, and stopping it under the bridge would fight the driver for
|
|
115
|
+
// WinDivert. This branch is why the same test used to pass or fail depending on
|
|
116
|
+
// whether the developer's ProxyBridge happened to be running.
|
|
117
|
+
const dir = join(home, 'proxybridge')
|
|
118
|
+
mkdirSync(dir, { recursive: true })
|
|
119
|
+
writeFileSync(join(dir, 'proxybridge-service.json'), `${JSON.stringify({
|
|
120
|
+
at: Date.now(), stoppedByUs: true, originalStartType: 'Automatic', parkedOnManual: true,
|
|
121
|
+
})}\n`, 'utf8')
|
|
122
|
+
let restores = 0
|
|
123
|
+
const result = await reconcile({
|
|
124
|
+
status: () => ({ running: true }),
|
|
125
|
+
restore: () => { restores += 1; return { restored: true } },
|
|
126
|
+
})
|
|
127
|
+
assert.equal(restores, 0, 'a running bridge keeps its service')
|
|
128
|
+
assert.equal(result.notes.some((note) => /ProxyBridgeSvc/.test(note)), false, result.notes.join('; '))
|
|
129
|
+
assert.equal(existsSync(join(dir, 'proxybridge-service.json')), true, 'state kept for the next start')
|
|
130
|
+
rmSync(join(dir, 'proxybridge-service.json'), { force: true })
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('the git config file is only touched for our own entries', { skip: skipWithout(HAS_GIT, 'git') }, () => {
|
|
98
134
|
const text = readFileSync(gitConfig, 'utf8')
|
|
99
135
|
assert.doesNotMatch(text, /git\.example\.com/)
|
|
100
136
|
})
|