Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions apps/web/src/components/chat/ComposerModelEffort.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import { useState } from "react";
import { expect, it } from "vite-plus/test";
import { page, userEvent } from "vite-plus/test/browser";

import "~/index.css";

import { render } from "../../../test/render";
import { deriveProviderInstanceEntries } from "../../providerInstances";
import { ComposerEffortColumn, describeComposerEffort } from "./ComposerModelEffort";
import { ProviderModelPicker } from "./ProviderModelPicker";
import type { TraitsSelectionInput } from "./TraitsPicker";

// Shaped like Devin over ACP: its session mode comes first, and its reasoning id is its own.
Expand Down Expand Up @@ -123,3 +127,130 @@ it("draws an agent's reasoning as bars and keeps its mode out of the levels", as
.toBeInTheDocument();
await expect.element(page.getByRole("menuitemradio")).not.toBeInTheDocument();
});

it("focuses a reasoning level by its first letter without selecting it", async () => {
await using screen = await render(<Column />, { router: false }); // no routes involved
await userEvent.tab();
await expect.element(screen.getByRole("radio", { name: "Medium" })).toHaveFocus();
await userEvent.keyboard("l");
await expect.element(screen.getByRole("radio", { name: "Low" })).toHaveFocus();
await expect
.element(screen.getByRole("radio", { name: "Medium" }))
.toHaveAttribute("aria-checked", "true");
for (const key of ["{Control>}h{/Control}", "{Meta>}h{/Meta}", "{Alt>}h{/Alt}", "{Delete}"]) {
await userEvent.keyboard(key);
await expect.element(screen.getByRole("radio", { name: "Low" })).toHaveFocus();
}
await userEvent.keyboard("H");
await expect.element(screen.getByRole("radio", { name: "High" })).toHaveFocus();
await userEvent.keyboard("{ArrowUp}");
await expect.element(screen.getByRole("radio", { name: "Medium" })).toHaveFocus();
await userEvent.keyboard("{ArrowDown}{Enter}");
await expect
.element(screen.getByRole("radio", { name: "High" }))
.toHaveAttribute("aria-checked", "true");
});

it("cycles effort labels inside the picker while keeping search and dismissal independent", async () => {
const model: ServerProviderModel = {
slug: "fusion",
name: "Fusion",
isCustom: false,
capabilities: createModelCapabilities({
optionDescriptors: [
{
id: "thought_level",
label: "Thinking",
type: "select",
role: "reasoning",
currentValue: "balanced",
promptInjectedValues: ["ultrathink"],
options: [
{ id: "small", label: "Minimal" },
{ id: "balanced", label: "Medium" },
{ id: "large", label: "Max", isDefault: true },
{ id: "light", label: "Low" },
],
},
{
id: "speed",
label: "Speed",
type: "select",
currentValue: "standard",
options: [{ id: "standard", label: "Standard" }],
},
],
}),
};
const instanceId = ProviderInstanceId.make("devin");
const entries = deriveProviderInstanceEntries([
{
instanceId,
driver: ProviderDriverKind.make("acpRegistry"),
enabled: true,
installed: true,
version: null,
status: "ready",
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00.000Z",
models: [model],
slashCommands: [],
skills: [],
},
]);

function Picker({ locked = false }: { locked?: boolean }) {
const [options, setOptions] = useState<ReadonlyArray<ProviderOptionSelection>>([]);
const traits: TraitsSelectionInput = {
...traitsInput(options, (next) => setOptions(next ?? [])),
models: [model],
promptUltrathink: locked ? "body" : "none",
};
return (
<ProviderModelPicker
environmentId={null}
activeInstanceId={instanceId}
model={model.slug}
lockedProvider={null}
instanceEntries={entries}
modelOptionsByInstance={new Map([[instanceId, [model]]])}
triggerAriaLabel="Choose model"
onInstanceModelChange={() => {}}
effortColumn={<ComposerEffortColumn traits={traits} />}
/>
);
}

await using screen = await render(<Picker />);
await screen.getByRole("button", { name: "Choose model" }).click();
const search = page.getByPlaceholder("Search models...");
await userEvent.keyboard("m");
await expect.element(search).toHaveValue("m");
await expect.element(search).toHaveFocus();
await userEvent.clear(search);
await userEvent.keyboard("{ArrowRight}");
await expect.element(page.getByRole("radio", { name: "Medium" })).toHaveFocus();

for (const name of [/^Max/, "Minimal", "Medium"]) {
await userEvent.keyboard("m");
await expect.element(page.getByRole("radio", { name, exact: true })).toHaveFocus();
}
await userEvent.keyboard("l{Enter}");
const low = page.getByRole("radio", { name: "Low" });
await expect.element(low).toHaveFocus();
await expect.element(low).toHaveAttribute("aria-checked", "true");
await expect.element(search).toHaveValue("");
await userEvent.keyboard("{Escape}");
await expect.element(search).not.toBeInTheDocument();
await expect.element(screen.getByRole("button", { name: "Choose model" })).toHaveFocus();

await screen.rerender(<Picker locked />);
await screen.getByRole("button", { name: "Choose model" }).click();
await expect.element(low).toBeDisabled();
await userEvent.keyboard("{ArrowRight}");
const speed = page.getByRole("button", { name: "Speed: Standard" });
await expect.element(speed).toHaveFocus();
const keydown = new KeyboardEvent("keydown", { key: "l", bubbles: true, cancelable: true });
expect(speed.element().dispatchEvent(keydown)).toBe(true);
await expect.element(speed).toHaveFocus();
});
21 changes: 17 additions & 4 deletions apps/web/src/components/chat/ComposerModelEffort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function ColumnRow(props: {
disabled: props.disabled,
"data-effort-row": true,
// Focus lands on a level after a model pick.
"data-effort-level": true,
"data-effort-level": props.label,
// Up and Down move between rows.
tabIndex: props.tabStop ? 0 : -1,
className: COLUMN_ROW,
Expand Down Expand Up @@ -222,15 +222,28 @@ function ColumnRow(props: {
}

function moveBetweenRows(event: KeyboardEvent<HTMLElement>) {
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
const arrow = event.key === "ArrowDown" || event.key === "ArrowUp";
if (
!arrow &&
(event.key.length !== 1 ||
event.key.trim() === "" ||
event.ctrlKey ||
event.altKey ||
event.metaKey ||
event.nativeEvent.isComposing)
)
return;
// An option's side menu is a React child here, but it moves through its own items.
if (!event.currentTarget.contains(event.target as Node)) return;
const rows = Array.from(
event.currentTarget.querySelectorAll<HTMLButtonElement>("[data-effort-row]:not(:disabled)"),
);
const index = rows.findIndex((row) => row === document.activeElement);
const next =
rows[Math.min(rows.length - 1, Math.max(0, index + (event.key === "ArrowDown" ? 1 : -1)))];
const next = arrow
? rows[Math.min(rows.length - 1, Math.max(0, index + (event.key === "ArrowDown" ? 1 : -1)))]
: [...rows.slice(index + 1), ...rows.slice(0, index + 1)].find((row) =>
row.dataset.effortLevel?.toLowerCase().startsWith(event.key.toLowerCase()),
);
if (!next) return;
event.preventDefault();
event.stopPropagation();
Expand Down
Loading