The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(engine): P3b — Playwright harness + fresh-onboarding→chat e2e
purplec3ef287eef13
diff --git a/.gitignore b/.gitignoreindex 0aae7c02..76ddbae3 100644--- a/.gitignore+++ b/.gitignore@@ -67,3 +67,9 @@ SETUP_REPORT.md# Built-in engine: llama.cpp build cache (P0 scripts/build-llama.sh).llama-build/++# Playwright e2e+/test-results/+/playwright-report/+/blob-report/+/playwright/.cache/diff --git a/e2e/onboarding-builtin.spec.ts b/e2e/onboarding-builtin.spec.tsnew file mode 100644index 00000000..1a8b7a61--- /dev/null+++ b/e2e/onboarding-builtin.spec.ts@@ -0,0 +1,64 @@+import { test, expect, type Page } from '@playwright/test'+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME } from './support/tauri-mock'++/**+ * P3b acceptance test — fresh onboarding → first chat over the built-in engine.+ *+ * With no external provider running (the Tauri mock reports Ollama/LM+ * Studio/ComfyUI unreachable), a brand-new install must be able to:+ * welcome → pick built-in (preselected) → download starter GGUF →+ * boot the bundled engine → finish → send a message → get a streamed reply.+ *+ * The reply text is a fixed marker the mocked engine "generates", so a green+ * run proves the whole managed-backend chat path is wired end to end.+ */++async function installMock(page: Page) {+ await page.addInitScript(tauriMockInit, {+ assistantReply: DEFAULT_ASSISTANT_REPLY,+ modelName: DEFAULT_MODEL_NAME,+ })+}++test('fresh onboarding boots the built-in engine and answers a chat', async ({ page }) => {+ await installMock(page)+ await page.goto('/')++ // welcome+ await expect(page.getByRole('button', { name: /Get Started/i })).toBeVisible()+ await page.getByRole('button', { name: /Get Started/i }).click()++ // backends — built-in engine is preselected, just continue+ await expect(page.getByRole('button', { name: /Continue/i })).toBeVisible()+ await page.getByRole('button', { name: /Continue/i }).click()++ // comfyui — skip (built-in text path doesn't need image gen)+ await expect(page.getByRole('button', { name: /Skip for now/i })).toBeVisible()+ await page.getByRole('button', { name: /Skip for now/i }).click()++ // models — select the starter GGUF, then install. The step auto-advances to+ // embeddings once the (mocked) download completes and the engine boots.+ await expect(page.getByRole('heading', { name: /Pick a starter model/i })).toBeVisible()+ await page.getByRole('button', { name: /Qwen 2\.5 0\.5B/i }).click()+ const installBtn = page.getByRole('button', { name: /Install \d+ model/i })+ await expect(installBtn).toBeVisible()+ await installBtn.click()++ // embeddings — skip; onboarding is Ollama-free on the built-in path+ await expect(page.getByRole('button', { name: /Skip for now/i })).toBeVisible({ timeout: 30_000 })+ await page.getByRole('button', { name: /Skip for now/i }).click()++ // done — finish sets onboardingDone and reveals the chat UI+ await expect(page.getByRole('button', { name: /Get Started/i })).toBeVisible()+ await page.getByRole('button', { name: /Get Started/i }).click()++ // chat — open a fresh conversation, which reveals the composer+ await page.getByRole('button', { name: /New Chat/i }).click()+ const composer = page.locator('textarea').first()+ await expect(composer).toBeVisible({ timeout: 20_000 })+ await composer.fill('ping the built-in engine')+ await page.getByRole('button', { name: /Send message/i }).click()++ // streamed assistant reply from the mocked built-in engine+ await expect(page.getByText(/PONG_BUILTIN_OK/)).toBeVisible({ timeout: 20_000 })+})diff --git a/e2e/support/tauri-mock.ts b/e2e/support/tauri-mock.tsnew file mode 100644index 00000000..c9760fb5--- /dev/null+++ b/e2e/support/tauri-mock.ts@@ -0,0 +1,192 @@+/* eslint-disable @typescript-eslint/no-explicit-any -- this stub is serialized+ into the browser page and stands in for Tauri's untyped `invoke` bridge; the+ dynamic command args and the `window` globals are `any` by nature. */+/**+ * In-page Tauri bridge mock for the built-in-engine e2e (P3b).+ *+ * Injected with `page.addInitScript` BEFORE the app boots, so+ * `window.__TAURI_INTERNALS__` exists when `isTauri()` (src/api/backend.ts)+ * first runs. Every `invoke()` from `@tauri-apps/api/core` funnels into+ * `__TAURI_INTERNALS__.invoke`, so this router stands in for the whole Rust+ * command surface — no Ollama, no llama-server, no ComfyUI.+ *+ * The interesting part is chat streaming: `proxy_localhost_stream_chunked`+ * receives an `onChunk` Tauri Channel whose `onmessage` the app has already+ * wired to a ReadableStream. We push OpenAI-shaped SSE bytes through it, then+ * an empty chunk (Rust's EOF marker), exactly like the real proxy.+ */++export interface TauriMockOptions {+ /** Assistant text the mocked built-in engine "generates" for the first chat. */+ assistantReply: string+ /** Picker id of the bundled starter model the engine reports as loaded. */+ modelName: string+}++export const DEFAULT_ASSISTANT_REPLY = 'PONG_BUILTIN_OK the built-in engine answered.'+export const DEFAULT_MODEL_NAME = 'qwen2.5-0.5b-instruct-q4_k_m'++/**+ * The function body below is serialized and runs in the PAGE context — it must+ * be fully self-contained (no imports, no outer closure references except the+ * single `opts` argument Playwright forwards).+ */+export function tauriMockInit(opts: TauriMockOptions) {+ const w = window as any+ const MODELS_DIR = '/tmp/lu-e2e/models'+ const modelFile = `${opts.modelName}.gguf`+ const modelPath = `${MODELS_DIR}/${modelFile}`++ // Filenames whose download the app kicked off — reported "complete" on the+ // very next `download_progress` poll so `awaitDownloadComplete` resolves fast.+ const startedDownloads = new Set<string>()++ const enc = (s: string) => Array.from(new TextEncoder().encode(s))++ // Ordered OpenAI SSE for one assistant turn, ending with [DONE].+ function chatSse(text: string): string {+ const frame = (delta: Record<string, unknown>, finish: string | null) =>+ `data: ${JSON.stringify({+ id: 'chatcmpl-e2e',+ object: 'chat.completion.chunk',+ model: opts.modelName,+ choices: [{ index: 0, delta, finish_reason: finish }],+ })}\n\n`+ return (+ frame({ role: 'assistant' }, null) ++ frame({ content: text }, null) ++ frame({}, 'stop') ++ 'data: [DONE]\n\n'+ )+ }++ function router(cmd: string, args: any): Promise<any> {+ switch (cmd) {+ // ── onboarding / lifecycle markers ────────────────────────────+ case 'is_onboarding_done':+ return Promise.resolve(false)+ case 'set_onboarding_done':+ return Promise.resolve(null)++ // ── model dir + download ──────────────────────────────────────+ case 'detect_model_path':+ return Promise.resolve(MODELS_DIR)+ case 'download_model_to_path': {+ const fn = args?.filename+ if (fn) startedDownloads.add(fn)+ return Promise.resolve({ status: 'started', id: `dl-${fn}` })+ }+ case 'download_progress': {+ const out: Record<string, any> = {}+ for (const fn of startedDownloads) {+ out[fn] = { progress: 1, total: 1, speed: 0, filename: fn, status: 'complete' }+ }+ return Promise.resolve(out)+ }+ case 'pause_download':+ case 'cancel_download':+ case 'resume_download':+ return Promise.resolve(null)++ // ── built-in engine lifecycle (engine.rs surface) ─────────────+ case 'start_bundled_engine':+ case 'swap_bundled_model':+ return Promise.resolve(8127)+ case 'stop_bundled_engine':+ return Promise.resolve(null)+ case 'bundled_engine_status':+ return Promise.resolve({ running: true, healthy: true, port: 8127, model_path: modelPath })+ case 'list_bundled_models':+ return Promise.resolve({+ dir: MODELS_DIR,+ models: [{ name: opts.modelName, path: modelPath, size: 400 * 1024 * 1024, loaded: true }],+ })++ // ── detection: nothing external is running ────────────────────+ case 'get_ollama_host':+ return Promise.resolve('http://localhost:11434')+ case 'lmstudio_model_context':+ // Real Rust returns a shaped object; a null default here trips+ // useActiveContextWindow (`info.loaded`). Return the "unknown" shape.+ return Promise.resolve({ loaded: null, max: null, state: null })+ case 'start_ollama':+ case 'lmstudio_server_status':+ case 'comfyui_status':+ case 'whisper_status':+ case 'install_tts_status':+ case 'search_status':+ return Promise.reject('not running (e2e)')++ // ── chat streaming: drive the onChunk Channel ─────────────────+ case 'proxy_localhost_stream_chunked': {+ const channel = args?.onChunk+ const bytes = enc(chatSse(opts.assistantReply))+ // Deliver on a macrotask so the app's `settled` promise is already+ // being awaited, mirroring the async Rust→WebView channel delivery.+ setTimeout(() => {+ try {+ channel?.onmessage?.(bytes)+ channel?.onmessage?.([]) // empty chunk = EOF marker+ } catch {+ /* reader gone */+ }+ }, 0)+ return Promise.resolve(null)+ }+ case 'proxy_localhost_stream':+ return Promise.resolve(enc(chatSse(opts.assistantReply)))+ case 'cancel_proxy_stream':+ return Promise.resolve(null)++ // ── generic localhost proxy ───────────────────────────────────+ // Ollama's model list (`/api/tags`) must resolve to an EMPTY list so a+ // fresh box looks fresh (existingModelCount === 0 keeps the model picker+ // visible instead of auto-skipping). Resolving here also stops localFetch+ // from falling through to a direct fetch that could hit a REAL Ollama on+ // the dev machine. Every other probe rejects, so no external backend is+ // ever detected as live.+ case 'proxy_localhost': {+ const url: string = args?.url || ''+ if (url.includes('11434') || /\/tags(\?|$)/.test(url)) {+ return Promise.resolve(JSON.stringify({ models: [] }))+ }+ return Promise.reject('error sending request: connection refused (e2e)')+ }++ default:+ // Tauri plugin channels (event listen/unlisten, window, etc.) and any+ // unmodeled command: resolve benignly so nothing throws on boot.+ if (cmd.startsWith('plugin:')) return Promise.resolve(0)+ return Promise.resolve(null)+ }+ }++ let callbackId = 0+ const callbacks: Record<number, (v: any) => void> = {}++ w.__TAURI_INTERNALS__ = {+ metadata: {+ currentWindow: { label: 'main' },+ currentWebview: { label: 'main' },+ },+ // Channel/event construction routes through here.+ transformCallback(cb: (v: any) => void) {+ const id = ++callbackId+ callbacks[id] = cb+ w[`_${id}`] = cb+ return id+ },+ unregisterCallback(id: number) {+ delete callbacks[id]+ delete w[`_${id}`]+ },+ convertFileSrc(path: string) {+ return path+ },+ invoke(cmd: string, args: any) {+ return router(cmd, args)+ },+ }+ // Legacy v1 alias some detection code still probes for.+ w.__TAURI__ = w.__TAURI_INTERNALS__+}diff --git a/package-lock.json b/package-lock.jsonindex 0b0295ed..a39d34ac 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "locally-uncensored",- "version": "2.5.4",+ "version": "2.5.6","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "locally-uncensored",- "version": "2.5.4",+ "version": "2.5.6","license": "AGPL-3.0","dependencies": {"@react-three/drei": "^10.7.7",@@ -37,6 +37,7 @@},"devDependencies": {"@eslint/js": "^9.39.4",+ "@playwright/test": "^1.61.1","@tauri-apps/api": "^2.10.1","@tauri-apps/cli": "^2.10.1","@types/node": "^24.12.0",@@ -891,6 +892,22 @@"url": "https://github.com/sponsors/Boshen"}},+ "node_modules/@playwright/test": {+ "version": "1.61.1",+ "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.61.1.tgz",+ "integrity": "sha512-8nKv6+0RJSL9FE4jYOEGXnPeM/Hg12qZpmqzZjRh3qM0Y7c3z1mrOTfFLids72RDQYVh9WpLEfR5WdpNX4fkig==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "playwright": "1.61.1"+ },+ "bin": {+ "playwright": "cli.js"+ },+ "engines": {+ "node": ">=18"+ }+ },"node_modules/@react-three/drei": {"version": "10.7.7","resolved": "https://registry.npmjs.org/@react-three/drei/-/drei-10.7.7.tgz",@@ -5555,6 +5572,53 @@"url": "https://github.com/sponsors/jonschlinkert"}},+ "node_modules/playwright": {+ "version": "1.61.1",+ "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.61.1.tgz",+ "integrity": "sha512-DWnY5o3YbLWK4GovuAVwpqL+1VwGNdUGrRr++8j8PtQQzvAVZUIMjKQ90fY689sEJZJBbZVw1rXaOKSTitkzPQ==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "playwright-core": "1.61.1"+ },+ "bin": {+ "playwright": "cli.js"+ },+ "engines": {+ "node": ">=18"+ },+ "optionalDependencies": {+ "fsevents": "2.3.2"+ }+ },+ "node_modules/playwright-core": {+ "version": "1.61.1",+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.61.1.tgz",+ "integrity": "sha512-h7Qlt6m4REp25qvIdvbDtVmD4LqVXfpRxhORv9L0jzETM05p4fuPJ3dKyuSXQxDSbXnmS79HAgi9589lGSpLkg==",+ "dev": true,+ "license": "Apache-2.0",+ "bin": {+ "playwright-core": "cli.js"+ },+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/playwright/node_modules/fsevents": {+ "version": "2.3.2",+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",+ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",+ "dev": true,+ "hasInstallScript": true,+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ],+ "engines": {+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"+ }+ },"node_modules/postcss": {"version": "8.5.15","resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.15.tgz",diff --git a/package.json b/package.jsonindex 9b20a7a4..45e77861 100644--- a/package.json+++ b/package.json@@ -31,7 +31,8 @@"preview": "vite preview","tauri": "tauri","tauri:dev": "tauri dev",- "tauri:build": "tauri build"+ "tauri:build": "tauri build",+ "test:e2e": "playwright test"},"dependencies": {"@react-three/drei": "^10.7.7",@@ -62,6 +63,7 @@},"devDependencies": {"@eslint/js": "^9.39.4",+ "@playwright/test": "^1.61.1","@tauri-apps/api": "^2.10.1","@tauri-apps/cli": "^2.10.1","@types/node": "^24.12.0",diff --git a/playwright.config.ts b/playwright.config.tsnew file mode 100644index 00000000..f04f78aa--- /dev/null+++ b/playwright.config.ts@@ -0,0 +1,42 @@+import { defineConfig, devices } from '@playwright/test'++/**+ * Playwright harness for the 2.5.7 built-in-engine onboarding (P3b).+ *+ * The suite drives the real React app in a headless browser with the Tauri+ * bridge stubbed (see `e2e/support/tauri-mock.ts`): injecting+ * `window.__TAURI_INTERNALS__` makes `isTauri()` true, so every backend call+ * and the streaming chat proxy route through our in-page invoke router instead+ * of a real Rust sidecar. That lets the fresh-onboarding → first-chat happy+ * path run with zero external processes (no Ollama, no llama-server).+ *+ * We serve the app with `npm run dev` (Vite, port 5173 — the tauri devUrl). The+ * dev middleware only spawns on `/local-api/*` requests, which the mock never+ * triggers, so boot has no side effects.+ */+export default defineConfig({+ testDir: './e2e',+ fullyParallel: false,+ forbidOnly: !!process.env.CI,+ retries: 0,+ workers: 1,+ reporter: [['list']],+ timeout: 60_000,+ expect: { timeout: 15_000 },+ use: {+ baseURL: 'http://localhost:5173',+ trace: 'on-first-retry',+ headless: true,+ },+ projects: [+ { name: 'chromium', use: { ...devices['Desktop Chrome'] } },+ ],+ webServer: {+ command: 'npm run dev',+ url: 'http://localhost:5173',+ reuseExistingServer: !process.env.CI,+ timeout: 120_000,+ stdout: 'ignore',+ stderr: 'pipe',+ },+})