Ship the browser engine as its own release file

The installer no longer bundles the engine, and the installer script
stops when the bundle names it or when the setup file is over 30 MB.
pnpm build:browser-engine packages the engine, writes a deterministic
ZIP and its record to releases/browser-engine/<version>/, and pins the
ZIP in the host. The installer hooks remove the engine folder that 0.1.48
leaves behind, and uninstall removes the downloaded engine.
This commit is contained in:
Knotty Wyvern
2026-10-29 01:25:53 -07:00
parent c06d48f250
commit aebe700366
18 changed files with 511 additions and 52 deletions
+67 -2
View File
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, readFile, writeFile, copyFile, rm } from 'node:fs/promises';
import { mkdtemp, mkdir, readFile, writeFile, copyFile, rm } from 'node:fs/promises';
import { existsSync, readFileSync, realpathSync } from 'node:fs';
import { createRequire } from 'node:module';
import { tmpdir } from 'node:os';
@@ -51,6 +51,10 @@ test('the stock Tauri template still provides what the hooks rely on', { skip: t
assert.ok(index >= 0, 'The stock template no longer contains: ' + fragment);
return index;
};
// NSIS_HOOK_POSTUNINSTALL removes the downloaded engine. It needs ${BUNDLEID}, $UpdateMode, and its place after the app data step.
const removal = at('RmDir /r "$LOCALAPPDATA\\${BUNDLEID}"');
assert.ok(text.indexOf('${AndIf} $UpdateMode <> 1') < removal);
assert.ok(removal < at('!insertmacro NSIS_HOOK_POSTUNINSTALL'), 'The uninstall hook must run after the app data step.');
const include = at('!include "{{installer_hooks}}"');
assert.ok(include < at('!insertmacro MUI_PAGE_WELCOME'), 'Tauri must include the hooks before the first page.');
assert.ok(include < at('\nSection EarlyChecks'), 'Tauri must include the hooks before its first section.');
@@ -158,7 +162,7 @@ test('the hooks block downgrades in every installer mode', { skip: nsisSkip }, a
RequestExecutionLevel user
Name "RuneStone hook test"
OutFile "${executable}"
InstallDir "$TEMP"
InstallDir "${path.join(root, 'install')}"
AutoCloseWindow true
VIProductVersion "${windows}"
VIAddVersionKey "ProductName" "RuneStone hook test"
@@ -242,3 +246,64 @@ SectionEnd
await rm(root, { recursive: true, force: true });
}
});
// NSIS_HOOK_POSTINSTALL removes the engine folder that releases up to 0.1.48 put in the installation folder.
// NSIS_HOOK_POSTUNINSTALL removes the downloaded engine, keeps the browser profiles, and keeps everything during an update.
test('the hooks remove old and downloaded browser engines but keep the profiles', { skip: nsisSkip }, async () => {
const root = await mkdtemp(path.join(tmpdir(), 'runestone-installer-engine-'));
const bundle = 'com.runestone.hook-test-' + path.basename(root);
const local = path.join(process.env.LOCALAPPDATA!, bundle);
const install = path.join(root, 'install');
const key = 'Software\\RuneStoneInstallerTest-' + path.basename(root);
const program = async (name: string, updateMode: number) => {
const executable = path.join(root, name + '.exe'), script = path.join(root, name + '.nsi');
const source = `Unicode true
SilentInstall silent
RequestExecutionLevel user
Name "RuneStone engine hook test"
OutFile "${executable}"
InstallDir "${install}"
VIProductVersion "0.1.49.0"
VIAddVersionKey "ProductName" "RuneStone engine hook test"
VIAddVersionKey "FileVersion" "0.1.49"
VIAddVersionKey "ProductVersion" "0.1.49"
!define RUNESTONE_UNINSTKEY "${key}"
!define BUNDLEID "${bundle}"
!include "${hooks}"
Var UpdateMode
Section Install
StrCpy $UpdateMode ${updateMode}
!insertmacro NSIS_HOOK_POSTINSTALL
!insertmacro NSIS_HOOK_POSTUNINSTALL
SectionEnd
`;
await writeFile(script, source);
compile(script, source);
return executable;
};
const seed = async () => {
await mkdir(path.join(install, 'browser-engine', 'locales'), { recursive: true });
await writeFile(path.join(install, 'browser-engine', 'RuneStone-Browser.exe'), 'old engine');
await writeFile(path.join(install, 'runestone.exe'), 'app');
await mkdir(path.join(local, 'browser-engine', '0.1.8'), { recursive: true });
await writeFile(path.join(local, 'browser-engine', '0.1.8', 'RuneStone-Browser.exe'), 'engine');
await mkdir(path.join(local, 'browser'), { recursive: true });
await writeFile(path.join(local, 'browser', 'browser.json'), '{}');
};
try {
await seed();
assert.equal(spawnSync(await program('remove', 0), ['/S'], { windowsHide: true, timeout: 30000 }).status, 0);
assert.equal(existsSync(path.join(install, 'browser-engine')), false, 'Setup removes the old engine folder.');
assert.equal(existsSync(path.join(install, 'runestone.exe')), true);
assert.equal(existsSync(path.join(local, 'browser-engine')), false, 'Uninstall removes the downloaded engine.');
assert.equal(existsSync(path.join(local, 'browser', 'browser.json')), true, 'The profiles stay.');
await seed();
assert.equal(spawnSync(await program('update', 1), ['/S'], { windowsHide: true, timeout: 30000 }).status, 0);
assert.equal(existsSync(path.join(local, 'browser-engine', '0.1.8', 'RuneStone-Browser.exe')), true, 'An update keeps the downloaded engine.');
} finally {
spawnSync('reg', ['delete', 'HKCU\\' + key, '/f'], { windowsHide: true });
assert.equal(local.startsWith(process.env.LOCALAPPDATA!) && path.basename(local).startsWith('com.runestone.hook-test-'), true);
await rm(local, { recursive: true, force: true });
await rm(root, { recursive: true, force: true });
}
});