dsh-ris-ide 1.7.3 → 1.8.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.
- package/README.md +19 -7
- package/bin/proxy-janitor.mjs +106 -11
- package/bin/risd.mjs +287 -0
- package/bin/run-with-log.ps1 +43 -5
- package/lib/client.js +515 -1152
- package/lib/index.js +1124 -55
- package/lib/janitor.js +106 -15
- package/lib/proxy.js +86 -7
- package/lib/proxybridge-bundle.js +798 -0
- package/lib/redirector.js +484 -35
- package/lib/risd/build.js +91 -0
- package/lib/risd/debug.js +374 -0
- package/lib/risd/git.js +207 -0
- package/lib/risd/leases.js +124 -0
- package/lib/risd/lifecycle.js +148 -0
- package/lib/risd/log.js +59 -0
- package/lib/risd/ping.js +94 -0
- package/lib/risd/programs.js +348 -0
- package/lib/risd/server.js +1478 -0
- package/lib/risd/state.js +137 -0
- package/lib/risd/ui.js +1705 -0
- package/lib/risd/view.js +79 -0
- package/lib/risd-client.js +282 -0
- package/lib/standalone/window.html +14 -16
- package/lib/startup.js +114 -0
- package/package.json +4 -1
- package/test/client-build.test.mjs +113 -0
- package/test/client-viewer.test.mjs +166 -200
- package/test/dsh-origin.test.mjs +140 -0
- package/test/dsh-window-refresh.test.mjs +100 -0
- package/test/harness.test.mjs +9 -0
- package/test/host-noloop.test.mjs +74 -0
- package/test/host-tail.test.mjs +21 -4
- package/test/host-window.test.mjs +4 -4
- package/test/janitor.test.mjs +29 -1
- package/test/lifecycle.test.mjs +26 -5
- package/test/merge-owners.test.mjs +155 -0
- package/test/proxy-restart.test.mjs +37 -0
- package/test/proxy-window.test.mjs +45 -0
- package/test/proxy.test.mjs +41 -0
- package/test/proxybridge-bundle.test.mjs +687 -0
- package/test/redirector-bundle.test.mjs +391 -0
- package/test/redirector.test.mjs +59 -9
- package/test/risd-api.test.mjs +470 -0
- package/test/risd-bridge-degrade.test.mjs +101 -0
- package/test/risd-build.test.mjs +20 -0
- package/test/risd-cli-home.test.mjs +50 -0
- package/test/risd-client.test.mjs +130 -0
- package/test/risd-debug.test.mjs +261 -0
- package/test/risd-election.test.mjs +104 -0
- package/test/risd-engine.test.mjs +132 -0
- package/test/risd-entry.test.mjs +118 -0
- package/test/risd-git.test.mjs +109 -0
- package/test/risd-handoff.test.mjs +116 -0
- package/test/risd-heal.test.mjs +50 -0
- package/test/risd-helpers.mjs +108 -0
- package/test/risd-host-p2.test.mjs +147 -0
- package/test/risd-janitor-guard.test.mjs +46 -0
- package/test/risd-lease.test.mjs +83 -0
- package/test/risd-lifecycle.test.mjs +210 -0
- package/test/risd-log-follow.test.mjs +227 -0
- package/test/risd-mode.test.mjs +161 -0
- package/test/risd-ping.test.mjs +99 -0
- package/test/risd-programs.test.mjs +169 -0
- package/test/risd-review-p2.test.mjs +217 -0
- package/test/risd-shutdown.test.mjs +97 -0
- package/test/risd-teardown.test.mjs +87 -0
- package/test/risd-tools.test.mjs +211 -0
- package/test/risd-ui.test.mjs +445 -0
- package/test/risd-write.test.mjs +170 -0
- package/test/startup-reconcile.test.mjs +100 -0
- package/test/windows.test.mjs +37 -2
|
@@ -184,41 +184,16 @@ test('double-clicking a title-bar control does not maximise the pane', () => {
|
|
|
184
184
|
assert.equal(T.headerDoubleClickIsTitle(input), false)
|
|
185
185
|
})
|
|
186
186
|
|
|
187
|
-
test('the dialog marks exactly one of start/stop as the live action', async () => {
|
|
188
|
-
const { readFile } = await import('node:fs/promises')
|
|
189
|
-
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
190
|
-
// `S.buttonOff` is the DISABLED skin, so painting an enabled action with it made
|
|
191
|
-
// 启动/停止 look equally dead. One shared factory fixes the box, and only the
|
|
192
|
-
// actionable button is filled.
|
|
193
|
-
assert.ok(source.includes('function dialogButton(spec)'), 'start/stop/save must share one button shape')
|
|
194
|
-
assert.ok(source.includes('minWidth: 84, height: 28'), 'all three must share one box so the row lines up')
|
|
195
|
-
assert.ok(source.includes('var filled = spec.primary === true && spec.disabled !== true'),
|
|
196
|
-
'grey is reserved for "nothing to do here"')
|
|
197
|
-
assert.ok(source.includes("primary: !running,"), '启动 is the filled one while stopped')
|
|
198
|
-
assert.ok(source.includes("primary: running,"), '停止 is the filled one while running')
|
|
199
|
-
assert.ok(source.includes("'data-proxy-action': spec.action"), 'the three actions stay addressable')
|
|
200
|
-
// Enabled controls must not borrow the disabled skin.
|
|
201
|
-
assert.equal(source.includes("style: S.buttonOff, 'data-proxy-add'"), false, '+ 添加规则 is enabled, not inert')
|
|
202
|
-
assert.equal(source.includes("style: S.buttonOff, 'data-proxy-close'"), false, 'the close ✕ is enabled, not inert')
|
|
203
|
-
})
|
|
204
|
-
|
|
205
187
|
test('one proxy control governs engine, interception and git together', async () => {
|
|
206
188
|
const { readFile } = await import('node:fs/promises')
|
|
207
|
-
const client = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
208
189
|
const host = await readFile(new URL('../lib/index.js', import.meta.url), 'utf8')
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
assert.equal(client.includes('data-proxy-git-off'), false, 'the git-off button is gone')
|
|
212
|
-
assert.ok(client.includes('启动同时写入 git 代理,停止同时清除'), 'the footer has to say what start/stop do')
|
|
213
|
-
// Start/stop drive all three layers, and so does the host exit hook.
|
|
190
|
+
// Start/stop drive all three layers, and so does the host exit hook. The UI that
|
|
191
|
+
// used to say so lives on the risd page now (the panel dialog is deleted).
|
|
214
192
|
assert.ok(host.includes('const redirector = await startRedirectors()'), 'start brings the interception up')
|
|
215
193
|
assert.ok(host.includes('syncGitProxy({ cwd, host: gitHost, enabled: true })'), 'start writes the git entry')
|
|
216
194
|
assert.ok(host.includes('syncGitProxy({ cwd, host: gitHost, enabled: false })'), 'stop clears the git entry')
|
|
217
195
|
assert.ok(host.includes('const redirector = await stopRedirector()'), 'stop brings the interception down')
|
|
218
196
|
assert.ok(host.includes('clearGitProxySync()'), 'the exit hook undoes the git entry too')
|
|
219
|
-
// The route reports each layer's outcome so a dismissed UAC prompt is visible.
|
|
220
|
-
assert.ok(client.includes("' · 系统层拦截已启动('"), 'the note reports the interception start')
|
|
221
|
-
assert.ok(client.includes("' · git 代理已写入 '"), 'the note reports the git entry')
|
|
222
197
|
})
|
|
223
198
|
|
|
224
199
|
test('the console follows the live sidebar session, not the one it opened in', async () => {
|
|
@@ -239,15 +214,8 @@ test('the console follows the live sidebar session, not the one it opened in', a
|
|
|
239
214
|
assert.ok(source.includes("if (typeof liveSessionId === 'string' && liveSessionId !== '') sessionId = liveSessionId"),
|
|
240
215
|
'the live id must win over the injected one')
|
|
241
216
|
assert.ok(source.includes('}, [sessionIdentity])'), 'another workspace must drop the followed program')
|
|
242
|
-
// Both console shapes share one dialog, so it must not inherit either font.
|
|
243
|
-
assert.ok(source.includes("fontFamily: CHROME_FAMILY, fontSize: DEFAULT_FONT_SIZE + 'px'"),
|
|
244
|
-
'the proxy dialog pins the IDE chrome font so the narrow console does not wrap rows')
|
|
245
217
|
assert.ok(source.includes("'Microsoft YaHei', sans-serif)"),
|
|
246
218
|
'the chrome stack must match what the IDE theme resolves to, not a mono list')
|
|
247
|
-
// Form controls do not inherit the page font: the dialog has to say so, twice.
|
|
248
|
-
assert.ok(source.includes("fontFamily: 'inherit'"), 'the field style must inherit the dialog font')
|
|
249
|
-
assert.ok(source.includes('[data-proxy-dialog] input, [data-proxy-dialog] button, [data-proxy-dialog] select, [data-proxy-dialog] textarea { font-family: inherit; font-size: inherit; }'),
|
|
250
|
-
'every control inside the dialog must inherit the card font')
|
|
251
219
|
})
|
|
252
220
|
|
|
253
221
|
test('only invisible outcomes and failures raise a toast', async () => {
|
|
@@ -511,7 +479,8 @@ test('apply adds a Session-header button immediately right of DSH\'s open-in-app
|
|
|
511
479
|
const markup = renderToStaticMarkup(React.createElement(header.component, { sessionId: 's1' }))
|
|
512
480
|
assert.match(markup, /data-action="ris-ide-window"/)
|
|
513
481
|
assert.match(markup, /RIS-IDE/)
|
|
514
|
-
assert.match(markup, /title="
|
|
482
|
+
assert.match(markup, /title="打开 risd 维护页(概览 \/ 代理 \/ IDE):IDE 内嵌其中,可按工作区切换"/, 'the tooltip names the maintenance page')
|
|
483
|
+
assert.match(markup, /aria-busy="false"/, 'idle: the button says it is not opening anything')
|
|
515
484
|
}
|
|
516
485
|
})
|
|
517
486
|
|
|
@@ -541,6 +510,108 @@ test('the header button opens THIS session\'s workspace, not the remembered one'
|
|
|
541
510
|
)
|
|
542
511
|
})
|
|
543
512
|
|
|
513
|
+
test('⧉ reuses the prefetched daemon address, so a warm click adds no round trip', async () => {
|
|
514
|
+
// The visible delay was the on-demand spawn, but the host-view read sat in front
|
|
515
|
+
// of EVERY click. The header button and the console prefetch it on mount with a
|
|
516
|
+
// 20 s TTL; a click inside that window only has to call `window.open`.
|
|
517
|
+
const previous = { window: globalThis.window, document: globalThis.document, fetch: globalThis.fetch }
|
|
518
|
+
const opened = []
|
|
519
|
+
const requested = []
|
|
520
|
+
globalThis.document = { baseURI: 'http://127.0.0.1:3080/' }
|
|
521
|
+
globalThis.window = { open: (url, name) => { opened.push([url, name]); return { focus() {} } } }
|
|
522
|
+
globalThis.fetch = async (href) => {
|
|
523
|
+
requested.push(String(href))
|
|
524
|
+
return { ok: true, status: 200, json: async () => ({ ok: true, risd: { available: true, url: 'http://127.0.0.1:4567' } }) }
|
|
525
|
+
}
|
|
526
|
+
let fallbacks = 0
|
|
527
|
+
try {
|
|
528
|
+
T.resetRisdPrefetch()
|
|
529
|
+
const warm = await T.prefetchRisd({ sessionId: 's1', cwd: '/w/project' })
|
|
530
|
+
assert.equal(warm.url, 'http://127.0.0.1:4567', 'the prefetch keeps the daemon address')
|
|
531
|
+
assert.equal(requested.length, 1, 'the prefetch asks the host once')
|
|
532
|
+
assert.deepEqual(T.risdCachedAddress(), warm, 'the address is cached for the click')
|
|
533
|
+
|
|
534
|
+
const entry = await T.openRisdPage({ sessionId: 's1', cwd: '/w/project' }, async () => { fallbacks += 1 })
|
|
535
|
+
assert.equal(entry, 'risd')
|
|
536
|
+
assert.equal(requested.length, 1, 'the click adds no request: the cache answered')
|
|
537
|
+
assert.equal(opened.length, 1, 'exactly one tab')
|
|
538
|
+
assert.equal(opened[0][1], 'dsh-risd-ui', 'the maintenance tab keeps its name')
|
|
539
|
+
assert.match(opened[0][0], /^http:\/\/127\.0\.0\.1:4567\/ui\?cwd=%2Fw%2Fproject$/, 'preselects the workspace without switching the tab (m11345)')
|
|
540
|
+
assert.equal(fallbacks, 0, 'no standalone fallback when the daemon address is known')
|
|
541
|
+
} finally {
|
|
542
|
+
globalThis.window = previous.window
|
|
543
|
+
globalThis.document = previous.document
|
|
544
|
+
globalThis.fetch = previous.fetch
|
|
545
|
+
T.resetRisdPrefetch()
|
|
546
|
+
}
|
|
547
|
+
})
|
|
548
|
+
|
|
549
|
+
test('a cold ⧉ falls back to ensure and a double click still opens ONE tab', async () => {
|
|
550
|
+
const previous = { window: globalThis.window, document: globalThis.document, fetch: globalThis.fetch }
|
|
551
|
+
const opened = []
|
|
552
|
+
const requested = []
|
|
553
|
+
let releaseProxy = null
|
|
554
|
+
globalThis.document = { baseURI: 'http://127.0.0.1:3080/' }
|
|
555
|
+
globalThis.window = { open: (url, name) => { opened.push([url, name]); return { focus() {} } } }
|
|
556
|
+
globalThis.fetch = async (href) => {
|
|
557
|
+
const url = String(href)
|
|
558
|
+
requested.push(url)
|
|
559
|
+
if (url.includes('/risd/ensure')) {
|
|
560
|
+
return { ok: true, status: 200, json: async () => ({ ok: true, spawned: true, risd: { available: true, url: 'http://127.0.0.1:4567' } }) }
|
|
561
|
+
}
|
|
562
|
+
// Hold the host view open so the second click lands while the first is in flight.
|
|
563
|
+
return await new Promise((resolve) => {
|
|
564
|
+
releaseProxy = () => resolve({ ok: true, status: 200, json: async () => ({ ok: true, risd: { available: false } }) })
|
|
565
|
+
})
|
|
566
|
+
}
|
|
567
|
+
try {
|
|
568
|
+
T.resetRisdPrefetch()
|
|
569
|
+
const fallback = async () => { throw new Error('a spawnable daemon must not fall back') }
|
|
570
|
+
const first = T.openRisdPage({ sessionId: 's1', cwd: '/w/project' }, fallback)
|
|
571
|
+
const second = T.openRisdPage({ sessionId: 's1', cwd: '/w/project' }, fallback)
|
|
572
|
+
assert.equal(typeof releaseProxy, 'function', 'the host view read is in flight')
|
|
573
|
+
releaseProxy()
|
|
574
|
+
assert.equal(await first, 'risd')
|
|
575
|
+
assert.equal(await second, 'risd')
|
|
576
|
+
assert.equal(opened.length, 1, 'the in-flight open is shared, not duplicated')
|
|
577
|
+
assert.deepEqual(requested.map((href) => new URL(href).pathname), ['/dsh-ris-ide/proxy', '/dsh-ris-ide/risd/ensure'])
|
|
578
|
+
assert.equal(new URL(opened[0][0]).searchParams.get('cwd'), '/w/project', 'preselects the workspace')
|
|
579
|
+
assert.equal(new URL(opened[0][0]).searchParams.get('tab'), null, 'does not switch the tab (m11345)')
|
|
580
|
+
assert.equal(T.risdCachedAddress().url, 'http://127.0.0.1:4567', 'the ensured address warms the cache')
|
|
581
|
+
} finally {
|
|
582
|
+
globalThis.window = previous.window
|
|
583
|
+
globalThis.document = previous.document
|
|
584
|
+
globalThis.fetch = previous.fetch
|
|
585
|
+
T.resetRisdPrefetch()
|
|
586
|
+
}
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
test('both ⧉ buttons show progress and never run two opens at once', async () => {
|
|
590
|
+
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
591
|
+
// Session-header button: disabled + aria-busy, the ⧉ becomes an ellipsis and the
|
|
592
|
+
// label says 「打开中」; `finally` puts it back even when the popup was blocked.
|
|
593
|
+
assert.match(source, /'aria-busy': opening === true \? 'true' : 'false'/, 'the header button announces its busy state')
|
|
594
|
+
assert.match(source, /disabled: opening === true,/, 'and cannot be clicked twice')
|
|
595
|
+
assert.match(source, /opening === true \? '…' : '⧉'/, 'the icon becomes a progress ellipsis')
|
|
596
|
+
assert.match(source, /opening === true \? '打开中' : 'RIS-IDE'/, 'the label says it is opening')
|
|
597
|
+
assert.match(source, /setOpening\(false\)/, 'finally restores the button')
|
|
598
|
+
// The icon-only console ⧉ mirrors it (title / aria-label carry the wording).
|
|
599
|
+
assert.match(source, /'aria-busy': openingIde === true \? 'true' : 'false'/)
|
|
600
|
+
assert.match(source, /disabled: openingIde === true,/)
|
|
601
|
+
assert.match(source, /openingIde === true \? '…' : '⧉'/)
|
|
602
|
+
assert.match(source, /正在打开 risd 维护页/)
|
|
603
|
+
assert.match(source, /setOpeningIde\(false\)/, 'its finally restores the button too')
|
|
604
|
+
// Warm cache + single flight.
|
|
605
|
+
assert.match(source, /var risdPrefetch = \{ at: 0, risd: null, pending: null \}/)
|
|
606
|
+
assert.match(source, /var RISD_PREFETCH_TTL_MS = 20000/)
|
|
607
|
+
assert.match(source, /function prefetchRisd\(scope\)/)
|
|
608
|
+
assert.match(source, /if \(risdOpenPending !== null\) return risdOpenPending/)
|
|
609
|
+
assert.match(source, /onPointerEnter: warmRisdAddress/, 'hovering the header button warms the address')
|
|
610
|
+
assert.match(source, /onPointerEnter: warmCompactRisd/, 'the console icon warms it the same way')
|
|
611
|
+
assert.match(source, /void prefetchRisd\(\{ sessionId: sessionId, cwd: sessionCwd \}\)/, 'the header button warms the cache on mount')
|
|
612
|
+
assert.match(source, /void prefetchRisd\(\{ sessionId: sessionId, cwd: cwd \}\)/, 'the console warms it too')
|
|
613
|
+
})
|
|
614
|
+
|
|
544
615
|
test('openStandaloneWindow hands the scope to the plugin\'s own page', async () => {
|
|
545
616
|
const previousWindow = globalThis.window
|
|
546
617
|
const previousDocument = globalThis.document
|
|
@@ -555,7 +626,8 @@ test('openStandaloneWindow hands the scope to the plugin\'s own page', async ()
|
|
|
555
626
|
try {
|
|
556
627
|
const handle = await T.openStandaloneWindow({ sessionId: 's1', cwd: '/w/project', programId: 'p1' })
|
|
557
628
|
assert.equal(opened.length, 1)
|
|
558
|
-
const [openedUrl, name
|
|
629
|
+
const [openedUrl, name] = opened[0]
|
|
630
|
+
assert.equal(opened[0].length, 2, 'a plain window.open(url, name): no feature string')
|
|
559
631
|
const parsed = new URL(openedUrl)
|
|
560
632
|
// Same origin as the DSH page: no new port, cookie auth comes along.
|
|
561
633
|
assert.equal(parsed.origin, 'http://127.0.0.1:3080')
|
|
@@ -578,7 +650,6 @@ test('openStandaloneWindow hands the scope to the plugin\'s own page', async ()
|
|
|
578
650
|
const scoped = new URL(opened[opened.length - 1][0])
|
|
579
651
|
assert.equal(scoped.searchParams.get('cwd'), '/w/project/sub', 'the panel keeps its rooted cwd')
|
|
580
652
|
assert.equal(opened[opened.length - 1][1], T.standaloneWindowName('/w/project'), 'the window name stays workspace-keyed')
|
|
581
|
-
assert.match(features, /popup=yes/)
|
|
582
653
|
// The compact panel's 🐞 button: same window, plus "start the JDWP session".
|
|
583
654
|
await T.openStandaloneWindow({ sessionId: 's1', cwd: '/w/project', programId: 'p1', debug: true })
|
|
584
655
|
assert.equal(new URL(opened[opened.length - 1][0]).searchParams.get('debug'), '1')
|
|
@@ -699,7 +770,7 @@ test('a closed window never blocks the next open (dead registrations do not wait
|
|
|
699
770
|
}
|
|
700
771
|
})
|
|
701
772
|
|
|
702
|
-
test('openStandaloneWindow
|
|
773
|
+
test('openStandaloneWindow opens a normal browser window, not a sized popup', async () => {
|
|
703
774
|
const previousWindow = globalThis.window
|
|
704
775
|
const previousDocument = globalThis.document
|
|
705
776
|
const previousFetch = globalThis.fetch
|
|
@@ -712,16 +783,13 @@ test('openStandaloneWindow asks for the whole screen work area (maximized)', asy
|
|
|
712
783
|
globalThis.fetch = async () => ({ ok: false, status: 404, json: async () => ({}) })
|
|
713
784
|
try {
|
|
714
785
|
await T.openStandaloneWindow({ sessionId: 's1' })
|
|
715
|
-
|
|
716
|
-
assert.match(
|
|
717
|
-
|
|
718
|
-
assert.match(features, /left=0/, 'pinned to the left edge')
|
|
719
|
-
assert.match(features, /top=0/, 'pinned to the top edge')
|
|
720
|
-
assert.match(features, /popup=yes/)
|
|
721
|
-
// No screen information (odd hosts): keep the old fallback instead of NaN.
|
|
786
|
+
assert.equal(opened[0].length, 2, 'no features argument: the browser decides the frame')
|
|
787
|
+
assert.match(opened[0][1], /^dsh-ris-ide-window-/, 'the workspace-keyed name is what makes it single-instance')
|
|
788
|
+
// A host without screen information must not change the call shape either.
|
|
722
789
|
globalThis.window = { open: (...args) => { opened.push(args); return { focus() {} } } }
|
|
790
|
+
globalThis.window.localStorage = { getItem: () => '/w/project' }
|
|
723
791
|
await T.openStandaloneWindow({ sessionId: 's1' })
|
|
724
|
-
assert.
|
|
792
|
+
assert.equal(opened[1].length, 2)
|
|
725
793
|
} finally {
|
|
726
794
|
globalThis.window = previousWindow
|
|
727
795
|
globalThis.document = previousDocument
|
|
@@ -2189,8 +2257,8 @@ test('the title-bar controls share one 20px row height', { skip: !reactIsReal ?
|
|
|
2189
2257
|
const consoleTags = buttonsOf(consoleHead)
|
|
2190
2258
|
assert.ok(sourceTags.length >= 3, 'the source toolbar carries the font scale, the theme switch and reset')
|
|
2191
2259
|
const consoleActions = consoleTags.map((tag) => /data-action="([^"]+)"/.exec(tag)[1])
|
|
2192
|
-
assert.deepEqual(consoleActions, ['config-open', 'config-generate'
|
|
2193
|
-
'the console title bar carries 📄 open-config
|
|
2260
|
+
assert.deepEqual(consoleActions, ['config-open', 'config-generate'],
|
|
2261
|
+
'the console title bar carries 📄 open-config and ⚙ config-generate only (proxy moved out)')
|
|
2194
2262
|
for (const tag of sourceTags.concat(consoleTags)) {
|
|
2195
2263
|
const action = /data-action="([^"]+)"/.exec(tag)[1]
|
|
2196
2264
|
assert.match(tag, /height:20px/, `${action} must sit on the shared 20px row`)
|
|
@@ -4045,8 +4113,9 @@ test('one IDE window per workspace: the window name is keyed by the workspace cw
|
|
|
4045
4113
|
assert.doesNotMatch(source, /focusStandaloneWindow/, 'raising a foreign window is not attempted any more')
|
|
4046
4114
|
assert.match(source, /await requestStandaloneWindowClose\(windowName\)/, 'present: ask the old window to close, then open one')
|
|
4047
4115
|
assert.doesNotMatch(source, /focus-ack/, 'no focus handshake: the browser forbids it')
|
|
4048
|
-
assert.match(source, /window\.open\(url\.href, windowName
|
|
4049
|
-
assert.doesNotMatch(source, /window\.open\(
|
|
4116
|
+
assert.match(source, /window\.open\(url\.href, windowName\)/, 'absent: create it straight on the IDE url, as a normal window')
|
|
4117
|
+
assert.doesNotMatch(source, /window\.open\(url\.href, windowName, features\)/, 'no popup feature string any more')
|
|
4118
|
+
assert.doesNotMatch(source, /window\.open\('', windowName/, 'never a blank window to close again')
|
|
4050
4119
|
assert.doesNotMatch(source, /settleStandaloneWindow/)
|
|
4051
4120
|
})
|
|
4052
4121
|
|
|
@@ -4076,7 +4145,11 @@ test('the standalone window claims a single-instance lock before booting the IDE
|
|
|
4076
4145
|
// offers an explicit "close this window" action instead — and only that button
|
|
4077
4146
|
// may close it (never an automatic close at boot).
|
|
4078
4147
|
assert.match(claim, /关闭这个窗口/, 'the duplicate window can be closed on demand')
|
|
4079
|
-
|
|
4148
|
+
// One explicit close action remains; inside the maintenance page's iframe that
|
|
4149
|
+
// offer is dropped (window.close() is refused there — review D3).
|
|
4150
|
+
assert.equal((claim.match(/window\.close\(\)/g) || []).length, 2, 'closing happens only from the explicit user actions')
|
|
4151
|
+
assert.match(claim, /window\.self !== window\.top/, 'the embedded case is detected')
|
|
4152
|
+
assert.match(claim, /if \(!embedded\)/, 'the dead close button is not rendered inside an iframe')
|
|
4080
4153
|
// Booting waits for the claim, so the notice cannot be raced by a mounted panel.
|
|
4081
4154
|
assert.match(html, /window\.__risIdeClaimReady/)
|
|
4082
4155
|
assert.match(html, /window\.__risIdeBootPanel = bootPanel/)
|
|
@@ -4636,6 +4709,34 @@ test('trimLargeTextFront frees whole lines and keeps the line count aligned', ()
|
|
|
4636
4709
|
assert.deepEqual(T.trimLargeTextFront('', 100), { text: '', droppedLines: 0, droppedChars: 0 })
|
|
4637
4710
|
})
|
|
4638
4711
|
|
|
4712
|
+
test('hovering a tree row paints a faint background that stays below the selection', async () => {
|
|
4713
|
+
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
4714
|
+
// m09634: the row, not just its label, gets a light grey wash. A background
|
|
4715
|
+
// changes no metrics, so nothing moves; and since selected rows paint their tint
|
|
4716
|
+
// INLINE (S.treeRowOn / treeRowMulti), the stylesheet hover can never outrank them.
|
|
4717
|
+
const css = source.slice(source.indexOf('var TREE_HOVER_CSS'), source.indexOf('var SEARCH_PANEL_CSS'))
|
|
4718
|
+
assert.match(css, /\[data-tree-path\]:hover/)
|
|
4719
|
+
assert.match(css, /background:color-mix\(in srgb, currentColor 7%, transparent\)/, 'a faint grey wash')
|
|
4720
|
+
assert.doesNotMatch(css, /padding|margin|line-height|min-height|font-size|height:/, 'no metric changes: the tree must not jump')
|
|
4721
|
+
assert.match(source, /treeRowOn: \{[^}]*background: 'color-mix\(in srgb, currentColor 12%, transparent\)'/, 'the selected tint is an inline style (wins over hover)')
|
|
4722
|
+
assert.match(source, /treeRowMulti: \{[^}]*background:/, 'multi-selection tint too')
|
|
4723
|
+
assert.match(source, /PROGRAM_LOADING_CSS \+ TREE_HOVER_CSS/, 'injected with the panel styles')
|
|
4724
|
+
})
|
|
4725
|
+
|
|
4726
|
+
test('the embedded editor answers the maintenance page about unsaved buffers (m10900)', async () => {
|
|
4727
|
+
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
4728
|
+
// The daemon's maintenance page embeds this window cross-origin and reloads
|
|
4729
|
+
// itself on updates; it cannot read `docs`. It asks over postMessage, and only
|
|
4730
|
+
// the immediate parent plus the two named shapes are served.
|
|
4731
|
+
assert.match(source, /event\.source !== window\.parent/, 'only the embedding parent is served')
|
|
4732
|
+
assert.match(source, /'dsh-ris-ide:probe-dirty'/, 'it answers the dirty probe')
|
|
4733
|
+
assert.match(source, /'dsh-ris-ide:dirty-report'/, 'with a named report')
|
|
4734
|
+
assert.match(source, /'dsh-ris-ide:save-all'/, 'it can save every dirty buffer on request')
|
|
4735
|
+
assert.match(source, /'dsh-ris-ide:save-all-done'/, 'and reports whether the save succeeded')
|
|
4736
|
+
assert.match(source, /window\.parent\.postMessage\(payload, '\*'\)/, 'the reply goes to the parent')
|
|
4737
|
+
assert.match(source, /saveBulk\(pending\)/, 'the save-all reuses the bulk save path')
|
|
4738
|
+
})
|
|
4739
|
+
|
|
4639
4740
|
test('the editor scrollbars are visible and a start re-reads its log', async () => {
|
|
4640
4741
|
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
4641
4742
|
// BUG3: the host theme paints a 5px near-invisible scrollbar; the panel gives
|
|
@@ -4785,7 +4886,7 @@ test('search hits survive a pick and the shortcut selects the query', async () =
|
|
|
4785
4886
|
const pick = source.slice(source.indexOf('function pickSearchHit('), source.indexOf('function openContentHit('))
|
|
4786
4887
|
assert.doesNotMatch(pick, /setTreeQuery\(''\)/, 'the query stays after a pick')
|
|
4787
4888
|
assert.doesNotMatch(pick, /setSearchHits\(null\)/, 'the result set stays after a pick')
|
|
4788
|
-
const contentPick = source.slice(source.indexOf('function openContentHit('), source.indexOf('
|
|
4889
|
+
const contentPick = source.slice(source.indexOf('function openContentHit('), source.indexOf('// No auto-pick on first load'))
|
|
4789
4890
|
assert.doesNotMatch(contentPick, /setTreeQuery\(''\)/, 'a content pick keeps the query too')
|
|
4790
4891
|
// Both searches cache their payloads keyed by the query text.
|
|
4791
4892
|
assert.match(source, /searchCacheRef\.current\.get\('name:' \+ text\)/)
|
|
@@ -4950,156 +5051,21 @@ test('a folder row only expands; the context menu\'s 进入 re-roots with an 上
|
|
|
4950
5051
|
assert.match(region, /walk\(activeRoot, 0, \{\}\)/, 'Ctrl+A walks the active root')
|
|
4951
5052
|
})
|
|
4952
5053
|
|
|
4953
|
-
// ── proxy dialog
|
|
4954
|
-
test('the console
|
|
4955
|
-
const
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
test('the proxy dialog mounts with its address section and actions', { skip: !reactIsReal }, () => {
|
|
4961
|
-
const { renderToStaticMarkup } = require(`${REACT_ROOT}/react-dom/server`)
|
|
4962
|
-
const markup = renderToStaticMarkup(React.createElement(T.ProxyDialog, { scope: { sessionId: 's1', cwd: '/w/project' }, onClose: () => {} }))
|
|
4963
|
-
assert.match(markup, /data-proxy-dialog="1"/, 'the overlay is rendered')
|
|
4964
|
-
assert.match(markup, /data-proxy-close="1"/)
|
|
4965
|
-
// SSR runs no effect, so the form is still loading — the shell must exist anyway.
|
|
4966
|
-
assert.match(markup, /读取中/)
|
|
5054
|
+
// ── the old in-panel proxy dialog is gone; the risd page owns the rules ──
|
|
5055
|
+
test('the console keeps its log pane empty until a row is chosen (m07431)', async () => {
|
|
5056
|
+
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
5057
|
+
// First load used to pick the first running service and load its log, which
|
|
5058
|
+
// located/opened a file nobody asked for. A click on a row is the only way in.
|
|
5059
|
+
assert.match(source, /\/\/ No auto-pick on first load \(m07431\)/)
|
|
5060
|
+
assert.equal(source.includes('First load with no explicit target'), false)
|
|
4967
5061
|
})
|
|
4968
5062
|
|
|
4969
|
-
test('
|
|
4970
|
-
const { readFile } = await import('node:fs/promises')
|
|
4971
|
-
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
4972
|
-
// Launching programs from the dialog was dropped: ProxyBridge intercepts by
|
|
4973
|
-
// process name, so a program started anywhere is covered and a ▶ button only
|
|
4974
|
-
// ever covered the one instance we spawned.
|
|
4975
|
-
assert.equal(source.includes('data-proxy-run'), false, 'no row-level start button')
|
|
4976
|
-
assert.equal(source.includes('runButton('), false, 'the button builder is gone')
|
|
4977
|
-
// The mapping is decided by the program's capabilities, not by a checkbox: the
|
|
4978
|
-
// row reports the outcome instead.
|
|
4979
|
-
assert.equal(source.includes('checked: rule.shadow'), false, 'no mapping checkbox bound to the rule')
|
|
4980
|
-
assert.ok(source.includes("'data-proxy-map'"), 'the row still reports the mapping')
|
|
4981
|
-
assert.ok(source.includes("? '127.0.0.1' + portSuffix(rule)"), 'and names where it landed')
|
|
4982
|
-
// The state is machine-wide, so the row label is provenance, not a boundary.
|
|
4983
|
-
assert.ok(source.includes("'来源 '"))
|
|
4984
|
-
assert.ok(source.includes('data-proxy-redirector'), 'ProxyBridge block exists in the dialog')
|
|
4985
|
-
})
|
|
4986
|
-
|
|
4987
|
-
test('an adopted leftover engine is reported with a stop action', async () => {
|
|
5063
|
+
test('no ProxyDialog component is shipped any more (m07355 / D4)', async () => {
|
|
4988
5064
|
const { readFile } = await import('node:fs/promises')
|
|
4989
5065
|
const source = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
//
|
|
4994
|
-
assert.
|
|
4995
|
-
assert.match(region, /'data-proxy-inherited': '1'/, 'the banner is addressable in the DOM')
|
|
4996
|
-
assert.match(region, /原 dsh pid/, 'it names the dsh that started the engine')
|
|
4997
|
-
assert.match(region, /action: 'stop-inherited',/, 'it offers its own action id')
|
|
4998
|
-
assert.match(region, /onClick: function \(\) \{ act\('stop'\) \}/, 'the stop goes through the normal action path')
|
|
4999
|
-
})
|
|
5000
|
-
|
|
5001
|
-
test('auto-save is versioned, flushed before it can be lost, and the host decides "applies"', () => {
|
|
5002
|
-
const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
5003
|
-
// C-M1: the whole table is posted, so the payload names the table it came from.
|
|
5004
|
-
// Without that, two windows save and the loser's row disappears without an error.
|
|
5005
|
-
assert.ok(source.includes('revision: revisionRef.current'), 'the save names its base table')
|
|
5006
|
-
assert.ok(source.includes("answer.status === 409 && payload.conflict === true"), 'a stale save is detected')
|
|
5007
|
-
assert.ok(source.includes('规则表已在别处被修改,已重新载入(本次改动未写入)'), 'and reported in words')
|
|
5008
|
-
// C-M2: a 700 ms debounce is a window in which an edit exists only in memory; both
|
|
5009
|
-
// paths that reload the view must write it out first.
|
|
5010
|
-
assert.ok(source.includes('function flushSave()'), 'there is a flush')
|
|
5011
|
-
assert.ok(source.includes('flushSave().catch(function () {}).then(function () { actNow(action, ruleId, side) })'),
|
|
5012
|
-
'start/stop writes the pending edit first')
|
|
5013
|
-
assert.ok(source.includes('flushSave().catch(function () {}).then(function () { onClose() })'),
|
|
5014
|
-
'closing the dialog writes the pending edit first')
|
|
5015
|
-
// C-M3: local parsing is a preview; once the host has seen the exact row, its
|
|
5016
|
-
// verdict wins, so the form cannot claim a row applies when the engine skipped it.
|
|
5017
|
-
assert.ok(source.includes('function hostVerdictFor(rule)'), 'the host verdict is looked up')
|
|
5018
|
-
assert.ok(source.includes('var hostRow = hostVerdictFor(rule)'), 'and used by the row')
|
|
5019
|
-
// P2: the placeholder used to promise the opposite of what the engine does.
|
|
5020
|
-
assert.equal(source.includes('(空=不限)'), false, 'no placeholder advertises the old meaning')
|
|
5021
|
-
assert.ok(source.includes('(全部写 *;空=本行不生效)'))
|
|
5022
|
-
})
|
|
5023
|
-
|
|
5024
|
-
test('the program cell is typed, and the picker offers three tabs and one tree', () => {
|
|
5025
|
-
const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
5026
|
-
// Typing `java` (any path) or `D:\…\java.exe` (exact) is the primary way to set a
|
|
5027
|
-
// rule; the picker is a helper, not the only door.
|
|
5028
|
-
assert.ok(source.includes("'data-proxy-program': rule.id"))
|
|
5029
|
-
assert.ok(source.includes("placeholder: '程序名或路径:java / D:\\\\…\\\\java.exe'"))
|
|
5030
|
-
assert.ok(source.includes("'data-proxy-pick': rule.id"))
|
|
5031
|
-
// Exactly two tabs: running processes, and ONE file tree. On WSL the Windows
|
|
5032
|
-
// disks are ordinary folders under /mnt, so a separate "Windows 文件" tab would
|
|
5033
|
-
// be the same tree with another spelling.
|
|
5034
|
-
assert.ok(source.includes("tabButton('running', '运行中的程序')"))
|
|
5035
|
-
assert.ok(source.includes("tabButton('local', '选择文件')"))
|
|
5036
|
-
assert.equal(source.includes("tabButton('windows'"), false, 'one file tree, not two')
|
|
5037
|
-
// `/` is prepended client-side too: the roots list comes from the host half,
|
|
5038
|
-
// which only reloads with dsh web, and a refresh must not drop the entry that
|
|
5039
|
-
// reaches every path.
|
|
5040
|
-
assert.ok(source.includes('function withFilesystemRoot(roots, posix)'))
|
|
5041
|
-
assert.ok(source.includes('withFilesystemRoot(tree.roots, hostIsPosix)'))
|
|
5042
|
-
// …and the shortcuts in front of it are dropped, so the first thing the user sees
|
|
5043
|
-
// is the start of the filesystem, not a pile of convenience roots.
|
|
5044
|
-
assert.ok(source.includes("root.path === '/' || /^\\/mnt\\/[A-Za-z](\\/|$)/.test(root.path)"))
|
|
5045
|
-
// A pick under /mnt is written as a Windows path: that is the spelling the
|
|
5046
|
-
// program's own OS uses, and what a Windows-side interceptor matches.
|
|
5047
|
-
assert.ok(source.includes('function pickedPath(value)'))
|
|
5048
|
-
assert.ok(source.includes('program: pickedPath(value)'))
|
|
5049
|
-
assert.ok(source.includes("url.searchParams.set('side', side)"))
|
|
5050
|
-
// The picker is a dialog of its own, opened from the row: a two-root tree does
|
|
5051
|
-
// not fit in a rule row.
|
|
5052
|
-
assert.ok(source.includes("'data-proxy-picker-dialog': '1'"), 'the picker renders as a nested dialog')
|
|
5053
|
-
assert.ok(source.includes('void loadPrograms()'), 'the process list is fetched when the picker opens')
|
|
5054
|
-
// Expanding a folder must grow the tree IN PLACE — no "enter directory" stepping,
|
|
5055
|
-
// no breadcrumb, and no re-reading what is already on screen.
|
|
5056
|
-
assert.ok(source.includes('data-proxy-tree-dir'), 'folders are rows in the tree')
|
|
5057
|
-
assert.ok(source.includes('data-proxy-tree-file'), 'files are rows in the tree')
|
|
5058
|
-
assert.ok(source.includes('function toggleDir(dir)'), 'a folder toggles instead of navigating')
|
|
5059
|
-
assert.ok(source.includes("if (open !== true && tree.nodes[key] === undefined) void loadTreeDir(key)"),
|
|
5060
|
-
'a folder is read the first time it is expanded')
|
|
5061
|
-
assert.equal(source.includes("'data-proxy-browse-up'"), false, 'the stepwise browser is gone')
|
|
5062
|
-
// The program cell is typed, the picker is a helper: choosing a file must call
|
|
5063
|
-
// the chooser that belongs to the dialog (passing it into the tree, not closing
|
|
5064
|
-
// over a name that is not in scope).
|
|
5065
|
-
assert.ok(source.includes('function dirRow(dir, depth, chooser)'), 'the tree rows take the chooser')
|
|
5066
|
-
assert.ok(source.includes('rows = rows.concat(treeRows(dir.path, depth + 1, chooser))'))
|
|
5067
|
-
assert.ok(source.includes('rows = rows.concat(dirRow(dir, depth, chooser))'))
|
|
5068
|
-
// A file is not a folder: it gets no caret in that slot (only a placeholder span),
|
|
5069
|
-
// otherwise the arrow reads as "expand me" on something that cannot expand.
|
|
5070
|
-
assert.equal(source.includes("'▶ ' + file.name"), false, 'no caret in front of files')
|
|
5071
|
-
assert.ok(source.includes("h('span', null, '📄 ' + file.name)"))
|
|
5072
|
-
// A folder whose listing came back empty is a leaf: caret becomes `·`, no click.
|
|
5073
|
-
assert.ok(source.includes("'data-proxy-tree-leaf': leaf ? '1' : '0'"))
|
|
5074
|
-
assert.ok(source.includes("leaf ? '·' : open ? '▾' : '▸'"))
|
|
5075
|
-
// The old "choose from list only" button is gone.
|
|
5076
|
-
assert.equal(source.includes("rule.program === '' ? '选择程序…'"), false)
|
|
5077
|
-
})
|
|
5078
|
-
|
|
5079
|
-
test('edits save themselves, and adding a row adds a row', () => {
|
|
5080
|
-
const source = readSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
5081
|
-
// No 保存 button: every edit is written 700ms after the last keystroke, so a
|
|
5082
|
-
// half-typed IP never becomes a half-written rule on disk.
|
|
5083
|
-
assert.equal(source.includes("action: 'save'"), false, 'the save button is gone')
|
|
5084
|
-
assert.ok(source.includes('function draftSignature(draft)'))
|
|
5085
|
-
assert.ok(source.includes('savedSignature.current = draftSignature(draft)'),
|
|
5086
|
-
'what the host confirmed is remembered, so a reload is not an edit')
|
|
5087
|
-
// The timer lives in a ref so a button press or a close can flush it first.
|
|
5088
|
-
assert.ok(source.includes('saveTimer.current = setTimeout(function () { saveTimer.current = null; void save() }, 700)'))
|
|
5089
|
-
assert.ok(source.includes('data-proxy-autosave'))
|
|
5090
|
-
// Half-typed rows are not written: auto-save fires mid-typing, and a rule with no
|
|
5091
|
-
// program/ip/port would come back as a row that silently does nothing.
|
|
5092
|
-
assert.ok(source.includes('function storableRule(rule)'))
|
|
5093
|
-
assert.ok(source.includes('var mode = writeMode(rule)'))
|
|
5094
|
-
assert.ok(source.includes("if (storable.length === 0 && skipped > 0)"),
|
|
5095
|
-
'never blank the file while every row is still being typed')
|
|
5096
|
-
// A row that is already on disk must not silently keep its OLD content when it is
|
|
5097
|
-
// edited into an incomplete state: it is written as disabled instead.
|
|
5098
|
-
assert.ok(source.includes('function writeMode(rule)'))
|
|
5099
|
-
assert.ok(source.includes("return savedIds.current[rule.id] === true ? 'disable' : 'skip'"))
|
|
5100
|
-
assert.ok(source.includes("storable.push(Object.assign({}, rule, { enabled: false }))"))
|
|
5101
|
-
assert.ok(source.includes('savedIds.current = ids'))
|
|
5102
|
-
// "+ 添加规则" appends an empty row and does NOT pop the picker over the table.
|
|
5103
|
-
const addRule = source.slice(source.indexOf('function addRule()'), source.indexOf('function addRule()') + 900)
|
|
5104
|
-
assert.equal(addRule.includes('pickFor'), false, 'adding a row must not open the picker')
|
|
5066
|
+
assert.equal(source.includes('function ProxyDialog('), false, 'the old panel component is deleted')
|
|
5067
|
+
assert.equal(source.includes('ProxyDialog: ProxyDialog'), false, 'it is no longer exported')
|
|
5068
|
+
assert.equal(source.includes("'data-proxy-dialog'"), false, 'no markup keeps the old dialog addressable')
|
|
5069
|
+
// The page itself is served by the daemon: /ui owns the rule editor now.
|
|
5070
|
+
assert.ok(source.includes("routeUrl('dsh-ris-ide/proxy')"), 'the entry still asks the host where the page is')
|
|
5105
5071
|
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// The plugin's half of the daemon page's IDE tab: it records the browser's origin
|
|
2
|
+
// plus the current dsh sessionId into `dsh-window.json`, per workspace, so one
|
|
3
|
+
// daemon page can embed the IDE of every workspace someone has open.
|
|
4
|
+
//
|
|
5
|
+
// Only loopback Hosts are recorded (the daemon page itself is loopback-only too).
|
|
6
|
+
import assert from 'node:assert/strict'
|
|
7
|
+
import { createServer, request } from 'node:http'
|
|
8
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
10
|
+
import { join } from 'node:path'
|
|
11
|
+
import { after, before, test } from 'node:test'
|
|
12
|
+
import { handleRequest } from '../lib/index.js'
|
|
13
|
+
|
|
14
|
+
let home
|
|
15
|
+
let workspace
|
|
16
|
+
let server
|
|
17
|
+
let port
|
|
18
|
+
|
|
19
|
+
before(async () => {
|
|
20
|
+
home = mkdtempSync(join(tmpdir(), 'dsh-origin-home-'))
|
|
21
|
+
workspace = mkdtempSync(join(tmpdir(), 'dsh-origin-ws-'))
|
|
22
|
+
process.env.DSH_RIS_IDE_PROXY_HOME = home
|
|
23
|
+
process.env.DSH_RIS_IDE_WINDOW_NOTE = '1'
|
|
24
|
+
server = createServer((req, res) => {
|
|
25
|
+
handleRequest({ sessions: { get: () => ({ header: { cwd: workspace } }) } }, req, res, { maxBytes: 1024, restrictToCwd: false })
|
|
26
|
+
})
|
|
27
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
|
|
28
|
+
port = server.address().port
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
after(async () => {
|
|
32
|
+
await new Promise((resolve) => server.close(resolve))
|
|
33
|
+
delete process.env.DSH_RIS_IDE_PROXY_HOME
|
|
34
|
+
delete process.env.DSH_RIS_IDE_WINDOW_NOTE
|
|
35
|
+
rmSync(home, { recursive: true, force: true })
|
|
36
|
+
rmSync(workspace, { recursive: true, force: true })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
function get(path, host) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
const call = request({ host: '127.0.0.1', port, path, method: 'GET', headers: { host: host ?? `127.0.0.1:${port}` } }, (res) => {
|
|
42
|
+
res.resume()
|
|
43
|
+
res.on('end', () => resolve(res.statusCode))
|
|
44
|
+
})
|
|
45
|
+
call.on('error', () => resolve(0))
|
|
46
|
+
call.end()
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readWindows() {
|
|
51
|
+
const file = join(home, 'dsh-window.json')
|
|
52
|
+
if (!existsSync(file)) return null
|
|
53
|
+
return JSON.parse(readFileSync(file, 'utf8')).windows
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test('a loopback request records the dsh origin and session per workspace', async () => {
|
|
57
|
+
const status = await get(`/dsh-ris-ide/windows?sessionId=sess-1&cwd=${encodeURIComponent(workspace)}`)
|
|
58
|
+
assert.equal(status, 200)
|
|
59
|
+
const windows = readWindows()
|
|
60
|
+
assert.ok(Array.isArray(windows), 'dsh-window.json must hold a windows array')
|
|
61
|
+
assert.equal(windows.length, 1)
|
|
62
|
+
assert.equal(windows[0].url, `http://127.0.0.1:${port}`)
|
|
63
|
+
assert.equal(windows[0].sessionId, 'sess-1')
|
|
64
|
+
assert.equal(windows[0].cwd, workspace)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('a probe without a dsh session is not recorded as a workspace', async () => {
|
|
68
|
+
// `/windows?cwd=` probes come from the standalone/maintenance page and carry no
|
|
69
|
+
// session. Inheriting the previous window's id opened the IDE with the wrong
|
|
70
|
+
// session and made the liveness check prune the wrong entry (C2-P1-2).
|
|
71
|
+
const before = readWindows().length
|
|
72
|
+
const status = await get(`/dsh-ris-ide/windows?cwd=${encodeURIComponent(workspace)}`)
|
|
73
|
+
assert.equal(status, 200)
|
|
74
|
+
const after = readWindows()
|
|
75
|
+
assert.equal(after.length, before, 'nothing may be recorded without a sessionId')
|
|
76
|
+
assert.ok(after.every((row) => row.sessionId !== ''), 'every stored row names a real session')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('a non-loopback Host is not recorded', async () => {
|
|
80
|
+
const before = readWindows().length
|
|
81
|
+
const status = await get(`/dsh-ris-ide/windows?sessionId=sess-evil&cwd=${encodeURIComponent(workspace)}`, 'evil.example:80')
|
|
82
|
+
assert.equal(status, 403)
|
|
83
|
+
assert.equal(readWindows().length, before, 'a foreign origin cannot seed the IDE list')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('a second workspace upserts instead of replacing the list', async () => {
|
|
87
|
+
const other = mkdtempSync(join(tmpdir(), 'dsh-origin-ws2-'))
|
|
88
|
+
try {
|
|
89
|
+
const status = await get(`/dsh-ris-ide/windows?sessionId=sess-2&cwd=${encodeURIComponent(other)}`)
|
|
90
|
+
assert.equal(status, 200)
|
|
91
|
+
const windows = readWindows()
|
|
92
|
+
assert.equal(windows.length, 2, 'both workspaces are listed')
|
|
93
|
+
assert.deepEqual(windows.map((row) => row.sessionId).sort(), ['sess-1', 'sess-2'])
|
|
94
|
+
// A brand-new workspace is written immediately. Re-recording one that is already
|
|
95
|
+
// there is throttled to one write per 3 s (review C3-P2-6), so the order of the
|
|
96
|
+
// second call below is not promised — only that nothing duplicates.
|
|
97
|
+
const statusAgain = await get(`/dsh-ris-ide/windows?sessionId=sess-1&cwd=${encodeURIComponent(workspace)}`)
|
|
98
|
+
assert.equal(statusAgain, 200)
|
|
99
|
+
const after = readWindows()
|
|
100
|
+
assert.equal(after.length, 2, 'the same workspace must not duplicate')
|
|
101
|
+
assert.deepEqual(after.map((row) => row.cwd).sort(), [workspace, other].sort())
|
|
102
|
+
} finally {
|
|
103
|
+
rmSync(other, { recursive: true, force: true })
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('alternating known workspaces does not write on every request', async () => {
|
|
108
|
+
// Two dsh windows take turns hitting the plugin; each request used to rewrite the
|
|
109
|
+
// machine-level file (~one synchronous read+write per request). Now an already
|
|
110
|
+
// recorded workspace inside the 3 s window only moves the in-memory key.
|
|
111
|
+
const rows = readWindows()
|
|
112
|
+
// One request first: either it writes (the window had expired) or it is already
|
|
113
|
+
// inside the window — both leave the throttle armed for the loop below.
|
|
114
|
+
await get(`/dsh-ris-ide/windows?sessionId=${rows[0].sessionId}&cwd=${encodeURIComponent(rows[0].cwd)}`)
|
|
115
|
+
const before = readFileSync(join(home, 'dsh-window.json'), 'utf8')
|
|
116
|
+
for (const row of rows) {
|
|
117
|
+
await get(`/dsh-ris-ide/windows?sessionId=${row.sessionId}&cwd=${encodeURIComponent(row.cwd)}`)
|
|
118
|
+
}
|
|
119
|
+
const after = readFileSync(join(home, 'dsh-window.json'), 'utf8')
|
|
120
|
+
assert.equal(after, before, 'nothing was rewritten inside the throttle window')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('a non-loopback Host header records nothing', async () => {
|
|
124
|
+
const before = readWindows()
|
|
125
|
+
// The route itself may refuse a non-loopback Host (403); recording must not happen either way.
|
|
126
|
+
const status = await get('/dsh-ris-ide/windows?sessionId=sess-evil', 'evil.example.com')
|
|
127
|
+
assert.ok(status === 200 || status === 403, `unexpected status ${status}`)
|
|
128
|
+
const after = readWindows()
|
|
129
|
+
assert.equal(JSON.stringify(after), JSON.stringify(before))
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('a request without a workspace does not replace another workspace entry', async () => {
|
|
133
|
+
// Review C-P1-5: the empty-cwd entry used `existing[0].cwd` as its key, so a
|
|
134
|
+
// bare /dsh-ris-ide/proxy call overwrote somebody else's window entry.
|
|
135
|
+
const before = readWindows()
|
|
136
|
+
const status = await get('/dsh-ris-ide/proxy?sessionId=sess-3')
|
|
137
|
+
assert.equal(status, 200)
|
|
138
|
+
const after = readWindows()
|
|
139
|
+
assert.deepEqual(after.map((row) => row.cwd), before.map((row) => row.cwd), 'the list is unchanged')
|
|
140
|
+
})
|