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.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/lib/client.js +569 -98
  3. package/lib/debug/vendor/README.md +14 -0
  4. package/lib/debug/vendor/jdwp/client.js +9 -4
  5. package/lib/debug/vendor/src/jdwp/client.ts +12 -5
  6. package/lib/index.js +963 -64
  7. package/lib/redirector.js +76 -4
  8. package/lib/risd/lifecycle.js +54 -10
  9. package/lib/risd/ping.js +136 -17
  10. package/lib/risd/server.js +424 -22
  11. package/lib/risd/ui.js +218 -129
  12. package/lib/risd-client.js +4 -1
  13. package/lib/startup.js +27 -7
  14. package/package.json +2 -2
  15. package/test/client-viewer.test.mjs +268 -93
  16. package/test/clipboard.test.mjs +259 -0
  17. package/test/debug-engine.test.mjs +3 -1
  18. package/test/dsh-origin.test.mjs +4 -11
  19. package/test/dsh-window-refresh.test.mjs +166 -1
  20. package/test/harness.test.mjs +1 -1
  21. package/test/helpers/cmd.mjs +29 -0
  22. package/test/helpers/tgz.mjs +71 -0
  23. package/test/host-search.test.mjs +18 -11
  24. package/test/host-tail.test.mjs +190 -25
  25. package/test/proxy-route.test.mjs +61 -0
  26. package/test/proxy-window.test.mjs +5 -0
  27. package/test/proxy.test.mjs +40 -11
  28. package/test/proxybridge-bundle.test.mjs +1 -59
  29. package/test/redirector-bundle.test.mjs +21 -67
  30. package/test/redirector.test.mjs +71 -4
  31. package/test/risd-api.test.mjs +83 -29
  32. package/test/risd-bridge-degrade.test.mjs +3 -29
  33. package/test/risd-cli-home.test.mjs +41 -4
  34. package/test/risd-engine.test.mjs +13 -50
  35. package/test/risd-entry.test.mjs +0 -37
  36. package/test/risd-follow-start.test.mjs +102 -0
  37. package/test/risd-git.test.mjs +7 -5
  38. package/test/risd-handoff.test.mjs +6 -50
  39. package/test/risd-helpers.mjs +150 -3
  40. package/test/risd-host-p2.test.mjs +2 -30
  41. package/test/risd-lifecycle.test.mjs +203 -33
  42. package/test/risd-ping.test.mjs +77 -1
  43. package/test/risd-programs.test.mjs +4 -34
  44. package/test/risd-review-p2.test.mjs +0 -13
  45. package/test/risd-shutdown.test.mjs +5 -38
  46. package/test/risd-teardown.test.mjs +8 -27
  47. package/test/risd-ui.test.mjs +205 -14
  48. package/test/risd-write.test.mjs +2 -1
  49. package/test/startup-reconcile.test.mjs +44 -8
  50. package/test/proxy-restart.test.mjs +0 -39
@@ -19,6 +19,7 @@ import { tmpdir } from 'node:os'
19
19
  import { join } from 'node:path'
20
20
 
21
21
  import { __test } from '../lib/index.js'
22
+ import { HAS_BASH, HAS_GIT, skipWithout } from './helpers/cmd.mjs'
22
23
 
