|
| 1 | +import { |
| 2 | + ProviderDriverKind, |
| 3 | + ProviderInstanceId, |
| 4 | + type ProviderOptionSelection, |
| 5 | + type ServerProviderModel, |
| 6 | +} from "@t3tools/contracts"; |
| 7 | +import { createModelCapabilities } from "@t3tools/shared/model"; |
| 8 | +import { useState } from "react"; |
| 9 | +import { expect, it } from "vite-plus/test"; |
| 10 | +import { page, userEvent } from "vite-plus/test/browser"; |
| 11 | + |
| 12 | +import { render } from "../../../test/render"; |
| 13 | +import { ComposerEffortColumn, describeComposerEffort } from "./ComposerModelEffort"; |
| 14 | +import type { TraitsSelectionInput } from "./TraitsPicker"; |
| 15 | + |
| 16 | +// Shaped like Devin over ACP: its session mode comes first, and its reasoning id is its own. |
| 17 | +const models: ReadonlyArray<ServerProviderModel> = [ |
| 18 | + { |
| 19 | + slug: "fusion", |
| 20 | + name: "Fusion (Claude Opus 5.5 Medium + SWE-2 High)", |
| 21 | + isCustom: false, |
| 22 | + capabilities: createModelCapabilities({ |
| 23 | + optionDescriptors: [ |
| 24 | + { |
| 25 | + id: "mode", |
| 26 | + label: "Session Mode", |
| 27 | + type: "select", |
| 28 | + currentValue: "bypass", |
| 29 | + options: [ |
| 30 | + { id: "code", label: "Code" }, |
| 31 | + { id: "plan", label: "Plan" }, |
| 32 | + { id: "bypass", label: "Bypass Permissions" }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + { |
| 36 | + id: "thought_level", |
| 37 | + label: "Thinking", |
| 38 | + type: "select", |
| 39 | + role: "reasoning", |
| 40 | + currentValue: "medium", |
| 41 | + options: [ |
| 42 | + { id: "low", label: "Low" }, |
| 43 | + { id: "medium", label: "Medium" }, |
| 44 | + { id: "high", label: "High" }, |
| 45 | + ], |
| 46 | + }, |
| 47 | + { |
| 48 | + id: "speed", |
| 49 | + label: "Speed", |
| 50 | + type: "select", |
| 51 | + currentValue: "standard", |
| 52 | + options: [ |
| 53 | + { id: "standard", label: "Standard" }, |
| 54 | + { id: "fast", label: "Fast" }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + { id: "auto_approve", label: "Auto-approve tools", type: "boolean", currentValue: false }, |
| 58 | + ], |
| 59 | + }), |
| 60 | + }, |
| 61 | +]; |
| 62 | + |
| 63 | +function traitsInput( |
| 64 | + modelOptions: ReadonlyArray<ProviderOptionSelection>, |
| 65 | + onModelOptionsChange: (next: ReadonlyArray<ProviderOptionSelection> | undefined) => void, |
| 66 | +): TraitsSelectionInput { |
| 67 | + return { |
| 68 | + provider: ProviderDriverKind.make("acpRegistry"), |
| 69 | + instanceId: ProviderInstanceId.make("devin"), |
| 70 | + models, |
| 71 | + model: "fusion", |
| 72 | + modelOptions, |
| 73 | + planModeEnabled: false, |
| 74 | + onModelOptionsChange, |
| 75 | + }; |
| 76 | +} |
| 77 | + |
| 78 | +function Column() { |
| 79 | + const [options, setOptions] = useState<ReadonlyArray<ProviderOptionSelection>>([]); |
| 80 | + const traits = traitsInput(options, (next) => setOptions(next ?? [])); |
| 81 | + return ( |
| 82 | + <> |
| 83 | + <div data-model-picker-effort> |
| 84 | + <ComposerEffortColumn traits={traits} /> |
| 85 | + </div> |
| 86 | + <p role="status">{describeComposerEffort(traits, "bars", "sm").suffix}</p> |
| 87 | + </> |
| 88 | + ); |
| 89 | +} |
| 90 | + |
| 91 | +it("draws an agent's reasoning as bars and keeps its mode out of the levels", async () => { |
| 92 | + await using screen = await render(<Column />, { router: false }); // no routes involved |
| 93 | + const status = screen.getByRole("status"); |
| 94 | + expect(status.element().querySelector("[data-composer-effort-glyph]")).not.toBeNull(); |
| 95 | + await expect.element(status).toHaveTextContent(""); |
| 96 | + |
| 97 | + const levels = screen.getByRole("radiogroup", { name: "Thinking" }); |
| 98 | + await expect.element(levels.getByRole("radio")).toHaveLength(3); |
| 99 | + await expect.element(screen.getByRole("radio", { name: "Plan" })).not.toBeInTheDocument(); |
| 100 | + |
| 101 | + // Up and Down walk from the levels through the option rows without opening their menus. |
| 102 | + await userEvent.tab(); |
| 103 | + await expect.element(screen.getByRole("radio", { name: "Medium" })).toHaveFocus(); |
| 104 | + await userEvent.keyboard("{ArrowDown}{ArrowDown}{ArrowDown}"); |
| 105 | + const speed = screen.getByRole("button", { name: "Speed: Standard" }); |
| 106 | + await expect.element(speed).toHaveFocus(); |
| 107 | + await expect.element(page.getByRole("menuitemradio")).not.toBeInTheDocument(); |
| 108 | + await userEvent.keyboard("{ArrowRight}"); |
| 109 | + await expect.element(page.getByRole("menuitemradio", { name: "Standard" })).toHaveFocus(); |
| 110 | + await userEvent.keyboard("{ArrowLeft}"); |
| 111 | + await expect.element(page.getByRole("menuitemradio")).not.toBeInTheDocument(); |
| 112 | + await expect.element(speed).toHaveFocus(); |
| 113 | + |
| 114 | + await userEvent.click(screen.getByText("Auto-approve tools")); |
| 115 | + await expect |
| 116 | + .element(screen.getByRole("switch", { name: "Auto-approve tools" })) |
| 117 | + .toHaveAttribute("aria-checked", "true"); |
| 118 | + |
| 119 | + await userEvent.click(screen.getByRole("button", { name: "Session Mode: Bypass Permissions" })); |
| 120 | + await userEvent.click(page.getByRole("menuitemradio", { name: "Plan" })); |
| 121 | + await expect |
| 122 | + .element(screen.getByRole("button", { name: "Session Mode: Plan" })) |
| 123 | + .toBeInTheDocument(); |
| 124 | + await expect.element(page.getByRole("menuitemradio")).not.toBeInTheDocument(); |
| 125 | +}); |
0 commit comments