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): expose native update failures and bound fixture cleanup (#776)

tianma-ifc974ff69529d
diff --git a/.github/workflows/desktop-update-verification.yml b/.github/workflows/desktop-update-verification.yml
index 7430baca..5ae0f4b5 100644
--- a/.github/workflows/desktop-update-verification.yml
+++ b/.github/workflows/desktop-update-verification.yml
@@ -26,6 +26,8 @@ jobs:
name: Native update ${{ matrix.platform }} ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
+ env:
+ FIXTURE_RUN: ${{ inputs.fixture_run }}
strategy:
fail-fast: false
matrix:
@@ -141,10 +143,12 @@ jobs:
run: gh run download "$FIXTURE_RUN" --repo "$GITHUB_REPOSITORY" --name "$ARTIFACT_NAME" --dir "$RUNNER_TEMP/edgeever-update-verification"
- name: Exercise real native updates
+ timeout-minutes: 10
if: runner.os != 'Linux'
run: node scripts/verify-native-desktop-update.mjs "${{ runner.temp }}/edgeever-update-verification"
- name: Exercise real AppImage updates
+ timeout-minutes: 10
if: runner.os == 'Linux'
run: xvfb-run -a node scripts/verify-native-desktop-update.mjs "$RUNNER_TEMP/edgeever-update-verification"
diff --git a/scripts/native-update-instrumentation.test.mjs b/scripts/native-update-instrumentation.test.mjs
index c13f771c..2377a2c6 100644
--- a/scripts/native-update-instrumentation.test.mjs
+++ b/scripts/native-update-instrumentation.test.mjs
@@ -42,7 +42,7 @@ test("the installer workflow is official-only, manual, and never publishes asset
expect(matrices[2].map((entry) => entry.runner)).toEqual(["macos-15", "macos-15-intel", "windows-latest", "ubuntu-22.04"]);
});
-// This JavaScript is sent to a paused real application, so template escaping
+// This JavaScript is sent to a real application, so template escaping
// must be checked independently of the outer verifier script's syntax.
test("official bridge debugger bootstrap compiles for old/new and Windows paths", () => {
const source = readFileSync(new URL("./verify-native-release-bridge.mjs", import.meta.url), "utf8");
diff --git a/scripts/native-update-status.mjs b/scripts/native-update-status.mjs
new file mode 100644
index 00000000..eb54a4d5
--- /dev/null
+++ b/scripts/native-update-status.mjs
@@ -0,0 +1,30 @@
+// Read the public desktop bridge through the fixture's loopback main debugger.
+// No renderer/account state is changed; this is used only to diagnose a failure.
+export const readNativeUpdateStatus = async (endpoint) => {
+ if (!endpoint) return null;
+ const socket = new WebSocket(endpoint);
+ try {
+ await new Promise((resolve, reject) => {
+ const timer = setTimeout(() => reject(new Error("Fixture debugger connection timed out")), 5_000);
+ socket.addEventListener("open", () => { clearTimeout(timer); resolve(); }, { once: true });
+ socket.addEventListener("error", () => { clearTimeout(timer); reject(new Error("Fixture debugger unavailable")); }, { once: true });
+ });
+ const result = await new Promise((resolve, reject) => {
+ const timer = setTimeout(() => reject(new Error("Fixture status query timed out")), 5_000);
+ socket.addEventListener("message", ({ data }) => {
+ const response = JSON.parse(String(data));
+ if (response.id !== 1) return;
+ clearTimeout(timer);
+ resolve(response.result?.result?.value ?? response.error ?? response.result?.exceptionDetails);
+ });
+ socket.send(JSON.stringify({ id: 1, method: "Runtime.evaluate", params: { awaitPromise: true, returnByValue: true,
+ expression: `(async () => {
+ const req = process.getBuiltinModule('module').createRequire(process.resourcesPath + '/app.asar/package.json');
+ const window = req('electron').BrowserWindow.getAllWindows().find(value => value.webContents.getURL().startsWith('edgeever-app://app/'));
+ return window ? await window.webContents.executeJavaScript('window.edgeeverDesktop.updateStatus()') : {error: 'fixture window unavailable'};
+ })()`,
+ } }));
+ });
+ return result;
+ } finally { socket.close(); }
+};
diff --git a/scripts/verify-native-desktop-update.mjs b/scripts/verify-native-desktop-update.mjs
index e0fb4ed3..74eaa029 100644
--- a/scripts/verify-native-desktop-update.mjs
+++ b/scripts/verify-native-desktop-update.mjs
@@ -1,3 +1,4 @@
+import { readNativeUpdateStatus } from "./native-update-status.mjs";
import { macAppBundle, macAppExecutable } from "./native-update-macos.mjs";
import { windowsUpdateInstallerRunning, stopWindowsUpdateFixtures } from "./native-update-windows.mjs";
import { createServer } from "node:http";
@@ -17,6 +18,7 @@ const evidence = join(root, "evidence");
mkdirSync(evidence, { recursive: true });
const report = { platform: process.platform, arch: process.arch, sourceSha: process.env.GITHUB_SHA, versions,
instrumentation: "Full EdgeEver builds with isolated app identity, local feed, command harness and ephemeral Windows trust key; production update controller and native installers are unchanged.",
+ fixtureRun: process.env.FIXTURE_RUN || null,
scenarios: [] };
let feedVersion = intermediateVersion;
let corruptSignature = false;
@@ -105,7 +107,13 @@ const stopFixture = async (events) => {
// Only PIDs written by the isolated test app are eligible for termination.
for (const entry of events.filter((value) => value.event === "boot")) {
if (process.platform === "win32") spawnSync("taskkill", ["/PID", String(entry.pid), "/T", "/F"], { stdio: "ignore" });
- else { try { process.kill(entry.pid, "SIGTERM"); } catch {} }
+ else {
+ const current = spawnSync("ps", ["-p", String(entry.pid), "-o", "command="], { encoding: "utf8" });
+ if (current.stdout?.trim().startsWith(entry.executable)) {
+ spawnSync("pkill", ["-KILL", "-P", String(entry.pid)], { stdio: "ignore" });
+ try { process.kill(entry.pid, "SIGKILL"); } catch {}
+ }
+ }
}
};
@@ -131,12 +139,16 @@ try {
EDGE_EVER_UPDATE_VERIFIER_PUBLIC_KEY: join(root, "public-key.pem"),
}));
const executable = await installBaseline(directory);
+ let debuggerEndpoint;
const launch = () => {
if (!existsSync(executable)) throw new Error(`Installed fixture executable missing: ${executable}`);
- const child = spawn(executable, [], { env, stdio: ["ignore", "pipe", "pipe"] });
+ const child = spawn(executable, ["--inspect=127.0.0.1:0"], { env, stdio: ["ignore", "pipe", "pipe"] });
child.on("error", (error) => appendFileSync(join(directory, "process.log"), `${error.stack}\n`));
child.stdout.on("data", (data) => appendFileSync(join(directory, "process.log"), data));
- child.stderr.on("data", (data) => appendFileSync(join(directory, "process.log"), data));
+ child.stderr.on("data", (data) => {
+ appendFileSync(join(directory, "process.log"), data);
+ debuggerEndpoint ||= /Debugger listening on (ws:\/\/[^\s]+)/.exec(String(data))?.[1];
+ });
children.push(child);
return child;
};
@@ -190,7 +202,12 @@ try {
// Confirm the installed executable itself now contains the new version.
launch();
} else {
- await command("install");
+ const installation = await command("install");
+ if (installation.status?.state === "idle" || installation.event === "command-error") {
+ const status = await readNativeUpdateStatus(debuggerEndpoint).catch((error) => ({ error: error.message }));
+ writeFileSync(join(directory, "native-status.json"), JSON.stringify(status, null, 2));
+ throw new Error(`Native installation failed: ${JSON.stringify(status)}`);
+ }
}
await until(() => events().some((entry) => entry.event === "boot" && entry.version === latestVersion), "latest installed application launches", 240_000);
await until(() => {
@@ -229,7 +246,7 @@ try {
writeFileSync(join(evidence, "requests.json"), JSON.stringify(requests, null, 2));
writeFileSync(join(evidence, "result.json"), JSON.stringify(report, null, 2));
console.log(JSON.stringify(report, null, 2));
- for (const child of children) { if (child.exitCode === null) child.kill("SIGTERM"); }
+ for (const child of children) { if (child.exitCode === null) child.kill("SIGKILL"); }
server.closeAllConnections();
server.close();
// Keep logs; remove installed fixture apps and anonymous databases from artifacts.
diff --git a/scripts/verify-native-release-bridge.mjs b/scripts/verify-native-release-bridge.mjs
index 2657e809..e05d26c8 100644
--- a/scripts/verify-native-release-bridge.mjs
+++ b/scripts/verify-native-release-bridge.mjs
@@ -1,6 +1,5 @@
import { windowsUpdateInstallerRunning } from "./native-update-windows.mjs";
import { createServer } from "node:http";
-import { createServer as createTcpServer } from "node:net";
import { spawn, spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, createReadStream, statSync, renameSync } from "node:fs";
@@ -14,6 +13,8 @@ const evidence = join(root, "evidence");
const installed = join(root, "installed");
const profile = join(root, "profile");
for (const path of [evidence, installed, profile]) mkdirSync(path, { recursive: true });
+// Acknowledge only the isolated installation's first-run confirmation.
+writeFileSync(join(profile, "installation-confirmed"), new Date().toISOString());
const candidateName = readdirSync(candidate).find((name) => process.platform === "darwin" ? name.endsWith(".zip") : name.endsWith(".exe"));
const version = /EdgeEver-(\d+\.\d+\.\d+)-/.exec(candidateName)?.[1];
if (!version) throw new Error("Candidate installer version missing");
@@ -67,29 +68,23 @@ await new Promise((yes) => server.listen(0, "127.0.0.1", yes));
const feed = `http://127.0.0.1:${server.address().port}/`;
const children = [];
const launch = async (update) => {
- const portServer = createTcpServer();
- await new Promise((yes) => portServer.listen(0, "127.0.0.1", yes));
- const port = portServer.address().port;
- await new Promise((yes) => portServer.close(yes));
- const child = spawn(executable, [`--inspect-brk=127.0.0.1:${port}`, `--user-data-dir=${profile}`], {
+ let endpoint;
+ const child = spawn(executable, ["--inspect=127.0.0.1:0", `--user-data-dir=${profile}`], {
env: { ...process.env, EDGE_EVER_DISABLE_AUTO_UPDATE: update ? "0" : "1" }, stdio: ["ignore", "pipe", "pipe"],
});
children.push(child);
for (const stream of [child.stdout, child.stderr]) stream.on("data", (chunk) => {
const path = join(evidence, update ? "old-process.log" : "new-process.log");
writeFileSync(path, chunk, { flag: "a" });
+ endpoint ||= /Debugger listening on (ws:\/\/[^\s]+)/.exec(String(chunk))?.[1];
});
- const endpoint = await until(async () => {
- try { return (await (await fetch(`http://127.0.0.1:${port}/json/list`)).json())[0]?.webSocketDebuggerUrl; } catch { return null; }
- }, "isolated loopback main-process debugger");
+ await until(() => endpoint, "isolated loopback main-process debugger");
const socket = new WebSocket(endpoint);
await new Promise((yes, no) => { socket.addEventListener("open", yes, { once: true }); socket.addEventListener("error", no, { once: true }); });
let serial = 0;
const pending = new Map();
- let paused = false;
socket.addEventListener("message", ({ data }) => {
const message = JSON.parse(String(data));
- if (message.method === "Debugger.paused") paused = true;
if (message.id && pending.has(message.id)) { const callbacks = pending.get(message.id); pending.delete(message.id); if (message.error) callbacks.reject(new Error(JSON.stringify(message.error))); else callbacks.resolve(message.result); }
});
const send = (method, params = {}) => new Promise((resolveCall, reject) => {
@@ -102,10 +97,6 @@ const launch = async (update) => {
socket.send(JSON.stringify({ id, method, params }));
});
console.log(`Configuring ${update ? "old" : "updated"} application through its isolated debugger`);
- await send("Runtime.enable");
- await send("Debugger.enable");
- await send("Runtime.runIfWaitingForDebugger");
- await until(() => paused, "main process pauses before startup");
const expression = `(() => {
const req = process.getBuiltinModule('module').createRequire(process.resourcesPath + '/app.asar/package.json');
const { app, net, dialog } = req('electron');
@@ -117,7 +108,7 @@ const launch = async (update) => {
req('node:fs').appendFileSync(${JSON.stringify(join(evidence, update ? "old-renderer.jsonl" : "new-renderer.jsonl"))}, JSON.stringify({message}) + '\\n');
});
});
- app.setPath('userData', ${JSON.stringify(profile)});
+ const configure = () => {
req('node:fs').writeFileSync(${JSON.stringify(join(evidence, update ? "old-version.json" : "new-version.json"))}, JSON.stringify({version: app.getVersion(), executable: process.execPath}));
if (${JSON.stringify(update)}) {
const { autoUpdater } = req('electron-updater');
@@ -136,13 +127,14 @@ const launch = async (update) => {
return {response: options.buttons?.some(button => /restart|重启/i.test(button)) ? 0 : 1, checkboxChecked:false};
};
}
+ };
+ if (app.isReady()) configure(); else app.once('ready', configure);
return true;
})()`;
console.log("Applying feed selection and dialog automation; package bytes and trust remain unchanged");
const evaluated = await send("Runtime.evaluate", { expression, returnByValue: true });
if (evaluated.exceptionDetails) throw new Error(JSON.stringify(evaluated.exceptionDetails));
- await send("Debugger.resume");
- console.log("Application startup resumed");
+ console.log("Application startup continues without a debugger pause");
socket.close(); // Node must not wait for an attached debugger during quit.
return child;
};