23
24
  const {
24
25
  handleRequest, searchWorkspaceContent,
@@ -80,14 +81,18 @@ async function makeRepoFixture(label) {
80
81
  await writeFile(join(root, 'a.txt'), 'alpha\nbeta\nneedle one\nneedle two\nneedle three\n')
81
82
  await mkdir(join(root, 'sub'), { recursive: true })
82
83
  await writeFile(join(root, 'sub', 'b.txt'), 'x needle deep\n')
83
- execFileSync('git', ['init', '-q'], { cwd: root })
84
- execFileSync('git', ['add', '-A'], { cwd: root })
84
+ // 没有 git 的机器(Jenkins 裸镜像)里这些 fixture 测试整体跳过;这里仍然守住,
85
+ // 免得某个没加 skip 的调用方直接抛 ENOENT。
86
+ if (HAS_GIT) {
87
+ execFileSync('git', ['init', '-q'], { cwd: root })
88
+ execFileSync('git', ['add', '-A'], { cwd: root })
89
+ }
85
90
  return root
86
91
  }
87
92
 
88
93
  // ── Content search helper ───────────────────────────────────────────────────
89
94
 
90
- test('searchWorkspaceContent returns literal git-grep hits with absolute path, line and text', async () => {
95
+ test('searchWorkspaceContent returns literal git-grep hits with absolute path, line and text', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
91
96
  const root = await makeRepoFixture('content')
92
97
  const { hits, truncated, roots, files } = await searchWorkspaceContent(root, 'needle', 300, 8)
93
98
  assert.deepEqual(roots, [root])
@@ -104,7 +109,7 @@ test('searchWorkspaceContent returns literal git-grep hits with absolute path, l
104
109
  assert.deepEqual(regexHit.hits, [])
105
110
  })
106
111
 
107
- test('searchWorkspaceContent honours perFile and answers an empty hit list for no match', async () => {
112
+ test('searchWorkspaceContent honours perFile and answers an empty hit list for no match', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
108
113
  const root = await makeRepoFixture('cap')
109
114
  const capped = await searchWorkspaceContent(root, 'needle', 300, 2)
110
115
  const fromA = capped.hits.filter((hit) => hit.path === join(root, 'a.txt'))
@@ -132,7 +137,7 @@ test('searchWorkspaceContent falls back to a case-insensitive walk without a git
132
137
 
133
138
  // ── Content search route ────────────────────────────────────────────────────
134
139
 
135
- test('GET /search-content serves hits and rejects a missing q or the wrong method', async () => {
140
+ test('GET /search-content serves hits and rejects a missing q or the wrong method', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
136
141
  const root = await makeRepoFixture('content-route')
137
142
  await withServer(async ({ base }) => {
138
143
  const response = await fetch(`${base}${CONTENT_SEARCH_PATH}?sessionId=s1&q=needle&perFile=2&limit=50`)
@@ -189,8 +194,10 @@ async function makeTwoRootFixture(label) {
189
194
  await mkdir(dir, { recursive: true })
190
195
  await writeFile(join(dir, 'agent-one.txt'), 'needle one\nsecond needle\n')
191
196
  await writeFile(join(dir, 'other.txt'), 'nothing here\n')
192
- execFileSync('git', ['init', '-q'], { cwd: dir })
193
- execFileSync('git', ['add', '-A'], { cwd: dir })
197
+ if (HAS_GIT) {
198
+ execFileSync('git', ['init', '-q'], { cwd: dir })
199
+ execFileSync('git', ['add', '-A'], { cwd: dir })
200
+ }
194
201
  }
195
202
  return root
196
203
  }
@@ -219,7 +226,7 @@ test('createOrderedPages spends the row budget in root order, not arrival order'
219
226
  assert.deepEqual(pages, [['a1', 'a2'], ['a3']])
220
227
  })
221
228
 
222
- test('GET /search/stream pages the filename matches in tree order and ends with done', async () => {
229
+ test('GET /search/stream pages the filename matches in tree order and ends with done', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
223
230
  const root = await makeTwoRootFixture('stream-name')
224
231
  await withServer(async ({ base }) => {
225
232
  const response = await fetch(`${base}${SEARCH_STREAM_PATH}?sessionId=s1&q=agent&pageSize=1&limit=10`)
@@ -243,7 +250,7 @@ test('GET /search/stream pages the filename matches in tree order and ends with
243
250
  }, root)
244
251
  })
245
252
 
246
- test('GET /search-content/stream pages grep hits and keeps the batch validation', async () => {
253
+ test('GET /search-content/stream pages grep hits and keeps the batch validation', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
247
254
  const root = await makeTwoRootFixture('stream-content')
248
255
  await withServer(async ({ base }) => {
249
256
  const response = await fetch(`${base}${CONTENT_SEARCH_STREAM_PATH}?sessionId=s1&q=needle&pageSize=1&limit=10`)
@@ -269,7 +276,7 @@ test('GET /search-content/stream pages grep hits and keeps the batch validation'
269
276
  }, root)
270
277
  })
271
278
 
272
- test('GET /search/stream stops early at limit and reports truncated', async () => {
279
+ test('GET /search/stream stops early at limit and reports truncated', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
273
280
  const root = await makeTwoRootFixture('stream-limit')
274
281
  await withServer(async ({ base }) => {
275
282
  const response = await fetch(`${base}${SEARCH_STREAM_PATH}?sessionId=s1&q=agent&pageSize=2&limit=1`)
@@ -476,7 +483,7 @@ async function makeStartableFixture() {
476
483
  return root
477
484
  }
478
485
 
479
- test('POST /start with restart:true stops the running instance before starting a fresh one', async () => {
486
+ test('POST /start with restart:true stops the running instance before starting a fresh one', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
480
487
  const root = await makeStartableFixture()
481
488
  await withServer(async ({ base }) => {
482
489
  const programs = (await (await fetch(`${base}${PROGRAMS_PATH}?sessionId=s1&refresh=1`)).json()).programs
@@ -17,6 +17,7 @@ import { dirname, join, resolve } from 'node:path'
17
17
  import { fileURLToPath } from 'node:url'
18
18
 
19
19
  import { __test } from '../lib/index.js'
20
+ import { HAS_BASH, HAS_GIT, skipWithout } from './helpers/cmd.mjs'
20
21
 
21
22
  const {
22
23
  resolvePath, isLoopbackRequest, readTail, clampBytes, serveTail, serveStop, handleRequest,
@@ -32,7 +33,7 @@ const {
32
33
  startProgram, stopLogPath, processGroupLeader, groupMembers, jsonSafe,
33
34
  SKILL_NAME, PKG_VERSION, bundledSkillPath, findProjectRoot, skillRootFor, skillFileState, installSkill,
34
35
  skillRootsFor, syncInstalledSkills,
35
- TAIL_PATH, STOP_PATH, INSTANCES_PATH, PROGRAMS_PATH, START_PATH, CONFIG_PATH, OPENS_PATH, DEBUG_PATH,
36
+ TAIL_PATH, STOP_PATH, INSTANCES_PATH, PROGRAMS_PATH, OPEN_TARGET_PATH, START_PATH, CONFIG_PATH, OPENS_PATH, DEBUG_PATH,
36
37
  DEFAULT_BYTES, HARD_MAX_BYTES, MIN_BYTES, PID_SUFFIX,
37
38
  } = __test
38
39
  const WRAPPER = fileURLToPath(new URL('../bin/run-with-log.sh', import.meta.url))
@@ -315,7 +316,8 @@ test('readService reads the pidfile and reports liveness', async () => {
315
316
  await writeFile(log, 'x\n')
316
317
  assert.equal(await readService(log), undefined, 'no pidfile means no service')
317
318
 
318
- const child = spawn('sleep', ['30'], { stdio: 'ignore' })
319
+ // 一个“活着的无关进程”用 node 自己起,不依赖 sleep 这类外部程序(CI 裸镜像里没有)。
320
+ const child = spawn(process.execPath, ['-e', 'setTimeout(() => {}, 30000)'], { stdio: 'ignore' })
319
321
  try {
320
322
  await writeFile(`${log}${PID_SUFFIX}`, `${child.pid} ${process.pid} 1700000000000\n`)
321
323
  const service = await readService(log)
@@ -339,7 +341,7 @@ test('the stop route refuses a PID that is not the wrapper script', async () =>
339
341
  await withServer(async ({ base, cwd }) => {
340
342
  const log = join(cwd, 'fake.log')
341
343
  await writeFile(log, 'x\n')
342
- const child = spawn('sleep', ['30'], { stdio: 'ignore' })
344
+ const child = spawn(process.execPath, ['-e', 'setTimeout(() => {}, 30000)'], { stdio: 'ignore' })
343
345
  try {
344
346
  await writeFile(`${log}${PID_SUFFIX}`, `${child.pid} ${child.pid} 1\n`)
345
347
  const response = await post(base, { sessionId: 's1', path: log })
@@ -380,7 +382,7 @@ test('the stop route answers no-service without a pidfile and refuses a foreign
380
382
  })
381
383
  })
382
384
 
383
- test('the stop route terminates a real run-with-log.sh service end to end', async () => {
385
+ test('the stop route terminates a real run-with-log.sh service end to end', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
384
386
  // Generous TERM→KILL grace: under the full parallel suite the wrapper can take
385
387
  // longer than 5 s to trap TERM, reap `sleep` and write its exit banner; a 5 s
386
388
  // grace SIGKILLs it first and the banner assertion below then fails.
@@ -425,7 +427,7 @@ test('the stop route terminates a real run-with-log.sh service end to end', asyn
425
427
  }, { maxBytes: HARD_MAX_BYTES, restrictToCwd: false, stopGraceMs: 15000, minFreeMemoryBytes: 1 })
426
428
  })
427
429
 
428
- test('listInstances finds a real run-with-log.sh service and reports it verified', async () => {
430
+ test('listInstances finds a real run-with-log.sh service and reports it verified', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
429
431
  const logDir = join(scratch, 'instances-live')
430
432
  const log = join(logDir, 'instlive.log')
431
433
  const wrapper = spawn(WRAPPER, ['instlive', 'sleep', '60'], {
@@ -457,7 +459,7 @@ test('listInstances ignores junk pidfiles and orders live instances first', asyn
457
459
  assert.deepEqual(await listInstances(logDir), [], 'junk and pidfile-less logs are not instances')
458
460
  })
459
461
 
460
- test('the instances route lists services and refuses a directory outside the session cwd', async () => {
462
+ test('the instances route lists services and refuses a directory outside the session cwd', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
461
463
  await withServer(async ({ base, cwd }) => {
462
464
  const logDir = join(cwd, 'logs')
463
465
  const log = join(logDir, 'routetest.log')
@@ -667,7 +669,48 @@ test('the programs route scans over HTTP and the start route refuses bad input',
667
669
  }, undefined, root)
668
670
  })
669
671
 
670
- test('the start route launches a program through run-with-log.sh and stop terminates it', async () => {
672
+ test('the open-target route resolves a program by id and never invents a URL (m03945)', async () => {
673
+ const { root } = await makeProgramFixture()
674
+ await withServer(async ({ base }) => {
675
+ const listing = await (await fetch(`${base}${PROGRAMS_PATH}?sessionId=s1&refresh=1`)).json()
676
+ const program = listing.programs.find((entry) => entry.kind === 'frontend')
677
+ assert.ok(program !== undefined, 'the fixture frontend program is discovered')
678
+
679
+ // A program that never printed a dev-server line has no address: say so instead
680
+ // of opening about:blank (the panel turns `message` into its note bar).
681
+ const noUrl = await (await fetch(`${base}${OPEN_TARGET_PATH}?sessionId=s1&id=${encodeURIComponent(program.id)}`)).json()
682
+ assert.equal(noUrl.ok, false)
683
+ assert.equal(noUrl.code, 'no-url')
684
+ assert.match(noUrl.message, /Local: http:\/\/localhost/)
685
+
686
+ const unknown = await fetch(`${base}${OPEN_TARGET_PATH}?sessionId=s1&id=${encodeURIComponent('frontend:missing#dev')}`)
687
+ assert.equal(unknown.status, 404)
688
+ assert.equal((await unknown.json()).ok, false)
689
+ assert.equal((await fetch(`${base}${OPEN_TARGET_PATH}`)).status, 400, 'sessionId is required')
690
+ assert.equal((await fetch(`${base}${OPEN_TARGET_PATH}?sessionId=s1`, { method: 'POST' })).status, 405)
691
+ }, undefined, root)
692
+ })
693
+
694
+ test('a dev-server URL is read from local hosts, placeholders and ANSI logs (m03945)', async () => {
695
+ // What scaffolds actually print: webpack/vite use localhost, MDF prints
696
+ // `Node服务地址:http://<HOST地址>:3003`, and colour codes wrap both the label
697
+ // and the URL. A gateway URL on the next line must never win.
698
+ const cases = [
699
+ ['Local: http://localhost:5173/\n', 'http://localhost:5173/'],
700
+ ['Node服务地址:http://<HOST地址>:3003 当前环境:daily\n', 'http://127.0.0.1:3003'],
701
+ ['\u001b[32m - Local: \u001b[36mhttp://0.0.0.0:8080/\u001b[39m\n', 'http://127.0.0.1:8080/'],
702
+ ['http://[::]:9000/\n', 'http://127.0.0.1:9000/'],
703
+ ['Java服务地址:https://srmdev.hanslaser.com/c-ass-kk-hans\n', undefined],
704
+ ]
705
+ const dir = await mkdtemp(join(tmpdir(), 'ris-logurl-'))
706
+ const logPath = join(dir, 'prog.log')
707
+ for (const [line, want] of cases) {
708
+ await writeFile(logPath, line, 'utf8')
709
+ assert.equal(await __test.logUrl(logPath), want, `log line: ${JSON.stringify(line)}`)
710
+ }
711
+ })
712
+
713
+ test('the start route launches a program through run-with-log.sh and stop terminates it', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
671
714
  const { root } = await makeStartableFixture()
672
715
  await withServer(async ({ base }) => {
673
716
  const listing = await fetch(`${base}${PROGRAMS_PATH}?sessionId=s1&refresh=1`)
@@ -916,7 +959,7 @@ test('the config route generates, refuses to clobber and updates in place', asyn
916
959
  }, undefined, root)
917
960
  })
918
961
 
919
- test('the programs route reports config drift, and start honors startCommand/logName/grace', async () => {
962
+ test('the programs route reports config drift, and start honors startCommand/logName/grace', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
920
963
  const { root } = await makeStartableFixture()
921
964
  await ensureStateDir(root)
922
965
  await writeFile(configPathOf(root), JSON.stringify({
@@ -1011,7 +1054,7 @@ test('resolveProgramRef matches by id, exact name and a unique fragment', () =>
1011
1054
  assert.throws(() => resolveProgramRef(programs, { name: '-biz' }), /matches/)
1012
1055
  })
1013
1056
 
1014
- test('the tools list, start, read and stop a program through the shared core', async () => {
1057
+ test('the tools list, start, read and stop a program through the shared core', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
1015
1058
  const { root } = await makeStartableFixture()
1016
1059
  const { ctx, tools } = toolCtx(root)
1017
1060
  const dispose = registerAgentTools(ctx, {})
@@ -1076,7 +1119,7 @@ test('the opens route drains the queue exactly once', async () => {
1076
1119
 
1077
1120
  // ── Regressions: stop must free the port; tool output must be lossless JSON ─
1078
1121
 
1079
- test('stopping a wrapped command kills its whole process group (pnpm-style grandchildren)', async () => {
1122
+ test('stopping a wrapped command kills its whole process group (pnpm-style grandchildren)', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
1080
1123
  // The reported bug: `pnpm run dev` does not forward SIGTERM, so stopping only
1081
1124
  // the runner left vite holding its port. The wrapper is spawned detached
1082
1125
  // (own group) exactly like the host does it.
@@ -1106,7 +1149,7 @@ test('stopping a wrapped command kills its whole process group (pnpm-style grand
1106
1149
  }
1107
1150
  })
1108
1151
 
1109
- test('a start whose command dies immediately fails loudly, with the log tail', async () => {
1152
+ test('a start whose command dies immediately fails loudly, with the log tail', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
1110
1153
  const { root } = await makeStartableFixture()
1111
1154
  await ensureStateDir(root)
1112
1155
  await writeFile(configPathOf(root), JSON.stringify({
@@ -1134,7 +1177,7 @@ test('a start whose command dies immediately fails loudly, with the log tail', a
1134
1177
  )
1135
1178
  })
1136
1179
 
1137
- test('every ris_dev_* result is lossless JSON (no undefined values)', async () => {
1180
+ test('every ris_dev_* result is lossless JSON (no undefined values)', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
1138
1181
  const assertJsonSafe = (value, path = '$') => {
1139
1182
  if (value === undefined) assert.fail(`undefined at ${path}`)
1140
1183
  if (Array.isArray(value)) value.forEach((item, index) => assertJsonSafe(item, `${path}[${index}]`))
@@ -1166,7 +1209,7 @@ test('every ris_dev_* result is lossless JSON (no undefined values)', async () =
1166
1209
  })
1167
1210
 
1168
1211
 
1169
- test('ris_dev_status answers "is it up?" and ris_dev_restart restarts in place', async () => {
1212
+ test('ris_dev_status answers "is it up?" and ris_dev_restart restarts in place', { skip: skipWithout(HAS_BASH, 'bash') }, async () => {
1170
1213
  const { root } = await makeStartableFixture()
1171
1214
  const { ctx, tools } = toolCtx(root)
1172
1215
  const dispose = registerAgentTools(ctx, {})
@@ -1776,7 +1819,7 @@ test('PKG_VERSION tracks package.json', async () => {
1776
1819
 
1777
1820
 
1778
1821
  // ── gitignore-aware, compact-folding IDE tree ───────────────────────────────
1779
- test('listIdeTree hides ignored files and folds package chains only under java', async () => {
1822
+ test('listIdeTree hides ignored files and folds package chains only under java', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
1780
1823
  const { mkdtemp, mkdir, writeFile, rm } = await import('node:fs/promises')
1781
1824
  const { execFile } = await import('node:child_process')
1782
1825
  const { promisify } = await import('node:util')
@@ -1846,7 +1889,7 @@ test('listIdeTree hides ignored files and folds package chains only under java',
1846
1889
  }
1847
1890
  })
1848
1891
 
1849
- test('a CRLF .gitignore with a trailing blank line does not hide empty folders', async () => {
1892
+ test('a CRLF .gitignore with a trailing blank line does not hide empty folders', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
1850
1893
  const { mkdtemp, mkdir, writeFile, rm } = await import('node:fs/promises')
1851
1894
  const { execFile } = await import('node:child_process')
1852
1895
  const { promisify } = await import('node:util')
@@ -1880,7 +1923,7 @@ test('a CRLF .gitignore with a trailing blank line does not hide empty folders',
1880
1923
  }
1881
1924
  })
1882
1925
 
1883
- test('findGitRoot walks up to the repo, and an unversioned tree lists raw', async () => {
1926
+ test('findGitRoot walks up to the repo, and an unversioned tree lists raw', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
1884
1927
  const { mkdtemp, mkdir, writeFile, rm } = await import('node:fs/promises')
1885
1928
  const { execFile } = await import('node:child_process')
1886
1929
  const { promisify } = await import('node:util')
@@ -2045,12 +2088,8 @@ test('readTailWindow pages backwards with abutting, whole-line windows', async (
2045
2088
  assert.ok(pages > 2, 'this file needed several pages')
2046
2089
  })
2047
2090
 
2048
- test('the SSE stream route is advertised', () => {
2049
- assert.equal(__test.STREAM_PATH, `${__test.ROUTE_PREFIX}/stream`)
2050
- })
2051
-
2052
-
2053
2091
  test('the SSE stream pushes a tail snapshot, then append deltas', async () => {
2092
+ assert.equal(__test.STREAM_PATH, `${__test.ROUTE_PREFIX}/stream`)
2054
2093
  const { mkdtemp, writeFile, appendFile } = await import('node:fs/promises')
2055
2094
  const { tmpdir } = await import('node:os')
2056
2095
  const { join } = await import('node:path')
@@ -2122,7 +2161,7 @@ test('a stale session id still answers when the client sends an absolute cwd', a
2122
2161
  })
2123
2162
 
2124
2163
  // ── a fresh tree read must show a file created after the last listing ──
2125
- test('fresh=1 re-reads the git-visible set so a just-copied file appears', async () => {
2164
+ test('fresh=1 re-reads the git-visible set so a just-copied file appears', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
2126
2165
  const { mkdtemp, writeFile } = await import('node:fs/promises')
2127
2166
  const { tmpdir } = await import('node:os')
2128
2167
  const { join } = await import('node:path')
@@ -2149,7 +2188,7 @@ test('fresh=1 re-reads the git-visible set so a just-copied file appears', async
2149
2188
  assert.ok(fresh.includes('a - 副本.txt'), 'fresh=1 reveals it')
2150
2189
  })
2151
2190
 
2152
- test('filter=all shows gitignored files, the default hides them', async () => {
2191
+ test('filter=all shows gitignored files, the default hides them', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
2153
2192
  const { mkdtemp, mkdir, writeFile } = await import('node:fs/promises')
2154
2193
  const { tmpdir } = await import('node:os')
2155
2194
  const { join } = await import('node:path')
@@ -2254,7 +2293,7 @@ test('the tree topic pushes changed relative paths from a recursive watch', asyn
2254
2293
 
2255
2294
 
2256
2295
  // ── filename search must never answer "nothing" just because cwd is a subdir ──
2257
- test('searchWorkspaceFiles climbs to the enclosing repo and falls back to a raw walk', async () => {
2296
+ test('searchWorkspaceFiles climbs to the enclosing repo and falls back to a raw walk', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
2258
2297
  const { mkdtemp, mkdir, writeFile } = await import('node:fs/promises')
2259
2298
  const { tmpdir } = await import('node:os')
2260
2299
  const { join } = await import('node:path')
@@ -2522,7 +2561,7 @@ test('the bundle route serves the built CodeMirror chunk and refuses other names
2522
2561
 
2523
2562
 
2524
2563
  // ── the watch filter must use the tree's own ignore rules (no git per event) ──
2525
- test('treeWatchAccepts keeps visible files and drops gitignored churn', async () => {
2564
+ test('treeWatchAccepts keeps visible files and drops gitignored churn', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
2526
2565
  const { mkdtemp, mkdir, writeFile } = await import('node:fs/promises')
2527
2566
  const { tmpdir } = await import('node:os')
2528
2567
  const { join } = await import('node:path')
@@ -2755,6 +2794,103 @@ test('pasted OS files upload and import into the tree', async () => {
2755
2794
  assert.equal((await upload({ sessionId: 's1', cwd: dir, dir, name: 'bad\nname.bin' }, 'x')).status, 400)
2756
2795
  })
2757
2796
 
2797
+ /** One `/fs/*` request against a fake ctx, answered by the real route. */
2798
+ async function callFsOp(ctx, pathname, body) {
2799
+ const { Readable } = await import('node:stream')
2800
+ const chunks = []
2801
+ const res = {
2802
+ status: 0,
2803
+ writeHead(status, headers) { this.status = status; this.headers = headers },
2804
+ write(chunk) { chunks.push(String(chunk)); return true },
2805
+ end(chunk) { if (chunk !== undefined && chunk !== null) chunks.push(String(chunk)) },
2806
+ on() {},
2807
+ }
2808
+ const req = Object.assign(Readable.from([JSON.stringify(body)]), {
2809
+ method: 'POST',
2810
+ url: `/dsh-ris-ide/${pathname}`,
2811
+ headers: { host: '127.0.0.1:3080' },
2812
+ })
2813
+ await __test.serveFsOp(ctx, req, res, {})
2814
+ const text = chunks.join('')
2815
+ return { status: res.status, body: text === '' ? undefined : JSON.parse(text) }
2816
+ }
2817
+
2818
+ // ── workspace switch: the fence follows the workspace the page SHOWS ────────
2819
+ test('a declared cwd wins the fence when it is a registered workspace (m00220)', async () => {
2820
+ const { mkdtemp, mkdir } = await import('node:fs/promises')
2821
+ const { tmpdir } = await import('node:os')
2822
+ const { join } = await import('node:path')
2823
+ // `shown` is the workspace the panel displays, `old` the one its session header
2824
+ // still names — the pair that used to earn 「不能对工作区之外的路径执行新建文件夹」.
2825
+ const shown = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-shown-'))
2826
+ const old = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-old-'))
2827
+ await mkdir(join(shown, '.dsh-ris-ide'), { recursive: true })
2828
+ // No remembered window rows in this home: only the registry may name a workspace.
2829
+ const home = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-home-'))
2830
+ const previousHome = process.env.DSH_RIS_IDE_PROXY_HOME
2831
+ process.env.DSH_RIS_IDE_PROXY_HOME = home
2832
+ try {
2833
+ const ctx = {
2834
+ sessions: { get: () => ({ header: { cwd: old } }) },
2835
+ get: (key) => (key === 'workspaceRegistry' ? { list: () => [{ path: shown, title: 'shown' }] } : undefined),
2836
+ }
2837
+ // Delete's first step (create the undo trash) runs inside the SHOWN workspace.
2838
+ const trash = await callFsOp(ctx, 'fs/mkdir', { sessionId: 's1', cwd: shown, path: join(shown, '.dsh-ris-ide', 'trash') })
2839
+ assert.equal(trash.status, 200, 'the shown workspace owns the request')
2840
+ // The fence still exists: a write into the OLD workspace's tree, or into a
2841
+ // directory dsh never registered, is refused as before.
2842
+ const crossWrite = await callFsOp(ctx, 'fs/mkdir', { sessionId: 's1', cwd: shown, path: join(old, 'evil') })
2843
+ assert.equal(crossWrite.status, 403)
2844
+ assert.equal(crossWrite.body.code, 'outside-workspace')
2845
+ const stray = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-stray-'))
2846
+ const unregistered = await callFsOp(ctx, 'fs/mkdir', { sessionId: 's1', cwd: stray, path: join(stray, 'x') })
2847
+ assert.equal(unregistered.status, 403, 'an arbitrary absolute cwd is never a licence')
2848
+ } finally {
2849
+ if (previousHome === undefined) delete process.env.DSH_RIS_IDE_PROXY_HOME
2850
+ else process.env.DSH_RIS_IDE_PROXY_HOME = previousHome
2851
+ }
2852
+ })
2853
+
2854
+ test('a copy may read from another registered workspace, a move may not (m00220)', async () => {
2855
+ const { mkdtemp, readFile, writeFile } = await import('node:fs/promises')
2856
+ const { tmpdir } = await import('node:os')
2857
+ const { join } = await import('node:path')
2858
+ const from = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-copy-from-'))
2859
+ const current = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-copy-to-'))
2860
+ const outside = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-copy-stray-'))
2861
+ await writeFile(join(from, 'notes.md'), '# copied\n')
2862
+ await writeFile(join(from, 'moved.md'), '# moved\n')
2863
+ const home = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-home-'))
2864
+ const previousHome = process.env.DSH_RIS_IDE_PROXY_HOME
2865
+ process.env.DSH_RIS_IDE_PROXY_HOME = home
2866
+ try {
2867
+ const ctx = {
2868
+ sessions: { get: () => ({ header: { cwd: current } }) },
2869
+ get: () => ({ list: () => [{ path: from, title: 'from' }, { path: current, title: 'current' }] }),
2870
+ }
2871
+ // The clipboard still names workspace A after switching to B: Ctrl+V copies.
2872
+ const copied = await callFsOp(ctx, 'fs/copy', { sessionId: 's1', cwd: current, from: join(from, 'notes.md'), toDir: current })
2873
+ assert.equal(copied.status, 200)
2874
+ assert.equal(await readFile(join(current, 'notes.md'), 'utf8'), '# copied\n')
2875
+ // A copy whose DESTINATION is outside the current tree is still refused: only
2876
+ // the read side widened.
2877
+ const writeOut = await callFsOp(ctx, 'fs/copy', { sessionId: 's1', cwd: current, from: join(from, 'notes.md'), toDir: from })
2878
+ assert.equal(writeOut.status, 403)
2879
+ assert.equal(writeOut.body.code, 'outside-workspace')
2880
+ // Moving across workspaces would relocate a tree out of its git boundary.
2881
+ const moved = await callFsOp(ctx, 'fs/move', { sessionId: 's1', cwd: current, from: join(from, 'moved.md'), toDir: current })
2882
+ assert.equal(moved.status, 403)
2883
+ // Only a workspace dsh knows may be read: a stray directory stays fenced.
2884
+ await writeFile(join(outside, 'secret.txt'), 'no')
2885
+ const stray = await callFsOp(ctx, 'fs/copy', { sessionId: 's1', cwd: current, from: join(outside, 'secret.txt'), toDir: current })
2886
+ assert.equal(stray.status, 403)
2887
+ assert.equal(stray.body.code, 'outside-workspace')
2888
+ } finally {
2889
+ if (previousHome === undefined) delete process.env.DSH_RIS_IDE_PROXY_HOME
2890
+ else process.env.DSH_RIS_IDE_PROXY_HOME = previousHome
2891
+ }
2892
+ })
2893
+
2758
2894
  // ── the debug stream: a page reload must still show its pre-set breakpoints ──
2759
2895
  test('the debug stream carries pending breakpoints, so a reload shows its dots', async () => {
2760
2896
  const { mkdtemp } = await import('node:fs/promises')
@@ -3055,6 +3191,35 @@ test('fs/window pages a large file and never splits a multi-byte character', asy
3055
3191
  assert.equal(__test.utf8CompleteLength(Buffer.alloc(0)), 0)
3056
3192
  })
3057
3193
 
3194
+ test('a git spawn failed by a deleted cwd does not disable git for the process (m03193)', { skip: skipWithout(HAS_GIT, 'git') }, () => {
3195
+ // `spawn('git', …, { cwd })` reports a missing binary and a deleted cwd the same
3196
+ // way (ENOENT, error.path 'git'), and the plugin runs git inside tree folders. A
3197
+ // single folder deleted mid-command used to latch "no git" for the whole process:
3198
+ // every tree then answered git:false (no .gitignore filter, greyed toggle) until
3199
+ // dsh restarted. The verdict is now a short quarantine, confirmed by a probe.
3200
+ const { gitUnavailable, noteGitSpawnFailure, noteGitSuccess } = __test
3201
+ noteGitSuccess()
3202
+ assert.equal(gitUnavailable(), false, 'git is trusted to begin with')
3203
+
3204
+ // The failure that used to poison it: git exists, only the cwd was gone.
3205
+ noteGitSpawnFailure()
3206
+ assert.equal(gitUnavailable(), false, 'a bad cwd must not be held against git')
3207
+
3208
+ // A probe from a cwd that always exists still has to be able to say "gone".
3209
+ const savedPath = process.env.PATH
3210
+ process.env.PATH = '/definitely/not/here'
3211
+ try {
3212
+ noteGitSpawnFailure()
3213
+ assert.equal(gitUnavailable(), true, 'an empty PATH confirms the binary is absent')
3214
+ } finally {
3215
+ process.env.PATH = savedPath
3216
+ }
3217
+
3218
+ // …and one good answer brings git back without restarting dsh.
3219
+ noteGitSuccess()
3220
+ assert.equal(gitUnavailable(), false, 'a successful git command clears the verdict')
3221
+ })
3222
+
3058
3223
  test('a same-named row of another kind is not taken over by an update', () => {
3059
3224
  // A yds project: the launcher row is `spring`, the discovered frontend row carries
3060
3225
  // the package.json name — an update must not move the launcher's startCommand onto
@@ -14,6 +14,30 @@ process.env.DSH_RIS_IDE_PROXY_HOME = mkdtempSync(join(tmpdir(), 'ris-proxy-home-
14
14
 
15
15
  import { __test } from '../lib/index.js'
16
16
  import { readProxyConfig, writeProxyConfig } from '../lib/proxy.js'
17
+ import { __test as redirectorTest } from '../lib/redirector.js'
18
+
19
+ // Stub every probe that could reach the real Windows side for the whole file.
20
+ // Two reasons, and both are not theoretical: (1) saving the table in these tests
21
+ // runs the production reload path, which finds a bridge by probing and then
22
+ // restarts/stops it — with the user's ProxyBridge_CLI running that would kill it;
23
+ // (2) `Get-Process ProxyBridge_CLI` through powershell.exe takes seconds and times
24
+ // out, which made this file take 17-26 s and pass or fail depending on load.
25
+ const PROBE_HOOKS = {
26
+ windowsPids: () => [],
27
+ localProc: () => 0,
28
+ windowsPidsAsync: async () => [],
29
+ windowsAlive: () => false,
30
+ windowsAliveAsync: async () => false,
31
+ taskkill: () => 'ERROR: Access is denied.',
32
+ }
33
+ redirectorTest.setProbeHooks(PROBE_HOOKS)
34
+ process.on('exit', () => redirectorTest.resetProbeHooks())
35
+ // The Windows process listing spawns powershell.exe (3-4.5 s on WSL, and it reads
36
+ // the developer's real desktop). A fixed list is all this file needs: the picker
37
+ // assertions are about which names are *offered* (SOCKS-capable filtering), not
38
+ // about what happens to be running.
39
+ __test.setWindowsProgramProbe(() => ['java', 'git', 'node', 'curl', 'navicat', 'mysql', 'redis-cli'])
40
+ process.on('exit', () => __test.setWindowsProgramProbe(null))
17
41
 
18
42
  /** A response face that collects the JSON body. */
19
43
  function fakeRes() {
@@ -148,6 +172,43 @@ test('a reload rewrites the profile BEFORE restarting the interceptor', () => {
148
172
  assert.ok(source.includes('redirector: Object.assign(redirectorStatusCached()'), 'the view uses it too')
149
173
  })
150
174
 
175
+ test('the bridge restart action is wired on the card, in the daemon and in the plugin', () => {
176
+ // The bridge parses its profile when it starts, so a rule-table save can leave old
177
+ // rules intercepting; the card offers ONE enforcement button whose label follows
178
+ // the state, and a click restarts = stop, settle, start from the new profile.
179
+ // Source pins: stopRedirector/startRedirectors shell out to the real side with no
180
+ // injection point, so the ordering can only be asserted on the source here.
181
+ const read = (file) => readFileSync(new URL(`../${file}`, import.meta.url), 'utf8')
182
+
183
+ // The card: one button (no separate restart / elevate controls), the stale-reload
184
+ // label, and it asks the plugin for the restart instead of auto-starting a proxy.
185
+ const ui = read('lib/risd/ui.js')
186
+ assert.match(ui, /redirector-restart/)
187
+ assert.doesNotMatch(ui, /id="bridge-health-elevate"/)
188
+ assert.doesNotMatch(ui, /maybeStartProxy/)
189
+
190
+ // The daemon must understand the action, and a page-triggered restart may prompt
191
+ // (it is the user asking); background reconcilers must not.
192
+ const server = read('lib/risd/server.js')
193
+ const daemonAt = server.indexOf("action === 'redirector-restart'")
194
+ assert.ok(daemonAt > 0, 'daemon must handle redirector-restart')
195
+ const daemonBlock = server.slice(daemonAt, daemonAt + 600)
196
+ assert.match(daemonBlock, /await stopRedirector\(\)/)
197
+ assert.match(daemonBlock, /setTimeout\(resolve, 300\)/)
198
+ assert.match(daemonBlock, /await startRedirectors\(\{ interactive \}\)/)
199
+ assert.match(server, /const interactive = parsed\.interactive === true/)
200
+
201
+ // The plugin forwards the action to the daemon and can run it itself.
202
+ const index = read('lib/index.js')
203
+ assert.match(index, /'redirector-restart'/)
204
+ const pluginAt = index.indexOf("action === 'redirector-restart'")
205
+ assert.ok(pluginAt > 0, 'plugin must handle redirector-restart locally')
206
+ const pluginBlock = index.slice(pluginAt, pluginAt + 400)
207
+ assert.match(pluginBlock, /await stopRedirector\(\)/)
208
+ assert.match(pluginBlock, /setTimeout\(resolve, 300\)/)
209
+ assert.match(pluginBlock, /await startRedirectors\(\)/)
210
+ })
211
+
151
212
  test('a save rendered from a stale table is refused, not applied', async () => {
152
213
  // Two windows hold the same table; the second save must not silently drop the
153
214
  // first one's row. The payload names the table it was rendered from.
@@ -10,6 +10,11 @@ test('the panel no longer opens a proxy dialog at all', () => {
10
10
  // dsh); both console shapes lost their 🌐, so nothing in the plugin opens the
11
11
  // in-panel dialog or the standalone proxy window any more.
12
12
  assert.doesNotMatch(client, /data-action': 'compact-proxy'/)
13
+ // Neither console (header rows and the sidebar compact bar) pushes a 🌐 button
14
+ // any more, and the flag that opened the dialog is gone with it. Moved here from
15
+ // risd-entry.test.mjs, which only carried these two negative assertions.
16
+ assert.doesNotMatch(client, /consoleConfigActions\.push\(button\('🌐'/)
17
+ assert.doesNotMatch(client, /compactProxyOpen/)
13
18
  assert.doesNotMatch(client, /setProxyOpen\(true\)|setCompactProxyOpen\(true\)/)
14
19
  assert.doesNotMatch(client, /focus-ack/)
15
20
  })