dsh-ris-ide 1.7.1 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -2
- package/bin/check-listing.mjs +247 -0
- package/bin/proxy-janitor.mjs +88 -0
- package/lib/client-codemirror.js +110 -66
- package/lib/client.js +1809 -70
- package/lib/index.js +1638 -11
- package/lib/janitor.js +286 -0
- package/lib/proxy.js +1498 -0
- package/lib/redirector.js +2109 -0
- package/package.json +4 -2
- package/skills/dsh-ris-ide-debug/SKILL.md +37 -2
- package/test/client-viewer.test.mjs +622 -6
- package/test/companion.test.mjs +65 -0
- package/test/host-search.test.mjs +125 -1
- package/test/host-tail.test.mjs +95 -1
- package/test/inherit-engine.test.mjs +175 -0
- package/test/install-phase.test.mjs +36 -0
- package/test/janitor.test.mjs +144 -0
- package/test/lifecycle.test.mjs +88 -0
- package/test/proxy-route.test.mjs +599 -0
- package/test/proxy.test.mjs +873 -0
- package/test/redirector.test.mjs +521 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The two plugins must stay usable standalone, so the companion hint is a
|
|
2
|
+
// RECOMMENDATION that only appears when the workspace really looks like a
|
|
3
|
+
// YonBIP/YMS project — never on an ordinary Java/Vue repo.
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { tmpdir } from 'node:os'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import test from 'node:test'
|
|
9
|
+
|
|
10
|
+
import { __test } from '../lib/index.js'
|
|
11
|
+
|
|
12
|
+
const { detectCompanionPlugin, renderProgramList } = __test
|
|
13
|
+
|
|
14
|
+
function workspace() {
|
|
15
|
+
return mkdtempSync(join(tmpdir(), 'ris-companion-'))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('a plain workspace gets no companion hint', () => {
|
|
19
|
+
const dir = workspace()
|
|
20
|
+
try {
|
|
21
|
+
writeFileSync(join(dir, 'pom.xml'), '<project/>')
|
|
22
|
+
assert.equal(detectCompanionPlugin(dir), null)
|
|
23
|
+
assert.doesNotMatch(renderProgramList({ root: dir, dir, programs: [] }), /dsh-ris-yds/)
|
|
24
|
+
} finally {
|
|
25
|
+
rmSync(dir, { recursive: true, force: true })
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('yms-home marks the workspace as YonBIP/YMS', () => {
|
|
30
|
+
const dir = workspace()
|
|
31
|
+
try {
|
|
32
|
+
mkdirSync(join(dir, 'yms-home'))
|
|
33
|
+
const found = detectCompanionPlugin(dir)
|
|
34
|
+
assert.equal(found.plugin, 'dsh-ris-yds')
|
|
35
|
+
assert.match(found.detected, /yms-home/)
|
|
36
|
+
assert.match(found.hint, /YMS/)
|
|
37
|
+
} finally {
|
|
38
|
+
rmSync(dir, { recursive: true, force: true })
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('.vscode/settings.json with yds.* marks it too', () => {
|
|
43
|
+
const dir = workspace()
|
|
44
|
+
try {
|
|
45
|
+
mkdirSync(join(dir, '.vscode'))
|
|
46
|
+
writeFileSync(join(dir, '.vscode', 'settings.json'), JSON.stringify({ 'yds.module': 'c-ass-kk-hans' }))
|
|
47
|
+
assert.equal(detectCompanionPlugin(dir).plugin, 'dsh-ris-yds')
|
|
48
|
+
} finally {
|
|
49
|
+
rmSync(dir, { recursive: true, force: true })
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('the program list renders the hint as an optional extra line', () => {
|
|
54
|
+
const dir = workspace()
|
|
55
|
+
try {
|
|
56
|
+
mkdirSync(join(dir, 'yms-home'))
|
|
57
|
+
const text = renderProgramList({ root: dir, dir: join(dir, 'logs'), programs: [], companion: detectCompanionPlugin(dir) })
|
|
58
|
+
assert.match(text, /No runnable programs/)
|
|
59
|
+
assert.match(text, /Optional companion plugin: dsh-ris-yds/)
|
|
60
|
+
// Null companion keeps the rendered list exactly as before.
|
|
61
|
+
assert.doesNotMatch(renderProgramList({ root: dir, dir, programs: [], companion: null }), /Optional companion plugin/)
|
|
62
|
+
} finally {
|
|
63
|
+
rmSync(dir, { recursive: true, force: true })
|
|
64
|
+
}
|
|
65
|
+
})
|
|
@@ -22,7 +22,8 @@ import { __test } from '../lib/index.js'
|
|
|
22
22
|
|
|
23
23
|
const {
|
|
24
24
|
handleRequest, searchWorkspaceContent,
|
|
25
|
-
CONTENT_SEARCH_PATH,
|
|
25
|
+
CONTENT_SEARCH_PATH, SEARCH_STREAM_PATH, CONTENT_SEARCH_STREAM_PATH,
|
|
26
|
+
RUN_TEST_PATH, START_PATH, STOP_PATH, PROGRAMS_PATH,
|
|
26
27
|
runTestOutput, RUN_TEST_HEAD_CHARS, RUN_TEST_TAIL_CHARS, RUN_TEST_MAX_RECORDS,
|
|
27
28
|
HARD_MAX_BYTES, PID_SUFFIX, IS_WINDOWS,
|
|
28
29
|
} = __test
|
|
@@ -157,6 +158,129 @@ test('GET /search-content serves hits and rejects a missing q or the wrong metho
|
|
|
157
158
|
}, root)
|
|
158
159
|
})
|
|
159
160
|
|
|
161
|
+
// ── Streamed search routes (async paging) ──────────────────────────────────
|
|
162
|
+
|
|
163
|
+
/** Read one NDJSON search answer into its frames, in arrival order. */
|
|
164
|
+
async function readNdjson(response) {
|
|
165
|
+
const frames = []
|
|
166
|
+
const reader = response.body.getReader()
|
|
167
|
+
const decoder = new TextDecoder()
|
|
168
|
+
let buffer = ''
|
|
169
|
+
for (;;) {
|
|
170
|
+
const { done, value } = await reader.read()
|
|
171
|
+
if (done) break
|
|
172
|
+
buffer += decoder.decode(value, { stream: true })
|
|
173
|
+
let index = buffer.indexOf('\n')
|
|
174
|
+
while (index !== -1) {
|
|
175
|
+
const line = buffer.slice(0, index).trim()
|
|
176
|
+
buffer = buffer.slice(index + 1)
|
|
177
|
+
if (line !== '') frames.push(JSON.parse(line))
|
|
178
|
+
index = buffer.indexOf('\n')
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return frames
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Two nested repo roots (`aa-repo`, `bb-repo`), each holding one matching file. */
|
|
185
|
+
async function makeTwoRootFixture(label) {
|
|
186
|
+
const root = await mkdtemp(join(scratch, `${label}-`))
|
|
187
|
+
for (const name of ['aa-repo', 'bb-repo']) {
|
|
188
|
+
const dir = join(root, name)
|
|
189
|
+
await mkdir(dir, { recursive: true })
|
|
190
|
+
await writeFile(join(dir, 'agent-one.txt'), 'needle one\nsecond needle\n')
|
|
191
|
+
await writeFile(join(dir, 'other.txt'), 'nothing here\n')
|
|
192
|
+
execFileSync('git', ['init', '-q'], { cwd: dir })
|
|
193
|
+
execFileSync('git', ['add', '-A'], { cwd: dir })
|
|
194
|
+
}
|
|
195
|
+
return root
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
test('createOrderedPages spends the row budget in root order, not arrival order', () => {
|
|
199
|
+
// Roots answer concurrently: rows of a LATER root must never consume the budget
|
|
200
|
+
// before an earlier root has been emitted, or the streamed prefix would differ
|
|
201
|
+
// from the (sequential) batch answer. Roots 2 and 1 fill their buffers first.
|
|
202
|
+
const pages = []
|
|
203
|
+
let full = 0
|
|
204
|
+
const emitter = __test.createOrderedPages(3, 2, (page) => pages.push(page), { maxItems: 3, onFull: () => { full += 1 } })
|
|
205
|
+
emitter.push(2, ['c1', 'c2', 'c3'])
|
|
206
|
+
emitter.push(1, ['b1', 'b2', 'b3'])
|
|
207
|
+
assert.deepEqual(pages, [], 'a non-head root only buffers, whatever arrives first')
|
|
208
|
+
emitter.push(0, ['a1', 'a2', 'a3'])
|
|
209
|
+
assert.deepEqual(pages, [['a1', 'a2']], 'the head root pages as it fills')
|
|
210
|
+
emitter.finish(0)
|
|
211
|
+
assert.deepEqual(pages, [['a1', 'a2'], ['a3']], 'its remainder goes out as a short page')
|
|
212
|
+
assert.equal(full, 1, 'the third row spends the budget and closes the emitter')
|
|
213
|
+
assert.equal(emitter.total(), 3)
|
|
214
|
+
assert.equal(emitter.isClosed(), true)
|
|
215
|
+
// Nothing leaks in after the budget is spent, and later roots cannot emit.
|
|
216
|
+
emitter.push(2, ['c4'])
|
|
217
|
+
emitter.finish(1)
|
|
218
|
+
emitter.finish(2)
|
|
219
|
+
assert.deepEqual(pages, [['a1', 'a2'], ['a3']])
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
test('GET /search/stream pages the filename matches in tree order and ends with done', async () => {
|
|
223
|
+
const root = await makeTwoRootFixture('stream-name')
|
|
224
|
+
await withServer(async ({ base }) => {
|
|
225
|
+
const response = await fetch(`${base}${SEARCH_STREAM_PATH}?sessionId=s1&q=agent&pageSize=1&limit=10`)
|
|
226
|
+
assert.equal(response.status, 200)
|
|
227
|
+
assert.match(String(response.headers.get('content-type')), /application\/x-ndjson/)
|
|
228
|
+
const frames = await readNdjson(response)
|
|
229
|
+
assert.equal(frames[0].type, 'start')
|
|
230
|
+
assert.equal(frames[0].root, root)
|
|
231
|
+
assert.equal(frames[0].repoCount, 2, 'two nested repo roots are searched')
|
|
232
|
+
const pages = frames.filter((frame) => frame.type === 'page')
|
|
233
|
+
assert.equal(pages.length, 2, 'pageSize=1 ⇒ one page per matching root')
|
|
234
|
+
assert.deepEqual(pages.map((page) => page.items), [
|
|
235
|
+
[join(root, 'aa-repo', 'agent-one.txt')],
|
|
236
|
+
[join(root, 'bb-repo', 'agent-one.txt')],
|
|
237
|
+
], 'pages follow the repo-root order, never the completion order')
|
|
238
|
+
const done = frames.at(-1)
|
|
239
|
+
assert.equal(done.type, 'done')
|
|
240
|
+
assert.equal(done.matches, 2)
|
|
241
|
+
assert.equal(done.files, 4)
|
|
242
|
+
assert.equal(done.truncated, false)
|
|
243
|
+
}, root)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('GET /search-content/stream pages grep hits and keeps the batch validation', async () => {
|
|
247
|
+
const root = await makeTwoRootFixture('stream-content')
|
|
248
|
+
await withServer(async ({ base }) => {
|
|
249
|
+
const response = await fetch(`${base}${CONTENT_SEARCH_STREAM_PATH}?sessionId=s1&q=needle&pageSize=1&limit=10`)
|
|
250
|
+
assert.equal(response.status, 200)
|
|
251
|
+
const frames = await readNdjson(response)
|
|
252
|
+
const hits = frames.filter((frame) => frame.type === 'page').flatMap((frame) => frame.items)
|
|
253
|
+
assert.deepEqual(hits.map((hit) => `${hit.path.slice(root.length + 1)}:${hit.line}`), [
|
|
254
|
+
'aa-repo/agent-one.txt:1',
|
|
255
|
+
'aa-repo/agent-one.txt:2',
|
|
256
|
+
'bb-repo/agent-one.txt:1',
|
|
257
|
+
'bb-repo/agent-one.txt:2',
|
|
258
|
+
])
|
|
259
|
+
assert.deepEqual(frames.at(-1), { type: 'done', files: 2, matches: 4, truncated: false })
|
|
260
|
+
|
|
261
|
+
// A content search still needs a query, and the stream routes stay GET-only.
|
|
262
|
+
const missingQ = await fetch(`${base}${CONTENT_SEARCH_STREAM_PATH}?sessionId=s1`)
|
|
263
|
+
assert.equal(missingQ.status, 400)
|
|
264
|
+
assert.equal((await missingQ.json()).code, 'bad-request')
|
|
265
|
+
const wrongMethod = await postJson(base, SEARCH_STREAM_PATH, { sessionId: 's1', q: 'needle' })
|
|
266
|
+
assert.equal(wrongMethod.status, 405)
|
|
267
|
+
const noSession = await fetch(`${base}${SEARCH_STREAM_PATH}?q=needle`)
|
|
268
|
+
assert.equal(noSession.status, 400)
|
|
269
|
+
}, root)
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
test('GET /search/stream stops early at limit and reports truncated', async () => {
|
|
273
|
+
const root = await makeTwoRootFixture('stream-limit')
|
|
274
|
+
await withServer(async ({ base }) => {
|
|
275
|
+
const response = await fetch(`${base}${SEARCH_STREAM_PATH}?sessionId=s1&q=agent&pageSize=2&limit=1`)
|
|
276
|
+
const frames = await readNdjson(response)
|
|
277
|
+
const items = frames.filter((frame) => frame.type === 'page').flatMap((frame) => frame.items)
|
|
278
|
+
assert.equal(items.length, 1)
|
|
279
|
+
assert.equal(frames.at(-1).type, 'done')
|
|
280
|
+
assert.equal(frames.at(-1).truncated, true, 'limit=1 is reached before the second root answers')
|
|
281
|
+
}, root)
|
|
282
|
+
})
|
|
283
|
+
|
|
160
284
|
// ── Run-test route: validation ──────────────────────────────────────────────
|
|
161
285
|
|
|
162
286
|
/** A cwd holding one real Maven module (`mod/pom.xml`). */
|
package/test/host-tail.test.mjs
CHANGED
|
@@ -406,7 +406,9 @@ test('the stop route terminates a real run-with-log.sh service end to end', asyn
|
|
|
406
406
|
// The wrapper writes its exit banner just before it exits; under a loaded
|
|
407
407
|
// parallel test run the read can win the race, so poll briefly.
|
|
408
408
|
let banner = ''
|
|
409
|
-
|
|
409
|
+
// Generous budget: the wrapper is bash that has to reap `sleep`, trap TERM
|
|
410
|
+
// and write the banner, and the full test run keeps several files in flight.
|
|
411
|
+
for (let attempt = 0; attempt < 400; attempt += 1) {
|
|
410
412
|
banner = await readFile(log, 'utf8')
|
|
411
413
|
if (/stoptest exited/.test(banner)) break
|
|
412
414
|
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
@@ -529,6 +531,19 @@ async function makeStartableFixture() {
|
|
|
529
531
|
return { root }
|
|
530
532
|
}
|
|
531
533
|
|
|
534
|
+
test('a frontend row is named after module.xml, not the package.json domainKey', async () => {
|
|
535
|
+
const root = await mkdtemp(join(tmpdir(), 'dsh-ris-ide-fe-'))
|
|
536
|
+
const dir = join(root, 'my-fe')
|
|
537
|
+
await mkdir(dir, { recursive: true })
|
|
538
|
+
// MDF projects keep the backend domainKey in package.json — that is the collision.
|
|
539
|
+
await writeFile(join(dir, 'package.json'), JSON.stringify({ name: 'c-ass-kk-hans', scripts: { dev: 'vite' } }))
|
|
540
|
+
await writeFile(join(dir, 'module.xml'), '<module name="c-ass-kk-hans-fe" description="前端"><nginx_mode>mdf</nginx_mode></module>')
|
|
541
|
+
const programs = await scanPrograms(root, join(root, 'logs'), true)
|
|
542
|
+
const frontend = programs.filter((p) => p.kind === 'frontend')
|
|
543
|
+
assert.equal(frontend.length, 1)
|
|
544
|
+
assert.equal(frontend[0].name, 'c-ass-kk-hans-fe')
|
|
545
|
+
})
|
|
546
|
+
|
|
532
547
|
test('scanPrograms finds Spring Boot entries and frontend manifests, and skips node_modules', async () => {
|
|
533
548
|
const { root, moduleDir, uiDir } = await makeProgramFixture()
|
|
534
549
|
const logsDir = join(root, 'logs')
|
|
@@ -551,6 +566,7 @@ test('scanPrograms finds Spring Boot entries and frontend manifests, and skips n
|
|
|
551
566
|
`--spring.config.additional-location=file:${join(root, 'local.yml')}`,
|
|
552
567
|
])
|
|
553
568
|
assert.equal(frontend[0].dir, uiDir)
|
|
569
|
+
// No module.xml: a plain npm project keeps its package.json name.
|
|
554
570
|
assert.equal(frontend[0].name, 'demo-ui')
|
|
555
571
|
assert.equal(frontend[0].script, 'dev')
|
|
556
572
|
assert.equal(frontend[0].packageManager, 'pnpm', 'inferred from pnpm-lock.yaml')
|
|
@@ -1773,11 +1789,15 @@ test('listIdeTree hides ignored files and folds package chains only under java',
|
|
|
1773
1789
|
// A single-child folder chain OUTSIDE java must stay as separate rows.
|
|
1774
1790
|
await mkdir(join(root, 'docs', 'guide'), { recursive: true })
|
|
1775
1791
|
await writeFile(join(root, 'docs', 'guide', 'readme.md'), '# guide\n')
|
|
1792
|
+
// A chunked save stages its document next to the target; a crashed save may
|
|
1793
|
+
// leave one behind and it must never become a tree row.
|
|
1794
|
+
await writeFile(join(root, 'a.java' + __test.FS_WRITE_TEMP_SUFFIX), 'half a doc')
|
|
1776
1795
|
|
|
1777
1796
|
const level = await __test.listIdeTree(root, root)
|
|
1778
1797
|
const labels = level.entries.map((entry) => entry.label)
|
|
1779
1798
|
assert.ok(labels.includes('a.java'), 'a tracked/untracked-but-not-ignored file shows')
|
|
1780
1799
|
assert.equal(labels.includes('debug.log'), false, '*.log is ignored')
|
|
1800
|
+
assert.equal(labels.includes('a.java' + __test.FS_WRITE_TEMP_SUFFIX), false, 'save staging files stay out of the tree')
|
|
1781
1801
|
assert.equal(labels.includes('ignored'), false, 'an ignored directory disappears')
|
|
1782
1802
|
// src -> main -> java is a single-child chain, but it is NOT a package tail.
|
|
1783
1803
|
assert.equal(labels.includes('src'), true, 'src/main/java is not compacted into one row')
|
|
@@ -2292,6 +2312,64 @@ test('the fs routes read text, refuse binary/oversized and write back', async ()
|
|
|
2292
2312
|
assert.equal(written.status, 200)
|
|
2293
2313
|
assert.equal(written.body.ok, true)
|
|
2294
2314
|
assert.equal((await call('fs/read', { query: { sessionId: 's1', path: textFile } })).body.content, 'class A { int x; }\n')
|
|
2315
|
+
|
|
2316
|
+
// A save carries the whole document: the 64 KB generic JSON cap must NOT apply
|
|
2317
|
+
// to /fs/write (that is what made every save of a >64 KB file fail with
|
|
2318
|
+
// "request body too large"). 120 KB is an ordinary source file.
|
|
2319
|
+
const large = 'x'.repeat(120 * 1024)
|
|
2320
|
+
const largeSaved = await call('fs/write', { body: { sessionId: 's1', path: textFile, content: large } })
|
|
2321
|
+
assert.equal(largeSaved.status, 200, JSON.stringify(largeSaved.body))
|
|
2322
|
+
assert.equal(largeSaved.body.ok, true)
|
|
2323
|
+
const largeRead = await call('fs/read', { query: { sessionId: 's1', path: textFile } })
|
|
2324
|
+
assert.equal(largeRead.status, 200)
|
|
2325
|
+
assert.equal(largeRead.body.kind, 'text')
|
|
2326
|
+
assert.equal(largeRead.body.content, large, 'every byte of the large document landed')
|
|
2327
|
+
|
|
2328
|
+
// Above the writer's own ceiling the answer is a readable Chinese message,
|
|
2329
|
+
// not a bare "request body too large".
|
|
2330
|
+
const huge = await call('fs/write', { body: { sessionId: 's1', path: textFile, content: 'y'.repeat(9 * 1024 * 1024) } })
|
|
2331
|
+
assert.equal(huge.status, 413)
|
|
2332
|
+
assert.equal(huge.body.ok, false)
|
|
2333
|
+
assert.match(huge.body.message, /文件太大/)
|
|
2334
|
+
assert.match(huge.body.message, /8 MB/)
|
|
2335
|
+
const { stat } = await import('node:fs/promises')
|
|
2336
|
+
assert.equal((await stat(textFile)).size, Buffer.byteLength(large),
|
|
2337
|
+
'the refused save must not touch the file on disk')
|
|
2338
|
+
|
|
2339
|
+
// Chunked save: the editor sends utf8 pieces with byte offsets. Nothing is
|
|
2340
|
+
// visible until the final chunk renames the staged file over the target.
|
|
2341
|
+
const pieces = ['α' + 'b'.repeat(5000), '汉'.repeat(4000), 'end']
|
|
2342
|
+
const staging = textFile + __test.FS_WRITE_TEMP_SUFFIX
|
|
2343
|
+
let offset = 0
|
|
2344
|
+
for (let index = 0; index < pieces.length; index += 1) {
|
|
2345
|
+
const final = index === pieces.length - 1
|
|
2346
|
+
const answer = await call('fs/write', { body: { sessionId: 's1', path: textFile, content: pieces[index], offset, final } })
|
|
2347
|
+
assert.equal(answer.status, 200, JSON.stringify(answer.body))
|
|
2348
|
+
assert.equal(answer.body.chunked, true)
|
|
2349
|
+
assert.equal(answer.body.final, final)
|
|
2350
|
+
offset += Buffer.byteLength(pieces[index])
|
|
2351
|
+
if (!final) {
|
|
2352
|
+
assert.equal(existsSync(staging), true, 'a non-final chunk stages the document')
|
|
2353
|
+
assert.equal((await stat(textFile)).size, Buffer.byteLength(large), 'the old file is still intact mid-save')
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
assert.equal(existsSync(staging), false, 'the staging file is renamed away')
|
|
2357
|
+
const chunkedRead = await call('fs/read', { query: { sessionId: 's1', path: textFile } })
|
|
2358
|
+
assert.equal(chunkedRead.body.content, pieces.join(''))
|
|
2359
|
+
|
|
2360
|
+
// A skipped chunk is refused instead of silently leaving zero bytes behind.
|
|
2361
|
+
const firstChunk = await call('fs/write', { body: { sessionId: 's1', path: textFile, content: 'abc', offset: 0, final: false } })
|
|
2362
|
+
assert.equal(firstChunk.status, 200)
|
|
2363
|
+
const skipped = await call('fs/write', { body: { sessionId: 's1', path: textFile, content: 'def', offset: 9, final: true } })
|
|
2364
|
+
assert.equal(skipped.status, 409)
|
|
2365
|
+
assert.match(skipped.body.message, /missing/)
|
|
2366
|
+
assert.equal((await call('fs/read', { query: { sessionId: 's1', path: textFile } })).body.content, pieces.join(''),
|
|
2367
|
+
'a broken chunked save leaves the previous document in place')
|
|
2368
|
+
// Starting over at offset 0 recovers.
|
|
2369
|
+
await call('fs/write', { body: { sessionId: 's1', path: textFile, content: 'abc', offset: 0, final: false } })
|
|
2370
|
+
const recovered = await call('fs/write', { body: { sessionId: 's1', path: textFile, content: 'def', offset: 3, final: true } })
|
|
2371
|
+
assert.equal(recovered.status, 200)
|
|
2372
|
+
assert.equal((await call('fs/read', { query: { sessionId: 's1', path: textFile } })).body.content, 'abcdef')
|
|
2295
2373
|
})
|
|
2296
2374
|
|
|
2297
2375
|
// ── a browser that cancels an image/file stream must not kill the host ─────
|
|
@@ -2959,3 +3037,19 @@ test('fs/window pages a large file and never splits a multi-byte character', asy
|
|
|
2959
3037
|
assert.equal(__test.utf8CompleteLength(Buffer.from('ab中', 'utf8')), 5)
|
|
2960
3038
|
assert.equal(__test.utf8CompleteLength(Buffer.alloc(0)), 0)
|
|
2961
3039
|
})
|
|
3040
|
+
|
|
3041
|
+
test('a same-named row of another kind is not taken over by an update', () => {
|
|
3042
|
+
// A yds project: the launcher row is `spring`, the discovered frontend row carries
|
|
3043
|
+
// the package.json name — an update must not move the launcher's startCommand onto
|
|
3044
|
+
// the frontend row (that would delete the only way to start the backend).
|
|
3045
|
+
const next = { version: 1, defaults: { jvmArgs: [] }, programs: [
|
|
3046
|
+
{ id: 'frontend:fe#start', name: 'c-ass-kk-hans', kind: 'frontend', dir: 'fe', script: 'start' },
|
|
3047
|
+
] }
|
|
3048
|
+
const oldEntries = [
|
|
3049
|
+
{ name: 'c-ass-kk-hans', kind: 'spring', dir: '.', startCommand: 'node x/bin/yds.js start' },
|
|
3050
|
+
]
|
|
3051
|
+
const merged = mergeConfigDocuments(next, oldEntries, '/ws')
|
|
3052
|
+
assert.equal(merged.programs.length, 2, 'the launcher stays a separate row')
|
|
3053
|
+
assert.equal(merged.programs[0].startCommand, undefined, 'the frontend row keeps its own launch path')
|
|
3054
|
+
assert.equal(merged.programs[1].startCommand, 'node x/bin/yds.js start')
|
|
3055
|
+
})
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An engine left behind by a previous dsh process (the Ctrl+C leak under the old
|
|
3
|
+
* teardown) must be adopted and reported as inherited, not ignored or duplicated.
|
|
4
|
+
*
|
|
5
|
+
* A live janitor means the machine already has an owner for that engine (another
|
|
6
|
+
* dsh, or a watcher about to clean up after a crash) — that engine must NOT be
|
|
7
|
+
* claimed as ours.
|
|
8
|
+
*/
|
|
9
|
+
import assert from 'node:assert/strict'
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
import { existsSync, mkdtempSync, rmSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { connect, createServer } from 'node:net'
|
|
13
|
+
import { tmpdir } from 'node:os'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
import { after, test } from 'node:test'
|
|
17
|
+
|
|
18
|
+
const home = mkdtempSync(join(tmpdir(), 'ris-inherit-'))
|
|
19
|
+
const workspace = mkdtempSync(join(tmpdir(), 'ris-inherit-ws-'))
|
|
20
|
+
process.env.DSH_RIS_IDE_PROXY_HOME = home
|
|
21
|
+
|
|
22
|
+
const { __test } = await import('../lib/index.js')
|
|
23
|
+
const { proxyPid, proxyPidPath } = await import('../lib/proxy.js')
|
|
24
|
+
const { janitorStatePath, disarmJanitor } = await import('../lib/janitor.js')
|
|
25
|
+
|
|
26
|
+
const PROXY = fileURLToPath(new URL('../lib/proxy.js', import.meta.url))
|
|
27
|
+
const MARKER = 'dsh-ris-ide-proxy'
|
|
28
|
+
/** @type {import('node:child_process').ChildProcess | null} */
|
|
29
|
+
let engine = null
|
|
30
|
+
|
|
31
|
+
/** @returns {Promise<number>} a port the OS says is free right now. */
|
|
32
|
+
function freePort() {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
const server = createServer()
|
|
35
|
+
server.listen(0, '127.0.0.1', () => {
|
|
36
|
+
const { port } = server.address()
|
|
37
|
+
server.close(() => resolve(port))
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resolve once something accepts a TCP connection on the port.
|
|
44
|
+
* @param {number} port the port to probe.
|
|
45
|
+
* @param {{attempts?: number, interval?: number}} [options] budget.
|
|
46
|
+
* @returns {Promise<boolean>} whether the port accepted a connection.
|
|
47
|
+
*/
|
|
48
|
+
function waitForPort(port, { attempts = 60, interval = 100 } = {}) {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
let tries = 0
|
|
51
|
+
const attempt = () => {
|
|
52
|
+
const socket = connect({ host: '127.0.0.1', port })
|
|
53
|
+
socket.once('connect', () => { socket.destroy(); resolve(true) })
|
|
54
|
+
socket.once('error', () => {
|
|
55
|
+
socket.destroy()
|
|
56
|
+
tries += 1
|
|
57
|
+
if (tries >= attempts) resolve(false)
|
|
58
|
+
else setTimeout(attempt, interval)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
attempt()
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Poll a predicate until it holds (or the attempts run out).
|
|
67
|
+
* @param {() => boolean} predicate the condition.
|
|
68
|
+
* @param {{attempts?: number, interval?: number}} [options] budget.
|
|
69
|
+
* @returns {Promise<boolean>} whether it held.
|
|
70
|
+
*/
|
|
71
|
+
function waitFor(predicate, { attempts = 120, interval = 100 } = {}) {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
let tries = 0
|
|
74
|
+
const timer = setInterval(() => {
|
|
75
|
+
tries += 1
|
|
76
|
+
if (predicate()) {
|
|
77
|
+
clearInterval(timer)
|
|
78
|
+
resolve(true)
|
|
79
|
+
} else if (tries >= attempts) {
|
|
80
|
+
clearInterval(timer)
|
|
81
|
+
resolve(false)
|
|
82
|
+
}
|
|
83
|
+
}, interval)
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Spawn a detached engine exactly the way startProxy does, and publish its pidfile.
|
|
89
|
+
* @returns {Promise<{child: import('node:child_process').ChildProcess, port: number}>} the child and its port.
|
|
90
|
+
*/
|
|
91
|
+
async function spawnOrphanEngine() {
|
|
92
|
+
const port = await freePort()
|
|
93
|
+
writeFileSync(join(home, 'proxy.json'), JSON.stringify({
|
|
94
|
+
listenPort: port,
|
|
95
|
+
socks: { host: '10.3.91.121', port: 1080 },
|
|
96
|
+
rules: [],
|
|
97
|
+
shadows: [],
|
|
98
|
+
}))
|
|
99
|
+
const child = spawn(process.execPath, [PROXY, '--cwd', workspace, 'serve', `--marker=${MARKER}`], {
|
|
100
|
+
detached: true, stdio: 'ignore', windowsHide: true,
|
|
101
|
+
})
|
|
102
|
+
child.unref()
|
|
103
|
+
writeFileSync(proxyPidPath(), String(child.pid))
|
|
104
|
+
return { child, port }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Kill a spawned engine (SIGTERM is enough; it exits within the poll budget).
|
|
109
|
+
* @param {import('node:child_process').ChildProcess} child the engine.
|
|
110
|
+
* @returns {Promise<void>} settles when it is gone.
|
|
111
|
+
*/
|
|
112
|
+
async function killEngine(child) {
|
|
113
|
+
if (child.exitCode === null) {
|
|
114
|
+
try { child.kill('SIGTERM') } catch { /* already gone */ }
|
|
115
|
+
await waitFor(() => child.exitCode !== null, { attempts: 50, interval: 100 })
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
after(async () => {
|
|
120
|
+
if (engine !== null) await killEngine(engine)
|
|
121
|
+
disarmJanitor()
|
|
122
|
+
rmSync(home, { recursive: true, force: true })
|
|
123
|
+
rmSync(workspace, { recursive: true, force: true })
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('an engine with no watcher is adopted and shown as inherited', async () => {
|
|
127
|
+
// The pre-fix crash path: process.exit() killed dsh, the detached engine kept
|
|
128
|
+
// running, and no janitor state survived to name its owner.
|
|
129
|
+
rmSync(janitorStatePath(), { force: true })
|
|
130
|
+
const spawned = await spawnOrphanEngine()
|
|
131
|
+
engine = spawned.child
|
|
132
|
+
const ready = await waitForPort(spawned.port)
|
|
133
|
+
assert.equal(ready, true, 'the engine should start listening in the temp home')
|
|
134
|
+
assert.equal(await waitFor(() => proxyPid() === engine.pid), true, 'the pidfile must identify the engine')
|
|
135
|
+
|
|
136
|
+
const adopted = __test.adoptLeftoverEngine()
|
|
137
|
+
assert.notEqual(adopted, null, 'an engine with no watcher must be adopted')
|
|
138
|
+
assert.equal(adopted.pid, engine.pid)
|
|
139
|
+
|
|
140
|
+
const view = await __test.proxyView(workspace)
|
|
141
|
+
assert.equal(view.running, true, 'the adopted engine is the running one')
|
|
142
|
+
assert.equal(view.inherited, true, 'the dialog must mark it as inherited')
|
|
143
|
+
assert.equal(view.inheritedPid, engine.pid)
|
|
144
|
+
assert.equal(view.inheritedFrom, 0, 'no watcher state means the old dsh pid is unknown')
|
|
145
|
+
assert.equal(view.owner, 0, 'nothing owns it before this process arms the watcher')
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('the banner disappears once the adopted engine is gone', async () => {
|
|
149
|
+
assert.notEqual(engine, null)
|
|
150
|
+
await killEngine(engine)
|
|
151
|
+
rmSync(proxyPidPath(), { force: true })
|
|
152
|
+
assert.equal(__test.adoptLeftoverEngine(), null, 'a dead engine is nothing to inherit')
|
|
153
|
+
const view = await __test.proxyView(workspace)
|
|
154
|
+
assert.equal(view.inherited, false)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('a live watcher means the engine has an owner and must not be claimed', async () => {
|
|
158
|
+
const spawned = await spawnOrphanEngine()
|
|
159
|
+
engine = spawned.child
|
|
160
|
+
assert.equal(await waitForPort(spawned.port), true, 'the engine should start listening')
|
|
161
|
+
assert.equal(await waitFor(() => proxyPid() === engine.pid), true, 'the pidfile must identify the engine')
|
|
162
|
+
// A watcher exists and is alive, but it watches a dead dsh: this is the
|
|
163
|
+
// crash-in-progress case — the engine is about to be cleaned up, not ours.
|
|
164
|
+
writeFileSync(janitorStatePath(), JSON.stringify({
|
|
165
|
+
// The watcher pid must be a live process that is NOT us: disarmJanitor() in the
|
|
166
|
+
// teardown would SIGTERM its own test runner otherwise.
|
|
167
|
+
pid: engine.pid,
|
|
168
|
+
owner: 999999,
|
|
169
|
+
log: join(home, 'janitor.log'),
|
|
170
|
+
}))
|
|
171
|
+
assert.equal(__test.adoptLeftoverEngine(), null, 'a live watcher is not ours to take over')
|
|
172
|
+
const view = await __test.proxyView(workspace)
|
|
173
|
+
assert.equal(view.inherited, false, 'the dialog must not claim an engine another watcher owns')
|
|
174
|
+
rmSync(janitorStatePath(), { force: true })
|
|
175
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { installPlanFor } from '../lib/index.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A clone without node_modules is the common case for a fresh frontend checkout:
|
|
10
|
+
* the panel must install before it runs, and the log has to say so.
|
|
11
|
+
*/
|
|
12
|
+
test('installPlanFor installs only when dependencies are missing', () => {
|
|
13
|
+
const root = mkdtempSync(join(tmpdir(), 'dsh-install-'))
|
|
14
|
+
// No package.json: not a node project at all.
|
|
15
|
+
assert.equal(installPlanFor(root), null)
|
|
16
|
+
|
|
17
|
+
writeFileSync(join(root, 'package.json'), '{"name":"demo"}')
|
|
18
|
+
assert.deepEqual(installPlanFor(root), { pm: 'npm', args: ['install', '--no-audit', '--no-fund'], dir: root })
|
|
19
|
+
|
|
20
|
+
// An empty node_modules is what a killed install leaves behind.
|
|
21
|
+
mkdirSync(join(root, 'node_modules'))
|
|
22
|
+
assert.notEqual(installPlanFor(root), null)
|
|
23
|
+
|
|
24
|
+
writeFileSync(join(root, 'node_modules', 'leftover'), '')
|
|
25
|
+
assert.equal(installPlanFor(root), null)
|
|
26
|
+
|
|
27
|
+
// Lockfile decides the package manager.
|
|
28
|
+
rmSync(join(root, 'node_modules'), { recursive: true, force: true })
|
|
29
|
+
writeFileSync(join(root, 'pnpm-lock.yaml'), '')
|
|
30
|
+
assert.equal(installPlanFor(root)?.pm, 'pnpm')
|
|
31
|
+
rmSync(join(root, 'pnpm-lock.yaml'))
|
|
32
|
+
writeFileSync(join(root, 'yarn.lock'), '')
|
|
33
|
+
assert.equal(installPlanFor(root)?.pm, 'yarn')
|
|
34
|
+
|
|
35
|
+
rmSync(root, { recursive: true, force: true })
|
|
36
|
+
})
|