Skip to content

Commit 1da0dc8

Browse files
tellahoCarl
andauthored
fix(agents): show unavailable harnesses in a shared menu (#1941)
Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
1 parent 901b9d8 commit 1da0dc8

11 files changed

Lines changed: 402 additions & 249 deletions

File tree

‎src/bundled/agents/AgentSettingsHost.test.tsx‎

Lines changed: 134 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ import { useAgentSettingsHost } from "./AgentSettingsHost";
1313

1414
afterEach(cleanup);
1515

16-
function fixture({ hosted = true, anotherLocal = true, place = "here" } = {}) {
16+
function fixture({
17+
hosted = true,
18+
anotherLocal = true,
19+
place = "here",
20+
remoteSource = false,
21+
registered = true,
22+
} = {}) {
1723
const agent = {
1824
key: "a".repeat(64),
1925
pubkey: "a".repeat(64),
2026
name: "Ada",
2127
place,
22-
type: "local/echo",
28+
type: remoteSource ? "hosted/builderlab" : "local/echo",
2329
config: {},
2430
} as Agent;
2531
const local = {
26-
key: agent.type,
32+
key: "local/echo",
2733
pluginId: "local",
2834
revision: "1",
2935
id: "echo",
@@ -49,6 +55,9 @@ function fixture({ hosted = true, anotherLocal = true, place = "here" } = {}) {
4955
local,
5056
...(hosted ? [remote] : []),
5157
...(anotherLocal ? [next] : []),
58+
...(remoteSource
59+
? [{ ...next, key: "local/third", id: "third", title: "Third" }]
60+
: []),
5261
];
5362
const previewRetype = vi.fn(() => ({
5463
config: {},
@@ -59,7 +68,12 @@ function fixture({ hosted = true, anotherLocal = true, place = "here" } = {}) {
5968
const retype = vi.fn();
6069
const agents = { previewRetype, retype } as unknown as Agents;
6170
function Host() {
62-
const host = useAgentSettingsHost({ agents, agent, type: local, types });
71+
const host = useAgentSettingsHost({
72+
agents,
73+
agent,
74+
type: registered ? (remoteSource ? remote : local) : undefined,
75+
types,
76+
});
6377
return (
6478
<>
6579
{host.settingsHost.typeControl?.(false)}
@@ -90,15 +104,22 @@ it.each([false, true])(
90104
expect(hosted.querySelector("svg")).not.toBeNull();
91105
await user.hover(hosted);
92106
const help = await screen.findByRole("dialog", {
93-
name: "Builderlab hosting",
107+
name: "Harness availability",
94108
});
95109
expect(help).toHaveTextContent(
96-
"This agent’s signing key is stored on this device. Buzz can’t move that identity to Builderlab yet. To run hosted, create a new Builderlab agent.",
110+
"This agent runs on your device. You can’t switch it to Builderlab yet. To run hosted, create a new Builderlab agent.",
97111
);
98112
await user.hover(help);
99113
expect(screen.getByRole("menu")).toBeVisible();
100114
expect(help).toBeVisible();
101115
await user.hover(hosted);
116+
await user.unhover(hosted);
117+
await waitFor(() =>
118+
expect(
119+
screen.queryByRole("dialog", { name: "Harness availability" }),
120+
).toBeNull(),
121+
);
122+
await user.hover(hosted);
102123
await user.click(hosted);
103124
expect(screen.getByRole("menu")).toBeVisible();
104125
expect(screen.getByLabelText("Selected harness")).toHaveTextContent(
@@ -108,39 +129,43 @@ it.each([false, true])(
108129
expect(previewRetype).not.toHaveBeenCalled();
109130
expect(retype).not.toHaveBeenCalled();
110131
expect(remote.remote.provision).not.toHaveBeenCalled();
111-
await user.unhover(hosted);
132+
await user.keyboard("{Escape}");
112133
await waitFor(() =>
113134
expect(
114-
screen.queryByRole("dialog", { name: "Builderlab hosting" }),
135+
screen.queryByRole("dialog", { name: "Harness availability" }),
115136
).toBeNull(),
116137
);
117-
await user.keyboard("{Home}{ArrowDown}{Enter}");
138+
await user.keyboard("{End}{Enter}");
118139
expect(hosted).toHaveFocus();
119140
expect(
120-
await screen.findByRole("dialog", { name: "Builderlab hosting" }),
141+
await screen.findByRole("dialog", { name: "Harness availability" }),
121142
).toBeVisible();
122-
expect(hosted).toHaveAccessibleDescription(/signing key/);
143+
expect(hosted).toHaveAccessibleDescription(/runs on your device/);
123144
await user.keyboard("{ArrowUp}");
124-
expect(screen.getByRole("menuitemradio", { name: "Echo" })).toHaveFocus();
145+
expect(
146+
screen.getByRole("menuitemradio", {
147+
name: anotherLocal ? "Next" : "Echo",
148+
}),
149+
).toHaveFocus();
125150
await waitFor(() =>
126151
expect(
127-
screen.queryByRole("dialog", { name: "Builderlab hosting" }),
152+
screen.queryByRole("dialog", { name: "Harness availability" }),
128153
).toBeNull(),
129154
);
130155
await user.keyboard("{ArrowDown}{Enter}");
131156
expect(
132-
await screen.findByRole("dialog", { name: "Builderlab hosting" }),
157+
await screen.findByRole("dialog", { name: "Harness availability" }),
133158
).toBeVisible();
134159
await user.keyboard("{Escape}");
135160
await waitFor(() =>
136161
expect(
137-
screen.queryByRole("dialog", { name: "Builderlab hosting" }),
162+
screen.queryByRole("dialog", { name: "Harness availability" }),
138163
).toBeNull(),
139164
);
140165
expect(screen.getByRole("menu")).toBeVisible();
141166
await user.keyboard("{Enter}");
142167
expect(
143-
await screen.findByRole("dialog", { name: "Builderlab hosting" }),
168+
await screen.findByRole("dialog", { name: "Harness availability" }),
144169
).toBeVisible();
145170
expect(previewRetype).not.toHaveBeenCalled();
146171
expect(retype).not.toHaveBeenCalled();
@@ -169,10 +194,96 @@ it("keeps the existing local migration flow available", async () => {
169194
expect(retype).not.toHaveBeenCalled();
170195
});
171196

172-
it.each(["hosted", "elsewhere"])(
173-
"does not offer local migration for an agent %s",
174-
(place) => {
175-
fixture({ place });
176-
expect(screen.queryByRole("button", { name: /Change harness/ })).toBeNull();
177-
},
178-
);
197+
it("does not offer local migration for an agent on another device", () => {
198+
fixture({ place: "elsewhere" });
199+
expect(screen.queryByRole("button", { name: /Change harness/ })).toBeNull();
200+
});
201+
202+
it("shows local harnesses as unavailable for a hosted agent and keeps help keyboard accessible", async () => {
203+
const user = userEvent.setup();
204+
const { previewRetype, retype } = fixture({
205+
place: "hosted",
206+
remoteSource: true,
207+
});
208+
const trigger = screen.getByRole("button", {
209+
name: "Change harness from Builderlab",
210+
});
211+
await user.tab();
212+
expect(trigger).toHaveFocus();
213+
await user.keyboard("{Enter}");
214+
await screen.findByRole("menu");
215+
await user.keyboard("{Home}{ArrowDown}{Enter}");
216+
const local = await screen.findByRole("menuitemradio", { name: "Echo" });
217+
expect(local).toHaveFocus();
218+
expect(local).toHaveAttribute("aria-disabled", "true");
219+
expect(screen.getByRole("menuitemradio", { name: "Next" })).toHaveAttribute(
220+
"aria-disabled",
221+
"true",
222+
);
223+
expect(
224+
screen.getByRole("menuitemradio", { name: "Builderlab" }),
225+
).toBeChecked();
226+
const group = screen.getByRole("group", { name: "Unavailable harnesses" });
227+
const next = screen.getByRole("menuitemradio", { name: "Next" });
228+
expect(group).toContainElement(local);
229+
expect(group).toContainElement(next);
230+
expect(group).toContainElement(
231+
screen.getByRole("menuitemradio", { name: "Third" }),
232+
);
233+
expect(group).toHaveAttribute("tabindex", "-1");
234+
const copy =
235+
"This agent runs on Builderlab. You can’t switch it to a local harness yet. To run locally, create a new agent.";
236+
expect(
237+
await screen.findByRole("dialog", { name: "Harness availability" }),
238+
).toHaveTextContent(copy);
239+
expect(local).toHaveAccessibleDescription(copy);
240+
expect(next).toHaveAccessibleDescription(copy);
241+
const help = screen.getByRole("dialog", { name: "Harness availability" });
242+
expect(group).toHaveAttribute("aria-controls", help.id);
243+
expect(group).toHaveAttribute("aria-haspopup", "false");
244+
expect(group).not.toHaveAttribute("aria-expanded");
245+
expect(local).not.toHaveAttribute("aria-haspopup", "dialog");
246+
expect(next).not.toHaveAttribute("aria-haspopup", "dialog");
247+
await user.keyboard("{ArrowDown}");
248+
expect(next).toHaveFocus();
249+
expect(screen.getByRole("dialog", { name: "Harness availability" })).toBe(
250+
help,
251+
);
252+
await user.keyboard("{ArrowUp}");
253+
await user.keyboard("{Enter}{Space}");
254+
expect(screen.getByRole("menu")).toBeVisible();
255+
expect(screen.getByLabelText("Pending change")).toHaveTextContent("false");
256+
await user.keyboard("{Escape}");
257+
await waitFor(() =>
258+
expect(
259+
screen.queryByRole("dialog", { name: "Harness availability" }),
260+
).toBeNull(),
261+
);
262+
expect(screen.getByRole("menu")).toBeVisible();
263+
await user.hover(group);
264+
const hoveredHelp = await screen.findByRole("dialog", {
265+
name: "Harness availability",
266+
});
267+
await user.hover(local);
268+
await user.hover(next);
269+
expect(screen.getByRole("dialog", { name: "Harness availability" })).toBe(
270+
hoveredHelp,
271+
);
272+
await user.click(local);
273+
expect(screen.getByRole("menu")).toBeVisible();
274+
expect(previewRetype).not.toHaveBeenCalled();
275+
expect(retype).not.toHaveBeenCalled();
276+
});
277+
278+
it("withholds the harness control for a hosted agent whose type is unregistered", () => {
279+
const { previewRetype, retype } = fixture({
280+
place: "hosted",
281+
remoteSource: true,
282+
hosted: false,
283+
registered: false,
284+
});
285+
expect(screen.queryByRole("button", { name: /Change harness/ })).toBeNull();
286+
expect(screen.getByLabelText("Pending change")).toHaveTextContent("false");
287+
expect(previewRetype).not.toHaveBeenCalled();
288+
expect(retype).not.toHaveBeenCalled();
289+
});

0 commit comments

Comments
 (0)