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
test(e2e): built-in ctx honest end to end — dropdown swap + expert panel (ENG-5)
purple9df623b71e06
diff --git a/e2e/builtin-ctx.spec.ts b/e2e/builtin-ctx.spec.tsnew file mode 100644index 00000000..076d5fa8--- /dev/null+++ b/e2e/builtin-ctx.spec.ts@@ -0,0 +1,102 @@+import { test, expect, type Page } from '@playwright/test'+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME } from './support/tauri-mock'++/**+ * ENG-5 acceptance — the built-in engine's context window is HONEST end to end:+ *+ * 1. The Context dropdown relaunches the engine with the chosen ctx (the+ * tuning is injected from settings into swap_bundled_model), and the+ * TokenCounter denominator follows the engine's reported ctx — not a+ * hardcoded guess (the pre-2.6.0 counter lied with a fixed 16k).+ * 2. The Settings → AI Backends expert panel (ENG-2) shows the live engine+ * status incl. its real ctx and "Apply & Restart Engine" relaunches with+ * the edited tuning.+ *+ * The Tauri mock mirrors ENG-1 Rust semantics: every start/swap derives the+ * engine ctx from the injected tuning and `bundled_engine_status` reports it.+ */++async function completeBuiltinOnboarding(page: Page) {+ await page.addInitScript(tauriMockInit, {+ assistantReply: DEFAULT_ASSISTANT_REPLY,+ modelName: DEFAULT_MODEL_NAME,+ })+ await page.goto('/')++ await expect(page.getByRole('button', { name: /Get Started/i })).toBeVisible()+ await page.getByRole('button', { name: /Get Started/i }).click()+ await expect(page.getByRole('button', { name: /Continue/i })).toBeVisible()+ await page.getByRole('button', { name: /Continue/i }).click()+ await expect(page.getByRole('button', { name: /Skip for now/i })).toBeVisible()+ await page.getByRole('button', { name: /Skip for now/i }).click()+ await expect(page.getByRole('heading', { name: /Pick a starter model/i })).toBeVisible()+ await page.getByRole('button', { name: /Qwen 2\.5 0\.5B/i }).click()+ await page.getByRole('button', { name: /Install \d+ model/i }).click()+ await expect(page.getByRole('button', { name: /Skip for now/i })).toBeVisible({ timeout: 30_000 })+ await page.getByRole('button', { name: /Skip for now/i }).click()+ await expect(page.getByRole('button', { name: /Get Started/i })).toBeVisible()+ await page.getByRole('button', { name: /Get Started/i }).click()+}++test('context dropdown relaunches the built-in engine and the counter follows', async ({ page }) => {+ await completeBuiltinOnboarding(page)++ // Chat once so the TokenCounter renders (it needs messages).+ 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()+ await expect(page.getByText(/PONG_BUILTIN_OK/)).toBeVisible({ timeout: 20_000 })++ // Default tuning: engine runs with -c 8192 → dropdown trigger "ctx 8K",+ // counter denominator 8.2k. Both read the SAME status.ctx (ENG-3).+ const trigger = page.getByRole('button', { name: /ctx 8K/ })+ await expect(trigger).toBeVisible()+ await expect(page.getByText(/\/8\.2k/)).toBeVisible()++ // Pick 16K → apply() persists tuning.ctx and swaps the running engine.+ await trigger.click()+ await page.getByRole('button', { name: /^16K$/ }).click()++ await expect(page.getByRole('button', { name: /ctx 16K/ })).toBeVisible({ timeout: 10_000 })+ await expect(page.getByText(/\/16\.4k/)).toBeVisible()++ // The relaunch carried the settings-injected tuning, aimed at the loaded GGUF.+ const swap = await page.evaluate(() => {+ const calls = (window as unknown as { __E2E_ENGINE_CALLS__?: { cmd: string; modelPath?: string; tuning?: { ctx?: number } }[] }).__E2E_ENGINE_CALLS__ || []+ return calls.filter((c) => c.cmd === 'swap_bundled_model').pop() ?? null+ })+ expect(swap?.tuning?.ctx).toBe(16384)+ expect(swap?.modelPath).toContain(DEFAULT_MODEL_NAME)+})++test('expert panel shows live engine status and Apply & Restart uses the edited tuning', async ({ page }) => {+ await completeBuiltinOnboarding(page)++ await page.getByRole('button', { name: 'Settings' }).click()+ await page.getByRole('button', { name: /AI Backends/i }).click()++ // The expert section only renders while the managed built-in engine+ // occupies the openai slot — which the onboarding just configured. It is+ // a collapsed <Section>; open it first.+ await page.getByRole('button', { name: /Built-in Engine \(expert\)/i }).click()+ await expect(page.getByText(/Expert settings for the built-in engine/i)).toBeVisible()+ await expect(page.getByText(/Engine running/)).toBeVisible()+ await expect(page.getByText(/ctx 8,192/)).toBeVisible()++ // Raise the context, then Apply & Restart → swap with the new tuning and+ // the status line re-reads the engine's real ctx.+ const ctxInput = page.locator('input[placeholder="8192"]')+ await ctxInput.fill('32768')+ await page.getByRole('button', { name: /Apply & Restart Engine/i }).click()+ await expect(page.getByText(/ctx 32,768/)).toBeVisible({ timeout: 10_000 })++ const swap = await page.evaluate(() => {+ const calls = (window as unknown as { __E2E_ENGINE_CALLS__?: { cmd: string; tuning?: { ctx?: number; cacheTypeK?: string } }[] }).__E2E_ENGINE_CALLS__ || []+ return calls.filter((c) => c.cmd === 'swap_bundled_model').pop() ?? null+ })+ expect(swap?.tuning?.ctx).toBe(32768)+ // The full tuning blob rides along (not just ctx) — the whole point of ENG-2.+ expect(swap?.tuning?.cacheTypeK).toBeDefined()+})diff --git a/e2e/support/tauri-mock.ts b/e2e/support/tauri-mock.tsindex 60110b24..a2cab497 100644--- a/e2e/support/tauri-mock.ts+++ b/e2e/support/tauri-mock.ts@@ -41,6 +41,12 @@ export function tauriMockInit(opts: TauriMockOptions) {// very next `download_progress` poll so `awaitDownloadComplete` resolves fast.const startedDownloads = new Set<string>()+ // ENG-1 mirror: the ctx the "engine" is currently running with. Every+ // start/swap derives it from the injected tuning (0 = Rust default 8192),+ // and `bundled_engine_status` reports it back — exactly the loop the token+ // counter and the expert panel rely on.+ let engineCtx = 8192+const enc = (s: string) => Array.from(new TextEncoder().encode(s))// Ordered OpenAI SSE for one assistant turn, ending with [DONE].@@ -90,12 +96,22 @@ export function tauriMockInit(opts: TauriMockOptions) {// ── built-in engine lifecycle (engine.rs surface) ─────────────case 'start_bundled_engine':- case 'swap_bundled_model':+ case 'swap_bundled_model': {+ // Record every launch so specs can assert the settings-injected tuning+ // (api/engine.ts merges settings.builtinEngine into each call).+ ;(w.__E2E_ENGINE_CALLS__ = w.__E2E_ENGINE_CALLS__ || []).push({+ cmd,+ modelPath: args?.modelPath,+ tuning: args?.tuning,+ })+ const t = args?.tuning+ engineCtx = t && typeof t.ctx === 'number' && t.ctx > 0 ? t.ctx : 8192return 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 })+ return Promise.resolve({ running: true, healthy: true, port: 8127, model_path: modelPath, ctx: engineCtx })case 'list_bundled_models':return Promise.resolve({dir: MODELS_DIR,