AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
test(desktop): exercise real cross-version native updates (#776)
tianma-ifdcac4950f451
diff --git a/.github/workflows/desktop-update-verification.yml b/.github/workflows/desktop-update-verification.ymlnew file mode 100644index 00000000..87310dc9--- /dev/null+++ b/.github/workflows/desktop-update-verification.yml@@ -0,0 +1,109 @@+name: Verify native desktop updates++on:+ workflow_dispatch:++permissions:+ contents: read++jobs:+ native-update:+ if: github.repository == 'tianma-if/edgeever'+ name: Native update ${{ matrix.platform }} ${{ matrix.arch }}+ runs-on: ${{ matrix.runner }}+ timeout-minutes: 60+ strategy:+ fail-fast: false+ matrix:+ include:+ - platform: macOS+ runner: macos-15+ arch: arm64+ - platform: macOS+ runner: macos-15-intel+ arch: x64+ - platform: Windows+ runner: windows-latest+ arch: x64+ - platform: Linux+ runner: ubuntu-22.04+ arch: x64+ steps:+ - uses: actions/checkout@v5+ - uses: oven-sh/setup-bun@v2+ - uses: dtolnay/rust-toolchain@stable++ - name: Cache Rust dependencies+ uses: actions/cache@v5+ with:+ path: |+ ~/.cargo/registry+ ~/.cargo/git+ crates/desktop-sidecar/target+ key: ${{ runner.os }}-${{ matrix.arch }}-rust-${{ hashFiles('crates/desktop-sidecar/Cargo.lock', 'crates/desktop-sidecar/**/*.rs') }}+ restore-keys: |+ ${{ runner.os }}-${{ matrix.arch }}-rust-++ - name: Install Linux runtime dependencies+ if: runner.os == 'Linux'+ run: |+ sudo apt-get update+ sudo apt-get install --yes libfuse2 xvfb++ - name: Import macOS signing identity+ if: runner.os == 'macOS'+ env:+ MAC_CERTIFICATE_DER_BASE64: ${{ secrets.EDGEEVER_MAC_CERTIFICATE_DER_BASE64 }}+ MAC_PRIVATE_KEY_BASE64: ${{ secrets.EDGEEVER_MAC_PRIVATE_KEY_BASE64 }}+ run: |+ test -n "$MAC_CERTIFICATE_DER_BASE64"+ test -n "$MAC_PRIVATE_KEY_BASE64"+ keychain_path="$RUNNER_TEMP/edgeever-update-verification.keychain-db"+ keychain_password="$(openssl rand -hex 32)"+ certificate_path="$RUNNER_TEMP/update-signing.cer"+ private_key_path="$RUNNER_TEMP/update-signing.pem"+ traditional_key_path="$RUNNER_TEMP/update-signing-rsa.pem"+ printf '%s' "$MAC_CERTIFICATE_DER_BASE64" | base64 -D > "$certificate_path"+ printf '%s' "$MAC_PRIVATE_KEY_BASE64" | base64 -D > "$private_key_path"+ openssl rsa -in "$private_key_path" -out "$traditional_key_path"+ security create-keychain -p "$keychain_password" "$keychain_path"+ security set-keychain-settings -lut 21600 "$keychain_path"+ security unlock-keychain -p "$keychain_password" "$keychain_path"+ security import "$certificate_path" -k "$keychain_path" -f x509 -t cert -T /usr/bin/codesign+ security import "$traditional_key_path" -k "$keychain_path" -f openssl -t priv -P '' -T /usr/bin/codesign+ security set-key-partition-list -S apple-tool:,apple: -s -k "$keychain_password" "$keychain_path"+ security list-keychains -d user -s "$keychain_path" "$HOME/Library/Keychains/login.keychain-db"+ echo "CSC_KEYCHAIN=$keychain_path" >> "$GITHUB_ENV"+ echo "CSC_IDENTITY_AUTO_DISCOVERY=true" >> "$GITHUB_ENV"++ - name: Install dependencies+ run: bun install --frozen-lockfile++ - name: Build renderer and sidecar+ env:+ EDGE_EVER_DESKTOP_BUILD: '1'+ run: |+ bun run build:web+ cargo build --manifest-path crates/desktop-sidecar/Cargo.toml --release++ - name: Build three isolated instrumented EdgeEver installers+ env:+ EDGE_EVER_DESKTOP_ARCH: ${{ matrix.arch }}+ run: node scripts/build-native-update-fixtures.mjs++ - name: Exercise real native updates+ if: runner.os != 'Linux'+ run: node scripts/verify-native-desktop-update.mjs "${{ runner.temp }}/edgeever-update-verification"++ - name: Exercise real AppImage updates+ if: runner.os == 'Linux'+ run: xvfb-run -a node scripts/verify-native-desktop-update.mjs "$RUNNER_TEMP/edgeever-update-verification"++ - name: Save installation evidence+ if: always()+ uses: actions/upload-artifact@v6+ with:+ name: native-update-evidence-${{ matrix.platform }}-${{ matrix.arch }}+ path: ${{ runner.temp }}/edgeever-update-verification/evidence+ if-no-files-found: warn+ retention-days: 14diff --git a/scripts/build-native-update-fixtures.mjs b/scripts/build-native-update-fixtures.mjsnew file mode 100644index 00000000..28a201f2--- /dev/null+++ b/scripts/build-native-update-fixtures.mjs@@ -0,0 +1,73 @@+import { createRequire } from "node:module";+import { generateKeyPairSync } from "node:crypto";+import { readFileSync, writeFileSync, mkdirSync, copyFileSync, rmSync } from "node:fs";+import { join, resolve } from "node:path";+import { spawnSync } from "node:child_process";+import { createWindowsUpdateMetadata } from "./create-windows-update-metadata.mjs";+import { signWindowsUpdateManifest } from "./sign-windows-update-manifest.mjs";+import { instrumentNativeUpdateMain } from "./native-update-instrumentation.mjs";++if (process.env.GITHUB_ACTIONS !== "true" || process.env.GITHUB_REPOSITORY !== "tianma-if/edgeever") {+ throw new Error("Instrumented update builds run only on the official repository's disposable CI runners");+}+const root = process.cwd();+const output = resolve(process.argv[2] || join(process.env.RUNNER_TEMP, "edgeever-update-verification"));+mkdirSync(output, { recursive: true });+const desktop = join(root, "apps/desktop");+const packagePath = join(desktop, "package.json");+const mainPath = join(desktop, "src/main/index.mjs");+const controlPath = join(desktop, "src/main/native-update-verifier.mjs");+const configPath = join(desktop, "build/update-verification.json");+const originalMain = readFileSync(mainPath, "utf8");+const originalPackage = readFileSync(packagePath, "utf8");+const [major, minor, patch] = JSON.parse(originalPackage).version.split(".").map(Number);+const versions = [1, 2, 3].map((step) => `${major}.${minor}.${patch + step}`);+const { privateKey, publicKey } = generateKeyPairSync("ed25519");+const publicKeyPem = publicKey.export({ type: "spki", format: "pem" });+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 require = createRequire(join(desktop, "package.json"));+const builderCli = require.resolve("electron-builder/out/cli/cli.js");+const run = (command, args) => {+ const result = spawnSync(command, args, { cwd: root, env: process.env, stdio: "inherit" });+ if (result.error) throw result.error;+ if (result.status !== 0) throw new Error(`${command} exited with ${result.status}`);+};+try {+ writeFileSync(mainPath, instrumented);+ copyFileSync("scripts/fixtures/native-update/control.mjs", controlPath);+ mkdirSync(join(desktop, "build"), { recursive: true });+ if (process.platform === "darwin") run("bash", ["scripts/build-macos-share-extension.sh"]);+ for (const version of versions) {+ const metadata = { ...JSON.parse(originalPackage), name: "edgeever-update-verifier", version };+ writeFileSync(packagePath, JSON.stringify(metadata, null, 2));+ const directory = join(output, version);+ const config = {+ extends: "./electron-builder.yml", appId: "org.edgeever.update-verifier",+ productName: "EdgeEver Update Verification", executableName: "EdgeEverUpdateVerifier",+ directories: { output: directory },+ mac: { notarize: false },+ // Keep the test installer isolated from production protocol associations.+ protocols: [], fileAssociations: [], nsis: { include: null },+ };+ writeFileSync(configPath, JSON.stringify(config));+ const target = process.platform === "darwin" ? ["--mac", "zip"] : process.platform === "win32" ? ["--win", "nsis"] : ["--linux", "AppImage"];+ run(process.execPath, [builderCli, "--projectDir", desktop, "--config", configPath, "--publish", "never", ...target, `--${process.arch}`]);+ if (process.platform === "win32") {+ await createWindowsUpdateMetadata({ directory, version });+ signWindowsUpdateManifest({+ manifestPath: join(directory, "latest-windows.json"), signaturePath: join(directory, "latest-windows.json.sig"),+ privateKeyPath: keyPath, expectedPublicKey: publicKeyPem,+ });+ }+ }+} finally {+ writeFileSync(mainPath, originalMain);+ writeFileSync(packagePath, originalPackage);+ rmSync(controlPath, { force: true });+ rmSync(configPath, { force: true });+ rmSync(keyPath, { force: true });+}diff --git a/scripts/fixtures/native-update/control.mjs b/scripts/fixtures/native-update/control.mjsnew file mode 100644index 00000000..f2a745ae--- /dev/null+++ b/scripts/fixtures/native-update/control.mjs@@ -0,0 +1,50 @@+// Copied into instrumented CI builds only. Never included in release source.+import { appendFileSync, existsSync, readFileSync, unlinkSync } from "node:fs";+import { verifyWindowsUpdateMetadata, WINDOWS_UPDATE_KEY_ID } from "./windows-update-trust.mjs";++export const verifierLog = (event, details = {}) => {+ appendFileSync(process.env.EDGE_EVER_UPDATE_VERIFIER_LOG, `${JSON.stringify({ at: new Date().toISOString(), event, ...details })}\n`);+};+export const verifierWindowsMetadata = async ({ version, updateInfo }) => {+ const base = `${process.env.EDGE_EVER_UPDATE_VERIFIER_FEED}/release/${version}/`;+ const [manifest, signature] = await Promise.all([+ fetch(`${base}latest-windows.json`), fetch(`${base}latest-windows.json.sig`),+ ]);+ if (!manifest.ok || !signature.ok) throw new Error("Verification metadata request failed");+ return verifyWindowsUpdateMetadata({+ manifestBytes: Buffer.from(await manifest.arrayBuffer()),+ signatureBytes: Buffer.from(await signature.arrayBuffer()),+ expectedVersion: version, updateInfo,+ trustedPublicKeys: { [WINDOWS_UPDATE_KEY_ID]: readFileSync(process.env.EDGE_EVER_UPDATE_VERIFIER_PUBLIC_KEY, "utf8") },+ });+};+export const attachVerifier = ({ app, updater, controller }) => {+ verifierLog("boot", { version: app.getVersion(), executable: process.execPath, pid: process.pid });+ let busy = false;+ const path = process.env.EDGE_EVER_UPDATE_VERIFIER_COMMAND;+ const timer = setInterval(async () => {+ if (busy || !existsSync(path)) return;+ busy = true;+ let command;+ try {+ command = JSON.parse(readFileSync(path, "utf8"));+ unlinkSync(path);+ if (command.action === "check") {+ await controller.check("verification");+ if (controller.snapshot().state === "available") await controller.download("verification");+ } else if (command.action === "install") {+ await controller.install();+ } else if (command.action === "quit") {+ app.quit();+ } else if (command.action === "stop") {+ updater.autoInstallOnAppQuit = false;+ // Stop only this fixture and its children. No installed user app is used.+ app.exit(0);+ } else throw new Error("Unknown verifier command");+ verifierLog("command", { id: command.id, status: controller.snapshot() });+ } catch (error) {+ verifierLog("command-error", { id: command?.id, message: error.message, status: controller.snapshot() });+ } finally { busy = false; }+ }, 100);+ timer.unref();+};diff --git a/scripts/native-update-instrumentation.mjs b/scripts/native-update-instrumentation.mjsnew file mode 100644index 00000000..c8016efa--- /dev/null+++ b/scripts/native-update-instrumentation.mjs@@ -0,0 +1,15 @@+export const instrumentNativeUpdateMain = (originalMain) => {+ 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);+ };+ let instrumented = `import { verifierLog, verifierWindowsMetadata, attachVerifier } from "./native-update-verifier.mjs";\n${originalMain}`;+ instrumented = replace(instrumented, 'if (requestedUserDataDirectory) app.setPath("userData", requestedUserDataDirectory);', 'app.setPath("userData", process.env.EDGE_EVER_UPDATE_VERIFIER_PROFILE);');+ instrumented = replace(instrumented, ' desktopUpdateController = createDesktopUpdateController({', ` autoUpdater.setFeedURL({ provider: "generic", url: process.env.EDGE_EVER_UPDATE_VERIFIER_FEED + "/feed" });\n autoUpdater.disableDifferentialDownload = true;\n desktopUpdateController = createDesktopUpdateController({`);+ instrumented = replace(instrumented, 'fetchWindowsMetadata: (options) => fetchTrustedWindowsUpdate({ ...options, fetchImpl: net.fetch }),', 'fetchWindowsMetadata: verifierWindowsMetadata,');+ instrumented = replace(instrumented, ' onDownloaded: (version) => {', ' onDownloaded: (version) => {\n verifierLog("ready", { version, runningVersion: app.getVersion() });\n return;');+ 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.');+ return instrumented;+};diff --git a/scripts/native-update-instrumentation.test.mjs b/scripts/native-update-instrumentation.test.mjsnew file mode 100644index 00000000..2937c062--- /dev/null+++ b/scripts/native-update-instrumentation.test.mjs@@ -0,0 +1,39 @@+import { readFileSync, mkdtempSync, writeFileSync, rmSync } from "node:fs";+import { join } from "node:path";+import { tmpdir } from "node:os";+import { spawnSync } from "node:child_process";+import { expect, test } from "bun:test";+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 directory = mkdtempSync(join(tmpdir(), "edgeever-native-update-syntax-"));+ try {+ const path = join(directory, "index.mjs");+ writeFileSync(path, instrumented);+ const result = spawnSync("node", ["--check", path], { encoding: "utf8" });+ expect(result.status, result.stderr).toBe(0);+ expect(instrumented).toContain('createDesktopUpdateController({');+ expect(instrumented).toContain('verifierLog("ready", { version, runningVersion: app.getVersion() })');+ expect(instrumented).toContain('app.setPath("userData", process.env.EDGE_EVER_UPDATE_VERIFIER_PROFILE)');+ expect(instrumented).not.toContain('await confirmMacInstallation()');+ expect(main).not.toContain('native-update-verifier.mjs');+ } finally { rmSync(directory, { recursive: true, force: true }); }+});++test("fails closed if a product integration site moves or appears twice", () => {+ expect(() => instrumentNativeUpdateMain(main.replace(' onDownloaded: (version) => {', ' onDownloaded: async (version) => {'))).toThrow("exactly one");+ expect(() => instrumentNativeUpdateMain(main + '\n desktopUpdateController = createDesktopUpdateController({')).toThrow("exactly one");+});++test("the installer workflow is official-only, manual, and never publishes assets", () => {+ const workflow = readFileSync(new URL("../.github/workflows/desktop-update-verification.yml", import.meta.url), "utf8");+ expect(workflow).toContain("if: github.repository == 'tianma-if/edgeever'");+ expect(workflow).toContain("workflow_dispatch:");+ expect(workflow).not.toContain("contents: write");+ expect(workflow).not.toContain("release_tag");+ expect(workflow).toContain("runner: macos-15-intel");+ expect(workflow).toContain("runner: windows-latest");+ expect(workflow).toContain("runner: ubuntu-22.04");+});diff --git a/scripts/verify-native-desktop-update.mjs b/scripts/verify-native-desktop-update.mjsnew file mode 100644index 00000000..f261368c--- /dev/null+++ b/scripts/verify-native-desktop-update.mjs@@ -0,0 +1,201 @@+import { createServer } from "node:http";+import { createReadStream, existsSync, readFileSync, statSync, writeFileSync, mkdirSync, chmodSync, appendFileSync } from "node:fs";+import { cp, rm } from "node:fs/promises";+import { spawn, spawnSync } from "node:child_process";+import { join, resolve, basename, dirname } from "node:path";+import { createHash } from "node:crypto";++if (process.env.GITHUB_ACTIONS !== "true" || process.env.GITHUB_REPOSITORY !== "tianma-if/edgeever") {+ throw new Error("Native installer verification is restricted to the official disposable CI runners");+}+const root = resolve(process.argv[2]);+const versions = JSON.parse(readFileSync(join(root, "versions.json"), "utf8"));+const [oldVersion, intermediateVersion, latestVersion] = versions;+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.",+ scenarios: [] };+let feedVersion = intermediateVersion;+let corruptSignature = false;+let corruptPackage = false;+const requests = [];+const metadataName = process.platform === "darwin" ? "latest-mac.yml" : process.platform === "win32" ? "latest.yml" : "latest-linux.yml";+const packageName = (version) => process.platform === "darwin" ? `EdgeEver-${version}-mac-${process.arch}.zip`+ : process.platform === "win32" ? `EdgeEver-${version}-windows-x64.exe` : `EdgeEver-${version}-linux-x64.AppImage`;+const server = createServer((request, response) => {+ const pathname = new URL(request.url, "http://127.0.0.1").pathname;+ const parts = pathname.split("/").filter(Boolean);+ let version = feedVersion;+ let name;+ if (parts[0] === "feed" && parts.length === 2) name = parts[1];+ else if (parts[0] === "release" && parts.length === 3 && versions.includes(parts[1])) {+ version = parts[1]; name = parts[2];+ }+ if (!name || basename(name) !== name || ![metadataName, "latest-windows.json", "latest-windows.json.sig", packageName(version)].includes(name)) {+ response.writeHead(404).end(); return;+ }+ const path = join(root, version, name);+ if (!existsSync(path)) { response.writeHead(404).end(); return; }+ requests.push({ at: new Date().toISOString(), version, name });+ if (corruptSignature && name === "latest-windows.json.sig") {+ const signature = JSON.parse(readFileSync(path, "utf8"));+ signature.signature = Buffer.alloc(64).toString("base64");+ response.writeHead(200).end(JSON.stringify(signature)); return;+ }+ response.writeHead(200, { "Content-Length": statSync(path).size, "Content-Type": name.endsWith(".yml") ? "text/yaml" : "application/octet-stream" });+ if (corruptPackage && name === packageName(version)) {+ const bytes = readFileSync(path);+ bytes[bytes.length - 1] ^= 1;+ response.end(bytes); return;+ }+ createReadStream(path).pipe(response);+});+await new Promise((yes, no) => { server.once("error", no); server.listen(0, "127.0.0.1", yes); });+const feed = `http://127.0.0.1:${server.address().port}`;+let commandId = 0;+const children = [];+const readEvents = (path) => !existsSync(path) ? [] : readFileSync(path, "utf8").split(/\r?\n/).filter(Boolean).map((line) => JSON.parse(line));+const wait = (ms) => new Promise((yes) => setTimeout(yes, ms));+const until = async (predicate, description, timeout = 180_000) => {+ const deadline = Date.now() + timeout;+ while (Date.now() < deadline) {+ const value = predicate();+ if (value) return value;+ await wait(200);+ }+ throw new Error(`Timed out: ${description}`);+};+const installBaseline = async (directory) => {+ const installed = join(directory, "installed");+ mkdirSync(installed, { recursive: true });+ if (process.platform === "darwin") {+ const unpack = spawnSync("ditto", ["-x", "-k", join(root, oldVersion, packageName(oldVersion)), installed], { encoding: "utf8" });+ if (unpack.status !== 0) throw new Error(unpack.stderr);+ return join(installed, "EdgeEver Update Verification.app/Contents/MacOS/EdgeEverUpdateVerifier");+ }+ if (process.platform === "win32") {+ const installer = join(root, oldVersion, packageName(oldVersion));+ const result = spawnSync(installer, ["/S", `/D=${installed}`], { encoding: "utf8", windowsHide: true });+ if (result.status !== 0) throw new Error(`Baseline NSIS install failed: ${result.status} ${result.stderr}`);+ return join(installed, "EdgeEverUpdateVerifier.exe");+ }+ const appImage = join(installed, "EdgeEver.AppImage");+ await cp(join(root, oldVersion, packageName(oldVersion)), appImage);+ chmodSync(appImage, 0o755);+ return appImage;+};+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 {} }+ }+};++try {+ for (const scenario of ["install-latest", "quit-latest", "reject-corrupt-update"]) {+ const directory = join(evidence, scenario);+ mkdirSync(directory, { recursive: true });+ feedVersion = intermediateVersion;+ const eventsPath = join(directory, "events.jsonl");+ 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"),+ };+ const launch = () => {+ const child = spawn(executable, [], { 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));+ children.push(child);+ return child;+ };+ const events = () => readEvents(eventsPath);+ const command = async (action) => {+ const id = ++commandId;+ writeFileSync(commandPath, JSON.stringify({ id, action }));+ return until(() => events().find((entry) => entry.id === id), `command ${action}`);+ };+ try {+ launch();+ await until(() => events().some((entry) => entry.event === "ready" && entry.version === intermediateVersion), "intermediate package downloaded");+ feedVersion = latestVersion;+ if (scenario === "reject-corrupt-update") {+ if (process.platform === "win32") corruptSignature = true;+ else corruptPackage = true;+ const result = await command("check");+ const diagnostics = readEvents(join(profile, "logs/desktop.log"));+ if (!diagnostics.some((entry) => entry.event === "update.check-failed" || entry.event === "update.download-failed")) {+ throw new Error(`Corrupt metadata/package was not rejected: ${JSON.stringify(result)}`);+ }+ if (diagnostics.some((entry) => entry.event === "update.install-confirmed")) throw new Error("An invalid update triggered installation");+ corruptSignature = false;+ corruptPackage = false;+ await command("check");+ await until(() => events().some((entry) => entry.event === "ready" && entry.version === latestVersion), "valid replacement recovers after corruption");+ }+ if (scenario === "quit-latest") {+ await command("quit");+ await until(() => {+ const log = readEvents(join(profile, "logs/desktop.log"));+ return log.some((entry) => entry.event === "session.quit");+ }, "normal application shutdown");+ const digest = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");+ const expected = process.platform === "darwin"+ ? join(root, latestVersion, process.arch === "arm64" ? "mac-arm64" : "mac", "EdgeEver Update Verification.app/Contents/Resources/app.asar")+ : process.platform === "win32" ? join(root, latestVersion, "win-unpacked/resources/app.asar")+ : join(root, latestVersion, packageName(latestVersion));+ const installedPayload = process.platform === "darwin" ? join(dirname(executable), "../Resources/app.asar")+ : process.platform === "win32" ? join(dirname(executable), "resources/app.asar") : executable;+ const expectedDigest = digest(expected);+ await until(() => {+ try { return digest(installedPayload) === expectedDigest; } catch { return false; }+ }, "native installation replaces the actual installed payload", 240_000);+ await wait(1_000);+ if (events().filter((entry) => entry.event === "boot").length !== 1) throw new Error("Normal quit relaunched the application");+ // Confirm the installed executable itself now contains the new version.+ launch();+ } else {+ await command("install");+ }+ await until(() => events().some((entry) => entry.event === "boot" && entry.version === latestVersion), "latest installed application launches", 240_000);+ const diagnostics = readEvents(join(profile, "logs/desktop.log"));+ const installs = diagnostics.filter((entry) => entry.event === "update.install-confirmed");+ const boots = events().filter((entry) => entry.event === "boot").map((entry) => entry.version);+ if (boots.includes(intermediateVersion) || installs.length !== 1 || installs[0].version !== latestVersion) {+ throw new Error(`Unexpected installation sequence: ${JSON.stringify({ boots, installs })}`);+ }+ if (process.platform === "linux") {+ const digest = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");+ if (digest(executable) !== digest(join(root, latestVersion, packageName(latestVersion)))) throw new Error("Installed AppImage digest differs from the selected release");+ }+ report.scenarios.push({ scenario, ok: true, boots, installs, executable });+ writeFileSync(join(directory, "result.json"), JSON.stringify(report.scenarios.at(-1), null, 2));+ } finally {+ await stopFixture(events());+ await wait(1_000);+ }+ }+ report.ok = true;+} catch (error) {+ report.ok = false;+ report.error = error.stack;+ process.exitCode = 1;+} finally {+ 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"); }+ server.closeAllConnections();+ server.close();+ // Keep logs; remove installed fixture apps and anonymous databases from artifacts.+ for (const scenario of ["install-latest", "quit-latest", "reject-corrupt-update"]) {+ await rm(join(evidence, scenario, "installed"), { recursive: true, force: true }).catch(() => {});+ }+}