Skip to content

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

Settings: Try again after the teammate list fails, no Close mid-add (review on #7113)

Bugfixer 2a328ac1c6ae2
diff --git a/src/components/RemoteTeammatesSettings.dom.test.ts b/src/components/RemoteTeammatesSettings.dom.test.ts
index 7d71fc1cd0..6286b89896 100644
--- a/src/components/RemoteTeammatesSettings.dom.test.ts
+++ b/src/components/RemoteTeammatesSettings.dom.test.ts
@@ -9,13 +9,19 @@ const fixture = vi.hoisted(() => ({
calls: [] as Array<{ path: string; method: string; body?: Record<string, string> }>,
check: { ok: true } as Record<string, unknown>,
addError: null as string | null,
+ listError: null as string | null,
+ addGate: null as Promise<void> | null,
}));
vi.mock("@/state/store", () => ({
api: async (path: string, init: { method?: string; body?: string } = {}) => {
const method = init.method ?? "GET";
fixture.calls.push({ path, method, ...(init.body ? { body: JSON.parse(init.body) } : {}) });
- if (path === "/api/remote-teammates" && method === "GET") return { teammates: fixture.teammates };
+ if (path === "/api/remote-teammates" && method === "GET") {
+ if (fixture.listError) throw new Error(fixture.listError);
+ return { teammates: fixture.teammates };
+ }
if (path === "/api/remote-teammates" && method === "POST") {
+ await fixture.addGate;
if (fixture.addError) throw new Error(fixture.addError);
const body = JSON.parse(init.body!);
return { teammate: { id: "22222222-2222-4222-8222-222222222222", name: body.name, base: body.address, botId: body.botId, createdAt: "2026-11-23T00:00:00.000Z" } };
@@ -31,7 +37,7 @@ const SAVED: Teammate = { id: "11111111-1111-4111-8111-111111111111", name: "Sal
let container: HTMLDivElement, root: Root;
beforeEach(() => {
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
- Object.assign(fixture, { teammates: [], calls: [], check: { ok: true }, addError: null });
+ Object.assign(fixture, { teammates: [], calls: [], check: { ok: true }, addError: null, listError: null, addGate: null });
container = document.createElement("div"); document.body.append(container); root = createRoot(container);
});
afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.unstubAllGlobals(); });
@@ -114,3 +120,42 @@ it("removes a teammate only after asking, and drops the note that it was added",
expect(container.textContent).not.toContain("Sales desk");
expect(container.textContent).toContain("No teammates on other servers yet.");
});
+
+it("loads the list again on Try again after it could not be read", async () => {
+ fixture.listError = "server unreachable";
+ await render();
+ expect(container.querySelector('[role="alert"]')!.textContent).toBe("server unreachable");
+ expect(button("Add")).toBeUndefined();
+ fixture.listError = null;
+ fixture.teammates = [SAVED];
+ await click("Try again");
+ expect(fixture.calls.filter((call) => call.method === "GET")).toHaveLength(2);
+ expect(container.querySelector('[role="alert"]')).toBeNull();
+ expect(container.textContent).toContain("sales-bot · https://bots.example.com");
+ expect(button("Add")).toBeTruthy();
+});
+
+it("keeps the form open while a teammate is being added, so its answer can't close a newer draft", async () => {
+ let release!: () => void;
+ fixture.addGate = new Promise((done) => { release = done; });
+ await render();
+ await click("Add");
+ await input("Name", "Sales desk");
+ await input("Address", "https://bots.example.com");
+ await input("Bot API key", "bak_fixture_key_0123456789");
+ await click("Add teammate");
+ expect(button("Close")!.disabled).toBe(true);
+ await act(async () => { release(); await fixture.addGate; });
+ expect(container.textContent).toContain("Sales desk was added.");
+ expect(button("Add")!.disabled).toBe(false);
+ // After a refused add, Close works again.
+ fixture.addError = "that bot is already a teammate";
+ await click("Add");
+ await input("Name", "Sales desk");
+ await input("Address", "https://bots.example.com");
+ await input("Bot API key", "bak_fixture_key_0123456789");
+ await click("Add teammate");
+ expect(button("Close")!.disabled).toBe(false);
+ await click("Close");
+ expect(container.querySelector('input[aria-label="Name"]')).toBeNull();
+});
diff --git a/src/components/RemoteTeammatesSettings.tsx b/src/components/RemoteTeammatesSettings.tsx
index 4cd4b26c5e..7001c9b02b 100644
--- a/src/components/RemoteTeammatesSettings.tsx
+++ b/src/components/RemoteTeammatesSettings.tsx
@@ -33,9 +33,9 @@ const failure = (cause: unknown) => (cause instanceof Error && cause.message ? c
interface Draft { name: string; address: string; botId: string; key: string }
-function AddTeammateForm({ onAdded }: { onAdded: (teammate: RemoteTeammate) => void }) {
+/** `saving` is the card's: the form can't be closed while an add is on its way, or its answer would close a newer draft. */
+function AddTeammateForm({ onAdded, saving, setSaving }: { onAdded: (teammate: RemoteTeammate) => void; saving: boolean; setSaving: (saving: boolean) => void }) {
const [draft, setDraft] = useState<Draft>({ name: "", address: "", botId: "", key: "" });
- const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
const field = (key: keyof Draft) => ({
value: draft[key],
@@ -155,6 +155,9 @@ export function RemoteTeammatesSettings() {
const [error, setError] = useState<string | null>(null);
const [open, setOpen] = useState(false);
const [notice, setNotice] = useState<string | null>(null);
+ const [saving, setSaving] = useState(false);
+ /** Each Try again after a failed load reads the list once more. */
+ const [attempt, setAttempt] = useState(0);
useEffect(() => {
const controller = new AbortController();
@@ -162,13 +165,18 @@ export function RemoteTeammatesSettings() {
.then((loaded) => { if (!controller.signal.aborted) setTeammates(loaded.teammates); })
.catch((cause: unknown) => { if (!controller.signal.aborted) setError(failure(cause)); });
return () => controller.abort();
- }, []);
+ }, [attempt]);
return (
<SettingsGroup label={t("settings.remoteTeammates.title")} block="remote-teammates">
<SettingsRows>
{!teammates && !error && <SettingsSkeletonRows />}
- {error && <SettingsEmptyRow><span role="alert" className="text-danger">{error}</span></SettingsEmptyRow>}
+ {error && <SettingsEmptyRow>
+ <span className="flex items-center justify-between gap-3">
+ <span role="alert" className="text-danger">{error}</span>
+ <button type="button" className="ui-button" onClick={() => { setError(null); setAttempt((count) => count + 1); }}>{t("common.tryAgain")}</button>
+ </span>
+ </SettingsEmptyRow>}
{teammates?.length === 0 && <SettingsEmptyRow>{t("settings.remoteTeammates.empty")}</SettingsEmptyRow>}
{teammates?.map((teammate) => (
<TeammateRow key={teammate.id} teammate={teammate}
@@ -177,11 +185,11 @@ export function RemoteTeammatesSettings() {
{teammates && <>
<SettingRow title={t("settings.remoteTeammates.add")} subtitle={t("settings.remoteTeammates.line")}
message={!open && notice ? <span role="status">{notice}</span> : undefined}>
- <button type="button" className="ui-button" aria-expanded={open} onClick={() => { setOpen(!open); setNotice(null); }}>
+ <button type="button" className="ui-button" aria-expanded={open} disabled={saving} onClick={() => { setOpen(!open); setNotice(null); }}>
{t(open ? "common.close" : "settings.remoteTeammates.addButton")}
</button>
</SettingRow>
- {open && <AddTeammateForm onAdded={(teammate) => {
+ {open && <AddTeammateForm saving={saving} setSaving={setSaving} onAdded={(teammate) => {
setTeammates((current) => [...(current ?? []), teammate]);
setOpen(false);
setNotice(t("settings.remoteTeammates.added", { name: teammate.name }));