dsh-ris-ide 1.7.2 → 1.8.0

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 (79) hide show
  1. package/README.md +43 -4
  2. package/bin/check-listing.mjs +247 -0
  3. package/bin/proxy-janitor.mjs +183 -0
  4. package/bin/risd.mjs +287 -0
  5. package/bin/run-with-log.ps1 +43 -5
  6. package/lib/client-codemirror.js +92 -66
  7. package/lib/client.js +774 -89
  8. package/lib/index.js +2256 -21
  9. package/lib/janitor.js +377 -0
  10. package/lib/proxy.js +1577 -0
  11. package/lib/proxybridge-bundle.js +798 -0
  12. package/lib/redirector.js +2558 -0
  13. package/lib/risd/build.js +91 -0
  14. package/lib/risd/debug.js +374 -0
  15. package/lib/risd/git.js +207 -0
  16. package/lib/risd/leases.js +124 -0
  17. package/lib/risd/lifecycle.js +148 -0
  18. package/lib/risd/log.js +59 -0
  19. package/lib/risd/ping.js +94 -0
  20. package/lib/risd/programs.js +348 -0
  21. package/lib/risd/server.js +1478 -0
  22. package/lib/risd/state.js +137 -0
  23. package/lib/risd/ui.js +1705 -0
  24. package/lib/risd/view.js +79 -0
  25. package/lib/risd-client.js +282 -0
  26. package/lib/standalone/window.html +14 -16
  27. package/lib/startup.js +114 -0
  28. package/package.json +7 -2
  29. package/skills/dsh-ris-ide-debug/SKILL.md +37 -2
  30. package/test/client-build.test.mjs +113 -0
  31. package/test/client-viewer.test.mjs +314 -20
  32. package/test/companion.test.mjs +65 -0
  33. package/test/dsh-origin.test.mjs +140 -0
  34. package/test/dsh-window-refresh.test.mjs +100 -0
  35. package/test/harness.test.mjs +9 -0
  36. package/test/host-noloop.test.mjs +74 -0
  37. package/test/host-tail.test.mjs +54 -5
  38. package/test/host-window.test.mjs +4 -4
  39. package/test/inherit-engine.test.mjs +175 -0
  40. package/test/install-phase.test.mjs +36 -0
  41. package/test/janitor.test.mjs +172 -0
  42. package/test/lifecycle.test.mjs +109 -0
  43. package/test/merge-owners.test.mjs +155 -0
  44. package/test/proxy-restart.test.mjs +37 -0
  45. package/test/proxy-route.test.mjs +599 -0
  46. package/test/proxy-window.test.mjs +45 -0
  47. package/test/proxy.test.mjs +914 -0
  48. package/test/proxybridge-bundle.test.mjs +687 -0
  49. package/test/redirector-bundle.test.mjs +391 -0
  50. package/test/redirector.test.mjs +571 -0
  51. package/test/risd-api.test.mjs +470 -0
  52. package/test/risd-bridge-degrade.test.mjs +101 -0
  53. package/test/risd-build.test.mjs +20 -0
  54. package/test/risd-cli-home.test.mjs +50 -0
  55. package/test/risd-client.test.mjs +130 -0
  56. package/test/risd-debug.test.mjs +261 -0
  57. package/test/risd-election.test.mjs +104 -0
  58. package/test/risd-engine.test.mjs +132 -0
  59. package/test/risd-entry.test.mjs +118 -0
  60. package/test/risd-git.test.mjs +109 -0
  61. package/test/risd-handoff.test.mjs +116 -0
  62. package/test/risd-heal.test.mjs +50 -0
  63. package/test/risd-helpers.mjs +108 -0
  64. package/test/risd-host-p2.test.mjs +147 -0
  65. package/test/risd-janitor-guard.test.mjs +46 -0
  66. package/test/risd-lease.test.mjs +83 -0
  67. package/test/risd-lifecycle.test.mjs +210 -0
  68. package/test/risd-log-follow.test.mjs +227 -0
  69. package/test/risd-mode.test.mjs +161 -0
  70. package/test/risd-ping.test.mjs +99 -0
  71. package/test/risd-programs.test.mjs +169 -0
  72. package/test/risd-review-p2.test.mjs +217 -0
  73. package/test/risd-shutdown.test.mjs +97 -0
  74. package/test/risd-teardown.test.mjs +87 -0
  75. package/test/risd-tools.test.mjs +211 -0
  76. package/test/risd-ui.test.mjs +445 -0
  77. package/test/risd-write.test.mjs +170 -0
  78. package/test/startup-reconcile.test.mjs +100 -0
  79. package/test/windows.test.mjs +37 -2
