brsh 3.9.0 → 3.10.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/CHANGELOG.md +14 -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 +4074 -3717
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +26 -25
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +3 -3
- package/dist/terminal.cjs.js.map +1 -1
- package/dist/terminal.es.js +55 -33
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +3 -3
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +3082 -2710
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +16 -12
- package/dist/wbt.min.js.map +1 -1
- package/index.js +102 -80
- package/lib/BaseFileSystem.js +57 -2
- package/lib/BinaryContainer.js +1 -1
- package/lib/Command.js +1 -1
- package/lib/Context.js +4 -3
- package/lib/FileSystem.js +4 -2
- package/lib/InteractiveCommand.js +9 -8
- package/lib/JsCommand.js +113 -0
- package/lib/NodeFileSystem.js +164 -30
- package/lib/Readme.md +1 -0
- package/lib/ScriptCommand.js +148 -8
- package/lib/Terminal.js +60 -6
- package/lib/TtyStream.js +36 -2
- package/lib/WasmCommand.js +313 -66
- package/lib/buildFilesystemStructure.js +38 -24
- package/lib/isUtf8Text.js +47 -0
- package/lib/local/which.js +8 -3
- package/lib/wbt/index.js +473 -175
- package/lib/wbt/registry.js +21 -1
- package/package.json +3 -2
- package/test/devices-signals.test.js +112 -0
- package/test/doom.test.js +7 -4
- 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/terminal.test.js +148 -0
- package/test/wasm-cli.test.js +76 -0
- package/test/wbt.test.js +418 -10
- package/test/wbtCli.test.js +160 -0
|
@@ -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
|
+
});
|