brsh 2.6.0 → 2.7.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.
@@ -137,6 +137,18 @@ describe('buildStructure', () => {
137
137
  const { permissions } = buildStructure(root);
138
138
  expect(permissions['/bin/tool.sh']).toBe(0o755);
139
139
  });
140
+
141
+ it('encodes .wasm files as data:application/wasm;base64 and strips .wasm extension', () => {
142
+ const sub = join(root, 'bin');
143
+ mkdirSync(sub);
144
+ const wasmBytes = Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
145
+ writeFileSync(join(sub, 'jq.wasm'), wasmBytes);
146
+ chmodSync(join(sub, 'jq.wasm'), 0o755);
147
+ const { filesystem, permissions } = buildStructure(root);
148
+ expect(filesystem.bin).toHaveProperty('jq');
149
+ expect(filesystem.bin.jq).toBe(`data:application/wasm;base64,${wasmBytes.toString('base64')}`);
150
+ expect(permissions['/bin/jq']).toBe(0o755);
151
+ });
140
152
  });
141
153
 
142
154
  // ---------------------------------------------------------------------------
@@ -347,3 +359,69 @@ describe('exportFileSystem CLI --compress', () => {
347
359
  expect(code.length).toBeGreaterThan(100);
348
360
  });
349
361
  });
362
+
363
+ describe('exportFileSystem CLI --binary (.brfs indexed binary container)', () => {
364
+ const { isBinaryContainer, deserializeBinaryFilesystem } = require('../lib/BinaryContainer.js');
365
+ let root;
366
+ let outDir;
367
+
368
+ beforeEach(() => {
369
+ root = tmpDir();
370
+ outDir = tmpDir();
371
+ mkdirSync(join(root, 'bin'));
372
+ writeFileSync(join(root, 'hello.txt'), 'Hello Binary Container');
373
+ writeFileSync(join(root, 'bin', 'run.sh'), '#!/sh.js\necho hi');
374
+ chmodSync(join(root, 'bin', 'run.sh'), 0o755);
375
+ writeFileSync(join(root, 'bin', 'tool.wasm'), Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
376
+ chmodSync(join(root, 'bin', 'tool.wasm'), 0o755);
377
+ });
378
+
379
+ afterEach(() => {
380
+ rmSync(root, { recursive: true, force: true });
381
+ rmSync(outDir, { recursive: true, force: true });
382
+ });
383
+
384
+ it('writes a standalone BRFS v2 binary container when -o ends with .brfs', () => {
385
+ const outFile = join(outDir, 'fs.brfs');
386
+ const r = runCLI([root, '-o', outFile]);
387
+ expect(r.status).toBe(0);
388
+ expect(existsSync(outFile)).toBe(true);
389
+
390
+ const raw = new Uint8Array(readFileSync(outFile));
391
+ expect(isBinaryContainer(raw)).toBe(true);
392
+
393
+ const { filesystem, permissions } = deserializeBinaryFilesystem(raw);
394
+ expect(filesystem['hello.txt']).toBe('Hello Binary Container');
395
+ expect(filesystem.bin['run.sh']).toBe('#!/sh.js\necho hi');
396
+ expect(filesystem.bin.tool instanceof Uint8Array).toBe(true);
397
+ expect(permissions['/bin/run.sh']).toBe(0o755);
398
+ expect(permissions['/bin/tool']).toBe(0o755);
399
+ });
400
+
401
+ it('writes a JS loader and .brfs binary container when --binary (-b) is passed with -o fs.js', () => {
402
+ const outFile = join(outDir, 'fs.js');
403
+ const r = runCLI([root, '-v', 'FS', '-o', outFile, '--binary']);
404
+ expect(r.status).toBe(0);
405
+ expect(existsSync(outFile)).toBe(true);
406
+ expect(existsSync(join(outDir, 'fs.brfs'))).toBe(true);
407
+
408
+ const raw = new Uint8Array(readFileSync(join(outDir, 'fs.brfs')));
409
+ expect(isBinaryContainer(raw)).toBe(true);
410
+ });
411
+
412
+ it('boots a Shell directly from an exported .brfs file path and executes scripts inside it', async () => {
413
+ const Shell = require('../index.js');
414
+ const outFile = join(outDir, 'fs.brfs');
415
+ const r = runCLI([root, '-o', outFile]);
416
+ expect(r.status).toBe(0);
417
+
418
+ const shell = new Shell({ filesystem: outFile });
419
+ const output = [];
420
+ shell.on('stdOut', line => output.push(line));
421
+ await shell.onCommand('run.sh && cat /hello.txt');
422
+
423
+ expect(output).toContain('hi');
424
+ expect(output).toContain('Hello Binary Container');
425
+ });
426
+ });
427
+