Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(desktop): grant this computer again once the server reports ready

Hung Dao845a68d2841c
diff --git a/electron/local-computer-grant.node-test.mjs b/electron/local-computer-grant.node-test.mjs
index d0bb4a8f18..734b5be8d4 100644
--- a/electron/local-computer-grant.node-test.mjs
+++ b/electron/local-computer-grant.node-test.mjs
@@ -1,5 +1,6 @@
import assert from "node:assert/strict";
import test from "node:test";
+import { readFileSync } from "node:fs";
import { createLocalComputerGrant, LOCAL_COMPUTER_GRANT, localComputerGrantMessage } from "./local-computer-grant.mjs";
@@ -44,3 +45,24 @@ test("a missing or odd record is sent as no connection, and a failed send is onl
grant.changed();
assert.equal(lines.length, 2);
});
+
+test("a server whose listener comes after spawn still gets the grant once the app sends it again at ready", () => {
+ const grant = createLocalComputerGrant({ connection: () => READY });
+ let listening = false;
+ const heard = [];
+ const late = { postMessage: (message) => { if (listening) heard.push(message); } };
+ grant.attach(late, () => true);
+ assert.deepEqual(heard, [], "the spawn-time post is lost while the server bundle is still loading");
+ listening = true;
+ grant.attach(late, () => true);
+ assert.deepEqual(heard, [{ type: LOCAL_COMPUTER_GRANT, connection: READY }]);
+});
+
+test("the app grants this computer again when its server reports ready, on every start path", () => {
+ const main = readFileSync(new URL("./main.mjs", import.meta.url), "utf8");
+ const start = main.indexOf("async function startServerOn(");
+ const ready = main.indexOf('if (identity.outcome === "ready" && serverSupervisor.isCurrent(proc)) {', start);
+ assert.ok(start >= 0 && ready > start, "startServerOn checks the server's ready identity");
+ const block = main.slice(ready, main.indexOf("return { proc };", ready));
+ assert.match(block, /grantLocalComputer\(proc, /);
+});
diff --git a/electron/main.mjs b/electron/main.mjs
index e125c4bc02..c7e45be103 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -1172,11 +1172,11 @@ async function startServerOn(port, dataDir = runningDataDir ?? startupEnvironmen
listeningGraceMs: SERVER_LISTENING_GRACE_MS,
});
// The spawn-time post races the server child's listener registration (the child attaches its
- // private-message listener only after its module has finished loading). Re-post the capability
- // once the server reports ready; applying it is idempotent, and a token is required before the
- // desktop window can sign in locally.
+ // private-message listener only after its module has finished loading). Re-post the capabilities
+ // once the server reports ready; applying them is idempotent, a token is required before the
+ // desktop window can sign in locally, and without the grant "This computer" refuses every bot.
if (identity.outcome === "ready" && serverSupervisor.isCurrent(proc)) {
- syncDesktopMutationToken(proc);
+ syncDesktopMutationToken(proc); grantLocalComputer(proc, (child) => serverSupervisor.isCurrent(child));
return { proc };
}
slog(bootFailureMessage(port, identity));