Skip to content

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

Merge origin/main into train/nov16-s2

milind-sonic1d18144a530
diff --cc src/components/EngineSetup.antigravity.test.ts
index b7e9038330,6f84470038..69529f05ca
--- a/src/components/EngineSetup.antigravity.test.ts
+++ b/src/components/EngineSetup.antigravity.test.ts
@@@ -35,45 -35,60 +35,77 @@@ afterEach(() =>
vi.unstubAllGlobals();
});
- async function startSignIn(cloudHome: boolean, ogb: object): Promise<HTMLDetailsElement> {
- vi.stubGlobal("ogb", { platform: "linux", openExternal: vi.fn(async () => {}), ...ogb });
- const store = { state: { config: cloudHome ? { cloudHome: true } : {} }, dispatch: vi.fn(), refreshInstances: vi.fn(async () => {}), refreshModels: vi.fn(async () => {}) } as unknown as ReturnType<typeof useStore>;
+ function auth(body: object) {
+ return new Response(JSON.stringify({ auth: body }), { status: 200, headers: { "content-type": "application/json" } });
+ }
+
-async function startSignIn(status: object, ogb: object = { remoteClient: { active: false } }) {
++async function startSignIn(status: object, ogb: object = { remoteClient: { active: false } }, config: object = {}) {
+ const openExternal = vi.fn(async () => {});
+ vi.stubGlobal("ogb", { platform: "linux", openExternal, ...ogb });
+ const fetched = vi.fn(async (input: RequestInfo | URL) => String(input).includes("/auth/status")
+ ? auth(status)
+ : auth({ phase: "waiting", flowId: "flow-1", authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth?state=s" }));
+ vi.stubGlobal("fetch", fetched);
- const store = { state: { config: {} }, dispatch: vi.fn(), refreshInstances: vi.fn(async () => {}), refreshModels: vi.fn(async () => {}) } as unknown as ReturnType<typeof useStore>;
++ const store = { state: { config }, dispatch: vi.fn(), refreshInstances: vi.fn(async () => {}), refreshModels: vi.fn(async () => {}) } as unknown as ReturnType<typeof useStore>;
flushSync(() => root.render(createElement(BotEditorStore, { value: store, children: createElement(EngineSetup, { instance: antigravity }) })));
- const button = [...host.querySelectorAll("button")].find((b) => b.textContent?.includes("Sign in with Google"))!;
- button.click();
- await vi.waitFor(() => expect(host.querySelector("details")).not.toBeNull());
- return host.querySelector("details")!;
+ const button = () => [...host.querySelectorAll("button")].find((b) => /Sign in with Google|Open Google sign-in again/.test(b.textContent ?? ""))!;
+ button().click();
+ await vi.waitFor(() => expect(host.querySelector("[data-redirect-paste]")).not.toBeNull());
+ return { store, fetched, openExternal, button };
}
- it("opens the paste-the-redirect step on a Cloud, where Google's 127.0.0.1 redirect can't reach the server", async () => {
- expect((await startSignIn(true, { remoteClient: { active: false } })).open).toBe(true);
- });
+ it("shows the paste-the-redirect field the whole time the card waits, on the person's own computer too", async () => {
+ await startSignIn({ phase: "waiting", flowId: "flow-1" });
+ const field = host.querySelector<HTMLInputElement>("[data-redirect-paste] input")!;
+ expect(field.getAttribute("aria-label")).toBeTruthy();
+ expect(host.querySelector("details")).toBeNull();
+ await new Promise((resolve) => setTimeout(resolve, 2_300));
+ expect(host.querySelector("[data-redirect-paste] input")).not.toBeNull();
+ }, 15_000);
- it("opens it on a desktop paired to another computer's server", async () => {
- expect((await startSignIn(false, { remoteClient: { active: true } })).open).toBe(true);
+ it("opens the same Google link again instead of starting another sign-in", async () => {
+ const { fetched, openExternal, button } = await startSignIn({ phase: "waiting", flowId: "flow-1" });
+ await vi.waitFor(() => expect(button().textContent).toContain("Open Google sign-in again"));
+ button().click();
+ await vi.waitFor(() => expect(openExternal).toHaveBeenCalledTimes(2));
+ expect(fetched.mock.calls.filter(([input]) => String(input).includes("/auth/start"))).toHaveLength(1);
});
- it("keeps it folded on the person's own computer, where the redirect lands by itself", async () => {
- expect((await startSignIn(false, { remoteClient: { active: false } })).open).toBe(false);
- });
+ it("says the sign-in expired and offers to start again, once the server reports it", async () => {
+ const { button } = await startSignIn({ phase: "expired", flowId: "flow-1", message: "Google sign-in expired. Start sign-in again." });
+ await vi.waitFor(() => expect(host.textContent).toContain("Google sign-in expired. Start again."), { timeout: 6_000 });
+ expect(host.querySelector("[data-redirect-paste]")).toBeNull();
+ expect(button().textContent).toContain("Sign in with Google");
+ }, 15_000);
+
+ it("shows the server's fixed reason when the sign-in fails", async () => {
+ await startSignIn({ phase: "failed", flowId: "flow-1", message: "Google sign-in was not approved. Start sign-in again." });
+ await vi.waitFor(() => expect(host.textContent).toContain("Google sign-in was not approved. Start sign-in again."), { timeout: 6_000 });
+ }, 15_000);
+
+ it("reads the engines and their models when the sign-in finishes by itself", async () => {
+ const { store } = await startSignIn({ phase: "succeeded", flowId: "flow-1" });
+ await vi.waitFor(() => expect(store.refreshModels).toHaveBeenCalledWith("antigravity"), { timeout: 6_000 });
+ await vi.waitFor(() => expect(host.querySelector("[data-redirect-paste]")).toBeNull());
+ }, 15_000);
+// A Cloud's person saw Google's last page fail on 127.0.0.1 and read it as a broken sign-in: on a Cloud the card says up front
+// that this page won't load and that its address goes in the box, which it names for that.
+const cloudHint = "After you sign in, Google opens a page that won’t load. Copy its address and paste it below.";
+
+it("tells a Cloud's person, before they sign in, that Google's last page won't load and its address goes below", async () => {
- const details = await startSignIn(true, { remoteClient: { active: false } });
- expect(details.querySelector("summary")?.textContent).toBe("Google’s page didn’t load? Paste its address here");
++ await startSignIn({ phase: "waiting", flowId: "flow-1" }, { remoteClient: { active: false } }, { cloudHome: true });
++ expect(host.querySelector("[data-redirect-paste] p")?.textContent).toBe("Google’s page didn’t load? Paste its address here");
+ const hint = [...host.querySelectorAll("p")].find((p) => p.textContent === cloudHint)!;
+ expect(hint.nextElementSibling?.textContent).toContain("Open Google sign-in again");
+});
+
+it.each([false, true])("keeps the other-computer wording off a Cloud (paired to another computer: %s)", async (remote) => {
- const details = await startSignIn(false, { remoteClient: { active: remote } });
- expect(details.querySelector("summary")?.textContent).toBe("Signing in from another computer?");
++ await startSignIn({ phase: "waiting", flowId: "flow-1" }, { remoteClient: { active: remote } });
++ expect(host.querySelector("[data-redirect-paste] p")?.textContent).toBe("Signing in from another computer?");
+ expect(host.textContent).not.toContain(cloudHint);
+});
+
it("names Google on the sign-in card, never another provider", () => {
vi.stubGlobal("ogb", { platform: "linux", remoteClient: { active: false } });
const store = { state: { config: {} }, dispatch: vi.fn(), refreshInstances: vi.fn(async () => {}), refreshModels: vi.fn(async () => {}) } as unknown as ReturnType<typeof useStore>;
diff --cc src/components/EngineSetup.tsx
index 02f09b26c6,5197decfdb..4ae5e1cba9
--- a/src/components/EngineSetup.tsx
+++ b/src/components/EngineSetup.tsx
@@@ -379,8 -399,8 +401,8 @@@ function ManagedEngineSetup({ instance
<button type="button" onClick={() => void check()} className="w-full rounded-lg bg-control px-3 py-2 text-[12px] font-semibold text-ink hover:bg-raised-hover">
{busy === "check" ? t("common.checking") : t("engineSetup.finishedSignIn")}
</button>
- <details open={redirectPasteOpen(cloudHome)} className="rounded-lg border border-hairline/50 bg-app px-2.5 py-2 text-[12px] text-ink-secondary">
- <summary className="cursor-pointer select-none">{t(cloudHome ? "engineSetup.cloudPasteSummary" : "engineSetup.otherComputer")}</summary>
+ <div data-redirect-paste className="rounded-lg border border-hairline/50 bg-app px-2.5 py-2 text-[12px] text-ink-secondary">
- <p>{t("engineSetup.otherComputer")}</p>
++ <p>{t(cloudHome ? "engineSetup.cloudPasteSummary" : "engineSetup.otherComputer")}</p>
<p className="mt-2 leading-relaxed">{t("engineSetup.otherComputerHint")}</p>
<input
value={callbackUrl}