dsh-ris-ide 1.6.11 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -193,7 +193,7 @@ test('only invisible outcomes and failures raise a toast', async () => {
193
193
  }
194
194
  // Failures and warnings keep their toast (nothing else would tell the user).
195
195
  for (const kept of ['保存失败:', '启动失败:', '停止失败:', '加断点失败:', '删断点失败:',
196
- '清断点失败:', '撤销失败:', '移动失败:', '粘贴失败:', '新建文件失败:',
196
+ '清断点失败:', '撤销失败:', ' 项失败:', '粘贴失败:', '新建文件失败:',
197
197
  '取线程失败:', '取栈失败:', '取变量失败:', '文件不存在,已从最近历史移除:',
198
198
  '已复制路径:', '已复制文件名:']) {
199
199
  assert.ok(source.includes(kept), `${kept} must stay`)
@@ -1286,17 +1286,22 @@ test('the tree clipboard keys only fire while the tree owns the focus', async ()
1286
1286
  })
1287
1287
 
1288
1288
  // 1.6.10: Ctrl+C / Ctrl+X used to read the context-menu state only, so the
1289
- // keyboard silently copied nothing; 全选 has no meaning in a single-selection
1290
- // tree and must not hand the page a text selection either.
1291
- test('Ctrl+C copies the selected tree row without the context menu', async () => {
1289
+ // keyboard silently copied nothing. 1.6.11: the tree is a multi-selection
1290
+ // (Ctrl+click / Ctrl+A), so the clipboard carries every selected row.
1291
+ test('Ctrl+C copies the selected rows without the context menu', async () => {
1292
1292
  const { readFile } = await import('node:fs/promises')
1293
1293
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1294
- assert.match(source, /var entry = treeMenu !== null && treeMenu\.entry !== null && treeMenu\.entry !== undefined/,
1294
+ assert.match(source, /var seed = treeMenu !== null && treeMenu\.entry !== null && treeMenu\.entry !== undefined/,
1295
1295
  'the context-menu entry still wins when the menu is open')
1296
- assert.match(source, /: \(selectedPath === null \? null : findEntry\(selectedPath\)\)/,
1296
+ assert.match(source, /: \(selectedPath === null \? '' : selectedPath\)/,
1297
1297
  'the keyboard falls back to the tree selection')
1298
- assert.match(source, /if \(entry === null \|\| entry === undefined\) return/)
1298
+ assert.match(source, /var paths = selectionFor\(seed\)/, 'a menu/key command expands to the whole selection')
1299
+ assert.match(source, /setClipboard\(\{ mode: mode, items: items \}\)/, 'the clipboard carries every selected row')
1299
1300
  assert.match(source, /event\.key === 'a' \|\| event\.key === 'A'/, 'Ctrl+A is claimed while the tree owns the keys')
1301
+ assert.match(source, /var visible = visibleEntries\(\)/, 'Ctrl+A selects the visible rows')
1302
+ assert.match(source, /setSelectedPaths\(visible\.map\(function \(row\) \{ return row\.path \}\)\)/)
1303
+ // The page-wide text selection the old code leaked is gone: the tree handles it.
1304
+ assert.doesNotMatch(source, /The tree is single-selection, so 全选 has nothing to expand into/)
1300
1305
  })
1301
1306
 
1302
1307
  test('a file row is a drop target for the directory it lives in', async () => {
@@ -1304,7 +1309,9 @@ test('a file row is a drop target for the directory it lives in', async () => {
1304
1309
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1305
1310
  assert.match(source, /var dropDir = entry\.isDir === true \? entry\.path : parentOf\(entry\.path\)/)
1306
1311
  assert.match(source, /var isDropTarget = dropTarget === entry\.path/, 'file rows highlight too')
1307
- assert.match(source, /void moveInto\(from, dropDir\)/, 'dropping on a file moves into its parent')
1312
+ assert.match(source, /void moveEntriesInto\(paths, dropDir\)/, 'dropping on a file moves into its parent')
1313
+ assert.match(source, /setData\('application\/x-dsh-ris-ide-paths', JSON\.stringify\(dragged\)\)/, 'a drag carries the whole selection')
1314
+ assert.match(source, /function dragPaths\(transfer\)/, 'drops read the path list back')
1308
1315
  assert.match(source, /void importExternal\(dropDir, external, \[\]\)/)
1309
1316
  // The row handlers must not be dir-gated any more (the bug: `undefined` let the
1310
1317
  // list container's "blank area = workspace root" drop swallow the event).
@@ -1336,21 +1343,104 @@ test('the tree 复制 menu copies, while 创建副本 makes the duplicate', asyn
1336
1343
  assert.match(source, /setPrompt\(\{ mode: 'duplicate'/)
1337
1344
  assert.match(source, /setPromptName\(duplicateName\(/)
1338
1345
  assert.match(source, /副本名称不能与原文件相同/)
1339
- // A paste collision asks for a NEW name (the 副本 convention prefilled), it does
1340
- // not park a 覆盖/改名/取消 dialog any more — and the copy banner at the top of
1341
- // the tree is gone.
1342
- assert.match(source, /function parkPasteName\(source, dir, name\)/)
1343
- assert.match(source, /setPrompt\(\{ mode: 'paste', dir: dir, ext: '', title: '粘贴为', source: source, conflict: name \}\)/)
1344
- assert.match(source, /setPromptName\(duplicateName\(name, false\)\)/)
1346
+ // A paste collision opens the 粘贴为 card with the REAL name (no 副本 prefill),
1347
+ // an explicit 覆盖 button, and inline 请改名 instead of a toast; the copy banner
1348
+ // at the top of the tree stays gone.
1349
+ assert.match(source, /function parkPasteName\(source, dir, name, forcedMode\)/)
1350
+ assert.match(source, /setPrompt\(\{ mode: 'paste', dir: dir, ext: '', title: '粘贴为', source: source, conflict: name, pasteMode: forcedMode \}\)/)
1351
+ assert.match(source, /setPromptName\(name\)\n\s+setPromptNotice\(''\)/, 'the colliding name is prefilled verbatim')
1352
+ assert.doesNotMatch(source, /setPromptName\(duplicateName\(name, false\)\)/, 'no hidden 副本 prefill any more')
1353
+ assert.match(source, /async function overwritePaste\(\)/, '覆盖 overwrites under the same name')
1354
+ assert.match(source, /'data-tree-prompt-overwrite': '1'/, 'the card offers 覆盖')
1355
+ assert.match(source, /setPromptNotice\('同名文件已存在,请改名(或点「覆盖」)'\)/, '确定 with the same name asks for a new one')
1345
1356
  assert.match(source, /if \(prompt\.conflict !== undefined && name === prompt\.conflict\)/)
1346
1357
  assert.match(source, /if \(isExistsProblem\(problem\)\) \{\n\s+parkPasteName\(source, dir, name\)/)
1347
1358
  assert.doesNotMatch(source, /data-tree-paste-conflict/)
1348
1359
  assert.doesNotMatch(source, /data-tree-clipboard/)
1349
1360
  // A COPY onto its own path is a duplicate request (falls through to the prompt),
1350
1361
  // while CUT → its own folder stays a silent no-op.
1351
- assert.match(source, /if \(source\.kind === 'clipboard' && target === from && clipboard\.mode !== 'copy'\)/)
1362
+ assert.match(source, /if \(source\.kind === 'clipboard' && target === from && mode !== 'copy'\)/)
1352
1363
  // …and moving an entry into its own folder stays a silent no-op.
1353
- assert.match(source, /if \(from === dirPath \|\| parentOf\(from\) === dirPath\) return/)
1364
+ assert.match(source, /if \(from === trimmedDir \|\| parentOf\(from\) === trimmedDir\) continue/)
1365
+ })
1366
+
1367
+ // 1.6.11: 文件树多选 + 批量操作。Ctrl+点击 标记行、Ctrl+A 全选可见行;粘贴/移动把
1368
+ // 所有标记行放进目标目录,重名自动后缀「 副本」「 副本(n)」并用一条提示说明(批量
1369
+ // 操作绝不逐个弹窗),批量删除同样一条 Ctrl+Z 撤销。
1370
+ test('multi-selection batches copy/move and suffix colliding names', async () => {
1371
+ // Pure naming/toggle helpers (unit level).
1372
+ assert.equal(T.collisionCopyName('A.java', false, 1), 'A 副本.java')
1373
+ assert.equal(T.collisionCopyName('A.java', false, 2), 'A 副本(2).java')
1374
+ assert.equal(T.collisionCopyName('Main.vue', false, 3), 'Main 副本(3).vue')
1375
+ assert.equal(T.collisionCopyName('Makefile', false, 1), 'Makefile 副本')
1376
+ assert.equal(T.collisionCopyName('.gitignore', false, 1), '.gitignore 副本')
1377
+ assert.equal(T.collisionCopyName('pkg', true, 1), 'pkg 副本')
1378
+ assert.equal(T.collisionCopyName('pkg', true, 2), 'pkg 副本(2)')
1379
+ assert.equal(T.collisionCopyName('', false, 1), 'copy')
1380
+ assert.deepEqual(T.toggleTreeSelection([], '/a'), ['/a'])
1381
+ assert.deepEqual(T.toggleTreeSelection(['/a'], '/a'), [])
1382
+ assert.deepEqual(T.toggleTreeSelection(['/a', '/b'], '/b'), ['/a'])
1383
+ assert.deepEqual(T.toggleTreeSelection(['/a'], '/b'), ['/a', '/b'])
1384
+ const { readFile } = await import('node:fs/promises')
1385
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1386
+ // Ctrl+click toggles membership; it must not open a file nor expand a folder.
1387
+ assert.match(source, /var additive = event\.ctrlKey === true \|\| event\.metaKey === true/)
1388
+ assert.match(source, /var next = toggleTreeSelection\(selectedPaths, entry\.path\)/)
1389
+ // Multi rows are drawn apart from the primary row.
1390
+ assert.match(source, /'data-tree-multi': isMulti \? '1' : undefined/)
1391
+ assert.match(source, /treeRowMulti:/)
1392
+ // Batch paste: one collision → one `… 副本`, no dialog in the loop.
1393
+ assert.match(source, /async function pasteBatch\(items, dir, mode\)/)
1394
+ assert.match(source, /async function pasteEntryInto\(item, dir, mode, ask\)/)
1395
+ assert.match(source, /var name = attempt === 0 \? item\.name : collisionCopyName\(item\.name, item\.isDir === true, attempt\)/)
1396
+ assert.match(source, /if \(!isExistsProblem\(problem\)\) throw problem/)
1397
+ assert.match(source, /function notifyCollisionCopies\(renamed, failures\)/)
1398
+ assert.match(source, /存在同名文件,已生成/)
1399
+ assert.match(source, /await pasteBatch\(clipboardItems\(\), dir, mode === 'copy' \? 'copy' : 'cut'\)/)
1400
+ // Batch move (drag) uses the same collision rule.
1401
+ assert.match(source, /async function moveEntriesInto\(paths, dirPath\)/)
1402
+ assert.match(source, /await pasteEntryInto\(\{ path: from, isDir: isDir, name: fileBaseName\(from\) \}, dirPath, 'cut', true\)/, 'a drag surfaces collisions instead of silently renaming')
1403
+ assert.match(source, /if \(placed\.conflict === true\) \{\n\s+if \(paths\.length === 1\) \{\n\s+parkPasteName\(\{ kind: 'entry'/, 'a single drag collision parks the 粘贴为 card')
1404
+ assert.match(source, /conflicts\.push\(\{ path: from, isDir: isDir, name: fileBaseName\(from\) \}\)/, 'a batch drag collects the collisions')
1405
+ assert.match(source, /if \(ask === true && attempt === 0\) return \{ path: target, conflict: true, renamed: false \}/)
1406
+ assert.match(source, /var mode = forcedMode === 'cut' \|\| forcedMode === 'copy' \? forcedMode/, 'a parked drag keeps its cut semantics')
1407
+ // Batch collisions ask 覆盖 / 生成副本 (no name field) instead of suffixing silently.
1408
+ assert.match(source, /var \[batchConflict, setBatchConflict\] = useState\(null\)/)
1409
+ assert.match(source, /setBatchConflict\(\{ mode: mode, dir: trimmedDir, items: conflicts, created: created, origins: origins, touched: touched \}\)/)
1410
+ assert.match(source, /'data-tree-batch-conflict': '1'/)
1411
+ assert.match(source, /'data-tree-batch-overwrite': '1'/, '覆盖 replaces the colliding names')
1412
+ assert.match(source, /'data-tree-batch-copy': '1'/, '生成副本 suffixes the colliding names')
1413
+ assert.match(source, /async function resolveBatchConflict\(policy\)/)
1414
+ assert.match(source, /await fsMoveEntry\(scope, item\.path, pending\.dir, leaf, true\)/, '覆盖 keeps the cut semantics for a drag')
1415
+ assert.match(source, /var placed = await pasteEntryInto\(item, pending\.dir, pending\.mode, false\)/, '生成副本 reuses the suffix rule')
1416
+ assert.doesNotMatch(source, /生成副本'\n\s*: null/)
1417
+ // One compound undo entry per batch.
1418
+ assert.match(source, /rememberUndo\(mode === 'cut' \? '移动 ' \+ created\.length \+ ' 项' : '粘贴 ' \+ created\.length \+ ' 项'/)
1419
+ // Batch delete: trash + one undo + multi-row confirm.
1420
+ assert.match(source, /async function removeEntries\(entries\)/)
1421
+ assert.match(source, /var items = Array\.isArray\(pendingDelete\) \? pendingDelete : \[pendingDelete\]/)
1422
+ // A batch is invisible while it happens: the tree must say how many rows are
1423
+ // selected, Esc must drop the batch, and vanished paths must leave it.
1424
+ assert.match(source, /'data-tree-selection': String\(selectedPaths\.length\)/)
1425
+ assert.match(source, /已选 ' \+ selectedPaths\.length \+ ' 项'/)
1426
+ assert.match(source, /if \(event\.key === 'Escape' && selectedPaths\.length > 1\)/)
1427
+ assert.match(source, /var alive = selectedPaths\.filter\(function \(path\) \{ return findEntry\(path\) !== undefined \}\)/)
1428
+ })
1429
+
1430
+ test('destructive file operations offer an inline undo and never strand focus', async () => {
1431
+ const { readFile } = await import('node:fs/promises')
1432
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1433
+ // The toast itself carries 撤销: remembering Ctrl+Z is not a user interface.
1434
+ assert.match(source, /function notifyWithAction\(message, action\)/)
1435
+ assert.match(source, /'data-toast-action': String\(toast\.id\)/)
1436
+ assert.match(source, /function undoAction\(title\)/)
1437
+ // The tree hands its note callback down so delete/paste can pass the action.
1438
+ assert.match(source, /onActionNote: note/)
1439
+ // The delete dialog takes focus, answers Esc and gives focus back to the tree
1440
+ // (otherwise Del / the promised Ctrl+Z are dead right after a delete).
1441
+ assert.match(source, /var confirmCancelRef = useRef\(null\)/)
1442
+ assert.match(source, /function focusTreeRoot\(\)/)
1443
+ assert.match(source, /'data-tree-confirm-cancel': '1'/)
1354
1444
  })
1355
1445
 
1356
1446
  test('the recent-file dropdown is walkable like the result list', async () => {
@@ -1710,12 +1800,16 @@ test('the source tab bar scrolls its inner strip from anywhere on the row', () =
1710
1800
  detach()
1711
1801
  })
1712
1802
 
1713
- test('the top-bar controls share one 20px row height', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
1803
+ test('the title-bar controls share one 20px row height', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
1714
1804
  const markup = renderWorkbench({ onConfig: { open() {}, generate() {}, exists: true } })
1715
- const head = headOf(markup)
1716
- const tags = (head.match(/<button[^>]*>/g) || []).filter((tag) => /data-action="/.test(tag))
1717
- assert.ok(tags.length >= 5, 'the toolbar carries the A-/A+, theme and config/reset buttons')
1718
- for (const tag of tags) {
1805
+ const sourceHead = headOf(markup)
1806
+ const consoleHead = consoleHeadOf(markup)
1807
+ const buttonsOf = (head) => (head.match(/<button[^>]*>/g) || []).filter((tag) => /data-action="/.test(tag))
1808
+ const sourceTags = buttonsOf(sourceHead)
1809
+ const consoleTags = buttonsOf(consoleHead)
1810
+ assert.ok(sourceTags.length >= 3, 'the source toolbar carries the font scale, the theme switch and reset')
1811
+ assert.equal(consoleTags.length, 2, 'the console title bar carries 📄 open-config and ⚙ config-generate')
1812
+ for (const tag of sourceTags.concat(consoleTags)) {
1719
1813
  const action = /data-action="([^"]+)"/.exec(tag)[1]
1720
1814
  assert.match(tag, /height:20px/, `${action} must sit on the shared 20px row`)
1721
1815
  assert.match(tag, /min-height:20px/, `${action} must pin the minimum too`)
@@ -1822,9 +1916,45 @@ test('Ctrl+F goes to the workspace search unless the editor owns it', () => {
1822
1916
  assert.equal(T.globalFindShouldFocusSearch({ tagName: 'DIV', defaultPrevented: true }), false, 'editor already handled it')
1823
1917
  })
1824
1918
 
1919
+ test('a whole workbench console row picks the program, name and blank alike', async () => {
1920
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1921
+ // The row div itself is the hit target (the name span and the blank stretch
1922
+ // before the run buttons both land here); run controls stop the bubble so
1923
+ // pressing ■ on another program does not also switch this pane's log.
1924
+ assert.match(source, /onClick: function \(\) \{ selectProgram\(program\) \}/, 'row picks the program')
1925
+ assert.match(source, /button\('▶', function \(event\) \{ event\.stopPropagation\(\); void consoleStart\(program\) \}/)
1926
+ assert.match(source, /button\('■', function \(event\) \{ event\.stopPropagation\(\); void consoleStop\(program\) \}/)
1927
+ assert.match(source, /button\('⟳', function \(event\) \{ event\.stopPropagation\(\); void consoleRestart\(program\) \}/)
1928
+ assert.match(source, /button\(ideBadgeIcon\('bug', 'play', 13\), function \(event\) \{ event\.stopPropagation\(\); void consoleDebug\(program\) \}/)
1929
+ })
1930
+
1931
+ test('sidebar start/stop/restart stay silent, and ⟳ is green like ▶', async () => {
1932
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1933
+ // The sidebar row itself shows the settled state (dot + ▶/■ swap): successes
1934
+ // must not push the list down with a "已启动" strip. Failures still do.
1935
+ assert.doesNotMatch(source, /program\.name \+ ' 已(启动|重启|停止)'/, 'no success note in the sidebar console')
1936
+ assert.doesNotMatch(source, /program\.name \+ ' 已在运行'/, 'already-running stays silent too')
1937
+ assert.match(source, /'启动失败:' : kind === 'restart' \? '重启失败:' : '停止失败:'/, 'failures still surface')
1938
+ // ⟳ (re)starts, so it shares ▶'s green in BOTH consoles; ■ keeps red.
1939
+ assert.match(source, /S\.startIcon, disabled: busy, 'data-action': 'restart'/, 'sidebar ⟳ is green')
1940
+ assert.match(source, /width: 25, start: true, action: 'console-restart'/, 'workbench ⟳ is green')
1941
+ })
1942
+
1943
+ test('console program rows keep one horizontal inset when a row is picked', async () => {
1944
+ const S = T.stylesFor(1)
1945
+ assert.equal(S.consoleRow.padding, '1px 6px', 'unpicked rows have a left/right inset')
1946
+ assert.equal(S.consoleRowOn.padding, S.consoleRow.padding, 'picking must not change the padding')
1947
+ assert.equal(S.consoleRowOn.boxShadow, undefined, 'the picked row adds no border/shadow')
1948
+ // Both consoles (standalone workbench and the sidebar) render with these two
1949
+ // styles: the picked/unpicked swap must not touch padding either.
1950
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1951
+ assert.match(source, /selected \? S\.consoleRowOn : S\.consoleRow/, 'workbench console rows use both styles')
1952
+ assert.match(source, /picked \? S\.consoleRowOn : S\.consoleRow/, 'sidebar console rows use both styles')
1953
+ })
1954
+
1825
1955
  test('the help panel data covers tree, editor and debug shortcuts', () => {
1826
1956
  const sections = T.helpSections()
1827
- assert.deepEqual(sections.map((section) => section.title), ['通用', '文件树', '编辑器', '调试(仅 Java)', '使用说明'])
1957
+ assert.deepEqual(sections.map((section) => section.title), ['通用', '文件树', '检索', '编辑器', '日志', '配置', '调试(仅 Java)', '使用说明'])
1828
1958
  for (const section of sections) {
1829
1959
  assert.ok(section.rows.length > 0, `${section.title} has rows`)
1830
1960
  for (const row of section.rows) {
@@ -1835,9 +1965,31 @@ test('the help panel data covers tree, editor and debug shortcuts', () => {
1835
1965
  }
1836
1966
  const treeKeys = sections.find((section) => section.title === '文件树').rows.map((row) => row.keys).join(' ')
1837
1967
  assert.match(treeKeys, /Ctrl\+Z/, 'tree undo is documented')
1968
+ const searchKeys = sections.find((section) => section.title === '检索').rows.map((row) => row.keys).join(' ')
1969
+ assert.match(searchKeys, /↑ \/ ↓/, 'the results dropdown is keyboard-navigable')
1970
+ assert.match(searchKeys, /Enter/, 'Enter opens the highlighted result')
1971
+ const editorShortcutKeys = sections.find((section) => section.title === '编辑器').rows.map((row) => row.keys).join(' ')
1972
+ assert.match(editorShortcutKeys, /运行测试/, 'the per-file test run is documented')
1973
+ assert.match(editorShortcutKeys, /±/, 'the saved-vs-buffer diff is documented')
1974
+ const logShortcutKeys = sections.find((section) => section.title === '日志').rows.map((row) => row.keys).join(' ')
1975
+ assert.match(logShortcutKeys, /W\+/, 'the log level filter is documented')
1976
+ // Ctrl+W / Ctrl+F4 are browser-reserved: a page cannot cancel them, so the
1977
+ // help panel must not promise them as working shortcuts.
1978
+ const generalRows = sections.find((section) => section.title === '通用').rows
1979
+ const generalKeys = generalRows.map((row) => row.keys).join(' ')
1980
+ assert.doesNotMatch(generalKeys, /Ctrl\+W/, 'the browser-reserved Ctrl+W is not documented')
1981
+ assert.doesNotMatch(generalKeys, /Ctrl\+F4/, 'nor Ctrl+F4')
1982
+ assert.match(generalKeys, /Alt\+W/, 'the reachable close-tab chord is documented instead')
1983
+ assert.doesNotMatch(generalKeys, /Ctrl\+Alt\+W/, 'only Alt+W is advertised (user口径)')
1838
1984
  const editorKeys = sections.find((section) => section.title === '编辑器').rows.map((row) => row.keys).join(' ')
1839
1985
  assert.match(editorKeys, /Ctrl\+Shift\+K/)
1840
- assert.match(editorKeys, /Alt\+\u2191/)
1986
+ // README documented log Ctrl+F but the help panel never did (PM P1-5).
1987
+ const logKeys = sections.find((section) => section.title === '日志').rows.map((row) => row.keys).join(' ')
1988
+ assert.match(logKeys, /Ctrl\+F/, 'log find is documented')
1989
+ const configKeys = sections.find((section) => section.title === '配置').rows.map((row) => row.keys).join(' ')
1990
+ assert.match(configKeys, /\.dsh-ris-ide\.json/, 'the hidden config file is documented')
1991
+ // The help panel must not promise an editor back/forward that does not exist.
1992
+ assert.doesNotMatch(generalKeys, /Alt\+\u2190/, 'no fake editor back/forward row')
1841
1993
  })
1842
1994
 
1843
1995
  test('the workbench renders the bottom-right help button', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
@@ -1856,6 +2008,41 @@ test('the tree title bar carries the refresh button and the .gitignore eye', { s
1856
2008
  assert.match(filterMarkup, /data-icon="eye"/, 'an eye (not a funnel/triangle) reads as visibility')
1857
2009
  })
1858
2010
 
2011
+ test('the log find bar matches the editor find panel: chips and a tabular counter', async () => {
2012
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2013
+ const start = source.indexOf('data-log-find-bar')
2014
+ const region = source.slice(start - 400, start + 2600)
2015
+ assert.match(source, /logFindBar: \{/, 'the bar has its own style')
2016
+ assert.match(source, /logFindChip: \{/, 'arrows/close share one chip style')
2017
+ assert.match(source, /logFindCount: \{ fontSize: 11, opacity: 0\.62/, 'the counter mirrors the editor panel')
2018
+ assert.match(region, /style: S\.logFindBar, 'data-log-find-bar': '1'/)
2019
+ assert.match(region, /style: S\.logFindChip, 'data-action': 'log-find-prev'/, 'prev is a chip, not a padded button')
2020
+ assert.match(region, /style: S\.logFindChip, 'data-action': 'log-find-close'/, 'close is a chip too')
2021
+ assert.doesNotMatch(region, /padding: '0 4px' \}\), 'data-action': 'log-find-close'/, 'no ad-hoc padded close button')
2022
+ })
2023
+
2024
+ test('a background tree refresh stays silent; only the title bar refresh confirms', async () => {
2025
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2026
+ assert.match(source, /async function refreshTree\(announce\)/, 'refresh takes a "the user asked" flag')
2027
+ assert.match(source, /if \(announce !== true\) return\n\s*notify\(failed === 0/, 'silent unless announced')
2028
+ assert.match(source, /void refreshTree\(props\.refreshAnnounce === true\)/, 'the effect forwards the flag')
2029
+ assert.match(source, /var \[treeRefresh, setTreeRefresh\] = useState\(\{ tick: 0, announce: false \}\)/, 'tick and announce travel together')
2030
+ assert.match(source, /announce: false \} \}\)\n\s*note\(next \? '文件树:显示所有文件/, 'the filter toggle stays silent')
2031
+ assert.match(source, /announce: true \} \}\)/, 'the title bar asks for a toast')
2032
+ assert.match(source, /refreshNonce: treeRefresh\.tick, refreshAnnounce: treeRefresh\.announce/, 'both reach IdeTree')
2033
+ })
2034
+
2035
+ test('the large-file preview keeps its own component identity and remembers its offset', async () => {
2036
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
2037
+ const previewAt = source.indexOf('function LargeTextPreview(props) {')
2038
+ const workbenchAt = source.indexOf('function ProgramWorkbench(props) {')
2039
+ assert.ok(previewAt !== -1 && previewAt < workbenchAt, 'LargeTextPreview is module scope, not nested in ProgramWorkbench')
2040
+ assert.match(source, /var LARGE_TEXT_VIEW = new Map\(\)/, 'scroll offsets are remembered per path')
2041
+ assert.match(source, /LARGE_TEXT_VIEW\.set\(props\.path, box\.scrollTop\)/, 'scrolling records the offset')
2042
+ assert.match(source, /props\.active === false\) return/, 'a hidden pane is not restored')
2043
+ assert.match(source, /doc: doc, path: path, active: active,/, 'the pane passes path/active')
2044
+ })
2045
+
1859
2046
  test('the tree .gitignore eye fetches unfiltered listings, then re-reads the tree', async () => {
1860
2047
  const { readFile } = await import('node:fs/promises')
1861
2048
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
@@ -1863,7 +2050,7 @@ test('the tree .gitignore eye fetches unfiltered listings, then re-reads the tre
1863
2050
  assert.match(source, /if \(TREE_FILTER_ALL\) url\.searchParams\.set\('filter', 'all'\)/, 'the toggle reaches the host')
1864
2051
  assert.match(source, /\(TREE_FILTER_ALL \? '\\u0000all' : ''\)/, 'the cache key folds in the mode')
1865
2052
  assert.match(source, /function toggleTreeFilter\(\) \{/)
1866
- assert.match(source, /setTreeRefreshTick\(function \(value\) \{ return value \+ 1 \}\)/, 'a flip reloads root + expanded folders')
2053
+ assert.match(source, /setTreeRefresh\(function \(value\) \{ return \{ tick: value\.tick \+ 1, announce: false \} \}\)/, 'a flip reloads root + expanded folders, silently')
1867
2054
  assert.match(source, /data-filter-state': treeShowAll === true \? 'all' : 'git'/)
1868
2055
  assert.match(source, /ideIcon\(treeShowAll === true \? 'eyeOff' : 'eye', 14\)/, 'eye-off = ignored files shown too')
1869
2056
  assert.match(source, /disabled: treeGit !== true/, 'no git → nothing to filter')
@@ -1985,7 +2172,7 @@ test('Ctrl+R turns a single-line editor selection into the search query', async
1985
2172
  assert.match(source, /if \(text === '' \|\| text\.indexOf\('\\n'\) !== -1 \|\| text\.length > GLOBAL_FIND_SELECTION_MAX\) return ''/, 'multiline / oversized selections are ignored')
1986
2173
  assert.match(source, /if \(element\.closest\('\.cm-content'\) === null\) return ''/, 'only editor selections count')
1987
2174
  assert.match(source, /var picked = selectedEditorText\(\)[\s\S]{0,400}?setTreeQuery\(picked\)/, 'the pick becomes the query')
1988
- assert.match(source, /h\(SearchResults, \{[\s\S]{0,240}?active: searchActive, onHover: setSearchActive,[\s\S]{0,120}?fontRatio: fontRatio, cwd: cwd,/, 'results know the workspace root and the highlighted row')
2175
+ assert.match(source, /h\(SearchResults, \{[\s\S]{0,600}?active: searchActive, onHover: setSearchActive,[\s\S]{0,120}?fontRatio: fontRatio, cwd: cwd,/, 'results know the workspace root and the highlighted row')
1989
2176
  })
1990
2177
 
1991
2178
  test('an unfocused editor stops painting its selection', async () => {
@@ -2556,7 +2743,7 @@ test('every breakpoint row deletes from the LEFT, pre-set breakpoints included',
2556
2743
  assert.match(source, /width: 20, minWidth: 20, height: 20, padding: '0 0'/, 'the row delete is a 20px square icon button')
2557
2744
  assert.equal(source.split("'data-bp-remove': '1'").length - 1, 2, 'one shared + one failed-row icon button')
2558
2745
  const breakpointRows = source.slice(source.indexOf('var rows = []'), source.indexOf("} else if (ui.section === 'threads')"))
2559
- assert.equal(breakpointRows.split("}, '×')").length - 1, 2, 'both buttons render the × glyph, no text label')
2746
+ assert.ok(breakpointRows.split("}, '×')").length - 1 >= 2, 'both buttons render the × glyph, no text label')
2560
2747
  })
2561
2748
 
2562
2749
  test('the breakpoint clear-all is a title-bar icon, not an in-body text button', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
@@ -2595,6 +2782,18 @@ function headOf(markup) {
2595
2782
  return markup.slice(start, end)
2596
2783
  }
2597
2784
 
2785
+ /**
2786
+ * The CONSOLE pane's title bar: from its marker up to the source pane's title
2787
+ * bar (the grid renders the left column first, so the console header is what
2788
+ * sits between them).
2789
+ */
2790
+ function consoleHeadOf(markup) {
2791
+ const start = markup.indexOf('data-console-head="1"')
2792
+ assert.ok(start !== -1, 'the console pane must render its own title bar')
2793
+ const end = markup.indexOf('data-editor-head="1"', start)
2794
+ return markup.slice(start, end === -1 ? undefined : end)
2795
+ }
2796
+
2598
2797
  /**
2599
2798
  * SSR the workbench with a file already open (via the saved-UI localStorage the
2600
2799
  * workbench reads on mount) — the toolbar is rendered from that state, so a
@@ -2676,10 +2875,11 @@ test('the IDE grid has four draggable splitters and applies the default pane siz
2676
2875
  })
2677
2876
 
2678
2877
  test('the IDE top bar hosts the workspace search and only shows config buttons when hosted', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
2679
- const head = headOf(renderWorkbench({ onConfig: { open() {}, generate() {}, exists: true } }))
2878
+ const markup = renderWorkbench({ onConfig: { open() {}, generate() {}, exists: true } })
2879
+ const head = headOf(markup)
2680
2880
  assert.match(head, /data-action="tree-search"/, 'the tree search input sits in the top bar')
2681
- assert.match(head, /data-action="config-open"/)
2682
- assert.match(head, /data-action="config-generate"/)
2881
+ assert.doesNotMatch(head, /data-action="config-open"/, 'the config buttons left the source pane toolbar')
2882
+ assert.doesNotMatch(head, /data-action="config-generate"/)
2683
2883
 
2684
2884
  const bare = headOf(renderWorkbench({}))
2685
2885
  assert.match(bare, /data-action="tree-search"/, 'the search belongs to the top bar itself')
@@ -2697,12 +2897,18 @@ test('the IDE top bar hosts the workspace search and only shows config buttons w
2697
2897
  assert.match(resetTag[0], /width:22px/, 'the restore-layout control is an icon button')
2698
2898
  assert.match(resetTag[0], /text-align:center/)
2699
2899
  }
2700
- // The config controls are icon buttons too.
2900
+ // The config controls are icon buttons in the CONSOLE title bar: they describe
2901
+ // the programs listed underneath (the sidebar console keeps 打开配置/更新配置
2902
+ // in the same place), so they no longer ride on the source pane toolbar.
2903
+ const consoleHead = consoleHeadOf(markup)
2904
+ assert.match(consoleHead, /title="打开配置文件/, 'the console offers 📄 for .dsh-ris-ide.json')
2701
2905
  for (const action of ['config-open', 'config-generate']) {
2702
- const tag = head.match(new RegExp(`<button[^>]*data-action="${action}"[^>]*>`))
2703
- assert.ok(tag !== null, `missing ${action}`)
2906
+ const tag = consoleHead.match(new RegExp(`<button[^>]*data-action="${action}"[^>]*>`))
2907
+ assert.ok(tag !== null, `missing ${action} in the console title bar`)
2704
2908
  assert.match(tag[0], /width:22px/)
2705
2909
  }
2910
+ // Without a host callback the console renders neither button.
2911
+ assert.doesNotMatch(renderWorkbench({}), /data-action="config-open"/)
2706
2912
  })
2707
2913
 
2708
2914
  test('debug controls live in the debug pane toolbar, not in the top bar', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
@@ -3378,7 +3584,7 @@ test('a render failure inside the panel shows a retry banner instead of taking d
3378
3584
  assert.equal(typeof T.IdeErrorBoundary, 'function')
3379
3585
 
3380
3586
  // BOTH mount points are wrapped (the dsh sidebar tab and the standalone window).
3381
- assert.match(source, /function IdePanelBoundary\(props\) \{ return h\(IdeErrorBoundary, null, h\(ProgramsPanel, props\)\) \}/)
3587
+ assert.match(source, /function IdePanelBoundary\(props\) \{ return h\(IdeErrorBoundary, null, h\(ProgramsPanel, Object\.assign\(\{\}, props, \{ clientCtx: ctx \}\)\)\) \}/)
3382
3588
  assert.match(source, /root\.render\(h\(IdeErrorBoundary, null, h\(ProgramsPanel, \{ sessionId: sessionId, cwd: cwd, visible: true, compact: false \}\)\)\)/)
3383
3589
  })
3384
3590
 
@@ -3390,7 +3596,7 @@ test('a start switches to that program log before waiting for the spawn', async
3390
3596
  // block for START_WAIT_MS, and Maven compile prints nothing for tens of seconds.
3391
3597
  assert.match(source, /async function consoleStart\(program\) \{\n\s*\/\/[\s\S]*?\n\s*selectProgram\(program\)[\s\S]*?setConsoleBusy\(program\.id\)[\s\S]*?requestStart\(program\.id, scopeRef\.current\)/)
3392
3598
  // The sidebar rows do the same before awaiting requestStart.
3393
- assert.match(source, /if \(kind === 'start'\) \{ setActive\(program\); broadcastLogFocus\(program\.logPath\); setCompactLogNonce/)
3599
+ assert.match(source, /if \(boots\) \{ setActive\(program\); broadcastLogFocus\(program\.logPath\); setCompactLogNonce/)
3394
3600
  // …and every window watching another log is moved by the same broadcast.
3395
3601
  assert.match(source, /function broadcastLogFocus\(logPath\)/)
3396
3602
  })
@@ -3419,7 +3625,7 @@ test('the IDE console masks a program row while it starts, stops or debugs, and
3419
3625
  assert.match(source, /setConsoleBusy\(program\.id\)/)
3420
3626
  assert.match(source, /data-program-loading': program\.id/)
3421
3627
  // The mask is the same overlay the compact console uses, on a positioned row.
3422
- assert.match(source, /position: 'relative', overflow: 'hidden' \}\),\n\s*'data-console-on'/)
3628
+ assert.match(source, /position: 'relative', overflow: 'hidden', cursor: 'pointer',\n\s*\}\),\n\s*'data-console-on'/)
3423
3629
  assert.match(source, /PROGRAM_LOADING_CSS/)
3424
3630
  // A transient top-bar note clears itself after 5 seconds.
3425
3631
  assert.match(source, /\}, 5000\)\n\s*return function \(\) \{ clearTimeout\(timer\) \}/)
@@ -3431,7 +3637,12 @@ test('the console row masks itself while a start/stop is in flight', async () =>
3431
3637
  assert.match(source, /'data-program-loading': program\.id/)
3432
3638
  assert.match(source, /className: 'dsh-ris-ide-loading'/)
3433
3639
  assert.match(source, /dshRisIdeSpin/)
3434
- assert.match(source, /alive \? '停止中…' : '启动中…'/)
3640
+ // The label follows the ACTION, not `alive`: debugging a running program used
3641
+ // to flash 停止中 because the host restarts it in place.
3642
+ assert.match(source, /function busyMaskText\(alive, kind\) \{/)
3643
+ assert.match(source, /'data-program-loading-kind': busyKind/)
3644
+ assert.match(source, /'data-program-loading-kind': consoleBusyKind/)
3645
+ assert.doesNotMatch(source, /alive \? '停止中…' : '启动中…'/)
3435
3646
  // The mask swallows the click, and the row is the containing block for it.
3436
3647
  assert.match(source, /onClick: function \(event\) \{ event\.stopPropagation\(\); event\.preventDefault\(\) \}/)
3437
3648
  assert.match(source, /position: 'relative', overflow: 'hidden'/)
@@ -3642,6 +3853,16 @@ test('Ctrl+F searches what the editor, log or fallback editor has highlighted',
3642
3853
  assert.match(chunk, /search: picked/)
3643
3854
  const seeded = chunk.split('searchSelectedText(instance);').length - 1
3644
3855
  assert.ok(seeded >= 2, 'both the menu item and the Mod-f keymap seed the query from the selection')
3856
+ // Automatic searches start at the file top: the first occurrence wins, not the
3857
+ // next one after a caret parked deep in the document.
3858
+ assert.match(chunkSource, /function findFirstFromStart\(view\) \{\n\s*view\.dispatch\(\{ selection: \{ anchor: 0 \} \}\)\n\s*findNext\(view\)/)
3859
+ assert.match(chunkSource, /if \(jump\) findFirstFromStart\(view\)/)
3860
+ assert.match(chunkSource, /const seeded = searchSelectedText\(instance\); openSearchPanel\(instance\); if \(seeded\) findFirstFromStart\(instance\)/)
3861
+ assert.match(chunk, /function findFirstFromStart\(view\)/)
3862
+ assert.match(chunk, /if \(jump\) findFirstFromStart\(view\)/)
3863
+ // A handed-over hit still starts at ITS line (that is the point of clicking it).
3864
+ assert.match(chunkSource, /if \(typeof line === 'number' && Number\.isFinite\(line\) && line > 0\) \{/)
3865
+ assert.match(chunkSource, /No hit line to honour: an automatic search starts from the file's top/)
3645
3866
 
3646
3867
  // Log viewer + plain-text fallback editor: their own find bars get the highlight.
3647
3868
  assert.match(source, /function selectedLineTextIn\(element\)/)
@@ -3678,6 +3899,31 @@ test('an oversized text file opens a read-only windowed preview', async () => {
3678
3899
  assert.match(source, /function reloadLargeTextFromStart\(path\)/)
3679
3900
  assert.match(source, /'data-large-text-restart': '1'/)
3680
3901
  assert.match(source, /已释放前面 ' \+ dropLines \+ ' 行/)
3902
+ // 回归:`loadLargeTextPage` 读 `docsRef`,而 too-large 分支里的 `setDocs` 还没提交,
3903
+ // 当场调用只会看到 undefined 然后静默返回(预览停在「已加载 0 KB」)。必须等提交。
3904
+ assert.match(source, /function startFirstPage\(attempt\) \{/)
3905
+ assert.match(source, /if \(current !== undefined && current\.kind === 'large-text'\) \{/)
3906
+ assert.match(source, /startFirstPage\(0\)/)
3907
+ // 首帧/未填满也必须拉下一页(否则没有滚动条,滚动事件永远不来)。
3908
+ assert.match(source, /if \(box\.scrollHeight <= box\.clientHeight \+ 240\) props\.onLoadMore\(\)/)
3909
+ assert.match(source, /\}, \[doc\.text, doc\.loading, doc\.eof, doc\.error, doc\.size\]\)/)
3910
+ // The preview's right end carries a 编辑 button that force-loads the whole file
3911
+ // and hands it to the normal editor (the preview buffer frees its front, so this
3912
+ // has to re-read the file; the path is remembered so reopening stays editable).
3913
+ assert.match(source, /'data-large-text-edit': '1'/)
3914
+ assert.match(source, /if \(typeof props\.onForceEdit === 'function'\) props\.onForceEdit\(\)/)
3915
+ assert.match(source, /onForceEdit: function \(\) \{ void forceEditLargeText\(path\) \}/)
3916
+ assert.match(source, /var LARGE_TEXT_FORCE_MAX_BYTES = 32 \* 1024 \* 1024/)
3917
+ assert.match(source, /async function readWholeFileText\(path\)/)
3918
+ assert.match(source, /if \(page\.eof === true \|\| typeof page\.next !== 'number' \|\| page\.next <= from\) break/)
3919
+ assert.match(source, /async function forceEditLargeText\(path\)/)
3920
+ assert.match(source, /forceEditPathsRef\.current\.add\(path\)/)
3921
+ assert.match(source, /next\[path\] = \{ kind: 'text', text: normalized, saved: normalized, eol: eol \}/)
3922
+ assert.match(source, /已全量加载并进入编辑:' \+ fileBaseName\(path\)/)
3923
+ assert.match(source, /不能强制全量编辑;右端按钮上限 /)
3924
+ // Reopening a forced path skips the preview and loads the whole thing again.
3925
+ assert.match(source, /if \(code === 'too-large' && forceEditPathsRef\.current\.has\(path\)\) \{/)
3926
+ assert.match(source, /setTimeout\(function \(\) \{ void forceEditLargeText\(path\) \}, 50\)/)
3681
3927
  })
3682
3928
 
3683
3929
  test('trimLargeTextFront frees whole lines and keeps the line count aligned', () => {
@@ -3699,7 +3945,10 @@ test('the editor scrollbars are visible and a start re-reads its log', async ()
3699
3945
  assert.match(source, /var SCROLLBAR_CSS = /)
3700
3946
  assert.match(source, /::-webkit-scrollbar\{width:10px;height:10px\}/)
3701
3947
  assert.match(source, /::-webkit-scrollbar-thumb/)
3702
- assert.match(source, /SELECTION_CSS \+ SCROLLBAR_CSS \+ TOAST_CSS/, 'injected with the panel styles')
3948
+ const scrollbarCss = source.slice(source.indexOf('var SCROLLBAR_CSS'), source.indexOf('var SEARCH_PANEL_CSS'))
3949
+ assert.match(scrollbarCss, /rgba\(140,140,140,0\.45\)/, 'a neutral light-grey thumb')
3950
+ assert.doesNotMatch(scrollbarCss, /86,182,194/, 'the bars no longer use the teal accent')
3951
+ assert.match(source, /SELECTION_CSS \+ SCROLLBAR_CSS \+ SEARCH_PANEL_CSS \+ TOAST_CSS/, 'injected with the panel styles')
3703
3952
  assert.doesNotMatch(source, /SCROLLBAR_CSS[\s\S]{0,800}?scrollbar-gutter/, 'no empty gutter on files that do not overflow')
3704
3953
  // BUG6: a start records a size baseline and watches for its first new byte …
3705
3954
  assert.match(source, /async function consoleStart\(program\) \{[\s\S]{0,700}?await logSizeOf\(logPath\)/, 'the start records a size baseline')
@@ -3716,3 +3965,257 @@ test('the editor scrollbars are visible and a start re-reads its log', async ()
3716
3965
  const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
3717
3966
  assert.match(host, /if \(text !== '' && send\('append', \{ ok: true, text \}\) === false\) \{[\s\S]{0,200}?await snapshot\(\)/, 'a dropped frame re-snapshots')
3718
3967
  })
3968
+
3969
+ test('Ctrl+D deletes the current line in the CodeMirror editor', async () => {
3970
+ const { readFile } = await import('node:fs/promises')
3971
+ const src = await readFile(new URL('../src/chunks/codemirror.js', import.meta.url), 'utf8')
3972
+ const built = await readFile(new URL('../lib/client-codemirror.js', import.meta.url), 'utf8')
3973
+ // VS Code muscle memory: Ctrl/Cmd+D removes the line under the cursor. The
3974
+ // binding has to sit BEFORE `...searchKeymap`, whose own Mod-d is
3975
+ // selectNextOccurrence — the first binding that returns true wins.
3976
+ const custom = src.indexOf("{ key: 'Mod-d', preventDefault: true, run: deleteLine }")
3977
+ assert.ok(custom !== -1, 'the source binds Mod-d to deleteLine')
3978
+ assert.ok(custom < src.indexOf('...searchKeymap'), "and it outranks searchKeymap's selectNextOccurrence")
3979
+ assert.match(built, /key: "Mod-d",\s*\n\s*preventDefault: true,\s*\n\s*run: deleteLine/, 'the committed chunk ships the binding')
3980
+ // The right-click menu teaches the same chord.
3981
+ assert.match(src, /\{ label: '删除当前行', shortcut: 'Ctrl\+D \/ Ctrl\+Shift\+K'/)
3982
+ assert.match(built, /shortcut: "Ctrl\+D \/ Ctrl\+Shift\+K"/)
3983
+ })
3984
+
3985
+ test('the log level filter keeps ERROR/WARN headers and their indented continuations', () => {
3986
+ const lines = [
3987
+ { level: 'INFO', parts: [{ text: 'ok' }] },
3988
+ { level: 'WARN', parts: [{ text: 'slow' }] },
3989
+ { level: 'ERROR', parts: [{ text: 'boom' }] },
3990
+ { level: undefined, parts: [{ text: ' at a.B(C.java:1)' }] },
3991
+ { level: undefined, parts: [{ text: 'plain note' }] },
3992
+ ]
3993
+ assert.deepEqual(T.filterLogLines(lines, 'all'), lines, 'all means all')
3994
+ assert.deepEqual(T.filterLogLines(lines, 'warn').map(T.logLineText), ['slow', 'boom', ' at a.B(C.java:1)'], 'WARN keeps ERROR and indented stack frames')
3995
+ assert.deepEqual(T.filterLogLines(lines, 'error').map(T.logLineText), ['boom', ' at a.B(C.java:1)'], 'ERROR keeps ERROR and indented stack frames')
3996
+ assert.equal(T.logLineVisible({ level: 'FATAL' }, 'error'), true, 'FATAL counts as an error')
3997
+ assert.equal(T.logLineVisible({ level: 'INFO' }, 'error'), false, 'INFO is filtered out')
3998
+ })
3999
+
4000
+ test('the diff and test panes float over a still-mounted editor', async () => {
4001
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4002
+ // The editor must NOT be swapped out (a remount would drop CodeMirror's undo
4003
+ // history), so the panes are siblings rendered after `body`.
4004
+ assert.doesNotMatch(source, /testPane !== null \? testPane : diffPane !== null \? diffPane : body/,
4005
+ 'the editor is never replaced by an overlay')
4006
+ assert.match(source, /body,\n\s+previewing \? previewPaneNode\(\) : null,\n\s+diffPane,\n\s+testPane,\n\s+previewToggleBar\(\)\)\)/,
4007
+ 'both panes render on top of the mounted editor, with the preview chip last')
4008
+ // The panes are column stacks with a scrollable pre, not the centred media
4009
+ // wrapper that clipped the diff to the right half.
4010
+ assert.match(source, /style: S\.paneOverlay, 'data-editor-diff'/)
4011
+ assert.match(source, /style: S\.paneOverlay, 'data-test-pane'/)
4012
+ assert.match(source, /style: S\.paneScroll,\n\s+'data-diff-body'/)
4013
+ // Two gutters (old → new) per row.
4014
+ assert.match(source, /h\('span', \{ style: S\.diffNum \}, row\.kind === 'add' \? '' : String\(oldLine\)\)/)
4015
+ assert.match(source, /h\('span', \{ style: S\.diffNum \}, row\.kind === 'del' \? '' : String\(newLine\)\)/)
4016
+ })
4017
+
4018
+ test('the sidebar console opens the config as a sidebar file resource', async () => {
4019
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4020
+ // The right-sidebar tab body hands the panel the client ctx, so the compact
4021
+ // console can reach `sidebarRight.openResource` (a workbench is never mounted
4022
+ // there — the old code handed the path to a workbench that did not exist).
4023
+ assert.match(source, /h\(ProgramsPanel, Object\.assign\(\{\}, props, \{ clientCtx: ctx \}\)\)/)
4024
+ assert.match(source, /typeof sidebar\.openResource === 'function'/)
4025
+ assert.match(source, /sidebar\.openResource\(officialPreviewAddress\(\{ sessionId: sessionId, cwd: cwd \}, path\)\)/)
4026
+ assert.match(source, /已在右侧栏打开 /, 'the console reports where the config went')
4027
+ })
4028
+
4029
+ test('the mask names the action and a window opened on a program auto-debugs it', async () => {
4030
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4031
+
4032
+ // The mask label follows the ACTION. Deriving it from `alive` made a debug
4033
+ // restart of a running program say 停止中 — the host stops it on the way.
4034
+ assert.equal(T.busyMaskText(true, 'debug'), '调试中…')
4035
+ assert.equal(T.busyMaskText(true, 'stop'), '停止中…')
4036
+ assert.equal(T.busyMaskText(true, 'restart'), '重启中…')
4037
+ assert.equal(T.busyMaskText(false, 'start'), '启动中…')
4038
+ assert.equal(T.busyMaskText(true, 'start'), '停止中…', 'a stale `alive` still reads as a stop')
4039
+ // The tooltip spells out the action: "正在调试中" read like a plain stop.
4040
+ assert.equal(T.busyMaskTitle(true, 'debug', 'ris-codegen'), '正在以调试模式重启 ris-codegen…')
4041
+ assert.equal(T.busyMaskTitle(true, 'restart', 'x'), '正在重启 x…')
4042
+ assert.equal(T.busyMaskTitle(true, 'stop', 'x'), '正在停止 x…')
4043
+ assert.equal(T.busyMaskTitle(false, 'start', 'x'), '正在启动 x…')
4044
+ assert.doesNotMatch(source, /'正在' \+ busyMaskText/)
4045
+ assert.match(source, /var \[consoleBusyKind, setConsoleBusyKind\] = useState\(''\)/)
4046
+ assert.match(source, /var \[busyKind, setBusyKind\] = useState\(''\)/)
4047
+ assert.match(source, /setConsoleBusyKind\('debug'\)/)
4048
+
4049
+ // The standalone window carries its target row as a prop: the tab meta is
4050
+ // workspace-level, so `meta.autoDebug` never arrived and the 🐞 button opened
4051
+ // a window that did NOT start debugging.
4052
+ assert.match(source, /var openProgram = props !== null && props !== undefined && props\.openProgram !== null/)
4053
+ assert.match(source, /useState\(metaLogPath !== '' \? metaLogPath : openLogPath\)/, 'the pane opens on that program\'s log')
4054
+ assert.match(source, /openProgram: active !== null && active !== undefined && typeof active === 'object' \? active : null/)
4055
+ const effect = source.slice(source.indexOf('var autoDebugRef = useRef('), source.indexOf('// ── small pieces'))
4056
+ // It must wait for the row instead of firing on an empty program list.
4057
+ assert.match(effect, /\[debuggable, debugProgramId, ui\.busy, sessionId\]/)
4058
+ assert.match(effect, /debugProgramId === undefined/, 'waits until the row is known')
4059
+ assert.match(effect, /autoDebugRef\.current = false/)
4060
+ assert.match(effect, /void startDebug\(\)/)
4061
+ })
4062
+
4063
+ test('search hits survive a pick and the shortcut selects the query', async () => {
4064
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4065
+ const cache = new Map()
4066
+ assert.equal(T.rememberSearchEntry(cache, 'name:a', { matches: ['a'] }, 2), cache)
4067
+ T.rememberSearchEntry(cache, 'content:a', [{ path: 'a' }], 2)
4068
+ T.rememberSearchEntry(cache, 'name:ab', { matches: ['ab'] }, 2)
4069
+ assert.deepEqual([...cache.keys()], ['content:a', 'name:ab'], 'the oldest entry is evicted past the limit')
4070
+ T.rememberSearchEntry(cache, 'content:a', [], 2)
4071
+ assert.deepEqual([...cache.keys()], ['name:ab', 'content:a'], 'a touched key moves to the newest slot')
4072
+
4073
+ // Picking a row must NOT wipe the query/results (reopen the same hit for free).
4074
+ const pick = source.slice(source.indexOf('function pickSearchHit('), source.indexOf('function openContentHit('))
4075
+ assert.doesNotMatch(pick, /setTreeQuery\(''\)/, 'the query stays after a pick')
4076
+ assert.doesNotMatch(pick, /setSearchHits\(null\)/, 'the result set stays after a pick')
4077
+ const contentPick = source.slice(source.indexOf('function openContentHit('), source.indexOf('var runningSignature'))
4078
+ assert.doesNotMatch(contentPick, /setTreeQuery\(''\)/, 'a content pick keeps the query too')
4079
+ // Both searches cache their payloads keyed by the query text.
4080
+ assert.match(source, /searchCacheRef\.current\.get\('name:' \+ text\)/)
4081
+ assert.match(source, /rememberSearchEntry\(searchCacheRef\.current, 'content:' \+ text/)
4082
+ // The shortcut focuses THROUGH an effect so select() survives the repaint.
4083
+ assert.match(source, /searchFocusPendingRef\.current = true/)
4084
+ // The dropdown is focus-owned: a pick blurs the box, so re-clicking it fires
4085
+ // focus again and shows the cached rows.
4086
+ assert.match(pick, /searchInputRef\.current\.blur\(\)/, 'a pick blurs the box')
4087
+ assert.match(source, /searchFocused !== true\n\s+\? null/, 'the dropdown only renders while focused')
4088
+ // A content pick must survive a non-promise `openPath` and a late-registering
4089
+ // viewer: retry a few frames, then forward the query into the editor's find.
4090
+ assert.doesNotMatch(source, /void openPath\(path\)\.then\(/)
4091
+ assert.match(source, /function applyFind\(attempt\)/)
4092
+ assert.match(source, /typeof opened\.then === 'function'/)
4093
+ assert.match(source, /controls\.searchFor\(needle, hit\.line\)/)
4094
+ // A viewer that registers late still receives the pending find (chunk load).
4095
+ assert.match(source, /pendingFindRef\.current\[path\] = \{ needle: needle, line: hit\.line \}/)
4096
+ assert.match(source, /var pending = pendingFindRef\.current\[path\]/)
4097
+ // Synthetic window-target events must not make `contains` throw a UI toast.
4098
+ assert.match(source, /typeof target\.nodeType !== 'number'\) return false/)
4099
+ assert.match(source, /input\.focus\(\)\n\s+input\.select\(\)/)
4100
+ assert.match(source, /\[searchFocusNonce, treeQuery\]/, 'the select effect runs after the value paints')
4101
+ })
4102
+
4103
+ test('the editor find panel matches the IDE chrome', async () => {
4104
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4105
+ assert.match(source, /var SEARCH_PANEL_CSS = /)
4106
+ const css = source.slice(source.indexOf('var SEARCH_PANEL_CSS'), source.indexOf('var SELECTION_CSS'))
4107
+ // Two rows in one grid: both inputs sit in the same 1fr column (equal width) and
4108
+ // the buttons in six fixed 24px columns, so find-row and replace-row line up.
4109
+ assert.match(css, /\[data-workbench="ris-ide"\] \.cm-search\{display:grid;grid-template-columns:minmax\(0,1fr\) repeat\(6,24px\)/)
4110
+ assert.match(css, /\[data-workbench="ris-ide"\] \.cm-search input\{grid-column:1;width:100%;min-width:0/)
4111
+ assert.match(css, /\[data-workbench="ris-ide"\] \.cm-search button\{height:22px;width:24px/)
4112
+ assert.match(css, /button\[aria-pressed="true"\]\{background:rgba\(86,182,194,0\.30\)/)
4113
+ // Count on the replace row, between the input column and the replace buttons.
4114
+ assert.match(css, /\.dsh-find-count\{grid-row:2;grid-column:2 \/ span 4/)
4115
+ assert.match(css, /background:color-mix\(in srgb, currentColor 6%, transparent\) !important/)
4116
+ assert.match(css, /background-image:none !important/, 'CM gradient buttons are neutralised')
4117
+ assert.match(css, /\.cm-searchMatch-selected\{background:rgba\(255,150,40,0\.42\)/)
4118
+ // The panel itself is the IDE's own (chunk-side), not CodeMirror's built-in one.
4119
+ const chunkSource = await readFile(new URL('../src/chunks/codemirror.js', import.meta.url), 'utf8')
4120
+ const chunkBuilt = await readFile(new URL('../lib/client-codemirror.js', import.meta.url), 'utf8')
4121
+ assert.match(chunkSource, /search\(\{ top: true, createPanel: ideFindPanel \}\)/)
4122
+ assert.match(chunkBuilt, /createPanel: ideFindPanel/)
4123
+ assert.match(chunkSource, /const searchInput = makeInput\('search'/)
4124
+ assert.match(chunkSource, /const replaceInput = makeInput\('replace'/)
4125
+ assert.match(chunkSource, /const replaceButton = makeButton\('replace'/)
4126
+ assert.match(chunkSource, /const replaceAllButton = makeButton\('replace-all'/)
4127
+ assert.match(chunkSource, /setAttribute\('aria-pressed'/, 'toggles report their state')
4128
+ assert.match(chunkSource, /const apply = \(patch, jump\) =>/, 'one query-commit helper drives every control')
4129
+ assert.match(chunkBuilt, /data-find-action/)
4130
+ assert.match(source, /SELECTION_CSS \+ SCROLLBAR_CSS \+ SEARCH_PANEL_CSS \+ TOAST_CSS/, 'injected with the panel styles')
4131
+ // The content search drives the panel through the registered CM handle.
4132
+ assert.match(source, /props\.onToolbarControls\(handle\)/, 'the CM handle is registered')
4133
+ assert.match(source, /props\.onToolbarControls\(null\)/, 'and unregistered on destroy')
4134
+ })
4135
+
4136
+ test('the search dropdown paints a window and appends rows on scroll', async () => {
4137
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4138
+ // Hundreds of content hits used to be painted in full on every re-open of the
4139
+ // box; the dropdown now slices the row model and grows it near the bottom.
4140
+ assert.match(source, /var SEARCH_ROWS_FIRST = 40/)
4141
+ assert.match(source, /var SEARCH_ROWS_MORE = 60/)
4142
+ assert.match(source, /rows\.slice\(0, rowLimit\)\.map\(function \(row\) \{/)
4143
+ assert.match(source, /rowsNode\.push\(h\('div', \{[\s\S]{0,200}'data-search-more'/, 'a truncated list says how many rows are left')
4144
+ assert.match(source, /'data-search-more': String\(rows\.length - rowLimit\)/)
4145
+ assert.match(source, /if \(box\.scrollTop \+ box\.clientHeight < box\.scrollHeight - 120\) return/, 'near the bottom appends')
4146
+ assert.match(source, /setRowLimit\(Math\.min\(rows\.length, rowLimit \+ SEARCH_ROWS_MORE\)\)/)
4147
+ assert.match(source, /if \(active < 0 \|\| active < rowLimit\) return[\s\S]{0,200}setRowLimit\(Math\.min\(rows\.length, Math\.max\(rowLimit \+ SEARCH_ROWS_MORE, active \+ 1\)\)\)/,
4148
+ 'the keyboard widens the window instead of walking past the drawn rows')
4149
+ })
4150
+
4151
+ test('the diff pane shows added, removed and unchanged lines', () => {
4152
+ const rows = T.lineDiff('a\nb\nc', 'a\nB\nc\nd')
4153
+ const kinds = rows.map((row) => row.kind + ':' + row.text)
4154
+ // The LCS walks backwards and emits the ADD first when a line was replaced,
4155
+ // so the diff reads "+B" above "-b".
4156
+ assert.deepEqual(kinds, ['same:a', 'add:B', 'del:b', 'same:c', 'add:d'])
4157
+ assert.deepEqual(T.lineDiff('', ''), [], 'identical empty documents have no rows')
4158
+ })
4159
+
4160
+ test('a Java test file resolves to a reactor root, module and class selector', () => {
4161
+ const cwd = '/w'
4162
+ const target = T.testRunTarget('/w/ris/ris-model/ris-model-biz/src/test/java/cn/com/ris/DemoTest.java', cwd)
4163
+ assert.deepEqual(target, {
4164
+ reactorCwd: '/w/ris',
4165
+ module: 'ris-model/ris-model-biz',
4166
+ test: 'cn.com.ris.DemoTest',
4167
+ className: 'cn.com.ris.DemoTest',
4168
+ })
4169
+ assert.equal(T.testRunTarget('/w/ris/ris-model/ris-model-biz/src/main/java/A.java', cwd), null, 'main sources are not tests')
4170
+ assert.equal(T.testRunTarget('/w/ris/DemoTest.java', cwd), null, 'a file outside src/test/java has no target')
4171
+ assert.equal(T.testRunTarget('/etc/DemoTest.java', cwd), null, 'files outside the workspace are ignored')
4172
+ const rootModule = T.testRunTarget('/w/ris/src/test/java/A.java', cwd)
4173
+ assert.equal(rootModule.module, '.', 'a reactor-root test uses -pl .')
4174
+ })
4175
+
4176
+ test('content hits render in the same dropdown, with line numbers and the content row', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
4177
+ const { renderToStaticMarkup } = require(`${REACT_ROOT}/react-dom/server`)
4178
+ const markup = renderToStaticMarkup(React.createElement(T.SearchResults, {
4179
+ hits: { matches: ['/w/A.java'], dirs: {} },
4180
+ content: [{ path: '/w/A.java', line: 12, text: 'return value;' }],
4181
+ query: 'value',
4182
+ fontRatio: 1,
4183
+ }))
4184
+ assert.match(markup, /匹配 2 个/, 'one file row + one content row')
4185
+ assert.match(markup, /(文件 1 · 内容 1 处)/, 'the header breaks the count down')
4186
+ assert.match(markup, /data-search-hit="content"[^>]*data-search-line="12"/, 'the content row carries its line number')
4187
+ assert.match(markup, /data-search-hit-icon="content"/, 'content rows have their own icon')
4188
+ })
4189
+
4190
+ test('a dialog keeps the anchor it opened at when the pointer moves or clicks again', async () => {
4191
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4192
+ // The point is frozen on open, not read live on every render: a second
4193
+ // pointerdown used to re-anchor the dialog and it jumped out from the cursor.
4194
+ assert.match(source, /var dialogPointRef = useRef\(null\)/, 'a frozen anchor ref exists')
4195
+ assert.match(source, /var anyDialogOpen = prompt !== null \|\| pendingDelete !== null/, 'opening is detected from both dialogs')
4196
+ assert.match(source, /if \(anyDialogOpen === false\) dialogPointRef\.current = null/, 'closing releases the anchor')
4197
+ assert.match(source, /else if \(dialogPointRef\.current === null && pointerRef\.current !== null\) dialogPointRef\.current = pointerRef\.current/, 'opening pins the pointer once')
4198
+ const anchorFn = source.slice(source.indexOf('function dialogAnchor('), source.indexOf('function dialogAnchor(') + 700)
4199
+ assert.match(anchorFn, /var point = dialogPointRef\.current/, 'dialogAnchor reads the frozen point')
4200
+ assert.doesNotMatch(anchorFn, /var point = pointerRef\.current/, 'dialogAnchor no longer reads the live pointer')
4201
+ })
4202
+
4203
+ test('a folder row only expands; the context menu\'s 进入 re-roots with an 上级 row to walk back', async () => {
4204
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4205
+ const region = source.slice(source.indexOf('function IdeTree('), source.indexOf('function IdeEditor('))
4206
+ assert.match(region, /var \[rootTrail, setRootTrail\] = useState\(\[\]\)/, 'the tree keeps a root stack')
4207
+ assert.match(region, /var activeRoot = rootTrail\.length > 0 \? rootTrail\[rootTrail\.length - 1\] : rootPath/, 'the last stack entry is the rendered root')
4208
+ assert.match(region, /void loadLevel\(activeRoot, false\)\s*\}, \[activeRoot\]\)/, 'a new root loads itself')
4209
+ assert.match(region, /function openDirRoot\(path\) \{/, 'the deliberate gesture re-roots the tree')
4210
+ assert.match(region, /function closeDirRoot\(\) \{/, 'the 上级 row pops one level')
4211
+ assert.match(region, /toggle\(entry\)\n\s*if \(treeListRef\.current !== null\) treeListRef\.current\.focus/, 'a folder click expands like its twisty')
4212
+ assert.doesNotMatch(region, /onDoubleClick:/, 'no hidden double-click gesture')
4213
+ assert.match(region, /'data-tree-action': 'enter-dir'/, 'the context menu carries an explicit 进入 entry')
4214
+ assert.match(region, /onClick: function \(\) \{ openDirRoot\(treeMenu\.entry\.path\) \}/, '进入 re-roots the tree')
4215
+ assert.match(region, /'data-tree-submenu-panel': 'new'/, '新建文件 opens a flyout panel')
4216
+ assert.match(region, /setMenuSub\(\{ left: Math\.round\(rect\.width\), top: Math\.round\(rect\.top - treeMenu\.y\) \}\)/, 'the flyout anchors to the menu')
4217
+ assert.match(region, /'data-tree-up': '1'/, 'the 上级 row is rendered when the root stack is non-empty')
4218
+ assert.match(region, /'data-tree-root': activeRoot,/, 'the list announces the active root')
4219
+ assert.match(region, /if \(locateRequest\.kind === 'dir'\) openDirRoot\(locateRequest\.path\)/, 'picking a folder search hit re-roots too')
4220
+ assert.match(region, /walk\(activeRoot, 0, \{\}\)/, 'Ctrl+A walks the active root')
4221
+ })