dsh-ris-ide 1.8.4 → 1.8.6

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.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-ris-ide",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "license": "MIT",
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 窗口。",
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. \u00b7 DSH \u53f3\u4fa7\u680f\u672c\u5730\u5f00\u53d1\u9762\u677f\uff1a\u65e5\u5fd7\u5b9e\u65f6\u8ddf\u968f\u3001\u4e00\u952e\u542f\u505c\u672c\u5730\u7a0b\u5e8f\u3001Java \u65ad\u70b9\u8c03\u8bd5\u3001\u6587\u4ef6\u6811\u4e0e\u7f16\u8f91\u5668\u3001\u72ec\u7acb IDE \u7a97\u53e3\u3002",
6
6
  "keywords": [
7
7
  "dsh",
8
8
  "dsh-plugin",
@@ -107,6 +107,9 @@ test('a stale page offers a refresh and never reloads itself', () => {
107
107
  test('the stale-build bar carries a refresh button', () => {
108
108
  const source = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
109
109
  const notice = source.slice(source.indexOf('function showStaleBuildNotice'), source.indexOf('function watchClientBuild'))
110
+ // m06203: dsh端取消 —— the DSH page hosts this panel in its right sidebar, and the
111
+ // banner's only action is a full-page reload there, so it is standalone-only.
112
+ assert.match(notice, /if \(!inStandaloneIdeWindow\(\)\) return/)
110
113
  assert.match(notice, /textContent = '刷新'/)
111
114
  assert.match(notice, /location\.reload\(\)/, 'the reload happens only when the user clicks it')
112
115
  assert.match(notice, /staleNoticeDismissedFor = staleNoticeBuild/)
@@ -1643,6 +1643,100 @@ test('the selected range is highlighted stronger than the other matches', async
1643
1643
  assert.match(chunk, /dsh-ris-ide-has-selection/, 'the editor marks itself while a selection exists')
1644
1644
  })
1645
1645
 
1646
+ // 2026-11-16: Ctrl/Cmd-hover underlines every occurrence of the identifier and
1647
+ // Ctrl/Cmd+click goes to the declaration — Tier 0 of the no-index plan (the
1648
+ // file's own text plus package/import mapping; no repository scan, no compile).
1649
+ test('Ctrl+click jumps to declarations without an index', async () => {
1650
+ const { readFile } = await import('node:fs/promises')
1651
+ const chunk = await readFile(new URL('../lib/client-codemirror.js', import.meta.url), 'utf8')
1652
+ assert.match(chunk, /cm-symbol-hit/, 'hovered identifiers are underlined')
1653
+ assert.match(chunk, /symbolHighlightEffect/, 'the highlight is a state effect (clears on modifier release)')
1654
+ assert.match(chunk, /revealSymbol/, 'the handle can reveal a declaration by name')
1655
+ assert.match(chunk, /annotationContextAt\(view, pos, word\)/, 'the editor recognises annotation attributes')
1656
+ assert.match(chunk, /findAnnotationMemberDeclaration\(view, member\)/, 'annotation attribute declarations are locatable')
1657
+ assert.match(chunk, /revealLine/, 'the handle can reveal a line/column')
1658
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1659
+ assert.match(source, /onSymbolJump: jumpToSymbolInProject/, 'cross-file type jumps reach the workbench')
1660
+ assert.match(source, /function javaTypeCandidates\(cwd, fromPath, text, name\)/, 'package/import → path mapping')
1661
+ assert.match(source, /controls\.revealSymbol\(name, member === '' \? undefined : member\)/, 'the opened file reveals the type declaration (or the annotation attribute)')
1662
+ assert.match(source, /'\/src\/main\/java\/'/, 'Maven/Gradle source roots win over the workspace root (m04067)')
1663
+ })
1664
+
1665
+ test('cross-project and dependency symbols resolve by their last name segment (m04476)', async () => {
1666
+ const { readFile } = await import('node:fs/promises')
1667
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1668
+ assert.match(source, /function javaPackagePath\(text\)/, 'the package path is shared by the candidates and the fallback search')
1669
+ assert.match(source, /fsSearch\(scopeRef\.current, name \+ '\.java'\)/, 'an imported name is located by its last segment anywhere in the workspace')
1670
+ assert.match(source, /function javaTypeFqn\(text, name\)/, 'the click resolves a fully-qualified name before asking the host')
1671
+ assert.match(source, /fsDependencySource\(scopeRef\.current, fqn, logPath\)/, 'a jar class falls back to the debugger source pipeline by its FQN')
1672
+ assert.match(source, /var knownDependencyDoc = docsRef\.current\[dependencyPath\]/, 'an already-open dependency tab is noticed')
1673
+ assert.match(source, /reloadPath\(dependencyPath\)/, 'a new dependency jar version must re-read the cached file instead of showing the old text')
1674
+ assert.match(source, /remembered\.indexOf\('\/\.dsh-ris-ide\/cache\/'\)/, 'a remembered dependency source is re-resolved so an upgraded jar is noticed')
1675
+ const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
1676
+ assert.match(host, /const DECOMPILE_TIMEOUT_MS = 30 \* 1000/, 'a wedged decompiler jar cannot hang /debug/source forever')
1677
+ assert.match(host, /const JAVAP_TIMEOUT_MS = 15 \* 1000/, 'javap is bounded too')
1678
+ assert.match(host, /child\.kill\('SIGKILL'\)/, 'the timed-out child is actually killed')
1679
+ assert.match(host, /timedOut: true/, 'the caller can tell a timeout from a failure')
1680
+ assert.match(host, /const CLASS_JAR_CACHE = new Map\(\)/, 'repeated dependency jumps do not rescan every classpath jar')
1681
+ const chunk = await readFile(new URL('../lib/client-codemirror.js', import.meta.url), 'utf8')
1682
+ assert.ok(chunk.includes(String.raw`[\\w$]+\\.`), 'javap FQN headers still count as the type declaration')
1683
+ })
1684
+
1685
+ test('a class outside every program log still resolves: workspace classpath, then the JDK (m05797)', async () => {
1686
+ const { readFile } = await import('node:fs/promises')
1687
+ const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
1688
+ assert.match(host, /async function resolveDependencySourceIn\(cwd, dirs, className\)/, 'every workspace classpath file is tried for a class clicked outside a started program')
1689
+ assert.match(host, /async function findDependencyJarIn\(dirs, className\)/, 'the background sources job still knows which jar was clicked')
1690
+ assert.match(host, /async function resolveJdkSource\(cwd, className\)/, 'platform classes fall back to the JDK itself')
1691
+ assert.match(host, /function jdkSourcesArchives\(/, 'the JDK src.zip is preferred when the distribution ships one')
1692
+ assert.match(host, /runCapture\('javap', \['-p', '-c', '-l', className\]/, 'javap without a classpath reads the running module path')
1693
+ // Only the JDWP debug routes still require a program log; both dependency
1694
+ // routes accept a missing `path` (a class clicked in a module never started).
1695
+ assert.equal((host.match(/path \(the program log path\) is required/g) ?? []).length, 2, 'the dependency routes no longer require a program log')
1696
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1697
+ assert.match(source, /var logPath = dependencyLogPath\(fromPath\)\n\s+var fqn = javaTypeFqn\(text, name\)/, 'a missing log path does not abort the dependency route')
1698
+ assert.match(source, /statusNote\('正在解析 ' \+ fqn/, 'the note no longer claims the workspace search gave up')
1699
+ // Symbol-navigation messages belong in the bottom status bar, not toasts (m05950):
1700
+ // the transient area sits right after the "文件 x/20" counter and statusNote()
1701
+ // replaces the previous message and clears itself after a few seconds.
1702
+ assert.doesNotMatch(source, /note\('正在解析/, 'resolving a dependency never pops a toast')
1703
+ assert.doesNotMatch(source, /note\('找不到 ' \+ name/, 'a search miss never pops a toast')
1704
+ assert.ok(source.includes("statusNote('找不到 ' + name + ' 的声明'"), 'a search miss lands in the status bar instead')
1705
+ const fileCounter = source.indexOf("' · 文件 ' + openFiles.length")
1706
+ const statusArea = source.indexOf("'data-ide-status-text'")
1707
+ assert.ok(fileCounter >= 0 && statusArea > fileCounter && statusArea - fileCounter < 900, 'the transient status area follows the file counter')
1708
+ const chunk = await readFile(new URL('../lib/client-codemirror.js', import.meta.url), 'utf8')
1709
+ assert.match(chunk, /function symbolDrillWord\(view, pos\)/, 'a package line is not a symbol and only the last import segment is drillable')
1710
+ assert.match(chunk, /trimmed\.startsWith\(["']package["']\)/, 'package lines never highlight or jump')
1711
+ assert.match(source, /function symbolNavigationPath\(path\)/, 'symbol navigation is decided per document path')
1712
+ assert.match(source, /symbolNavigation: symbolNavigationPath\(/, 'only java/class tabs turn the feature on')
1713
+ assert.match(chunk, /options\.symbolNavigation === false/, 'a non-java tab never attaches the hover plugin or the click handler')
1714
+ })
1715
+
1716
+ test('a missing sources jar is fetched in the background while the decompiled text opens (m05238)', async () => {
1717
+ const { readFile } = await import('node:fs/promises')
1718
+ const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
1719
+ assert.match(host, /const DEBUG_SOURCE_STATUS_PATH = /, 'the editor can poll for the downloaded sources')
1720
+ assert.match(host, /payload\.sourcePending = true/, 'the decompiled answer carries sourcePending')
1721
+ assert.match(host, /'dependency:sources'/, 'Maven is the download mechanism (the workspace pom decides the repository)')
1722
+ assert.match(host, /-DincludeArtifactIds=/, 'only the artifact that was actually clicked is fetched')
1723
+ assert.match(host, /const SOURCE_FETCH_TIMEOUT_MS = 120 \* 1000/, 'a wedged mvn cannot hang the background job forever')
1724
+ assert.match(host, /function startSourceFetch\(cwd, programDir, jarPath\)/, 'one background job per jar')
1725
+ assert.match(host, /const mvnDir = nearestPomDir\(programDir\)/, 'Maven resolves the clicked dependency from the module POM, so the version is the one this build uses')
1726
+ assert.match(host, /async function serveDebugSourceStatus\(/, 'the status route exists')
1727
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
1728
+ assert.match(source, /if \(resolved\.sourcePending === true\) pollDependencySources\(/, 'a pending source starts the poller')
1729
+ assert.match(source, /routeUrl\('dsh-ris-ide\/debug\/source-status'\)/, 'the poller hits the status route')
1730
+ assert.match(source, /'data-source-upgrade': '1'/, 'the banner is rendered above the editor')
1731
+ assert.match(source, /payload\.member/, 'the click payload carries the annotation attribute')
1732
+ assert.match(source, /switchToDependencySource\(upgrade\)/, 'clicking the banner switches to the real sources')
1733
+ assert.match(source, /activePathRef\.current === decompiledPath/, 'the decompiled view switches by itself once the sources land')
1734
+ assert.match(source, /closePath\(upgrade\.decompiledPath\)/, 'the decompiled fallback tab is closed after switching')
1735
+ assert.match(source, /docsRef\.current\[decompiledPath\] === undefined/, 'a closed decompiled tab stops the fetch poller silently')
1736
+ assert.match(source, /sourceUpgrade\.decompiledPath === path\) setSourceUpgrade\(null\)/, 'closing the fallback tab drops its stale banner')
1737
+ assert.match(source, /sourcePending: parsed\.sourcePending === true/, 'the host flag survives the client parser')
1738
+ })
1739
+
1646
1740
  test('the tree clipboard keys only fire while the tree owns the focus', async () => {
1647
1741
  const { readFile } = await import('node:fs/promises')
1648
1742
  const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
@@ -3508,11 +3602,12 @@ test('only a FRONTEND row offers the browser button, and only a yds project prom
3508
3602
  assert.match(source, /event\.stopPropagation\(\); openSite\(program\)/)
3509
3603
  // Errors are told in the panel's note bar, never swallowed.
3510
3604
  assert.match(source, /还没有可打开的地址|这个程序还没有\.\.\./)
3511
- // The token sentence may only appear behind the yds flag: a plain workspace must
3512
- // never read "yds" (m04354).
3605
+ // The yds sentence may only appear behind the yds flag: a plain workspace must
3606
+ // never read "yds" (m04354). It promises the debugging browser now — the 🌐 button
3607
+ // no longer just opens the dev-server page for a yds front-end.
3513
3608
  assert.match(source, /async function requestYdsProject\(scope\)/)
3514
3609
  assert.match(source, /dsh-ris-yds\/probe\?/)
3515
- assert.match(source, /ydsProject \? '(yds 项目:请求自动带上登录 token,免登录)' : ''/)
3610
+ assert.match(source, /ydsProject \? '(yds 项目:点 🌐 用专用调试浏览器打开工作台,模块由扩展指向本地 dev server)' : ''/)
3516
3611
  assert.doesNotMatch(source, /yds 项目会自动注入 YYCToken/, 'the old unconditional yds wording is gone')
3517
3612
  })
3518
3613
 
@@ -3556,12 +3651,12 @@ test('the IDE console opens a frontend page with the same 🌐 as the sidebar (m
3556
3651
  assert.match(busyTag, /disabled=""/)
3557
3652
  assert.match(busy, /…<\/button>/)
3558
3653
 
3559
- // The token sentence only appears for a yds workspace (m04354).
3654
+ // The yds sentence only appears for a yds workspace (m04354).
3560
3655
  const yds = renderWorkbench({
3561
3656
  ydsProject: true,
3562
3657
  programs: [{ id: 'frontend:ui#dev', name: 'ris-ui-3', kind: 'frontend', logPath: '/w/logs/ui.log', running: { alive: true } }],
3563
3658
  })
3564
- assert.match(yds, /yds 项目:请求自动带上登录 token,免登录/)
3659
+ assert.match(yds, /yds 项目:点 🌐 用专用调试浏览器打开工作台/)
3565
3660
  })
3566
3661
 
3567
3662
  test('the tab strip shows ⟳ while the buffer is clean and ± once it is dirty (m00388/m00808)', { skip: !reactIsReal ? 'React unavailable for SSR' : false }, () => {
@@ -4510,8 +4605,28 @@ test('a frame without source in the workspace is ignored quietly', async () => {
4510
4605
  assert.doesNotMatch(source, /源码不在工作区/)
4511
4606
  assert.match(source, /'data-missing-source': '1'/)
4512
4607
  assert.match(source, /'无源码 · '/)
4513
- // The miss stays cached so a step storm never re-scans the workspace.
4514
- assert.match(source, /sourcePathRef\.current\[cleaned\] = found === undefined \? null : found/)
4608
+ // A miss is cached for a minute only: `mvn` may still be fetching the sources
4609
+ // jar in the background, so the lookup has to run again later (m06100).
4610
+ assert.match(source, /var sourceMissRef = useRef\(\{\}\)/)
4611
+ assert.match(source, /var SOURCE_MISS_TTL_MS = 60 \* 1000/)
4612
+ assert.match(source, /Date\.now\(\) - missedAt < SOURCE_MISS_TTL_MS/)
4613
+ assert.match(source, /sourceMissRef\.current\[cleaned\] = Date\.now\(\)/)
4614
+ assert.match(source, /sourcePathRef\.current\[cleaned\] = found\n/)
4615
+ assert.doesNotMatch(source, /sourcePathRef\.current\[cleaned\] = found === undefined \? null : found/)
4616
+ })
4617
+
4618
+ test('the debugger shares the click-to-declaration dependency pipeline (m06100)', async () => {
4619
+ const { readFile } = await import('node:fs/promises')
4620
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
4621
+
4622
+ // Same host route, same pending-sources poller and banner as Ctrl/Cmd+click:
4623
+ // the poller lives at workbench scope so both entry points can call it.
4624
+ assert.match(source, /^ function pollDependencySources\(displayName, fqn, logPath, decompiledPath\) \{/m)
4625
+ assert.match(source, /^ function switchToDependencySource\(upgrade\) \{/m)
4626
+ assert.match(source, /var resolved = await fsDependencySource\(scopeRef\.current, cleaned, debugLogPath\)/)
4627
+ assert.match(source, /found = resolved\.path/)
4628
+ assert.match(source, /if \(resolved\.sourcePending === true\) \{/)
4629
+ assert.match(source, /pollDependencySources\(cleaned\.split\('\.'\)\.pop\(\), cleaned, debugLogPath, found\)/)
4515
4630
  })
4516
4631
 
4517
4632
  test('a debug start, stop or resume re-reads the log pane', async () => {
@@ -5378,3 +5493,61 @@ test('the workbench reads its saved blob once per mount and remounts per workspa
5378
5493
  // The compact panel layout is a machine-wide preference on purpose.
5379
5494
  assert.match(source, /Deliberately NOT workspace-scoped/)
5380
5495
  })
5496
+
5497
+ test('member access is classified and inherited members walk the extends chain (m06015)', async () => {
5498
+ const chunk = await readFile(new URL('../lib/client-codemirror.js', import.meta.url), 'utf8')
5499
+ const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
5500
+ // Chunk side: `Receiver.Member` is parsed from the click position and handed to
5501
+ // the core, which knows about imports, parents and dependency sources.
5502
+ assert.match(chunk, /function memberAccessAt\(view, pos\)/, 'Receiver.Member is parsed at the click position')
5503
+ assert.match(chunk, /function jumpToMember\(view, access, options\)/, 'member clicks are handed to the core')
5504
+ assert.match(chunk, /receiver: access\.receiver,/, 'the receiver travels with the member')
5505
+ // Core side: classification + resolution.
5506
+ assert.match(source, /function memberDeclarationIn\(source, member\)/, 'member declarations are classified')
5507
+ assert.match(source, /function javaVariableType\(source, name\)/, 'a variable receiver resolves through its declared type')
5508
+ assert.match(source, /function javaSuperClass\(source\)/, 'the extends chain is followed for inherited fields')
5509
+ assert.match(source, /var receiver = typeof payload\.receiver === 'string'/, 'member payloads take the member route')
5510
+ assert.match(source, /jumpToMemberInProject\(receiver, member, fromPath, text\)/)
5511
+ assert.match(source, /'父类 ' \+ parent/, 'inherited members say which parent declared them')
5512
+ assert.match(source, /label \+ ' · ' \+ describeMember\(decl\)/, 'the status bar states the member kind')
5513
+ assert.match(source, /decl\.static \? '静态方法' : '方法'/, 'static methods are labelled')
5514
+ assert.match(source, /decl\.constant \? '静态常量' : '静态字段'/, 'static final uppercase fields are constants')
5515
+ assert.match(source, /receiver === 'this' \|\| receiver === 'super'/, 'this/super start at the current type')
5516
+
5517
+ // Behaviour: extract the three text helpers and check a small Java sample.
5518
+ function sliceFunction(name) {
5519
+ const start = source.indexOf('function ' + name + '(')
5520
+ assert.ok(start >= 0, name + ' exists')
5521
+ const end = source.indexOf('\n }', start)
5522
+ return source.slice(start, end + 6)
5523
+ }
5524
+ const helpers = new Function(
5525
+ sliceFunction('memberDeclarationIn') + '\n' + sliceFunction('javaVariableType') + '\n' + sliceFunction('javaSuperClass') +
5526
+ '\nreturn { memberDeclarationIn, javaVariableType, javaSuperClass }',
5527
+ )()
5528
+ const sample = [
5529
+ 'package a.b;',
5530
+ 'public class SqlMethod {',
5531
+ ' public static final SqlMethod INSERT_ONE = new SqlMethod();',
5532
+ ' private final Class<?> entityClass;',
5533
+ ' public static boolean retBool(long n) { return n > 0; }',
5534
+ '}',
5535
+ 'class SqlHelper { static boolean retBool(long n) { return true; } }',
5536
+ 'class Base { protected Class<?> entityClass; }',
5537
+ 'class Sub extends Base { private String name; }',
5538
+ ].join('\n')
5539
+ const constant = helpers.memberDeclarationIn(sample, 'INSERT_ONE')
5540
+ assert.equal(constant.kind, 'field')
5541
+ assert.equal(constant.static, true)
5542
+ assert.equal(constant.constant, true, 'static final uppercase field is a constant')
5543
+ assert.equal(constant.line, 3)
5544
+ const field = helpers.memberDeclarationIn(sample, 'entityClass')
5545
+ assert.equal(field.kind, 'field')
5546
+ assert.equal(field.static, false)
5547
+ const method = helpers.memberDeclarationIn(sample, 'retBool')
5548
+ assert.equal(method.kind, 'method')
5549
+ assert.equal(method.static, true)
5550
+ assert.equal(helpers.javaVariableType('private final Class<?> entityClass;', 'entityClass'), 'Class')
5551
+ assert.equal(helpers.javaVariableType('private String name = "x";', 'name'), 'String')
5552
+ assert.equal(helpers.javaSuperClass('class Sub extends Base { }'), 'Base')
5553
+ })
@@ -4,7 +4,8 @@
4
4
  // inside the freshness window.
5
5
  import assert from 'node:assert/strict'
6
6
  import { createServer, request } from 'node:http'
7
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
7
+ import { spawn } from 'node:child_process'
8
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
8
9
  import { tmpdir } from 'node:os'
9
10
  import { join } from 'node:path'
10
11
  import { after, before, test } from 'node:test'
@@ -12,14 +13,20 @@ import { __test, handleRequest } from '../lib/index.js'
12
13
 
13
14
  let home
14
15
 
16
+ // The refresh tick drops a row whose workspace directory no longer exists (m14800),
17
+ // so the fixture workspaces these tests talk about must really exist on disk.
18
+ const FIXTURE_DIRS = ['/tmp/ws-a', '/tmp/ws-b', '/tmp/ws-c', '/tmp/ws-garbage', '/tmp/ws-moved', '/tmp/ws-new', '/tmp/ws-other']
19
+
15
20
  before(() => {
16
21
  home = mkdtempSync(join(tmpdir(), 'dsh-window-refresh-'))
17
22
  process.env.DSH_RIS_IDE_PROXY_HOME = home
23
+ for (const dir of FIXTURE_DIRS) mkdirSync(dir, { recursive: true })
18
24
  })
19
25
 
20
26
  after(() => {
21
27
  delete process.env.DSH_RIS_IDE_PROXY_HOME
22
28
  rmSync(home, { recursive: true, force: true })
29
+ for (const dir of FIXTURE_DIRS) rmSync(dir, { recursive: true, force: true })
23
30
  })
24
31
 
25
32
  function writeWindows(windows) {
@@ -67,16 +74,49 @@ test('a missing window list is a no-op', () => {
67
74
  assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => ({}) } }), { changed: 0, windows: 0, dropped: 0 })
68
75
  })
69
76
 
70
- test("another dsh instance's rows are left alone", () => {
77
+ test("a live dsh instance's rows are left alone", async () => {
71
78
  // The home is machine-wide: two dsh processes share dsh-window.json, and each may
72
79
  // only vouch for sessions IT knows. A row stamped with a foreign ownerPid must
73
- // survive even though this process cannot resolve its sessionId (review C2-P2-2).
80
+ // survive while that process runs, even though this process cannot resolve its
81
+ // sessionId (review C2-P2-2) — but it can never be pruned by anyone once that
82
+ // process exits (m14800), so the liveness check has to be real.
83
+ const peer = spawn(process.execPath, ['-e', 'setInterval(function () {}, 1000)'], { stdio: 'ignore' })
84
+ try {
85
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
86
+ writeWindows([
87
+ { url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-other', sessionId: 's-foreign', ownerPid: peer.pid, at: old },
88
+ ])
89
+ assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => null } }), { changed: 0, windows: 1, dropped: 0 })
90
+ assert.equal(readWindows()[0].sessionId, 's-foreign')
91
+ } finally {
92
+ peer.kill()
93
+ }
94
+ })
95
+
96
+ test('a row whose dsh process exited is dropped (m14800)', () => {
97
+ // Nothing else could ever retire the row: its owner is gone, and the daemon keeps
98
+ // rows for seven days. The workspace used to sit in the IDE list for days.
74
99
  const old = new Date(Date.now() - 10 * 60_000).toISOString()
75
100
  writeWindows([
76
101
  { url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-other', sessionId: 's-foreign', ownerPid: 999999, at: old },
77
102
  ])
78
- assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => null } }), { changed: 0, windows: 1, dropped: 0 })
79
- assert.equal(readWindows()[0].sessionId, 's-foreign')
103
+ assert.deepEqual(__test.refreshDshWindows({ sessions: { get: () => null } }), { changed: 0, windows: 0, dropped: 1 })
104
+ assert.deepEqual(readWindows(), [])
105
+ })
106
+
107
+ test('a row for a deleted workspace directory is dropped (m14800)', () => {
108
+ // Deleting a workspace while a session still points at it used to keep the row
109
+ // alive: the session resolved, so the refresh only re-stamped `at`. The IDE then
110
+ // advertised a workspace that cannot be opened.
111
+ const old = new Date(Date.now() - 10 * 60_000).toISOString()
112
+ writeWindows([
113
+ { url: 'http://127.0.0.1:3080', cwd: '/tmp/ws-deleted-14800', sessionId: 's-live', at: old },
114
+ ])
115
+ const result = __test.refreshDshWindows({
116
+ sessions: { get: (id) => (id === 's-live' ? { header: { cwd: '/tmp/ws-deleted-14800' } } : null) },
117
+ })
118
+ assert.deepEqual(result, { changed: 0, windows: 0, dropped: 1 })
119
+ assert.deepEqual(readWindows(), [])
80
120
  })
81
121
 
82
122
  test('a garbage ownerPid makes the row ours, not somebody else\'s', () => {
@@ -22,6 +22,8 @@ export const HAS_GIT = hasCommand('git')
22
22
  export const HAS_BASH = hasCommand('bash', ['-c', 'true'])
23
23
  /** WSL 上把 Linux 路径翻成 Windows 形式要靠它;普通 Linux 用 lib 的测试接缝替代。 */
24
24
  export const HAS_WSLPATH = hasCommand('wslpath', ['-w', '/tmp'])
25
+ /** javap ships with the JDK; platform-class fallback needs it (m05797). */
26
+ export const HAS_JAVAP = hasCommand('javap', ['-version'])
25
27
 
26
28
  /** node:test `skip` value: false when available, else the reason string. */
27
29
  export function skipWithout(available, label) {
@@ -17,7 +17,7 @@ import { dirname, join, resolve } from 'node:path'
17
17
  import { fileURLToPath } from 'node:url'
18
18
 
19
19
  import { __test } from '../lib/index.js'
20
- import { HAS_BASH, HAS_GIT, skipWithout } from './helpers/cmd.mjs'
20
+ import { HAS_BASH, HAS_GIT, HAS_JAVAP, skipWithout } from './helpers/cmd.mjs'
21
21
 
22
22
  const {
23
23
  resolvePath, isLoopbackRequest, readTail, clampBytes, serveTail, serveStop, handleRequest,
@@ -669,6 +669,23 @@ test('the programs route scans over HTTP and the start route refuses bad input',
669
669
  }, undefined, root)
670
670
  })
671
671
 
672
+ test('platform classes resolve from the JDK itself when no jar carries them (m05797)', { skip: skipWithout(HAS_JAVAP, 'javap') }, async () => {
673
+ const workspace = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-jdk-'))
674
+ try {
675
+ const resolved = await __test.resolveJdkSource(workspace, 'java.lang.annotation.ElementType')
676
+ assert.ok(resolved !== undefined, 'javap (or a JDK src.zip) answers for a platform class')
677
+ const text = await readFile(resolved.path, 'utf8')
678
+ assert.match(text, /java\.lang\.annotation\.ElementType/, 'the cached text carries the class')
679
+ // The same path without any module directory (a class clicked in a module that
680
+ // was never started through the IDE has no program log to name).
681
+ const viaEmptyDirs = await __test.resolveDependencySourceIn(workspace, [], 'java.lang.annotation.ElementType')
682
+ assert.ok(viaEmptyDirs !== undefined)
683
+ assert.equal(viaEmptyDirs.kind, resolved.kind)
684
+ } finally {
685
+ await rm(workspace, { recursive: true, force: true })
686
+ }
687
+ })
688
+
672
689
  test('the open-target route resolves a program by id and never invents a URL (m03945)', async () => {
673
690
  const { root } = await makeProgramFixture()
674
691
  await withServer(async ({ base }) => {
@@ -691,6 +708,72 @@ test('the open-target route resolves a program by id and never invents a URL (m0
691
708
  }, undefined, root)
692
709
  })
693
710
 
711
+ test('a yds front-end opens yds\' debugging browser, never a tab at the dev URL', async () => {
712
+ // The 🌐 answer for a yds front-end is NOT its dev server: the platform page is the
713
+ // workbench, and only yds' own browser carries the extension that points the module
714
+ // at the local dev server. ris-ide asks for `mode:'debug'` and passes the log's URL
715
+ // along as the live dev port — it must not window.open it.
716
+ const { root } = await makeProgramFixture()
717
+ const ctx = { sessions: { get: (id) => (id === 's1' ? { header: { cwd: root } } : undefined) } }
718
+ const calls = []
719
+ const state = { refuse: false }
720
+ const answer = (res, payload) => {
721
+ res.writeHead(200, { 'content-type': 'application/json' })
722
+ res.end(JSON.stringify(payload))
723
+ }
724
+ const server = createServer((req, res) => {
725
+ const url = new URL(req.url ?? '/', 'http://dsh.internal')
726
+ if (url.pathname === '/dsh-ris-yds/probe') {
727
+ answer(res, { ok: true, yds: true, projectDir: join(root, 'proj-a'), frontends: ['ui'] })
728
+ return
729
+ }
730
+ if (url.pathname === '/dsh-ris-yds/open') {
731
+ const chunks = []
732
+ req.on('data', (chunk) => chunks.push(chunk))
733
+ req.on('end', () => {
734
+ const body = JSON.parse(Buffer.concat(chunks).toString('utf8'))
735
+ calls.push(body)
736
+ if (state.refuse) answer(res, { ok: false, code: 'not-yds-frontend', reason: '不是这个前端' })
737
+ else answer(res, { ok: true, mode: 'debug', pid: 4242, port: 9222, url: 'https://workbench.example/c-ass-kk-hans' })
738
+ })
739
+ return
740
+ }
741
+ handleRequest(ctx, req, res, { maxBytes: HARD_MAX_BYTES, restrictToCwd: false, stopGraceMs: 5000 })
742
+ })
743
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
744
+ const base = `http://127.0.0.1:${server.address().port}`
745
+ try {
746
+ const listing = await (await fetch(`${base}${PROGRAMS_PATH}?sessionId=s1&refresh=1`)).json()
747
+ const program = listing.programs.find((entry) => entry.kind === 'frontend')
748
+ assert.ok(program !== undefined, 'the fixture frontend program is discovered')
749
+ await mkdir(join(root, 'logs'), { recursive: true })
750
+ await writeFile(program.logPath, ' \u001b[32m- Local:\u001b[39m http://localhost:5173/\n')
751
+
752
+ const opened = await (await fetch(`${base}${OPEN_TARGET_PATH}?sessionId=s1&id=${encodeURIComponent(program.id)}`)).json()
753
+ assert.equal(opened.ok, true, JSON.stringify(opened))
754
+ assert.equal(opened.mode, 'debug', 'yds started its own browser')
755
+ assert.equal(opened.source, 'yds')
756
+ assert.equal(opened.pid, 4242)
757
+ assert.equal(opened.url, 'https://workbench.example/c-ass-kk-hans')
758
+ assert.equal(calls.length, 1)
759
+ assert.equal(calls[0].mode, 'debug', 'a yds front-end is never asked for the proxy page')
760
+ assert.equal(calls[0].workspace, root)
761
+ assert.equal(calls[0].frontend.code, 'ui')
762
+ assert.equal(calls[0].devUrl, 'http://localhost:5173/', 'the live dev URL travels along as a port hint')
763
+
764
+ // A refusal is reported, not papered over with a window at the dev URL.
765
+ state.refuse = true
766
+ const refused = await (await fetch(`${base}${OPEN_TARGET_PATH}?sessionId=s1&id=${encodeURIComponent(program.id)}`)).json()
767
+ assert.equal(refused.ok, false, 'a refusal is not turned into a silent window')
768
+ assert.equal(refused.code, 'not-yds-frontend')
769
+ assert.match(refused.message, /不是这个前端/)
770
+ assert.equal(calls.length, 2)
771
+ } finally {
772
+ await new Promise((resolve) => server.close(resolve))
773
+ await rm(root, { recursive: true, force: true })
774
+ }
775
+ })
776
+
694
777
  test('a dev-server URL is read from local hosts, placeholders and ANSI logs (m03945)', async () => {
695
778
  // What scaffolds actually print: webpack/vite use localhost, MDF prints
696
779
  // `Node服务地址:http://<HOST地址>:3003`, and colour codes wrap both the label
@@ -701,6 +784,13 @@ test('a dev-server URL is read from local hosts, placeholders and ANSI logs (m03
701
784
  ['\u001b[32m - Local: \u001b[36mhttp://0.0.0.0:8080/\u001b[39m\n', 'http://127.0.0.1:8080/'],
702
785
  ['http://[::]:9000/\n', 'http://127.0.0.1:9000/'],
703
786
  ['Java服务地址:https://srmdev.hanslaser.com/c-ass-kk-hans\n', undefined],
787
+ // The LAST URL in a log is usually quoted from a failed request; the address is
788
+ // the one a server line announced (mftm: mdf-node prints no bare `Local:` line).
789
+ [' - Local: http://localhost:5173/\nERROR fetch http://127.0.0.1:3003/api/x.json\n', 'http://localhost:5173/'],
790
+ ['Node服务地址:http://<HOST地址>:3003 当前环境:daily\nERROR Unable to fetch http://127.0.0.1:3003/}/c-ass-kk-hans/version.json\n', 'http://127.0.0.1:3003'],
791
+ // A URL with an unresolved template is not an address: opening it lands on a 404.
792
+ ['GET http://127.0.0.1:3003/}/c-ass-kk-hans/version.json\n', undefined],
793
+ ['\u001b[32mready in 512 ms\u001b[39m\n\u001b[36m➜\u001b[39m http://127.0.0.1:3004/\n', 'http://127.0.0.1:3004/'],
704
794
  ]
705
795
  const dir = await mkdtemp(join(tmpdir(), 'ris-logurl-'))
706
796
  const logPath = join(dir, 'prog.log')