Skip to content

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

Phones: stay on the way-in choice when it could not be turned on

aivsomkardb548f62e7ab
diff --git a/src/components/PhoneDevicesSection.consent.dom.test.ts b/src/components/PhoneDevicesSection.consent.dom.test.ts
new file mode 100644
index 0000000000..d929006b2f
--- /dev/null
+++ b/src/components/PhoneDevicesSection.consent.dom.test.ts
@@ -0,0 +1,58 @@
+// @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 { usePhoneSetupController, type CompanionState } from "./PhoneSetupFlow";
+
+vi.mock("@/state/store", () => ({ useStore: () => ({ state: { config: {} } }) }));
+const { PairDeviceDialog } = await import("./PhoneDevicesSection");
+
+const off = { on: false, since: null };
+const closed: CompanionState = { enabled: false, keepAwake: false, port: 8810, devices: [], pairing: null,
+ routes: { wifi: off, relay: off, tailscale: off, https: off } };
+
+function Page() {
+ const c = usePhoneSetupController();
+ return c.state ? createElement(PairDeviceDialog, { c, state: c.state, onClose: () => {} }) : null;
+}
+
+let host: HTMLDivElement;
+let root: Root;
+const dialog = () => document.querySelector<HTMLElement>("[data-pair-dialog]");
+const turnOn = () => document.querySelector<HTMLButtonElement>("[data-pair-turn-on]");
+
+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;
+});
+
+it("stays on the choice and says why when the chosen way in could not be turned on", async () => {
+ const companion = {
+ state: vi.fn(async () => closed),
+ setRoute: vi.fn(async () => { throw new Error("settings not writable"); }),
+ start: vi.fn(async () => ({ ...closed, enabled: true })),
+ pairing: vi.fn(async () => closed),
+ refreshTailscale: vi.fn(async () => closed),
+ };
+ (globalThis as { ogb?: unknown }).ogb = { companion };
+ flushSync(() => root.render(createElement(Page)));
+ await vi.waitFor(() => expect(turnOn()?.disabled).toBe(false));
+ turnOn()!.click();
+ await vi.waitFor(() => expect(companion.setRoute).toHaveBeenCalledWith("wifi", true));
+ await vi.waitFor(() => expect(dialog()?.querySelector('[role="alert"]')?.textContent).toBe(
+ "Remote access could not be updated. Open Advanced & troubleshooting and try again.",
+ ));
+ expect(dialog()?.dataset.pairDialog).toBe("consent");
+ expect(companion.pairing).not.toHaveBeenCalled();
+});
diff --git a/src/components/PhoneDevicesSection.tsx b/src/components/PhoneDevicesSection.tsx
index b5bc4aac24..9c2df627da 100644
--- a/src/components/PhoneDevicesSection.tsx
+++ b/src/components/PhoneDevicesSection.tsx
@@ -273,7 +273,7 @@ export function PairDeviceDialog({ c, state, onClose, secureAddress = false, pla
if (c.phase !== "sign-in") setStep("consent");
}, [step, signedIn, c.phase]);
const begin = async () => {
- await c.act((bridge) => setRoute(bridge, picked, true));
+ if (!await c.act((bridge) => setRoute(bridge, picked, true))) return;
setStep("pairing");
c.useLocal();
};
@@ -325,6 +325,7 @@ export function PairDeviceDialog({ c, state, onClose, secureAddress = false, pla
)}
</div>
<p className="text-[12px] leading-4 text-ink-secondary">{t("phone.pair.footShort")}</p>
+ {c.error && <p role="alert" className="text-[12px] leading-4 text-danger">{c.error}</p>}
<div className="flex justify-end gap-2">
<button type="button" className="ui-button" onClick={close}>{t("common.cancel")}</button>
<button type="button" disabled={c.busy} onClick={() => void begin()} className="ui-button ui-button-primary" data-pair-turn-on="">{t("phone.pair.turnOnShow")}</button>