Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

test(desktop): preserve isolated verifier config across native relaunch (#776)

tianma-if21c7b866fc47
diff --git a/scripts/build-native-update-fixtures.mjs b/scripts/build-native-update-fixtures.mjs
index 28a201f2..7195f578 100644
--- a/scripts/build-native-update-fixtures.mjs
+++ b/scripts/build-native-update-fixtures.mjs
@@ -28,7 +28,7 @@ const keyPath = join(output, "signing-key.pem");
writeFileSync(keyPath, privateKey.export({ type: "pkcs8", format: "pem" }), { mode: 0o600 });
writeFileSync(join(output, "public-key.pem"), publicKeyPem);
writeFileSync(join(output, "versions.json"), JSON.stringify(versions));
-const instrumented = instrumentNativeUpdateMain(originalMain);
+const instrumented = instrumentNativeUpdateMain(originalMain, join(output, "runtime.json"));
const require = createRequire(join(desktop, "package.json"));
const builderCli = require.resolve("electron-builder/out/cli/cli.js");
const run = (command, args) => {
diff --git a/scripts/native-update-instrumentation.mjs b/scripts/native-update-instrumentation.mjs
index c8016efa..b30d8110 100644
--- a/scripts/native-update-instrumentation.mjs
+++ b/scripts/native-update-instrumentation.mjs
@@ -1,4 +1,4 @@
-export const instrumentNativeUpdateMain = (originalMain) => {
+export const instrumentNativeUpdateMain = (originalMain, runtimeConfigPath) => {
const replace = (source, from, to) => {
if (source.split(from).length !== 2) throw new Error(`Expected exactly one instrumentation site: ${from}`);
return source.replace(from, to);
@@ -11,5 +11,10 @@ export const instrumentNativeUpdateMain = (originalMain) => {
instrumented = replace(instrumented, ' void checkForDesktopUpdate("startup", { force: true });', ' attachVerifier({ app, updater: autoUpdater, controller: desktopUpdateController });\n void checkForDesktopUpdate("startup", { force: true });');
instrumented = instrumented.replace(' await confirmMacInstallation();', ' // Verification bundle stays in its isolated runner directory.');
instrumented = instrumented.replace(' await ejectMountedMacInstallers();', ' // Verification does not eject unrelated volumes.');
+ if (runtimeConfigPath) {
+ instrumented = 'import { readFileSync as readVerifierConfig } from "node:fs";\n' + instrumented;
+ const bootstrap = `for (const [key, value] of Object.entries(JSON.parse(readVerifierConfig(${JSON.stringify(runtimeConfigPath)}, "utf8")))) process.env[key] = value;\n`;
+ instrumented = instrumented.replace('const { autoUpdater } = electronUpdater;', bootstrap + 'const { autoUpdater } = electronUpdater;');
+ }
return instrumented;
};
diff --git a/scripts/native-update-instrumentation.test.mjs b/scripts/native-update-instrumentation.test.mjs
index 2937c062..71153ea8 100644
--- a/scripts/native-update-instrumentation.test.mjs
+++ b/scripts/native-update-instrumentation.test.mjs
@@ -7,7 +7,7 @@ import { instrumentNativeUpdateMain } from "./native-update-instrumentation.mjs"
const main = readFileSync(new URL("../apps/desktop/src/main/index.mjs", import.meta.url), "utf8");
test("instruments the actual current EdgeEver entry without changing its update controller", () => {
- const instrumented = instrumentNativeUpdateMain(main);
+ const instrumented = instrumentNativeUpdateMain(main, "/tmp/native-update-config.json");
const directory = mkdtempSync(join(tmpdir(), "edgeever-native-update-syntax-"));
try {
const path = join(directory, "index.mjs");
diff --git a/scripts/verify-native-desktop-update.mjs b/scripts/verify-native-desktop-update.mjs
index f261368c..8f114763 100644
--- a/scripts/verify-native-desktop-update.mjs
+++ b/scripts/verify-native-desktop-update.mjs
@@ -102,12 +102,19 @@ try {
const commandPath = join(directory, "command.json");
const profile = join(directory, "profile");
mkdirSync(profile, { recursive: true });
- const executable = await installBaseline(directory);
const env = { ...process.env,
EDGE_EVER_UPDATE_VERIFIER_PROFILE: profile, EDGE_EVER_UPDATE_VERIFIER_LOG: eventsPath,
EDGE_EVER_UPDATE_VERIFIER_COMMAND: commandPath, EDGE_EVER_UPDATE_VERIFIER_FEED: feed,
EDGE_EVER_UPDATE_VERIFIER_PUBLIC_KEY: join(root, "public-key.pem"),
};
+ // Squirrel/LaunchServices can relaunch without inheriting environment.
+ // Every signed fixture embeds only this fixed config path, never secrets.
+ writeFileSync(join(root, "runtime.json"), JSON.stringify({
+ EDGE_EVER_UPDATE_VERIFIER_PROFILE: profile, EDGE_EVER_UPDATE_VERIFIER_LOG: eventsPath,
+ EDGE_EVER_UPDATE_VERIFIER_COMMAND: commandPath, EDGE_EVER_UPDATE_VERIFIER_FEED: feed,
+ EDGE_EVER_UPDATE_VERIFIER_PUBLIC_KEY: join(root, "public-key.pem"),
+ }));
+ const executable = await installBaseline(directory);
const launch = () => {
const child = spawn(executable, [], { env, stdio: ["ignore", "pipe", "pipe"] });
child.on("error", (error) => appendFileSync(join(directory, "process.log"), `${error.stack}\n`));