Prepare Linux builds and validate native desktop runtime

This commit is contained in:
2026-10-14 18:06:22 -07:00
parent edef2520af
commit 30cbfeedd6
15 changed files with 481 additions and 27 deletions
@@ -0,0 +1,65 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { mkdtemp, mkdir, writeFile, readFile, readdir, chmod, rm, stat } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { stageRuntime } from '../scripts/stage-runtime.mjs';
async function fixture(t) {
const root = await mkdtemp(join(tmpdir(), 'runestone-stage-test-'));
t.after(() => rm(root, { recursive: true, force: true }));
const project = join(root, 'browser-runtime');
const source = join(project, 'dist/RuneStone-Browser-linux-x64');
const destination = join(root, 'src-tauri/browser-engine');
await mkdir(source, { recursive: true });
await chmod(source, 0o755);
await mkdir(destination, { recursive: true });
await writeFile(join(source, 'RuneStone-Browser'), 'fixture', { mode: 0o755 });
await writeFile(join(destination, 'RuneStone-Browser.exe'), 'old runtime');
return { project, host: root, source, destination, platform: 'linux', arch: 'x64' };
}
test('staging replaces a foreign runtime tree and preserves a recoverable backup', async t => {
const options = await fixture(t);
const result = await stageRuntime(options);
assert.deepEqual(await readdir(options.destination), ['RuneStone-Browser']);
if (process.platform !== 'win32') {
assert.equal((await stat(options.destination)).mode & 0o777, 0o755);
assert.equal((await stat(join(options.destination, 'RuneStone-Browser'))).mode & 0o777, 0o755);
}
assert.equal(await readFile(join(result.backup, 'RuneStone-Browser.exe'), 'utf8'), 'old runtime');
assert.equal(await readFile(join(options.source, 'RuneStone-Browser'), 'utf8'), 'fixture');
});
test('missing source leaves the previous runtime intact', async t => {
const options = await fixture(t);
await assert.rejects(stageRuntime({ ...options, arch: 'arm64' }), /ENOENT/);
assert.equal(await readFile(join(options.destination, 'RuneStone-Browser.exe'), 'utf8'), 'old runtime');
});
test('Linux staging rejects a non-executable runtime before replacing the old tree', { skip: process.platform === 'win32' }, async t => {
const options = await fixture(t);
await chmod(join(options.source, 'RuneStone-Browser'), 0o644);
await assert.rejects(stageRuntime(options), /EACCES/);
assert.equal(await readFile(join(options.destination, 'RuneStone-Browser.exe'), 'utf8'), 'old runtime');
});
test('Windows staging retains the exe layout without Linux execute permissions', async t => {
const options = await fixture(t);
const source = join(options.project, 'dist/RuneStone-Browser-win32-x64');
await mkdir(source, { recursive: true });
await writeFile(join(source, 'RuneStone-Browser.exe'), 'windows fixture', { mode: 0o644 });
const result = await stageRuntime({ ...options, platform: 'win32' });
assert.deepEqual(await readdir(result.destination), ['RuneStone-Browser.exe']);
assert.equal(await readFile(join(result.destination, 'RuneStone-Browser.exe'), 'utf8'), 'windows fixture');
});
test('Linux staging normalizes a private packager output root for installation', { skip: process.platform === 'win32' }, async t => {
const options = await fixture(t);
await chmod(options.source, 0o700);
const result = await stageRuntime(options);
assert.equal((await stat(result.destination)).mode & 0o777, 0o755);
assert.equal((await stat(options.source)).mode & 0o777, 0o700);
});