Skip to content

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

fix(lending): the menu says it's waiting until a Cloud accepts this computer (#4078)

B Rishabh Raobca772c7c557
diff --git a/electron/cloud-lending.node-test.mjs b/electron/cloud-lending.node-test.mjs
index f868c58a46..53c9b1e969 100644
--- a/electron/cloud-lending.node-test.mjs
+++ b/electron/cloud-lending.node-test.mjs
@@ -349,7 +349,7 @@ test("Pause is instant: the Cloud is told, running work is cancelled, nothing mo
home.push({ action: "computer_call", tool_name: "click", arguments: {} });
await delay(300);
assert.equal((await readFile(driver.calls, "utf8")).trim(), "drag");
- assert.deepEqual(summaries.at(-1), { lending: [], clouds: ["My Cloud"], using: [], paused: true, terminal: false, busy: null, screen: null });
+ assert.deepEqual(summaries.at(-1), { lending: [], clouds: ["My Cloud"], waiting: [], using: [], paused: true, terminal: false, busy: null, screen: null });
assert.equal(sharing.cloudState(env).problem, "paused");
});
diff --git a/electron/computer-sharing.d.mts b/electron/computer-sharing.d.mts
index 99717b1e4c..b124ead838 100644
--- a/electron/computer-sharing.d.mts
+++ b/electron/computer-sharing.d.mts
@@ -64,6 +64,8 @@ export interface ComputerAsk {
export interface LendingSummary {
lending: string[];
clouds: string[];
+ /** Lent Clouds that haven't accepted this computer yet (asleep ones excluded). */
+ waiting?: string[];
using: string[];
paused: boolean;
terminal?: boolean;
diff --git a/electron/computer-sharing.mjs b/electron/computer-sharing.mjs
index 8131136eee..9fdb46bf56 100644
--- a/electron/computer-sharing.mjs
+++ b/electron/computer-sharing.mjs
@@ -241,6 +241,9 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, cu
return {
lending: lent.map(env => env.id),
clouds: (paused ? ownClouds() : lent).map(env => env.name),
+ // Lent, but the Cloud hasn't accepted this computer yet (or lost it): the menu must not say it can use it. A
+ // sleeping My Cloud still can; it wakes when a bot needs this computer.
+ waiting: lent.filter(env => !status.get(env.id)?.connected && status.get(env.id)?.problem !== "asleep").map(env => env.name),
using: using.map(env => env.name),
paused,
terminal: terminalAccount !== null && terminalAccount === signedInAccount(),
diff --git a/electron/lend-automatically.node-test.mjs b/electron/lend-automatically.node-test.mjs
index 6a292a930a..0a5110d8d0 100644
--- a/electron/lend-automatically.node-test.mjs
+++ b/electron/lend-automatically.node-test.mjs
@@ -209,7 +209,7 @@ test("Pause stops every Cloud at once and lasts across restarts; Resume lends ag
await until(() => homes[HOME].connects.length === 1 && homes[OTHER].connects.length === 1, "both Clouds to be lent");
mac.sharing.pause();
await until(() => homes[HOME].disconnects.length === 1 && homes[OTHER].disconnects.length === 1, "both Clouds to be told");
- assert.deepEqual(mac.summaries.at(-1), { lending: [], clouds: ["My Cloud", "Client A"], using: [], paused: true, terminal: false, busy: null, screen: null });
+ assert.deepEqual(mac.summaries.at(-1), { lending: [], clouds: ["My Cloud", "Client A"], waiting: [], using: [], paused: true, terminal: false, busy: null, screen: null });
assert.equal(mac.sharing.lentToCloud(myCloud).paused, true, "Files keeps My Cloud's copies, and holds bots' changes there");
const plans = path.join(mac.dir, "Plans");
await mkdir(plans);
@@ -555,3 +555,27 @@ test("the activity window says what every language pack says, word for word", as
for (const key of keys) assert.equal(WORDS[locale][key], pack[key] ?? en[key], `${locale} ${key}: copy src/locales/${file} into electron/lending-words.mjs`);
}
});
+
+test("a home server that refuses this computer is shown as waiting, never as able to use it, until it accepts (#4078)", async t => {
+ const GARAGE = "https://garage.example.test", garage = { id: "garage", kind: "remote", name: "Garage server", origin: GARAGE };
+ const server = cloudHome({ link: false, chrome: false });
+ const answer = server.fetch;
+ let refuse = true;
+ const reply = (value, status) => ({ ok: status < 400, status, headers: { get: () => null }, body: (async function* () { yield Buffer.from(JSON.stringify(value)); })() });
+ server.fetch = async (url, init) => {
+ const route = new URL(url).pathname;
+ if (route === "/api/auth/session") return reply({ kind: "session", id: server.sessionId, scopes: ["admin", "client"], own: true }, 200);
+ if (route === "/api/shared-computers/connect" && refuse) return reply({ error: "Forbidden" }, 403);
+ return answer(url, init);
+ };
+ const mac = await computer(t, { homes: { [GARAGE]: server }, places: [garage], ownHome: () => ({ origin: GARAGE, environmentId: server.environmentId }) });
+ mac.sharing.start();
+ await until(() => mac.summaries.some(summary => summary.waiting?.includes("Garage server")), "the refused server to be waiting");
+ assert.equal(server.connects.length, 0);
+ assert.deepEqual(mac.summaries.at(-1).clouds, ["Garage server"], "still lent, so the menu-bar item stays");
+ assert.equal(indicatorText(mac.summaries.at(-1), "Mac").line, "Waiting for Garage server to accept this Mac");
+ refuse = false;
+ await until(() => server.connects.length === 1, "the server to accept on the next try", 8000);
+ await until(() => mac.summaries.at(-1).waiting.length === 0, "the waiting line to go");
+ assert.equal(indicatorText(mac.summaries.at(-1), "Mac").line, "Garage server can use this Mac");
+});
diff --git a/electron/lending-indicator.mjs b/electron/lending-indicator.mjs
index 04ad07df72..496a96ed84 100644
--- a/electron/lending-indicator.mjs
+++ b/electron/lending-indicator.mjs
@@ -9,12 +9,17 @@ const short = names => names.length < 3 ? listed(names) : `${names.length} Cloud
/** `screen`: computer control's state; while it isn't ready the line says what the Clouds
* can't use, and `screen` why. */
-export function indicatorText({ clouds, using, paused, screen = null }, device) {
+/** `waiting`: lent Clouds that haven't accepted this computer yet; they are never said to be able to use it, and
+ * `pending` says who is still being waited for. */
+export function indicatorText({ clouds, using, paused, screen = null, waiting = [] }, device) {
const it = `this ${device}`;
if (paused) return { line: `Paused: ${listed(clouds)} can't use ${it}`, title: "Paused", screen: null };
const why = screenLine(screen, device);
- if (using.length) return { line: `${listed(using)} ${using.length > 1 ? "are" : "is"} using ${it}`, title: `${short(using)} ${using.length > 1 ? "are" : "is"} using ${it}`, screen: why };
- return { line: why ? `${listed(clouds)} can use ${it}, but not its apps and screen` : `${listed(clouds)} can use ${it}`, title: "", screen: why };
+ const pending = waiting.length ? { pending: `Waiting for ${listed(waiting)} to accept ${it}` } : {};
+ if (using.length) return { line: `${listed(using)} ${using.length > 1 ? "are" : "is"} using ${it}`, title: `${short(using)} ${using.length > 1 ? "are" : "is"} using ${it}`, screen: why, ...pending };
+ const ready = clouds.filter(name => !waiting.includes(name));
+ if (!ready.length) return { line: pending.pending ?? `${listed(clouds)} can use ${it}`, title: "", screen: why };
+ return { line: why ? `${listed(ready)} can use ${it}, but not its apps and screen` : `${listed(ready)} can use ${it}`, title: "", screen: why, ...pending };
}
export function createLendingIndicator({ Tray, Menu, nativeImage, iconPath, onPause, onResume, onActivity, onTerminal, onStartScreen = () => {}, device = deviceWord() }) {
@@ -22,13 +27,14 @@ export function createLendingIndicator({ Tray, Menu, nativeImage, iconPath, onPa
let shown = null;
const draw = view => {
if (!tray || tray.isDestroyed()) return;
- const { line, title, screen } = indicatorText(view, device);
+ const { line, title, screen, pending } = indicatorText(view, device);
const fix = screen ? screenFixLabel(view.screen) : null;
- tray.setToolTip(`OpenMausBot: ${line}${screen ? `. ${screen}` : ""}`);
+ tray.setToolTip(`OpenMausBot: ${line}${pending ? `. ${pending}` : ""}${screen ? `. ${screen}` : ""}`);
// Electron shows a tray title beside the icon on macOS only.
tray.setTitle?.(title);
tray.setContextMenu(Menu.buildFromTemplate([
{ label: line, enabled: false },
+ ...pending ? [{ label: pending, enabled: false }] : [],
...screen ? [{ label: screen, enabled: false }] : [],
...fix ? [{ label: fix, click: () => onStartScreen() }] : [],
{ type: "separator" },
@@ -40,8 +46,8 @@ export function createLendingIndicator({ Tray, Menu, nativeImage, iconPath, onPa
]));
};
return {
- update({ clouds = [], using = [], paused = false, terminal = false, screen = null }) {
- const next = { clouds: [...clouds], using: paused ? [] : [...using], paused: paused === true, terminal: terminal === true,
+ update({ clouds = [], using = [], paused = false, terminal = false, screen = null, waiting = [] }) {
+ const next = { clouds: [...clouds], using: paused ? [] : [...using], waiting: paused ? [] : [...waiting], paused: paused === true, terminal: terminal === true,
screen: screen ? { ready: screen.ready === true, reason: screen.reason ?? null, fix: screen.fix ?? null, ...(screen.message ? { message: screen.message } : {}) } : null };
if (shown && JSON.stringify(next) === JSON.stringify(shown)) return;
shown = next;
diff --git a/electron/screen-status.node-test.mjs b/electron/screen-status.node-test.mjs
index c80b00d767..85a969f0d8 100644
--- a/electron/screen-status.node-test.mjs
+++ b/electron/screen-status.node-test.mjs
@@ -98,3 +98,24 @@ test("a failed start keeps the reason Windows gave, not only the kind of failure
assert.equal(driverFailure(Object.assign(new Error("EmbeddedDriverError.StartupTimeout"), { tag: "StartupTimeout", inner: { timeoutMs: 10_000n } })), "StartupTimeout: timeoutMs 10000");
assert.equal(driverFailure(new Error("plain")), "plain");
});
+
+test("the menu never says a Cloud can use this computer before that Cloud accepts it (#4078)", () => {
+ const ready = { ready: true, reason: null };
+ assert.deepEqual(indicatorText({ clouds: ["Debian Server"], using: [], paused: false, screen: ready, waiting: ["Debian Server"] }, "Mac"),
+ { line: "Waiting for Debian Server to accept this Mac", title: "", screen: null });
+ assert.deepEqual(indicatorText({ clouds: ["My Cloud", "Debian Server"], using: [], paused: false, screen: ready, waiting: ["Debian Server"] }, "Mac"),
+ { line: "My Cloud can use this Mac", title: "", screen: null, pending: "Waiting for Debian Server to accept this Mac" });
+ assert.equal(indicatorText({ clouds: ["Debian Server"], using: [], paused: true, screen: ready, waiting: [] }, "Mac").line,
+ "Paused: Debian Server can't use this Mac", "paused is unchanged");
+
+ const trays = [];
+ class Tray { constructor() { trays.push(this); } on() {} setToolTip(tip) { this.tip = tip; } setTitle() {} setContextMenu(menu) { this.menu = menu; } isDestroyed() { return false; } destroy() {} }
+ const indicator = createLendingIndicator({ Tray, Menu: { buildFromTemplate: items => items }, nativeImage: { createFromPath: () => ({ resize: () => ({}) }) }, iconPath: "",
+ onPause: () => {}, onResume: () => {}, onActivity: () => {}, onTerminal: () => {}, device: "Mac" });
+ indicator.update({ clouds: ["My Cloud", "Debian Server"], waiting: ["Debian Server"], screen: ready });
+ assert.deepEqual(trays[0].menu.filter(item => item.label).map(item => item.label),
+ ["My Cloud can use this Mac", "Waiting for Debian Server to accept this Mac", "Pause", "Let Clouds run commands on this Mac", "See activity"]);
+ assert.equal(trays[0].tip, "OpenMausBot: My Cloud can use this Mac. Waiting for Debian Server to accept this Mac");
+ indicator.update({ clouds: ["My Cloud", "Debian Server"], waiting: [], screen: ready });
+ assert.equal(trays[0].menu[0].label, "My Cloud and Debian Server can use this Mac", "accepted: the waiting line goes away");
+});