summaryrefslogtreecommitdiffhomepage
path: root/packages/app/e2e/prompt
diff options
context:
space:
mode:
authorKit Langton <[email protected]>2026-03-31 21:24:39 -0400
committerGitHub <[email protected]>2026-03-31 21:24:39 -0400
commitc8ecd640220331ce7695d72ea8c618dd8909eab1 (patch)
treec9b1037d1f1f9c2ecd14bab102144dfb97fb7884 /packages/app/e2e/prompt
parentca376a4cffc47e1fd629c4073d3cdca27eba9adc (diff)
downloadopencode-c8ecd640220331ce7695d72ea8c618dd8909eab1.tar.gz
opencode-c8ecd640220331ce7695d72ea8c618dd8909eab1.zip
test(app): add mock llm e2e fixture (#20375)
Diffstat (limited to 'packages/app/e2e/prompt')
-rw-r--r--packages/app/e2e/prompt/prompt.spec.ts107
1 files changed, 76 insertions, 31 deletions
diff --git a/packages/app/e2e/prompt/prompt.spec.ts b/packages/app/e2e/prompt/prompt.spec.ts
index 0466d0988..1acf17f5b 100644
--- a/packages/app/e2e/prompt/prompt.spec.ts
+++ b/packages/app/e2e/prompt/prompt.spec.ts
@@ -1,8 +1,44 @@
+import fs from "node:fs/promises"
+import path from "node:path"
import { test, expect } from "../fixtures"
import { promptSelector } from "../selectors"
-import { cleanupSession, sessionIDFromUrl, withSession } from "../actions"
+import { sessionIDFromUrl } from "../actions"
+import { createSdk } from "../utils"
-test("can send a prompt and receive a reply", async ({ page, sdk, gotoSession }) => {
+async function config(dir: string, url: string) {
+ await fs.writeFile(
+ path.join(dir, "opencode.json"),
+ JSON.stringify({
+ $schema: "https://opencode.ai/config.json",
+ enabled_providers: ["e2e-llm"],
+ provider: {
+ "e2e-llm": {
+ name: "E2E LLM",
+ npm: "@ai-sdk/openai-compatible",
+ env: [],
+ models: {
+ "test-model": {
+ name: "Test Model",
+ tool_call: true,
+ limit: { context: 128000, output: 32000 },
+ },
+ },
+ options: {
+ apiKey: "test-key",
+ baseURL: url,
+ },
+ },
+ },
+ agent: {
+ build: {
+ model: "e2e-llm/test-model",
+ },
+ },
+ }),
+ )
+}
+
+test("can send a prompt and receive a reply", async ({ page, llm, withProject }) => {
test.setTimeout(120_000)
const pageErrors: string[] = []
@@ -11,42 +47,51 @@ test("can send a prompt and receive a reply", async ({ page, sdk, gotoSession })
}
page.on("pageerror", onPageError)
- await gotoSession()
-
- const token = `E2E_OK_${Date.now()}`
+ try {
+ await withProject(
+ async (project) => {
+ const sdk = createSdk(project.directory)
+ const token = `E2E_OK_${Date.now()}`
- const prompt = page.locator(promptSelector)
- await prompt.click()
- await page.keyboard.type(`Reply with exactly: ${token}`)
- await page.keyboard.press("Enter")
+ await llm.text(token)
+ await project.gotoSession()
- await expect(page).toHaveURL(/\/session\/[^/?#]+/, { timeout: 30_000 })
+ const prompt = page.locator(promptSelector)
+ await prompt.click()
+ await page.keyboard.type(`Reply with exactly: ${token}`)
+ await page.keyboard.press("Enter")
- const sessionID = (() => {
- const id = sessionIDFromUrl(page.url())
- if (!id) throw new Error(`Failed to parse session id from url: ${page.url()}`)
- return id
- })()
+ await expect(page).toHaveURL(/\/session\/[^/?#]+/, { timeout: 30_000 })
- try {
- await expect
- .poll(
- async () => {
- const messages = await sdk.session.messages({ sessionID, limit: 50 }).then((r) => r.data ?? [])
- return messages
- .filter((m) => m.info.role === "assistant")
- .flatMap((m) => m.parts)
- .filter((p) => p.type === "text")
- .map((p) => p.text)
- .join("\n")
- },
- { timeout: 90_000 },
- )
+ const sessionID = (() => {
+ const id = sessionIDFromUrl(page.url())
+ if (!id) throw new Error(`Failed to parse session id from url: ${page.url()}`)
+ return id
+ })()
+ project.trackSession(sessionID)
- .toContain(token)
+ await expect
+ .poll(
+ async () => {
+ const messages = await sdk.session.messages({ sessionID, limit: 50 }).then((r) => r.data ?? [])
+ return messages
+ .filter((m) => m.info.role === "assistant")
+ .flatMap((m) => m.parts)
+ .filter((p) => p.type === "text")
+ .map((p) => p.text)
+ .join("\n")
+ },
+ { timeout: 30_000 },
+ )
+ .toContain(token)
+ },
+ {
+ model: { providerID: "e2e-llm", modelID: "test-model" },
+ setup: (dir) => config(dir, llm.url),
+ },
+ )
} finally {
page.off("pageerror", onPageError)
- await cleanupSession({ sdk, sessionID })
}
if (pageErrors.length > 0) {