dsh-ris-ide 1.7.3 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +21 -7
  2. package/bin/proxy-janitor.mjs +106 -11
  3. package/bin/risd.mjs +284 -0
  4. package/bin/run-with-log.ps1 +43 -5
  5. package/lib/client.js +609 -1178
  6. package/lib/index.js +1124 -55
  7. package/lib/janitor.js +106 -15
  8. package/lib/proxy.js +86 -7
  9. package/lib/proxybridge-bundle.js +798 -0
  10. package/lib/proxybridge-health.js +206 -0
  11. package/lib/redirector.js +1615 -115
  12. package/lib/risd/build.js +91 -0
  13. package/lib/risd/debug.js +374 -0
  14. package/lib/risd/git.js +207 -0
  15. package/lib/risd/leases.js +124 -0
  16. package/lib/risd/lifecycle.js +148 -0
  17. package/lib/risd/log.js +59 -0
  18. package/lib/risd/ping.js +94 -0
  19. package/lib/risd/programs.js +348 -0
  20. package/lib/risd/server.js +1919 -0
  21. package/lib/risd/state.js +137 -0
  22. package/lib/risd/ui.js +1989 -0
  23. package/lib/risd/view.js +79 -0
  24. package/lib/risd-client.js +282 -0
  25. package/lib/standalone/window.html +14 -16
  26. package/lib/startup.js +114 -0
  27. package/package.json +4 -1
  28. package/test/client-build.test.mjs +113 -0
  29. package/test/client-viewer.test.mjs +279 -227
  30. package/test/dsh-origin.test.mjs +140 -0
  31. package/test/dsh-window-refresh.test.mjs +100 -0
  32. package/test/harness.test.mjs +9 -0
  33. package/test/host-noloop.test.mjs +74 -0
  34. package/test/host-tail.test.mjs +21 -4
  35. package/test/host-window.test.mjs +4 -4
  36. package/test/janitor.test.mjs +29 -1
  37. package/test/lifecycle.test.mjs +26 -5
  38. package/test/merge-owners.test.mjs +155 -0
  39. package/test/proxy-restart.test.mjs +39 -0
  40. package/test/proxy-window.test.mjs +45 -0
  41. package/test/proxy.test.mjs +41 -0
  42. package/test/proxybridge-bundle.test.mjs +687 -0
  43. package/test/proxybridge-health.test.mjs +116 -0
  44. package/test/redirector-bundle.test.mjs +391 -0
  45. package/test/redirector.test.mjs +413 -10
  46. package/test/risd-api.test.mjs +514 -0
  47. package/test/risd-bridge-degrade.test.mjs +101 -0
  48. package/test/risd-build.test.mjs +20 -0
  49. package/test/risd-cli-home.test.mjs +50 -0
  50. package/test/risd-client.test.mjs +130 -0
  51. package/test/risd-debug.test.mjs +261 -0
  52. package/test/risd-election.test.mjs +104 -0
  53. package/test/risd-engine.test.mjs +132 -0
  54. package/test/risd-entry.test.mjs +118 -0
  55. package/test/risd-git.test.mjs +109 -0
  56. package/test/risd-handoff.test.mjs +116 -0
  57. package/test/risd-heal.test.mjs +50 -0
  58. package/test/risd-helpers.mjs +108 -0
  59. package/test/risd-host-p2.test.mjs +147 -0
  60. package/test/risd-janitor-guard.test.mjs +46 -0
  61. package/test/risd-lease.test.mjs +83 -0
  62. package/test/risd-lifecycle.test.mjs +210 -0
  63. package/test/risd-log-follow.test.mjs +227 -0
  64. package/test/risd-mode.test.mjs +161 -0
  65. package/test/risd-ping.test.mjs +99 -0
  66. package/test/risd-programs.test.mjs +169 -0
  67. package/test/risd-restart.test.mjs +104 -0
  68. package/test/risd-review-p2.test.mjs +217 -0
  69. package/test/risd-shutdown.test.mjs +97 -0
  70. package/test/risd-teardown.test.mjs +87 -0
  71. package/test/risd-tools.test.mjs +211 -0
  72. package/test/risd-ui.test.mjs +607 -0
  73. package/test/risd-write.test.mjs +170 -0
  74. package/test/startup-reconcile.test.mjs +100 -0
  75. package/test/windows.test.mjs +37 -2
