Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Phones: say a phone was removed only after the computer removed it
aivsomkarbcfd09b88404
diff --git a/src/components/PairedPhones.remove.dom.test.ts b/src/components/PairedPhones.remove.dom.test.tsnew file mode 100644index 0000000000..5c5310efc1--- /dev/null+++ b/src/components/PairedPhones.remove.dom.test.ts@@ -0,0 +1,57 @@+// @vitest-environment happy-dom+// The real controller runs against a fake preload bridge.+import { createElement } from "react";+import { flushSync } from "react-dom";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";++import { setLocale } from "@/lib/i18n";+import { PairedPhones } from "./PairedPhones";+import { usePhoneSetupController, type CompanionState } from "./PhoneSetupFlow";++const ada = { id: "phone-1", name: "Ada", createdAt: 1, lastSeenAt: 1, cloudDesktopAccess: true };+const paired: CompanionState = { enabled: true, keepAwake: false, port: 8810, devices: [ada], pairing: null };++function Page() {+ const c = usePhoneSetupController();+ return c.state ? createElement(PairedPhones, { c, state: c.state }) : null;+}++let host: HTMLDivElement;+let root: Root;+const remove = () => host.querySelector<HTMLButtonElement>("[data-phone-remove]");++beforeEach(() => {+ setLocale("en");+ host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+});+afterEach(() => {+ flushSync(() => root.unmount());+ host.remove();+ delete (globalThis as { ogb?: unknown }).ogb;+});++async function clickRemove(revoke: () => Promise<CompanionState>) {+ (globalThis as { ogb?: unknown }).ogb = { companion: { state: vi.fn(async () => paired), revoke: vi.fn(revoke) } };+ flushSync(() => root.render(createElement(Page)));+ await vi.waitFor(() => expect(remove()?.disabled).toBe(false));+ remove()!.click();+}++it("says a phone was removed once the computer removed it", async () => {+ await clickRemove(async () => ({ ...paired, devices: [] }));+ await vi.waitFor(() => expect(host.textContent).toContain("Removed Ada."));+});++it("never says a phone was removed when removing it failed", async () => {+ let failed = false;+ await clickRemove(async () => {+ failed = true;+ throw new Error("sidecar down");+ });+ await vi.waitFor(() => expect(failed).toBe(true));+ await vi.waitFor(() => expect(remove()?.disabled).toBe(false));+ expect(host.textContent).not.toContain("Removed Ada.");+});diff --git a/src/components/PairedPhones.tsx b/src/components/PairedPhones.tsxindex 7fac91c3b1..e1ae9886ac 100644--- a/src/components/PairedPhones.tsx+++ b/src/components/PairedPhones.tsx@@ -72,7 +72,7 @@ export function PhoneRow({ device, connected, state, c, onRemoved, onPairAgain,)}<button type="button"disabled={c.busy}- onClick={() => void c.act((companion) => companion.revoke(device.id)).then(() => onRemoved(device.name))}+ onClick={() => void c.act((companion) => companion.revoke(device.id)).then((next) => { if (next) onRemoved(device.name); })}aria-label={t("remote.devices.remove", { name: device.name })}data-danger="" data-phone-remove=""className="settings-quiet shrink-0 cursor-pointer disabled:opacity-40"diff --git a/src/components/PhoneSetupFlow.publicNetwork.test.ts b/src/components/PhoneSetupFlow.publicNetwork.test.tsindex 6da5dffaf0..bbff2dfff1 100644--- a/src/components/PhoneSetupFlow.publicNetwork.test.ts+++ b/src/components/PhoneSetupFlow.publicNetwork.test.ts@@ -51,7 +51,7 @@ const controller = (over: Partial<PhoneSetupController>): PhoneSetupController =cancel: noop,refreshCode: noop,finish: noop,- act: async () => {},+ act: async () => null,accountAct: async () => {},...over,});diff --git a/src/components/PhoneSetupFlow.tsx b/src/components/PhoneSetupFlow.tsxindex 72586f9d1c..979592b5f5 100644--- a/src/components/PhoneSetupFlow.tsx+++ b/src/components/PhoneSetupFlow.tsx@@ -155,7 +155,8 @@ export interface PhoneSetupController {cancel: () => void;refreshCode: () => void;finish: () => void;- act: (call: (companion: CompanionBridge) => Promise<CompanionState>) => Promise<void>;+ /** The state after the call, or null when it did not run or failed (then `error` says why). */+ act: (call: (companion: CompanionBridge) => Promise<CompanionState>) => Promise<CompanionState | null>;accountAct: (call: (remote: AccountBridge) => Promise<CompanionAccountState>) => Promise<void>;}@@ -239,7 +240,7 @@ export function usePhoneSetupController(profileEmail = ""): PhoneSetupControllerconst act = useCallback(async (call: (companion: CompanionBridge) => Promise<CompanionState>) => {const companion = companionBridge();- if (!companion) return;+ if (!companion) return null;setActionBusy(true);setError(null);try {@@ -248,6 +249,7 @@ export function usePhoneSetupController(profileEmail = ""): PhoneSetupController() => call(companion),);if (mounted.current) setState(next);+ return next;} catch (cause) {if (mounted.current) setError(normalizePhoneSetupActionError(@@ -255,6 +257,7 @@ export function usePhoneSetupController(profileEmail = ""): PhoneSetupControllert("phone.error.remoteUpdate"),),);+ return null;} finally {if (mounted.current) setActionBusy(false);}