Skip to content

Commit 9818f77

Browse files
tellahoCarl
andauthored
fix(builderlab): keep identity fields visible while loading (#1936)
Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
1 parent 4692666 commit 9818f77

13 files changed

Lines changed: 558 additions & 250 deletions

File tree

‎src/bundled/builderlab/adapter-type/Instructions.test.tsx‎

Lines changed: 125 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,126 @@ function fixture() {
121121
},
122122
};
123123
}
124+
async function loadedInstructions() {
125+
const field = screen.getByRole("textbox", { name: "Instructions" });
126+
await waitFor(() => expect(field).toBeEnabled());
127+
return field;
128+
}
129+
it.each([false, true])(
130+
"keeps the full form mounted across settings and catalog loading (catalog fails: %s)",
131+
async (fails) => {
132+
const h = fixture();
133+
const user = userEvent.setup();
134+
const settings = deferred<HostResponse>();
135+
const catalog = deferred<HostResponse>();
136+
const data = JSON.parse(response().body);
137+
Object.assign(data.agents[0], {
138+
model_id: "one",
139+
reasoning_effort: "high",
140+
model_selection_status: 1,
141+
});
142+
const settingsResponse = { ...response(), body: JSON.stringify(data) };
143+
const request = h.request.getMockImplementation();
144+
if (!request) throw new Error("Missing request fixture");
145+
h.request.mockImplementation((input) => {
146+
if (input.url.endsWith("/list-agents")) return settings.promise;
147+
if (input.url.endsWith("/get-model-catalog")) return catalog.promise;
148+
return request(input);
149+
});
150+
render(<h.Tab agent={agent()} save={vi.fn()} />, { wrapper: StrictMode });
151+
const field = screen.getByRole("textbox", { name: "Instructions" });
152+
const harness = screen.getByRole("button", { name: "Harness: Builderlab" });
153+
const model = screen.getByRole("button", { name: "Model: …" });
154+
const thinking = screen.getByRole("combobox", { name: "Thinking" });
155+
const region = field.closest("[aria-busy]");
156+
try {
157+
await waitFor(() =>
158+
expect(h.request).toHaveBeenCalledWith(
159+
expect.objectContaining({
160+
url: expect.stringContaining("/list-agents"),
161+
}),
162+
),
163+
);
164+
expect(region).toHaveAttribute("aria-busy", "true");
165+
expect(region?.querySelector(".sr-only")).toBeInTheDocument();
166+
expect(region?.querySelector(".buzz-loading-region-feedback")).toBeNull();
167+
expect(model).toBeDisabled();
168+
expect(model.querySelector(".buzz-select-leading")).toBeNull();
169+
expect(thinking).toBeDisabled();
170+
expect(field).toBeDisabled();
171+
expect(field).toHaveValue("");
172+
await user.type(field, "Must not become a draft.");
173+
expect(field).toHaveValue("");
174+
expect(screen.queryByRole("button", { name: "Save" })).toBeNull();
175+
act(() => harness.focus());
176+
await act(async () => settings.resolve(settingsResponse));
177+
await waitFor(() => expect(field).toBeEnabled());
178+
await waitFor(() =>
179+
expect(h.request).toHaveBeenCalledWith(
180+
expect.objectContaining({
181+
url: expect.stringContaining("/get-model-catalog"),
182+
}),
183+
),
184+
);
185+
expect(harness).toHaveFocus();
186+
expect(screen.getByRole("textbox", { name: "Instructions" })).toBe(field);
187+
expect(field).toHaveValue("First instructions.");
188+
expect(region).toHaveAttribute("aria-busy", "true");
189+
expect(region?.querySelector(".sr-only")).toBeInTheDocument();
190+
expect(model).toBeDisabled();
191+
expect(thinking).toBeDisabled();
192+
await user.type(field, " Draft.");
193+
if (fails) {
194+
await act(async () =>
195+
catalog.resolve({ status: 400, headers: {}, body: "{}" }),
196+
);
197+
expect(await screen.findByRole("alert")).toHaveTextContent("HTTP 400");
198+
expect(model).toHaveTextContent("Unavailable");
199+
expect(model.querySelector(".buzz-select-leading")).toBeNull();
200+
expect(model).toBeDisabled();
201+
expect(thinking).toBeDisabled();
202+
h.request.mockImplementation(request);
203+
await user.click(screen.getByRole("button", { name: "Retry models" }));
204+
} else {
205+
const result = await request({
206+
url: "https://builderlab.example/get-model-catalog",
207+
method: "POST",
208+
});
209+
await act(async () => catalog.resolve(result));
210+
}
211+
await waitFor(() => expect(model).toBeEnabled());
212+
expect(model).toHaveTextContent("Friendly Model");
213+
expect(thinking).toHaveTextContent("High");
214+
expect(region).toHaveAttribute("aria-busy", "false");
215+
expect(field).toHaveValue("First instructions. Draft.");
216+
expect(screen.getByRole("button", { name: /^Model:/ })).toBe(model);
217+
expect(screen.getByRole("combobox", { name: "Thinking" })).toBe(thinking);
218+
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
219+
} finally {
220+
await act(async () => {
221+
settings.resolve(response());
222+
catalog.resolve({ status: 200, headers: {}, body: '{"models":[]}' });
223+
});
224+
}
225+
},
226+
);
124227
it("retries a failed load and refuses to save a draft through another account", async () => {
125228
const h = fixture();
126229
const user = userEvent.setup();
127230
h.request.mockResolvedValueOnce({ ...response(), status: 400 });
128231
render(<h.Tab agent={agent()} save={vi.fn()} />, { wrapper: StrictMode });
129232
expect(await screen.findByRole("alert")).toHaveTextContent("HTTP 400");
233+
expect(
234+
screen.getByRole("button", { name: "Harness: Builderlab" }),
235+
).toBeVisible();
236+
expect(
237+
screen.getByRole("button", { name: "Model: Unavailable" }),
238+
).toBeDisabled();
239+
expect(screen.getByRole("combobox", { name: "Thinking" })).toBeDisabled();
240+
expect(screen.getByRole("textbox", { name: "Instructions" })).toBeDisabled();
241+
expect(screen.queryByRole("button", { name: "Save" })).toBeNull();
130242
await user.click(screen.getByRole("button", { name: "Retry" }));
131-
const field = await screen.findByRole("textbox", { name: "Instructions" });
243+
const field = await loadedInstructions();
132244
expect(field).toHaveValue("First instructions.");
133245
await user.type(field, "Changed.");
134246
await act(async () => h.changeAccount());
@@ -146,7 +258,7 @@ it("switching agents hides the old draft and ignores the switched-away read", as
146258
const mounted = render(<h.Tab agent={agent()} save={vi.fn()} />, {
147259
wrapper: StrictMode,
148260
});
149-
const field = await screen.findByRole("textbox", { name: "Instructions" });
261+
const field = await loadedInstructions();
150262
await user.type(field, "Unsaved.");
151263
const delayed = deferred<HostResponse>();
152264
h.request.mockReturnValueOnce(delayed.promise);
@@ -159,14 +271,14 @@ it("switching agents hides the old draft and ignores the switched-away read", as
159271
),
160272
).toHaveLength(2),
161273
);
162-
expect(screen.getByRole("status")).toHaveTextContent("Loading settings");
163274
expect(
164-
screen.queryByRole("textbox", { name: "Instructions" }),
165-
).not.toBeInTheDocument();
275+
screen.getByRole("textbox", { name: "Instructions" }),
276+
).toBeDisabled();
277+
expect(screen.getByRole("textbox", { name: "Instructions" })).toHaveValue(
278+
"",
279+
);
166280
mounted.rerender(<h.Tab agent={agent()} save={vi.fn()} />);
167-
expect(
168-
await screen.findByRole("textbox", { name: "Instructions" }),
169-
).toHaveValue("First instructions.");
281+
expect(await loadedInstructions()).toHaveValue("First instructions.");
170282
} finally {
171283
await act(async () => {
172284
delayed.resolve(response());
@@ -252,7 +364,7 @@ it("keeps hosted instructions on cancellation and resets a confirmed discard", a
252364
"aria-selected",
253365
"true",
254366
);
255-
const field = await screen.findByRole("textbox", { name: "Instructions" });
367+
const field = await loadedInstructions();
256368
expect(await screen.findByRole("button", { name: /^Model:/ })).toBeVisible();
257369
expect(screen.getByRole("combobox", { name: "Thinking" })).toBeVisible();
258370
expect(screen.queryByText("Workspace")).toBeNull();
@@ -308,7 +420,7 @@ it("keeps hosted instructions on cancellation and resets a confirmed discard", a
308420
expect(screen.queryByRole("button", { name: /^Model:/ })).toBeNull();
309421
expect(screen.queryByRole("combobox", { name: "Thinking" })).toBeNull();
310422
await user.click(screen.getByRole("tab", { name: "Identity" }));
311-
const fresh = await screen.findByRole("textbox", { name: "Instructions" });
423+
const fresh = await loadedInstructions();
312424
expect(fresh).not.toBe(field);
313425
expect(fresh).toHaveValue("First instructions.");
314426
expect(screen.queryByRole("alert")).toBeNull();
@@ -320,7 +432,7 @@ it("guards hosted model drafts and a pending model save", async () => {
320432
const h = fixture();
321433
const user = userEvent.setup();
322434
renderTabs(h);
323-
await screen.findByRole("textbox", { name: "Instructions" });
435+
await loadedInstructions();
324436
const modelTrigger = await screen.findByRole("button", { name: /^Model:/ });
325437
await waitFor(() => expect(modelTrigger).toBeEnabled());
326438
await user.click(modelTrigger);
@@ -361,9 +473,7 @@ it("guards hosted model drafts and a pending model save", async () => {
361473
expect(screen.getByText("Agent settings")).toBeVisible();
362474
expect(screen.queryByRole("button", { name: /^Model:/ })).toBeNull();
363475
await user.click(screen.getByRole("tab", { name: "Identity" }));
364-
expect(
365-
await screen.findByRole("textbox", { name: "Instructions" }),
366-
).toHaveValue("First instructions.");
476+
expect(await loadedInstructions()).toHaveValue("First instructions.");
367477
expect(
368478
await screen.findByRole("button", { name: /^Model:/ }),
369479
).toHaveTextContent("Choose a model");
@@ -377,7 +487,7 @@ it("saves model and instructions together through one footer action", async () =
377487
const h = fixture();
378488
const user = userEvent.setup();
379489
renderTabs(h);
380-
const field = await screen.findByRole("textbox", { name: "Instructions" });
490+
const field = await loadedInstructions();
381491
expect(screen.queryByRole("button", { name: "Save" })).toBeNull();
382492
const modelTrigger = await screen.findByRole("button", { name: /^Model:/ });
383493
await waitFor(() => expect(modelTrigger).toBeEnabled());

‎src/bundled/builderlab/adapter-type/Instructions.tsx‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useEffect, useState } from "react";
22
import type { AgentViewProps } from "../../../features/agents/service";
3-
import { Button } from "../../../shared/design-system/ui/Button";
43
import { PreferenceRow } from "../../../shared/design-system/ui/PreferenceRow";
54
import { SettingsGroup } from "../../../shared/design-system/ui/SettingsGroup";
65
import inlineStyles from "../../../shared/InlineReference.module.css";
@@ -49,31 +48,11 @@ export function createSettingsTab(client: AgentClient, session: OAuthSession) {
4948
return () => current.abort();
5049
}, [pubkey]);
5150
return (
52-
<div className="grid gap-4">
53-
{loaded && (
54-
<ModelSettings
55-
client={client}
56-
session={session}
57-
agent={loaded.agent}
58-
subject={loaded.subject}
59-
/>
60-
)}
61-
{!loaded &&
62-
(busy ? (
63-
<p role="status" className="m-0 text-body-sm text-secondary">
64-
Loading settings…
65-
</p>
66-
) : (
67-
<div>
68-
<Button onClick={retry}>Retry</Button>
69-
</div>
70-
))}
71-
{error && (
72-
<p role="alert" className="m-0 text-body-sm text-danger">
73-
{error}
74-
</p>
75-
)}
76-
</div>
51+
<ModelSettings
52+
client={client}
53+
session={session}
54+
settings={loaded ?? { pending: busy, error, retry }}
55+
/>
7756
);
7857
}
7958
return function Settings({

‎src/bundled/builderlab/adapter-type/ModelSettings.test.tsx‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,26 @@ async function fixture(
9393
session,
9494
null,
9595
);
96-
render(<ModelSettings {...{ client, session, agent }} subject="account" />, {
97-
wrapper: ({ children }) => (
98-
<StrictMode>
99-
<ToastProvider>{children}</ToastProvider>
100-
</StrictMode>
101-
),
102-
});
103-
await waitFor(() => expect(screen.queryByText("Loading models…")).toBeNull());
96+
render(
97+
<ModelSettings
98+
{...{ client, session }}
99+
settings={{ agent, subject: "account" }}
100+
/>,
101+
{
102+
wrapper: ({ children }) => (
103+
<StrictMode>
104+
<ToastProvider>{children}</ToastProvider>
105+
</StrictMode>
106+
),
107+
},
108+
);
109+
await waitFor(() =>
110+
expect(
111+
screen
112+
.getByRole("textbox", { name: "Instructions" })
113+
.closest("[aria-busy]"),
114+
).toHaveAttribute("aria-busy", "false"),
115+
);
104116
return {
105117
request,
106118
session,

0 commit comments

Comments
 (0)