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
@@ -184,41 +184,16 @@ test('double-clicking a title-bar control does not maximise the pane', () => {
184
184
  assert.equal(T.headerDoubleClickIsTitle(input), false)
185
185
  })
186
186
 
187
- test('the dialog marks exactly one of start/stop as the live action', async () => {
188
- const { readFile } = await import('node:fs/promises')
189
- const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
190
- // `S.buttonOff` is the DISABLED skin, so painting an enabled action with it made
191
- // 启动/停止 look equally dead. One shared factory fixes the box, and only the
192
- // actionable button is filled.
193
- assert.ok(source.includes('function dialogButton(spec)'), 'start/stop/save must share one button shape')
194
- assert.ok(source.includes('minWidth: 84, height: 28'), 'all three must share one box so the row lines up')
195
- assert.ok(source.includes('var filled = spec.primary === true && spec.disabled !== true'),
196
- 'grey is reserved for "nothing to do here"')
197
- assert.ok(source.includes("primary: !running,"), '启动 is the filled one while stopped')
198
- assert.ok(source.includes("primary: running,"), '停止 is the filled one while running')
199
- assert.ok(source.includes("'data-proxy-action': spec.action"), 'the three actions stay addressable')
200
- // Enabled controls must not borrow the disabled skin.
201
- assert.equal(source.includes("style: S.buttonOff, 'data-proxy-add'"), false, '+ 添加规则 is enabled, not inert')
202
- assert.equal(source.includes("style: S.buttonOff, 'data-proxy-close'"), false, 'the close ✕ is enabled, not inert')
203
- })
204
-
205
187
  test('one proxy control governs engine, interception and git together', async () => {
206
188
  const { readFile } = await import('node:fs/promises')
207
- const client = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
208
189
  const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
209
- // No separate git buttons: git follows the tunnel it belongs to.
210
- assert.equal(client.includes('data-proxy-git-on'), false, 'the git-on button is gone')
211
- assert.equal(client.includes('data-proxy-git-off'), false, 'the git-off button is gone')
212
- assert.ok(client.includes('启动同时写入 git 代理,停止同时清除'), 'the footer has to say what start/stop do')
213
- // Start/stop drive all three layers, and so does the host exit hook.
190
+ // Start/stop drive all three layers, and so does the host exit hook. The UI that
191
+ // used to say so lives on the risd page now (the panel dialog is deleted).
214
192
  assert.ok(host.includes('const redirector = await startRedirectors()'), 'start brings the interception up')
215
193
  assert.ok(host.includes('syncGitProxy({ cwd, host: gitHost, enabled: true })'), 'start writes the git entry')
216
194
  assert.ok(host.includes('syncGitProxy({ cwd, host: gitHost, enabled: false })'), 'stop clears the git entry')
217
195
  assert.ok(host.includes('const redirector = await stopRedirector()'), 'stop brings the interception down')
218
196
  assert.ok(host.includes('clearGitProxySync()'), 'the exit hook undoes the git entry too')
219
- // The route reports each layer's outcome so a dismissed UAC prompt is visible.
220
- assert.ok(client.includes("' · 系统层拦截已启动('"), 'the note reports the interception start')
221
- assert.ok(client.includes("' · git 代理已写入 '"), 'the note reports the git entry')
222
197
  })
223
198
 
224
199
  test('the console follows the live sidebar session, not the one it opened in', async () => {
@@ -239,15 +214,8 @@ test('the console follows the live sidebar session, not the one it opened in', a
239
214
  assert.ok(source.includes("if (typeof liveSessionId === 'string' && liveSessionId !== '') sessionId = liveSessionId"),
240
215
  'the live id must win over the injected one')
241
216
  assert.ok(source.includes('}, [sessionIdentity])'), 'another workspace must drop the followed program')
242
- // Both console shapes share one dialog, so it must not inherit either font.
243
- assert.ok(source.includes("fontFamily: CHROME_FAMILY, fontSize: DEFAULT_FONT_SIZE + 'px'"),
244
- 'the proxy dialog pins the IDE chrome font so the narrow console does not wrap rows')
245
217
  assert.ok(source.includes("'Microsoft YaHei', sans-serif)"),
246
218
  'the chrome stack must match what the IDE theme resolves to, not a mono list')
247
- // Form controls do not inherit the page font: the dialog has to say so, twice.
248
- assert.ok(source.includes("fontFamily: 'inherit'"), 'the field style must inherit the dialog font')
249
- assert.ok(source.includes('[data-proxy-dialog] input, [data-proxy-dialog] button, [data-proxy-dialog] select, [data-proxy-dialog] textarea { font-family: inherit; font-size: inherit; }'),
250
- 'every control inside the dialog must inherit the card font')
251
219
  })
252
220
 
253
221
  test('only invisible outcomes and failures raise a toast', async () => {
@@ -511,7 +479,8 @@ test('apply adds a Session-header button immediately right of DSH\'s open-in-app
511
479
  const markup = renderToStaticMarkup(React.createElement(header.component, { sessionId: 's1' }))
512
480
  assert.match(markup, /data-action="ris-ide-window"/)
513
481
  assert.match(markup, /RIS-IDE/)
514
- assert.match(markup, /title="在独立窗口中打开RIS-IDE"/, 'the tooltip is the short wording')
482
+ assert.match(markup, /title="打开 risd 维护页(概览 \/ 代理 \/ IDE):IDE 内嵌其中,可按工作区切换"/, 'the tooltip names the maintenance page')
483
+ assert.match(markup, /aria-busy="false"/, 'idle: the button says it is not opening anything')
515
484
  }
516
485
  })
517
486
 
@@ -541,6 +510,108 @@ test('the header button opens THIS session\'s workspace, not the remembered one'
541
510
  )
542
511
  })
543
512
 
