brsh 2.7.0 → 2.8.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 +13 -0
- package/Readme.md +33 -16
- package/bin/brsh-shell.js +15 -1
- package/dist/shell.es.js +83 -28
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +3 -3
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +101 -0
- package/dist/terminal.cjs.js.map +1 -0
- package/dist/terminal.es.js +290 -8107
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +4 -32
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +346 -5821
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +4 -18
- package/dist/wbt.min.js.map +1 -1
- package/index.js +29 -0
- package/lib/Terminal.js +45 -10
- package/lib/local/curl.js +60 -2
- package/lib/wbt/index.js +27 -50
- package/lib/wbt/packages/wllama.js +1051 -0
- package/lib/wbt/registry.js +20 -17
- package/package.json +3 -2
- package/test/curl.test.js +166 -0
- package/test/terminal.test.js +113 -0
- package/test/wasm-cli.test.js +127 -0
- package/test/wbt.test.js +322 -231
- package/vite.config.terminal.js +16 -12
- package/vitest.config.js +6 -0
- package/lib/wbt/daemon.js +0 -264
- package/lib/wbt/packages/pglite.js +0 -590
package/lib/wbt/registry.js
CHANGED
|
@@ -15,19 +15,6 @@
|
|
|
15
15
|
* - type: 'builtin-adapter' (uses a built-in Command adapter) | 'custom-wasm' (raw WASI binary)
|
|
16
16
|
*/
|
|
17
17
|
const DEFAULT_REGISTRY = {
|
|
18
|
-
pglite: {
|
|
19
|
-
name: 'pglite',
|
|
20
|
-
bin: 'pglite',
|
|
21
|
-
aliases: ['psql', 'pg_ctl'],
|
|
22
|
-
version: '0.2.17',
|
|
23
|
-
description: 'Lightweight WASM Postgres database & daemon in the browser and Node',
|
|
24
|
-
details: 'PGlite is a WASM build of PostgreSQL packaged into a client-side library that runs a full Postgres database in memory, persisted to the brsh filesystem, or as a background server daemon (`pglite serve` / `pg_ctl start`).',
|
|
25
|
-
homepage: 'https://pglite.dev',
|
|
26
|
-
cdnUrl: 'https://esm.sh/@electric-sql/pglite@0.2.17',
|
|
27
|
-
type: 'builtin-adapter',
|
|
28
|
-
adapter: 'pglite',
|
|
29
|
-
size: '3.1 MB'
|
|
30
|
-
},
|
|
31
18
|
sqlite3: {
|
|
32
19
|
name: 'sqlite3',
|
|
33
20
|
bin: 'sqlite3',
|
|
@@ -156,6 +143,20 @@ const DEFAULT_REGISTRY = {
|
|
|
156
143
|
type: 'generic-runtime',
|
|
157
144
|
repl: { prompt: 'lua> ', evalFlag: '-e' },
|
|
158
145
|
size: '410 KB'
|
|
146
|
+
},
|
|
147
|
+
wllama: {
|
|
148
|
+
name: 'wllama',
|
|
149
|
+
bin: 'wllama',
|
|
150
|
+
aliases: ['llama', 'llama-cli'],
|
|
151
|
+
version: '3.8.1',
|
|
152
|
+
description: 'WebAssembly & WebGPU LLM inference engine powered by llama.cpp (@wllama/wllama)',
|
|
153
|
+
details: 'Wllama v3 runs GGUF large language models in WebAssembly with automatic WebGPU hardware acceleration. Supports one-shot chat/text completions, interactive chat REPL, model inspection, embeddings, benchmarks, and Hugging Face & local filesystem GGUF loading.',
|
|
154
|
+
homepage: 'https://github.com/ngxson/wllama',
|
|
155
|
+
cdnUrl: 'https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/esm/index.js',
|
|
156
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/src/wasm/wllama.wasm',
|
|
157
|
+
type: 'builtin-adapter',
|
|
158
|
+
adapter: 'wllama',
|
|
159
|
+
size: '8.8 MB'
|
|
159
160
|
}
|
|
160
161
|
};
|
|
161
162
|
|
|
@@ -163,8 +164,6 @@ const DEFAULT_REGISTRY = {
|
|
|
163
164
|
const PACKAGE_ALIASES = {
|
|
164
165
|
sqlite: 'sqlite3',
|
|
165
166
|
'sqlite-wasm': 'sqlite3',
|
|
166
|
-
psql: 'pglite',
|
|
167
|
-
postgres: 'pglite',
|
|
168
167
|
asc: 'assemblyscript',
|
|
169
168
|
asrun: 'assemblyscript',
|
|
170
169
|
asnode: 'assemblyscript',
|
|
@@ -174,12 +173,16 @@ const PACKAGE_ALIASES = {
|
|
|
174
173
|
dot: 'graphviz',
|
|
175
174
|
wat2wasm: 'wabt',
|
|
176
175
|
wasm2wat: 'wabt',
|
|
177
|
-
qjs: 'quickjs'
|
|
176
|
+
qjs: 'quickjs',
|
|
177
|
+
llama: 'wllama',
|
|
178
|
+
'llama-cli': 'wllama',
|
|
179
|
+
'llama.cpp': 'wllama',
|
|
180
|
+
'@wllama/wllama': 'wllama'
|
|
178
181
|
};
|
|
179
182
|
|
|
180
183
|
function resolvePackageName(name) {
|
|
181
184
|
if (!name) return null;
|
|
182
|
-
const lower = name.toLowerCase();
|
|
185
|
+
const lower = name.toLowerCase().replace(/^(npm|esm):/i, '').replace(/@[\d.^~><=*]+$/, '');
|
|
183
186
|
return PACKAGE_ALIASES[lower] || lower;
|
|
184
187
|
}
|
|
185
188
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brsh",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "A unix like shell written in javascript",
|
|
5
5
|
"main": "./dist/shell.min.js",
|
|
6
6
|
"module": "./dist/shell.es.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"./terminal": {
|
|
14
14
|
"import": "./dist/terminal.es.js",
|
|
15
|
-
"require": "./dist/terminal.
|
|
15
|
+
"require": "./dist/terminal.cjs.js",
|
|
16
16
|
"default": "./dist/terminal.min.js"
|
|
17
17
|
},
|
|
18
18
|
"./wbt": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"build:wbt": "vite build --config vite.config.wbt.js",
|
|
36
36
|
"shell": "node bin/brsh-shell.js",
|
|
37
37
|
"demo:shell": "node bin/brsh-shell.js --demo",
|
|
38
|
+
"pretest": "npm run build",
|
|
38
39
|
"test": "vitest run",
|
|
39
40
|
"test:watch": "vitest",
|
|
40
41
|
"prepublishOnly": "npm run build"
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { createShell, run } from './helpers.js';
|
|
3
|
+
import { BinaryFile } from '../lib/FileSystem.js';
|
|
4
|
+
|
|
5
|
+
describe('curl command', () => {
|
|
6
|
+
let shell;
|
|
7
|
+
let originalFetch;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
shell = await createShell({
|
|
11
|
+
filesystem: {
|
|
12
|
+
home: {}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
originalFetch = globalThis.fetch;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
globalThis.fetch = originalFetch;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('fetches text and prints to stdout', async () => {
|
|
23
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
24
|
+
ok: true,
|
|
25
|
+
status: 200,
|
|
26
|
+
statusText: 'OK',
|
|
27
|
+
headers: new Headers({ 'content-type': 'text/plain' }),
|
|
28
|
+
text: async () => 'Hello, world!\nLine 2',
|
|
29
|
+
arrayBuffer: async () => new TextEncoder().encode('Hello, world!\nLine 2').buffer
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const res = await run(shell, 'curl https://example.com/hello.txt');
|
|
33
|
+
expect(res.exitCode).toBe(0);
|
|
34
|
+
expect(res.output).toEqual(['Hello, world!', 'Line 2']);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('includes response headers with -i', async () => {
|
|
38
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
39
|
+
ok: true,
|
|
40
|
+
status: 200,
|
|
41
|
+
statusText: 'OK',
|
|
42
|
+
headers: new Headers({
|
|
43
|
+
'content-type': 'text/plain',
|
|
44
|
+
'x-custom-header': 'test-val'
|
|
45
|
+
}),
|
|
46
|
+
text: async () => 'response body',
|
|
47
|
+
arrayBuffer: async () => new TextEncoder().encode('response body').buffer
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const res = await run(shell, 'curl -i https://example.com');
|
|
51
|
+
expect(res.exitCode).toBe(0);
|
|
52
|
+
expect(res.output).toContain('HTTP/1.1 200 OK');
|
|
53
|
+
expect(res.output).toContain('x-custom-header: test-val');
|
|
54
|
+
expect(res.output).toContain('response body');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('downloads binary data to a file without UTF-8 corruption', async () => {
|
|
58
|
+
// Raw bytes with non-UTF8 sequences (e.g. WASM or GGUF magic headers)
|
|
59
|
+
const binaryBytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x80]);
|
|
60
|
+
|
|
61
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
62
|
+
ok: true,
|
|
63
|
+
status: 200,
|
|
64
|
+
statusText: 'OK',
|
|
65
|
+
headers: new Headers({
|
|
66
|
+
'content-type': 'application/octet-stream',
|
|
67
|
+
'content-length': String(binaryBytes.length)
|
|
68
|
+
}),
|
|
69
|
+
arrayBuffer: async () => binaryBytes.buffer
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const res = await run(shell, 'curl -s -o /home/model.wasm https://example.com/model.wasm');
|
|
73
|
+
expect(res.exitCode).toBe(0);
|
|
74
|
+
|
|
75
|
+
const savedFile = shell.context.fs.getFileByPath('/home/model.wasm');
|
|
76
|
+
expect(savedFile).toBeDefined();
|
|
77
|
+
expect(savedFile instanceof BinaryFile || savedFile instanceof Uint8Array).toBe(true);
|
|
78
|
+
expect(new Uint8Array(savedFile)).toEqual(binaryBytes);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('emits live carriage return progress bar during streaming download to a file', async () => {
|
|
82
|
+
const chunk1 = new Uint8Array([1, 2, 3, 4, 5]);
|
|
83
|
+
const chunk2 = new Uint8Array([6, 7, 8, 9, 10]);
|
|
84
|
+
let readCount = 0;
|
|
85
|
+
|
|
86
|
+
const mockReader = {
|
|
87
|
+
read: vi.fn().mockImplementation(async () => {
|
|
88
|
+
readCount++;
|
|
89
|
+
if (readCount === 1) return { done: false, value: chunk1 };
|
|
90
|
+
if (readCount === 2) return { done: false, value: chunk2 };
|
|
91
|
+
return { done: true, value: undefined };
|
|
92
|
+
})
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
96
|
+
ok: true,
|
|
97
|
+
status: 200,
|
|
98
|
+
statusText: 'OK',
|
|
99
|
+
headers: new Headers({
|
|
100
|
+
'content-type': 'application/octet-stream',
|
|
101
|
+
'content-length': '10'
|
|
102
|
+
}),
|
|
103
|
+
body: {
|
|
104
|
+
getReader: () => mockReader
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const res = await run(shell, 'curl -o /home/stream.bin https://example.com/stream.bin');
|
|
109
|
+
expect(res.exitCode).toBe(0);
|
|
110
|
+
|
|
111
|
+
// Verify progress updates with \r were emitted
|
|
112
|
+
const progressLines = res.output.filter(l => l.startsWith('\r'));
|
|
113
|
+
expect(progressLines.length).toBeGreaterThan(0);
|
|
114
|
+
expect(progressLines.some(l => l.includes('50%'))).toBe(true);
|
|
115
|
+
expect(progressLines.some(l => l.includes('100%'))).toBe(true);
|
|
116
|
+
|
|
117
|
+
const savedFile = shell.context.fs.getFileByPath('/home/stream.bin');
|
|
118
|
+
expect(new Uint8Array(savedFile)).toEqual(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('suppresses progress bar when -s / --silent is passed', async () => {
|
|
122
|
+
const chunk = new Uint8Array([1, 2, 3, 4, 5]);
|
|
123
|
+
let done = false;
|
|
124
|
+
|
|
125
|
+
const mockReader = {
|
|
126
|
+
read: vi.fn().mockImplementation(async () => {
|
|
127
|
+
if (!done) {
|
|
128
|
+
done = true;
|
|
129
|
+
return { done: false, value: chunk };
|
|
130
|
+
}
|
|
131
|
+
return { done: true, value: undefined };
|
|
132
|
+
})
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
136
|
+
ok: true,
|
|
137
|
+
status: 200,
|
|
138
|
+
statusText: 'OK',
|
|
139
|
+
headers: new Headers({
|
|
140
|
+
'content-type': 'application/octet-stream',
|
|
141
|
+
'content-length': '5'
|
|
142
|
+
}),
|
|
143
|
+
body: {
|
|
144
|
+
getReader: () => mockReader
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const res = await run(shell, 'curl -s -o /home/quiet.bin https://example.com/quiet.bin');
|
|
149
|
+
expect(res.exitCode).toBe(0);
|
|
150
|
+
expect(res.output.some(l => l.startsWith('\r'))).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('automatically creates parent directories for output files', async () => {
|
|
154
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
155
|
+
ok: true,
|
|
156
|
+
status: 200,
|
|
157
|
+
statusText: 'OK',
|
|
158
|
+
headers: new Headers({ 'content-type': 'text/plain' }),
|
|
159
|
+
arrayBuffer: async () => new TextEncoder().encode('nested data').buffer
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const res = await run(shell, 'curl -s -o /home/nested/sub/dir/app.txt https://example.com/app.txt');
|
|
163
|
+
expect(res.exitCode).toBe(0);
|
|
164
|
+
expect(shell.context.fs.getFileByPath('/home/nested/sub/dir/app.txt')).toBe('nested data');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import Shell from '../index.js';
|
|
3
|
+
import Terminal from '../lib/Terminal.js';
|
|
4
|
+
|
|
5
|
+
describe('Terminal decoupling and Shell resolution', () => {
|
|
6
|
+
let originalWindow;
|
|
7
|
+
let originalDocument;
|
|
8
|
+
let originalShell;
|
|
9
|
+
let originalGlobalShell;
|
|
10
|
+
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
originalWindow = globalThis.window;
|
|
13
|
+
originalDocument = globalThis.document;
|
|
14
|
+
originalShell = globalThis.Shell;
|
|
15
|
+
originalGlobalShell = globalThis.shell;
|
|
16
|
+
|
|
17
|
+
// Minimal DOM mock
|
|
18
|
+
globalThis.window = {
|
|
19
|
+
addEventListener: () => {},
|
|
20
|
+
removeEventListener: () => {}
|
|
21
|
+
};
|
|
22
|
+
globalThis.document = {
|
|
23
|
+
createElement: () => ({
|
|
24
|
+
style: {},
|
|
25
|
+
classList: { add: () => {} },
|
|
26
|
+
appendChild: () => {},
|
|
27
|
+
setAttribute: () => {},
|
|
28
|
+
addEventListener: () => {},
|
|
29
|
+
getBoundingClientRect: () => ({ width: 800, height: 600 }),
|
|
30
|
+
querySelectorAll: () => []
|
|
31
|
+
}),
|
|
32
|
+
head: { appendChild: () => {} }
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterAll(() => {
|
|
37
|
+
globalThis.window = originalWindow;
|
|
38
|
+
globalThis.document = originalDocument;
|
|
39
|
+
globalThis.Shell = originalShell;
|
|
40
|
+
globalThis.shell = originalGlobalShell;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('instantiates with options.cli directly', () => {
|
|
44
|
+
delete globalThis.Shell;
|
|
45
|
+
delete globalThis.shell;
|
|
46
|
+
|
|
47
|
+
const customShell = new Shell({ cwd: '/test' });
|
|
48
|
+
const term = new Terminal({
|
|
49
|
+
el: document.createElement('div'),
|
|
50
|
+
cli: customShell
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(term.cli).toBe(customShell);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('instantiates with options.Shell constructor', () => {
|
|
57
|
+
delete globalThis.Shell;
|
|
58
|
+
delete globalThis.shell;
|
|
59
|
+
|
|
60
|
+
const term = new Terminal({
|
|
61
|
+
el: document.createElement('div'),
|
|
62
|
+
Shell: Shell,
|
|
63
|
+
cwd: '/test'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(term.cli).toBeInstanceOf(Shell);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('instantiates with globalThis.Shell fallback', () => {
|
|
70
|
+
globalThis.Shell = Shell;
|
|
71
|
+
|
|
72
|
+
const term = new Terminal({
|
|
73
|
+
el: document.createElement('div'),
|
|
74
|
+
cwd: '/test'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(term.cli).toBeInstanceOf(Shell);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('throws a helpful error when no Shell or cli is available', () => {
|
|
81
|
+
delete globalThis.Shell;
|
|
82
|
+
delete globalThis.shell;
|
|
83
|
+
|
|
84
|
+
expect(() => {
|
|
85
|
+
new Terminal({
|
|
86
|
+
el: document.createElement('div'),
|
|
87
|
+
Shell: null
|
|
88
|
+
});
|
|
89
|
+
}).toThrow(/Shell is required by Terminal/);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('can be required as a CommonJS module via dist/terminal.cjs.js', () => {
|
|
93
|
+
const { createRequire } = require('module');
|
|
94
|
+
const fs = require('fs');
|
|
95
|
+
const path = require('path');
|
|
96
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
97
|
+
const distFile = path.resolve(import.meta.dirname, '../dist/terminal.cjs.js');
|
|
98
|
+
if (!fs.existsSync(distFile)) {
|
|
99
|
+
const { execSync } = require('child_process');
|
|
100
|
+
execSync('npm run build:terminal', { stdio: 'ignore' });
|
|
101
|
+
}
|
|
102
|
+
const CjsTerminal = cjsRequire('../dist/terminal.cjs.js');
|
|
103
|
+
const TermClass = CjsTerminal.default || CjsTerminal;
|
|
104
|
+
expect(typeof TermClass).toBe('function');
|
|
105
|
+
|
|
106
|
+
const customShell = new Shell({ cwd: '/test' });
|
|
107
|
+
const term = new TermClass({
|
|
108
|
+
el: document.createElement('div'),
|
|
109
|
+
cli: customShell
|
|
110
|
+
});
|
|
111
|
+
expect(term.cli).toBe(customShell);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import Shell from '../index.js';
|
|
3
|
+
import { run } from './helpers.js';
|
|
4
|
+
|
|
5
|
+
// Minimal valid WASM binary that exports _start and exits with 0:
|
|
6
|
+
const MINIMAL_WASM_BYTES = new Uint8Array([
|
|
7
|
+
0x00, 0x61, 0x73, 0x6d,
|
|
8
|
+
0x01, 0x00, 0x00, 0x00,
|
|
9
|
+
0x01, 0x04, 0x01, 0x60, 0x00, 0x00,
|
|
10
|
+
0x03, 0x02, 0x01, 0x00,
|
|
11
|
+
0x07, 0x0a, 0x01, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00,
|
|
12
|
+
0x0a, 0x04, 0x01, 0x02, 0x00, 0x0b
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
describe('Running .wasm files directly as CLI tools in base shell', () => {
|
|
16
|
+
it('refuses to execute a .wasm file without execute permissions (permission denied)', async () => {
|
|
17
|
+
const shell = new Shell({
|
|
18
|
+
filesystem: {
|
|
19
|
+
home: {
|
|
20
|
+
'mytool.wasm': MINIMAL_WASM_BYTES
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
cwd: '/home'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Default mode is 0o644 -> not executable
|
|
27
|
+
const res = await run(shell, './mytool.wasm');
|
|
28
|
+
expect(res.exitCode).toBe(1);
|
|
29
|
+
expect(res.errors.join('')).toContain('permission denied');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('executes a .wasm file via ./mytool.wasm after chmod +x', async () => {
|
|
33
|
+
const shell = new Shell({
|
|
34
|
+
filesystem: {
|
|
35
|
+
home: {
|
|
36
|
+
'mytool.wasm': MINIMAL_WASM_BYTES
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
cwd: '/home'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await run(shell, 'chmod +x mytool.wasm');
|
|
43
|
+
const res = await run(shell, './mytool.wasm');
|
|
44
|
+
expect(res.exitCode).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('refuses to run a file in cwd by bare name without path (standard PATH behavior)', async () => {
|
|
48
|
+
const shell = new Shell({
|
|
49
|
+
filesystem: {
|
|
50
|
+
home: {
|
|
51
|
+
'mytool.wasm': MINIMAL_WASM_BYTES
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
permissions: {
|
|
55
|
+
'/home/mytool.wasm': 0o755
|
|
56
|
+
},
|
|
57
|
+
cwd: '/home'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const res = await run(shell, 'mytool.wasm');
|
|
61
|
+
expect(res.exitCode).toBe(1);
|
|
62
|
+
expect(res.errors.join('')).toContain('Command not found');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('executes an executable .wasm file placed in /bin by bare name without .wasm extension', async () => {
|
|
66
|
+
const shell = new Shell({
|
|
67
|
+
filesystem: {
|
|
68
|
+
bin: {
|
|
69
|
+
'cowsay.wasm': MINIMAL_WASM_BYTES
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
permissions: {
|
|
73
|
+
'/bin/cowsay.wasm': 0o755
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const res = await run(shell, 'cowsay');
|
|
78
|
+
expect(res.exitCode).toBe(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('supports --help and --version automatically on raw .wasm binaries', async () => {
|
|
82
|
+
const shell = new Shell({
|
|
83
|
+
filesystem: {
|
|
84
|
+
home: {
|
|
85
|
+
'mytool.wasm': MINIMAL_WASM_BYTES
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
permissions: {
|
|
89
|
+
'/home/mytool.wasm': 0o755
|
|
90
|
+
},
|
|
91
|
+
cwd: '/home'
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const helpRes = await run(shell, './mytool.wasm --help');
|
|
95
|
+
expect(helpRes.exitCode).toBe(0);
|
|
96
|
+
const helpText = helpRes.output.join('\n');
|
|
97
|
+
expect(helpText).toContain('Usage: mytool.wasm');
|
|
98
|
+
expect(helpText).toContain('-h, --help');
|
|
99
|
+
expect(helpText).toContain('-V, --version');
|
|
100
|
+
expect(helpText).toContain('WASM Exports: _start');
|
|
101
|
+
|
|
102
|
+
const verRes = await run(shell, './mytool.wasm --version');
|
|
103
|
+
expect(verRes.exitCode).toBe(0);
|
|
104
|
+
expect(verRes.output.join('\n')).toContain('mytool.wasm');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('supports piping stdin into .wasm binaries and redirecting stdout to files', async () => {
|
|
108
|
+
const shell = new Shell({
|
|
109
|
+
filesystem: {
|
|
110
|
+
bin: {
|
|
111
|
+
'mytool.wasm': MINIMAL_WASM_BYTES
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
permissions: {
|
|
115
|
+
'/bin/mytool.wasm': 0o755
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const pipeRes = await run(shell, 'echo "input data" | mytool');
|
|
120
|
+
expect(pipeRes.exitCode).toBe(0);
|
|
121
|
+
|
|
122
|
+
const redirRes = await run(shell, 'mytool --help > /help.txt');
|
|
123
|
+
expect(redirRes.exitCode).toBe(0);
|
|
124
|
+
expect(shell.context.fs.exists('/help.txt')).toBe(true);
|
|
125
|
+
expect(shell.context.fs.getFileByPath('/help.txt')).toContain('Usage: mytool.wasm');
|
|
126
|
+
});
|
|
127
|
+
});
|