|
| 1 | +#!/usr/bin/env node |
| 2 | +// Captures chat model-picker proof shots: the open picker inheriting the agent |
| 3 | +// default, the same picker with a session override, and the picker after a |
| 4 | +// failed catalog refresh. Also reports the x offset between the provider |
| 5 | +// heading label and the model row name (the row-alignment change). |
| 6 | +import { mkdir } from "node:fs/promises"; |
| 7 | +import path from "node:path"; |
| 8 | +import { chromium } from "playwright"; |
| 9 | +import { |
| 10 | + canRunPlaywrightChromium, |
| 11 | + installMockGateway, |
| 12 | + resolvePlaywrightChromiumExecutablePath, |
| 13 | + startControlUiE2eServer, |
| 14 | +} from "../ui/src/test-helpers/control-ui-e2e.ts"; |
| 15 | + |
| 16 | +function readOption(name: string): string | undefined { |
| 17 | + const prefix = `--${name}=`; |
| 18 | + const inline = process.argv.slice(2).find((arg) => arg.startsWith(prefix)); |
| 19 | + if (inline) { |
| 20 | + return inline.slice(prefix.length); |
| 21 | + } |
| 22 | + const index = process.argv.indexOf(`--${name}`); |
| 23 | + return index >= 0 ? process.argv[index + 1] : undefined; |
| 24 | +} |
| 25 | + |
| 26 | +const outputDir = path.resolve( |
| 27 | + readOption("output-dir") ?? ".artifacts/control-ui-e2e/model-picker-proof", |
| 28 | +); |
| 29 | +const label = readOption("label") ?? "after"; |
| 30 | +const executablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath()); |
| 31 | +if (!canRunPlaywrightChromium(executablePath)) { |
| 32 | + throw new Error(`Playwright Chromium is unavailable at ${executablePath}`); |
| 33 | +} |
| 34 | + |
| 35 | +const models = [ |
| 36 | + { id: "gpt-5.5", name: "GPT-5.5", provider: "openai", contextWindow: 400_000 }, |
| 37 | + { id: "gpt-5.6-luna", name: "GPT-5.6 Luna", provider: "openai", contextWindow: 1_000_000 }, |
| 38 | + { id: "gpt-5.6-sol", name: "GPT-5.6 Sol", provider: "openai", contextWindow: 1_000_000 }, |
| 39 | + { id: "gpt-5.6-terra", name: "GPT-5.6 Terra", provider: "openai", contextWindow: 1_000_000 }, |
| 40 | + { |
| 41 | + id: "claude-sonnet-4-6", |
| 42 | + name: "Claude Sonnet 4.6", |
| 43 | + provider: "anthropic", |
| 44 | + contextWindow: 200_000, |
| 45 | + }, |
| 46 | + { id: "claude-opus-4-6", name: "Claude Opus 4.6", provider: "anthropic", contextWindow: 200_000 }, |
| 47 | +]; |
| 48 | + |
| 49 | +await mkdir(outputDir, { recursive: true }); |
| 50 | +const server = await startControlUiE2eServer(undefined, { source: true }); |
| 51 | +const browser = await chromium.launch({ executablePath }); |
| 52 | +const context = await browser.newContext({ |
| 53 | + colorScheme: "dark", |
| 54 | + viewport: { width: 1280, height: 900 }, |
| 55 | +}); |
| 56 | +const page = await context.newPage(); |
| 57 | +page.setDefaultTimeout(30_000); |
| 58 | + |
| 59 | +try { |
| 60 | + const gateway = await installMockGateway(page, { agentModel: "openai/gpt-5.5", models }); |
| 61 | + await page.goto(`${server.baseUrl}chat`); |
| 62 | + await gateway.waitForRequest("chat.startup"); |
| 63 | + |
| 64 | + const composer = page.locator(".agent-chat__input"); |
| 65 | + await composer.waitFor({ state: "visible" }); |
| 66 | + const trigger = composer.locator('[data-chat-model-select="true"]'); |
| 67 | + const menu = composer.locator(".chat-controls__model-menu"); |
| 68 | + |
| 69 | + const openPicker = async () => { |
| 70 | + await trigger.click(); |
| 71 | + await menu.waitFor({ state: "visible" }); |
| 72 | + await page.waitForTimeout(500); |
| 73 | + }; |
| 74 | + const closePicker = async () => { |
| 75 | + await page.keyboard.press("Escape"); |
| 76 | + await page.waitForTimeout(250); |
| 77 | + }; |
| 78 | + const shoot = async (name: string) => { |
| 79 | + const box = await menu.boundingBox(); |
| 80 | + if (!box) { |
| 81 | + throw new Error(`model menu has no layout box for ${name}`); |
| 82 | + } |
| 83 | + await page.screenshot({ |
| 84 | + path: path.join(outputDir, `${label}-${name}.png`), |
| 85 | + clip: { |
| 86 | + x: Math.max(0, box.x - 8), |
| 87 | + y: Math.max(0, box.y - 8), |
| 88 | + width: box.width + 16, |
| 89 | + height: box.height + 16, |
| 90 | + }, |
| 91 | + }); |
| 92 | + }; |
| 93 | + |
| 94 | + await openPicker(); |
| 95 | + await shoot("default"); |
| 96 | + |
| 97 | + const headingLabel = menu.locator(".chat-controls__provider-heading span").last(); |
| 98 | + const rowName = menu.locator(".chat-controls__model-option-name").first(); |
| 99 | + const headingBox = await headingLabel.boundingBox(); |
| 100 | + const rowBox = await rowName.boundingBox(); |
| 101 | + |
| 102 | + const search = menu.locator("[data-chat-model-search]"); |
| 103 | + await search.fill("default"); |
| 104 | + await page.waitForTimeout(400); |
| 105 | + await shoot("search-default"); |
| 106 | + const searchMatches = await menu |
| 107 | + .locator("[data-chat-model-option]:not([hidden])") |
| 108 | + .evaluateAll((rows) => rows.map((row) => row.textContent?.replace(/\s+/gu, " ").trim() ?? "")); |
| 109 | + await search.fill(""); |
| 110 | + await page.waitForTimeout(250); |
| 111 | + |
| 112 | + const override = menu.locator('[data-chat-model-option="openai/gpt-5.6-terra"]'); |
| 113 | + await override.click(); |
| 114 | + await page.waitForTimeout(600); |
| 115 | + await openPicker(); |
| 116 | + await shoot("override"); |
| 117 | + await closePicker(); |
| 118 | + |
| 119 | + // A fresh page drops the per-client catalog cache, so the picker's own load |
| 120 | + // reaches the mock gateway and fails there. |
| 121 | + await gateway.setMethodResponse("models.list", { |
| 122 | + __mockError: { code: "UNAVAILABLE", message: "mock catalog refresh failed" }, |
| 123 | + }); |
| 124 | + await page.reload(); |
| 125 | + await composer.waitFor({ state: "visible" }); |
| 126 | + await page.waitForTimeout(1000); |
| 127 | + await openPicker(); |
| 128 | + await page.waitForTimeout(1500); |
| 129 | + await shoot("refresh-failure"); |
| 130 | + const catalogStateText = await menu.locator("[data-chat-model-catalog-state]").allTextContents(); |
| 131 | + const rowsAfterFailure = await menu.locator("[data-chat-model-option]").count(); |
| 132 | + await closePicker(); |
| 133 | + |
| 134 | + console.log( |
| 135 | + JSON.stringify( |
| 136 | + { |
| 137 | + label, |
| 138 | + outputDir, |
| 139 | + providerHeadingLabelX: headingBox?.x ?? null, |
| 140 | + modelRowNameX: rowBox?.x ?? null, |
| 141 | + alignmentDeltaPx: headingBox && rowBox ? rowBox.x - headingBox.x : null, |
| 142 | + searchDefaultMatches: searchMatches, |
| 143 | + catalogStateAfterRefreshFailure: catalogStateText, |
| 144 | + modelRowsAfterRefreshFailure: rowsAfterFailure, |
| 145 | + }, |
| 146 | + null, |
| 147 | + 2, |
| 148 | + ), |
| 149 | + ); |
| 150 | +} finally { |
| 151 | + await context.close(); |
| 152 | + await browser.close(); |
| 153 | + await server.close(); |
| 154 | +} |
0 commit comments