Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
test(preload): the bridge keeps every function a page of the last two releases calls (#4059)
Milind Soni9acd9ab7cee4
diff --git a/electron/bridge-contract.json b/electron/bridge-contract.jsonnew file mode 100644index 0000000000..ea477495de--- /dev/null+++ b/electron/bridge-contract.json@@ -0,0 +1,282 @@+{+ "releases": [+ "0.1.135",+ "0.1.136"+ ],+ "paths": [+ "androidDevice",+ "androidDevice.frame",+ "androidDevice.input",+ "androidDevice.status",+ "app",+ "app.ownPage",+ "app.version",+ "applySkin",+ "approvals",+ "approvals.setMode",+ "beginScreenPreviewIntent",+ "callActive",+ "cloudAccount",+ "cloudAccount.begin",+ "cloudAccount.cancel",+ "cloudAccount.cancelPlan",+ "cloudAccount.checkout",+ "cloudAccount.connectHome",+ "cloudAccount.connectHomeForPhone",+ "cloudAccount.copyCheckoutLink",+ "cloudAccount.files",+ "cloudAccount.interest",+ "cloudAccount.keepPlan",+ "cloudAccount.look",+ "cloudAccount.offer",+ "cloudAccount.onState",+ "cloudAccount.openDashboard",+ "cloudAccount.openTeam",+ "cloudAccount.readySeen",+ "cloudAccount.refresh",+ "cloudAccount.reopen",+ "cloudAccount.reopenCheckout",+ "cloudAccount.setLook",+ "cloudAccount.sheet",+ "cloudAccount.signInAgain",+ "cloudAccount.signInCancel",+ "cloudAccount.signInStart",+ "cloudAccount.signInVerify",+ "cloudAccount.signOut",+ "cloudAccount.state",+ "cloudAdd",+ "cloudAdd.copyLink",+ "cloudAdd.interest",+ "cloudAdd.open",+ "cloudAdd.organization",+ "cloudAdd.reopen",+ "cloudAdd.sheet",+ "cloudAdd.start",+ "cloudAdd.state",+ "cloudPlan",+ "cloudPlan.cancel",+ "cloudPlan.keep",+ "cloudPlan.manage",+ "cloudPlan.noticeSeen",+ "cloudPlan.restartNow",+ "cloudPlan.roomNotNow",+ "cloudPlan.signIn",+ "cloudPlan.state",+ "cloudPlan.upgrade",+ "cloudPlan.upgradePreview",+ "cloudSendPage",+ "cloudSendPage.dismiss",+ "cloudSendPage.keepHere",+ "cloudSendPage.moveRetry",+ "cloudSendPage.moveToTeam",+ "cloudSendPage.notice",+ "cloudSendPage.onNotice",+ "cloudSendPage.openTeam",+ "cloudSendPage.setKeepHere",+ "cloudSendPage.teamRetry",+ "cloudSendPage.teams",+ "companion",+ "companion.browserControl",+ "companion.cloudDesktop",+ "companion.keepAwake",+ "companion.pairing",+ "companion.refreshTailscale",+ "companion.revoke",+ "companion.start",+ "companion.state",+ "companion.stop",+ "companionAccount",+ "companionAccount.prepare",+ "companionAccount.requestCode",+ "companionAccount.retry",+ "companionAccount.signOut",+ "companionAccount.state",+ "companionAccount.verifyCode",+ "companyBackups",+ "companyBackups.cancel",+ "companyBackups.configureSchedule",+ "companyBackups.create",+ "companyBackups.delete",+ "companyBackups.list",+ "companyBackups.onState",+ "companyBackups.prepareRestore",+ "companyBackups.restore",+ "companyBackups.state",+ "computerSharing",+ "computerSharing.activity",+ "computerSharing.chooseFolder",+ "computerSharing.revoke",+ "computerSharing.save",+ "computerSharing.state",+ "confirm",+ "copyText",+ "desktopAnalytics",+ "desktopAnalytics.enabled",+ "desktopAnalytics.set",+ "desktopLanguage",+ "desktopLanguage.choice",+ "desktopLanguage.onChange",+ "desktopLanguage.set",+ "desktopNotices",+ "desktopNotices.seen",+ "desktopNotices.shown",+ "desktopNotices.state",+ "desktopProfile",+ "desktopProfile.systemName",+ "desktopViewer",+ "desktopViewer.close",+ "desktopViewer.currentState",+ "desktopViewer.onState",+ "desktopViewer.open",+ "desktopWorkspace",+ "desktopWorkspace.close",+ "desktopWorkspace.layout",+ "desktopWorkspace.onState",+ "desktopWorkspace.open",+ "desktopWorkspace.setInteractive",+ "environments",+ "environments.addFromLink",+ "environments.create",+ "environments.forget",+ "environments.onOpenSettings",+ "environments.pickDir",+ "environments.state",+ "environments.switch",+ "exportDiagnostics",+ "getCapabilities",+ "getPathForFile",+ "home",+ "home.onState",+ "home.remove",+ "home.repair",+ "home.retry",+ "home.signIn",+ "home.state",+ "home.updating",+ "localControl",+ "localControl.disable",+ "localControl.enable",+ "localControl.retry",+ "localControl.status",+ "onCapabilitiesChanged",+ "onChatLink",+ "onOpenAppSettings",+ "onPackageInstall",+ "onSpeechEnd",+ "onSpeechTranscript",+ "openAtLogin",+ "openAtLogin.set",+ "openAtLogin.state",+ "openExternal",+ "openInstallTerminal",+ "openLogsFolder",+ "organization",+ "organization.begin",+ "organization.cancelEnrollment",+ "organization.disconnect",+ "organization.onState",+ "organization.refresh",+ "organization.reopen",+ "organization.settingsOpened",+ "organization.state",+ "permOpenSettings",+ "permRequestMic",+ "permStatus",+ "pickFolder",+ "platform",+ "rail",+ "rail.drawsFrame",+ "rail.expand",+ "rail.onFramed",+ "rail.onSkin",+ "rail.onState",+ "rail.setHidden",+ "rail.state",+ "relaunch",+ "remoteClient",+ "remoteClient.active",+ "remoteClient.disconnect",+ "remoteClient.pair",+ "remoteClient.state",+ "revealInFolder",+ "routines",+ "routines.keepAwake",+ "routines.wakeState",+ "saveFile",+ "screenFrame",+ "setCredential",+ "setUnreadCount",+ "speechFinish",+ "speechStart",+ "speechStop",+ "talkShortcut",+ "talkShortcut.set",+ "talkShortcut.state",+ "twoPlaces",+ "twoPlaces.accept",+ "twoPlaces.dismiss",+ "twoPlaces.onChanged",+ "twoPlaces.state",+ "updater",+ "updater.check",+ "updater.install",+ "updater.onState",+ "updater.seen",+ "updatesConsent",+ "updatesConsent.choose",+ "updatesConsent.state",+ "windowControls",+ "windowControls.close",+ "windowControls.minimize",+ "windowControls.onMaximizedChanged",+ "windowControls.state",+ "windowControls.toggleMaximize",+ "windowFrame",+ "windowFrame.set",+ "windowFrame.state",+ "workspaces",+ "workspaces.add",+ "workspaces.color",+ "workspaces.line",+ "workspaces.look",+ "workspaces.makeHome",+ "workspaces.menu",+ "workspaces.onChanged",+ "workspaces.open",+ "workspaces.places",+ "workspaces.recolor",+ "workspaces.remove",+ "workspaces.state"+ ],+ "remoteSafe": [+ "app",+ "applySkin",+ "cloudAdd",+ "cloudPlan",+ "cloudSendPage",+ "desktopAnalytics",+ "desktopLanguage",+ "desktopNotices",+ "getCapabilities",+ "onCapabilitiesChanged",+ "onOpenAppSettings",+ "permStatus",+ "platform",+ "rail",+ "setUnreadCount",+ "updatesConsent",+ "windowControls",+ "windowFrame",+ "workspaces"+ ],+ "homePage": [+ "callActive",+ "exportDiagnostics",+ "home",+ "onChatLink",+ "onOpenAppSettings",+ "onPackageInstall",+ "openAtLogin",+ "openLogsFolder"+ ]+}diff --git a/electron/preload-contract.node-test.mjs b/electron/preload-contract.node-test.mjsnew file mode 100644index 0000000000..14ea8811de--- /dev/null+++ b/electron/preload-contract.node-test.mjs@@ -0,0 +1,40 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import { createRequire } from "node:module";+import test from "node:test";++// Node tests run without Electron: satisfy preload's require("electron") from the require cache; the real preload still runs.+const require = createRequire(import.meta.url);+// The company desktop's keys are part of the bridge too: the test looks at the whole of it.+process.argv.push("--omb-company-desktop=1");+const exposed = { api: null };+const fakeElectron = {+ ipcRenderer: { on: () => undefined, removeListener: () => undefined, invoke: async () => undefined, send: () => undefined },+ contextBridge: { exposeInMainWorld: (_name, api) => { exposed.api = api; } },+ webUtils: { getPathForFile: () => "" },+};+const electronEntry = require.resolve("electron");+require.cache[electronEntry] = { id: electronEntry, filename: electronEntry, loaded: true, exports: fakeElectron };+require("./preload.cjs");++const contract = JSON.parse(readFileSync(new URL("./bridge-contract.json", import.meta.url), "utf8"));+const source = readFileSync(new URL("./preload.cjs", import.meta.url), "utf8");+const listed = (name) => {+ const match = new RegExp(`const ${name} = (?:new Set\\()?\\[([^\\]]*)\\]`).exec(source);+ return match ? [...match[1].matchAll(/"([^"]+)"/g)].map((found) => found[1]) : [];+};+const KEEP = `A Cloud or server page on ${contract.releases.join(" or ")} still calls it once this desktop updates ahead of that Cloud. `+ + "Keep it, as a stub if need be, for two releases after the last page that calls it; only then take it out of electron/bridge-contract.json.";++test("the bridge keeps every function a page of the last two releases calls", () => {+ for (const path of contract.paths) {+ const value = path.split(".").reduce((at, key) => at?.[key], exposed.api);+ assert.notEqual(value, undefined, `window.ogb.${path} is gone. ${KEEP}`);+ }+});++test("a Cloud or server page keeps the bridge keys it had, and the home page its own", () => {+ const remote = new Set(listed("REMOTE_SAFE")), home = new Set([...remote, ...listed("HOME_PAGE")]);+ for (const key of contract.remoteSafe) assert.ok(remote.has(key), `${key} left REMOTE_SAFE. ${KEEP}`);+ for (const key of contract.homePage) assert.ok(home.has(key), `${key} left the home page's bridge. ${KEEP}`);+});