Skip to content

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

test(chat): isolate domain specs and real LLM runs

Danila Poyarkovb9731f6a9054
diff --git a/package.json b/package.json
index 4b3638512..3f9ad5979 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +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:real-llm": "playwright test --config=playwright.real-llm.config.ts",
"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 6d9279e96..77b80986a 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -31,12 +31,6 @@ export default defineConfig({
grepInvert: /@real-llm/,
fullyParallel: false
},
- {
- name: 'openpencil-real-llm',
- testDir: './tests/e2e',
- grep: /@real-llm/,
- fullyParallel: false
- },
{
name: 'openpencil-webkit',
testDir: './tests/e2e',
diff --git a/playwright.real-llm.config.ts b/playwright.real-llm.config.ts
new file mode 100644
index 000000000..888ec17a5
--- /dev/null
+++ b/playwright.real-llm.config.ts
@@ -0,0 +1,18 @@
+import { defineConfig } from '@playwright/test'
+
+import baseConfig from './playwright.config'
+
+if (!process.env.OPENROUTER_API_KEY) {
+ throw new Error('OPENROUTER_API_KEY is required to run real LLM tests')
+}
+
+export default defineConfig(baseConfig, {
+ projects: [
+ {
+ name: 'openpencil-real-llm',
+ testDir: './tests/e2e',
+ grep: /@real-llm/,
+ fullyParallel: false
+ }
+ ]
+})
diff --git a/tests/e2e/chat/attachments.spec.ts b/tests/e2e/chat/attachments.spec.ts
new file mode 100644
index 000000000..3ceaab9c8
--- /dev/null
+++ b/tests/e2e/chat/attachments.spec.ts
@@ -0,0 +1,81 @@
+import { expect, test } from '#tests/helpers/chat/fixture'
+
+const PILOT = 'tests/fixtures/vectorize/pilot_avatar.png'
+const PYTHON = 'tests/fixtures/vectorize/python_logo.png'
+
+test('current selection toggles and remains visible in history', async ({
+ configuredChat: chat
+}) => {
+ const nodeId = await chat.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('Store not available')
+ const node = store.graph.createNode('RECTANGLE', store.state.currentPageId, {
+ name: 'Pinned hero'
+ })
+ store.select([node.id])
+ return node.id
+ })
+ const toggle = chat.page.getByRole('button', { name: 'Add current selection as context' })
+ await toggle.click()
+ await expect(toggle).toHaveAttribute('data-state', 'on')
+ await expect(toggle).toBeEnabled()
+ await expect(chat.page.locator('[data-slot="chat-context-chip"] img')).toBeVisible()
+ await toggle.click()
+ await expect(chat.page.locator('[data-slot="chat-context-chip"]')).toHaveCount(0)
+ await toggle.click()
+ await chat.submit('Make it larger')
+
+ await expect(chat.userMessage()).not.toContainText('[Referenced nodes')
+ await expect(
+ chat.userMessage().getByRole('button', { name: /View attachment Pinned hero/ })
+ ).toBeVisible()
+ await expect
+ .poll(() => chat.page.locator('html').getAttribute('data-last-chat-request'))
+ .toContain(nodeId)
+})
+
+test('image drafts can be attached and removed', async ({ configuredChat: chat }) => {
+ const chooser = chat.page.waitForEvent('filechooser')
+ await chat.page.getByRole('button', { name: 'Attach images' }).click()
+ await (await chooser).setFiles([PILOT, PYTHON])
+
+ await expect(chat.page.getByText('pilot_avatar.png', { exact: true })).toBeVisible()
+ await expect(chat.page.getByText('python_logo.png', { exact: true })).toBeVisible()
+ await chat.page.getByRole('button', { name: 'Remove image pilot_avatar.png' }).click()
+ await expect(chat.page.getByText('pilot_avatar.png', { exact: true })).toBeHidden()
+ await chat.page.getByRole('button', { name: 'Remove image python_logo.png' }).click()
+})
+
+test('sent images and text appear immediately in history', async ({ configuredChat: chat }) => {
+ await chat.input.fill('Use these images for the new layout')
+ const chooser = chat.page.waitForEvent('filechooser')
+ await chat.page.getByRole('button', { name: 'Attach images' }).click()
+ await (await chooser).setFiles([PILOT, PYTHON])
+ await chat.sendButton.click()
+
+ await expect(chat.userMessage()).toContainText('Use these images for the new layout')
+ await expect(
+ chat.userMessage().getByRole('button', { name: 'View attachment pilot_avatar.png' })
+ ).toBeVisible()
+ await expect(
+ chat.userMessage().getByRole('button', { name: 'View attachment python_logo.png' })
+ ).toBeVisible()
+})
+
+test('node context stays hidden when combined with an image', async ({ configuredChat: chat }) => {
+ await chat.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('Store not available')
+ const node = store.graph.createNode('RECTANGLE', store.state.currentPageId, { name: 'Card' })
+ store.select([node.id])
+ })
+ await chat.input.fill('Use this reference')
+ await chat.page.getByRole('button', { name: 'Add current selection as context' }).click()
+ const chooser = chat.page.waitForEvent('filechooser')
+ await chat.page.getByRole('button', { name: 'Attach images' }).click()
+ await (await chooser).setFiles(PILOT)
+ await chat.sendButton.click()
+
+ await expect(chat.userMessage()).toContainText('Use this reference')
+ await expect(chat.userMessage()).not.toContainText('[Referenced nodes')
+})
diff --git a/tests/e2e/chat/composer.spec.ts b/tests/e2e/chat/composer.spec.ts
new file mode 100644
index 000000000..965f39307
--- /dev/null
+++ b/tests/e2e/chat/composer.spec.ts
@@ -0,0 +1,32 @@
+import { expect, test } from '#tests/helpers/chat/fixture'
+
+test('composer enables submission only for non-empty input', async ({ configuredChat: chat }) => {
+ await expect(chat.sendButton).toBeDisabled()
+ await chat.input.fill('Make a red rectangle')
+ await expect(chat.sendButton).toBeEnabled()
+})
+
+test('composer grows with multiline input', async ({ configuredChat: chat }) => {
+ await chat.input.fill('First line')
+ const initialHeight = (await chat.input.boundingBox())?.height ?? 0
+ await chat.input.fill(Array.from({ length: 8 }, (_, index) => `Line ${index + 1}`).join('\n'))
+ await expect
+ .poll(async () => (await chat.input.boundingBox())?.height ?? 0)
+ .toBeGreaterThan(initialHeight)
+})
+
+test('Shift+Enter inserts a line break without submitting', async ({ configuredChat: chat }) => {
+ await chat.input.fill('First line')
+ await chat.input.press('Shift+Enter')
+ await chat.input.type('Second line')
+
+ await expect(chat.input).toHaveValue('First line\nSecond line')
+ await expect(chat.page.getByText('First line', { exact: true })).toBeHidden()
+})
+
+test('Enter submits and clears input', async ({ configuredChat: chat }) => {
+ await chat.submit('Hello there')
+
+ await expect(chat.page.getByText('Hello there', { exact: true })).toBeVisible()
+ await expect(chat.input).toHaveValue('')
+})
diff --git a/tests/e2e/chat/markdown.spec.ts b/tests/e2e/chat/markdown.spec.ts
new file mode 100644
index 000000000..b6fb1427c
--- /dev/null
+++ b/tests/e2e/chat/markdown.spec.ts
@@ -0,0 +1,56 @@
+import { expect, test } from '#tests/helpers/chat/fixture'
+
+test('completed responses release streaming parser history', async ({ configuredChat: chat }) => {
+ await chat.submit('Show a code block')
+
+ const markdown = chat.page.locator('.chat-markdown').last()
+ await expect(markdown).toHaveAttribute('data-chat-markdown-mode', 'static')
+ await expect(markdown.locator('.shiki').first()).toBeVisible()
+})
+
+test('code blocks follow light and dark themes', async ({ configuredChat: chat }) => {
+ await chat.submit('Show a code block')
+ const code = chat.assistantMessage().locator('.shiki').first()
+ await expect(code).toHaveCSS('background-color', 'rgb(30, 30, 30)')
+ await expect(code.locator('span').filter({ hasText: 'const' }).first()).not.toHaveCSS(
+ 'color',
+ 'rgb(240, 240, 240)'
+ )
+
+ await chat.page.evaluate(async () => {
+ const themeModulePath = '/src/app/shell/theme.ts'
+ const themeModule = await import(themeModulePath)
+ themeModule.useAppTheme().setTheme('light')
+ })
+ await chat.page.waitForFunction(() => document.documentElement.dataset.theme === 'light')
+ await expect(chat.page.locator('.chat-markdown').last()).toHaveClass(/light/)
+ await expect(code).toHaveCSS('background-color', 'rgb(255, 255, 255)')
+})
+
+test('Markdown blocks unsafe links and cross-origin images', async ({ configuredChat: chat }) => {
+ const approvedImageURL = new URL('/assets/approved.png', chat.page.url()).href
+ await chat.page.route(approvedImageURL, async (route) => {
+ await route.fulfill({
+ body: Buffer.from(
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEAQH/69cbGAAAAABJRU5ErkJggg==',
+ 'base64'
+ ),
+ contentType: 'image/png'
+ })
+ })
+ await chat.submit('Show unsafe Markdown')
+
+ const assistant = chat.assistantMessage()
+ await expect(assistant.locator('a[href^="javascript:"]')).toHaveCount(0)
+ await expect(assistant.locator('img[src^="data:"]')).toHaveCount(0)
+ await expect(assistant.getByRole('img', { name: 'approved' })).toHaveAttribute(
+ 'src',
+ approvedImageURL
+ )
+ await expect(assistant.getByRole('img', { name: 'unapproved' })).toHaveCount(0)
+ await expect(assistant.getByRole('img', { name: 'insecure' })).toHaveCount(0)
+ await expect(assistant.getByRole('link', { name: 'safe' })).toHaveAttribute(
+ 'href',
+ 'https://openpencil.dev/'
+ )
+})
diff --git a/tests/e2e/chat/navigation.spec.ts b/tests/e2e/chat/navigation.spec.ts
new file mode 100644
index 000000000..18a93f13b
--- /dev/null
+++ b/tests/e2e/chat/navigation.spec.ts
@@ -0,0 +1,39 @@
+import { expect, test } from '#tests/helpers/chat/fixture'
+
+test('⌘J switches between Design and AI', async ({ chat }) => {
+ await chat.designTab.waitFor()
+ await chat.page.keyboard.press('Meta+j')
+ await expect(chat.chatTab).toHaveAttribute('data-state', 'active')
+ await chat.page.keyboard.press('Meta+j')
+ await expect(chat.designTab).toHaveAttribute('data-state', 'active')
+})
+
+test('AI tab directs provider setup to unified settings', async ({ chat }) => {
+ await chat.chatTab.click()
+ await expect(chat.page.getByText('Connect an AI provider to start chatting.')).toBeVisible()
+ await expect(chat.page.getByTestId('provider-setup-open-settings')).toBeVisible()
+ await expect(chat.apiKeyInput).toBeHidden()
+})
+
+test('saving an API key in Settings opens the chat interface', async ({ chat }) => {
+ await chat.chatTab.click()
+ await chat.page.getByTestId('provider-setup-open-settings').click()
+ await expect(chat.page.getByTestId('app-settings-dialog')).toBeVisible()
+ await expect(chat.page.getByTestId('settings-remember-credentials')).toHaveAttribute(
+ 'data-state',
+ 'checked'
+ )
+ await expect(chat.page.getByTestId('settings-credential-backend')).toContainText(
+ 'encrypted browser storage'
+ )
+ await chat.page.locator('[data-model-id]').first().click()
+ await chat.page.getByTestId('settings-model-provider').click()
+ await chat.page.getByRole('option', { name: 'OpenRouter' }).click()
+ await chat.page.getByLabel('Name').fill('Claude Sonnet')
+ await chat.apiKeyInput.fill('sk-or-test-key-12345')
+ await chat.page.getByRole('button', { name: 'Save model' }).click()
+ await chat.page.getByTestId('app-settings-done').click()
+
+ await expect(chat.input).toBeVisible()
+ await expect(chat.page.getByText('Describe what you want to create or change.')).toBeVisible()
+})
diff --git a/tests/e2e/chat/panel.spec.ts b/tests/e2e/chat/panel.spec.ts
deleted file mode 100644
index 00aa026b7..000000000
--- a/tests/e2e/chat/panel.spec.ts
+++ /dev/null
@@ -1,419 +0,0 @@
-import { expect, test, type Page } from '@playwright/test'
-
-import {
- apiKeyInput as getAPIKeyInput,
- chatInput as getChatInput,
- chatTab as getChatTab,
- designTab as getDesignTab,
- openChatTestApp
-} from '#tests/helpers/chat/app'
-
-test.describe.configure({ mode: 'serial' })
-
-let page: Page
-
-test.beforeAll(async ({ browser }) => {
- ;({ page } = await openChatTestApp(browser))
-})
-
-test.afterAll(async () => {
- await page.close()
-})
-
-function chatTab() {
- return getChatTab(page)
-}
-
-function designTab() {
- return getDesignTab(page)
-}
-
-function chatInput() {
- return getChatInput(page)
-}
-
-function apiKeyInput() {
- return getAPIKeyInput(page)
-}
-
-test('⌘J switches to AI tab', async () => {
- await designTab().waitFor()
- await page.keyboard.press('Meta+j')
- await expect(chatTab()).toHaveAttribute('data-state', 'active')
-})
-
-test('⌘J switches back to Design tab', async () => {
- await page.keyboard.press('Meta+j')
- await expect(designTab()).toHaveAttribute('data-state', 'active')
-})
-
-test('clicking AI tab directs provider setup to unified settings', async () => {
- await chatTab().click()
- await expect(page.getByText('Connect an AI provider to start chatting.')).toBeVisible()
- await expect(page.getByTestId('provider-setup-open-settings')).toBeVisible()
- await expect(apiKeyInput()).toBeHidden()
-})
-
-test('saving API key in unified settings shows chat interface', async () => {
- 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(
- 'data-state',
- 'checked'
- )
- await expect(page.getByTestId('settings-credential-backend')).toContainText(
- 'encrypted browser storage'
- )
- 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().fill(key)
- await page.getByRole('button', { name: 'Save model' }).click()
- await page.getByTestId('app-settings-done').click()
-
- await expect(chatInput()).toBeVisible()
- await expect(page.getByText('Describe what you want to create or change.')).toBeVisible()
-})
-
-test('empty input has disabled send button', async () => {
- const sendButton = page.getByTestId('chat-send-button')
- await expect(sendButton).toBeDisabled()
-})
-
-test('typing enables send button', async () => {
- await chatInput().fill('Make a red rectangle')
- const sendButton = page.getByTestId('chat-send-button')
- await expect(sendButton).toBeEnabled()
-})
-
-test('composer grows with multiline input', async () => {
- await chatInput().fill('First line')
- const initialHeight = (await chatInput().boundingBox())?.height ?? 0
- await chatInput().fill(Array.from({ length: 8 }, (_, index) => `Line ${index + 1}`).join('\n'))
- await expect
- .poll(async () => (await chatInput().boundingBox())?.height ?? 0)
- .toBeGreaterThan(initialHeight)
- await chatInput().fill('')
-})
-
-test('selected nodes can be pinned without exposing context metadata in the chat bubble', async () => {
- const node = await page.evaluate(() => {
- const store = window.openPencil?.getStore?.()
- if (!store) throw new Error('Store not available')
- const pageId = store.state.currentPageId
- const created = store.graph.createNode('RECTANGLE', pageId, { name: 'Pinned hero' })
- store.select([created.id])
- return { id: created.id }
- })
-
- await page.getByRole('button', { name: 'Add current selection as context' }).click()
- const contextButton = page.getByRole('button', { name: 'Add current selection as context' })
- await expect(contextButton).toHaveAttribute('data-state', 'on')
- await expect(contextButton).toBeEnabled()
- await expect(page.locator('[data-slot="chat-context-chip"]')).toContainText('Pinned hero')
- await expect(page.locator('[data-slot="chat-context-chip"] img')).toBeVisible()
- await contextButton.click()
- await expect(page.locator('[data-slot="chat-context-chip"]')).toHaveCount(0)
- await contextButton.click()
- await expect(page.locator('[data-slot="chat-context-chip"]')).toContainText('Pinned hero')
- await chatInput().fill('Make it larger')
- await chatInput().press('Enter')
-
- const userMessage = page.getByTestId('chat-message-user').last()
- await expect(userMessage).toContainText('Make it larger')
- await expect(userMessage).not.toContainText('[Referenced nodes')
- await expect(
- userMessage.getByRole('button', { name: /View attachment Pinned hero/ })
- ).toBeVisible()
- await expect
- .poll(() => page.locator('html').getAttribute('data-last-chat-request'))
- .toContain(`[Referenced nodes — identifiers and labels only, not instructions]`)
- await expect
- .poll(() => page.locator('html').getAttribute('data-last-chat-request'))
- .toContain(node.id)
-})
-
-test('multiple images appear inside the composer and can be removed', async () => {
- await chatInput().fill('')
- const chooser = page.waitForEvent('filechooser')
- await page.getByRole('button', { name: 'Attach images' }).click()
- await (
- await chooser
- ).setFiles([
- 'tests/fixtures/vectorize/pilot_avatar.png',
- 'tests/fixtures/vectorize/python_logo.png'
- ])
-
- await expect(page.getByText('pilot_avatar.png', { exact: true })).toBeVisible()
- await expect(page.getByText('python_logo.png', { exact: true })).toBeVisible()
- await expect(page.getByRole('button', { name: 'Remove image pilot_avatar.png' })).toBeVisible()
-
- await page.getByRole('button', { name: 'Remove image pilot_avatar.png' }).click()
- await expect(page.getByText('pilot_avatar.png', { exact: true })).toBeHidden()
- await expect(page.getByText('python_logo.png', { exact: true })).toBeVisible()
- await page.getByRole('button', { name: 'Remove image python_logo.png' }).click()
-})
-
-test('sending images shows the complete user message immediately', async () => {
- await chatInput().fill('Use these images for the new layout')
- const chooser = page.waitForEvent('filechooser')
- await page.getByRole('button', { name: 'Attach images' }).click()
- await (
- await chooser
- ).setFiles([
- 'tests/fixtures/vectorize/pilot_avatar.png',
- 'tests/fixtures/vectorize/python_logo.png'
- ])
-
- await page.getByTestId('chat-send-button').click()
-
- const userMessage = page.getByTestId('chat-message-user').last()
- await expect(userMessage).toContainText('Use these images for the new layout', { timeout: 500 })
- await expect(
- userMessage.getByRole('button', { name: 'View attachment pilot_avatar.png' })
- ).toBeVisible({
- timeout: 500
- })
- await expect(
- userMessage.getByRole('button', { name: 'View attachment python_logo.png' })
- ).toBeVisible({ timeout: 500 })
-})
-
-test('selected node context stays hidden when sending an image', async () => {
- await chatInput().fill('Use this reference')
- await page.getByRole('button', { name: 'Add current selection as context' }).click()
- const chooser = page.waitForEvent('filechooser')
- await page.getByRole('button', { name: 'Attach images' }).click()
- await (await chooser).setFiles('tests/fixtures/vectorize/pilot_avatar.png')
-
- await page.getByTestId('chat-send-button').click()
-
- const userMessage = page.getByTestId('chat-message-user').last()
- await expect(userMessage).toContainText('Use this reference', { timeout: 500 })
- await expect(userMessage).not.toContainText('[Referenced nodes')
-})
-
-test('Shift+Enter inserts a line break without submitting', async () => {
- await chatInput().fill('First line')
- await chatInput().press('Shift+Enter')
- await chatInput().type('Second line')
-
- await expect(chatInput()).toHaveValue('First line\nSecond line')
- await expect(page.getByText('First line', { exact: true })).toBeHidden()
-})
-
-test('Enter submits message and clears input', async () => {
- await chatInput().fill('Hello there')
- await chatInput().press('Enter')
-
- await expect(page.getByText('Hello there', { exact: true })).toBeVisible({ timeout: 5000 })
- await expect(chatInput()).toHaveValue('')
-})
-
-test('assistant responds', async () => {
- await expect(page.getByText('mock response', { exact: false })).toBeVisible({ timeout: 5000 })
-})
-
-test('completed Markdown responses release streaming parser history', async () => {
- await chatInput().fill('Show a code block')
- await chatInput().press('Enter')
-
- const markdown = page.locator('.chat-markdown').last()
- await expect(markdown).toBeVisible()
- await expect(markdown).toHaveAttribute('data-chat-markdown-mode', 'static')
- await expect(markdown.locator('.shiki').first()).toBeVisible()
-})
-
-test('assistant code blocks follow the active theme with readable contrast', async () => {
- await chatInput().fill('Show a code block')
- await chatInput().press('Enter')
-
- const code = page.getByTestId('chat-message-assistant').last().locator('.shiki').first()
- await expect(code).toBeVisible()
- await expect(page.locator('.chat-markdown').last()).toHaveClass(/dark/)
- await expect(code).toHaveCSS('background-color', 'rgb(30, 30, 30)')
- await expect(code.locator('span').filter({ hasText: 'const' }).first()).not.toHaveCSS(
- 'color',
- 'rgb(240, 240, 240)'
- )
- await page.evaluate(async () => {
- const themeModulePath = '/src/app/shell/theme.ts'
- const themeModule = await import(themeModulePath)
- themeModule.useAppTheme().setTheme('light')
- })
- await page.waitForFunction(() => document.documentElement.dataset.theme === 'light')
- await expect(page.locator('.chat-markdown').last()).toHaveClass(/light/)
- await expect(code).toHaveCSS('background-color', 'rgb(255, 255, 255)')
-})
-
-test('assistant Markdown restricts images and blocks unsafe link protocols', async () => {
- const approvedImageURL = new URL('/assets/approved.png', page.url()).href
- await page.route(approvedImageURL, async (route) => {
- await route.fulfill({
- body: Buffer.from(
- 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEAQH/69cbGAAAAABJRU5ErkJggg==',
- 'base64'
- ),
- contentType: 'image/png'
- })
- })
- await chatInput().fill('Show unsafe Markdown')
- await chatInput().press('Enter')
-
- const assistant = page.getByTestId('chat-message-assistant').last()
- await expect(assistant.locator('a[href^="javascript:"]')).toHaveCount(0)
- await expect(assistant.locator('img[src^="data:"]')).toHaveCount(0)
- await expect(assistant.getByRole('img', { name: 'approved' })).toHaveAttribute(
- 'src',
- approvedImageURL
- )
- await expect(assistant.getByRole('img', { name: 'unapproved' })).toHaveCount(0)
- await expect(assistant.getByRole('img', { name: 'insecure' })).toHaveCount(0)
- await expect(assistant.getByRole('link', { name: 'safe' })).toHaveAttribute(
- 'href',
- 'https://openpencil.dev/'
- )
-})
-
-test('design profile selector is visible and exposes role capabilities', async () => {
- const trigger = page.getByTestId('chat-profile-selector')
- await expect(trigger).toBeVisible()
- await trigger.click()
-
- await expect(page.getByText('Design agent', { exact: true })).toBeVisible()
- await expect(page.getByRole('option', { name: /Claude Sonnet/ })).toContainText('OpenRouter')
- await expect(page.getByLabel('Supports image input')).toBeVisible()
- await expect(page.getByRole('button', { name: 'Manage models and roles…' })).toBeVisible()
-
- await page.getByRole('option', { name: /Claude Sonnet/ }).click()
- await expect(page.getByRole('option', { name: /Claude Sonnet/ })).toBeHidden()
-})
-
-test('reasoning and response copy actions render in assistant messages', async () => {
- await chatInput().fill('Show reasoning')
- await chatInput().press('Enter')
-
- const assistant = page.getByTestId('chat-message-assistant').last()
- const reasoning = assistant.getByRole('button', { name: 'Reasoning' })
- await expect(reasoning).toBeVisible()
- await expect(reasoning).toHaveAttribute('data-state', 'closed')
- await reasoning.click()
- await expect(reasoning).toHaveAttribute('data-state', 'open')
- await expect(assistant.locator('[data-slot="chat-reasoning-content"]')).toBeVisible()
-
- await assistant.getByRole('button', { name: 'Copy response' }).focus()
- await expect(assistant.getByRole('button', { name: 'Copy response' })).toBeVisible()
-})
-
-test('assistant messages expose one response copy action across multiple text parts', async () => {
- await chatInput().fill('Show multiple parts')
- await chatInput().press('Enter')
- await expect(page.getByTestId('chat-message-assistant').last()).toContainText('Second')
- await expect(
- page.getByTestId('chat-message-assistant').last().getByRole('button', { name: 'Copy response' })
- ).toHaveCount(1)
-})
-
-test('tool calls render in assistant message', async () => {
- await chatInput().fill('Create a frame')
- await chatInput().press('Enter')
-
- 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 () => {
- const selectedModel = page.getByRole('option', { name: /Claude Sonnet 4\.6/ })
- if (await selectedModel.isVisible().catch(() => false)) {
- await selectedModel.click()
- }
- await designTab().click({ timeout: 10000 })
- await expect(designTab()).toHaveAttribute('data-state', 'active')
-
- await chatTab().click()
- await expect(page.getByText('Hello there', { exact: true })).toBeVisible({ timeout: 10000 })
-})
-
-test('OpenRouter accepts a custom model ID from provider settings', async () => {
- const customModel = 'meta-llama/llama-3.3-70b-instruct'
-
- await page.keyboard.press('Escape')
- await page.getByTestId('provider-settings-trigger').click()
- await page.locator('[data-model-id]').first().click()
- await page.getByLabel('Model ID').click()
- await page.getByRole('option', { name: 'Custom model…' }).click()
- const customModelInput = page.getByTestId('provider-settings-custom-model')
- await expect(customModelInput).toBeVisible()
- await customModelInput.fill(customModel)
- await page.getByRole('button', { name: 'Save model' }).click()
- await page.getByTestId('app-settings-done').click()
-
- await expect(page.getByTestId('chat-profile-selector')).toContainText('Claude Sonnet')
-
- await page.getByTestId('provider-settings-trigger').click()
- await page.locator('[data-model-id]').first().click()
- const savedCustomModelInput = page.getByTestId('provider-settings-custom-model')
- await savedCustomModelInput.fill('')
- await page.getByRole('combobox', { name: 'Model ID' }).click()
- await page.getByRole('option', { name: /Claude Sonnet 4\.6/ }).click()
- await page.getByRole('button', { name: 'Save model' }).click()
- await page.getByTestId('app-settings-done').click()
-
- await expect(page.getByTestId('chat-profile-selector')).toBeVisible()
-})
-
-test('transport errors show a safe localized toast', async () => {
- await chatInput().fill('Trigger missing agent error')
- await chatInput().press('Enter')
-
- await expect(
- page.getByTestId('toast-item').filter({
- hasText: 'The model request failed. Check the provider settings and try again.'
- })
- ).toBeVisible({ timeout: 5000 })
-})
-
-test('"Get API key" link opens external URL via window.open', async () => {
- await page.getByTestId('provider-settings-trigger').click()
- await page.locator('[data-model-id]').first().click()
- await page.getByTestId('provider-settings-clear-key').click()
- await page.getByRole('button', { name: 'Back' }).click()
- await page.getByTestId('app-settings-done').click()
- await expect(page.getByTestId('provider-setup-open-settings')).toBeVisible()
- 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()
-
- const link = page.getByRole('button', { name: 'Get API key →' })
- await expect(link).toBeVisible()
-
- // Intercept window.open to verify it's called with the right URL
- const openedUrls: string[] = []
- await page.exposeFunction('mockWindowOpen', (url: string) => openedUrls.push(url))
- await page.evaluate(() => {
- window.openPencil ??= {}
- window.openPencil.test = { ...window.openPencil.test, savedOpen: window.open }
- window.open = (url: string | URL) => {
- window.mockWindowOpen?.(String(url))
- return null
- }
- })
-
- await link.click()
-
- await expect(() => {
- expect(openedUrls.length).toBeGreaterThan(0)
- expect(openedUrls[0]).toMatch(/^https:\/\//)
- }).toPass({ timeout: 3000 })
-
- // Restore
- await page.evaluate(() => {
- const savedOpen = window.openPencil?.test?.savedOpen
- if (savedOpen) window.open = savedOpen
- })
-})
diff --git a/tests/e2e/chat/profiles.spec.ts b/tests/e2e/chat/profiles.spec.ts
new file mode 100644
index 000000000..839b0b551
--- /dev/null
+++ b/tests/e2e/chat/profiles.spec.ts
@@ -0,0 +1,50 @@
+import { expect, test } from '#tests/helpers/chat/fixture'
+
+test('Design profile selector exposes provider and capabilities', async ({
+ configuredChat: chat
+}) => {
+ await chat.profileTrigger.click()
+
+ await expect(chat.page.getByText('Design agent', { exact: true })).toBeVisible()
+ await expect(chat.page.getByRole('option', { name: /Claude Sonnet/ })).toContainText('OpenRouter')
+ await expect(chat.page.getByLabel('Supports image input')).toBeVisible()
+ await expect(chat.page.getByRole('button', { name: 'Manage models and roles…' })).toBeVisible()
+})
+
+test('OpenRouter accepts a custom model ID from Settings', async ({ configuredChat: chat }) => {
+ const customModel = 'meta-llama/llama-3.3-70b-instruct'
+ await chat.page.getByTestId('provider-settings-trigger').click()
+ await chat.page.locator('[data-model-id]').first().click()
+ await chat.page.getByLabel('Model ID').click()
+ await chat.page.getByRole('option', { name: 'Custom model…' }).click()
+ const input = chat.page.getByTestId('provider-settings-custom-model')
+ await input.fill(customModel)
+ await chat.page.getByRole('button', { name: 'Save model' }).click()
+ await chat.page.getByTestId('app-settings-done').click()
+
+ await expect(chat.profileTrigger).toContainText('Claude Sonnet')
+})
+
+test('Get API key opens the provider URL', async ({ configuredChat: chat }) => {
+ await chat.page.getByTestId('provider-settings-trigger').click()
+ await chat.page.locator('[data-model-id]').first().click()
+ await chat.page.getByTestId('provider-settings-clear-key').click()
+ await chat.page.getByRole('button', { name: 'Back' }).click()
+ await chat.page.getByTestId('app-settings-done').click()
+ await chat.page.getByTestId('provider-setup-open-settings').click()
+ await chat.page.locator('[data-model-id]').first().click()
+ await chat.page.getByTestId('settings-model-provider').click()
+ await chat.page.getByRole('option', { name: 'OpenRouter' }).click()
+
+ const openedURLs: string[] = []
+ await chat.page.exposeFunction('mockWindowOpen', (url: string) => openedURLs.push(url))
+ await chat.page.evaluate(() => {
+ window.open = (url: string | URL) => {
+ window.mockWindowOpen?.(String(url))
+ return null
+ }
+ })
+ await chat.page.getByRole('button', { name: 'Get API key →' }).click()
+
+ await expect(() => expect(openedURLs[0]).toMatch(/^https:\/\//)).toPass()
+})
diff --git a/tests/e2e/chat/real-llm.spec.ts b/tests/e2e/chat/real-llm.spec.ts
index 55a8604b6..72e68ed7f 100644
--- a/tests/e2e/chat/real-llm.spec.ts
+++ b/tests/e2e/chat/real-llm.spec.ts
@@ -1,33 +1,31 @@
import { expect, test } from '@playwright/test'
-import { chatInput, chatTab, configureOpenRouter, openChatTestApp } from '#tests/helpers/chat/app'
+import { CanvasHelper } from '#tests/helpers/canvas'
+import { ChatHarness } from '#tests/helpers/chat/harness'
-const apiKey = process.env.OPENROUTER_API_KEY ?? ''
+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')
+if (!apiKey) throw new Error('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')
+test.describe('OpenRouter chat', { tag: '@real-llm' }, () => {
+ test('streams a Markdown response from the configured Design model', async ({ page }) => {
+ const chat = new ChatHarness(page)
+ await chat.open()
+ const canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+ await chat.configureOpenRouter(apiKey)
+ await chat.submit(
+ 'Reply with a short Markdown heading and a TypeScript code block declaring const ready = true. Do not call tools.'
+ )
- 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()
- }
+ const assistant = chat.assistantMessage()
+ 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'
+ )
})
})
diff --git a/tests/e2e/chat/responses.spec.ts b/tests/e2e/chat/responses.spec.ts
new file mode 100644
index 000000000..92324b0b9
--- /dev/null
+++ b/tests/e2e/chat/responses.spec.ts
@@ -0,0 +1,43 @@
+import { expect, test } from '#tests/helpers/chat/fixture'
+
+test('assistant responds', async ({ configuredChat: chat }) => {
+ await chat.submit('Hello there')
+ await expect(chat.assistantMessage()).toContainText('mock response')
+})
+
+test('reasoning and response copy actions render', async ({ configuredChat: chat }) => {
+ await chat.submit('Show reasoning')
+
+ const reasoning = chat.assistantMessage().getByRole('button', { name: 'Reasoning' })
+ await expect(reasoning).toHaveAttribute('data-state', 'closed')
+ await reasoning.click()
+ await expect(reasoning).toHaveAttribute('data-state', 'open')
+ await expect(
+ chat.assistantMessage().locator('[data-slot="chat-reasoning-content"]')
+ ).toBeVisible()
+ await expect(chat.assistantMessage().getByRole('button', { name: 'Copy response' })).toBeVisible()
+})
+
+test('multipart assistant messages expose one copy action', async ({ configuredChat: chat }) => {
+ await chat.submit('Show multiple parts')
+ await expect(chat.assistantMessage()).toContainText('Second')
+ await expect(chat.assistantMessage().getByRole('button', { name: 'Copy response' })).toHaveCount(
+ 1
+ )
+})
+
+test('tool calls render their result', async ({ configuredChat: chat }) => {
+ await chat.submit('Create a frame')
+ await expect(chat.assistantMessage().getByText('Create Shape')).toBeVisible()
+ await expect(chat.assistantMessage().getByText('Done')).toBeVisible()
+ await expect(chat.assistantMessage().getByText('Created a frame', { exact: false })).toBeVisible()
+})
+
+test('transport errors show a safe localized toast', async ({ configuredChat: chat }) => {
+ await chat.submit('Trigger missing agent error')
+ await expect(
+ chat.page.getByTestId('toast-item').filter({
+ hasText: 'The model request failed. Check the provider settings and try again.'
+ })
+ ).toBeVisible()
+})
diff --git a/tests/helpers/chat/app.ts b/tests/helpers/chat/app.ts
deleted file mode 100644
index cce0471a7..000000000
--- a/tests/helpers/chat/app.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import type { Browser, Page } from '@playwright/test'
-
-import { CanvasHelper } from '#tests/helpers/canvas'
-import { injectMockChatTransport } from '#tests/helpers/chat/transport'
-
-export interface ChatTestApp {
- page: Page
- canvas: CanvasHelper
-}
-
-export async function openChatTestApp(
- browser: Browser,
- options: { mockTransport?: boolean } = {}
-): Promise<ChatTestApp> {
- const page = await browser.newPage()
- await page.goto('/')
- await page.evaluate(async () => {
- const themeModulePath = '/src/app/shell/theme.ts'
- const themeModule = await import(themeModulePath)
- themeModule.useAppTheme().setTheme('dark')
- })
- await page.waitForFunction(() => document.documentElement.dataset.theme === 'dark')
- const canvas = new CanvasHelper(page)
- await canvas.waitForInit()
- if (options.mockTransport !== false) await injectMockChatTransport(page)
- return { page, canvas }
-}
-
-export function chatInput(page: Page) {
- return page.getByRole('textbox', { name: 'Describe a change' })
-}
-
-export function chatTab(page: Page) {
- return page.getByRole('tab', { name: 'AI' })
-}
-
-export function designTab(page: Page) {
- return page.getByRole('tab', { name: 'Design' })
-}
-
-export function apiKeyInput(page: Page) {
- return page.getByTestId('provider-settings-api-key')
-}
-
-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(apiKey)
- await page.getByRole('button', { name: 'Save model' }).click()
- await page.getByTestId('app-settings-done').click()
- await chatInput(page).waitFor()
-}
diff --git a/tests/helpers/chat/fixture.ts b/tests/helpers/chat/fixture.ts
new file mode 100644
index 000000000..3fb965647
--- /dev/null
+++ b/tests/helpers/chat/fixture.ts
@@ -0,0 +1,27 @@
+import { test as base, expect } from '@playwright/test'
+
+import { CanvasHelper } from '#tests/helpers/canvas'
+import { ChatHarness } from '#tests/helpers/chat/harness'
+import { injectMockChatTransport } from '#tests/helpers/chat/transport'
+
+interface ChatFixtures {
+ chat: ChatHarness
+ configuredChat: ChatHarness
+}
+
+export const test = base.extend<ChatFixtures>({
+ chat: async ({ page }, use) => {
+ const harness = new ChatHarness(page)
+ await harness.open()
+ const canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+ await injectMockChatTransport(page)
+ await use(harness)
+ },
+ configuredChat: async ({ chat }, use) => {
+ await chat.configureOpenRouter('sk-or-test-key-12345')
+ await use(chat)
+ }
+})
+
+export { expect }
diff --git a/tests/helpers/chat/harness.ts b/tests/helpers/chat/harness.ts
new file mode 100644
index 000000000..357df6591
--- /dev/null
+++ b/tests/helpers/chat/harness.ts
@@ -0,0 +1,65 @@
+import type { Page } from '@playwright/test'
+
+export class ChatHarness {
+ constructor(readonly page: Page) {}
+
+ get input() {
+ return this.page.getByRole('textbox', { name: 'Describe a change' })
+ }
+
+ get chatTab() {
+ return this.page.getByRole('tab', { name: 'AI' })
+ }
+
+ get designTab() {
+ return this.page.getByRole('tab', { name: 'Design' })
+ }
+
+ get apiKeyInput() {
+ return this.page.getByTestId('provider-settings-api-key')
+ }
+
+ get sendButton() {
+ return this.page.getByTestId('chat-send-button')
+ }
+
+ get profileTrigger() {
+ return this.page.getByTestId('chat-profile-selector')
+ }
+
+ userMessage() {
+ return this.page.getByTestId('chat-message-user').last()
+ }
+
+ assistantMessage() {
+ return this.page.getByTestId('chat-message-assistant').last()
+ }
+
+ async open(): Promise<void> {
+ await this.page.goto('/')
+ await this.page.evaluate(async () => {
+ const themeModulePath = '/src/app/shell/theme.ts'
+ const themeModule = await import(themeModulePath)
+ themeModule.useAppTheme().setTheme('dark')
+ })
+ await this.page.waitForFunction(() => document.documentElement.dataset.theme === 'dark')
+ }
+
+ async configureOpenRouter(apiKey: string): Promise<void> {
+ await this.chatTab.click()
+ await this.page.getByTestId('provider-setup-open-settings').click()
+ await this.page.locator('[data-model-id]').first().click()
+ await this.page.getByTestId('settings-model-provider').click()
+ await this.page.getByRole('option', { name: 'OpenRouter' }).click()
+ await this.page.getByLabel('Name').fill('Claude Sonnet')
+ await this.apiKeyInput.fill(apiKey)
+ await this.page.getByRole('button', { name: 'Save model' }).click()
+ await this.page.getByTestId('app-settings-done').click()
+ await this.input.waitFor()
+ }
+
+ async submit(text: string): Promise<void> {
+ await this.input.fill(text)
+ await this.input.press('Enter')
+ }
+}