From c8ecd640220331ce7695d72ea8c618dd8909eab1 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Tue, 31 Mar 2026 21:24:39 -0400 Subject: test(app): add mock llm e2e fixture (#20375) --- packages/app/e2e/fixtures.ts | 67 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) (limited to 'packages/app/e2e/fixtures.ts') diff --git a/packages/app/e2e/fixtures.ts b/packages/app/e2e/fixtures.ts index ca06858a4..7fc4cda05 100644 --- a/packages/app/e2e/fixtures.ts +++ b/packages/app/e2e/fixtures.ts @@ -1,5 +1,8 @@ import { test as base, expect, type Page } from "@playwright/test" +import { ManagedRuntime } from "effect" import type { E2EWindow } from "../src/testing/terminal" +import type { Item, Reply, Usage } from "../../opencode/test/lib/llm-server" +import { TestLLMServer } from "../../opencode/test/lib/llm-server" import { healthPhase, cleanupSession, @@ -13,6 +16,24 @@ import { } from "./actions" import { createSdk, dirSlug, getWorktree, sessionPath } from "./utils" +type LLMFixture = { + url: string + push: (...input: (Item | Reply)[]) => Promise + text: (value: string, opts?: { usage?: Usage }) => Promise + tool: (name: string, input: unknown) => Promise + toolHang: (name: string, input: unknown) => Promise + reason: (value: string, opts?: { text?: string; usage?: Usage }) => Promise + fail: (message?: unknown) => Promise + error: (status: number, body: unknown) => Promise + hang: () => Promise + hold: (value: string, wait: PromiseLike) => Promise + hits: () => Promise }>> + calls: () => Promise + wait: (count: number) => Promise + inputs: () => Promise[]> + pending: () => Promise +} + export const settingsKey = "settings.v3" const seedModel = (() => { @@ -26,6 +47,7 @@ const seedModel = (() => { })() type TestFixtures = { + llm: LLMFixture sdk: ReturnType gotoSession: (sessionID?: string) => Promise withProject: ( @@ -36,7 +58,11 @@ type TestFixtures = { trackSession: (sessionID: string, directory?: string) => void trackDirectory: (directory: string) => void }) => Promise, - options?: { extra?: string[] }, + options?: { + extra?: string[] + model?: { providerID: string; modelID: string } + setup?: (directory: string) => Promise + }, ) => Promise } @@ -46,6 +72,31 @@ type WorkerFixtures = { } export const test = base.extend({ + llm: async ({}, use) => { + const rt = ManagedRuntime.make(TestLLMServer.layer) + try { + const svc = await rt.runPromise(TestLLMServer.asEffect()) + await use({ + url: svc.url, + push: (...input) => rt.runPromise(svc.push(...input)), + text: (value, opts) => rt.runPromise(svc.text(value, opts)), + tool: (name, input) => rt.runPromise(svc.tool(name, input)), + toolHang: (name, input) => rt.runPromise(svc.toolHang(name, input)), + reason: (value, opts) => rt.runPromise(svc.reason(value, opts)), + fail: (message) => rt.runPromise(svc.fail(message)), + error: (status, body) => rt.runPromise(svc.error(status, body)), + hang: () => rt.runPromise(svc.hang), + hold: (value, wait) => rt.runPromise(svc.hold(value, wait)), + hits: () => rt.runPromise(svc.hits), + calls: () => rt.runPromise(svc.calls), + wait: (count) => rt.runPromise(svc.wait(count)), + inputs: () => rt.runPromise(svc.inputs), + pending: () => rt.runPromise(svc.pending), + }) + } finally { + await rt.dispose() + } + }, page: async ({ page }, use) => { let boundary: string | undefined setHealthPhase(page, "test") @@ -99,7 +150,8 @@ export const test = base.extend({ const root = await createTestProject() const sessions = new Map() const dirs = new Set() - await seedStorage(page, { directory: root, extra: options?.extra }) + await options?.setup?.(root) + await seedStorage(page, { directory: root, extra: options?.extra, model: options?.model }) const gotoSession = async (sessionID?: string) => { await page.goto(sessionPath(root, sessionID)) @@ -133,7 +185,14 @@ export const test = base.extend({ }, }) -async function seedStorage(page: Page, input: { directory: string; extra?: string[] }) { +async function seedStorage( + page: Page, + input: { + directory: string + extra?: string[] + model?: { providerID: string; modelID: string } + }, +) { await seedProjects(page, input) await page.addInitScript((model: { providerID: string; modelID: string }) => { const win = window as E2EWindow @@ -158,7 +217,7 @@ async function seedStorage(page: Page, input: { directory: string; extra?: strin variant: {}, }), ) - }, seedModel) + }, input.model ?? seedModel) } export { expect } -- cgit v1.2.3