brsh 3.10.1 → 3.10.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/CHANGELOG.md +14 -0
- package/dist/shell.es.js +650 -548
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +16 -15
- package/dist/shell.min.js.map +1 -1
- package/dist/wbt.es.js +170 -88
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +10 -10
- package/dist/wbt.min.js.map +1 -1
- package/index.js +64 -13
- package/lib/Command.js +3 -2
- package/lib/ScriptCommand.js +47 -17
- package/lib/WasmCommand.js +79 -12
- package/lib/wbt/index.js +22 -4
- package/package.json +1 -1
- package/test/devices-signals.test.js +194 -0
- package/test/doom.test.js +62 -3
- package/test/fixtures/nano.wasm +0 -0
- package/test/scripts.test.js +48 -0
- package/test/shell.test.js +60 -0
- package/test/wbt.test.js +41 -0
|
@@ -281,5 +281,199 @@ describe('WASM requirements auto-discovery', () => {
|
|
|
281
281
|
await p;
|
|
282
282
|
expect(shell.lastCode).toBe(0);
|
|
283
283
|
});
|
|
284
|
+
|
|
285
|
+
function buildTermiosTestWasm(initialLflag) {
|
|
286
|
+
const uleb = (n) => {
|
|
287
|
+
const out = [];
|
|
288
|
+
do {
|
|
289
|
+
let b = n & 0x7f;
|
|
290
|
+
n >>>= 7;
|
|
291
|
+
if (n) b |= 0x80;
|
|
292
|
+
out.push(b);
|
|
293
|
+
} while (n);
|
|
294
|
+
return out;
|
|
295
|
+
};
|
|
296
|
+
const sleb = (n) => {
|
|
297
|
+
const out = [];
|
|
298
|
+
let more = true;
|
|
299
|
+
while (more) {
|
|
300
|
+
let b = n & 0x7f;
|
|
301
|
+
n >>= 7;
|
|
302
|
+
if ((n === 0 && (b & 0x40) === 0) || (n === -1 && (b & 0x40) !== 0)) more = false;
|
|
303
|
+
else b |= 0x80;
|
|
304
|
+
out.push(b);
|
|
305
|
+
}
|
|
306
|
+
return out;
|
|
307
|
+
};
|
|
308
|
+
const str = (s) => {
|
|
309
|
+
const b = Buffer.from(s, 'utf8');
|
|
310
|
+
return [...uleb(b.length), ...b];
|
|
311
|
+
};
|
|
312
|
+
const sec = (id, body) => [id, ...uleb(body.length), ...body];
|
|
313
|
+
const vec = (items) => [...uleb(items.length), ...items.flat()];
|
|
314
|
+
const fnBody = (locals, instrs) => {
|
|
315
|
+
const b = [...vec(locals), ...instrs, 0x0b];
|
|
316
|
+
return [...uleb(b.length), ...b];
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const types = sec(1, vec([
|
|
320
|
+
[0x60, 0, 0],
|
|
321
|
+
[0x60, 0, 1, 0x7f],
|
|
322
|
+
[0x60, 1, 0x7f, 0],
|
|
323
|
+
[0x60, 2, 0x7f, 0x7f, 0],
|
|
324
|
+
[0x60, 4, 0x7f, 0x7f, 0x7f, 0x7f, 1, 0x7f],
|
|
325
|
+
]));
|
|
326
|
+
const imports = sec(2, vec([
|
|
327
|
+
[...str('wasi_snapshot_preview1'), ...str('clock_nanosleep'), 0x00, 4],
|
|
328
|
+
[...str('wasi_snapshot_preview1'), ...str('fd_read'), 0x00, 4],
|
|
329
|
+
[...str('wasi_snapshot_preview1'), ...str('fd_write'), 0x00, 4],
|
|
330
|
+
]));
|
|
331
|
+
const funcs = sec(3, vec([3, 1, 2, 0, 2, 0, 1, 0]));
|
|
332
|
+
const mem = sec(5, vec([[0x00, 1]]));
|
|
333
|
+
const globals = sec(6, vec([
|
|
334
|
+
[0x7f, 1, 0x41, ...sleb(0), 0x0b],
|
|
335
|
+
[0x7f, 1, 0x41, ...sleb(initialLflag), 0x0b],
|
|
336
|
+
]));
|
|
337
|
+
const exports = sec(7, vec([
|
|
338
|
+
[...str('memory'), 0x02, 0],
|
|
339
|
+
[...str('set_terminal_size'), 0x00, 3],
|
|
340
|
+
[...str('get_termios_lflag'), 0x00, 4],
|
|
341
|
+
[...str('asyncify_start_unwind'), 0x00, 5],
|
|
342
|
+
[...str('asyncify_stop_unwind'), 0x00, 6],
|
|
343
|
+
[...str('asyncify_start_rewind'), 0x00, 7],
|
|
344
|
+
[...str('asyncify_stop_rewind'), 0x00, 8],
|
|
345
|
+
[...str('asyncify_get_state'), 0x00, 9],
|
|
346
|
+
[...str('_start'), 0x00, 10],
|
|
347
|
+
]));
|
|
348
|
+
|
|
349
|
+
const startInstrs = initialLflag === 1
|
|
350
|
+
? [
|
|
351
|
+
0x41, ...sleb(256), 0x42, ...sleb(5000000000), 0x37, 3, 0,
|
|
352
|
+
0x41, 0, 0x41, 0, 0x41, ...sleb(256), 0x41, ...sleb(264), 0x10, 0, 0x1a
|
|
353
|
+
]
|
|
354
|
+
: [
|
|
355
|
+
0x03, 0x40,
|
|
356
|
+
0x41, ...sleb(128), 0x41, ...sleb(160), 0x36, 2, 0,
|
|
357
|
+
0x41, ...sleb(132), 0x41, 1, 0x36, 2, 0,
|
|
358
|
+
0x41, 0, 0x41, ...sleb(128), 0x41, 1, 0x41, ...sleb(136), 0x10, 1, 0x1a,
|
|
359
|
+
0x23, 0, 0x41, 1, 0x46, 0x04, 0x40, 0x0f, 0x0b,
|
|
360
|
+
0x41, ...sleb(160), 0x2d, 0, 0, 0x21, 0,
|
|
361
|
+
0x20, 0, 0x41, 0x18, 0x46, 0x04, 0x40, 0x0f, 0x0b,
|
|
362
|
+
0x20, 0, 0x41, ...sleb(0x73), 0x46, 0x04, 0x40, 0x41, 1, 0x24, 1, 0x0b,
|
|
363
|
+
0x20, 0, 0x41, 3, 0x46, 0x04, 0x40,
|
|
364
|
+
0x41, ...sleb(300), 0x41, ...sleb(0x585445), 0x36, 2, 0,
|
|
365
|
+
0x41, ...sleb(140), 0x41, ...sleb(300), 0x36, 2, 0,
|
|
366
|
+
0x41, ...sleb(144), 0x41, 3, 0x36, 2, 0,
|
|
367
|
+
0x41, 1, 0x41, ...sleb(140), 0x41, 1, 0x41, ...sleb(148), 0x10, 2, 0x1a,
|
|
368
|
+
0x0b,
|
|
369
|
+
0x0c, 0,
|
|
370
|
+
0x0b
|
|
371
|
+
];
|
|
372
|
+
|
|
373
|
+
const code = sec(10, vec([
|
|
374
|
+
fnBody([], []),
|
|
375
|
+
fnBody([], [0x23, 1]),
|
|
376
|
+
fnBody([], [0x41, 1, 0x24, 0]),
|
|
377
|
+
fnBody([], [0x41, 0, 0x24, 0]),
|
|
378
|
+
fnBody([], [0x41, 2, 0x24, 0]),
|
|
379
|
+
fnBody([], [0x41, 0, 0x24, 0]),
|
|
380
|
+
fnBody([], [0x23, 0]),
|
|
381
|
+
fnBody([[1, 0x7f]], startInstrs),
|
|
382
|
+
]));
|
|
383
|
+
|
|
384
|
+
return new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, ...types, ...imports, ...funcs, ...mem, ...globals, ...exports, ...code]);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
it('terminates cbreak WASM command (ISIG enabled) on Ctrl+C immediately, restores screen, and aborts parent launcher script', async () => {
|
|
388
|
+
const cbreakWasm = buildTermiosTestWasm(1);
|
|
389
|
+
const shell = await createShell({
|
|
390
|
+
filesystem: {
|
|
391
|
+
bin: {
|
|
392
|
+
'cbreak-game': cbreakWasm,
|
|
393
|
+
'launch-game': '#!/bin/sh\ncbreak-game\necho "AFTER_GAME" > /after.txt\n'
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
permissions: {
|
|
397
|
+
'/bin/cbreak-game': 0o755,
|
|
398
|
+
'/bin/launch-game': 0o755
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// 1. Direct WASM execution: Ctrl+C via stream write (\x03) cancels 5s clock_nanosleep immediately
|
|
403
|
+
const out1 = [];
|
|
404
|
+
const onOut1 = c => out1.push(String(c));
|
|
405
|
+
shell.stdout.on('data', onOut1);
|
|
406
|
+
|
|
407
|
+
const t0 = Date.now();
|
|
408
|
+
const p1 = shell.onCommand('cbreak-game');
|
|
409
|
+
await new Promise(r => setTimeout(r, 30));
|
|
410
|
+
|
|
411
|
+
shell.write('\x03');
|
|
412
|
+
await p1;
|
|
413
|
+
const elapsed = Date.now() - t0;
|
|
414
|
+
shell.stdout.off('data', onOut1);
|
|
415
|
+
|
|
416
|
+
expect(shell.lastCode).toBe(130);
|
|
417
|
+
expect(elapsed).toBeLessThan(1000);
|
|
418
|
+
expect(out1.join('')).toContain('\x1b[?1049h');
|
|
419
|
+
expect(out1.join('')).toContain('\x1b[?1049l');
|
|
420
|
+
expect(out1.join('')).not.toContain('^C\r\n');
|
|
421
|
+
|
|
422
|
+
// 2. Via shell script wrapper (like freedoom): Ctrl+C kills child + script without running subsequent lines
|
|
423
|
+
const p2 = shell.onCommand('launch-game');
|
|
424
|
+
await new Promise(r => setTimeout(r, 40));
|
|
425
|
+
|
|
426
|
+
shell.write('\x03');
|
|
427
|
+
await p2;
|
|
428
|
+
|
|
429
|
+
expect(shell.lastCode).toBe(130);
|
|
430
|
+
expect(shell.context.fs.exists('/after.txt')).toBe(false);
|
|
431
|
+
|
|
432
|
+
// 3. Ctrl+C via shell.onInput('^C') also delivers SIGINT cleanly
|
|
433
|
+
const p3 = shell.onCommand('cbreak-game');
|
|
434
|
+
await new Promise(r => setTimeout(r, 30));
|
|
435
|
+
shell.onInput('^C');
|
|
436
|
+
await p3;
|
|
437
|
+
expect(shell.lastCode).toBe(130);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('passes Ctrl+C (\\x03) as raw input when WASM clears ISIG (~ISIG) and honors dynamic ISIG re-enablement', async () => {
|
|
441
|
+
const rawWasm = buildTermiosTestWasm(0);
|
|
442
|
+
const shell = await createShell({
|
|
443
|
+
filesystem: {
|
|
444
|
+
bin: {
|
|
445
|
+
'raw-editor': rawWasm
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
permissions: {
|
|
449
|
+
'/bin/raw-editor': 0o755
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
const chunks = [];
|
|
454
|
+
const onData = c => chunks.push(String(c));
|
|
455
|
+
shell.stdout.on('data', onData);
|
|
456
|
+
|
|
457
|
+
const p = shell.onCommand('raw-editor');
|
|
458
|
+
await new Promise(r => setTimeout(r, 30));
|
|
459
|
+
|
|
460
|
+
// While lflag == 0 (~ISIG), Ctrl+C is delivered as byte 0x03 ("ETX" written to stdout)
|
|
461
|
+
shell.write('\x03');
|
|
462
|
+
await new Promise(r => setTimeout(r, 30));
|
|
463
|
+
expect(chunks.join('')).toContain('ETX');
|
|
464
|
+
expect(shell.runningCommand).toBeDefined();
|
|
465
|
+
|
|
466
|
+
// Sending 's' toggles lflag to 1 (re-enabling ISIG dynamically at runtime)
|
|
467
|
+
shell.write('s');
|
|
468
|
+
await new Promise(r => setTimeout(r, 20));
|
|
469
|
+
|
|
470
|
+
// Subsequent Ctrl+C now terminates with SIGINT (130)
|
|
471
|
+
shell.write('\x03');
|
|
472
|
+
await p;
|
|
473
|
+
shell.stdout.off('data', onData);
|
|
474
|
+
|
|
475
|
+
expect(shell.lastCode).toBe(130);
|
|
476
|
+
});
|
|
284
477
|
});
|
|
285
478
|
|
|
479
|
+
|
package/test/doom.test.js
CHANGED
|
@@ -4,18 +4,24 @@ import path from 'path';
|
|
|
4
4
|
import { createShell } from './helpers.js';
|
|
5
5
|
|
|
6
6
|
const DOOM_WASM_CANDIDATES = [
|
|
7
|
+
path.resolve(import.meta.dirname, '../../doom-wasm/dist/doom.wasm'),
|
|
7
8
|
'/home/antigravity/eliotstocker/doom-wasm/dist/doom.wasm',
|
|
8
9
|
'/home/antigravity/doom-ascii/dist/doom.wasm',
|
|
9
10
|
'/tmp/doom-asyncify.wasm'
|
|
10
11
|
];
|
|
12
|
+
const DOOM_WAD_CANDIDATES = [
|
|
13
|
+
'/tmp/doom1.wad',
|
|
14
|
+
'/tmp/freedoom1.wad'
|
|
15
|
+
];
|
|
11
16
|
const DOOM_WASM_PATH = DOOM_WASM_CANDIDATES.find(p => fs.existsSync(p)) || DOOM_WASM_CANDIDATES[0];
|
|
12
|
-
const DOOM_WAD_PATH =
|
|
17
|
+
const DOOM_WAD_PATH = DOOM_WAD_CANDIDATES.find(p => fs.existsSync(p)) || DOOM_WAD_CANDIDATES[0];
|
|
13
18
|
const hasDoom = fs.existsSync(DOOM_WASM_PATH) && fs.existsSync(DOOM_WAD_PATH);
|
|
19
|
+
const hasDoom1Demo = fs.existsSync(DOOM_WASM_PATH) && fs.existsSync('/tmp/doom1.wad');
|
|
14
20
|
|
|
15
21
|
describe('Doom in brsh', () => {
|
|
16
|
-
it.skipIf(!
|
|
22
|
+
it.skipIf(!hasDoom1Demo)('executes doom timedemo benchmark cleanly to completion', async () => {
|
|
17
23
|
const doomWasm = fs.readFileSync(DOOM_WASM_PATH);
|
|
18
|
-
const doomWad = fs.readFileSync(
|
|
24
|
+
const doomWad = fs.readFileSync('/tmp/doom1.wad');
|
|
19
25
|
const shell = await createShell({
|
|
20
26
|
filesystem: {
|
|
21
27
|
bin: { 'doom': doomWasm },
|
|
@@ -36,4 +42,57 @@ describe('Doom in brsh', () => {
|
|
|
36
42
|
expect(allOut).toContain('DOOM ASCII');
|
|
37
43
|
expect(allOut).toMatch(/timed \d+ gametics/);
|
|
38
44
|
}, 30000);
|
|
45
|
+
|
|
46
|
+
it.skipIf(!hasDoom)('exits interactive doom and freedoom cleanly on Ctrl+C (SIGINT, exit code 130)', async () => {
|
|
47
|
+
const doomWasm = new Uint8Array(fs.readFileSync(DOOM_WASM_PATH));
|
|
48
|
+
const doomWad = new Uint8Array(fs.readFileSync(DOOM_WAD_PATH));
|
|
49
|
+
const mod = new WebAssembly.Module(doomWasm);
|
|
50
|
+
expect(WebAssembly.Module.exports(mod).map(e => e.name)).toContain('get_termios_lflag');
|
|
51
|
+
|
|
52
|
+
const shell = await createShell({
|
|
53
|
+
filesystem: {
|
|
54
|
+
usr: {
|
|
55
|
+
lib: {
|
|
56
|
+
doom: {
|
|
57
|
+
'doom.wasm': doomWasm,
|
|
58
|
+
'freedoom': '#!/bin/sh\ndoom -iwad /usr/share/games/doom/game.wad -nosound\n',
|
|
59
|
+
'package.json': JSON.stringify({ name: 'doom', bin: 'doom', interactive: true })
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
share: {
|
|
63
|
+
games: {
|
|
64
|
+
doom: {
|
|
65
|
+
'game.wad': doomWad
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
shell.context.fs.createSymlink('/usr/lib/doom/doom.wasm', '/bin/doom');
|
|
73
|
+
shell.context.fs.setMode('/usr/lib/doom/doom.wasm', 0o755);
|
|
74
|
+
shell.context.fs.createSymlink('/usr/lib/doom/freedoom', '/bin/freedoom');
|
|
75
|
+
shell.context.fs.setMode('/usr/lib/doom/freedoom', 0o755);
|
|
76
|
+
|
|
77
|
+
const chunks = [];
|
|
78
|
+
const onData = chunk => chunks.push(String(chunk));
|
|
79
|
+
shell.stdout.on('data', onData);
|
|
80
|
+
|
|
81
|
+
const runPromise = shell.onCommand('freedoom');
|
|
82
|
+
await new Promise(r => setTimeout(r, 350));
|
|
83
|
+
|
|
84
|
+
expect(shell.runningCommand).toBeDefined();
|
|
85
|
+
expect(shell.runningCommand.isRaw).toBe(false);
|
|
86
|
+
expect(shell.runningCommand._inAltScreen).toBe(true);
|
|
87
|
+
|
|
88
|
+
shell.write('\x03');
|
|
89
|
+
await runPromise;
|
|
90
|
+
shell.stdout.off('data', onData);
|
|
91
|
+
|
|
92
|
+
const out = chunks.join('');
|
|
93
|
+
expect(shell.lastCode).toBe(130);
|
|
94
|
+
expect(out).toContain('\x1b[?1049h');
|
|
95
|
+
expect(out).toContain('\x1b[?1049l\x1b[?25h');
|
|
96
|
+
expect(out).not.toContain('^C\r\n');
|
|
97
|
+
}, 30000);
|
|
39
98
|
});
|
package/test/fixtures/nano.wasm
CHANGED
|
Binary file
|
package/test/scripts.test.js
CHANGED
|
@@ -561,4 +561,52 @@ describe('multiline quotes and line continuations in scripts', () => {
|
|
|
561
561
|
expect(res.exitCode).toBe(0);
|
|
562
562
|
expect(res.output).toEqual(['matched-2', 'matched-help', 'other:custom']);
|
|
563
563
|
});
|
|
564
|
+
|
|
565
|
+
it('splits accumulated $EXTRA_ARGS and preserves distinct "$@" arguments in wrapper scripts', async () => {
|
|
566
|
+
const received = [];
|
|
567
|
+
class TargetApp extends Command {
|
|
568
|
+
static get name() { return 'target-app'; }
|
|
569
|
+
run() {
|
|
570
|
+
received.push([...this.arguments]);
|
|
571
|
+
return Promise.resolve();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const shell = await createShell({
|
|
576
|
+
filesystem: {
|
|
577
|
+
bin: {
|
|
578
|
+
'launcher.sh': [
|
|
579
|
+
'#!/bin/sh',
|
|
580
|
+
'EXTRA_ARGS=""',
|
|
581
|
+
'for ARG in $@',
|
|
582
|
+
'do',
|
|
583
|
+
' case "$ARG" in',
|
|
584
|
+
' --blocks|--block|-b)',
|
|
585
|
+
' EXTRA_ARGS="$EXTRA_ARGS -blocks"',
|
|
586
|
+
' ;;',
|
|
587
|
+
' *)',
|
|
588
|
+
' EXTRA_ARGS="$EXTRA_ARGS $ARG"',
|
|
589
|
+
' ;;',
|
|
590
|
+
' esac',
|
|
591
|
+
'done',
|
|
592
|
+
'target-app -iwad "/game/freedoom1.wad" -nosound $EXTRA_ARGS'
|
|
593
|
+
].join('\n'),
|
|
594
|
+
'passthrough.sh': '#!/bin/sh\ntarget-app "$@"\n'
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
permissions: execPerms('/bin/launcher.sh', '/bin/passthrough.sh')
|
|
598
|
+
});
|
|
599
|
+
shell.context.setCommand(TargetApp);
|
|
600
|
+
|
|
601
|
+
await run(shell, 'launcher.sh --blocks -scaling 2');
|
|
602
|
+
await run(shell, 'passthrough.sh "first with spaces" --blocks');
|
|
603
|
+
await run(shell, 'passthrough.sh');
|
|
604
|
+
|
|
605
|
+
expect(received).toEqual([
|
|
606
|
+
['-iwad', '/game/freedoom1.wad', '-nosound', '-blocks', '-scaling', '2'],
|
|
607
|
+
['first with spaces', '--blocks'],
|
|
608
|
+
[]
|
|
609
|
+
]);
|
|
610
|
+
});
|
|
564
611
|
});
|
|
612
|
+
|
package/test/shell.test.js
CHANGED
|
@@ -719,3 +719,63 @@ describe('stream redirection syntax', () => {
|
|
|
719
719
|
});
|
|
720
720
|
});
|
|
721
721
|
|
|
722
|
+
describe('unquoted expansion word splitting', () => {
|
|
723
|
+
let shell;
|
|
724
|
+
let capturedArgs;
|
|
725
|
+
|
|
726
|
+
beforeEach(async () => {
|
|
727
|
+
capturedArgs = [];
|
|
728
|
+
class ArgCaptureCmd extends Shell.Command {
|
|
729
|
+
static get name() { return 'capture'; }
|
|
730
|
+
run() {
|
|
731
|
+
capturedArgs.push([...this.arguments]);
|
|
732
|
+
return Promise.resolve();
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
shell = await createShell();
|
|
736
|
+
shell.context.setCommand(ArgCaptureCmd);
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
it('splits unquoted variable expansions on whitespace and strips leading/trailing spaces', async () => {
|
|
740
|
+
await run(shell, 'EXTRA_ARGS=""');
|
|
741
|
+
await run(shell, 'EXTRA_ARGS="$EXTRA_ARGS -blocks"');
|
|
742
|
+
await run(shell, 'capture -iwad "/path with spaces/freedoom1.wad" -nosound $EXTRA_ARGS');
|
|
743
|
+
expect(capturedArgs).toEqual([
|
|
744
|
+
['-iwad', '/path with spaces/freedoom1.wad', '-nosound', '-blocks']
|
|
745
|
+
]);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
it('splits multiple flags accumulated in an unquoted variable into separate argv tokens', async () => {
|
|
749
|
+
await run(shell, 'EXTRA_ARGS=" -blocks -scaling 2 "');
|
|
750
|
+
await run(shell, 'capture $EXTRA_ARGS');
|
|
751
|
+
expect(capturedArgs).toEqual([['-blocks', '-scaling', '2']]);
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
it('omits empty unquoted variable expansions while preserving explicit empty quotes ""', async () => {
|
|
755
|
+
await run(shell, 'EMPTY=""');
|
|
756
|
+
await run(shell, 'capture a $EMPTY "" b');
|
|
757
|
+
expect(capturedArgs).toEqual([['a', '', 'b']]);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it('preserves whitespace when variable expansion is double-quoted', async () => {
|
|
761
|
+
await run(shell, 'EXTRA_ARGS=" -blocks -scaling 2"');
|
|
762
|
+
await run(shell, 'capture "$EXTRA_ARGS"');
|
|
763
|
+
expect(capturedArgs).toEqual([[' -blocks -scaling 2']]);
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
it('does not word-split bare variable assignments or export assignments', async () => {
|
|
767
|
+
await run(shell, 'SRC=" hello world "');
|
|
768
|
+
await run(shell, 'DEST=$SRC');
|
|
769
|
+
expect(shell.context.getVar('DEST')).toBe(' hello world ');
|
|
770
|
+
|
|
771
|
+
await run(shell, 'export EXPORTED=$(echo alpha beta)');
|
|
772
|
+
expect(shell.context.getVar('EXPORTED')).toBe('alpha beta');
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
it('preserves backslash-escaped spaces on literal tokens without $ expansion', async () => {
|
|
776
|
+
await run(shell, 'capture hello\\ world');
|
|
777
|
+
expect(capturedArgs).toEqual([['hello world']]);
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
|
package/test/wbt.test.js
CHANGED
|
@@ -1541,6 +1541,47 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1541
1541
|
expect(saved).toContain('Hello from stream!');
|
|
1542
1542
|
expect(saved).not.toContain('HHeelllloo');
|
|
1543
1543
|
});
|
|
1544
|
+
|
|
1545
|
+
it('delivers Ctrl+C (\\x03) as raw input to nano (~ISIG) without killing nano', async () => {
|
|
1546
|
+
if (!NANO_WASM_BYTES) return;
|
|
1547
|
+
const mod = new WebAssembly.Module(NANO_WASM_BYTES);
|
|
1548
|
+
const exportNames = WebAssembly.Module.exports(mod).map(e => e.name);
|
|
1549
|
+
expect(exportNames).toContain('get_termios_lflag');
|
|
1550
|
+
|
|
1551
|
+
await run(shell, 'wbt install nano');
|
|
1552
|
+
|
|
1553
|
+
const stdoutChunks = [];
|
|
1554
|
+
const onData = (chunk) => stdoutChunks.push(String(chunk));
|
|
1555
|
+
shell.stdout.on('data', onData);
|
|
1556
|
+
|
|
1557
|
+
const cmdPromise = shell.onCommand('nano /ctrlc-test.txt');
|
|
1558
|
+
await new Promise(r => setTimeout(r, 80));
|
|
1559
|
+
|
|
1560
|
+
for (const ch of 'Nano raw mode') {
|
|
1561
|
+
shell.write(ch);
|
|
1562
|
+
await new Promise(r => setTimeout(r, 5));
|
|
1563
|
+
}
|
|
1564
|
+
await new Promise(r => setTimeout(r, 30));
|
|
1565
|
+
|
|
1566
|
+
// In GNU nano, Ctrl+C (\x03) shows cursor position in the status bar instead of exiting
|
|
1567
|
+
shell.write('\x03');
|
|
1568
|
+
await new Promise(r => setTimeout(r, 40));
|
|
1569
|
+
expect(shell.runningCommand).toBeDefined();
|
|
1570
|
+
expect(stdoutChunks.join('')).toMatch(/line\s+1|col\s+14/i);
|
|
1571
|
+
|
|
1572
|
+
// Save (Ctrl+O, Enter) and exit (Ctrl+X) cleanly
|
|
1573
|
+
shell.write('\x0f');
|
|
1574
|
+
await new Promise(r => setTimeout(r, 30));
|
|
1575
|
+
shell.write('\r');
|
|
1576
|
+
await new Promise(r => setTimeout(r, 30));
|
|
1577
|
+
shell.write('\x18');
|
|
1578
|
+
|
|
1579
|
+
await cmdPromise;
|
|
1580
|
+
shell.stdout.off('data', onData);
|
|
1581
|
+
|
|
1582
|
+
expect(shell.lastCode).toBe(0);
|
|
1583
|
+
expect(shell.context.fs.getFileByPath('/ctrlc-test.txt')).toContain('Nano raw mode');
|
|
1584
|
+
});
|
|
1544
1585
|
});
|
|
1545
1586
|
|
|
1546
1587
|
describe('WBT filesystem installer architecture (installer, not runtime)', () => {
|