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
@@ -205,10 +205,13 @@ export function saveProxy(state, { cwd, config, revision, gitHost } = {}) {
205
205
  }
206
206
 
207
207
  /** Run one of the three-layer actions (engine + bridge + git) in the daemon. */
208
- export function proxyAction(state, { cwd, action, gitHost, ruleId } = {}) {
208
+ export function proxyAction(state, { cwd, action, gitHost, ruleId, interactive } = {}) {
209
209
  const body = { cwd, action }
210
210
  if (typeof gitHost === 'string' && gitHost !== '') body.gitHost = gitHost
211
211
  if (typeof ruleId === 'string' && ruleId !== '') body.ruleId = ruleId
212
+ // Only an explicit click sets this: a password dialog must never be a side
213
+ // effect of saving rules or of dsh starting (m13910).
214
+ if (interactive === true) body.interactive = true
212
215
  return risdRequest(state, '/v1/action', { method: 'POST', body })
213
216
  }
214
217
 
package/lib/startup.js CHANGED
@@ -14,7 +14,7 @@
14
14
  // @module dsh-ris-ide/startup
15
15
  import { existsSync, rmSync } from 'node:fs'
16
16
  import { proxyPid, proxyPidPath, proxyStatus, readProxyConfig } from './proxy.js'
17
- import { reloadFailedPath, readWindowsServiceState, redirectorStatusCached, restoreWindowsService } from './redirector.js'
17
+ import { clearWindowsServiceState, reloadFailedPath, readWindowsServiceState, redirectorStatusCached, restoreWindowsService } from './redirector.js'
18
18
  import { clearGitProxy, enabledGitRuleHost, readGitProxyState, syncGitProxy } from './risd/git.js'
19
19
  import { readRisdState, removeRisdState } from './risd/state.js'
20
20
  import { risdHealth } from './risd-client.js'
@@ -22,11 +22,27 @@ import { risdHealth } from './risd-client.js'
22
22
  /**
23
23
  * Bring the machine back in line with the current rules.
24
24
  *
25
- * @param {{cwd?: string, log?: (message: string) => void}} [options] - workspace
26
- * hint (only used to resolve legacy paths) and a logger.
25
+ * @param {object} [options] - workspace hint (legacy paths), a logger, and the two
26
+ * bridge probes. The probes are injectable on purpose: `redirectorStatusCached()`
27
+ * shells out to PowerShell on WSL/Windows (seconds, and only accurate while the
28
+ * probe of the moment answers) and `restoreWindowsService()` really runs
29
+ * `Set-Service`/`Start-Service`. A test that called them directly was (a) slow,
30
+ * (b) flaky — a bridge that happened to be running silently changed the branch —
31
+ * and (c) able to restart the developer's own ProxyBridgeSvc.
32
+ * @param {string} [options.cwd] - workspace hint, only used to resolve legacy paths.
33
+ * @param {(message: string) => void} [options.log] - logger.
34
+ * @param {() => {running?: boolean}} [options.status] - bridge status probe.
35
+ * @param {() => {restored?: boolean, reason?: string}} [options.restore] - service restore.
36
+ * @param {number|null} [options.ownPid] - this process, so its own state is never removed.
27
37
  * @returns {Promise<{ok: boolean, notes: string[]}>} what was cleaned (empty = clean).
28
38
  */
29
- export async function reconcileStartupLeftovers({ cwd = '', log = () => {}, ownPid = null } = {}) {
39
+ export async function reconcileStartupLeftovers({
40
+ cwd = '',
41
+ log = () => {},
42
+ ownPid = null,
43
+ status = redirectorStatusCached,
44
+ restore = restoreWindowsService,
45
+ } = {}) {
30
46
  const notes = []
31
47
  const note = (message) => {
32
48
  notes.push(message)
@@ -85,15 +101,19 @@ export async function reconcileStartupLeftovers({ cwd = '', log = () => {}, ownP
85
101
 
86
102
  // A reload failure marker from the previous run describes a bridge that is not
87
103
  // running any more; keeping it makes the panel warn about nothing.
88
- if (existsSync(reloadFailedPath()) && redirectorStatusCached().running !== true) {
104
+ if (existsSync(reloadFailedPath()) && status().running !== true) {
89
105
  rmSync(reloadFailedPath(), { force: true })
90
106
  note('清掉了上次遗留的桥接重载失败标记')
91
107
  }
92
108
 
93
109
  const serviceState = readWindowsServiceState()
94
110
  if (serviceState !== null && serviceState.stoppedByUs === true) {
95
- if (redirectorStatusCached().running !== true) {
96
- const restored = restoreWindowsService()
111
+ if (status().running !== true) {
112
+ const restored = restore()
113
+ // `restoreWindowsService()` clears the record itself; with an injected
114
+ // `restore` (tests) nothing would, so clear here too — the record describes a
115
+ // service that is no longer parked either way.
116
+ if (restored.restored === true) clearWindowsServiceState()
97
117
  note(restored.restored === true
98
118
  ? '已恢复上次被停用的 ProxyBridgeSvc'
99
119
  : `ProxyBridgeSvc 未能自动恢复:${restored.reason ?? '未知原因'}(可手动把启动类型改回 Automatic)`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ris-ide",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "license": "MIT",
5
5
  "description": "RIS-IDE local dev panel for the DSH web GUI: live log tail, one-click start/stop of workspace programs, JDWP debugging, file tree + editor, and a standalone IDE window that carries no session history. · DSH 右侧栏本地开发面板:日志实时跟随、一键启停本地程序、Java 断点调试、文件树与编辑器、独立 IDE 窗口。",
6
6
  "keywords": [
@@ -75,7 +75,7 @@
75
75
  }
76
76
  },
77
77
  "scripts": {
78
- "test": "node --test \"test/*.test.mjs\"",
78
+ "test": "node --test --test-timeout=120000 \"test/*.test.mjs\"",
79
79
  "build": "tsdown --config tsdown.config.mjs",
80
80
  "check:listing": "node bin/check-listing.mjs"
81
81
  },
@@ -20,6 +20,7 @@ import { join } from 'node:path'
20
20
  import { fileURLToPath } from 'node:url'
21
21
 
22
22
  import { __test as hostTest } from '../lib/index.js'
23
+ import { HAS_GIT, skipWithout } from './helpers/cmd.mjs'
23
24
 
24
25
  const require = createRequire(import.meta.url)
25
26
  const ROOT = fileURLToPath(new URL('..', import.meta.url))
@@ -189,7 +190,7 @@ test('one proxy control governs engine, interception and git together', async ()
189
190
  const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
190
191
  // Start/stop drive all three layers, and so does the host exit hook. The UI that
191
192
  // used to say so lives on the risd page now (the panel dialog is deleted).
192
- assert.ok(host.includes('const redirector = await startRedirectors()'), 'start brings the interception up')
193
+ assert.ok(host.includes('const redirector = await startRedirectors({ interactive })'), 'start brings the interception up (a local fallback keeps the click interactive)')
193
194
  assert.ok(host.includes('syncGitProxy({ cwd, host: gitHost, enabled: true })'), 'start writes the git entry')
194
195
  assert.ok(host.includes('syncGitProxy({ cwd, host: gitHost, enabled: false })'), 'stop clears the git entry')
195
196
  assert.ok(host.includes('const redirector = await stopRedirector()'), 'stop brings the interception down')
@@ -218,7 +219,7 @@ test('the console follows the live sidebar session, not the one it opened in', a
218
219
  'the chrome stack must match what the IDE theme resolves to, not a mono list')
219
220
  })
220
221
 
221
- test('only invisible outcomes and failures raise a toast', async () => {
222
+ test('only invisible outcomes and failures raise a toast, and progress goes to the status bar', async () => {
222
223
  const { readFile } = await import('node:fs/promises')
223
224
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
224
225
  // Visible-in-the-UI successes stay silent: the row/tab/marker already changed.
@@ -242,6 +243,20 @@ test('only invisible outcomes and failures raise a toast', async () => {
242
243
  assert.ok(source.includes("'已复制 ' : '已剪切 '"), 'clipboard state is invisible: keep it')
243
244
  assert.equal(source.includes('data-tree-clipboard'), false, 'no clipboard strip above the tree')
244
245
  assert.ok(source.includes('已移到回收站'))
246
+ // The sidebar console's success notes are gone too (its row settles in place);
247
+ // failures still say which action failed.
248
+ assert.doesNotMatch(source, /program\.name \+ ' 已(启动|重启|停止)'/, 'no success note in the sidebar console')
249
+ assert.doesNotMatch(source, /program\.name \+ ' 已在运行'/, 'already-running stays silent too')
250
+ assert.match(source, /'启动失败:' : kind === 'restart' \? '重启失败:' : '停止失败:'/, 'failures still surface')
251
+ // Progress lives in a status channel of its own, not in a toast; the static
252
+ // bottom shortcut hint moved into the ? panel.
253
+ assert.ok(!source.includes('Ctrl+S 保存 · Ctrl+W 关页签 · 拖分隔条调大小 · 双击标题最大化'))
254
+ assert.ok(!source.includes("' · F5 步入 · F6 单步 · F7 步出 · F8 继续'"))
255
+ assert.ok(source.includes("var [statusText, setStatusText] = useState('')"))
256
+ assert.ok(source.includes("statusNote('正在获取依赖源码:' + cleaned + '…', 0)"))
257
+ assert.ok(source.includes("statusNote('正在启动 ' + program.name + '…', 0)"))
258
+ assert.ok(!source.includes("note('正在获取依赖源码:"))
259
+ assert.ok(source.includes("'data-ide-status-text': statusText === '' ? '0' : '1'"))
245
260
  })
246
261
 
247
262
  test('the tab dropdown lists open files then recent history, capped at 30', () => {
@@ -317,19 +332,6 @@ test('bulk close separates victims from the dirty ones it must ask about', () =>
317
332
  assert.deepEqual(T.bulkClosePlan([], undefined, dirty, false), { victims: [], dirty: [] })
318
333
  })
319
334
 
320
- test('the editor surfaces the batch-close prompt and the tab dropdown', async () => {
321
- const { readFile } = await import('node:fs/promises')
322
- const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
323
- for (const action of ['bulk-save-close', 'bulk-discard-close', 'bulk-cancel-close', 'tabs-menu']) {
324
- assert.ok(source.includes(`'data-action': '${action}'`), `${action} is wired`)
325
- }
326
- assert.match(source, /'data-bulk-prompt': '1'/)
327
- assert.match(source, /'data-tabs-menu': '1'/)
328
- assert.match(source, /recent: recentFiles/, 'the history survives a reload')
329
- assert.match(source, /'data-search-history': '1'/, 'the empty search box shows the history')
330
- assert.match(source, /'data-search-history-row': row.path/)
331
- })
332
-
333
335
  test('the bundle registers under the package name and exports a cordis plugin', () => {
334
336
  assert.equal(registration.id, 'dsh-ris-ide')
335
337
  assert.equal(client.name, 'dsh-ris-ide')
@@ -385,27 +387,70 @@ test('the compact panel is console rows plus a resizable 240px log pane', () =>
385
387
  }
386
388
  })
387
389
 
388
- test('the compact panel remembers which section is maximized', () => {
389
- assert.equal(T.readCompactMax(), '', 'nothing saved yet: the split view')
390
- const storage = {
391
- getItem: (key) => (key === T.COMPACT_MAX_KEY ? 'log' : null),
392
- setItem: () => {},
393
- }
390
+ test('each session remembers ITS workspace; the origin-wide slot stays separate (m04873)', () => {
391
+ // One slot shared by every document on the origin made the sidebar console and
392
+ // the IDE console drag each other to whichever workspace was remembered last.
393
+ const map = new Map()
394
394
  const previous = globalThis.window.localStorage
395
- globalThis.window.localStorage = storage
395
+ globalThis.window.localStorage = {
396
+ getItem: (key) => (map.has(key) ? map.get(key) : null),
397
+ setItem: (key, value) => { map.set(key, value) },
398
+ }
396
399
  try {
397
- assert.equal(T.readCompactMax(), 'log', 'the maximized log is remembered')
398
- storage.getItem = () => 'console'
399
- assert.equal(T.readCompactMax(), 'console')
400
- storage.getItem = () => 'editor'
401
- assert.equal(T.readCompactMax(), '', 'an unknown section degrades to the split view')
402
- storage.getItem = () => 'not-json'
403
- assert.equal(T.readCompactMax(), '')
400
+ T.rememberSessionCwd('/work/a', 'session-a')
401
+ T.rememberSessionCwd('/work/b', 'session-b')
402
+ assert.equal(T.knownSessionCwd('session-a'), '/work/a')
403
+ assert.equal(T.knownSessionCwd('session-b'), '/work/b')
404
+ assert.equal(map.get(T.SESSION_CWD_PREFIX + 'session-a'), '/work/a', 'keyed by session')
405
+ // The origin-wide slot is written by the panels too, but reading it as a
406
+ // SESSION's workspace is exactly the cross-talk this fixes.
407
+ T.rememberWorkspaceCwd('/work/b')
408
+ assert.equal(T.knownWorkspaceCwd(), '/work/b')
409
+ assert.equal(T.knownSessionCwd('session-a'), '/work/a', 'a session keeps its own answer')
410
+ // Garbage never lands: relative paths and missing session ids are ignored.
411
+ T.rememberSessionCwd('relative/path', 'session-a')
412
+ T.rememberSessionCwd('/work/c', '')
413
+ assert.equal(T.knownSessionCwd('session-a'), '/work/a')
414
+ assert.equal(T.knownSessionCwd(''), undefined)
415
+ assert.equal(T.knownSessionCwd(undefined), undefined)
404
416
  } finally {
405
417
  globalThis.window.localStorage = previous
406
418
  }
407
419
  })
408
420
 
421
+ test('a panel never steers the host with a GUESSED workspace (m04873)', () => {
422
+ const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
423
+ // The console resolves its workspace from the session store or from what the host
424
+ // answered for THIS session; the origin-wide last-cwd slot is not an input.
425
+ assert.match(source, /var sessionCwd = knownSessionCwd\(sessionId\)/)
426
+ assert.match(source, /if \(cwdKnown === true && typeof cwd === 'string' && cwd !== ''\) url\.searchParams\.set\('cwd', cwd\)/)
427
+ assert.match(source, /rememberSessionCwd\(payload\.root, sessionId\)/)
428
+ // The standalone IDE window is pinned to the workspace in its URL, so a hello
429
+ // that resolved to another workspace cannot move its console.
430
+ assert.match(source, /payload\.root !== props\.cwd\) return/)
431
+ // A log pane follows its own scope, never the origin-wide slot.
432
+ assert.match(source, /var scopedCwd = knownSessionCwd\(sessionId\)/)
433
+ })
434
+
435
+ test('the compact panel does NOT remember which section was maximized (m00584)', () => {
436
+ // A persisted ⤢ used to hide the other section on every reopen, with nothing on
437
+ // screen explaining where it went, so the maximize mode became view state only.
438
+ assert.equal(T.readCompactMax, undefined, 'the stored mode is no longer read at all')
439
+ assert.equal(T.COMPACT_MAX_KEY, undefined, 'and the machine-wide key is gone')
440
+ if (!reactIsReal) return
441
+ const previous = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage') ? globalThis.localStorage : undefined
442
+ globalThis.localStorage = { getItem: () => 'log', setItem: () => {} }
443
+ try {
444
+ const { renderToStaticMarkup } = require(`${REACT_ROOT}/react-dom/server`)
445
+ const markup = renderToStaticMarkup(React.createElement(T.ProgramsPanel, { sessionId: 's1', cwd: '/w', visible: true, compact: true }))
446
+ assert.match(markup, /data-action="compact-max-console"/, 'a stored "log" still leaves both sections on screen')
447
+ assert.match(markup, /data-action="compact-max-log"/)
448
+ } finally {
449
+ if (previous === undefined) delete globalThis.localStorage
450
+ else globalThis.localStorage = previous
451
+ }
452
+ })
453
+
409
454
  test('the compact shape renders the console and the IDE-window button, not the full workbench', { skip: !reactIsReal }, () => {
410
455
  const { renderToStaticMarkup } = require(`${REACT_ROOT}/react-dom/server`)
411
456
  const markup = renderToStaticMarkup(React.createElement(T.ProgramsPanel, { sessionId: 's1', cwd: '/w/project', visible: true, compact: true }))
@@ -1891,7 +1936,7 @@ test('destructive file operations offer an inline undo and never strand focus',
1891
1936
  assert.match(source, /'data-tree-confirm-cancel': '1'/)
1892
1937
  })
1893
1938
 
1894
- test('the recent-file dropdown is walkable like the result list', async () => {
1939
+ test('the recent-file dropdown is walkable like the result list, and the tab/batch menus are wired', async () => {
1895
1940
  const { readFile } = await import('node:fs/promises')
1896
1941
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1897
1942
  // One highlighted index drives both dropdowns.
@@ -1905,6 +1950,16 @@ test('the recent-file dropdown is walkable like the result list', async () => {
1905
1950
  assert.match(source, /'data-search-history-active': on \? '1' : '0'/)
1906
1951
  assert.match(source, /onMouseEnter: function \(\) \{ setSearchActive\(index\) \}/)
1907
1952
  assert.match(source, /最近打开 · ' \+ searchHistoryRows\.length \+ ' 个(↑↓ 选择,Enter 打开)/)
1953
+ // The same menu machinery drives the tab dropdown and the batch-close prompt
1954
+ // (the batch bar's buttons are only reachable from that menu).
1955
+ for (const action of ['bulk-save-close', 'bulk-discard-close', 'bulk-cancel-close', 'tabs-menu']) {
1956
+ assert.ok(source.includes(`'data-action': '${action}'`), `${action} is wired`)
1957
+ }
1958
+ assert.match(source, /'data-bulk-prompt': '1'/)
1959
+ assert.match(source, /'data-tabs-menu': '1'/)
1960
+ assert.match(source, /'data-search-history': '1'/, 'the empty search box shows the history')
1961
+ assert.match(source, /'data-search-history-row': row.path/)
1962
+ assert.match(source, /recent: recentFiles/, 'the history survives a reload')
1908
1963
  })
1909
1964
 
1910
1965
  test('renaming a file or folder keeps tabs, drafts and history pointing at it', async () => {
@@ -2113,6 +2168,77 @@ test('the tree mutations post JSON to the fs op routes', async () => {
2113
2168
  }
2114
2169
  })
2115
2170
 
2171
+ test('an outside-workspace refusal re-reads the live session and retries once (m00220)', async () => {
2172
+ const posts = []
2173
+ const original = globalThis.fetch
2174
+ globalThis.fetch = async (url, init) => {
2175
+ const href = String(url)
2176
+ // The window that kept the Session it booted on asks the host which Session
2177
+ // owns the workspace it shows.
2178
+ if (href.includes('/dsh-ris-ide/windows')) {
2179
+ return { ok: true, status: 200, json: async () => ({ ok: true, windows: [], session: { id: 's-live' } }) }
2180
+ }
2181
+ posts.push({ url: href, body: JSON.parse(init.body) })
2182
+ if (posts.length === 1) {
2183
+ return { ok: false, status: 403, json: async () => ({ ok: false, code: 'outside-workspace', message: '不能对工作区之外的路径执行新建文件夹' }) }
2184
+ }
2185
+ return { ok: true, status: 200, json: async () => ({ ok: true, path: '/w/newdir' }) }
2186
+ }
2187
+ try {
2188
+ const created = await T.fsMkdir({ sessionId: 's-stale', cwd: '/w' }, '/w/newdir')
2189
+ assert.equal(created.ok, true, 'the mutation succeeds instead of hitting the global error banner')
2190
+ assert.equal(posts.length, 2, 'exactly one retry')
2191
+ assert.equal(posts[0].body.sessionId, 's-stale')
2192
+ assert.equal(posts[1].body.sessionId, 's-live', 'the retry carries the host-live Session')
2193
+ assert.equal(posts[1].body.cwd, '/w', 'and the workspace the tree showed')
2194
+ } finally {
2195
+ globalThis.fetch = original
2196
+ }
2197
+ })
2198
+
2199
+ test('a refusal with nothing to heal surfaces with the host code, without a retry loop', async () => {
2200
+ const posts = []
2201
+ const original = globalThis.fetch
2202
+ globalThis.fetch = async (url, init) => {
2203
+ const href = String(url)
2204
+ if (href.includes('/dsh-ris-ide/windows')) {
2205
+ return { ok: true, status: 200, json: async () => ({ ok: true, windows: [], session: { id: 's1' } }) }
2206
+ }
2207
+ posts.push(href)
2208
+ return { ok: false, status: 403, json: async () => ({ ok: false, code: 'outside-workspace', message: '不能对工作区之外的路径执行删除' }) }
2209
+ }
2210
+ try {
2211
+ await assert.rejects(
2212
+ () => T.fsRemoveEntry({ sessionId: 's1', cwd: '/w' }, '/w/x', true),
2213
+ (error) => error.code === 'outside-workspace' && /不能对工作区之外的路径执行删除/.test(error.message),
2214
+ )
2215
+ assert.equal(posts.length, 1, 'the same Session is not asked twice')
2216
+ } finally {
2217
+ globalThis.fetch = original
2218
+ }
2219
+ })
2220
+
2221
+ test('the panel publishes its freshest scope for the retry', async () => {
2222
+ const { readFile } = await import('node:fs/promises')
2223
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2224
+ assert.match(source, /function setLiveScopeResolver\(resolver\)/, 'the page can register a live-scope reader')
2225
+ assert.match(source, /return function \(\) \{ setLiveScopeResolver\(null\) \}/, 'and clears it when the panel unmounts')
2226
+ assert.match(source, /var live = liveSidebarSessionId\(\)/, 'the reader asks the sidebar which Session is live')
2227
+ assert.match(source, /await liveSessionOfScope\(scope\)/, 'the retry can also ask the host')
2228
+ })
2229
+
2230
+ test('context-menu rows show the same faint hover background as the tree rows (m00220)', async () => {
2231
+ const { readFile } = await import('node:fs/promises')
2232
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2233
+ // `S.tabMenuItem` pins `background: transparent` inline, so the stylesheet needs
2234
+ // `!important` or every menu row keeps its flat look on hover.
2235
+ assert.match(source, /var MENU_HOVER_CSS = '\[data-workbench="ris-ide"\] \[data-ris-ide-menu\] button:hover:not\(:disabled\)'/)
2236
+ assert.match(source, /background:rgba\(0,0,0,0\.05\) !important/)
2237
+ assert.match(source, /\+ TREE_HOVER_CSS \+ MENU_HOVER_CSS\)/, 'the panel style sheet carries the rule')
2238
+ const marked = (source.match(/'data-ris-ide-menu': '1'/g) ?? []).length
2239
+ assert.ok(marked >= 5, `every menu container is marked (tree, flyout, tabs, tab, editor): ${marked}`)
2240
+ })
2241
+
2116
2242
  test('absolutePath resolves cwd-relative paths and keeps absolute ones', () => {
2117
2243
  assert.equal(T.absolutePath('/w', 'ris/a.java'), '/w/ris/a.java')
2118
2244
  assert.equal(T.absolutePath('/w/', 'ris/a.java'), '/w/ris/a.java')
@@ -2378,19 +2504,7 @@ test('a whole workbench console row picks the program, name and blank alike', as
2378
2504
  assert.match(source, /button\(ideBadgeIcon\('bug', 'play', 13\), function \(event\) \{ event\.stopPropagation\(\); void consoleDebug\(program\) \}/)
2379
2505
  })
2380
2506
 
2381
- test('sidebar start/stop/restart stay silent, and ⟳ is green like ▶', async () => {
2382
- const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2383
- // The sidebar row itself shows the settled state (dot + ▶/■ swap): successes
2384
- // must not push the list down with a "已启动" strip. Failures still do.
2385
- assert.doesNotMatch(source, /program\.name \+ ' 已(启动|重启|停止)'/, 'no success note in the sidebar console')
2386
- assert.doesNotMatch(source, /program\.name \+ ' 已在运行'/, 'already-running stays silent too')
2387
- assert.match(source, /'启动失败:' : kind === 'restart' \? '重启失败:' : '停止失败:'/, 'failures still surface')
2388
- // ⟳ (re)starts, so it shares ▶'s green in BOTH consoles; ■ keeps red.
2389
- assert.match(source, /S\.startIcon, disabled: busy, 'data-action': 'restart'/, 'sidebar ⟳ is green')
2390
- assert.match(source, /width: 25, start: true, action: 'console-restart'/, 'workbench ⟳ is green')
2391
- })
2392
-
2393
- test('the stop mark is a drawn square, and the sidebar batch bar keeps the row tones', async () => {
2507
+ test('the stop mark is a drawn square, ⟳ is green like ▶, and the sidebar batch bar keeps the row tones', async () => {
2394
2508
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2395
2509
  // The ■ character's ink is about half its advance width: inside a 20px sidebar
2396
2510
  // button (or a 25px workbench one) it read as a dot. Every stop control draws a
@@ -2409,6 +2523,9 @@ test('the stop mark is a drawn square, and the sidebar batch bar keeps the row t
2409
2523
  assert.match(source, /width: 25, stop: true, action: 'batch-stop'/, 'workbench batch ■ keeps its red tone')
2410
2524
  const glyphUses = source.match(/stopGlyph\(/g) || []
2411
2525
  assert.ok(glyphUses.length >= 4, 'both consoles (row + batch) draw the square')
2526
+ // ⟳ (re)starts, so it shares ▶'s green in BOTH consoles; ■ keeps red.
2527
+ assert.match(source, /S\.startIcon, disabled: busy, 'data-action': 'restart'/, 'sidebar ⟳ is green')
2528
+ assert.match(source, /width: 25, start: true, action: 'console-restart'/, 'workbench ⟳ is green')
2412
2529
  })
2413
2530
 
2414
2531
  test('copying in the tree also publishes the files to the OS clipboard', async () => {
@@ -2695,7 +2812,7 @@ test('fsTree fails loudly on a host without the tree route (no sidebar fallback)
2695
2812
  }
2696
2813
  })
2697
2814
 
2698
- test('the saved layout (maximised + theme + font + sizes) restores on init, even from a legacy key', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
2815
+ test('the saved layout (theme + font + sizes) restores on init, even from a legacy key — but maximised mode does not (m00584)', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
2699
2816
  const hadLocalStorage = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage')
2700
2817
  const previousLocalStorage = globalThis.localStorage
2701
2818
  try {
@@ -2720,8 +2837,9 @@ test('the saved layout (maximised + theme + font + sizes) restores on init, even
2720
2837
  const root = workbenchRootTagOf(markup)
2721
2838
  assert.match(root, /font-size:15px/, 'the persisted font size is applied at init')
2722
2839
  assert.match(root, /data-theme="page"/, 'the IDE itself no longer stores a colour scheme')
2723
- assert.doesNotMatch(markup, /data-ide-pane="tree"/, 'the persisted maximised pane is applied at init')
2840
+ assert.match(markup, /data-ide-pane="tree"/, 'a persisted "editor" maximise mode is IGNORED: the grid comes back')
2724
2841
  assert.match(markup, /data-ide-pane="editor"/)
2842
+ assert.match(markup, /data-splitter="left"/, 'and so do the splitters')
2725
2843
  } finally {
2726
2844
  if (hadLocalStorage) globalThis.localStorage = previousLocalStorage
2727
2845
  else globalThis.localStorage = undefined
@@ -2862,7 +2980,7 @@ test('the tree highlight follows the editor, not the last locate', async () => {
2862
2980
  assert.match(tree, /if \(selectedPath === active\) return\n\s*selectOne\(active\)/)
2863
2981
  })
2864
2982
 
2865
- test('the locate walk against a real single-child package chain reaches the file parent', async () => {
2983
+ test('the locate walk against a real single-child package chain reaches the file parent', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
2866
2984
  const { mkdtemp, mkdir, writeFile, rm } = await import('node:fs/promises')
2867
2985
  const { execFile } = await import('node:child_process')
2868
2986
  const { promisify } = await import('node:util')
@@ -3152,7 +3270,7 @@ test('streamed search answers are read page by page, not after the whole body',
3152
3270
  await assert.rejects(() => T.readSearchStream({}, () => {}), /不支持流式读取/)
3153
3271
  })
3154
3272
 
3155
- test('fsSearchStream paints page by page from the REAL streamed host route', async () => {
3273
+ test('fsSearchStream paints page by page from the REAL streamed host route', { skip: skipWithout(HAS_GIT, 'git') }, async () => {
3156
3274
  // End-to-end through the host half's own handler and a real listener: the
3157
3275
  // NDJSON is chunked over HTTP, so this proves the client parser and the host
3158
3276
  // framing agree — a unit fixture with a hand-made Response cannot.
@@ -3374,6 +3492,95 @@ test('every advisory strip carries a ✕ to close it', { skip: !reactIsReal ? 'R
3374
3492
  assert.match(workbench, /data-notice-close="config-note"/, 'the config note is closable')
3375
3493
  })
3376
3494
 
3495
+ test('only a FRONTEND row offers the browser button, and only a yds project promises a token (m03945/m04354)', async () => {
3496
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
3497
+ // Two renderers (sidebar compact row + full panel) both carry the button, but a
3498
+ // backend (spring) program serves no page to open — m04354: no button there.
3499
+ const hits = source.split("'data-action': 'open-site'").length - 1
3500
+ assert.equal(hits, 2, 'the 🌐 button is rendered by both program rows')
3501
+ assert.match(source, /startable && program\.kind === 'frontend'/, 'the sidebar row gates on kind')
3502
+ assert.match(source, /program\.kind === 'frontend'\s*\n\s*\? h\('button', \{/, 'the full row gates on kind')
3503
+ assert.match(source, /async function requestOpenTarget\(program, scope\)/)
3504
+ assert.match(source, /dsh-ris-ide\/open-target\?/)
3505
+ assert.match(source, /function openSite\(program\)/)
3506
+ // The row click picks the program for the log pane: the button must not steal or
3507
+ // pass that click through.
3508
+ assert.match(source, /event\.stopPropagation\(\); openSite\(program\)/)
3509
+ // Errors are told in the panel's note bar, never swallowed.
3510
+ assert.match(source, /还没有可打开的地址|这个程序还没有\.\.\./)
3511
+ // The token sentence may only appear behind the yds flag: a plain workspace must
3512
+ // never read "yds" (m04354).
3513
+ assert.match(source, /async function requestYdsProject\(scope\)/)
3514
+ assert.match(source, /dsh-ris-yds\/probe\?/)
3515
+ assert.match(source, /ydsProject \? '(yds 项目:请求自动带上登录 token,免登录)' : ''/)
3516
+ assert.doesNotMatch(source, /yds 项目会自动注入 YYCToken/, 'the old unconditional yds wording is gone')
3517
+ })
3518
+
3519
+ test('the tab strip shows ⟳ while the buffer is clean and ± once it is dirty (m00388/m00808)', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
3520
+ const markup = renderWorkbenchWithFile('/w/README.md')
3521
+ const tag = (markup.match(/<button[^>]*data-action="reload-file"[^>]*>/) || [''])[0]
3522
+ assert.ok(tag !== '', 'the ⟳ button is in the source pane toolbar')
3523
+ assert.doesNotMatch(tag, /disabled/, 'it is enabled while a file is open')
3524
+ assert.match(tag, /重新加载 README\.md/, 'the tooltip names the file')
3525
+ assert.doesNotMatch(markup, /data-action="diff"/, 'a clean buffer has no comparison to offer, so ± is gone')
3526
+ const empty = renderWorkbench({})
3527
+ const emptyTag = (empty.match(/<button[^>]*data-action="reload-file"[^>]*>/) || [''])[0]
3528
+ assert.match(emptyTag, /disabled/, 'nothing to reload without an open file')
3529
+ })
3530
+
3531
+ test('closing a notice sticks for EVERY mounted copy of the panel (m00388)', () => {
3532
+ // The DSH sidebar can mount the same pane twice (a hidden keepMounted copy next
3533
+ // to the visible one); a per-instance useState made the ✕ look dead because the
3534
+ // other copy kept rendering the same notice.
3535
+ T.__resetNoticeDismissals()
3536
+ assert.equal(T.noticeIsOpen('config-updated', 'updated'), true, 'starts open')
3537
+ T.dismissNotice('config-updated', 'updated')
3538
+ assert.equal(T.noticeIsOpen('config-updated', 'updated'), false, 'closed for the shared table')
3539
+ assert.equal(T.noticeIsOpen('config-updated', 'updated-2'), true, 'a NEW signature reopens it')
3540
+ assert.equal(T.noticeIsOpen('config-generated', 'generated:cfg'), true, 'other kinds are untouched')
3541
+ T.dismissNotice('config-updated', 'updated')
3542
+ T.dismissNotice('config-updated', 'updated-2')
3543
+ assert.equal(T.noticeIsOpen('config-updated', 'updated'), true, 'a newer signature supersedes the old dismissal')
3544
+ T.__resetNoticeDismissals()
3545
+ assert.equal(T.noticeIsOpen('config-updated', 'updated'), true, 'reset restores the initial state')
3546
+ })
3547
+
3548
+ test('the automatic config sync is silent: nothing renders a sync notice (m03291)', async () => {
3549
+ // The host rewrites .dsh-ris-ide/config.json whenever the scan drifts, and the
3550
+ // panel used to answer with a row per sync ("配置已与工作区同步…") that was noise
3551
+ // after every workspace switch — and could not be dismissed while two copies of
3552
+ // the pane were mounted. The text is gone; the actionable drift notice stays.
3553
+ const { readFile } = await import('node:fs/promises')
3554
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
3555
+ assert.doesNotMatch(source, /配置已与工作区同步/, 'the auto-sync notice text is gone')
3556
+ assert.doesNotMatch(source, /'config-updated'/, 'nothing renders that kind any more')
3557
+ assert.match(source, /kind: 'drift'/, 'the actionable drift notice stays')
3558
+ assert.match(source, /kind: 'config-generated'/, 'the one-off "config created" note stays')
3559
+ })
3560
+
3561
+ test('the source tab strip offers 重新加载, and a dirty tab asks before dropping it (m00388)', async () => {
3562
+ const { readFile } = await import('node:fs/promises')
3563
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
3564
+ assert.match(source, /'data-action': 'reload-file'/, 'the ⟳ button lives in the tab strip')
3565
+ assert.match(source, /function reloadPath\(path\)/, 'reload drops the draft, then rereads')
3566
+ assert.match(source, /ensureDoc\(path, true\)/, 'and forces a real read of an already-open path')
3567
+ for (const action of ['save-reload', 'discard-reload', 'cancel-reload']) {
3568
+ assert.match(source, new RegExp(`'data-action': '${action}'`), `missing the ${action} choice`)
3569
+ }
3570
+ assert.match(source, /'data-reload-prompt': '1'/, 'the (race-only) dirty-tab question is its own strip')
3571
+ // Reload must never merge: the draft is forgotten BEFORE the read.
3572
+ const reloadBody = source.slice(source.indexOf('function reloadPath(path)'))
3573
+ assert.ok(reloadBody.indexOf('forgetDoc(path)') < reloadBody.indexOf('ensureDoc(path, true)'), 'forget first, then read')
3574
+ // ± and ⟳ are mutually exclusive, sharing one slot (m00808): dirty -> diff,
3575
+ // clean -> reload. Both rendered unconditionally used to leave a dead ±.
3576
+ const diffAt = source.indexOf("'data-action': 'diff'")
3577
+ const reloadAt = source.indexOf("'data-action': 'reload-file'")
3578
+ const slot = source.slice(diffAt - 700, reloadAt)
3579
+ assert.ok(diffAt !== -1 && reloadAt > diffAt, 'both controls still exist, in that order')
3580
+ assert.match(slot, /isDirty\(openFile\) === true\s*\?\s*h\('button'/, 'the dirty case picks ±')
3581
+ assert.match(source.slice(diffAt, reloadAt), /:\s*h\('button'/, 'the clean case picks ⟳')
3582
+ })
3583
+
3377
3584
  test('driftSignature is stable per drift payload', () => {
3378
3585
  const a = { added: ['x'], missing: ['y'], changed: [] }
3379
3586
  assert.equal(T.driftSignature(a), T.driftSignature({ added: ['x'], missing: ['y'], changed: [] }))
@@ -3513,24 +3720,24 @@ function logHeadOf(markup) {
3513
3720
  return markup.slice(start, end === -1 ? undefined : end)
3514
3721
  }
3515
3722
 
3516
- test('a first ever open starts with the source pane maximised, and that state is saved', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
3723
+ test('every open starts on the plain 2x2 grid: a maximised pane is never persisted nor restored (m00584)', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
3517
3724
  const hadLocalStorage = Object.prototype.hasOwnProperty.call(globalThis, 'localStorage')
3518
3725
  const previousLocalStorage = globalThis.localStorage
3519
- const writes = []
3520
3726
  try {
3521
- // No saved layout at all: the workbench should collapse to the source pane.
3522
- globalThis.localStorage = { getItem: () => null, setItem: (key, value) => { writes.push({ key, value: JSON.parse(value) }) } }
3727
+ // No saved layout at all: the four panes are all on screen (no auto-maximize).
3728
+ globalThis.localStorage = { getItem: () => null, setItem: () => {} }
3523
3729
  const first = renderWorkbench({})
3524
- assert.match(first, /data-ide-pane="editor"/, 'the first open shows the source pane')
3525
- assert.doesNotMatch(first, /data-ide-pane="tree"/, 'the other panes are maximised away')
3526
- // Persistence round-trip: the same `ui.maximized` the effect writes is what a
3527
- // later open reads back (effects do not run under SSR, so emulate the write).
3730
+ assert.match(first, /data-ide-pane="tree"/, 'the first open shows every pane, not only the editor')
3731
+ assert.match(first, /data-ide-pane="editor"/)
3732
+ assert.match(first, /data-splitter="left"/)
3733
+
3734
+ // A blob from the old build still carrying `ui.maximized` is ignored.
3528
3735
  globalThis.localStorage = { getItem: () => JSON.stringify({ ui: { maximized: 'editor' }, files: [], sizes: {} }), setItem() {} }
3529
3736
  const again = renderWorkbench({})
3530
- assert.match(again, /data-ide-pane="editor"/, 'the saved maximised state restores')
3531
- assert.doesNotMatch(again, /data-ide-pane="tree"/)
3737
+ assert.match(again, /data-ide-pane="tree"/, 'the persisted maximised pane does not come back')
3738
+ assert.match(again, /data-ide-pane="editor"/)
3532
3739
 
3533
- // A stored layout (even "not maximised") always wins over the default.
3740
+ // The rest of the layout still restores.
3534
3741
  globalThis.localStorage = { getItem: () => JSON.stringify({ ui: { maximized: null }, files: [], sizes: {} }), setItem() {} }
3535
3742
  const restored = renderWorkbench({})
3536
3743
  assert.match(restored, /data-ide-pane="tree"/, 'a saved non-maximised layout restores the grid')
@@ -3570,7 +3777,7 @@ test('the IDE top bar hosts the workspace search and only shows config buttons w
3570
3777
  for (const bar of [head, bare]) {
3571
3778
  assert.match(bar, /data-action="layout-reset"/, 'the restore-layout button sits at the top bar right end')
3572
3779
  assert.match(bar, /title="还原布局尺寸/)
3573
- assert.match(bar, /data-action="layout-reset"[^>]*>⟲</, 'the button is labelled ⟲')
3780
+ assert.match(bar, /data-action="layout-reset"[^>]*>▦</, 'the button is labelled ▦ (no longer the ⟲ that read as reload)')
3574
3781
  const resetTag = bar.match(/<button[^>]*data-action="layout-reset"[^>]*>/)
3575
3782
  assert.ok(resetTag !== null)
3576
3783
  assert.match(resetTag[0], /width:22px/, 'the restore-layout control is an icon button')
@@ -4379,23 +4586,15 @@ test('the IDE console masks a program row while it starts, stops or debugs, and
4379
4586
  assert.match(source, /PROGRAM_LOADING_CSS/)
4380
4587
  // A transient top-bar note clears itself after 5 seconds.
4381
4588
  assert.match(source, /\}, 5000\)\n\s*return function \(\) \{ clearTimeout\(timer\) \}/)
4382
- })
4383
-
4384
- test('the console row masks itself while a start/stop is in flight', async () => {
4385
- const { readFile } = await import('node:fs/promises')
4386
- const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4387
- assert.match(source, /'data-program-loading': program\.id/)
4589
+ // The mask layer: its own class, spinner, and the ACTION (not `alive`) wording.
4388
4590
  assert.match(source, /className: 'dsh-ris-ide-loading'/)
4389
4591
  assert.match(source, /dshRisIdeSpin/)
4390
- // The label follows the ACTION, not `alive`: debugging a running program used
4391
- // to flash 停止中 because the host restarts it in place.
4392
4592
  assert.match(source, /function busyMaskText\(alive, kind\) \{/)
4393
4593
  assert.match(source, /'data-program-loading-kind': busyKind/)
4394
4594
  assert.match(source, /'data-program-loading-kind': consoleBusyKind/)
4395
4595
  assert.doesNotMatch(source, /alive \? '停止中…' : '启动中…'/)
4396
- // The mask swallows the click, and the row is the containing block for it.
4596
+ // The mask swallows the click.
4397
4597
  assert.match(source, /onClick: function \(event\) \{ event\.stopPropagation\(\); event\.preventDefault\(\) \}/)
4398
- assert.match(source, /position: 'relative', overflow: 'hidden'/)
4399
4598
  // Rows keep their own height so the list scrolls; a shrinkable row used to
4400
4599
  // squash the whole project list into the panel (no scrollbar at all).
4401
4600
  assert.match(source, /flex: '0 0 auto', minWidth: 0, cursor: 'pointer', position: 'relative', overflow: 'hidden'/)
@@ -4538,20 +4737,6 @@ test('every change of the suspended top frame moves the editor there', async ()
4538
4737
  assert.ok(source.includes('void followDebugLocation(top)'))
4539
4738
  })
4540
4739
 
4541
- test('progress goes to the status bar; toasts stay for things the user must know', async () => {
4542
- const { readFile } = await import('node:fs/promises')
4543
- const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4544
- // The static bottom help text moved into the ? panel.
4545
- assert.ok(!source.includes('Ctrl+S 保存 · Ctrl+W 关页签 · 拖分隔条调大小 · 双击标题最大化'))
4546
- assert.ok(!source.includes("' · F5 步入 · F6 单步 · F7 步出 · F8 继续'"))
4547
- // A status channel exists and the dependency-source progress uses it (no toast).
4548
- assert.ok(source.includes("var [statusText, setStatusText] = useState('')"))
4549
- assert.ok(source.includes("statusNote('正在获取依赖源码:' + cleaned + '…', 0)"))
4550
- assert.ok(source.includes("statusNote('正在启动 ' + program.name + '…', 0)"))
4551
- assert.ok(!source.includes("note('正在获取依赖源码:"))
4552
- assert.ok(source.includes("'data-ide-status-text': statusText === '' ? '0' : '1'"))
4553
- })
4554
-
4555
4740
  test('while a debug session is attached, F5 cannot reload the window', async () => {
4556
4741
  const { readFile } = await import('node:fs/promises')
4557
4742
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
@@ -5131,16 +5316,6 @@ test('the console keeps its log pane empty until a row is chosen (m07431)', asyn
5131
5316
  assert.equal(source.includes('First load with no explicit target'), false)
5132
5317
  })
5133
5318
 
5134
- test('no ProxyDialog component is shipped any more (m07355 / D4)', async () => {
5135
- const { readFile } = await import('node:fs/promises')
5136
- const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
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
5319
  test('the workbench reads its saved blob once per mount and remounts per workspace', async () => {
5145
5320
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
5146
5321
  // One read per mount, from a lazy useState initialiser: readSavedUi also runs