Skip to content
Merged
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
26 changes: 26 additions & 0 deletions webview-ui/playwright/gallery/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ export const stories: Record<string, Story> = {
</AppProviders>
)
},
"api-provider-dropdown": async () => {
const [{ AppProviders }, { default: ApiOptions }, { providerIdentifiers }] = await Promise.all([
import("../AppProviders"),
import("@/components/settings/ApiOptions"),
import("@roo-code/types"),
])
const apiConfiguration: import("@roo-code/types").ProviderSettings = {
apiProvider: providerIdentifiers.anthropic,
apiKey: "sk-ant-example-key",
}
return (
<AppProviders initialState={{ apiConfiguration }}>
<div
className="w-[480px] p-4 bg-vscode-editor-background text-vscode-foreground"
data-testid="api-provider-dropdown-story">
<ApiOptions
uriScheme="vscode"
apiConfiguration={apiConfiguration}
setApiConfigurationField={() => undefined}
errorMessage={undefined}
setErrorMessage={() => undefined}
/>
</div>
</AppProviders>
)
},
"auto-approve-settings": async () => {
const { AutoApproveSettingsStory } =
await import("@/components/settings/__tests__/AutoApproveSettings.visual.fixture")
Expand Down
6 changes: 6 additions & 0 deletions webview-ui/src/components/settings/ApiOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@
}
}

const zooGatewayIndex = options.findIndex((opt) => opt.value === providerIdentifiers.zooGateway)
if (zooGatewayIndex > 0) {

Check warning on line 439 in webview-ui/src/components/settings/ApiOptions.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/settings/ApiOptions.tsx:439: Survived EqualityOperator mutant (replacement: zooGatewayIndex >= 0). See the job summary for the complete list and resolution guidance.
const [zooGatewayOption] = options.splice(zooGatewayIndex, 1)
options.unshift(zooGatewayOption)
}

return options
}, [organizationAllowList, apiConfiguration.apiProvider, fromWelcomeView])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { useSelectedModel } from "@src/components/ui/hooks/useSelectedModel"
import ApiOptions from "../ApiOptions"
import { MODELS_BY_PROVIDER, PROVIDERS } from "../constants"

type ProviderOption = {
value: string
label: string
}

// Mock the extension state context
vi.mock("@src/context/ExtensionStateContext", () => ({
ExtensionStateContextProvider: ({ children }: any) => children,
Expand Down Expand Up @@ -113,6 +118,11 @@ describe("ApiOptions Provider Filtering", () => {
return renderWithExtensionState(<ApiOptions {...props} />)
}

const getProviderOptions = (): ProviderOption[] => {
const selectElement = screen.getByTestId("provider-select")
return JSON.parse(selectElement.getAttribute("data-options") || "[]") as ProviderOption[]
}

beforeEach(() => {
vi.clearAllMocks()
vi.mocked(useSelectedModel).mockReturnValue({
Expand Down Expand Up @@ -190,6 +200,64 @@ describe("ApiOptions Provider Filtering", () => {
expect(providerValues).toContain("ollama") // dynamic provider
})

it("pins Zoo Gateway first while preserving alphabetical order for the remaining providers", () => {
renderWithProviders()

const options = getProviderOptions()
const remainingLabels = options.slice(1).map(({ label }) => label)

expect(options[0]?.value).toBe(providerIdentifiers.zooGateway)
expect(remainingLabels).toEqual([...remainingLabels].sort((a, b) => a.localeCompare(b)))
})

it("pins Zoo Gateway first and OpenRouter second in the welcome view", () => {
renderWithProviders({ ...defaultProps, fromWelcomeView: true })

const providerValues = getProviderOptions().map(({ value }) => value)

expect(providerValues.slice(0, 2)).toEqual([providerIdentifiers.zooGateway, providerIdentifiers.openrouter])
})

it("does not reintroduce Zoo Gateway when an organization allow list excludes it", () => {
vi.mocked(useExtensionState).mockReturnValueOnce({
...useExtensionState(),
organizationAllowList: {
allowAll: false,
providers: {
[providerIdentifiers.anthropic]: { allowAll: true },
[providerIdentifiers.openrouter]: { allowAll: true },
},
},
})

renderWithProviders()

expect(getProviderOptions().map(({ value }) => value)).toEqual([
providerIdentifiers.anthropic,
providerIdentifiers.openrouter,
])
})

it("keeps Zoo Gateway first when an organization allow list includes it", () => {
vi.mocked(useExtensionState).mockReturnValueOnce({
...useExtensionState(),
organizationAllowList: {
allowAll: false,
providers: {
[providerIdentifiers.anthropic]: { allowAll: true },
[providerIdentifiers.zooGateway]: { allowAll: true },
},
},
})

renderWithProviders()

expect(getProviderOptions().map(({ value }) => value)).toEqual([
providerIdentifiers.zooGateway,
providerIdentifiers.anthropic,
])
})

it("should hide static providers with empty models", () => {
// Mock MODELS_BY_PROVIDER to have an empty provider
const _originalModels = { ...MODELS_BY_PROVIDER }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "../../../../playwright/coverage-fixture"
import { mountedStory } from "../../../../playwright/mounted-story"

test("renders the open provider dropdown with Zoo Gateway first", async ({ mount, page }) => {
await page.setViewportSize({ width: 520, height: 720 })
// The full provider bundle leaves bare Zod references after gallery tree-shaking.
await page.evaluate(() => Object.assign(globalThis, { z: undefined, z$1: undefined }))
const component = mountedStory(await mount("api-provider-dropdown"))

await component.getByTestId("provider-select").click()
await expect(page.getByRole("listbox")).toBeVisible()
await expect(page).toHaveScreenshot("api-provider-dropdown-open.png")
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading