brsh 3.9.0 → 3.10.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/CHANGELOG.md +7 -0
- package/Readme.md +22 -4
- package/bin/Readme.md +33 -3
- package/bin/exportFileSystem.js +127 -110
- package/bin/wbt.js +118 -0
- package/dist/shell.es.js +6852 -6616
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +23 -22
- package/dist/shell.min.js.map +1 -1
- package/dist/wbt.es.js +2534 -2342
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +15 -11
- package/dist/wbt.min.js.map +1 -1
- package/index.js +66 -71
- package/lib/BaseFileSystem.js +55 -2
- package/lib/Context.js +1 -1
- package/lib/FileSystem.js +4 -2
- package/lib/JsCommand.js +113 -0
- package/lib/NodeFileSystem.js +164 -30
- package/lib/Readme.md +1 -0
- package/lib/ScriptCommand.js +110 -7
- package/lib/WasmCommand.js +85 -25
- package/lib/buildFilesystemStructure.js +38 -24
- package/lib/isUtf8Text.js +47 -0
- package/lib/local/which.js +8 -3
- package/lib/wbt/index.js +344 -160
- package/lib/wbt/registry.js +21 -1
- package/package.json +3 -2
- package/test/exportFileSystem.test.js +37 -15
- package/test/js-command.test.js +125 -0
- package/test/node-filesystem.test.js +7 -0
- package/test/scripts.test.js +30 -0
- package/test/wbt.test.js +308 -10
- package/test/wbtCli.test.js +160 -0
package/test/wbt.test.js
CHANGED
|
@@ -559,6 +559,45 @@ function createTestWbt() {
|
|
|
559
559
|
arrayBuffer: async () => NANO_WASM_BYTES.buffer
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
|
+
if (url.includes('/bin/freedoom')) {
|
|
563
|
+
const scriptPath = path.resolve(import.meta.dirname, '../../eliotstocker/doom-wasm/bin/freedoom');
|
|
564
|
+
const scriptText = fs.existsSync(scriptPath)
|
|
565
|
+
? fs.readFileSync(scriptPath, 'utf8')
|
|
566
|
+
: [
|
|
567
|
+
'#!/bin/sh',
|
|
568
|
+
'WAD_DIR="/usr/share/games/doom"',
|
|
569
|
+
'WAD_NAME="freedoom1.wad"',
|
|
570
|
+
'WAD_URL="https://raw.githubusercontent.com/redox-os/freedoom/master/freedoom1.wad"',
|
|
571
|
+
'EXTRA_ARGS=""',
|
|
572
|
+
'for ARG in $@',
|
|
573
|
+
'do',
|
|
574
|
+
' case "$ARG" in',
|
|
575
|
+
' --phase2|--freedoom2|-2)',
|
|
576
|
+
' WAD_NAME="freedoom2.wad"',
|
|
577
|
+
' WAD_URL="https://raw.githubusercontent.com/redox-os/freedoom/master/freedoom2.wad"',
|
|
578
|
+
' ;;',
|
|
579
|
+
' --help|-h)',
|
|
580
|
+
' echo "Usage: freedoom [--phase1 | --phase2] [doom options...]"',
|
|
581
|
+
' return 0',
|
|
582
|
+
' ;;',
|
|
583
|
+
' *)',
|
|
584
|
+
' EXTRA_ARGS="$EXTRA_ARGS $ARG"',
|
|
585
|
+
' ;;',
|
|
586
|
+
' esac',
|
|
587
|
+
'done',
|
|
588
|
+
'WAD_FILE="$WAD_DIR/$WAD_NAME"',
|
|
589
|
+
'if [ ! -f "$WAD_FILE" ]; then',
|
|
590
|
+
' mkdir -p "$WAD_DIR"',
|
|
591
|
+
' curl -# -L -o "$WAD_FILE" "$WAD_URL"',
|
|
592
|
+
'fi',
|
|
593
|
+
'doom -iwad "$WAD_FILE" -nosound $EXTRA_ARGS'
|
|
594
|
+
].join('\n');
|
|
595
|
+
return {
|
|
596
|
+
ok: true,
|
|
597
|
+
status: 200,
|
|
598
|
+
text: async () => scriptText
|
|
599
|
+
};
|
|
600
|
+
}
|
|
562
601
|
if (url === 'https://example.com/hello.wasm' || /\.wasm(\?.*)?$/i.test(url)) {
|
|
563
602
|
return {
|
|
564
603
|
ok: true,
|
|
@@ -689,13 +728,13 @@ describe('WBT CLI subcommands (list, search, show, install, remove, update)', ()
|
|
|
689
728
|
const installRes = await run(shell, 'wbt install sqlite3');
|
|
690
729
|
expect(installRes.exitCode).toBe(0);
|
|
691
730
|
expect(fetchedUrls.some(u => u.includes('sql-wasm.wasm'))).toBe(true);
|
|
692
|
-
expect(shell.context.fs.exists('/
|
|
731
|
+
expect(shell.context.fs.exists('/usr/lib/sqlite3/sqlite3.wasm')).toBe(true);
|
|
693
732
|
|
|
694
733
|
const showRes = await run(shell, 'wbt show sqlite3');
|
|
695
|
-
expect(showRes.output.join('\n')).toContain('WASM-File: /
|
|
734
|
+
expect(showRes.output.join('\n')).toContain('WASM-File: /usr/lib/sqlite3/sqlite3.wasm');
|
|
696
735
|
|
|
697
736
|
await run(shell, 'wbt remove sqlite3');
|
|
698
|
-
expect(shell.context.fs.exists('/
|
|
737
|
+
expect(shell.context.fs.exists('/usr/lib/sqlite3/sqlite3.wasm')).toBe(false);
|
|
699
738
|
});
|
|
700
739
|
|
|
701
740
|
it('removes an installed package and unregisters its binary from /bin', async () => {
|
|
@@ -722,15 +761,19 @@ describe('WBT CLI subcommands (list, search, show, install, remove, update)', ()
|
|
|
722
761
|
expect(showCustom.output.join('\n')).toContain('Remote registry test package');
|
|
723
762
|
});
|
|
724
763
|
|
|
725
|
-
it('
|
|
764
|
+
it('treats /usr/lib/<pkg>/ as the single source of truth without creating /var/lib/wbt/installed.json', async () => {
|
|
726
765
|
await run(shell, 'wbt install sqlite3');
|
|
766
|
+
expect(shell.context.fs.exists('/var/lib/wbt/installed.json')).toBe(false);
|
|
767
|
+
expect(shell.context.fs.exists('/usr/lib/sqlite3/package.json')).toBe(true);
|
|
768
|
+
|
|
727
769
|
const rawFs = shell.context.fs.getRaw();
|
|
728
770
|
const rawPerms = shell.context.fs.getRawPermissions();
|
|
729
771
|
|
|
730
|
-
|
|
772
|
+
// Restore filesystem into a new shell from the directory structure alone
|
|
731
773
|
const shell2 = await createShell({
|
|
732
774
|
filesystem: {
|
|
733
|
-
|
|
775
|
+
usr: rawFs.usr,
|
|
776
|
+
bin: rawFs.bin
|
|
734
777
|
},
|
|
735
778
|
permissions: rawPerms
|
|
736
779
|
});
|
|
@@ -1366,7 +1409,7 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1366
1409
|
it('installs nano and nano-wasm into /bin and runs --version and --help', async () => {
|
|
1367
1410
|
const installRes = await run(shell, 'wbt install nano');
|
|
1368
1411
|
expect(installRes.exitCode).toBe(0);
|
|
1369
|
-
expect(shell.context.fs.exists('/
|
|
1412
|
+
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(true);
|
|
1370
1413
|
expect(shell.context.fs.exists('/bin/nano')).toBe(true);
|
|
1371
1414
|
expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(true);
|
|
1372
1415
|
|
|
@@ -1394,18 +1437,18 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1394
1437
|
await run(shell, 'wbt install nano-wasm');
|
|
1395
1438
|
expect(shell.context.fs.exists('/bin/nano')).toBe(true);
|
|
1396
1439
|
expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(true);
|
|
1397
|
-
expect(shell.context.fs.exists('/
|
|
1440
|
+
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(true);
|
|
1398
1441
|
|
|
1399
1442
|
const rmRes = await run(shell, 'wbt remove nano');
|
|
1400
1443
|
expect(rmRes.exitCode).toBe(0);
|
|
1401
1444
|
expect(shell.context.fs.exists('/bin/nano')).toBe(false);
|
|
1402
1445
|
expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(false);
|
|
1403
|
-
expect(shell.context.fs.exists('/
|
|
1446
|
+
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(false);
|
|
1404
1447
|
});
|
|
1405
1448
|
|
|
1406
1449
|
it('runs nano even when invoked with readonlyContext without context.fs', async () => {
|
|
1407
1450
|
await run(shell, 'wbt install nano');
|
|
1408
|
-
const NanoCmd = shell.
|
|
1451
|
+
const NanoCmd = shell._resolveCommandFromPath('/bin/nano');
|
|
1409
1452
|
expect(NanoCmd).toBeDefined();
|
|
1410
1453
|
|
|
1411
1454
|
const readonlyCtx = Object.freeze({
|
|
@@ -1500,6 +1543,261 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1500
1543
|
});
|
|
1501
1544
|
});
|
|
1502
1545
|
|
|
1546
|
+
describe('WBT filesystem installer architecture (installer, not runtime)', () => {
|
|
1547
|
+
let shell;
|
|
1548
|
+
|
|
1549
|
+
beforeEach(async () => {
|
|
1550
|
+
shell = await createShell({ filesystem: { home: {} } });
|
|
1551
|
+
shell.context.setCommand(createTestWbt());
|
|
1552
|
+
});
|
|
1553
|
+
|
|
1554
|
+
it('installs pure WASM to /usr/lib/<pkg>/<bin>.wasm and symlinks into /bin/<cmd>', async () => {
|
|
1555
|
+
const installRes = await run(shell, 'wbt install nano');
|
|
1556
|
+
expect(installRes.exitCode).toBe(0);
|
|
1557
|
+
|
|
1558
|
+
// Binary placed in /usr/lib/nano/nano.wasm
|
|
1559
|
+
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(true);
|
|
1560
|
+
expect(shell.context.fs.isExecutable('/usr/lib/nano/nano.wasm')).toBe(true);
|
|
1561
|
+
|
|
1562
|
+
// Symlinks in /bin
|
|
1563
|
+
expect(shell.context.fs.isSymlink('/bin/nano')).toBe(true);
|
|
1564
|
+
expect(shell.context.fs.readSymlink('/bin/nano')).toBe('/usr/lib/nano/nano.wasm');
|
|
1565
|
+
expect(shell.context.fs.isSymlink('/bin/nano-wasm')).toBe(true);
|
|
1566
|
+
expect(shell.context.fs.readSymlink('/bin/nano-wasm')).toBe('/usr/lib/nano/nano.wasm');
|
|
1567
|
+
|
|
1568
|
+
// Verify /var/lib/wbt is not created
|
|
1569
|
+
expect(shell.context.fs.exists('/var/lib/wbt')).toBe(false);
|
|
1570
|
+
});
|
|
1571
|
+
|
|
1572
|
+
it('runs WASM command directly from /bin without wbt registered in context', async () => {
|
|
1573
|
+
await run(shell, 'wbt install nano');
|
|
1574
|
+
|
|
1575
|
+
// Persist filesystem as BRFS binary container (the official format for brsh persistence)
|
|
1576
|
+
const containerBytes = shell.context.fs.toBinaryContainer();
|
|
1577
|
+
|
|
1578
|
+
// Create a completely fresh shell with the restored filesystem and NO wbt command registered
|
|
1579
|
+
const cleanShell = await createShell({
|
|
1580
|
+
filesystem: containerBytes
|
|
1581
|
+
});
|
|
1582
|
+
if (cleanShell.context.fs.exists('/bin/wbt')) {
|
|
1583
|
+
cleanShell.context.fs.deleteFileByPath('/bin/wbt');
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
// Verify wbt is NOT in cleanShell
|
|
1587
|
+
expect(cleanShell.context.getCommand('wbt')).toBeNull();
|
|
1588
|
+
|
|
1589
|
+
// Invoking bare command 'nano --version' runs WASM directly through Shell & WasmCommand
|
|
1590
|
+
const res = await run(cleanShell, 'nano --version');
|
|
1591
|
+
expect(res.exitCode).toBe(0);
|
|
1592
|
+
expect(res.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
1593
|
+
|
|
1594
|
+
// Invoking via full path '/bin/nano --version' also runs WASM directly
|
|
1595
|
+
const binRes = await run(cleanShell, '/bin/nano --version');
|
|
1596
|
+
expect(binRes.exitCode).toBe(0);
|
|
1597
|
+
expect(binRes.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
1598
|
+
|
|
1599
|
+
// Invoking via alias 'nano-wasm --version' also runs WASM directly
|
|
1600
|
+
const aliasRes = await run(cleanShell, 'nano-wasm --version');
|
|
1601
|
+
expect(aliasRes.exitCode).toBe(0);
|
|
1602
|
+
expect(aliasRes.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
1603
|
+
});
|
|
1604
|
+
|
|
1605
|
+
it('auto-wires sibling JS and WASM in /usr/lib/<pkg>/ without wbt runtime', async () => {
|
|
1606
|
+
const dummyWasmBytes = new Uint8Array([
|
|
1607
|
+
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
|
|
1608
|
+
0x01, 0x04, 0x01, 0x60, 0x00, 0x00,
|
|
1609
|
+
0x03, 0x02, 0x01, 0x00,
|
|
1610
|
+
0x07, 0x0a, 0x01, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00,
|
|
1611
|
+
0x0a, 0x04, 0x01, 0x02, 0x00, 0x0b
|
|
1612
|
+
]);
|
|
1613
|
+
|
|
1614
|
+
const jsCode = `
|
|
1615
|
+
module.exports = async function(Module) {
|
|
1616
|
+
return {
|
|
1617
|
+
exec: async function(args) {
|
|
1618
|
+
return 0;
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
};
|
|
1622
|
+
`;
|
|
1623
|
+
|
|
1624
|
+
// Co-locate .wasm and .js in /usr/lib/mytool/
|
|
1625
|
+
const WasmCmd = shell.constructor.WasmCommand;
|
|
1626
|
+
WasmCmd.writeBytesToFs(shell.context.fs, '/usr/lib/mytool/mytool.wasm', dummyWasmBytes);
|
|
1627
|
+
shell.context.fs.setFileByPath('/usr/lib/mytool/mytool.js', jsCode, true);
|
|
1628
|
+
shell.context.fs.setMode('/usr/lib/mytool/mytool.wasm', 0o755);
|
|
1629
|
+
shell.context.fs.setMode('/usr/lib/mytool/mytool.js', 0o755);
|
|
1630
|
+
|
|
1631
|
+
// Create symlink /bin/mytool -> /usr/lib/mytool/mytool.js
|
|
1632
|
+
shell.context.fs.createSymlink('/usr/lib/mytool/mytool.js', '/bin/mytool');
|
|
1633
|
+
shell.context.fs.setMode('/bin/mytool', 0o755);
|
|
1634
|
+
|
|
1635
|
+
const execRes = await run(shell, 'mytool hello world');
|
|
1636
|
+
expect(execRes.exitCode).toBe(0);
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
it('registers doom package with aliases doom-wasm, doom-ascii, and freedoom launcher script', async () => {
|
|
1640
|
+
const BaseWbt = createTestWbt();
|
|
1641
|
+
const registry = BaseWbt.DEFAULT_REGISTRY;
|
|
1642
|
+
expect(registry.doom).toBeDefined();
|
|
1643
|
+
expect(registry.doom.bin).toBe('doom');
|
|
1644
|
+
expect(registry.doom.aliases).toContain('doom-wasm');
|
|
1645
|
+
expect(registry.doom.aliases).toContain('doom-ascii');
|
|
1646
|
+
expect(registry.doom.scripts).toBeDefined();
|
|
1647
|
+
expect(registry.doom.scripts.freedoom).toContain('/bin/freedoom');
|
|
1648
|
+
expect(registry.doom.type).toBe('custom-wasm');
|
|
1649
|
+
|
|
1650
|
+
// Test search by script name 'freedoom'
|
|
1651
|
+
const searchRes = await run(shell, 'wbt search freedoom');
|
|
1652
|
+
expect(searchRes.exitCode).toBe(0);
|
|
1653
|
+
expect(searchRes.output.join('\n')).toContain('doom/wasm');
|
|
1654
|
+
|
|
1655
|
+
// Test show
|
|
1656
|
+
const showRes = await run(shell, 'wbt show freedoom');
|
|
1657
|
+
expect(showRes.exitCode).toBe(0);
|
|
1658
|
+
expect(showRes.output.join('\n')).toContain('Package: doom');
|
|
1659
|
+
expect(showRes.output.join('\n')).toContain('Aliases: doom-wasm, doom-ascii');
|
|
1660
|
+
expect(showRes.output.join('\n')).toContain('Scripts: freedoom');
|
|
1661
|
+
expect(showRes.output.join('\n')).toContain('doom.wasm');
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
it('installs freedoom launcher script alongside doom, auto-downloads freedoom1.wad if missing, and reuses cached WAD on second run', async () => {
|
|
1665
|
+
// Ephemeral wbt run freedoom --help works even before installing doom
|
|
1666
|
+
const ephemeralHelp = await run(shell, 'wbt run freedoom --help');
|
|
1667
|
+
expect(ephemeralHelp.exitCode).toBe(0);
|
|
1668
|
+
expect(ephemeralHelp.output.join('\n')).toContain('Usage: freedoom');
|
|
1669
|
+
expect(shell.context.fs.exists('/bin/freedoom')).toBe(false);
|
|
1670
|
+
|
|
1671
|
+
const installRes = await run(shell, 'wbt install doom');
|
|
1672
|
+
expect(installRes.exitCode).toBe(0);
|
|
1673
|
+
|
|
1674
|
+
expect(shell.context.fs.exists('/usr/lib/doom/doom.wasm')).toBe(true);
|
|
1675
|
+
expect(shell.context.fs.exists('/usr/lib/doom/freedoom')).toBe(true);
|
|
1676
|
+
expect(shell.context.fs.isSymlink('/bin/doom')).toBe(true);
|
|
1677
|
+
expect(shell.context.fs.isSymlink('/bin/freedoom')).toBe(true);
|
|
1678
|
+
expect(shell.context.fs.readSymlink('/bin/freedoom')).toBe('/usr/lib/doom/freedoom');
|
|
1679
|
+
|
|
1680
|
+
// Help works without fetching WAD
|
|
1681
|
+
const helpRes = await run(shell, 'freedoom --help');
|
|
1682
|
+
expect(helpRes.exitCode).toBe(0);
|
|
1683
|
+
expect(helpRes.output.join('\n')).toContain('Usage: freedoom');
|
|
1684
|
+
expect(shell.context.fs.exists('/usr/share/games/doom/freedoom1.wad')).toBe(false);
|
|
1685
|
+
|
|
1686
|
+
// Mock global fetch for curl WAD download
|
|
1687
|
+
const origFetch = globalThis.fetch;
|
|
1688
|
+
let wad1FetchCount = 0;
|
|
1689
|
+
let wad2FetchCount = 0;
|
|
1690
|
+
const fakeWadBytes = new Uint8Array([0x49, 0x57, 0x41, 0x44, 0x00, 0x00, 0x00, 0x00]); // "IWAD\0\0\0\0"
|
|
1691
|
+
globalThis.fetch = async (url) => {
|
|
1692
|
+
if (String(url).includes('freedoom1.wad')) {
|
|
1693
|
+
wad1FetchCount++;
|
|
1694
|
+
return new Response(fakeWadBytes, {
|
|
1695
|
+
status: 200,
|
|
1696
|
+
headers: { 'content-type': 'application/octet-stream', 'content-length': String(fakeWadBytes.length) }
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
if (String(url).includes('freedoom2.wad')) {
|
|
1700
|
+
wad2FetchCount++;
|
|
1701
|
+
return new Response(fakeWadBytes, {
|
|
1702
|
+
status: 200,
|
|
1703
|
+
headers: { 'content-type': 'application/octet-stream', 'content-length': String(fakeWadBytes.length) }
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
return origFetch(url);
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
try {
|
|
1710
|
+
// First run: downloads freedoom1.wad to /usr/share/games/doom/freedoom1.wad and runs doom
|
|
1711
|
+
const run1 = await run(shell, 'freedoom');
|
|
1712
|
+
expect(run1.exitCode).toBe(0);
|
|
1713
|
+
expect(wad1FetchCount).toBe(1);
|
|
1714
|
+
expect(shell.context.fs.exists('/usr/share/games/doom/freedoom1.wad')).toBe(true);
|
|
1715
|
+
|
|
1716
|
+
// Second run: WAD already exists at /usr/share/games/doom/freedoom1.wad -> skips download!
|
|
1717
|
+
const run2 = await run(shell, 'freedoom');
|
|
1718
|
+
expect(run2.exitCode).toBe(0);
|
|
1719
|
+
expect(wad1FetchCount).toBe(1);
|
|
1720
|
+
|
|
1721
|
+
// Phase 2: downloads freedoom2.wad to /usr/share/games/doom/freedoom2.wad
|
|
1722
|
+
const runPhase2 = await run(shell, 'freedoom --phase2');
|
|
1723
|
+
expect(runPhase2.exitCode).toBe(0);
|
|
1724
|
+
expect(wad2FetchCount).toBe(1);
|
|
1725
|
+
expect(shell.context.fs.exists('/usr/share/games/doom/freedoom2.wad')).toBe(true);
|
|
1726
|
+
} finally {
|
|
1727
|
+
globalThis.fetch = origFetch;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// Removing doom removes /bin/freedoom and /usr/lib/doom/freedoom cleanly
|
|
1731
|
+
const rmRes = await run(shell, 'wbt remove doom');
|
|
1732
|
+
expect(rmRes.exitCode).toBe(0);
|
|
1733
|
+
expect(shell.context.fs.exists('/bin/freedoom')).toBe(false);
|
|
1734
|
+
expect(shell.context.fs.isSymlink('/bin/freedoom')).toBe(false);
|
|
1735
|
+
expect(shell.context.fs.exists('/usr/lib/doom/freedoom')).toBe(false);
|
|
1736
|
+
});
|
|
1737
|
+
|
|
1738
|
+
it('forwards interactive TTY input and raw ANSI stdout cleanly when an interactive WASM binary is launched inside a shell script', async () => {
|
|
1739
|
+
await run(shell, 'wbt install nano');
|
|
1740
|
+
|
|
1741
|
+
// Create a wrapper shell script similar to freedoom
|
|
1742
|
+
shell.context.fs._setFileRaw('/bin/edit-note', '#!/bin/sh\nnano /home/script-note.txt\n', true);
|
|
1743
|
+
shell.context.fs.setMode('/bin/edit-note', 0o755);
|
|
1744
|
+
|
|
1745
|
+
const rawChunks = [];
|
|
1746
|
+
const onData = (chunk) => rawChunks.push(typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk));
|
|
1747
|
+
shell.stdout.on('data', onData);
|
|
1748
|
+
|
|
1749
|
+
const cmdPromise = shell.onCommand('edit-note');
|
|
1750
|
+
await new Promise(r => setTimeout(r, 120));
|
|
1751
|
+
|
|
1752
|
+
for (const ch of 'Via wrapper!') {
|
|
1753
|
+
shell.write(ch);
|
|
1754
|
+
await new Promise(r => setTimeout(r, 8));
|
|
1755
|
+
}
|
|
1756
|
+
await new Promise(r => setTimeout(r, 30));
|
|
1757
|
+
|
|
1758
|
+
// Save: Ctrl+O, Enter, Exit: Ctrl+X
|
|
1759
|
+
shell.write('\x0f');
|
|
1760
|
+
await new Promise(r => setTimeout(r, 30));
|
|
1761
|
+
shell.write('\r');
|
|
1762
|
+
await new Promise(r => setTimeout(r, 30));
|
|
1763
|
+
shell.write('\x18');
|
|
1764
|
+
|
|
1765
|
+
await cmdPromise;
|
|
1766
|
+
shell.stdout.off('data', onData);
|
|
1767
|
+
|
|
1768
|
+
expect(shell.lastCode).toBe(0);
|
|
1769
|
+
expect(rawChunks.join('')).toContain('\x1b[?1049h');
|
|
1770
|
+
const saved = shell.context.fs.getFileByPath('/home/script-note.txt');
|
|
1771
|
+
expect(saved).toContain('Via wrapper!');
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
it('Wbt.restoreInstalled is a safe no-op on already-restored filesystems', async () => {
|
|
1775
|
+
await run(shell, 'wbt install nano');
|
|
1776
|
+
expect(shell.context.fs.isSymlink('/bin/nano')).toBe(true);
|
|
1777
|
+
|
|
1778
|
+
const BaseWbt = createTestWbt();
|
|
1779
|
+
BaseWbt.restoreInstalled(shell);
|
|
1780
|
+
|
|
1781
|
+
// /bin/nano remains a symlink to /usr/lib/nano/nano.wasm
|
|
1782
|
+
expect(shell.context.fs.isSymlink('/bin/nano')).toBe(true);
|
|
1783
|
+
expect(shell.context.fs.readSymlink('/bin/nano')).toBe('/usr/lib/nano/nano.wasm');
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1786
|
+
it('cleans up temporary files in /tmp after wbt run', async () => {
|
|
1787
|
+
const runRes = await run(shell, 'wbt run nano --version');
|
|
1788
|
+
expect(runRes.exitCode).toBe(0);
|
|
1789
|
+
expect(runRes.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
1790
|
+
|
|
1791
|
+
// Not installed permanently
|
|
1792
|
+
expect(shell.context.fs.exists('/bin/nano')).toBe(false);
|
|
1793
|
+
|
|
1794
|
+
// Check that /tmp does not contain lingering .wbt-run- directories
|
|
1795
|
+
const tmpDir = shell.context.fs.getFileByPath('/tmp') || {};
|
|
1796
|
+
const tmpKeys = Object.keys(tmpDir);
|
|
1797
|
+
expect(tmpKeys.some(k => k.startsWith('.wbt-run-'))).toBe(false);
|
|
1798
|
+
});
|
|
1799
|
+
});
|
|
1800
|
+
|
|
1503
1801
|
|
|
1504
1802
|
|
|
1505
1803
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
4
|
+
import { spawnSync } from 'child_process';
|
|
5
|
+
import { resolve, join } from 'path';
|
|
6
|
+
import { mkdtempSync, rmSync, existsSync, readlinkSync, readFileSync, lstatSync } from 'fs';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import Shell from '../index.js';
|
|
9
|
+
import { createShell, run } from './helpers.js';
|
|
10
|
+
|
|
11
|
+
const WBT_CLI = resolve(import.meta.dirname, '../bin/wbt.js');
|
|
12
|
+
const EXPORT_FS_CLI = resolve(import.meta.dirname, '../bin/exportFileSystem.js');
|
|
13
|
+
|
|
14
|
+
function runWbt(args, cwd) {
|
|
15
|
+
return spawnSync(process.execPath, [WBT_CLI, ...args], {
|
|
16
|
+
cwd,
|
|
17
|
+
encoding: 'utf8'
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function runExportFs(args, cwd) {
|
|
22
|
+
return spawnSync(process.execPath, [EXPORT_FS_CLI, ...args], {
|
|
23
|
+
cwd,
|
|
24
|
+
encoding: 'utf8'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('Standalone wbt CLI (bin/wbt.js)', () => {
|
|
29
|
+
let tmpFsRoot;
|
|
30
|
+
let outDir;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
tmpFsRoot = mkdtempSync(join(tmpdir(), 'brsh-wbt-cli-test-root-'));
|
|
34
|
+
outDir = mkdtempSync(join(tmpdir(), 'brsh-wbt-cli-test-out-'));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
rmSync(tmpFsRoot, { recursive: true, force: true });
|
|
39
|
+
rmSync(outDir, { recursive: true, force: true });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('displays help when invoked with --help without requiring --root', () => {
|
|
43
|
+
const res = runWbt(['--help']);
|
|
44
|
+
expect(res.status).toBe(0);
|
|
45
|
+
expect(res.stdout).toContain('wbt [options] <command> [args...]');
|
|
46
|
+
expect(res.stdout).toContain('--root');
|
|
47
|
+
expect(res.stdout).toContain('install');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('displays version when invoked with --version without requiring --root', () => {
|
|
51
|
+
const res = runWbt(['--version']);
|
|
52
|
+
expect(res.status).toBe(0);
|
|
53
|
+
expect(res.stdout).toMatch(/\d+\.\d+\.\d+/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('allows searching packages without requiring --root', () => {
|
|
57
|
+
const res = runWbt(['search', 'editor']);
|
|
58
|
+
expect(res.status).toBe(0);
|
|
59
|
+
expect(res.stdout).toContain('nano');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('allows showing package details without requiring --root', () => {
|
|
63
|
+
const res = runWbt(['show', 'nano']);
|
|
64
|
+
expect(res.status).toBe(0);
|
|
65
|
+
expect(res.stdout).toContain('Package: nano');
|
|
66
|
+
expect(res.stdout).toContain('Version: 8.0.1');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('fails when --root is missing for mutating commands (install, remove, list, update)', () => {
|
|
70
|
+
const installRes = runWbt(['install', 'nano']);
|
|
71
|
+
expect(installRes.status).toBe(1);
|
|
72
|
+
expect(installRes.stderr).toContain('--root <dir>');
|
|
73
|
+
|
|
74
|
+
const removeRes = runWbt(['remove', 'nano']);
|
|
75
|
+
expect(removeRes.status).toBe(1);
|
|
76
|
+
expect(removeRes.stderr).toContain('--root <dir>');
|
|
77
|
+
|
|
78
|
+
const listRes = runWbt(['list', '--installed']);
|
|
79
|
+
expect(listRes.status).toBe(1);
|
|
80
|
+
expect(listRes.stderr).toContain('--root <dir>');
|
|
81
|
+
|
|
82
|
+
const updateRes = runWbt(['update']);
|
|
83
|
+
expect(updateRes.status).toBe(1);
|
|
84
|
+
expect(updateRes.stderr).toContain('--root <dir>');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('fails when --root is set to system root / for safety', () => {
|
|
88
|
+
const res = runWbt(['--root', '/', 'install', 'nano']);
|
|
89
|
+
expect(res.status).toBe(1);
|
|
90
|
+
expect(res.stderr).toContain("Refusing to operate on system root '/'");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('fails when --root does not exist', () => {
|
|
94
|
+
const nonExistent = join(tmpdir(), `non-existent-${Date.now()}`);
|
|
95
|
+
const res = runWbt(['--root', nonExistent, 'install', 'nano']);
|
|
96
|
+
expect(res.status).toBe(1);
|
|
97
|
+
expect(res.stderr).toContain('does not exist');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('installs a package into an explicit --root directory on the host filesystem', () => {
|
|
101
|
+
const res = runWbt(['--root', tmpFsRoot, 'install', 'nano']);
|
|
102
|
+
expect(res.status).toBe(0);
|
|
103
|
+
|
|
104
|
+
// Verify /usr/lib/nano/nano.wasm and /usr/lib/nano/package.json
|
|
105
|
+
const wasmPath = join(tmpFsRoot, 'usr', 'lib', 'nano', 'nano.wasm');
|
|
106
|
+
const pkgJsonPath = join(tmpFsRoot, 'usr', 'lib', 'nano', 'package.json');
|
|
107
|
+
expect(existsSync(wasmPath)).toBe(true);
|
|
108
|
+
expect(existsSync(pkgJsonPath)).toBe(true);
|
|
109
|
+
|
|
110
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
|
111
|
+
expect(pkgJson.name).toBe('nano');
|
|
112
|
+
expect(pkgJson.version).toBe('8.0.1');
|
|
113
|
+
|
|
114
|
+
// Verify symlinks in /bin
|
|
115
|
+
const binNano = join(tmpFsRoot, 'bin', 'nano');
|
|
116
|
+
const binNanoWasm = join(tmpFsRoot, 'bin', 'nano-wasm');
|
|
117
|
+
expect(lstatSync(binNano).isSymbolicLink()).toBe(true);
|
|
118
|
+
expect(lstatSync(binNanoWasm).isSymbolicLink()).toBe(true);
|
|
119
|
+
|
|
120
|
+
// Symlink target is virtual path relative to container root
|
|
121
|
+
expect(readlinkSync(binNano)).toBe('/usr/lib/nano/nano.wasm');
|
|
122
|
+
expect(readlinkSync(binNanoWasm)).toBe('/usr/lib/nano/nano.wasm');
|
|
123
|
+
|
|
124
|
+
// Verify installed.json was NOT created
|
|
125
|
+
expect(existsSync(join(tmpFsRoot, 'var', 'lib', 'wbt', 'installed.json'))).toBe(false);
|
|
126
|
+
|
|
127
|
+
// Verify `wbt --root <dir> list --installed` lists nano
|
|
128
|
+
const listRes = runWbt(['-r', tmpFsRoot, 'list', '--installed']);
|
|
129
|
+
expect(listRes.status).toBe(0);
|
|
130
|
+
expect(listRes.stdout).toContain('nano');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('pre-installs packages via wbt CLI, packages with exportFileSystem into .brfs, and boots clean Shell executing WASM without wbt', async () => {
|
|
134
|
+
// 1. Install nano into tmpFsRoot using standalone wbt CLI
|
|
135
|
+
const installRes = runWbt(['--root', tmpFsRoot, 'install', 'nano']);
|
|
136
|
+
expect(installRes.status).toBe(0);
|
|
137
|
+
|
|
138
|
+
// 2. Export filesystem into a standalone .brfs container
|
|
139
|
+
const brfsFile = join(outDir, 'prepackaged.brfs');
|
|
140
|
+
const exportRes = runExportFs([tmpFsRoot, '-o', brfsFile]);
|
|
141
|
+
expect(exportRes.status).toBe(0);
|
|
142
|
+
expect(existsSync(brfsFile)).toBe(true);
|
|
143
|
+
|
|
144
|
+
// 3. Boot a Shell directly from the .brfs binary container file
|
|
145
|
+
const shell = await createShell({ filesystem: brfsFile });
|
|
146
|
+
|
|
147
|
+
// Verify wbt is NOT registered in this shell
|
|
148
|
+
expect(shell.context.getCommand('wbt')).toBeNull();
|
|
149
|
+
|
|
150
|
+
// 4. Run `nano --version` inside the clean Shell
|
|
151
|
+
const res = await run(shell, 'nano --version');
|
|
152
|
+
expect(res.exitCode).toBe(0);
|
|
153
|
+
expect(res.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
154
|
+
|
|
155
|
+
// 5. Run via alias `nano-wasm --version`
|
|
156
|
+
const aliasRes = await run(shell, 'nano-wasm --version');
|
|
157
|
+
expect(aliasRes.exitCode).toBe(0);
|
|
158
|
+
expect(aliasRes.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
159
|
+
});
|
|
160
|
+
});
|