Skip to content

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

Desktop: removing the server that is home brings this computer's copy back

stph lc4bd86cd5fb2
diff --git a/electron/main.mjs b/electron/main.mjs
index 74d3a376a4..f6ff605f99 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -1904,6 +1904,7 @@ async function forgetEnvironment(id, purge = false, confirmed = false) {
}
}
persistEnvironments(withoutEnvironment(environmentsState, id));
+ if (env.kind !== "local") void ownHome?.kick().catch((error) => slog(`own home: ${error?.message ?? error}`));
if (wasActive) navigateMainWindow(activeOrigin());
if (!env.origin) return { ok: true };
try {
diff --git a/electron/own-home-main.mjs b/electron/own-home-main.mjs
index 29984e9805..e317962125 100644
--- a/electron/own-home-main.mjs
+++ b/electron/own-home-main.mjs
@@ -141,7 +141,7 @@ export function installOwnHome({ localRequest, fetch: fetchImpl, environments, h
const picked = chosen();
if (!picked) return null;
return { origin: picked.origin, account: `own:${picked.environmentId}`, machine: picked.origin, ready: true, moves: true, paid: false, name: picked.name,
- ended: !placeOf(picked) && !awayIn(parseJournal(journal.read())) };
+ ended: !placeOf(picked) };
};
const home = createOneHome({
journal,
diff --git a/electron/own-home-main.node-test.mjs b/electron/own-home-main.node-test.mjs
index 1569ad145b..04ecbf9b7d 100644
--- a/electron/own-home-main.node-test.mjs
+++ b/electron/own-home-main.node-test.mjs
@@ -223,3 +223,33 @@ test("after an own-home move is done, an app update does not send the old worksp
assert.deepEqual(files(), []);
second.close();
});
+
+test("once home is on a server that was then removed from the list, this computer's own copy opens again and the choice is let go", async () => {
+ const choice = memory({ v: 1, id: "g", origin: garage.origin, environmentId: ID, name: "Garage server", at: 1 });
+ const cloud = { origin: garage.origin, account: `own:${ID}`, machine: garage.origin, name: "Garage server" };
+ const journal = memory({ v: 1, phase: "done", cloud, doneAt: 1_000, version: "0.1.151", lent: true, told: true });
+ let frozen = true, saved = [garage];
+ const asked = [], lines = [];
+ const localRequest = async (route, init) => {
+ asked.push(`${init?.method ?? "GET"} ${route}`);
+ if (route === "/api/move/freeze" && init?.method === "DELETE") { frozen = false; return Response.json({ frozen: false }); }
+ if (route === "/api/move/freeze") return Response.json({ frozen });
+ return Response.json({ v: 1 });
+ };
+ const fetch = async (url) => { asked.push(`server ${new URL(url).pathname}`); return Response.json({ error: "forbidden" }, { status: 403 }); };
+ const own = installOwnHome({
+ localRequest, fetch, environments: () => saved, handoff: async () => ({}), journal, choice, sendState: memory(), cloudJournal: () => null,
+ version: "0.1.151", log: (line) => lines.push(line), now: () => 5_000_000,
+ });
+ await own.kick();
+ assert.equal(frozen, true, "a server still on the list keeps home, whether or not it answers");
+ assert.equal(own.origin(), garage.origin);
+ saved = [];
+ await own.kick();
+ assert.equal(frozen, false, lines.join("\n"));
+ assert.equal(own.journal().phase, "back");
+ assert.equal(own.origin(), null);
+ assert.equal(own.chosen(), null, "nothing still points at the removed server");
+ assert.deepEqual(asked.filter((line) => line.startsWith("server ")), [], "nothing is asked of a server this app signed out of");
+ own.close();
+});
diff --git a/electron/server-supervisor.node-test.mjs b/electron/server-supervisor.node-test.mjs
index d118fc32a0..d1bd5bc957 100644
--- a/electron/server-supervisor.node-test.mjs
+++ b/electron/server-supervisor.node-test.mjs
@@ -331,7 +331,7 @@ function runForget(state) {
const start = MAIN_SOURCE.indexOf("async function forgetEnvironment(");
const end = MAIN_SOURCE.indexOf("function showContextMenu(", start);
assert.ok(start > 0 && end > start, "the forget helper exists");
- const calls = { dialogs: [], shares: [], persisted: [], navigated: [], rm: [] };
+ const calls = { dialogs: [], shares: [], persisted: [], navigated: [], rm: [], homeKicks: [] };
const rmOptions = [];
const ctx = {
environmentsState: state,
@@ -350,6 +350,7 @@ function runForget(state) {
path,
AbortSignal,
remoteMicrophoneRefused: new Set(),
+ ownHome: { kick: async () => { calls.homeKicks.push(1); } },
desktopDataDir: () => "/Users/me/.openmausbot",
slog: () => {},
session: { defaultSession: { fetch: async () => ({ ok: true }), clearStorageData: async () => {} } },
@@ -363,7 +364,7 @@ function runForget(state) {
test("forgetting the ACTIVE local environment is refused with {error:active} and touches nothing", async () => {
const { calls, context } = runForget({ environments: [LOCAL_FIXTURE], activeId: "l1" });
assert.deepEqual(plain(await context.forgetEnvironment("l1", true)), { ok: false, error: "active" });
- assert.deepEqual(calls, { dialogs: [], shares: [], persisted: [], navigated: [], rm: [] });
+ assert.deepEqual(calls, { dialogs: [], shares: [], persisted: [], navigated: [], rm: [], homeKicks: [] });
});
test("forgetting a local environment asks nothing of the user, and a failed purge keeps the entry with {error:purge}", async () => {
@@ -397,6 +398,7 @@ test("forgetting a remote environment keeps its sign-out confirmation and answer
assert.equal(calls.dialogs[0].message, "Remove Office from this app?");
assert.match(calls.dialogs[0].detail, /The server keeps running and your bots stay there/);
assert.deepEqual(plain(calls.persisted[0].environments), []);
+ assert.equal(calls.homeKicks.length, 1, "a home on the removed server comes back to this computer now, not at the next launch");
});
test("forgetting a local environment whose folder the server child uses is refused with {error:active}", async () => {