@@ -0,0 +1,97 @@
1
+ // "Stop the daemon" must stop what the daemon supervises.
2
+ //
3
+ // The maintenance page is the only UI when no dsh is open: if stopping the daemon
4
+ // left JVMs (or the proxy engine behind them) running with nothing to stop them,
5
+ // the only remedy would be `kill`. A handoff (upgrade) is different and is covered
6
+ // by risd-handoff.test.mjs — it must keep them alive.
7
+ import assert from 'node:assert/strict'
8
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
9
+ import { request } from 'node:http'
10
+ import { tmpdir } from 'node:os'
11
+ import { join } from 'node:path'
12
+ import { after, before, test } from 'node:test'
13
+ import { sleep, startRisdProcess } from './risd-helpers.mjs'
14
+
15
+ let daemon
16
+ let workspace
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
+ before(async () => {
52
+ workspace = mkdtempSync(join(tmpdir(), 'risd-shutdown-ws-'))
53
+ mkdirSync(join(workspace, '.dsh-ris-ide'), { recursive: true })
54
+ writeFileSync(join(workspace, '.dsh-ris-ide', 'config.json'), `${JSON.stringify({
55
+ version: 1,
56
+ defaults: {},
57
+ programs: [{
58
+ id: 'demo',
59
+ name: 'demo',
60
+ kind: 'custom',
61
+ dir: workspace,
62
+ relDir: '.',
63
+ project: '',
64
+ logName: 'demo',
65
+ startCommand: `${JSON.stringify(process.execPath)} -e "setInterval(() => {}, 60000)"`,
66
+ stopGraceMs: 1500,
67
+ }],
68
+ }, null, 2)}\n`, 'utf8')
69
+ daemon = await startRisdProcess({ port: 0 })
70
+ })
71
+
72
+ after(async () => {
73
+ if (daemon !== undefined) await daemon.stop()
74
+ if (workspace !== undefined) rmSync(workspace, { recursive: true, force: true })
75
+ })
76
+
77
+ test('shutdown stops the programs it supervises before exiting', async () => {
78
+ const started = await api(daemon.state, '/v1/programs', {
79
+ method: 'POST',
80
+ body: { cwd: workspace, action: 'start', id: 'demo' },
81
+ })
82
+ assert.equal(started.status, 200, JSON.stringify(started.body))
83
+ const pid = started.body.pid
84
+ assert.ok(Number.isInteger(pid) && pid > 0, 'the start result carries the wrapper pid')
85
+ assert.equal(alive(pid), true, 'the program is running')
86
+
87
+ const shutdown = await api(daemon.state, '/v1/shutdown', { method: 'POST', body: { reason: 'test' } })
88
+ assert.equal(shutdown.status, 200)
89
+
90
+ // Give the wrapper's TERM grace a moment, then require the process to be gone.
91
+ let gone = false
92
+ for (let attempt = 0; attempt < 60; attempt += 1) {
93
+ if (!alive(pid)) { gone = true; break }
94
+ await sleep(200)
95
+ }
96
+ assert.equal(gone, true, 'stopping the daemon must not leave the program behind')
97
+ })
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Session policy: the daemon owns the engine, so it also decides when the
3
+ * network has no consumer left. Last lease gone ⇒ stop the engine (P2 scope:
4
+ * engine only — git and the bridge move in P5).
5
+ */
6
+ import assert from 'node:assert/strict'
7
+ import test from 'node:test'
8
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
9
+ import { tmpdir } from 'node:os'
10
+ import { join } from 'node:path'
11
+ import { RISD_API_VERSION } from '../lib/risd/state.js'
12
+ import { makeHome, removeHome, sleep, startRisdProcess } from './risd-helpers.mjs'
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
+ }
29
+
30
+ async function startFixture(t) {
31
+ const home = makeHome('risd-teardown-')
32
+ const cwd = mkdtempSync(join(tmpdir(), 'risd-teardown-ws-'))
33
+ const port = 20000 + Math.floor(Math.random() * 20000)
34
+ writeFileSync(join(home, 'proxy.json'), JSON.stringify({
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
+ }))
39
+ const daemon = await startRisdProcess({ home, env: { DSH_RIS_IDE_PROXY_HOME: home } })
40
+ t.after(async () => {
41
+ await daemon.stop()
42
+ removeHome(home)
43
+ rmSync(cwd, { recursive: true, force: true })
44
+ })
45
+ const h = headers(daemon.state)
46
+ const startEngine = async () => {
47
+ const res = await fetch(`${daemon.state.url}/v1/engine`, { method: 'POST', headers: h, body: JSON.stringify({ action: 'start', cwd }) })
48
+ return res.json()
49
+ }
50
+ const lease = async (sessionId) => (await (await fetch(`${daemon.state.url}/v1/leases`, { method: 'POST', headers: h, body: JSON.stringify({ ownerPid: process.pid, sessionId, cwd }) })).json()).lease
51
+ const release = async (id) => (await (await fetch(`${daemon.state.url}/v1/leases/${encodeURIComponent(id)}`, { method: 'DELETE', headers: h })).json()).released
52
+ const engine = async () => (await (await fetch(`${daemon.state.url}/v1/engine?cwd=${encodeURIComponent(cwd)}`, { headers: h })).json()).engine
53
+ return { daemon, home, cwd, startEngine, lease, release, engine }
54
+ }
55
+
56
+ test('the last release stops the engine, the first one does not', async (t) => {
57
+ const fx = await startFixture(t)
58
+ const started = await fx.startEngine()
59
+ assert.equal(started.result.ok, true, JSON.stringify(started.result))
60
+ const pid = started.result.pid
61
+
62
+ const a = await fx.lease('A')
63
+ const b = await fx.lease('B')
64
+ assert.equal(await fx.release(a.id), true)
65
+ await sleep(600)
66
+ assert.equal((await fx.engine()).running, true, 'one lease left: the engine must stay up')
67
+
68
+ assert.equal(await fx.release(b.id), true)
69
+ assert.equal(await waitFor(async () => (await fx.engine()).running === false), true, 'last lease gone: the engine stops')
70
+ assert.equal(await waitFor(() => !existsSync(join(fx.home, 'proxy.pid'))), true)
71
+ assert.equal((await fx.engine()).pid, null)
72
+ assert.equal(pid > 0, true)
73
+ })
74
+
75
+ test('a dead owner is swept and then the engine is torn down', async (t) => {
76
+ const fx = await startFixture(t)
77
+ const started = await fx.startEngine()
78
+ assert.equal(started.result.ok, true)
79
+
80
+ const orphan = (await import('node:child_process')).spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore' })
81
+ t.after(() => orphan.kill('SIGKILL'))
82
+ const h = headers(fx.daemon.state)
83
+ await fetch(`${fx.daemon.state.url}/v1/leases`, { method: 'POST', headers: h, body: JSON.stringify({ ownerPid: orphan.pid, sessionId: 'gone', cwd: fx.cwd }) })
84
+ orphan.kill('SIGKILL')
85
+
86
+ assert.equal(await waitFor(async () => (await fx.engine()).running === false, 15000), true, 'swept lease must trigger teardown')
87
+ })
@@ -0,0 +1,211 @@
1
+ // P4: the agent tools ask risd first when the plugin runs in daemonMode=auto.
2
+ //
3
+ // These tests never boot a real daemon: a tiny HTTP server records what the
4
+ // tools ask for, __test.setRisdBridge() points the plugin at it, and the local
5
+ // branch stays available as the fallback (checked by closing the server).
6
+ import test from 'node:test'
7
+ import assert from 'node:assert/strict'
8
+ import { createServer } from 'node:http'
9
+ import { mkdtempSync, rmSync } from 'node:fs'
10
+ import { tmpdir } from 'node:os'
11
+ import { join } from 'node:path'
12
+
13
+ import { registerAgentTools, __test } from '../lib/index.js'
14
+
15
+ const ROW = {
16
+ id: 'demo',
17
+ name: 'demo',
18
+ kind: 'spring',
19
+ logName: 'demo',
20
+ dir: '.',
21
+ relDir: '.',
22
+ logPath: '/tmp/risd-tools.test/demo.log',
23
+ running: { pid: 11, alive: true, uptimeMs: 1000 },
24
+ }
25
+
26
+ function fakeDaemon() {
27
+ const requests = []
28
+ const server = createServer((req, res) => {
29
+ const chunks = []
30
+ req.on('data', (chunk) => chunks.push(chunk))
31
+ req.on('end', () => {
32
+ const raw = Buffer.concat(chunks).toString('utf8')
33
+ const body = raw === '' ? undefined : JSON.parse(raw)
34
+ requests.push({ method: req.method, url: req.url, body })
35
+ const json = (value) => {
36
+ res.writeHead(200, { 'content-type': 'application/json' })
37
+ res.end(JSON.stringify(value))
38
+ }
39
+ const url = String(req.url ?? '')
40
+ // C-P2-2: the tools probe /v1/health once per window before trusting the
41
+ // bridge's daemon pointer, so the fake daemon has to answer it like the real one.
42
+ if (req.method === 'GET' && url === '/v1/health') {
43
+ return json({ ok: true, apiVersion: 1, version: '1.8.0', pid: 4242, port: server.address().port, state: 'ready' })
44
+ }
45
+ if (req.method === 'GET' && url.startsWith('/v1/programs/log')) {
46
+ return json({ ok: true, path: ROW.logPath, exists: true, running: true, pid: 11, text: 'line1\nline2\n' })
47
+ }
48
+ if (req.method === 'GET' && url.startsWith('/v1/programs')) {
49
+ return json({ ok: true, cwd: '/tmp/ws', dir: 'logs', programs: [ROW] })
50
+ }
51
+ if (req.method === 'POST' && url === '/v1/programs') {
52
+ return json({ ok: true, cwd: '/tmp/ws', action: body?.action, alreadyRunning: false, program: ROW })
53
+ }
54
+ if (req.method === 'POST' && url === '/v1/debug') {
55
+ if (body?.action === 'status') return json({ ok: true, action: 'status', attached: false, port: 0 })
56
+ if (body?.action === 'breakpoints') return json({ ok: true, breakpoints: [{ id: 1, className: 'A', line: 12 }] })
57
+ if (body?.action === 'threads') return json({ ok: true, threads: [{ id: 't1', name: 'main' }] })
58
+ return json({ ok: true, action: body?.action })
59
+ }
60
+ res.writeHead(404, { 'content-type': 'application/json' })
61
+ res.end(JSON.stringify({ ok: false, code: 'not-found' }))
62
+ })
63
+ })
64
+ return new Promise((resolve) => {
65
+ server.listen(0, '127.0.0.1', () => {
66
+ resolve({
67
+ port: server.address().port,
68
+ requests,
69
+ close: () => new Promise((done) => { server.closeAllConnections?.(); server.close(() => done()) }),
70
+ })
71
+ })
72
+ })
73
+ }
74
+
75
+ function toolContext(cwd, warnings = []) {
76
+ const definitions = new Map()
77
+ const ctx = {
78
+ sessions: { get: () => ({ header: { cwd } }) },
79
+ tools: { register: (definition) => { definitions.set(definition.name, definition); return () => {} } },
80
+ logger: { warn(message) { warnings.push(String(message)) } },
81
+ }
82
+ return { ctx, definitions }
83
+ }
84
+
85
+ const exec = { agent: { session: { id: 'session-1' } } }
86
+
87
+ test('ris_dev_programs reads the daemon rows in auto mode', async () => {
88
+ const cwd = mkdtempSync(join(tmpdir(), 'risd-tools-'))
89
+ const daemon = await fakeDaemon()
90
+ try {
91
+ __test.setRisdBridge({ mode: 'auto', state: { url: `http://127.0.0.1:${daemon.port}`, port: daemon.port, token: 't', apiVersion: 1, pid: 4242, home: cwd }, leaseId: null, pending: null })
92
+ const { ctx, definitions } = toolContext(cwd)
93
+ registerAgentTools(ctx, { daemonMode: 'auto' })
94
+ const value = await definitions.get('ris_dev_programs').execute({}, exec)
95
+ assert.equal(value.ok, true)
96
+ assert.equal(value.programs[0].id, 'demo')
97
+ assert.ok(daemon.requests.some((request) => request.method === 'GET' && request.url.startsWith('/v1/programs?cwd=')))
98
+ } finally {
99
+ __test.setRisdBridge(null)
100
+ await daemon.close()
101
+ rmSync(cwd, { recursive: true, force: true })
102
+ }
103
+ })
104
+
105
+ test('ris_dev_start / ris_dev_logs go through the daemon', async () => {
106
+ const cwd = mkdtempSync(join(tmpdir(), 'risd-tools-'))
107
+ const daemon = await fakeDaemon()
108
+ try {
109
+ __test.setRisdBridge({ mode: 'auto', state: { url: `http://127.0.0.1:${daemon.port}`, port: daemon.port, token: 't', apiVersion: 1, pid: 4242, home: cwd }, leaseId: null, pending: null })
110
+ const { ctx, definitions } = toolContext(cwd)
111
+ registerAgentTools(ctx, { daemonMode: 'auto' })
112
+
113
+ const started = await definitions.get('ris_dev_start').execute({ id: 'demo' }, exec)
114
+ assert.equal(started.ok, true)
115
+ assert.equal(started.alreadyRunning, false)
116
+ assert.equal(started.program.id, 'demo')
117
+ assert.ok(daemon.requests.some((request) => request.method === 'POST' && request.body?.action === 'start'))
118
+
119
+ const logs = await definitions.get('ris_dev_logs').execute({ id: 'demo', lines: 10 }, exec)
120
+ assert.equal(logs.ok, true)
121
+ assert.equal(logs.running, true)
122
+ assert.match(logs.content, /line2/)
123
+ } finally {
124
+ __test.setRisdBridge(null)
125
+ await daemon.close()
126
+ rmSync(cwd, { recursive: true, force: true })
127
+ }
128
+ })
129
+
130
+ test('ris_dev_debug state and threads are answered by the daemon', async () => {
131
+ const cwd = mkdtempSync(join(tmpdir(), 'risd-tools-'))
132
+ const daemon = await fakeDaemon()
133
+ try {
134
+ __test.setRisdBridge({ mode: 'auto', state: { url: `http://127.0.0.1:${daemon.port}`, port: daemon.port, token: 't', apiVersion: 1, pid: 4242, home: cwd }, leaseId: null, pending: null })
135
+ const { ctx, definitions } = toolContext(cwd)
136
+ registerAgentTools(ctx, { daemonMode: 'auto' })
137
+ const debug = definitions.get('ris_dev_debug')
138
+
139
+ const state = await debug.execute({ action: 'state', id: 'demo' }, exec)
140
+ assert.equal(state.ok, true)
141
+ assert.equal(state.debug.attached, false)
142
+ assert.equal(state.breakpoints.length, 1)
143
+ const debugCalls = () => daemon.requests
144
+ .filter((request) => request.url === '/v1/debug')
145
+ .map((request) => request.body.action)
146
+ assert.deepEqual(debugCalls().slice(0, 2), ['status', 'breakpoints'])
147
+
148
+ const threads = await debug.execute({ action: 'threads', id: 'demo' }, exec)
149
+ assert.equal(threads.ok, true)
150
+ assert.equal(threads.threads[0].id, 't1')
151
+ assert.ok(debugCalls().includes('threads'))
152
+ } finally {
153
+ __test.setRisdBridge(null)
154
+ await daemon.close()
155
+ rmSync(cwd, { recursive: true, force: true })
156
+ }
157
+ })
158
+
159
+ test('a stopped daemon falls back to the local implementation', async () => {
160
+ const cwd = mkdtempSync(join(tmpdir(), 'risd-tools-'))
161
+ const daemon = await fakeDaemon()
162
+ __test.setRisdBridge({ mode: 'auto', state: { url: `http://127.0.0.1:${daemon.port}`, port: daemon.port, token: 't', apiVersion: 1, pid: 4242, home: cwd }, leaseId: null, pending: null })
163
+ const { ctx, definitions } = toolContext(cwd)
164
+ registerAgentTools(ctx, { daemonMode: 'auto' })
165
+ // Trip the heal breaker: without a daemon this call must fall back locally, not
166
+ // spawn a real one (which would also make the assertion meaningless).
167
+ for (let attempt = 0; attempt < 3; attempt += 1) __test.noteRisdHealFailure('probe failed', Date.now())
168
+ await daemon.close()
169
+ try {
170
+ const value = await definitions.get('ris_dev_programs').execute({}, exec)
171
+ assert.equal(value.ok, true)
172
+ // The local branch scans the (empty) workspace itself: same contract, no daemon.
173
+ assert.deepEqual(value.programs, [])
174
+ } finally {
175
+ __test.setRisdBridge(null)
176
+ rmSync(cwd, { recursive: true, force: true })
177
+ }
178
+ })
179
+
180
+ test('a half-dead daemon is demoted and the fallback is said out loud (C-P2-2)', async () => {
181
+ // Before: a non-null pointer was trusted forever, so each tool call paid a 2 s
182
+ // timeout and quietly ran locally — the programs it started were then invisible to
183
+ // the daemon (stopping the daemon would not stop them).
184
+ const cwd = mkdtempSync(join(tmpdir(), 'risd-tools-'))
185
+ const home = mkdtempSync(join(tmpdir(), 'risd-tools-home-'))
186
+ const previousHome = process.env.DSH_RIS_IDE_PROXY_HOME
187
+ process.env.DSH_RIS_IDE_PROXY_HOME = home
188
+ const bridge = { mode: 'auto', state: { url: 'http://127.0.0.1:9', port: 9, token: 't', apiVersion: 1 }, leaseId: null, pending: null, degraded: false, lastProbeAt: 0 }
189
+ try {
190
+ // Trip the heal breaker so the call cannot spawn a real daemon: this test is about
191
+ // the probe + warning, not about the spawn path.
192
+ const now = Date.now()
193
+ __test.setRisdBridge(bridge)
194
+ for (let attempt = 0; attempt < 3; attempt += 1) __test.noteRisdHealFailure('probe failed', now)
195
+ const warnings = []
196
+ const { ctx, definitions } = toolContext(cwd, warnings)
197
+ registerAgentTools(ctx, { daemonMode: 'auto' })
198
+ const value = await definitions.get('ris_dev_programs').execute({}, exec)
199
+ assert.equal(value.ok, true, 'the local implementation still answers')
200
+ assert.equal(bridge.state, null, 'the dead pointer is dropped')
201
+ assert.equal(bridge.degraded, true)
202
+ assert.ok(warnings.some((message) => /不在 daemon 的托管范围内(停 daemon 不会停它)/.test(message)),
203
+ `expected a local-fallback warning, got ${JSON.stringify(warnings)}`)
204
+ } finally {
205
+ __test.setRisdBridge(null)
206
+ if (previousHome === undefined) delete process.env.DSH_RIS_IDE_PROXY_HOME
207
+ else process.env.DSH_RIS_IDE_PROXY_HOME = previousHome
208
+ rmSync(cwd, { recursive: true, force: true })
209
+ rmSync(home, { recursive: true, force: true })
210
+ }
211
+ })