RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { mkdtemp, mkdir, writeFile, readFile, readdir, chmod, rm, stat, symlink, rename } 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('macOS staging preserves the app bundle and executable layout', async t => {
|
||||
const options = await fixture(t);
|
||||
const source = join(options.project, 'dist/RuneStone-Browser-darwin-arm64');
|
||||
const executable = 'RuneStone-Browser.app/Contents/MacOS/RuneStone-Browser';
|
||||
await mkdir(join(source, 'RuneStone-Browser.app/Contents/MacOS'), { recursive: true });
|
||||
await writeFile(join(source, executable), 'macOS fixture', { mode: 0o755 });
|
||||
await writeFile(join(source, 'RuneStone-Browser.app/Contents/Info.plist'), 'bundle metadata');
|
||||
if (process.platform !== 'win32') {
|
||||
await symlink('../Info.plist', join(source, 'RuneStone-Browser.app/Contents/MacOS/metadata'));
|
||||
}
|
||||
const result = await stageRuntime({ ...options, platform: 'darwin', arch: 'arm64' });
|
||||
await rename(source, `${source}-moved`);
|
||||
assert.equal(await readFile(join(result.destination, executable), 'utf8'), 'macOS fixture');
|
||||
assert.equal(await readFile(join(result.destination, 'RuneStone-Browser.app/Contents/Info.plist'), 'utf8'), 'bundle metadata');
|
||||
assert.equal(await readFile(join(result.backup, 'RuneStone-Browser.exe'), 'utf8'), 'old runtime');
|
||||
if (process.platform !== 'win32') {
|
||||
assert.equal(await readFile(join(result.destination, 'RuneStone-Browser.app/Contents/MacOS/metadata'), 'utf8'), 'bundle metadata');
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user