Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Review: keep a moved copy from being hidden, and let the person leave it
Dante47404cd7103c
diff --git a/electron/cloud-account-ipc.node-test.mjs b/electron/cloud-account-ipc.node-test.mjsindex 31bcb7dc2e..43ce486b4f 100644--- a/electron/cloud-account-ipc.node-test.mjs+++ b/electron/cloud-account-ipc.node-test.mjs@@ -51,18 +51,20 @@ test("a team's Cloud opens from the page by its id alone: the team comes from thawait f.bridge.cloudAccount.openTeam({ toString: () => "team-acme" }, { origin: "https://evil.example.test" });assert.deepEqual(f.invoked, [["cloud-account:openTeam", "team-acme"]]);const source = readFileSync(new URL("./main.mjs", import.meta.url), "utf8"), start = source.indexOf("const workspaceOnly ="), end = source.indexOf('ipcMain.handle("organization:settings-opened"', start);- const handlers = new Map(), shown = [], frame = { url: `${origin}/` }, contents = { mainFrame: frame };+ const handlers = new Map(), shown = [], cancelled = [], frame = { url: `${origin}/` }, contents = { mainFrame: frame };const acme = { id: "team-acme", name: "Acme", role: "member", machine: { status: "ready", origin: "https://omb-t-2.fly.dev" } };let state = { status: "connected", teams: [acme] };localOrigin.setLocalOrigin(origin);const context = vm.createContext({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) },localOnly: localOrigin.localOnly, workspaceSenderAllowed: environments.workspaceSenderAllowed, mainWindow: { webContents: contents },rendererOrigin: () => origin, environmentsState: { environments: [], activeId: "local" }, ensureCloudAccount: () => ({ state: () => state }),+ homeWindow: { cancel: () => cancelled.push(1) },showHome: async options => { shown.push(JSON.parse(JSON.stringify(options))); } });vm.runInContext(source.slice(start, end), context);const open = handlers.get("cloud-account:openTeam"), page = { sender: contents, senderFrame: frame };await open(page, "team-acme");assert.deepEqual(shown, [{ place: { team: "team-acme", name: "Acme" } }]);+ assert.equal(cancelled.length, 1, "a team chosen from the page takes the window back from any recovery");await assert.rejects(async () => open(page, "team-other"), /not in that team/);state = { status: "unavailable", teams: [acme] };await assert.rejects(async () => open(page, "team-acme"), /not in that team/, "only a connected session's teams");diff --git a/electron/cloud-home.node-test.mjs b/electron/cloud-home.node-test.mjsindex ffe81f2c71..290890f848 100644--- a/electron/cloud-home.node-test.mjs+++ b/electron/cloud-home.node-test.mjs@@ -440,7 +440,7 @@ test("the Server menu opens My Cloud through the Cloud's own connection, never aopenCloudSettings: async () => { calls.push("settings"); },persistEnvironments: next => { calls.push(`active:${next.activeId}`); context.environmentsState = next; }, withActive: environments.withActive,navigateMainWindow: url => calls.push(`navigate:${url}`), activeOrigin: () => context.environmentsState.environments.find(e => e.id === context.environmentsState.activeId)?.origin,- homeWindow: { cloudOrigin: () => null, asking: () => false }, showHome: async (options) => { calls.push(options ? `home:${JSON.stringify(options)}` : "home"); },+ homeWindow: { cloudOrigin: () => null, asking: () => false, cancel: () => {} }, showHome: async (options) => { calls.push(options ? `home:${JSON.stringify(options)}` : "home"); },homePlaces: { remember: (place) => calls.push(`remember:${JSON.stringify(place)}`) },runningDataDir: "/data", desktopDataDir: () => "/data",handSaved, serverOpens: async (place) => { calls.push(`look:${place.id}`); return answers; }, session: { defaultSession: { fetch: async () => null } }, dialog: {},@@ -460,10 +460,10 @@ test("the Server menu opens My Cloud through the Cloud's own connection, never acalls.length = 0; await context.switchEnvironment("acme");assert.deepEqual(calls, ['home:{"place":{"team":"team-acme","name":"Acme"}}'], "a team opens through the home window's team pairing, never a plain navigation");context.environmentsState = { environments: [entry, other, acme], activeId: "acme" };- context.homeWindow = { cloudOrigin: () => origin, asking: () => false };+ context.homeWindow = { cloudOrigin: () => origin, asking: () => false, cancel: () => {} };calls.length = 0; await context.switchEnvironment("cloud");assert.deepEqual(calls, ["remember:null", 'home:{"place":"cloud"}'], "back to My Cloud from a team: My Cloud itself, remembered");- context.homeWindow = { cloudOrigin: () => null, asking: () => false };+ context.homeWindow = { cloudOrigin: () => null, asking: () => false, cancel: () => {} };context.environmentsState = { environments: [entry, other], activeId: environments.LOCAL_ID };context.environmentsState = { environments: [entry, other], activeId: environments.LOCAL_ID };context.cloudAccount = { homeTarget: () => null, state: () => ({ status: "connected", machine: { status: "stopped" } }) }; context.remember({ accountId: "a1", origin });@@ -475,12 +475,12 @@ test("the Server menu opens My Cloud through the Cloud's own connection, never acontext.cloudAccount = null; context.environmentsState = { environments: [entry, other], activeId: environments.LOCAL_ID };calls.length = 0; await context.switchEnvironment("cloud");assert.deepEqual(calls, ["remember:null", "active:cloud", `navigate:${origin}`]);- context.homeWindow = { cloudOrigin: () => origin, asking: () => false }; context.environmentsState = { environments: [entry, other], activeId: "vps" };+ context.homeWindow = { cloudOrigin: () => origin, asking: () => false, cancel: () => {} }; context.environmentsState = { environments: [entry, other], activeId: "vps" };calls.length = 0; await context.switchEnvironment("cloud");assert.deepEqual(calls, ["remember:null", 'home:{"place":"cloud"}'], "once My Cloud is home, choosing it shows home the one way every window does");// A My Cloud entry saved before, for the address the Admin is setting up again: never loaded by its address.- context.homeWindow = { cloudOrigin: () => null, asking: () => false }; context.remember(null);+ context.homeWindow = { cloudOrigin: () => null, asking: () => false, cancel: () => {} }; context.remember(null);context.cloudAccount = { homeTarget: () => null, state: () => ({ status: "connected", machine: { status: "provisioning", origin } }) };context.environmentsState = { environments: [entry, other], activeId: environments.LOCAL_ID };connect = async () => { calls.push("connect"); };@@ -489,7 +489,7 @@ test("the Server menu opens My Cloud through the Cloud's own connection, never a// That screen is this computer's own page: This computer is already the Server menu's choice, and still leaves it.calls.length = 0; await context.switchEnvironment(environments.LOCAL_ID);assert.deepEqual(calls, [], "nothing asked for: choosing the server shown changes nothing");- context.homeWindow = { cloudOrigin: () => null, asking: () => true };+ context.homeWindow = { cloudOrigin: () => null, asking: () => true, cancel: () => {} };calls.length = 0; await context.switchEnvironment(environments.LOCAL_ID);assert.deepEqual(calls.slice(0, 2), ["remember:null", `active:${environments.LOCAL_ID}`]);assert.match(calls[2], /^navigate:/);diff --git a/electron/desktop-prefs.node-test.mjs b/electron/desktop-prefs.node-test.mjsindex 4aea59e243..82763f8266 100644--- a/electron/desktop-prefs.node-test.mjs+++ b/electron/desktop-prefs.node-test.mjs@@ -303,10 +303,10 @@ test("production wiring: main answers this computer's page, My Cloud's own pageassert.deepEqual(calls, ["restored", "offers"]);options.languageChanged("en", windows[0].webContents);assert.deepEqual(sent, [["home", "desktop-language:changed", "en"], ["rail", "desktop-language:changed", "en"]], "every other open window hears the pick, and the window's rail");- const navigate = main.slice(main.indexOf("function navigateMainWindow(url) {"), main.indexOf("\n}\n", main.indexOf("function navigateMainWindow(url) {")) + 3);- const load = vm.runInNewContext(`${navigate}; navigateMainWindow`, { mainWindow: { isDestroyed: () => false, loadURL: async url => { if (url.endsWith("fail")) throw new Error("ERR_CONNECTION_REFUSED"); } } });+ const navigate = main.slice(main.indexOf("function navigateMainWindow(url, keepingRecovery = false) {"), main.indexOf("\n}\n", main.indexOf("function navigateMainWindow(url, keepingRecovery = false) {")) + 3);+ const load = vm.runInNewContext(`${navigate}; navigateMainWindow`, { homeWindow: { cancel: () => {} }, mainWindow: { isDestroyed: () => false, loadURL: async url => { if (url.endsWith("fail")) throw new Error("ERR_CONNECTION_REFUSED"); } } });assert.equal(await load(`${LOCAL}/ok`), true); assert.equal(await load(`${LOCAL}/fail`), false, "a failed load answers false, never throws");- assert.equal(await vm.runInNewContext(`${navigate}; navigateMainWindow`, { mainWindow: null })(`${LOCAL}/`), false, "no window");+ assert.equal(await vm.runInNewContext(`${navigate}; navigateMainWindow`, { homeWindow: { cancel: () => {} }, mainWindow: null })(`${LOCAL}/`), false, "no window");});test("the window's rail of places is shown until the person hides it, and the choice survives a restart", () => {diff --git a/electron/home-window-recovery.node-test.mjs b/electron/home-window-recovery.node-test.mjsnew file mode 100644index 0000000000..cf0efeaedb--- /dev/null+++ b/electron/home-window-recovery.node-test.mjs@@ -0,0 +1,64 @@+import assert from "node:assert/strict";+import test from "node:test";++import { HOME_SCREEN_PATH, OPEN_MS } from "./home-window.mjs";+import { LOCAL, world } from "./fixtures/home-window-world.mjs";++const tick = () => new Promise((resolve) => setImmediate(resolve));++test("the recovery owns the window until it settles, and a server chosen meanwhile takes it back", async () => {+ const garage = "https://garage.example.test";+ const marker = { frozen: true, cloud: garage, place: "Garage server" };+ const choosing = world({ journal: null, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });+ choosing.reopenAnswer = false;+ let chosen = () => {};+ choosing.reopenGate = new Promise((resolve) => { chosen = resolve; });+ const recoveringChoice = choosing.home.show();+ for (let i = 0; i < 200 && choosing.reopened.length === 0; i++) await tick();+ choosing.home.cancel();+ chosen();+ await recoveringChoice;+ assert.deepEqual(choosing.local, [], "no frozen page either way");+ assert.notEqual(choosing.home.view().screen, "offline", "a server chosen while the recovery runs keeps the screen to itself");+ const leaving = world({ journal: null, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });+ leaving.reopenAnswer = false;+ await leaving.home.show();+ assert.deepEqual(leaving.home.view(), { screen: "offline", reason: "Your bots are on Garage server." });+ assert.equal(leaving.timers.length, 1, "it was going to look again by itself");+ leaving.url = "https://studio.example.test/";+ leaving.home.cancel();+ assert.equal(leaving.timers.length, 0, "the recovery's own retry is retired with it");+ await leaving.later(5_000);+ assert.equal(leaving.url, "https://studio.example.test/", "the retry left with the recovery it belonged to");+ const overlapped = world({ journal: null, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });+ overlapped.reopenGate = new Promise(() => {});+ let settled = false;+ const firstLook = overlapped.home.show().then(() => { settled = true; });+ for (let i = 0; i < 200 && overlapped.timers.length === 0; i++) await tick();+ overlapped.url = `${garage}/`;+ await overlapped.home.show();+ await overlapped.later(OPEN_MS);+ await tick();+ assert.equal(settled, true, "a second show() leaves the deadline to the recovery");+ assert.deepEqual(overlapped.home.view(), { screen: "offline", reason: "Your bots are on Garage server." }, "a page that never commits is still bounded");+ assert.equal(overlapped.timers.length, 1, "and looks again by itself");+ await firstLook;+ const replaced = world({ journal: null, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });+ let releaseOld = () => {};+ replaced.reopenAnswer = false;+ replaced.reopenGate = new Promise((resolve) => { releaseOld = resolve; });+ const old = replaced.home.show();+ for (let i = 0; i < 200 && replaced.reopened.length === 0; i++) await tick();+ replaced.home.cancel();+ replaced.reopenGate = new Promise(() => {});+ const newer = replaced.home.show();+ for (let i = 0; i < 200 && replaced.reopened.length === 1; i++) await tick();+ releaseOld();+ await old;+ void replaced.home.show();+ await tick();+ await tick();+ assert.equal(replaced.reopened.length, 2, "a cancelled recovery never unlocks the one that replaced it");+ void newer;+});+diff --git a/electron/home-window.d.mts b/electron/home-window.d.mtsindex da6147ba4b..1792ed949c 100644--- a/electron/home-window.d.mts+++ b/electron/home-window.d.mts@@ -73,6 +73,7 @@ type Timers = { set(work: () => void, ms: number): unknown; clear(timer: unknownexport interface HomeWindow {show(options?: { open?: "phone" | null; place?: HomeAsk }): Promise<unknown>;+ cancel(): void;openCloud(open?: "phone" | null): Promise<unknown>;/** Remove from list from this computer's screen: the Cloud it shows leaves the person's list. */remove(): Promise<import("./cloud-account.mjs").CloudRemoveOutcome>;diff --git a/electron/home-window.mjs b/electron/home-window.mjsindex 6d60c9137c..775cf348b5 100644--- a/electron/home-window.mjs+++ b/electron/home-window.mjs@@ -225,6 +225,7 @@ export function createHomeWindow(deps) {splash = () => null, lastInput = () => 0, publish = () => {}, rehomed = () => {}, versionEveryMs = VERSION_EVERY_MS, quietMs = QUIET_MS,now = Date.now, timers = DEFAULT_TIMERS, hosts = () => null, readyStore = null, ownMove = () => null, log = () => {} } = deps;let home = { kind: "computer" }, screen = null, status = null, opens = 0, retry = null, tries = 0, loaded = null, newer = false, repairing = null;+ let recovering = null;/** My Cloud asked for before the move made it home (`{ open }`), until its page loads or the person goes elsewhere;* `naming`: since when, and how often, a brand-new My Cloud's name was not found. */let asked = null, naming = null;@@ -251,9 +252,8 @@ export function createHomeWindow(deps) {clock.seen(state());const kept = parseJournal(journal());let frozenCloud = null, frozenPlace = null;- if (!kept) {+ if (!awayIn(kept)) {const marker = await frozen().catch(() => null);- // A freeze for a server of the person's own names it (`place`): home is that server, shown as any saved server is.if (marker?.frozen && !marker.place) frozenCloud = typeof marker.cloud === "string" ? marker.cloud : true;else if (marker?.frozen && marker.place) frozenPlace = { origin: typeof marker.cloud === "string" ? marker.cloud : null, place: String(marker.place) };}@@ -296,6 +296,11 @@ export function createHomeWindow(deps) {const win = window();return Boolean(win && !win.isDestroyed()) && originOf(win.webContents.getURL()) === origin;};+ const onOwnPage = () => {+ const win = window();+ const at = win && !win.isDestroyed() ? originOf(win.webContents.getURL()) : null;+ return !at || at === localOrigin();+ };const onScreen = () => {const win = window();if (!win || win.isDestroyed()) return false;@@ -500,6 +505,7 @@ export function createHomeWindow(deps) {* "cloud" for My Cloud, `{ team }` for a team's Cloud, `{ cloud }` for another of the person's own, else the place* remembered from last time. */async function show({ open = null, place = null } = {}) {+ if (recovering) { if (!open && !place) return; recovering = null; }const token = ++opens;const current = await refresh();if (!wanted(token)) return;@@ -535,21 +541,23 @@ export function createHomeWindow(deps) {asked = null; naming = null;}if (current.kind === "computer") {- // A copy frozen by a move to a server of the person's own is never shown; a move under way keeps its own screen.const parkedAt = current.frozenPlace;- if (!current.clean && parkedAt && !ownMove() && !(parkedAt.origin && shows(parkedAt.origin))) {+ if (!current.clean && parkedAt && !ownMove() && onOwnPage()) {clearRetry(); screen = null; status = null; shown = null; away = false;ensureWindow();let slow = null;- const back = await Promise.race([- reopen(parkedAt, () => wanted(token)).catch(() => false),- new Promise((done) => { slow = timers.set(() => done(false), OPEN_MS); }),- ]);- timers.clear(slow);- if (!wanted(token)) return;- if (back) return;- toScreen({ screen: "offline", reason: `Your bots are on ${parkedAt.place}.` });- return later();+ const mine = {}; recovering = mine;+ try {+ const back = await Promise.race([+ reopen(parkedAt, () => wanted(token)).catch(() => false),+ new Promise((done) => { slow = timers.set(() => done(false), OPEN_MS); }),+ ]);+ timers.clear(slow);+ if (!wanted(token)) return;+ if (back) return;+ toScreen({ screen: "offline", reason: `Your bots are on ${parkedAt.place}.` });+ return later();+ } finally { if (recovering === mine) recovering = null; }}if (current.clean && !(await clean.enter())) { if (wanted(token)) { ensureWindow(); clearRetry(); toScreen({ screen: "signin", ...(current.other ? { other: true } : {}) }); } return; }if (!wanted(token)) return;@@ -718,12 +726,11 @@ export function createHomeWindow(deps) {* computer's screen says so and the window tries again by itself. False for any other server. */failed(url, code = 0) {const at = originOf(url), place = placeOrigin(), mine = readyCloudOrigin(state());- // The window's own way back to a frozen copy's server (a recovery at launch): its page didn't load, so this- // computer's screen says where the bots are and looks again, never the generic dialog and the way to Local.const parkedAt = home.frozenPlace;if (!place && parkedAt?.origin && at === parkedAt.origin) {++opens;- toScreen({ screen: "offline", reason: `Your bots are on ${parkedAt.place}.` });+ if (ownMove()) tell();+ else toScreen({ screen: "offline", reason: `Your bots are on ${parkedAt.place}.` });later();return true;}@@ -749,6 +756,7 @@ export function createHomeWindow(deps) {},/** Signs the team on screen in again now, without moving the page (the timer's own step; also for tests). */renew: () => renew(),+ cancel() { opens++; recovering = null; clearRetry(); screen = null; status = null; shown = null; away = false; },close() { opens++; clearRetry(); clearRenewal(); timers.clear(watcher); },};}diff --git a/electron/home-window.node-test.mjs b/electron/home-window.node-test.mjsindex 5e3bd2d096..07fc3877b7 100644--- a/electron/home-window.node-test.mjs+++ b/electron/home-window.node-test.mjs@@ -55,8 +55,7 @@ test("a server of the person's own their bots moved to is no Cloud: no sign-in,test("a frozen copy left on this computer's own page goes back to the server it names, or says where the bots are", async () => {const garage = "https://garage.example.test";const marker = { frozen: true, cloud: garage, place: "Garage server" };- // The window opens on this computer's page, and that server is frozen: its page is the home screen, which waits on a- // home that is not here, so it spins there for ever. The window goes back to the server instead, as any saved server does.+ // This computer's page has nothing to show for a frozen copy: the window goes back to the server, as any saved server does.const parked = world({ journal: null, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });await parked.home.show();assert.deepEqual(parked.reopened, [{ origin: garage, place: "Garage server" }], "the server is asked for again, never the frozen page");@@ -91,7 +90,7 @@ test("a frozen copy left on this computer's own page goes back to the server itrelease();await recovering;assert.equal(racing.url, `${garage}/`, "an overlapping show() never pulls the window back to the frozen page");- assert.deepEqual(racing.local, [false], "it leaves the window where the recovery is taking it");+ assert.deepEqual(racing.local, [], "it leaves the window, and the deadline, to the recovery");// The recovery's own page failing to load is this app's to answer, not main's generic "not reachable" dialog.const loading = world({ journal: null, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });await loading.home.show();@@ -114,6 +113,16 @@ test("a frozen copy left on this computer's own page goes back to the server itawait moving.home.show();assert.deepEqual(moving.reopened, [], "an unfinished move is not opened");assert.deepEqual(moving.home.view(), { screen: "moving", name: "Garage server" });+ assert.equal(moving.home.failed(`${garage}/chats`, -105), true, "the move's own load failure is answered here too");+ assert.deepEqual(moving.home.view(), { screen: "moving", name: "Garage server" }, "never the offline screen in the middle of a move");+ assert.equal(moving.timers.length, 1, "and it looks again by itself");+ const keptBack = world({ journal: { ...done(), phase: "back" }, marker, state: { status: "signed-out" }, url: `${LOCAL}${HOME_SCREEN_PATH}` });+ await keptBack.home.show();+ assert.deepEqual(keptBack.reopened, [{ origin: garage, place: "Garage server" }], "a journal that keeps this computer does not hide the marker");+ const elsewhere = world({ journal: null, marker, state: { status: "signed-out" }, url: "https://studio.example.test/" });+ await elsewhere.home.show();+ assert.deepEqual(elsewhere.reopened, [], "a server already open is not left for the frozen one");+ assert.equal(elsewhere.url, "https://studio.example.test/", "the window stays where it is");});test("a sign-in keeps only a path of My Cloud's own", () => {diff --git a/electron/main-navigation.node-test.mjs b/electron/main-navigation.node-test.mjsnew file mode 100644index 0000000000..30ac34c5a2--- /dev/null+++ b/electron/main-navigation.node-test.mjs@@ -0,0 +1,22 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";+import vm from "node:vm";++test("a navigation retires the launch recovery, except the recovery's own", async () => {+ const source = readFileSync(new URL("./main.mjs", import.meta.url), "utf8");+ const start = source.indexOf("function navigateMainWindow(");+ assert.ok(start > 0);+ const end = source.indexOf("\n}\n", start) + 3;+ const calls = [];+ const context = vm.createContext({+ homeWindow: { cancel: () => calls.push("cancel") },+ mainWindow: { isDestroyed: () => false, loadURL: async (url) => { calls.push(`load:${url}`); } },+ });+ vm.runInContext(`${source.slice(start, end)}; this.navigateMainWindow = navigateMainWindow;`, context);+ await context.navigateMainWindow("https://studio.example.test/");+ assert.deepEqual(calls, ["cancel", "load:https://studio.example.test/"], "a place opened on purpose takes the window back");+ calls.length = 0;+ await context.navigateMainWindow("https://garage.example.test/", true);+ assert.deepEqual(calls, ["load:https://garage.example.test/"], "the recovery's own way back is not a choice");+});diff --git a/electron/main.mjs b/electron/main.mjsindex 9499ba5cca..4342a80e6f 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -1576,7 +1576,8 @@ async function workspaceMenuAction(action) {}}-function navigateMainWindow(url) {+function navigateMainWindow(url, keepingRecovery = false) {+ if (!keepingRecovery) homeWindow.cancel();if (!mainWindow || mainWindow.isDestroyed()) return Promise.resolve(false);return mainWindow.loadURL(url).then(() => true, () => false);}@@ -1687,6 +1688,7 @@ async function switchLocalEnvironmentTo(targetDir, targetId, quiet = false) {async function switchEnvironment(id) {if ((id === environmentsState.activeId && !homeWindow.asking()) || (id !== LOCAL_ID && !environmentsState.environments.some((entry) => entry.id === id))) return;+ homeWindow.cancel();const entry = environmentsState.environments.find((candidate) => candidate.id === id);if (entry?.team || entry?.cloud) return void await showHome({ place: entry.team ? { team: entry.team.id, name: entry.name } : { cloud: entry.cloud.id, name: entry.name } });homePlaces.remember(null);@@ -2555,6 +2557,7 @@ ipcMain.handle("cloud-account:openTeam", localWorkspaceOnly("cloud-account:openTconst current = ensureCloudAccount().state();const team = current.status === "connected" ? current.teams?.find(entry => entry.id === teamId) ?? null : null;if (!team) throw new Error("You're not in that team.");+ homeWindow.cancel();await showHome({ place: { team: team.id, name: team.name } });}));// Cancel trial / Cancel plan and Keep my plan: the page sends the survey's words only; the Cloud is the verified session's own.@@ -2666,15 +2669,15 @@ const homeWindow = createHomeWindow({ clean: cleanWorkspace, journal: oneHome.johosts: () => session.defaultSession, readyStore: jsonFile(path.join(app.getPath("userData"), "cloud-ready.json")), ownMove: () => ownHome?.underWay() ?? null,remembered: homePlaces.remembered, remember: homePlaces.remember, left: homePlaces.left, drop: homePlaces.drop,publish: view => { if (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })) mainWindow.webContents.send("home:state-changed", view); },- go: (url, origin, place) => { if (place?.kind === "team" || place?.kind === "own") { activatePlace(place); if (place.kind === "team") teamProfileSeeds.opened(place.origin); } else if (origin) activateCloud(origin); else if (activeEnvironment(environmentsState)) persistEnvironments(withActive(environmentsState, LOCAL_ID)); return navigateMainWindow(url); },- reopen: (place, still) => reopenSavedServer(place, { still, saved: () => environmentsState.environments, fetch: (...args) => session.defaultSession.fetch(...args), opened: async (entry) => { homePlaces.remember(null); persistEnvironments(withActive(environmentsState, entry.id)); return navigateMainWindow(activeOrigin()); } }),+ go: (url, origin, place) => { if (place?.kind === "team" || place?.kind === "own") { activatePlace(place); if (place.kind === "team") teamProfileSeeds.opened(place.origin); } else if (origin) activateCloud(origin); else if (activeEnvironment(environmentsState)) persistEnvironments(withActive(environmentsState, LOCAL_ID)); return navigateMainWindow(url, true); },+ reopen: (place, still) => reopenSavedServer(place, { still, saved: () => environmentsState.environments.filter(handSaved), fetch: (...args) => session.defaultSession.fetch(...args), opened: async (entry) => { homePlaces.remember(null); persistEnvironments(withActive(environmentsState, entry.id)); return navigateMainWindow(activeOrigin(), true); } }),showLocal: leaving => { if (!mainWindow || mainWindow.isDestroyed()) return createWindow(); if (!leaving) return; persistEnvironments(withActive(environmentsState, LOCAL_ID)); return navigateMainWindow(rendererOrigin()); } });installHomeWindowIpc({ ipcMain, homeWindow, cloudPage: cloudPageAsking });/** Every path that shows the window: My Cloud once it is the person's home, else as before. */function showHome(options) {return homeWindow.show(options).catch(error => slog(`home: ${error?.message ?? error}`));}-const openOwnCloud = id => showHome({ place: { cloud: id, name: environmentsState.environments.find(entry => entry.cloud?.id === id)?.name } });+const openOwnCloud = id => { homeWindow.cancel(); return showHome({ place: { cloud: id, name: environmentsState.environments.find(entry => entry.cloud?.id === id)?.name } }); };// The rail and its + (cloud-rail.mjs): its list for this app's page and hosted Clouds' pages only, opened through switchEnvironment.const railList = () => { ownHome?.refresh(); return railPlaces({ saved: environmentsState, home: homeWindow.cloudOrigin() ?? ownHome?.origin() ?? null, mine: myCloud(), state: desktopRemoteAccess ? null : cloudAccount?.state(), offers: entry => !desktopRemoteAccess && ownHome?.offers(entry) === true }); };// The rail as the window's own chrome (chrome-rail.mjs): this app's page beside every place's page, the one that lists.diff --git a/electron/saved-server.mjs b/electron/saved-server.mjsindex fb42785ccf..ee516e190e 100644--- a/electron/saved-server.mjs+++ b/electron/saved-server.mjs@@ -46,6 +46,7 @@ export async function reopenSavedServer({ origin }, { saved, fetch: fetchImpl, sconst entry = origin ? saved().find((candidate) => candidate.origin === origin) ?? null : null;if (!entry) return false;if (!(await serverAnswers(entry.origin, fetchImpl))) return false;+ if (!saved().some((candidate) => candidate.id === entry.id)) return false;if (!still()) return false;return Boolean(await opened(entry));}diff --git a/electron/saved-server.node-test.mjs b/electron/saved-server.node-test.mjsindex d4a2c3777d..3502ede56a 100644--- a/electron/saved-server.node-test.mjs+++ b/electron/saved-server.node-test.mjs@@ -1,7 +1,7 @@import assert from "node:assert/strict";import test from "node:test";-import { serverAnswers, serverOpens } from "./saved-server.mjs";+import { reopenSavedServer, serverAnswers, serverOpens } from "./saved-server.mjs";const office = { id: "vps", name: "pro cloud", origin: "https://omb-u-gone.fly.dev" };const answering = (status) => async () => new Response("{}", { status });@@ -43,3 +43,20 @@ test("one that doesn't answer is the person's choice: Cancel stays put, Remove fassert.equal(await serverOpens(office, { fetch: back, dialog: retry.dialog, forget: () => assert.fail("not asked to") }), true, "it answered the second time");assert.equal(retry.shown.length, 1);});++test("the way back opens a saved server that answers, and gives up on one that left the list or a newer show() took over", async () => {+ const entry = { id: "vps", origin: office.origin };+ let opened = null;+ const open = (more = {}) => ({ saved: () => [entry], fetch: answering(200), opened: (found) => { opened = found; return true; }, ...more });+ assert.equal(await reopenSavedServer({ origin: office.origin }, open()), true, "saved here and answering: it opens");+ assert.equal(opened.id, "vps");+ assert.equal(await reopenSavedServer({ origin: "https://elsewhere.example.test" }, open()), false, "not saved here any more");+ assert.equal(await reopenSavedServer({ origin: office.origin }, open({ fetch: gone })), false, "nothing answers at it");+ assert.equal(await reopenSavedServer({ origin: office.origin }, open({ still: () => false })), false, "a newer show() took over");+ assert.equal(await reopenSavedServer({ origin: null }, open()), false, "no server named");+ let looks = 0;+ opened = null;+ const left = () => { looks += 1; return looks === 1 ? [entry] : []; };+ assert.equal(await reopenSavedServer({ origin: office.origin }, { saved: left, fetch: answering(200), opened: (found) => { opened = found; return true; } }), false, "forgotten while it was asked");+ assert.equal(opened, null, "never opened the environment that is now active");+});