import type { Locator, Page } from "@playwright/test" import { test, expect } from "../fixtures" import { openSidebar, resolveSlug, setWorkspacesEnabled, waitSession, waitSlug } from "../actions" import { promptAgentSelector, promptModelSelector, promptVariantSelector, workspaceItemSelector, workspaceNewSessionSelector, } from "../selectors" import { createSdk, sessionPath } from "../utils" type Footer = { agent: string model: string variant: string } type Probe = { dir?: string sessionID?: string agent?: string model?: { providerID: string; modelID: string; name?: string } variant?: string | null pick?: { agent?: string model?: { providerID: string; modelID: string } variant?: string | null } variants?: string[] models?: Array<{ providerID: string; modelID: string; name: string }> agents?: Array<{ name: string }> } const escape = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") const text = async (locator: Locator) => ((await locator.textContent()) ?? "").trim() const modelKey = (state: Probe | null) => (state?.model ? `${state.model.providerID}:${state.model.modelID}` : null) async function probe(page: Page): Promise { return page.evaluate(() => { const win = window as Window & { __opencode_e2e?: { model?: { current?: Probe } } } return win.__opencode_e2e?.model?.current ?? null }) } async function currentModel(page: Page) { await expect.poll(() => probe(page).then(modelKey), { timeout: 30_000 }).not.toBe(null) const value = await probe(page).then(modelKey) if (!value) throw new Error("Failed to resolve current model key") return value } async function waitControl(page: Page, key: "setAgent" | "setModel" | "setVariant") { await expect .poll( () => page.evaluate((key) => { const win = window as Window & { __opencode_e2e?: { model?: { controls?: Record } } } return !!win.__opencode_e2e?.model?.controls?.[key] }, key), { timeout: 30_000 }, ) .toBe(true) } async function pickAgent(page: Page, value: string) { await waitControl(page, "setAgent") await page.evaluate((value) => { const win = window as Window & { __opencode_e2e?: { model?: { controls?: { setAgent?: (value: string | undefined) => void } } } } const fn = win.__opencode_e2e?.model?.controls?.setAgent if (!fn) throw new Error("Model e2e agent control is not enabled") fn(value) }, value) } async function pickModel(page: Page, value: { providerID: string; modelID: string }) { await waitControl(page, "setModel") await page.evaluate((value) => { const win = window as Window & { __opencode_e2e?: { model?: { controls?: { setModel?: (value: { providerID: string; modelID: string } | undefined) => void } } } } const fn = win.__opencode_e2e?.model?.controls?.setModel if (!fn) throw new Error("Model e2e model control is not enabled") fn(value) }, value) } async function pickVariant(page: Page, value: string) { await waitControl(page, "setVariant") await page.evaluate((value) => { const win = window as Window & { __opencode_e2e?: { model?: { controls?: { setVariant?: (value: string | undefined) => void } } } } const fn = win.__opencode_e2e?.model?.controls?.setVariant if (!fn) throw new Error("Model e2e variant control is not enabled") fn(value) }, value) } async function read(page: Page): Promise