Skip to content

AI-native design editor. Open-source Figma alternative.

test(chat): isolate real LLM smoke coverage

Danila Poyarkov1455fab099db
diff --git a/package.json b/package.json
index 93e537f21..4b3638512 100644
--- a/package.json
+++ b/package.json
@@ -49,6 +49,7 @@
"check:arch": "steiger .",
"check:vue": "vue-tsc --noEmit -p tsconfig.json && vue-tsc --noEmit -p packages/vue/tsconfig.json",
"test": "playwright test --project=openpencil",
+ "test:real-llm": "playwright test --project=openpencil-real-llm",
"test:update": "playwright test --project=openpencil --update-snapshots",
"test:figma": "playwright test --project=figma",
"figma:debug": "open -a Figma --args --remote-debugging-port=9222",
diff --git a/playwright.config.ts b/playwright.config.ts
index b2f7e0549..6d9279e96 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -28,6 +28,13 @@ export default defineConfig({
{
name: 'openpencil',
testDir: './tests/e2e',
+ grepInvert: /@real-llm/,
+ fullyParallel: false
+ },
+ {
+ name: 'openpencil-real-llm',
+ testDir: './tests/e2e',
+ grep: /@real-llm/,
fullyParallel: false
},
{
diff --git a/tests/e2e/chat/panel.spec.ts b/tests/e2e/chat/panel.spec.ts
index 828c63046..00aa026b7 100644
--- a/tests/e2e/chat/panel.spec.ts
+++ b/tests/e2e/chat/panel.spec.ts
@@ -5,8 +5,7 @@ import {
chatInput as getChatInput,
chatTab as getChatTab,
designTab as getDesignTab,
- openChatTestApp,
- USE_REAL_LLM
+ openChatTestApp
} from '#tests/helpers/chat/app'
test.describe.configure({ mode: 'serial' })
@@ -56,7 +55,7 @@ test('clicking AI tab directs provider setup to unified settings', async () => {
})
test('saving API key in unified settings shows chat interface', async () => {
- const key = USE_REAL_LLM ? (process.env.OPENROUTER_API_KEY ?? '') : 'sk-or-test-key-12345'
+ const key = 'sk-or-test-key-12345'
await page.getByTestId('provider-setup-open-settings').click()
await expect(page.getByTestId('app-settings-dialog')).toBeVisible()
await expect(page.getByTestId('settings-remember-credentials')).toHaveAttribute(
@@ -214,13 +213,7 @@ test('Enter submits message and clears input', async () => {
})
test('assistant responds', async () => {
- if (USE_REAL_LLM) {
- await expect(page.locator('.chat-markdown, [class*="rounded-tl-md"]').first()).toBeVisible({
- timeout: 30000
- })
- } else {
- await expect(page.getByText('mock response', { exact: false })).toBeVisible({ timeout: 5000 })
- }
+ await expect(page.getByText('mock response', { exact: false })).toBeVisible({ timeout: 5000 })
})
test('completed Markdown responses release streaming parser history', async () => {
@@ -327,16 +320,10 @@ test('tool calls render in assistant message', async () => {
await chatInput().fill('Create a frame')
await chatInput().press('Enter')
- if (USE_REAL_LLM) {
- await expect(page.locator('.chat-markdown, [class*="rounded-tl-md"]').first()).toBeVisible({
- timeout: 30000
- })
- } else {
- const assistant = page.getByTestId('chat-message-assistant').last()
- await expect(assistant.getByText('Create Shape')).toBeVisible({ timeout: 5000 })
- await expect(assistant.getByText('Done')).toBeVisible()
- await expect(assistant.getByText('Created a frame', { exact: false })).toBeVisible()
- }
+ const assistant = page.getByTestId('chat-message-assistant').last()
+ await expect(assistant.getByText('Create Shape')).toBeVisible({ timeout: 5000 })
+ await expect(assistant.getByText('Done')).toBeVisible()
+ await expect(assistant.getByText('Created a frame', { exact: false })).toBeVisible()
})
test('switching tabs preserves chat', async () => {
diff --git a/tests/e2e/chat/real-llm.spec.ts b/tests/e2e/chat/real-llm.spec.ts
new file mode 100644
index 000000000..55a8604b6
--- /dev/null
+++ b/tests/e2e/chat/real-llm.spec.ts
@@ -0,0 +1,33 @@
+import { expect, test } from '@playwright/test'
+
+import { chatInput, chatTab, configureOpenRouter, openChatTestApp } from '#tests/helpers/chat/app'
+
+const apiKey = process.env.OPENROUTER_API_KEY ?? ''
+
+test.describe('OpenRouter chat @real-llm', () => {
+ test.skip(!apiKey, 'OPENROUTER_API_KEY is required for real LLM smoke tests')
+
+ test('streams a Markdown response from the configured Design model', async ({ browser }) => {
+ const { page } = await openChatTestApp(browser, { mockTransport: false })
+ try {
+ await chatTab(page).click()
+ await configureOpenRouter(page, apiKey)
+ await chatInput(page).fill(
+ 'Reply with a short Markdown heading and a TypeScript code block declaring const ready = true. Do not call tools.'
+ )
+ await chatInput(page).press('Enter')
+
+ const assistant = page.getByTestId('chat-message-assistant').last()
+ await expect(assistant.locator('.chat-markdown')).toBeVisible({ timeout: 60_000 })
+ await expect(assistant.locator('.shiki')).toContainText('const ready = true', {
+ timeout: 60_000
+ })
+ await expect(assistant.locator('.chat-markdown')).toHaveAttribute(
+ 'data-chat-markdown-mode',
+ 'static'
+ )
+ } finally {
+ await page.close()
+ }
+ })
+})
diff --git a/tests/helpers/chat/app.ts b/tests/helpers/chat/app.ts
index 07403c99e..cce0471a7 100644
--- a/tests/helpers/chat/app.ts
+++ b/tests/helpers/chat/app.ts
@@ -3,15 +3,15 @@ import type { Browser, Page } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
import { injectMockChatTransport } from '#tests/helpers/chat/transport'
-const USE_REAL_LLM = process.env.TEST_REAL_LLM === '1'
-const OPENROUTER_KEY = process.env.OPENROUTER_API_KEY ?? ''
-
export interface ChatTestApp {
page: Page
canvas: CanvasHelper
}
-export async function openChatTestApp(browser: Browser): Promise<ChatTestApp> {
+export async function openChatTestApp(
+ browser: Browser,
+ options: { mockTransport?: boolean } = {}
+): Promise<ChatTestApp> {
const page = await browser.newPage()
await page.goto('/')
await page.evaluate(async () => {
@@ -22,7 +22,7 @@ export async function openChatTestApp(browser: Browser): Promise<ChatTestApp> {
await page.waitForFunction(() => document.documentElement.dataset.theme === 'dark')
const canvas = new CanvasHelper(page)
await canvas.waitForInit()
- if (!USE_REAL_LLM) await injectMockChatTransport(page)
+ if (options.mockTransport !== false) await injectMockChatTransport(page)
return { page, canvas }
}
@@ -42,18 +42,15 @@ export function apiKeyInput(page: Page) {
return page.getByTestId('provider-settings-api-key')
}
-export async function configureChat(page: Page): Promise<void> {
- const key = USE_REAL_LLM ? OPENROUTER_KEY : 'sk-or-test-key-12345'
+export async function configureOpenRouter(page: Page, apiKey: string): Promise<void> {
await chatTab(page).click()
await page.getByTestId('provider-setup-open-settings').click()
await page.locator('[data-model-id]').first().click()
await page.getByTestId('settings-model-provider').click()
await page.getByRole('option', { name: 'OpenRouter' }).click()
await page.getByLabel('Name').fill('Claude Sonnet')
- await apiKeyInput(page).fill(key)
+ await apiKeyInput(page).fill(apiKey)
await page.getByRole('button', { name: 'Save model' }).click()
await page.getByTestId('app-settings-done').click()
await chatInput(page).waitFor()
}
-
-export { USE_REAL_LLM }