513
+ test('⧉ reuses the prefetched daemon address, so a warm click adds no round trip', async () => {
514
+ // The visible delay was the on-demand spawn, but the host-view read sat in front
515
+ // of EVERY click. The header button and the console prefetch it on mount with a
516
+ // 20 s TTL; a click inside that window only has to call `window.open`.
517
+ const previous = { window: globalThis.window, document: globalThis.document, fetch: globalThis.fetch }
518
+ const opened = []
519
+ const requested = []
520
+ globalThis.document = { baseURI: 'http://127.0.0.1:3080/' }
521
+ globalThis.window = { open: (url, name) => { opened.push([url, name]); return { focus() {} } } }
522
+ globalThis.fetch = async (href) => {
523
+ requested.push(String(href))
524
+ return { ok: true, status: 200, json: async () => ({ ok: true, risd: { available: true, url: 'http://127.0.0.1:4567' } }) }
525
+ }
526
+ let fallbacks = 0
527
+ try {
528
+ T.resetRisdPrefetch()
529
+ const warm = await T.prefetchRisd({ sessionId: 's1', cwd: '/w/project' })
530
+ assert.equal(warm.url, 'http://127.0.0.1:4567', 'the prefetch keeps the daemon address')
531
+ assert.equal(requested.length, 1, 'the prefetch asks the host once')
532
+ assert.deepEqual(T.risdCachedAddress(), warm, 'the address is cached for the click')
533
+
534
+ const entry = await T.openRisdPage({ sessionId: 's1', cwd: '/w/project' }, async () => { fallbacks += 1 })
535
+ assert.equal(entry, 'risd')
536
+ assert.equal(requested.length, 1, 'the click adds no request: the cache answered')
537
+ assert.equal(opened.length, 1, 'exactly one tab')
538
+ assert.equal(opened[0][1], 'dsh-risd-ui', 'the maintenance tab keeps its name')
539
+ assert.match(opened[0][0], /^http:\/\/127\.0\.0\.1:4567\/ui\?cwd=%2Fw%2Fproject$/, 'preselects the workspace without switching the tab (m11345)')
540
+ assert.equal(fallbacks, 0, 'no standalone fallback when the daemon address is known')
541
+ } finally {
542
+ globalThis.window = previous.window
543
+ globalThis.document = previous.document
544
+ globalThis.fetch = previous.fetch
545
+ T.resetRisdPrefetch()
546
+ }
547
+ })
548
+
549
+ test('a cold ⧉ falls back to ensure and a double click still opens ONE tab', async () => {
550
+ const previous = { window: globalThis.window, document: globalThis.document, fetch: globalThis.fetch }
551
+ const opened = []
552
+ const requested = []
553
+ let releaseProxy = null
554
+ globalThis.document = { baseURI: 'http://127.0.0.1:3080/' }
555
+ globalThis.window = { open: (url, name) => { opened.push([url, name]); return { focus() {} } } }
556
+ globalThis.fetch = async (href) => {
557
+ const url = String(href)
558
+ requested.push(url)
559
+ if (url.includes('/risd/ensure')) {
560
+ return { ok: true, status: 200, json: async () => ({ ok: true, spawned: true, risd: { available: true, url: 'http://127.0.0.1:4567' } }) }
561
+ }
562
+ // Hold the host view open so the second click lands while the first is in flight.
563
+ return await new Promise((resolve) => {
564
+ releaseProxy = () => resolve({ ok: true, status: 200, json: async () => ({ ok: true, risd: { available: false } }) })
565
+ })
566
+ }
567
+ try {
568
+ T.resetRisdPrefetch()
569
+ const fallback = async () => { throw new Error('a spawnable daemon must not fall back') }
570
+ const first = T.openRisdPage({ sessionId: 's1', cwd: '/w/project' }, fallback)
571
+ const second = T.openRisdPage({ sessionId: 's1', cwd: '/w/project' }, fallback)
572
+ assert.equal(typeof releaseProxy, 'function', 'the host view read is in flight')
573
+ releaseProxy()
574
+ assert.equal(await first, 'risd')
575
+ assert.equal(await second, 'risd')
576
+ assert.equal(opened.length, 1, 'the in-flight open is shared, not duplicated')
577
+ assert.deepEqual(requested.map((href) => new URL(href).pathname), ['/dsh-ris-ide/proxy', '/dsh-ris-ide/risd/ensure'])
578
+ assert.equal(new URL(opened[0][0]).searchParams.get('cwd'), '/w/project', 'preselects the workspace')
579
+ assert.equal(new URL(opened[0][0]).searchParams.get('tab'), null, 'does not switch the tab (m11345)')
580
+ assert.equal(T.risdCachedAddress().url, 'http://127.0.0.1:4567', 'the ensured address warms the cache')
581
+ } finally {
582
+ globalThis.window = previous.window
583
+ globalThis.document = previous.document
584
+ globalThis.fetch = previous.fetch
585
+ T.resetRisdPrefetch()
586
+ }
587
+ })
588
+
589
+ test('both ⧉ buttons show progress and never run two opens at once', async () => {
590
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
591
+ // Session-header button: disabled + aria-busy, the ⧉ becomes an ellipsis and the
592
+ // label says 「打开中」; `finally` puts it back even when the popup was blocked.
593
+ assert.match(source, /'aria-busy': opening === true \? 'true' : 'false'/, 'the header button announces its busy state')
594
+ assert.match(source, /disabled: opening === true,/, 'and cannot be clicked twice')
595
+ assert.match(source, /opening === true \? '…' : '⧉'/, 'the icon becomes a progress ellipsis')
596
+ assert.match(source, /opening === true \? '打开中' : 'RIS-IDE'/, 'the label says it is opening')
597
+ assert.match(source, /setOpening\(false\)/, 'finally restores the button')
598
+ // The icon-only console ⧉ mirrors it (title / aria-label carry the wording).
599
+ assert.match(source, /'aria-busy': openingIde === true \? 'true' : 'false'/)
600
+ assert.match(source, /disabled: openingIde === true,/)
601
+ assert.match(source, /openingIde === true \? '…' : '⧉'/)
602
+ assert.match(source, /正在打开 risd 维护页/)
603
+ assert.match(source, /setOpeningIde\(false\)/, 'its finally restores the button too')
604
+ // Warm cache + single flight.
605
+ assert.match(source, /var risdPrefetch = \{ at: 0, risd: null, pending: null \}/)
606
+ assert.match(source, /var RISD_PREFETCH_TTL_MS = 20000/)
607
+ assert.match(source, /function prefetchRisd\(scope\)/)
608
+ assert.match(source, /if \(risdOpenPending !== null\) return risdOpenPending/)
609
+ assert.match(source, /onPointerEnter: warmRisdAddress/, 'hovering the header button warms the address')
610
+ assert.match(source, /onPointerEnter: warmCompactRisd/, 'the console icon warms it the same way')
611
+ assert.match(source, /void prefetchRisd\(\{ sessionId: sessionId, cwd: sessionCwd \}\)/, 'the header button warms the cache on mount')
612
+ assert.match(source, /void prefetchRisd\(\{ sessionId: sessionId, cwd: cwd \}\)/, 'the console warms it too')
613
+ })
614
+
544
615
  test('openStandaloneWindow hands the scope to the plugin\'s own page', async () => {
545
616
  const previousWindow = globalThis.window
546
617
  const previousDocument = globalThis.document
@@ -555,7 +626,8 @@ test('openStandaloneWindow hands the scope to the plugin\'s own page', async ()
555
626
  try {
556
627
  const handle = await T.openStandaloneWindow({ sessionId: 's1', cwd: '/w/project', programId: 'p1' })
557
628
  assert.equal(opened.length, 1)
558
- const [openedUrl, name, features] = opened[0]
629
+ const [openedUrl, name] = opened[0]
630
+ assert.equal(opened[0].length, 2, 'a plain window.open(url, name): no feature string')
559
631
  const parsed = new URL(openedUrl)
560
632
  // Same origin as the DSH page: no new port, cookie auth comes along.
561
633
  assert.equal(parsed.origin, 'http://127.0.0.1:3080')
@@ -578,7 +650,6 @@ test('openStandaloneWindow hands the scope to the plugin\'s own page', async ()
578
650
  const scoped = new URL(opened[opened.length - 1][0])
579
651
  assert.equal(scoped.searchParams.get('cwd'), '/w/project/sub', 'the panel keeps its rooted cwd')
580
652
  assert.equal(opened[opened.length - 1][1], T.standaloneWindowName('/w/project'), 'the window name stays workspace-keyed')
581
- assert.match(features, /popup=yes/)
582
653
  // The compact panel's 🐞 button: same window, plus "start the JDWP session".
583
654
  await T.openStandaloneWindow({ sessionId: 's1', cwd: '/w/project', programId: 'p1', debug: true })
584
655
  assert.equal(new URL(opened[opened.length - 1][0]).searchParams.get('debug'), '1')
@@ -699,7 +770,7 @@ test('a closed window never blocks the next open (dead registrations do not wait
699
770
  }
700
771
  })
701
772
 
702
- test('openStandaloneWindow asks for the whole screen work area (maximized)', async () => {
773
+ test('openStandaloneWindow opens a normal browser window, not a sized popup', async () => {
703
774
  const previousWindow = globalThis.window
704
775
  const previousDocument = globalThis.document
705
776
  const previousFetch = globalThis.fetch
@@ -712,16 +783,13 @@ test('openStandaloneWindow asks for the whole screen work area (maximized)', asy
712
783
  globalThis.fetch = async () => ({ ok: false, status: 404, json: async () => ({}) })
713
784
  try {
714
785
  await T.openStandaloneWindow({ sessionId: 's1' })
715
- const features = opened[0][2]
716
- assert.match(features, /width=1920/, 'the work area width, not a fixed width')
717
- assert.match(features, /height=1040/, 'the work area height, not a fixed height')
718
- assert.match(features, /left=0/, 'pinned to the left edge')
719
- assert.match(features, /top=0/, 'pinned to the top edge')
720
- assert.match(features, /popup=yes/)
721
- // No screen information (odd hosts): keep the old fallback instead of NaN.
786
+ assert.equal(opened[0].length, 2, 'no features argument: the browser decides the frame')
787
+ assert.match(opened[0][1], /^dsh-ris-ide-window-/, 'the workspace-keyed name is what makes it single-instance')
788
+ // A host without screen information must not change the call shape either.
722
789
  globalThis.window = { open: (...args) => { opened.push(args); return { focus() {} } } }
790
+ globalThis.window.localStorage = { getItem: () => '/w/project' }
723
791
  await T.openStandaloneWindow({ sessionId: 's1' })
724
- assert.match(opened[1][2], /width=1500/)
792
+ assert.equal(opened[1].length, 2)
725
793
  } finally {
726
794
  globalThis.window = previousWindow
727
795
  globalThis.document = previousDocument
@@ -2189,8 +2257,8 @@ test('the title-bar controls share one 20px row height', { skip: !reactIsReal ?
2189
2257
  const consoleTags = buttonsOf(consoleHead)
2190
2258
  assert.ok(sourceTags.length >= 3, 'the source toolbar carries the font scale, the theme switch and reset')
2191
2259
  const consoleActions = consoleTags.map((tag) => /data-action="([^"]+)"/.exec(tag)[1])
2192
- assert.deepEqual(consoleActions, ['config-open', 'config-generate', 'proxy-open'],
2193
- 'the console title bar carries 📄 open-config, ⚙ config-generate and 🌐 proxy')
2260
+ assert.deepEqual(consoleActions, ['config-open', 'config-generate'],
2261
+ 'the console title bar carries 📄 open-config and ⚙ config-generate only (proxy moved out)')
2194
2262
  for (const tag of sourceTags.concat(consoleTags)) {
2195
2263
  const action = /data-action="([^"]+)"/.exec(tag)[1]
2196
2264
  assert.match(tag, /height:20px/, `${action} must sit on the shared 20px row`)
@@ -2631,7 +2699,8 @@ test('the saved layout (maximised + theme + font + sizes) restores on init, even
2631
2699
  const hadLocalStorage = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage')
2632
2700
  const previousLocalStorage = globalThis.localStorage
2633
2701
  try {
2634
- // A legacy per-program blob: the panel used to key the layout by program id.
2702
+ // A pre-m13444 blob for THIS tab: the panel used to key the layout without a
2703
+ // workspace suffix, and the first workspace to open the tab migrates it once.
2635
2704
  const legacy = JSON.stringify({
2636
2705
  ui: { maximized: 'editor', section: 'threads' },
2637
2706
  theme: 'light',
@@ -2640,7 +2709,7 @@ test('the saved layout (maximised + theme + font + sizes) restores on init, even
2640
2709
  files: [],
2641
2710
  file: undefined,
2642
2711
  })
2643
- const store = new Map([['dsh-ris-ide:ui:spring:ris/ris-model#a.B', legacy]])
2712
+ const store = new Map([['dsh-ris-ide:ui:workspace', legacy]])
2644
2713
  globalThis.localStorage = {
2645
2714
  get length() { return store.size },
2646
2715
  key: (index) => Array.from(store.keys())[index],
@@ -2659,33 +2728,49 @@ test('the saved layout (maximised + theme + font + sizes) restores on init, even
2659
2728
  }
2660
2729
  })
2661
2730
 
2662
- test('readSavedUi prefers the exact key, falls back to a legacy one, and survives junk', () => {
2731
+ test('readSavedUi prefers the exact key, migrates the legacy one ONCE, and survives junk', () => {
2663
2732
  const hadLocalStorage = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage')
2664
2733
  const previousLocalStorage = globalThis.localStorage
2665
2734
  try {
2666
2735
  const store = new Map([
2667
- ['dsh-ris-ide:ui:workspace', JSON.stringify({ ui: { maximized: null }, font: 13 })],
2668
- ['dsh-ris-ide:ui:spring:x#y', JSON.stringify({ ui: { maximized: 'tree' }, font: 18 })],
2736
+ ['dsh-ris-ide:ui:workspace@/w/a', JSON.stringify({ ui: { maximized: null }, font: 13 })],
2737
+ ['dsh-ris-ide:ui:workspace', JSON.stringify({ ui: { maximized: 'tree' }, font: 18 })],
2669
2738
  ])
2670
2739
  globalThis.localStorage = {
2671
2740
  get length() { return store.size },
2672
2741
  key: (index) => Array.from(store.keys())[index],
2673
2742
  getItem: (key) => (store.has(key) ? store.get(key) : null),
2743
+ setItem: (key, value) => { store.set(key, value) },
2744
+ removeItem: (key) => { store.delete(key) },
2745
+ }
2746
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/a', '/w/a').font, 13, 'the exact key wins')
2747
+ // The pre-m13444 global key is adopted once by the FIRST workspace and deleted,
2748
+ // so a second workspace does not inherit the same tabs again (C review P1-2).
2749
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/b', '/w/b').font, 18, 'the legacy key is adopted')
2750
+ assert.equal(store.has('dsh-ris-ide:ui:workspace'), false, 'and removed after adoption')
2751
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/c', '/w/c'), null, 'a second workspace gets nothing')
2752
+
2753
+ // Non-blob preferences share the `…:ui:` prefix; they must not abort the scan.
2754
+ const noisy = new Map([['dsh-ris-ide:ui:compact-max', 'log']])
2755
+ globalThis.localStorage = {
2756
+ get length() { return noisy.size },
2757
+ key: (index) => Array.from(noisy.keys())[index],
2758
+ getItem: (key) => (noisy.has(key) ? noisy.get(key) : null),
2674
2759
  setItem: () => {},
2760
+ removeItem: () => {},
2675
2761
  }
2676
- assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace').font, 13, 'the exact key wins')
2762
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:nothing', 'nothing'), null, 'junk does not throw')
2677
2763
 
2678
- const withoutExact = new Map(Array.from(store.entries()).filter(([key]) => key !== 'dsh-ris-ide:ui:workspace'))
2764
+ // Another workspace's tab is never adopted; a cwd containing `@` cannot spoof it.
2765
+ const other = new Map([['dsh-ris-ide:ui:workspace@/ws/x@/w/a', JSON.stringify({ font: 19 })]])
2679
2766
  globalThis.localStorage = {
2680
- get length() { return withoutExact.size },
2681
- key: (index) => Array.from(withoutExact.keys())[index],
2682
- getItem: (key) => (withoutExact.has(key) ? withoutExact.get(key) : null),
2767
+ get length() { return other.size },
2768
+ key: (index) => Array.from(other.keys())[index],
2769
+ getItem: (key) => (other.has(key) ? other.get(key) : null),
2683
2770
  setItem: () => {},
2771
+ removeItem: () => {},
2684
2772
  }
2685
- assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace').font, 18, 'a legacy per-program key is adopted')
2686
-
2687
- withoutExact.set('dsh-ris-ide:ui:broken', '{not json')
2688
- assert.ok(T.readSavedUi('dsh-ris-ide:ui:nothing') !== null, 'junk does not throw')
2773
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/b', '/w/b'), null, 'cross-workspace adoption is refused')
2689
2774
  } finally {
2690
2775
  if (hadLocalStorage) globalThis.localStorage = previousLocalStorage
2691
2776
  else globalThis.localStorage = undefined
@@ -3585,6 +3670,58 @@ test('capOpenFiles appends under the cap and evicts only the oldest clean tab',
3585
3670
 
3586
3671
 
3587
3672
 
3673
+ test('tabs, recent history and search cache are scoped to one workspace (m13444)', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
3674
+ const hadLocalStorage = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage')
3675
+ const previousLocalStorage = globalThis.localStorage
3676
+ try {
3677
+ const keys = []
3678
+ globalThis.localStorage = {
3679
+ getItem: (key) => { keys.push(String(key)); return null },
3680
+ setItem: () => {},
3681
+ }
3682
+ renderWorkbench({ scope: { sessionId: 's1', cwd: '/w/a' }, tab: { id: T.PROGRAM_TAB_ID, type: T.PROGRAM_TAB_ID, title: 'workspace' } })
3683
+ renderWorkbench({ scope: { sessionId: 's1', cwd: '/w/b' }, tab: { id: T.PROGRAM_TAB_ID, type: T.PROGRAM_TAB_ID, title: 'workspace' } })
3684
+ assert.ok(keys.includes('dsh-ris-ide:ui:workspace@/w/a'), `workspace A key missing: ${keys.join(', ')}`)
3685
+ assert.ok(keys.includes('dsh-ris-ide:ui:workspace@/w/b'), `workspace B key missing: ${keys.join(', ')}`)
3686
+
3687
+ // Adopting a legacy blob must stay inside the current workspace.
3688
+ const store = new Map([
3689
+ ['dsh-ris-ide:ui:workspace@/w/a', JSON.stringify({ files: ['/w/a/x.java'], file: '/w/a/x.java' })],
3690
+ ])
3691
+ globalThis.localStorage = {
3692
+ getItem: (key) => store.get(key) ?? null,
3693
+ setItem: () => {},
3694
+ get length() { return store.size },
3695
+ key: (index) => [...store.keys()][index] ?? null,
3696
+ }
3697
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/b', '/w/b'), null, "another workspace's tabs are not adopted")
3698
+ assert.deepEqual(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/a', '/w/a').files, ['/w/a/x.java'])
3699
+ // A migrated legacy blob is consumed once: another FILE tab of the same
3700
+ // workspace must not inherit the pre-m13444 tabs again (20261109-2326 review).
3701
+ const legacyStore = new Map([['dsh-ris-ide:ui:workspace', JSON.stringify({ files: ['/w/a/x.java'] })]]);
3702
+ const removedKeys = []
3703
+ globalThis.localStorage = {
3704
+ getItem: (key) => (legacyStore.has(key) ? legacyStore.get(key) : null),
3705
+ setItem: (key, value) => { legacyStore.set(key, String(value)) },
3706
+ removeItem: (key) => { removedKeys.push(key); legacyStore.delete(key) },
3707
+ get length() { return legacyStore.size },
3708
+ key: (index) => [...legacyStore.keys()][index] ?? null,
3709
+ }
3710
+ assert.deepEqual(T.readSavedUi('dsh-ris-ide:ui:workspace@/w/a', '/w/a').files, ['/w/a/x.java'], 'the first opener migrates the legacy blob')
3711
+ assert.deepEqual(removedKeys, ['dsh-ris-ide:ui:workspace'], 'the legacy key is consumed exactly once')
3712
+ assert.equal(T.readSavedUi('dsh-ris-ide:ui:demo@/w/a', '/w/a'), null, 'switching to another file tab does not re-migrate')
3713
+ } finally {
3714
+ if (hadLocalStorage) globalThis.localStorage = previousLocalStorage
3715
+ else globalThis.localStorage = undefined
3716
+ }
3717
+ })
3718
+
3719
+ test('the elevation terminal never opens during a test run (m13621)', async () => {
3720
+ const source = await readFile(new URL('../lib/redirector.js', import.meta.url), 'utf8')
3721
+ assert.match(source, /NODE_TEST_CONTEXT !== undefined && process\.env\.DSH_RIS_IDE_ALLOW_TERMINAL !== '1'/)
3722
+ assert.match(source, /if \(process\.env\.NODE_TEST_CONTEXT !== undefined && process\.env\.DSH_RIS_IDE_ALLOW_TERMINAL !== '1'\) return false/)
3723
+ })
3724
+
3588
3725
  test('the workbench restores open source tabs from localStorage and shows the workspace path', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
3589
3726
  const hadLocalStorage = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage')
3590
3727
  const previousLocalStorage = globalThis.localStorage
@@ -3592,7 +3729,7 @@ test('the workbench restores open source tabs from localStorage and shows the wo
3592
3729
  globalThis.localStorage = {
3593
3730
  getItem: (key) => {
3594
3731
  keys.push(key)
3595
- return key === 'dsh-ris-ide:ui:workspace'
3732
+ return String(key).startsWith('dsh-ris-ide:ui:workspace@')
3596
3733
  ? JSON.stringify({ ui: {}, files: ['/w/a.java', '/w/b.java'], file: '/w/a.java', sizes: {} })
3597
3734
  : null
3598
3735
  },
@@ -3604,7 +3741,7 @@ test('the workbench restores open source tabs from localStorage and shows the wo
3604
3741
  // No program meta → the WORKSPACE storage key, the one this test restores.
3605
3742
  tab: { id: T.PROGRAM_TAB_ID, type: T.PROGRAM_TAB_ID, title: 'workspace' },
3606
3743
  })
3607
- assert.ok(keys.includes('dsh-ris-ide:ui:workspace'), `unexpected storage key ${keys.join(', ')}`)
3744
+ assert.ok(keys.some((key) => key.startsWith('dsh-ris-ide:ui:workspace@')), `unexpected storage key ${keys.join(', ')}`)
3608
3745
  assert.match(markup, /data-workbench-path="1">\/w\/work</, 'the top bar shows the workspace path')
3609
3746
  assert.equal((markup.match(/data-tab-close="source"/g) || []).length, 2, 'both restored files get a tab')
3610
3747
  assert.match(markup, /a\.java/)
@@ -3724,7 +3861,7 @@ test('a stored font size scales the IDE blocks through the style proxy', { skip:
3724
3861
  globalThis.localStorage = {
3725
3862
  getItem: (key) => {
3726
3863
  keys.push(key)
3727
- return key === 'dsh-ris-ide:ui:workspace'
3864
+ return String(key).startsWith('dsh-ris-ide:ui:workspace@')
3728
3865
  ? JSON.stringify({ font: 15, files: [], ui: {}, sizes: {} })
3729
3866
  : null
3730
3867
  },
@@ -3733,7 +3870,7 @@ test('a stored font size scales the IDE blocks through the style proxy', { skip:
3733
3870
  try {
3734
3871
  // Meta-less tab → the workspace key (a program meta would use its own key).
3735
3872
  const markup = renderWorkbench({ tab: { id: T.PROGRAM_TAB_ID, type: T.PROGRAM_TAB_ID, title: 'workspace' } })
3736
- assert.ok(keys.includes('dsh-ris-ide:ui:workspace'), `unexpected storage keys ${keys.join(', ')}`)
3873
+ assert.ok(keys.some((key) => key.startsWith('dsh-ris-ide:ui:workspace@')), `unexpected storage keys ${keys.join(', ')}`)
3737
3874
  assert.match(workbenchRootTagOf(markup), /font-size:15px/, 'the stored size reaches the workbench root')
3738
3875
  assert.match(styleChildOf(markup), /\.cm-editor\{font-size:15px !important\}/, 'the stored size reaches CodeMirror')
3739
3876
  // 12px authored × (15 / 12.5) = 14.4 → nearest 0.5px = 14.5
@@ -3795,7 +3932,7 @@ function stubWorkspaceUi(patch, keys) {
3795
3932
  globalThis.localStorage = {
3796
3933
  getItem: (key) => {
3797
3934
  if (keys !== undefined) keys.push(key)
3798
- return key === 'dsh-ris-ide:ui:workspace'
3935
+ return String(key).startsWith('dsh-ris-ide:ui:workspace@')
3799
3936
  ? JSON.stringify(Object.assign({ files: [], ui: {}, sizes: {} }, patch))
3800
3937
  : null
3801
3938
  },
@@ -4045,8 +4182,9 @@ test('one IDE window per workspace: the window name is keyed by the workspace cw
4045
4182
  assert.doesNotMatch(source, /focusStandaloneWindow/, 'raising a foreign window is not attempted any more')
4046
4183
  assert.match(source, /await requestStandaloneWindowClose\(windowName\)/, 'present: ask the old window to close, then open one')
4047
4184
  assert.doesNotMatch(source, /focus-ack/, 'no focus handshake: the browser forbids it')
4048
- assert.match(source, /window\.open\(url\.href, windowName, features\)/, 'absent: create it straight on the IDE url')
4049
- assert.doesNotMatch(source, /window\.open\('', windowName, features\)/, 'never a blank window to close again')
4185
+ assert.match(source, /window\.open\(url\.href, windowName\)/, 'absent: create it straight on the IDE url, as a normal window')
4186
+ assert.doesNotMatch(source, /window\.open\(url\.href, windowName, features\)/, 'no popup feature string any more')
4187
+ assert.doesNotMatch(source, /window\.open\('', windowName/, 'never a blank window to close again')
4050
4188
  assert.doesNotMatch(source, /settleStandaloneWindow/)
4051
4189
  })
4052
4190
 
@@ -4076,7 +4214,11 @@ test('the standalone window claims a single-instance lock before booting the IDE
4076
4214
  // offers an explicit "close this window" action instead — and only that button
4077
4215
  // may close it (never an automatic close at boot).
4078
4216
  assert.match(claim, /关闭这个窗口/, 'the duplicate window can be closed on demand')
4079
- assert.equal((claim.match(/window\.close\(\)/g) || []).length, 2, 'closing happens only from the two explicit user actions')
4217
+ // One explicit close action remains; inside the maintenance page's iframe that
4218
+ // offer is dropped (window.close() is refused there — review D3).
4219
+ assert.equal((claim.match(/window\.close\(\)/g) || []).length, 2, 'closing happens only from the explicit user actions')
4220
+ assert.match(claim, /window\.self !== window\.top/, 'the embedded case is detected')
4221
+ assert.match(claim, /if \(!embedded\)/, 'the dead close button is not rendered inside an iframe')
4080
4222
  // Booting waits for the claim, so the notice cannot be raced by a mounted panel.
4081
4223
  assert.match(html, /window\.__risIdeClaimReady/)
4082
4224
  assert.match(html, /window\.__risIdeBootPanel = bootPanel/)
@@ -4547,15 +4689,17 @@ test('the find box accepts more than one character while it has matches', async
4547
4689
  test('Ctrl+R re-reads the workspace instead of replaying the search cache', async () => {
4548
4690
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4549
4691
 
4550
- // The cache is keyed by the query TEXT only, so an explicit re-search must drop
4551
- // the entries and make both streaming effects run again.
4692
+ // The cache is keyed by kind + WORKSPACE + query (m13444), so an explicit
4693
+ // re-search must drop this workspace's entries and re-run both effects.
4552
4694
  assert.match(source, /var \[searchReload, setSearchReload\] = useState\(0\)/)
4695
+ assert.match(source, /function searchKey\(kind, text\) \{/)
4696
+ assert.match(source, /return kind \+ ':' \+ workspaceKey \+ '\\u0000' \+ text/)
4553
4697
  assert.match(source, /function reloadWorkspaceSearch\(text\) \{/)
4554
- assert.match(source, /searchCacheRef\.current\.delete\('content:' \+ query\)/)
4555
- assert.match(source, /searchCacheRef\.current\.delete\('name:' \+ query\)/)
4556
- const effects = source.split("var cached = searchCacheRef.current.get('name:' + text)")
4698
+ assert.match(source, /searchCacheRef\.current\.delete\(searchKey\('content', query\)\)/)
4699
+ assert.match(source, /searchCacheRef\.current\.delete\(searchKey\('name', query\)\)/)
4700
+ const effects = source.split("var cached = searchCacheRef.current.get(searchKey('name', text))")
4557
4701
  assert.equal(effects.length, 2)
4558
- const contentStart = effects[1].indexOf("var cached = searchCacheRef.current.get('content:' + text)")
4702
+ const contentStart = effects[1].indexOf("var cached = searchCacheRef.current.get(searchKey('content', text))")
4559
4703
  assert.ok(contentStart !== -1)
4560
4704
  assert.match(effects[1].slice(contentStart, contentStart + 5000), /\}, \[treeQuery, cwd, searchReload\]\)/)
4561
4705
 
@@ -4636,6 +4780,34 @@ test('trimLargeTextFront frees whole lines and keeps the line count aligned', ()
4636
4780
  assert.deepEqual(T.trimLargeTextFront('', 100), { text: '', droppedLines: 0, droppedChars: 0 })
4637
4781
  })
4638
4782
 
4783
+ test('hovering a tree row paints a faint background that stays below the selection', async () => {
4784
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4785
+ // m09634: the row, not just its label, gets a light grey wash. A background
4786
+ // changes no metrics, so nothing moves; and since selected rows paint their tint
4787
+ // INLINE (S.treeRowOn / treeRowMulti), the stylesheet hover can never outrank them.
4788
+ const css = source.slice(source.indexOf('var TREE_HOVER_CSS'), source.indexOf('var SEARCH_PANEL_CSS'))
4789
+ assert.match(css, /\[data-tree-path\]:hover/)
4790
+ assert.match(css, /background:color-mix\(in srgb, currentColor 7%, transparent\)/, 'a faint grey wash')
4791
+ assert.doesNotMatch(css, /padding|margin|line-height|min-height|font-size|height:/, 'no metric changes: the tree must not jump')
4792
+ assert.match(source, /treeRowOn: \{[^}]*background: 'color-mix\(in srgb, currentColor 12%, transparent\)'/, 'the selected tint is an inline style (wins over hover)')
4793
+ assert.match(source, /treeRowMulti: \{[^}]*background:/, 'multi-selection tint too')
4794
+ assert.match(source, /PROGRAM_LOADING_CSS \+ TREE_HOVER_CSS/, 'injected with the panel styles')
4795
+ })
4796
+
4797
+ test('the embedded editor answers the maintenance page about unsaved buffers (m10900)', async () => {
4798
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4799
+ // The daemon's maintenance page embeds this window cross-origin and reloads
4800
+ // itself on updates; it cannot read `docs`. It asks over postMessage, and only
4801
+ // the immediate parent plus the two named shapes are served.
4802
+ assert.match(source, /event\.source !== window\.parent/, 'only the embedding parent is served')
4803
+ assert.match(source, /'dsh-ris-ide:probe-dirty'/, 'it answers the dirty probe')
4804
+ assert.match(source, /'dsh-ris-ide:dirty-report'/, 'with a named report')
4805
+ assert.match(source, /'dsh-ris-ide:save-all'/, 'it can save every dirty buffer on request')
4806
+ assert.match(source, /'dsh-ris-ide:save-all-done'/, 'and reports whether the save succeeded')
4807
+ assert.match(source, /window\.parent\.postMessage\(payload, '\*'\)/, 'the reply goes to the parent')
4808
+ assert.match(source, /saveBulk\(pending\)/, 'the save-all reuses the bulk save path')
4809
+ })
4810
+
4639
4811
  test('the editor scrollbars are visible and a start re-reads its log', async () => {
4640
4812
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4641
4813
  // BUG3: the host theme paints a 5px near-invisible scrollbar; the panel gives
@@ -4785,11 +4957,11 @@ test('search hits survive a pick and the shortcut selects the query', async () =
4785
4957
  const pick = source.slice(source.indexOf('function pickSearchHit('), source.indexOf('function openContentHit('))
4786
4958
  assert.doesNotMatch(pick, /setTreeQuery\(''\)/, 'the query stays after a pick')
4787
4959
  assert.doesNotMatch(pick, /setSearchHits\(null\)/, 'the result set stays after a pick')
4788
- const contentPick = source.slice(source.indexOf('function openContentHit('), source.indexOf('var runningSignature'))
4960
+ const contentPick = source.slice(source.indexOf('function openContentHit('), source.indexOf('// No auto-pick on first load'))
4789
4961
  assert.doesNotMatch(contentPick, /setTreeQuery\(''\)/, 'a content pick keeps the query too')
4790
- // Both searches cache their payloads keyed by the query text.
4791
- assert.match(source, /searchCacheRef\.current\.get\('name:' \+ text\)/)
4792
- assert.match(source, /rememberSearchEntry\(searchCacheRef\.current, 'content:' \+ text/)
4962
+ // Both searches cache their payloads keyed by kind + workspace + query.
4963
+ assert.match(source, /searchCacheRef\.current\.get\(searchKey\('name', text\)\)/)
4964
+ assert.match(source, /rememberSearchEntry\(searchCacheRef\.current, searchKey\('content', text\)/)
4793
4965
  // The shortcut focuses THROUGH an effect so select() survives the repaint.
4794
4966
  assert.match(source, /searchFocusPendingRef\.current = true/)
4795
4967
  // The dropdown is focus-owned: a pick blurs the box, so re-clicking it fires
@@ -4950,156 +5122,36 @@ test('a folder row only expands; the context menu\'s 进入 re-roots with an 上
4950
5122
  assert.match(region, /walk\(activeRoot, 0, \{\}\)/, 'Ctrl+A walks the active root')
4951
5123
  })
4952
5124
 
4953
- // ── proxy dialog: both consoles offer it, and it renders standalone ──────────
4954
- test('the console title bar carries the proxy button', { skip: !reactIsReal }, () => {
4955
- const { renderToStaticMarkup } = require(`${REACT_ROOT}/react-dom/server`)
4956
- const markup = renderToStaticMarkup(React.createElement(T.ProgramsPanel, { sessionId: 's1', cwd: '/w/project', visible: true, compact: true }))
4957
- assert.match(markup, /data-action="compact-proxy"/, 'the sidebar console opens the proxy dialog')
4958
- })
4959
-
4960
- test('the proxy dialog mounts with its address section and actions', { skip: !reactIsReal }, () => {
4961
- const { renderToStaticMarkup } = require(`${REACT_ROOT}/react-dom/server`)
4962
- const markup = renderToStaticMarkup(React.createElement(T.ProxyDialog, { scope: { sessionId: 's1', cwd: '/w/project' }, onClose: () => {} }))
4963
- assert.match(markup, /data-proxy-dialog="1"/, 'the overlay is rendered')
4964
- assert.match(markup, /data-proxy-close="1"/)
4965
- // SSR runs no effect, so the form is still loading — the shell must exist anyway.
4966
- assert.match(markup, /读取中/)
5125
+ // ── the old in-panel proxy dialog is gone; the risd page owns the rules ──
5126
+ test('the console keeps its log pane empty until a row is chosen (m07431)', async () => {
5127
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
5128
+ // First load used to pick the first running service and load its log, which
5129
+ // located/opened a file nobody asked for. A click on a row is the only way in.
5130
+ assert.match(source, /\/\/ No auto-pick on first load \(m07431\)/)
5131
+ assert.equal(source.includes('First load with no explicit target'), false)
4967
5132
  })
4968
5133
 
4969
- test('the proxy dialog has no per-row launch or mapping switch', async () => {
5134
+ test('no ProxyDialog component is shipped any more (m07355 / D4)', async () => {
4970
5135
  const { readFile } = await import('node:fs/promises')
4971
5136
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4972
- // Launching programs from the dialog was dropped: ProxyBridge intercepts by
4973
- // process name, so a program started anywhere is covered and a ▶ button only
4974
- // ever covered the one instance we spawned.
4975
- assert.equal(source.includes('data-proxy-run'), false, 'no row-level start button')
4976
- assert.equal(source.includes('runButton('), false, 'the button builder is gone')
4977
- // The mapping is decided by the program's capabilities, not by a checkbox: the
4978
- // row reports the outcome instead.
4979
- assert.equal(source.includes('checked: rule.shadow'), false, 'no mapping checkbox bound to the rule')
4980
- assert.ok(source.includes("'data-proxy-map'"), 'the row still reports the mapping')
4981
- assert.ok(source.includes("? '127.0.0.1' + portSuffix(rule)"), 'and names where it landed')
4982
- // The state is machine-wide, so the row label is provenance, not a boundary.
4983
- assert.ok(source.includes("'来源 '"))
4984
- assert.ok(source.includes('data-proxy-redirector'), 'ProxyBridge block exists in the dialog')
4985
- })
4986
-
4987
- test('an adopted leftover engine is reported with a stop action', async () => {
4988
- const { readFile } = await import('node:fs/promises')
5137
+ assert.equal(source.includes('function ProxyDialog('), false, 'the old panel component is deleted')
5138
+ assert.equal(source.includes('ProxyDialog: ProxyDialog'), false, 'it is no longer exported')
5139
+ assert.equal(source.includes("'data-proxy-dialog'"), false, 'no markup keeps the old dialog addressable')
5140
+ // The page itself is served by the daemon: /ui owns the rule editor now.
5141
+ assert.ok(source.includes("routeUrl('dsh-ris-ide/proxy')"), 'the entry still asks the host where the page is')
5142
+ })
5143
+
5144
+ test('the workbench reads its saved blob once per mount and remounts per workspace', async () => {
4989
5145
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4990
- const region = source.slice(source.indexOf('function ProxyDialog('), source.indexOf('function viewerFontCss('))
4991
- // A previous dsh left its engine behind (the pre-fix Ctrl+C leak). The host adopts
4992
- // it so the tunnel keeps working, and the dialog must say who started it instead
4993
- // of pretending this session did — plus a stop that does not touch the rule table.
4994
- assert.match(region, /view\.inherited === true/, 'the banner is driven by the host flag')
4995
- assert.match(region, /'data-proxy-inherited': '1'/, 'the banner is addressable in the DOM')
4996
- assert.match(region, /原 dsh pid/, 'it names the dsh that started the engine')
4997
- assert.match(region, /action: 'stop-inherited',/, 'it offers its own action id')
4998
- assert.match(region, /onClick: function \(\) \{ act\('stop'\) \}/, 'the stop goes through the normal action path')
4999
- })
5000
-
5001
- test('auto-save is versioned, flushed before it can be lost, and the host decides "applies"', () => {
5002
- const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
5003
- // C-M1: the whole table is posted, so the payload names the table it came from.
5004
- // Without that, two windows save and the loser's row disappears without an error.
5005
- assert.ok(source.includes('revision: revisionRef.current'), 'the save names its base table')
5006
- assert.ok(source.includes("answer.status === 409 && payload.conflict === true"), 'a stale save is detected')
5007
- assert.ok(source.includes('规则表已在别处被修改,已重新载入(本次改动未写入)'), 'and reported in words')
5008
- // C-M2: a 700 ms debounce is a window in which an edit exists only in memory; both
5009
- // paths that reload the view must write it out first.
5010
- assert.ok(source.includes('function flushSave()'), 'there is a flush')
5011
- assert.ok(source.includes('flushSave().catch(function () {}).then(function () { actNow(action, ruleId, side) })'),
5012
- 'start/stop writes the pending edit first')
5013
- assert.ok(source.includes('flushSave().catch(function () {}).then(function () { onClose() })'),
5014
- 'closing the dialog writes the pending edit first')
5015
- // C-M3: local parsing is a preview; once the host has seen the exact row, its
5016
- // verdict wins, so the form cannot claim a row applies when the engine skipped it.
5017
- assert.ok(source.includes('function hostVerdictFor(rule)'), 'the host verdict is looked up')
5018
- assert.ok(source.includes('var hostRow = hostVerdictFor(rule)'), 'and used by the row')
5019
- // P2: the placeholder used to promise the opposite of what the engine does.
5020
- assert.equal(source.includes('(空=不限)'), false, 'no placeholder advertises the old meaning')
5021
- assert.ok(source.includes('(全部写 *;空=本行不生效)'))
5022
- })
5023
-
5024
- test('the program cell is typed, and the picker offers three tabs and one tree', () => {
5025
- const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
5026
- // Typing `java` (any path) or `D:\…\java.exe` (exact) is the primary way to set a
5027
- // rule; the picker is a helper, not the only door.
5028
- assert.ok(source.includes("'data-proxy-program': rule.id"))
5029
- assert.ok(source.includes("placeholder: '程序名或路径:java / D:\\\\…\\\\java.exe'"))
5030
- assert.ok(source.includes("'data-proxy-pick': rule.id"))
5031
- // Exactly two tabs: running processes, and ONE file tree. On WSL the Windows
5032
- // disks are ordinary folders under /mnt, so a separate "Windows 文件" tab would
5033
- // be the same tree with another spelling.
5034
- assert.ok(source.includes("tabButton('running', '运行中的程序')"))
5035
- assert.ok(source.includes("tabButton('local', '选择文件')"))
5036
- assert.equal(source.includes("tabButton('windows'"), false, 'one file tree, not two')
5037
- // `/` is prepended client-side too: the roots list comes from the host half,
5038
- // which only reloads with dsh web, and a refresh must not drop the entry that
5039
- // reaches every path.
5040
- assert.ok(source.includes('function withFilesystemRoot(roots, posix)'))
5041
- assert.ok(source.includes('withFilesystemRoot(tree.roots, hostIsPosix)'))
5042
- // …and the shortcuts in front of it are dropped, so the first thing the user sees
5043
- // is the start of the filesystem, not a pile of convenience roots.
5044
- assert.ok(source.includes("root.path === '/' || /^\\/mnt\\/[A-Za-z](\\/|$)/.test(root.path)"))
5045
- // A pick under /mnt is written as a Windows path: that is the spelling the
5046
- // program's own OS uses, and what a Windows-side interceptor matches.
5047
- assert.ok(source.includes('function pickedPath(value)'))
5048
- assert.ok(source.includes('program: pickedPath(value)'))
5049
- assert.ok(source.includes("url.searchParams.set('side', side)"))
5050
- // The picker is a dialog of its own, opened from the row: a two-root tree does
5051
- // not fit in a rule row.
5052
- assert.ok(source.includes("'data-proxy-picker-dialog': '1'"), 'the picker renders as a nested dialog')
5053
- assert.ok(source.includes('void loadPrograms()'), 'the process list is fetched when the picker opens')
5054
- // Expanding a folder must grow the tree IN PLACE — no "enter directory" stepping,
5055
- // no breadcrumb, and no re-reading what is already on screen.
5056
- assert.ok(source.includes('data-proxy-tree-dir'), 'folders are rows in the tree')
5057
- assert.ok(source.includes('data-proxy-tree-file'), 'files are rows in the tree')
5058
- assert.ok(source.includes('function toggleDir(dir)'), 'a folder toggles instead of navigating')
5059
- assert.ok(source.includes("if (open !== true && tree.nodes[key] === undefined) void loadTreeDir(key)"),
5060
- 'a folder is read the first time it is expanded')
5061
- assert.equal(source.includes("'data-proxy-browse-up'"), false, 'the stepwise browser is gone')
5062
- // The program cell is typed, the picker is a helper: choosing a file must call
5063
- // the chooser that belongs to the dialog (passing it into the tree, not closing
5064
- // over a name that is not in scope).
5065
- assert.ok(source.includes('function dirRow(dir, depth, chooser)'), 'the tree rows take the chooser')
5066
- assert.ok(source.includes('rows = rows.concat(treeRows(dir.path, depth + 1, chooser))'))
5067
- assert.ok(source.includes('rows = rows.concat(dirRow(dir, depth, chooser))'))
5068
- // A file is not a folder: it gets no caret in that slot (only a placeholder span),
5069
- // otherwise the arrow reads as "expand me" on something that cannot expand.
5070
- assert.equal(source.includes("'▶ ' + file.name"), false, 'no caret in front of files')
5071
- assert.ok(source.includes("h('span', null, '📄 ' + file.name)"))
5072
- // A folder whose listing came back empty is a leaf: caret becomes `·`, no click.
5073
- assert.ok(source.includes("'data-proxy-tree-leaf': leaf ? '1' : '0'"))
5074
- assert.ok(source.includes("leaf ? '·' : open ? '▾' : '▸'"))
5075
- // The old "choose from list only" button is gone.
5076
- assert.equal(source.includes("rule.program === '' ? '选择程序…'"), false)
5077
- })
5078
-
5079
- test('edits save themselves, and adding a row adds a row', () => {
5080
- const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
5081
- // No 保存 button: every edit is written 700ms after the last keystroke, so a
5082
- // half-typed IP never becomes a half-written rule on disk.
5083
- assert.equal(source.includes("action: 'save'"), false, 'the save button is gone')
5084
- assert.ok(source.includes('function draftSignature(draft)'))
5085
- assert.ok(source.includes('savedSignature.current = draftSignature(draft)'),
5086
- 'what the host confirmed is remembered, so a reload is not an edit')
5087
- // The timer lives in a ref so a button press or a close can flush it first.
5088
- assert.ok(source.includes('saveTimer.current = setTimeout(function () { saveTimer.current = null; void save() }, 700)'))
5089
- assert.ok(source.includes('data-proxy-autosave'))
5090
- // Half-typed rows are not written: auto-save fires mid-typing, and a rule with no
5091
- // program/ip/port would come back as a row that silently does nothing.
5092
- assert.ok(source.includes('function storableRule(rule)'))
5093
- assert.ok(source.includes('var mode = writeMode(rule)'))
5094
- assert.ok(source.includes("if (storable.length === 0 && skipped > 0)"),
5095
- 'never blank the file while every row is still being typed')
5096
- // A row that is already on disk must not silently keep its OLD content when it is
5097
- // edited into an incomplete state: it is written as disabled instead.
5098
- assert.ok(source.includes('function writeMode(rule)'))
5099
- assert.ok(source.includes("return savedIds.current[rule.id] === true ? 'disable' : 'skip'"))
5100
- assert.ok(source.includes("storable.push(Object.assign({}, rule, { enabled: false }))"))
5101
- assert.ok(source.includes('savedIds.current = ids'))
5102
- // "+ 添加规则" appends an empty row and does NOT pop the picker over the table.
5103
- const addRule = source.slice(source.indexOf('function addRule()'), source.indexOf('function addRule()') + 900)
5104
- assert.equal(addRule.includes('pickFor'), false, 'adding a row must not open the picker')
5146
+ // One read per mount, from a lazy useState initialiser: readSavedUi also runs
5147
+ // the one-shot legacy migration (it removes the adopted key), so calling it on
5148
+ // every render re-probed localStorage per keystroke.
5149
+ assert.match(source, /var \[savedUi\] = useState\(function \(\) \{ return readSavedUi\(storageKey, workspaceKey\) \}\)/)
5150
+ assert.doesNotMatch(source, /var savedUi = readSavedUi\(storageKey, workspaceKey\)/)
5151
+ // Tabs/recent/layout are seeded from that blob at mount, so a workspace switch
5152
+ // must remount the workbench instead of keeping the previous workspace's state.
5153
+ const mount = source.slice(source.indexOf('return h(ProgramWorkbench, {'), source.indexOf('return h(ProgramWorkbench, {') + 600)
5154
+ assert.match(mount, /key: typeof cwd === 'string' && cwd !== '' \? cwd : 'default'/)
5155
+ // The compact panel layout is a machine-wide preference on purpose.
5156
+ assert.match(source, /Deliberately NOT workspace-scoped/)
5105
5157
  })