@@ -0,0 +1,140 @@
1
+ // The plugin's half of the daemon page's IDE tab: it records the browser's origin
2
+ // plus the current dsh sessionId into `dsh-window.json`, per workspace, so one
3
+ // daemon page can embed the IDE of every workspace someone has open.
4
+ //
5
+ // Only loopback Hosts are recorded (the daemon page itself is loopback-only too).
6
+ import assert from 'node:assert/strict'
7
+ import { createServer, request } from 'node:http'
8
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
9
+ import { tmpdir } from 'node:os'
10
+ import { join } from 'node:path'
11
+ import { after, before, test } from 'node:test'
12
+ import { handleRequest } from '../lib/index.js'
13
+
14
+ let home
15
+ let workspace
16
+ let server
17
+ let port
18
+
19
+ before(async () => {
20
+ home = mkdtempSync(join(tmpdir(), 'dsh-origin-home-'))
21
+ workspace = mkdtempSync(join(tmpdir(), 'dsh-origin-ws-'))
22
+ process.env.DSH_RIS_IDE_PROXY_HOME = home
23
+ process.env.DSH_RIS_IDE_WINDOW_NOTE = '1'
24
+ server = createServer((req, res) => {
25
+ handleRequest({ sessions: { get: () => ({ header: { cwd: workspace } }) } }, req, res, { maxBytes: 1024, restrictToCwd: false })
26
+ })
27
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
28
+ port = server.address().port
29
+ })
30
+
31
+ after(async () => {
32
+ await new Promise((resolve) => server.close(resolve))
33
+ delete process.env.DSH_RIS_IDE_PROXY_HOME
34
+ delete process.env.DSH_RIS_IDE_WINDOW_NOTE
35
+ rmSync(home, { recursive: true, force: true })
36
+ rmSync(workspace, { recursive: true, force: true })
37
+ })
38
+
39
+ function get(path, host) {
40
+ return new Promise((resolve) => {
41
+ const call = request({ host: '127.0.0.1', port, path, method: 'GET', headers: { host: host ?? `127.0.0.1:${port}` } }, (res) => {
42
+ res.resume()
43
+ res.on('end', () => resolve(res.statusCode))
44
+ })
45
+ call.on('error', () => resolve(0))
46
+ call.end()
47
+ })
48
+ }
49
+
50
+ function readWindows() {
51
+ const file = join(home, 'dsh-window.json')
52
+ if (!existsSync(file)) return null
53
+ return JSON.parse(readFileSync(file, 'utf8')).windows
54
+ }
55
+
56
+ test('a loopback request records the dsh origin and session per workspace', async () => {
57
+ const status = await get(`/dsh-ris-ide/windows?sessionId=sess-1&cwd=${encodeURIComponent(workspace)}`)
58
+ assert.equal(status, 200)
59
+ const windows = readWindows()
60
+ assert.ok(Array.isArray(windows), 'dsh-window.json must hold a windows array')
61
+ assert.equal(windows.length, 1)
62
+ assert.equal(windows[0].url, `http://127.0.0.1:${port}`)
63
+ assert.equal(windows[0].sessionId, 'sess-1')
64
+ assert.equal(windows[0].cwd, workspace)
65
+ })
66
+
67
+ test('a probe without a dsh session is not recorded as a workspace', async () => {
68
+ // `/windows?cwd=` probes come from the standalone/maintenance page and carry no
69
+ // session. Inheriting the previous window's id opened the IDE with the wrong
70
+ // session and made the liveness check prune the wrong entry (C2-P1-2).
71
+ const before = readWindows().length
72
+ const status = await get(`/dsh-ris-ide/windows?cwd=${encodeURIComponent(workspace)}`)
73
+ assert.equal(status, 200)
74
+ const after = readWindows()
75
+ assert.equal(after.length, before, 'nothing may be recorded without a sessionId')
76
+ assert.ok(after.every((row) => row.sessionId !== ''), 'every stored row names a real session')
77
+ })
78
+
79
+ test('a non-loopback Host is not recorded', async () => {
80
+ const before = readWindows().length
81
+ const status = await get(`/dsh-ris-ide/windows?sessionId=sess-evil&cwd=${encodeURIComponent(workspace)}`, 'evil.example:80')
82
+ assert.equal(status, 403)
83
+ assert.equal(readWindows().length, before, 'a foreign origin cannot seed the IDE list')
84
+ })
85
+
86
+ test('a second workspace upserts instead of replacing the list', async () => {
87
+ const other = mkdtempSync(join(tmpdir(), 'dsh-origin-ws2-'))
88
+ try {
89
+ const status = await get(`/dsh-ris-ide/windows?sessionId=sess-2&cwd=${encodeURIComponent(other)}`)
90
+ assert.equal(status, 200)
91
+ const windows = readWindows()
92
+ assert.equal(windows.length, 2, 'both workspaces are listed')
93
+ assert.deepEqual(windows.map((row) => row.sessionId).sort(), ['sess-1', 'sess-2'])
94
+ // A brand-new workspace is written immediately. Re-recording one that is already
95
+ // there is throttled to one write per 3 s (review C3-P2-6), so the order of the
96
+ // second call below is not promised — only that nothing duplicates.
97
+ const statusAgain = await get(`/dsh-ris-ide/windows?sessionId=sess-1&cwd=${encodeURIComponent(workspace)}`)
98
+ assert.equal(statusAgain, 200)
99
+ const after = readWindows()
100
+ assert.equal(after.length, 2, 'the same workspace must not duplicate')
101
+ assert.deepEqual(after.map((row) => row.cwd).sort(), [workspace, other].sort())
102
+ } finally {
103
+ rmSync(other, { recursive: true, force: true })
104
+ }
105
+ })
106
+
107
+ test('alternating known workspaces does not write on every request', async () => {
108
+ // Two dsh windows take turns hitting the plugin; each request used to rewrite the
109
+ // machine-level file (~one synchronous read+write per request). Now an already
110
+ // recorded workspace inside the 3 s window only moves the in-memory key.
111
+ const rows = readWindows()
112
+ // One request first: either it writes (the window had expired) or it is already
113
+ // inside the window — both leave the throttle armed for the loop below.
114
+ await get(`/dsh-ris-ide/windows?sessionId=${rows[0].sessionId}&cwd=${encodeURIComponent(rows[0].cwd)}`)
115
+ const before = readFileSync(join(home, 'dsh-window.json'), 'utf8')
116
+ for (const row of rows) {
117
+ await get(`/dsh-ris-ide/windows?sessionId=${row.sessionId}&cwd=${encodeURIComponent(row.cwd)}`)
118
+ }
119
+ const after = readFileSync(join(home, 'dsh-window.json'), 'utf8')
120
+ assert.equal(after, before, 'nothing was rewritten inside the throttle window')
121
+ })
122
+
123
+ test('a non-loopback Host header records nothing', async () => {
124
+ const before = readWindows()
125
+ // The route itself may refuse a non-loopback Host (403); recording must not happen either way.
126
+ const status = await get('/dsh-ris-ide/windows?sessionId=sess-evil', 'evil.example.com')
127
+ assert.ok(status === 200 || status === 403, `unexpected status ${status}`)
128
+ const after = readWindows()
129
+ assert.equal(JSON.stringify(after), JSON.stringify(before))
130
+ })
131
+
132
+ test('a request without a workspace does not replace another workspace entry', async () => {
133
+ // Review C-P1-5: the empty-cwd entry used `existing[0].cwd` as its key, so a
134
+ // bare /dsh-ris-ide/proxy call overwrote somebody else's window entry.
135
+ const before = readWindows()
136
+ const status = await get('/dsh-ris-ide/proxy?sessionId=sess-3')
137
+ assert.equal(status, 200)
138
+ const after = readWindows()
139
+ assert.deepEqual(after.map((row) => row.cwd), before.map((row) => row.cwd), 'the list is unchanged')
140
+ })
@@ -0,0 +1,100 @@
1
+ // The plugin is the only writer of dsh-window.json, so it must also keep the
2
+ // entries fresh while dsh still knows their session (m08228). Without this the
3
+ // daemon page would list only the workspace that happened to call an endpoint
4
+ // inside the freshness window.
5
+ import assert from 'node:assert/strict'
6
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
7
+ import { tmpdir } from 'node:os'
8
+ import { join } from 'node:path'
9
+ import { after, before, test } from 'node:test'
10
+ import { __test } from '../lib/index.js'
11
+
12
+ let home
13
+
14
+ before(() => {
15
+ home = mkdtempSync(join(tmpdir(), 'dsh-window-refresh-'))
16
+ process.env.DSH_RIS_IDE_PROXY_HOME = home
17
+ })
18
+
19
+ after(() => {
20
+ delete process.env.DSH_RIS_IDE_PROXY_HOME
21
+ rmSync(home, { recursive: true, force: true })
22
+ })
23
+
24
+ function writeWindows(windows) {
25
+ writeFileSync(join(home, 'dsh-window.json'), `${JSON.stringify({ windows })}\n`, { mode: 0o600 })
26
+ }
27
+
28
+ function readWindows() {
29
+ return JSON.parse(readFileSync(join(home, 'dsh-window.json'), 'utf8')).windows
30
+ }
31
+
32
+ test('a session dsh still knows is refreshed, a gone one is dropped', () => {
33
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
34
+ writeWindows([
35
+ { url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-a', sessionId: 's-live', at: old },
36
+ { url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-b', sessionId: 's-gone', at: old },
37
+ ])
38
+ const result = __test.refreshDshWindows({
39
+ sessions: { get: (id) => (id === 's-live' ? { header: { cwd: '/tmp/ws-a' } } : null) },
40
+ })
41
+ // `windows` counts what SURVIVES: the pre-prune number misled callers (E P2-2).
42
+ assert.deepEqual(result, { changed: 1, windows: 1, dropped: 1 })
43
+ const rewritten = readWindows()
44
+ assert.equal(rewritten.length, 1)
45
+ assert.equal(rewritten[0].sessionId, 's-live')
46
+ assert.notEqual(rewritten[0].at, old, 'the live session is refreshed')
47
+ })
48
+
49
+ test('entries whose session dsh dropped are pruned', () => {
50
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
51
+ writeWindows([{ url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-b', sessionId: 's-gone', at: old }])
52
+ const result = __test.refreshDshWindows({ sessions: { get: () => null } })
53
+ assert.deepEqual(result, { changed: 0, windows: 0, dropped: 1 })
54
+ assert.deepEqual(readWindows(), [])
55
+ })
56
+
57
+ test('an entry without a session id is kept (nothing to verify)', () => {
58
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
59
+ writeWindows([{ url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-c', at: old }])
60
+ assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => null } }), { changed: 0, windows: 1, dropped: 0 })
61
+ assert.equal(readWindows().length, 1)
62
+ })
63
+
64
+ test('a missing window list is a no-op', () => {
65
+ rmSync(join(home, 'dsh-window.json'), { force: true })
66
+ assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => ({}) } }), { changed: 0, windows: 0, dropped: 0 })
67
+ })
68
+
69
+ test("another dsh instance's rows are left alone", () => {
70
+ // The home is machine-wide: two dsh processes share dsh-window.json, and each may
71
+ // only vouch for sessions IT knows. A row stamped with a foreign ownerPid must
72
+ // survive even though this process cannot resolve its sessionId (review C2-P2-2).
73
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
74
+ writeWindows([
75
+ { url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-other', sessionId: 's-foreign', ownerPid: 999999, at: old },
76
+ ])
77
+ assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => null } }), { changed: 0, windows: 1, dropped: 0 })
78
+ assert.equal(readWindows()[0].sessionId, 's-foreign')
79
+ })
80
+
81
+ test('a garbage ownerPid makes the row ours, not somebody else\'s', () => {
82
+ // Number('abc') is NaN: the old test treated that as "non-finite, not a foreign
83
+ // owner" and pruned the row as if it were ours-but-unknown. It must at least go
84
+ // through the same ownership check as a legacy row (no ownerPid) — review C3-P2-5.
85
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
86
+ writeWindows([{ url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-garbage', sessionId: 's-garbage', ownerPid: 'abc', at: old }])
87
+ const result = __test.refreshDshWindows({
88
+ sessions: { get: (id) => (id === 's-garbage' ? { header: { cwd: '/tmp/ws-garbage' } } : null) },
89
+ })
90
+ assert.deepEqual(result, { changed: 1, windows: 1, dropped: 0 }, 'the known session is refreshed')
91
+ assert.notEqual(readWindows()[0].at, old)
92
+ })
93
+
94
+ test('a session that reopened on another workspace drops the stale row', () => {
95
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
96
+ writeWindows([{ url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-moved', sessionId: 's-moved', at: old }])
97
+ const result = __test.refreshDshWindows({ sessions: { get: () => ({ header: { cwd: '/tmp/ws-new' } }) } })
98
+ assert.deepEqual(result, { changed: 0, windows: 0, dropped: 1 })
99
+ assert.deepEqual(readWindows(), [])
100
+ })
@@ -76,6 +76,15 @@ test('npm test needs no install and no network', async () => {
76
76
  assert.ok(pkg.devDependencies['react-dom'], 'react-dom is a devDependency (public registry)')
77
77
  })
78
78
 
79
+ test('spawned daemons cannot edit the machine git config', async () => {
80
+ // `git config --global` follows HOME/GIT_CONFIG_GLOBAL. A fixture that starts the
81
+ // daemon with a git rule would otherwise rewrite the developer's ~/.gitconfig
82
+ // (this happened once: a real `git.example.com` proxy entry appeared).
83
+ const text = await readFile(join(ROOT, 'test/risd-helpers.mjs'), 'utf8')
84
+ assert.match(text, /GIT_CONFIG_GLOBAL: join\(home, '\.gitconfig'\)/, 'the spawn helper pins GIT_CONFIG_GLOBAL into the temp home')
85
+ assert.match(text, /HOME: home/, 'the spawn helper pins HOME into the temp home')
86
+ })
87
+
79
88
  test('test files import only builtins and relative modules', async () => {
80
89
  const dir = join(ROOT, 'test')
81
90
  const offenders = []
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The two inline "GUI side" routes (`/opens`, `/debugs`) are for the page served on
3
+ * this machine, not for the LAN: like the other host routes they must refuse a
4
+ * request whose Host authority is not loopback, or whose Origin does not match it.
5
+ * A browser on another origin (or a DNS-rebinding attacker) must not be able to
6
+ * read the pending-open stack or the debug-session list.
7
+ */
8
+ import assert from 'node:assert/strict'
9
+ import { createServer, request as httpRequest } from 'node:http'
10
+ import { mkdtempSync } from 'node:fs'
11
+ import { tmpdir } from 'node:os'
12
+ import { join } from 'node:path'
13
+ import { test } from 'node:test'
14
+
15
+ const home = mkdtempSync(join(tmpdir(), 'ris-noloop-'))
16
+ process.env.DSH_RIS_IDE_PROXY_HOME = home
17
+
18
+ const { __test } = await import('../lib/index.js')
19
+ const { handleRequest, OPENS_PATH, DEBUGS_PATH } = __test
20
+
21
+ async function withServer(run) {
22
+ const server = createServer((req, res) => { handleRequest({ sessions: { get: () => undefined } }, req, res, { maxBytes: 1024, restrictToCwd: false }) })
23
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
24
+ const port = server.address().port
25
+ try {
26
+ return await run({ port })
27
+ } finally {
28
+ await new Promise((resolve) => server.close(resolve))
29
+ }
30
+ }
31
+
32
+ /** One GET with arbitrary Host/Origin headers; resolves `{ status, body }`. */
33
+ function get(port, path, headers) {
34
+ return new Promise((resolve, reject) => {
35
+ const call = httpRequest({ host: '127.0.0.1', port, method: 'GET', path, headers }, (response) => {
36
+ let body = ''
37
+ response.setEncoding('utf8')
38
+ response.on('data', (chunk) => { body += chunk })
39
+ response.on('end', () => resolve({ status: response.statusCode, body }))
40
+ })
41
+ call.on('error', reject)
42
+ call.end()
43
+ })
44
+ }
45
+
46
+ test('GUI-side routes refuse a non-loopback Host', async () => {
47
+ await withServer(async ({ port }) => {
48
+ for (const path of [OPENS_PATH, DEBUGS_PATH]) {
49
+ const foreignHost = await get(port, path, { host: 'evil.example' })
50
+ assert.equal(foreignHost.status, 403, `${path} must refuse a foreign Host`)
51
+ assert.equal(JSON.parse(foreignHost.body).code, 'forbidden')
52
+ }
53
+ })
54
+ })
55
+
56
+ test('GUI-side routes refuse a non-loopback Origin even with a loopback Host', async () => {
57
+ await withServer(async ({ port }) => {
58
+ for (const path of [OPENS_PATH, DEBUGS_PATH]) {
59
+ const foreignOrigin = await get(port, path, { host: `127.0.0.1:${port}`, origin: 'http://evil.example' })
60
+ assert.equal(foreignOrigin.status, 403, `${path} must refuse a foreign Origin`)
61
+ }
62
+ })
63
+ })
64
+
65
+ test('GUI-side routes still answer a same-origin loopback request', async () => {
66
+ await withServer(async ({ port }) => {
67
+ const opens = await get(port, OPENS_PATH, { host: `127.0.0.1:${port}` })
68
+ assert.equal(opens.status, 200)
69
+ assert.equal(JSON.parse(opens.body).ok, true)
70
+ const debugs = await get(port, DEBUGS_PATH, { host: `127.0.0.1:${port}`, origin: `http://127.0.0.1:${port}` })
71
+ assert.equal(debugs.status, 200)
72
+ assert.equal(JSON.parse(debugs.body).ok, true)
73
+ })
74
+ })
@@ -381,6 +381,9 @@ test('the stop route answers no-service without a pidfile and refuses a foreign
381
381
  })
382
382
 
383
383
  test('the stop route terminates a real run-with-log.sh service end to end', async () => {
384
+ // Generous TERM→KILL grace: under the full parallel suite the wrapper can take
385
+ // longer than 5 s to trap TERM, reap `sleep` and write its exit banner; a 5 s
386
+ // grace SIGKILLs it first and the banner assertion below then fails.
384
387
  await withServer(async ({ base, cwd }) => {
385
388
  const logDir = join(cwd, 'logs')
386
389
  const log = join(logDir, 'stoptest.log')
@@ -419,7 +422,7 @@ test('the stop route terminates a real run-with-log.sh service end to end', asyn
419
422
  } finally {
420
423
  if (wrapper.exitCode === null && wrapper.signalCode === null) wrapper.kill('SIGKILL')
421
424
  }
422
- })
425
+ }, { maxBytes: HARD_MAX_BYTES, restrictToCwd: false, stopGraceMs: 15000, minFreeMemoryBytes: 1 })
423
426
  })
424
427
 
425
428
  test('listInstances finds a real run-with-log.sh service and reports it verified', async () => {
@@ -542,6 +545,9 @@ test('a frontend row is named after module.xml, not the package.json domainKey',
542
545
  const frontend = programs.filter((p) => p.kind === 'frontend')
543
546
  assert.equal(frontend.length, 1)
544
547
  assert.equal(frontend[0].name, 'c-ass-kk-hans-fe')
548
+ // logName follows the row name: the "<project>-" prefix made this row collide
549
+ // with the backend (launcher) row that owns the same log/pidfile.
550
+ assert.equal(frontend[0].logName, 'c-ass-kk-hans-fe')
545
551
  })
546
552
 
547
553
  test('scanPrograms finds Spring Boot entries and frontend manifests, and skips node_modules', async () => {
@@ -568,6 +574,7 @@ test('scanPrograms finds Spring Boot entries and frontend manifests, and skips n
568
574
  assert.equal(frontend[0].dir, uiDir)
569
575
  // No module.xml: a plain npm project keeps its package.json name.
570
576
  assert.equal(frontend[0].name, 'demo-ui')
577
+ assert.equal(frontend[0].logName, 'demo-ui', 'a frontend log name is its own name, not "<project>-<name>"')
571
578
  assert.equal(frontend[0].script, 'dev')
572
579
  assert.equal(frontend[0].packageManager, 'pnpm', 'inferred from pnpm-lock.yaml')
573
580
  })
@@ -1435,10 +1442,12 @@ test('the Git Bash runtime is detected and can be requested explicitly', async (
1435
1442
  assert.equal(pickGitBash([wslBash, gitBash]), gitBash)
1436
1443
  assert.equal(pickGitBash([join(dir, 'missing', 'bash.exe')]), undefined)
1437
1444
 
1438
- // auto: bash when found, PowerShell when not
1439
- assert.deepEqual(resolveWindowsRuntime('auto', gitBash), { runtime: 'bash', bashPath: gitBash })
1445
+ // auto: native PowerShell even when Git Bash is installed — MSYS rewrites the
1446
+ // Windows paths the bash wrapper passes to `mkdir`/`cd` (2026-11-09 Windows review).
1447
+ assert.deepEqual(resolveWindowsRuntime('auto', gitBash), { runtime: 'powershell' })
1440
1448
  assert.deepEqual(resolveWindowsRuntime('powershell', gitBash), { runtime: 'powershell' })
1441
- // explicit bash must fail loudly when it is not installed
1449
+ // bash stays opt-in, and must fail loudly when it is not installed
1450
+ assert.deepEqual(resolveWindowsRuntime('bash', gitBash), { runtime: 'bash', bashPath: gitBash })
1442
1451
  assert.throws(() => resolveWindowsRuntime('bash', join(dir, 'missing', 'bash.exe')), /Git Bash/)
1443
1452
  })
1444
1453
 
@@ -1446,6 +1455,14 @@ test('the windows-bash command keeps the POSIX wrapper but uses a Windows classp
1446
1455
  const program = { kind: 'spring', dir: 'C:\\ws\\ris\\m1', mainClass: 'a.B', args: ['--x'], logName: 'm1' }
1447
1456
  const spec = buildStartSpec(program, { workspace: 'C:\\ws', logsDir: 'C:\\ws\\logs', variant: 'windows-bash' })
1448
1457
  assert.match(spec.command, /-cp "target\\classes;\$\(cat target\/cp\.txt\)" a\.B --x$/)
1458
+ // Git Bash builtins are POSIX: paths handed to mkdir/cd must be /c/... form,
1459
+ // otherwise MSYS creates a file literally named `C:\ws\...`.
1460
+ // (cspDir is resolved with path.resolve first, so on a Linux runner its prefix is
1461
+ // the test cwd — the tail is what proves the conversion happened.)
1462
+ assert.match(spec.command, /^mkdir -p '[^']*\/csp'/)
1463
+ assert.match(spec.command, /&& cd \/c\/ws\/ris\/m1/)
1464
+ // The JVM is a Windows binary: -D paths stay in Windows spelling.
1465
+ assert.match(spec.command, /-DJM\.LOG\.PATH='C:\\ws\\logs'/)
1449
1466
  assert.match(spec.command, /exec java -DJM\.LOG\.PATH=/)
1450
1467
  // ...while a plain POSIX build keeps ':' and target/classes
1451
1468
  const posix = buildStartSpec(program, { workspace: '/w', logsDir: '/w/logs' })
@@ -61,10 +61,10 @@ test('the standalone window page is a self-contained HTML document', async () =>
61
61
  assert.ok(appAt > vendorAt, 'the browser half loads after React')
62
62
  assert.match(page.body, /__ModuleLoader__/, 'the page shims the module loader')
63
63
  assert.match(page.body, /mountStandalone/, 'and calls the standalone mount entry')
64
- // Script-opened windows may size themselves: the page fills the work area so
65
- // the IDE opens "maximized" even when the opener size is clamped.
66
- assert.match(page.body, /window\.moveTo\(0, 0\)/, 'the page repositions itself to the screen origin')
67
- assert.match(page.body, /window\.resizeTo\(window\.screen\.availWidth, window\.screen\.availHeight\)/, 'and fills the work area')
64
+ // A normal browser window: the page must NOT try to move or resize itself
65
+ // (script resizing is ignored in tabs and was only there for the old popup).
66
+ assert.doesNotMatch(page.body, /window\.moveTo\(/, 'no self-repositioning')
67
+ assert.doesNotMatch(page.body, /window\.resizeTo\(/, 'no self-resizing')
68
68
  } finally {
69
69
  await host.close()
70
70
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import assert from 'node:assert/strict'
7
7
  import { spawn } from 'node:child_process'
8
- import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
8
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
9
9
  import { tmpdir } from 'node:os'
10
10
  import { join } from 'node:path'
11
11
  import { test } from 'node:test'
@@ -22,6 +22,7 @@ const {
22
22
  janitorStatePath,
23
23
  janitorStatus,
24
24
  pendingSideEffects,
25
+ removeOwnJanitorState,
25
26
  } = await import('../lib/janitor.js')
26
27
 
27
28
  /** A process that stays alive until we kill it (stands in for dsh). */
@@ -142,3 +143,30 @@ test('the watcher cleans up and exits once its owner is gone', async () => {
142
143
  assert.match(log, /已退出,开始清理/)
143
144
  assert.match(log, /清理完成/)
144
145
  })
146
+
147
+ test('disarming never signals a stranger that inherited the watcher pid (B-P2-9)', async () => {
148
+ const stranger = fakeOwner()
149
+ try {
150
+ writeFileSync(janitorStatePath(), `${JSON.stringify({ pid: stranger.pid, owner: 12345, log: '' })}\n`, { mode: 0o600 })
151
+ const result = disarmJanitor()
152
+ assert.equal(result.stopped, false, 'a pid that is not a proxy-janitor is left alone')
153
+ await new Promise((resolve) => setTimeout(resolve, 300))
154
+ assert.equal(stranger.exitCode, null, 'the unrelated process is still running')
155
+ assert.equal(existsSync(janitorStatePath()), false, 'the stale state file is still removed')
156
+ } finally {
157
+ stranger.kill('SIGKILL')
158
+ rmSync(janitorStatePath(), { force: true })
159
+ }
160
+ })
161
+
162
+ test('the watcher only removes a state file it wrote itself (B-P2-9)', () => {
163
+ writeFileSync(janitorStatePath(), `${JSON.stringify({ pid: 424242, owner: 1, log: '' })}\n`, { mode: 0o600 })
164
+ try {
165
+ assert.equal(removeOwnJanitorState(999), false)
166
+ assert.equal(existsSync(janitorStatePath()), true, 'a successor watcher file is not deleted')
167
+ assert.equal(removeOwnJanitorState(424242), true)
168
+ assert.equal(existsSync(janitorStatePath()), false)
169
+ } finally {
170
+ rmSync(janitorStatePath(), { force: true })
171
+ }
172
+ })
@@ -10,7 +10,7 @@
10
10
  * neither stacks exit listeners nor leaves the heartbeat dead.
11
11
  */
12
12
  import assert from 'node:assert/strict'
13
- import { existsSync, mkdtempSync, rmSync } from 'node:fs'
13
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
14
14
  import { tmpdir } from 'node:os'
15
15
  import { join } from 'node:path'
16
16
  import { after, test } from 'node:test'
@@ -18,7 +18,7 @@ import { after, test } from 'node:test'
18
18
  const home = mkdtempSync(join(tmpdir(), 'ris-lifecycle-'))
19
19
  process.env.DSH_RIS_IDE_PROXY_HOME = home
20
20
 
21
- const { apply } = await import('../lib/index.js')
21
+ const { apply, __test } = await import('../lib/index.js')
22
22
  const { janitorStatePath, janitorStatus, disarmJanitor } = await import('../lib/janitor.js')
23
23
  const { heartbeatPath } = await import('../lib/redirector.js')
24
24
 
@@ -52,7 +52,7 @@ after(() => {
52
52
  test('a disposed plugin keeps the exit hook and the watcher armed', () => {
53
53
  const before = process.listenerCount('exit')
54
54
  const ctx = fakeCtx()
55
- apply(ctx, {})
55
+ apply(ctx, { daemonMode: 'off' })
56
56
  assert.ok(process.listenerCount('exit') > before, 'apply must install the exit hook')
57
57
  const armed = janitorStatus()
58
58
  assert.equal(armed.running, true, 'apply must arm the janitor')
@@ -69,7 +69,7 @@ test('a disposed plugin keeps the exit hook and the watcher armed', () => {
69
69
  const installed = process.listenerCount('exit')
70
70
  // Re-applying (a profile hot reload runs every effect again) reuses the hook.
71
71
  const reload = fakeCtx()
72
- apply(reload, {})
72
+ apply(reload, { daemonMode: 'off' })
73
73
  assert.equal(process.listenerCount('exit'), installed, 'a hot reload must not stack exit hooks')
74
74
  assert.equal(existsSync(heartbeatPath()), true, 'the heartbeat is rebuilt after the teardown stopped it')
75
75
  reload.dispose()
@@ -81,8 +81,29 @@ test('three apply/dispose cycles add no exit listeners at all', () => {
81
81
  const before = process.listenerCount('exit')
82
82
  for (let index = 0; index < 3; index += 1) {
83
83
  const ctx = fakeCtx()
84
- apply(ctx, {})
84
+ apply(ctx, { daemonMode: 'off' })
85
85
  ctx.dispose()
86
86
  }
87
87
  assert.equal(process.listenerCount('exit'), before)
88
88
  })
89
+
90
+ test('a failed heartbeat write warns once instead of failing silently', () => {
91
+ const warns = []
92
+ const saved = process.env.DSH_RIS_IDE_PROXY_HOME
93
+ // A regular file where a directory is expected makes mkdir() fail fast (ENOTDIR),
94
+ // so writeHeartbeat() reports false — the same code path as a read-only home.
95
+ const blocker = join(home, 'heartbeat-blocker')
96
+ writeFileSync(blocker, 'not a directory\n')
97
+ process.env.DSH_RIS_IDE_PROXY_HOME = join(blocker, 'home')
98
+ let beat = null
99
+ try {
100
+ beat = __test.startHeartbeat({ warn: (message) => warns.push(message) })
101
+ } finally {
102
+ if (saved === undefined) delete process.env.DSH_RIS_IDE_PROXY_HOME
103
+ else process.env.DSH_RIS_IDE_PROXY_HOME = saved
104
+ }
105
+ if (beat !== null) clearInterval(beat)
106
+ assert.equal(warns.length, 1, 'the first failed write warns exactly once')
107
+ assert.match(warns[0], /心跳写入失败/)
108
+ assert.match(warns[0], /20s/)
109
+ })