dsh-ris-ide 1.7.3 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -7
- package/bin/proxy-janitor.mjs +106 -11
- package/bin/risd.mjs +284 -0
- package/bin/run-with-log.ps1 +43 -5
- package/lib/client.js +609 -1178
- 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/proxybridge-health.js +206 -0
- package/lib/redirector.js +1615 -115
- 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 +1919 -0
- package/lib/risd/state.js +137 -0
- package/lib/risd/ui.js +1989 -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 +279 -227
- 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 +39 -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/proxybridge-health.test.mjs +116 -0
- package/test/redirector-bundle.test.mjs +391 -0
- package/test/redirector.test.mjs +413 -10
- package/test/risd-api.test.mjs +514 -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-restart.test.mjs +104 -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 +607 -0
- package/test/risd-write.test.mjs +170 -0
- package/test/startup-reconcile.test.mjs +100 -0
- package/test/windows.test.mjs +37 -2
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 1b P4: the daemon is the only writer of the machine-wide rule table.
|
|
3
|
+
*
|
|
4
|
+
* The acceptance that matters here is the one the old plugin-side CAS only
|
|
5
|
+
* approximated: two windows posting the same base revision must not both win, and
|
|
6
|
+
* the loser must be told the revision that IS current (so it can reload instead of
|
|
7
|
+
* guessing). The daemon also serves the same injection the engine would produce —
|
|
8
|
+
* one implementation, two callers.
|
|
9
|
+
*/
|
|
10
|
+
import assert from 'node:assert/strict'
|
|
11
|
+
import test from 'node:test'
|
|
12
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
13
|
+
import { tmpdir } from 'node:os'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
import { spawnSync } from 'node:child_process'
|
|
16
|
+
import { RISD_API_VERSION } from '../lib/risd/state.js'
|
|
17
|
+
import { readProxyConfig } from '../lib/proxy.js'
|
|
18
|
+
import { risdConfigRevision } from '../lib/risd/view.js'
|
|
19
|
+
import { makeHome, removeHome, startRisdProcess } from './risd-helpers.mjs'
|
|
20
|
+
|
|
21
|
+
const FIXTURE = {
|
|
22
|
+
socks: { host: 'proxy.example.com', port: 10080 },
|
|
23
|
+
listenPort: 11081,
|
|
24
|
+
rules: [
|
|
25
|
+
{ id: 'keep', program: 'git', hosts: 'git.example.com', ports: '*', enabled: true, shadow: false, source: 'user', workspace: '/tmp/ws' },
|
|
26
|
+
{ id: 'direct-java', program: 'java', hosts: '172.20.235.*', ports: '*', enabled: true, shadow: false, source: 'user', workspace: '/tmp/ws', direct: true },
|
|
27
|
+
],
|
|
28
|
+
shadows: [],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function call(state, path, { method = 'GET', body = undefined } = {}) {
|
|
32
|
+
const headers = {
|
|
33
|
+
authorization: `Bearer ${state.token}`,
|
|
34
|
+
'x-risd-api-version': String(RISD_API_VERSION),
|
|
35
|
+
}
|
|
36
|
+
if (body !== undefined) headers['content-type'] = 'application/json'
|
|
37
|
+
return fetch(`${state.url}${path}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function startFixture(t) {
|
|
41
|
+
const home = makeHome('risd-write-')
|
|
42
|
+
const saved = process.env.DSH_RIS_IDE_PROXY_HOME
|
|
43
|
+
process.env.DSH_RIS_IDE_PROXY_HOME = home
|
|
44
|
+
t.after(() => {
|
|
45
|
+
if (saved === undefined) delete process.env.DSH_RIS_IDE_PROXY_HOME
|
|
46
|
+
else process.env.DSH_RIS_IDE_PROXY_HOME = saved
|
|
47
|
+
removeHome(home)
|
|
48
|
+
})
|
|
49
|
+
writeFileSync(join(home, 'proxy.json'), `${JSON.stringify(FIXTURE, null, 2)}\n`, { mode: 0o600 })
|
|
50
|
+
const daemon = await startRisdProcess({ home, env: { DSH_RIS_IDE_PROXY_HOME: home } })
|
|
51
|
+
t.after(() => daemon.stop())
|
|
52
|
+
// The daemon refuses a cwd that does not exist (a write for a deleted workspace
|
|
53
|
+
// would create rules nobody asked for), so the fixture owns a real one.
|
|
54
|
+
const cwd = mkdtempSync(join(tmpdir(), 'risd-write-ws-'))
|
|
55
|
+
t.after(() => rmSync(cwd, { recursive: true, force: true }))
|
|
56
|
+
return { home, state: daemon.state, cwd }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function rowsFor(id, program) {
|
|
60
|
+
return [{ id, program, hosts: 'example.test', ports: '*', enabled: true, shadow: false, source: 'user' }]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test('two concurrent writes: exactly one wins, the loser gets 409 with the live revision', async (t) => {
|
|
64
|
+
const { home, state, cwd } = await startFixture(t)
|
|
65
|
+
const base = risdConfigRevision(readProxyConfig(cwd))
|
|
66
|
+
assert.equal(base, risdConfigRevision(FIXTURE), 'fixture revision is the one clients see')
|
|
67
|
+
|
|
68
|
+
const [a, b] = await Promise.all([
|
|
69
|
+
call(state, '/v1/proxy', { method: 'POST', body: { cwd, revision: base, config: { socks: FIXTURE.socks, listenPort: 11081, rules: rowsFor('write-a', 'node') } } }),
|
|
70
|
+
call(state, '/v1/proxy', { method: 'POST', body: { cwd, revision: base, config: { socks: FIXTURE.socks, listenPort: 11081, rules: rowsFor('write-b', 'curl') } } }),
|
|
71
|
+
])
|
|
72
|
+
const statuses = [a.status, b.status].sort()
|
|
73
|
+
assert.deepEqual(statuses, [200, 409], 'one write, one conflict')
|
|
74
|
+
|
|
75
|
+
const loser = a.status === 409 ? a : b
|
|
76
|
+
const conflict = await loser.json()
|
|
77
|
+
assert.equal(conflict.ok, false)
|
|
78
|
+
assert.equal(conflict.conflict, true)
|
|
79
|
+
assert.equal(conflict.code, 'conflict')
|
|
80
|
+
assert.equal(conflict.message, '规则表已在别处被修改,本次改动未写入')
|
|
81
|
+
assert.equal(conflict.revision, risdConfigRevision(readProxyConfig(cwd)), 'the conflict names the current revision')
|
|
82
|
+
|
|
83
|
+
const onDisk = JSON.parse(readFileSync(join(home, 'proxy.json'), 'utf8'))
|
|
84
|
+
const ids = onDisk.rules.map((rule) => rule.id)
|
|
85
|
+
assert.equal(ids.filter((id) => id === 'write-a' || id === 'write-b').length, 1, 'exactly one new row landed')
|
|
86
|
+
// The incoming table is authoritative for non-yds rows (that is how the panel's
|
|
87
|
+
// full-table save works), so fixture rows absent from it are retired on purpose.
|
|
88
|
+
assert.equal(ids.includes('keep'), false, 'the losing table did not leak its rows')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('a stale revision never lands, and an empty one is the deliberate force path', async (t) => {
|
|
92
|
+
const { cwd, state } = await startFixture(t)
|
|
93
|
+
const stale = await call(state, '/v1/proxy', {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
body: { cwd, revision: '000000000000', config: { socks: FIXTURE.socks, listenPort: 11081, rules: rowsFor('stale', 'node') } },
|
|
96
|
+
})
|
|
97
|
+
assert.equal(stale.status, 409)
|
|
98
|
+
assert.equal((await stale.json()).revision, risdConfigRevision(readProxyConfig(cwd)))
|
|
99
|
+
|
|
100
|
+
const forced = await call(state, '/v1/proxy', {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
body: { cwd, revision: '', config: { socks: FIXTURE.socks, listenPort: 11081, rules: rowsFor('forced', 'node') } },
|
|
103
|
+
})
|
|
104
|
+
assert.equal(forced.status, 200)
|
|
105
|
+
assert.ok(readProxyConfig(cwd).rules.some((rule) => rule.id === 'forced'))
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('injection is the same object the engine would inject (direct vs allow-list)', async (t) => {
|
|
109
|
+
const { cwd, state } = await startFixture(t)
|
|
110
|
+
|
|
111
|
+
const allowed = await call(state, `/v1/injection?cwd=${encodeURIComponent(cwd)}&program=git`)
|
|
112
|
+
assert.equal(allowed.status, 200)
|
|
113
|
+
const allow = await allowed.json()
|
|
114
|
+
assert.equal(allow.ok, true)
|
|
115
|
+
assert.equal(allow.injection.direct, false)
|
|
116
|
+
assert.equal(allow.injection.httpProxyUrl, 'http://127.0.0.1:11081')
|
|
117
|
+
assert.equal(allow.injection.env.HTTP_PROXY, 'http://127.0.0.1:11081')
|
|
118
|
+
assert.equal(allow.injection.env.NO_PROXY, 'localhost,127.0.0.1,::1')
|
|
119
|
+
assert.ok(allow.injection.jvmArgs.includes('-Dhttp.proxyPort=11081'))
|
|
120
|
+
assert.equal(allow.injection.jvmArgs.some((arg) => arg.startsWith('-DsocksProxyHost=')), false)
|
|
121
|
+
|
|
122
|
+
const direct = await call(state, `/v1/injection?cwd=${encodeURIComponent(cwd)}&program=java`)
|
|
123
|
+
const bypass = await direct.json()
|
|
124
|
+
assert.equal(bypass.injection.direct, true)
|
|
125
|
+
assert.equal(bypass.injection.jvmArgs[0], '-DsocksProxyHost=proxy.example.com')
|
|
126
|
+
assert.equal(bypass.injection.env.ALL_PROXY, 'socks5h://proxy.example.com:10080')
|
|
127
|
+
|
|
128
|
+
const missing = await call(state, `/v1/injection?cwd=${encodeURIComponent(cwd)}&program=node`)
|
|
129
|
+
assert.equal(missing.status, 200)
|
|
130
|
+
assert.equal((await missing.json()).injection, null, 'no enabled rule for node → nothing injected')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('a save re-points the scoped git entry instead of hiding the old host', async (t) => {
|
|
134
|
+
const home = makeHome('risd-git-save-')
|
|
135
|
+
const gitconfig = join(home, 'gitconfig')
|
|
136
|
+
writeFileSync(gitconfig, '')
|
|
137
|
+
const savedHome = process.env.DSH_RIS_IDE_PROXY_HOME
|
|
138
|
+
process.env.DSH_RIS_IDE_PROXY_HOME = home
|
|
139
|
+
const rules = (host) => [{ id: 'yds-git', program: 'git', hosts: host, ports: '*', enabled: true, shadow: false, source: 'user' }]
|
|
140
|
+
const table = (host) => ({ socks: { host: '127.0.0.1', port: 1080 }, listenPort: 11081, rules: rules(host), shadows: [] })
|
|
141
|
+
writeFileSync(join(home, 'proxy.json'), `${JSON.stringify(table('git-old.example'), null, 2)}\n`, { mode: 0o600 })
|
|
142
|
+
const daemon = await startRisdProcess({ home, env: { DSH_RIS_IDE_PROXY_HOME: home, GIT_CONFIG_GLOBAL: gitconfig } })
|
|
143
|
+
const cwd = mkdtempSync(join(tmpdir(), 'risd-git-save-ws-'))
|
|
144
|
+
t.after(() => {
|
|
145
|
+
daemon.stop()
|
|
146
|
+
rmSync(cwd, { recursive: true, force: true })
|
|
147
|
+
if (savedHome === undefined) delete process.env.DSH_RIS_IDE_PROXY_HOME
|
|
148
|
+
else process.env.DSH_RIS_IDE_PROXY_HOME = savedHome
|
|
149
|
+
removeHome(home)
|
|
150
|
+
})
|
|
151
|
+
const value = (key) => {
|
|
152
|
+
const out = spawnSync('git', ['config', '--global', '--get', key], {
|
|
153
|
+
encoding: 'utf8',
|
|
154
|
+
windowsHide: true,
|
|
155
|
+
env: Object.assign({}, process.env, { GIT_CONFIG_GLOBAL: gitconfig }),
|
|
156
|
+
})
|
|
157
|
+
return String(out.stdout ?? '').trim()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const first = await call(daemon.state, '/v1/proxy', { method: 'POST', body: { cwd, revision: '', config: table('git-old.example') } })
|
|
161
|
+
assert.equal(first.status, 200)
|
|
162
|
+
assert.equal(value('http.https://git-old.example/.proxy'), 'socks5h://127.0.0.1:1080')
|
|
163
|
+
|
|
164
|
+
const second = await call(daemon.state, '/v1/proxy', { method: 'POST', body: { cwd, revision: '', config: table('git-new.example') } })
|
|
165
|
+
assert.equal(second.status, 200)
|
|
166
|
+
const body = await second.json()
|
|
167
|
+
assert.equal(body.git?.host, 'git-new.example', 'the save reports the host it applied')
|
|
168
|
+
assert.equal(value('http.https://git-old.example/.proxy'), '', 'the old host entry must be removed, not left behind')
|
|
169
|
+
assert.equal(value('http.https://git-new.example/.proxy'), 'socks5h://127.0.0.1:1080')
|
|
170
|
+
})
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Startup reconciliation: leftovers that no longer match today's rules/state.
|
|
2
|
+
// A reboot kills every process we started (engine, daemon, bridge) but NOT the two
|
|
3
|
+
// machine-level side effects — the scoped git entry and the parked ProxyBridgeSvc —
|
|
4
|
+
// so the next start must undo what is provably ours and leave everything else alone.
|
|
5
|
+
import assert from 'node:assert/strict'
|
|
6
|
+
import { spawnSync } from 'node:child_process'
|
|
7
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { tmpdir } from 'node:os'
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
import { after, before, test } from 'node:test'
|
|
11
|
+
import { reconcileStartupLeftovers } from '../lib/startup.js'
|
|
12
|
+
|
|
13
|
+
let root
|
|
14
|
+
let home
|
|
15
|
+
let gitConfig
|
|
16
|
+
|
|
17
|
+
function git(args) {
|
|
18
|
+
const res = spawnSync('git', args, { encoding: 'utf8', env: process.env })
|
|
19
|
+
assert.equal(res.status, 0, `git ${args.join(' ')}: ${res.stderr}`)
|
|
20
|
+
return res.stdout.trim()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function gitGet(key) {
|
|
24
|
+
const res = spawnSync('git', ['config', '--global', '--get', key], { encoding: 'utf8', env: process.env })
|
|
25
|
+
assert.ok(res.status === 0 || res.status === 1, `git --get ${key}: ${res.stderr}`)
|
|
26
|
+
return res.status === 0 ? res.stdout.trim() : ''
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writeGitState(state) {
|
|
30
|
+
writeFileSync(join(home, 'git-proxy.json'), `${JSON.stringify(state)}\n`, 'utf8')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
before(() => {
|
|
34
|
+
root = mkdtempSync(join(tmpdir(), 'dsh-ris-ide-startup-'))
|
|
35
|
+
home = join(root, 'home')
|
|
36
|
+
mkdirSync(home, { recursive: true })
|
|
37
|
+
gitConfig = join(root, 'gitconfig')
|
|
38
|
+
writeFileSync(gitConfig, '', 'utf8')
|
|
39
|
+
process.env.DSH_RIS_IDE_PROXY_HOME = home
|
|
40
|
+
process.env.GIT_CONFIG_GLOBAL = gitConfig
|
|
41
|
+
process.env.GIT_CONFIG_NOSYSTEM = '1'
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
after(() => {
|
|
45
|
+
delete process.env.DSH_RIS_IDE_PROXY_HOME
|
|
46
|
+
delete process.env.GIT_CONFIG_GLOBAL
|
|
47
|
+
delete process.env.GIT_CONFIG_NOSYSTEM
|
|
48
|
+
rmSync(root, { recursive: true, force: true })
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('a clean machine is a no-op', async () => {
|
|
52
|
+
const result = await reconcileStartupLeftovers()
|
|
53
|
+
assert.equal(result.ok, true)
|
|
54
|
+
assert.deepEqual(result.notes, [])
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('a git entry from a dead engine is removed (it is ours)', async () => {
|
|
58
|
+
const key = 'http.https://git.example.com/.proxy'
|
|
59
|
+
const value = 'socks5h://10.0.0.1:1080'
|
|
60
|
+
writeGitState({ key, host: 'git.example.com', value })
|
|
61
|
+
git(['config', '--global', key, value])
|
|
62
|
+
const result = await reconcileStartupLeftovers()
|
|
63
|
+
assert.ok(result.notes.some((note) => /git 代理/.test(note)), result.notes.join('; '))
|
|
64
|
+
assert.equal(gitGet(key), '')
|
|
65
|
+
assert.equal(existsSync(join(home, 'git-proxy.json')), false, 'state file is gone')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('a foreign git value is left alone', async () => {
|
|
69
|
+
const key = 'http.https://other.example.com/.proxy'
|
|
70
|
+
writeGitState({ key, host: 'other.example.com', value: 'socks5h://10.0.0.1:1080' })
|
|
71
|
+
git(['config', '--global', key, 'http://corp-proxy:3128'])
|
|
72
|
+
const result = await reconcileStartupLeftovers()
|
|
73
|
+
assert.ok(result.notes.some((note) => /保留了/.test(note)), result.notes.join('; '))
|
|
74
|
+
assert.equal(gitGet(key), 'http://corp-proxy:3128')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('a stale pidfile and a dead risd.json are cleared', async () => {
|
|
78
|
+
writeFileSync(join(home, 'proxy.pid'), '999999\n', 'utf8')
|
|
79
|
+
writeFileSync(join(home, 'risd.json'), `${JSON.stringify({ pid: 999999, port: 1, token: 'x', apiVersion: 1 })}\n`, 'utf8')
|
|
80
|
+
const result = await reconcileStartupLeftovers()
|
|
81
|
+
assert.equal(existsSync(join(home, 'proxy.pid')), false, 'stale pidfile removed')
|
|
82
|
+
assert.equal(existsSync(join(home, 'risd.json')), false, 'dead daemon state removed')
|
|
83
|
+
assert.ok(result.notes.length >= 2, result.notes.join('; '))
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('a parked ProxyBridgeSvc is restored and its state cleared', async () => {
|
|
87
|
+
const dir = join(home, 'proxybridge')
|
|
88
|
+
mkdirSync(dir, { recursive: true })
|
|
89
|
+
writeFileSync(join(dir, 'proxybridge-service.json'), `${JSON.stringify({
|
|
90
|
+
at: Date.now(), stoppedByUs: true, originalStartType: 'Automatic', parkedOnManual: true,
|
|
91
|
+
})}\n`, 'utf8')
|
|
92
|
+
const result = await reconcileStartupLeftovers()
|
|
93
|
+
assert.ok(result.notes.some((note) => /ProxyBridgeSvc/.test(note)), result.notes.join('; '))
|
|
94
|
+
assert.equal(existsSync(join(dir, 'proxybridge-service.json')), false, 'service state cleared')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('the git config file is only touched for our own entries', () => {
|
|
98
|
+
const text = readFileSync(gitConfig, 'utf8')
|
|
99
|
+
assert.doesNotMatch(text, /git\.example\.com/)
|
|
100
|
+
})
|
package/test/windows.test.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import { readFile } from 'node:fs/promises'
|
|
|
16
16
|
import { join } from 'node:path'
|
|
17
17
|
|
|
18
18
|
import { __test } from '../lib/index.js'
|
|
19
|
+
import { isBashDialectCommand, resolveWindowsRuntime } from '../lib/index.js'
|
|
19
20
|
|
|
20
21
|
const {
|
|
21
22
|
WINDOWS_PATH,
|
|
@@ -161,8 +162,9 @@ test('clicking the IDE button closes the old window and opens a fresh one', () =
|
|
|
161
162
|
assert.match(clientSource, /await requestStandaloneWindowClose\(windowName\)/, 'a dead registration cannot block the next open')
|
|
162
163
|
assert.match(clientSource, /channel\.postMessage\(\{ type: 'close' \}\)/, 'the old window is told to close itself')
|
|
163
164
|
assert.match(clientSource, /if \(state\.alive !== true\) \{ release\(\); resolve\(true\); return \}/, 'the handshake waits for the stream to go')
|
|
164
|
-
assert.match(clientSource, /window\.open\(url\.href, windowName
|
|
165
|
-
assert.doesNotMatch(clientSource, /window\.open\(
|
|
165
|
+
assert.match(clientSource, /window\.open\(url\.href, windowName\)/, 'the new window is opened directly, as a normal window (no blank popup)')
|
|
166
|
+
assert.doesNotMatch(clientSource, /window\.open\(url\.href, windowName, features\)/, 'no sized popup any more')
|
|
167
|
+
assert.doesNotMatch(clientSource, /window\.open\('', windowName/, 'no blank popup that has to be closed again')
|
|
166
168
|
assert.doesNotMatch(clientSource, /settleStandaloneWindow/)
|
|
167
169
|
assert.match(windowHtml, /function closeForOpener\(\)/, 'the window can close itself on request')
|
|
168
170
|
assert.match(windowHtml, /if \(data\.type === 'close'\) \{/, 'the lock holder obeys the close request')
|
|
@@ -196,3 +198,36 @@ test('a restarted host makes every pane drop its stale error and re-read', () =>
|
|
|
196
198
|
assert.match(clientSource, /doc\.kind !== 'error'/, 'only documents that failed are retried (edits are kept)')
|
|
197
199
|
assert.match(clientSource, /setError\(undefined\)\n return true/, 'a successful background read also clears the tree banner')
|
|
198
200
|
})
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
test('a bash-dialect startCommand keeps Git Bash under runtime=auto', () => {
|
|
204
|
+
// `auto` prefers the native PowerShell wrapper, which runs custom commands
|
|
205
|
+
// through cmd.exe; `$(cat cp.txt)` and `exec java` die there without a word
|
|
206
|
+
// (review A2-P1-2). Commands that need a POSIX shell must fall back to Git Bash.
|
|
207
|
+
assert.equal(isBashDialectCommand('mvn compile && exec java -cp "$(cat target/cp.txt)" App'), true)
|
|
208
|
+
assert.equal(isBashDialectCommand('java -jar app.jar --home=$HOME'), true)
|
|
209
|
+
assert.equal(isBashDialectCommand('cd target && java -cp "${CLASSPATH}" App'), true)
|
|
210
|
+
assert.equal(isBashDialectCommand('export JAVA_HOME=/opt/jdk && java -jar app.jar'), true)
|
|
211
|
+
assert.equal(isBashDialectCommand('npm run dev'), false)
|
|
212
|
+
assert.equal(isBashDialectCommand(''), false)
|
|
213
|
+
// An explicit powershell request is respected even for a bash-dialect command;
|
|
214
|
+
// the wrapper then fails loudly instead of silently running under cmd.exe.
|
|
215
|
+
assert.deepEqual(resolveWindowsRuntime('powershell', undefined, { bashDialect: true }), { runtime: 'powershell' })
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('PowerShell commands are not mistaken for bash dialect', () => {
|
|
219
|
+
// `$env:NAME` is how PowerShell spells an environment variable, `$x = 1` is an
|
|
220
|
+
// assignment and `-Command` names powershell itself; none of those can run under
|
|
221
|
+
// Git Bash. Treating them as bash forced Git Bash (or failed with `no-bash` when
|
|
222
|
+
// it was not installed) for the most common PowerShell startCommand (review C3-P1-1).
|
|
223
|
+
assert.equal(isBashDialectCommand('pwsh -NoProfile -Command "$env:JAVA_HOME\\bin\\java -jar app.jar"'), false)
|
|
224
|
+
assert.equal(isBashDialectCommand('powershell -Command "$x = 1; .\\run.ps1"'), false)
|
|
225
|
+
assert.equal(isBashDialectCommand('pwsh -File .\\run.ps1 -Workspace C:\\work'), false)
|
|
226
|
+
assert.equal(isBashDialectCommand('$env:JAVA_HOME = "C:\\jdk"; & "$env:JAVA_HOME\\bin\\java" -jar app.jar'), false)
|
|
227
|
+
assert.equal(isBashDialectCommand('$root = Split-Path -Parent $MyInvocation.MyCommand.Path'), false)
|
|
228
|
+
assert.equal(isBashDialectCommand('Start-Process java -ArgumentList @("-jar","app.jar")'), false)
|
|
229
|
+
// Still bash: `$(...)`, backticks, `${...}`, exec/export/source, ALL-CAPS $VAR.
|
|
230
|
+
assert.equal(isBashDialectCommand('exec java -cp "$(cat cp.txt)" App'), true)
|
|
231
|
+
assert.equal(isBashDialectCommand('java -jar `cat jar.txt`'), true)
|
|
232
|
+
assert.equal(isBashDialectCommand('source ./env.sh && java -jar app.jar'), true)
|
|
233
|
+
})
|