|
| 1 | +import type { Page } from "@playwright/test"; |
| 2 | +import { admin, AI_TIMEOUT, aiResponse, chooseForMotion, expect, providerCalls, test } from "./fixtures"; |
| 3 | + |
| 4 | +// Feature map: features/model-defaults.md. |
| 5 | +const motion = "This House would make public transport free at the point of use"; |
| 6 | +const OPUS = "anthropic/claude-opus-5.5"; |
| 7 | +const HAIKU = "anthropic/claude-haiku-5.5"; |
| 8 | + |
| 9 | +async function settings(userId: string) { |
| 10 | + const { data, error } = await admin.from("user_settings").select("feature_configs").eq("user_id", userId).single(); |
| 11 | + if (error) throw error; |
| 12 | + return data.feature_configs as Record<string, { model: string }>; |
| 13 | +} |
| 14 | + |
| 15 | +async function updateSettings(userId: string, values: Record<string, unknown>) { |
| 16 | + const { error } = await admin.from("user_settings").update(values).eq("user_id", userId); |
| 17 | + if (error) throw error; |
| 18 | +} |
| 19 | + |
| 20 | +async function generateOnce(page: Page) { |
| 21 | + await page.getByRole("textbox", { name: "Motion / Topic *" }).fill(motion); |
| 22 | + const response = aiResponse(page, "generate"); |
| 23 | + await page.getByRole("button", { name: "Generate Debate Case" }).click(); |
| 24 | + await chooseForMotion(page, "once"); |
| 25 | + return response; |
| 26 | +} |
| 27 | + |
| 28 | +test("model-pro-default: a new Pro account starts on Claude Opus 5.5 and generates with it", async ({ signedIn: page, user, evidence }) => { |
| 29 | + const userId = await user.userId(); |
| 30 | + await expect.poll(async () => (await settings(userId)).generate?.model, { timeout: AI_TIMEOUT }).toBe(OPUS); |
| 31 | + |
| 32 | + await page.goto("/app/generate"); |
| 33 | + const selector = page.getByRole("combobox", { name: "Select AI model for generate" }); |
| 34 | + await expect(selector).toContainText("Claude Opus 5.5"); |
| 35 | + await selector.click(); |
| 36 | + await expect(page.getByRole("option", { name: /Claude Haiku 5\.5/ })).toBeEnabled(); |
| 37 | + await expect(page.getByRole("option", { name: /Claude Sonnet 5\.5/ })).toBeEnabled(); |
| 38 | + await evidence.shot("01-pro-model-list"); |
| 39 | + await page.keyboard.press("Escape"); |
| 40 | + await evidence.step("New Pro account: selector shows Claude Opus 5.5, all Claude 5.5 models enabled"); |
| 41 | + |
| 42 | + const body = await generateOnce(page); |
| 43 | + expect((body.meta as { resolvedModel?: string } | undefined)?.resolvedModel ?? OPUS).toBe(OPUS); |
| 44 | + const calls = await providerCalls(); |
| 45 | + // Live mode rewrites the upstream model to the pin, so read what the app asked for. |
| 46 | + expect(calls.filter((call) => call.feature === "generate").map((call) => call.requestedModel ?? call.model)).toContain(OPUS); |
| 47 | + const { data: usage } = await admin.from("ai_requests").select("feature,status,model").eq("user_id", userId); |
| 48 | + expect(usage).toContainEqual(expect.objectContaining({ feature: "generate", status: "success", model: OPUS })); |
| 49 | + await evidence.json("02-ai-requests", usage); |
| 50 | + await evidence.shot("02-generated-with-opus"); |
| 51 | +}); |
| 52 | + |
| 53 | +test("model-basic-default: a Basic account starts on Claude Haiku 5.5 with only Haiku, Luna and Muse Spark unlocked", async ({ signedIn: page, user, evidence }) => { |
| 54 | + const userId = await user.userId(); |
| 55 | + // Demo sign-in grants Pro; turn the account into a fresh trial with nothing saved. |
| 56 | + await updateSettings(userId, { |
| 57 | + subscription_tier: "trial", |
| 58 | + trial_ends_at: new Date(Date.now() + 2 * 86_400_000).toISOString(), |
| 59 | + grace_period_ends_at: null, |
| 60 | + daily_limit_override: null, |
| 61 | + feature_configs: {}, |
| 62 | + }); |
| 63 | + await page.goto("/app/generate"); |
| 64 | + await expect.poll(async () => (await settings(userId)).generate?.model, { timeout: AI_TIMEOUT }).toBe(HAIKU); |
| 65 | + |
| 66 | + const selector = page.getByRole("combobox", { name: "Select AI model for generate" }); |
| 67 | + await expect(selector).toContainText("Claude Haiku 5.5"); |
| 68 | + await selector.click(); |
| 69 | + await expect(page.getByRole("option", { name: /Claude Opus 5\.5/ })).toBeDisabled(); |
| 70 | + await expect(page.getByRole("option", { name: /Claude Sonnet 5\.5/ })).toBeDisabled(); |
| 71 | + await expect(page.getByRole("option", { name: /Gemini 3\.8 Flash/ })).toBeDisabled(); |
| 72 | + await expect(page.getByRole("option", { name: /GPT-6 Luna/ })).toBeEnabled(); |
| 73 | + await expect(page.getByRole("option", { name: /Muse Spark 1\.3/ })).toBeEnabled(); |
| 74 | + await evidence.shot("01-basic-model-list"); |
| 75 | + await page.keyboard.press("Escape"); |
| 76 | + await evidence.step("Basic account: selector shows Claude Haiku 5.5; Luna and Muse Spark enabled; Opus, Sonnet and Gemini locked behind Pro"); |
| 77 | + |
| 78 | + await generateOnce(page); |
| 79 | + const { data: usage } = await admin.from("ai_requests").select("feature,status,model").eq("user_id", userId); |
| 80 | + expect(usage).toContainEqual(expect.objectContaining({ feature: "generate", status: "success", model: HAIKU })); |
| 81 | + await evidence.json("02-ai-requests", usage); |
| 82 | +}); |
| 83 | + |
| 84 | +test("model-retired: a saved Claude Sonnet 5 setting moves to Claude Opus 5.5", async ({ signedIn: page, user, evidence }) => { |
| 85 | + const userId = await user.userId(); |
| 86 | + const retired = Object.fromEntries(["generate", "attack", "brainstorm", "factoids", "ask", "sparring"].map((feature) => [ |
| 87 | + feature, |
| 88 | + { provider: "openrouter", model: "anthropic/claude-sonnet-5", temperature: 0.7, reasoningEffort: "low" }, |
| 89 | + ])); |
| 90 | + await updateSettings(userId, { feature_configs: retired }); |
| 91 | + await page.evaluate(() => localStorage.removeItem("debate-trainer-settings")); |
| 92 | + await page.goto("/app/generate"); |
| 93 | + |
| 94 | + await expect(page.getByRole("combobox", { name: "Select AI model for generate" })).toContainText("Claude Opus 5.5"); |
| 95 | + await expect.poll(async () => Object.values(await settings(userId)).map((config) => config.model), { timeout: AI_TIMEOUT }) |
| 96 | + .toEqual(Array(6).fill(OPUS)); |
| 97 | + await evidence.shot("01-retired-migrated"); |
| 98 | + await evidence.step("Saved Sonnet 5 configs were rewritten to Opus 5.5 in user_settings"); |
| 99 | +}); |
0 commit comments