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): the agent audit fixes, proven on the running app
purplef89ebeceb9e1
diff --git a/e2e/coding-agent.spec.ts b/e2e/coding-agent.spec.tsnew file mode 100644index 00000000..5880e777--- /dev/null+++ b/e2e/coding-agent.spec.ts@@ -0,0 +1,190 @@+import { test, expect, type Page } from '@playwright/test'+import { tauriMockInit, DEFAULT_MODEL_NAME } from './support/tauri-mock'+import { seedOnboardingDone } from './support/cloud-mock'+import { openNewChat } from './support/ui'++/**+ * End-to-end cover for the 2.6.3 agent audit, driven through the real React+ * app against the built-in engine — the DEFAULT backend, and the one every+ * finding below was measured on.+ *+ * These are the checks no unit test can make, because each one is about the+ * loop, the view lifecycle and the transport agreeing with each other:+ *+ * A1 the Code tab streams on a NON-Ollama transport (the built-in engine+ * is providerId 'openai'); it used to sit silent until the whole call+ * returned, which is what David reported repeatedly.+ * A2 a run started before a tab switch is still stoppable afterwards — the+ * view unmounts, the hook is rebuilt, and the store aborter is what+ * carries the handle across.+ * B1 edit → test → edit → test: the second identical shell command really+ * re-runs instead of being swallowed as a repeat.+ * B8 the agent injects the long shell timeout, so a build is not killed at+ * the Rust side's 2-minute default.+ * C1 file_read pages: offset/limit return a window, not the whole file.+ */++const FILE_LINES = Array.from({ length: 200 }, (_, i) => `line ${i + 1}`).join('\n')++type Turn = { text?: string; toolCalls?: Array<{ name: string; args: Record<string, unknown> }> }++async function boot(page: Page, agentTurns: Turn[]) {+ await page.addInitScript(tauriMockInit, {+ assistantReply: 'unused in agent specs',+ modelName: DEFAULT_MODEL_NAME,+ replyChunkDelayMs: 8,+ agentTurns,+ files: { 'big.ts': FILE_LINES },+ })+ await seedOnboardingDone(page)+ await page.goto('/')+ // Mode first, THEN the chat: the sidebar's mode buttons clear the active+ // conversation by design, so a chat opened before the switch is dropped.+ await page.getByRole('button', { name: 'Code', exact: true }).click()+ await openNewChat(page)+}++async function instruct(page: Page, text: string) {+ const composer = page.locator('textarea').first()+ await expect(composer).toBeVisible({ timeout: 20_000 })+ await page.waitForTimeout(800)+ await composer.fill(text)+ await composer.press('Enter')+}++const toolCalls = (page: Page) =>+ page.evaluate(() => (window as any).__E2E_TOOL_CALLS__ || [])++test('the Code tab streams on the built-in engine instead of painting in one tick', async ({ page }) => {+ // One long prose turn, no tools: the whole point is WHEN the text appears.+ const answer = 'Streaming through the built-in engine, token by token, in the Code tab.'+ await boot(page, [{ text: answer }])++ await instruct(page, 'explain the repo layout')++ // Partial text on screen is the proof: with the old blocking chatWithTools+ // path nothing rendered until the call returned, so no prefix could ever be+ // visible on its own.+ const main = page.getByRole('main')+ await expect(main.getByText(/Streaming through/)).toBeVisible({ timeout: 20_000 })+ await expect(main.getByText(answer)).toBeVisible({ timeout: 20_000 })+})++test('a run survives a tab switch and is still stoppable afterwards', async ({ page }) => {+ // A long script so the run is still going while we switch away and back.+ const turns: Turn[] = Array.from({ length: 40 }, (_, i) => ({+ text: `step ${i + 1}`,+ toolCalls: [{ name: 'file_read', args: { path: `src/file-${i}.ts` } }],+ }))+ await boot(page, turns)++ await instruct(page, 'walk the whole source tree')+ // The run is under way.+ await expect.poll(async () => (await toolCalls(page)).length, { timeout: 20_000 }).toBeGreaterThan(0)++ // Look at another view and come back. AppShell mounts ChatView on+ // `currentView === 'chat'`, so this really unmounts CodexView and rebuilds+ // the hook with empty refs — the exact move that used to orphan the run.+ // (The sidebar's mode buttons clear the active conversation by design, so+ // they would prove something else.)+ const header = page.getByRole('banner')+ await header.getByRole('button', { name: 'Models' }).click()+ await page.waitForTimeout(800)+ await header.getByRole('button', { name: 'Chat' }).click()++ // The remounted view must still show the run as active — before the fix the+ // fresh hook reported idle, offered a second Send and no Stop at all.+ const stop = page.getByRole('button', { name: /Stop/i })+ await expect(stop).toBeVisible({ timeout: 20_000 })++ await stop.click()+ // And Stop actually reaches the controller the OLD hook instance created:+ // the tool calls stop climbing.+ await page.waitForTimeout(1500)+ const settled = (await toolCalls(page)).length+ await page.waitForTimeout(2500)+ expect((await toolCalls(page)).length).toBe(settled)+})++/**+ * Agent mode (the Chat tab with the Agent toggle) is a DIFFERENT loop from the+ * Code tab — useAgentChat, not useCodex — and audit B1/B8 are findings about+ * that loop specifically. Running them in the Code tab proves nothing: useCodex+ * never had the exact-repeat set, and it always injected the shell timeout.+ */+async function bootAgentMode(page: Page, agentTurns: Turn[]) {+ await page.addInitScript(tauriMockInit, {+ assistantReply: 'unused in agent specs',+ modelName: DEFAULT_MODEL_NAME,+ replyChunkDelayMs: 8,+ agentTurns,+ files: { 'big.ts': FILE_LINES },+ })+ await seedOnboardingDone(page)+ // Auto-approve the tool categories this spec drives. Agent mode defaults to+ // asking for terminal/filesystem, and an approval dialog is a different+ // behaviour than the one under test here.+ await page.addInitScript(() => {+ window.localStorage.setItem(+ 'locally-uncensored-permissions',+ JSON.stringify({+ state: {+ globalPermissions: {+ filesystem: 'auto', terminal: 'auto', desktop: 'auto', web: 'auto',+ system: 'auto', image: 'auto', video: 'auto', workflow: 'auto',+ },+ conversationOverrides: {}, perToolOverrides: {}, modeScope: 'agent',+ },+ version: 2,+ }),+ )+ })+ await page.goto('/')+ await openNewChat(page)+ const agentToggle = page.getByRole('main').getByRole('button', { name: 'Agent', exact: true })+ await agentToggle.click()+ await expect(agentToggle).toHaveAttribute('title', /Agent Mode is on/i, { timeout: 10_000 })+ // Activation offers a workspace; the sandbox is the right answer for a spec.+ const sandbox = page.getByRole('button', { name: /Sandbox/i })+ if (await sandbox.isVisible().catch(() => false)) await sandbox.click()+}++test('agent mode: edit, test, edit, test — the second identical command really re-runs', async ({ page }) => {+ const RUN = 'npm test'+ await bootAgentMode(page, [+ { text: 'running the suite', toolCalls: [{ name: 'shell_execute', args: { command: RUN } }] },+ { text: 'fixing it', toolCalls: [{ name: 'file_write', args: { path: 'src/fix.ts', content: 'export const fixed = true' } }] },+ { text: 'verifying', toolCalls: [{ name: 'shell_execute', args: { command: RUN } }] },+ { text: 'Done: the suite is green.' },+ ])++ await instruct(page, 'make the failing test green')+ await expect(page.getByRole('main').getByText('Done: the suite is green.')).toBeVisible({ timeout: 30_000 })++ const calls = await toolCalls(page)+ const shellRuns = calls.filter((c: any) => c.cmd === 'shell_execute' && c.command === RUN)+ // Two real executions. The over-loop guard used to drop the second one and+ // tell the model nothing had changed — with a file_write in between, which+ // is exactly when it HAS changed (audit B1).+ expect(shellRuns.length).toBe(2)++ // And agent mode injects the long shell timeout now, instead of leaving the+ // Rust default of 120 s to kill a real build (audit B8).+ expect(shellRuns[0].timeout).toBe(600000)+})++test('file_read pages a large file instead of dumping it whole', async ({ page }) => {+ await boot(page, [+ { text: 'reading the middle', toolCalls: [{ name: 'file_read', args: { path: 'src/big.ts', offset: 100, limit: 5 } }] },+ { text: 'Read lines 100 to 104.' },+ ])++ await instruct(page, 'show me the middle of big.ts')+ await expect(page.getByRole('main').getByText('Read lines 100 to 104.')).toBeVisible({ timeout: 30_000 })++ // Open the tool block and read what the window actually returned.+ await page.getByRole('main').getByText('file_read').first().click()+ const block = page.getByRole('main')+ await expect(block.getByText(/\[lines 100-104 of 200\]/)).toBeVisible({ timeout: 10_000 })+ await expect(block.getByText(/call file_read again with offset: 105/)).toBeVisible()+})diff --git a/e2e/support/tauri-mock.ts b/e2e/support/tauri-mock.tsindex 211809cc..166101ac 100644--- a/e2e/support/tauri-mock.ts+++ b/e2e/support/tauri-mock.ts@@ -52,6 +52,25 @@ export interface TauriMockOptions {* run against a byte-accurate snapshot of the real API with no network.*/hfTree?: { repo: string; entries: Array<{ type: string; path: string; size: number }> }+ /**+ * Scripted agent turns for the Code / Agent ReAct loop. Turn N of the run is+ * answered by entry N; the last entry repeats once the script runs out (so a+ * text-only final entry ends the loop). Without this the mock answers every+ * turn with plain prose, which means the loop stops after one step and no+ * spec can drive the coding agent at all.+ *+ * Tool-call frames go out as OpenAI streaming deltas, the same shape the+ * built-in engine and every openai-compat backend emit, so the provider's+ * own accumulator is what the spec exercises.+ */+ agentTurns?: Array<{+ /** Prose for this turn, streamed as content deltas. */+ text?: string+ /** Tool calls for this turn, streamed as tool_call deltas. */+ toolCalls?: Array<{ name: string; args: Record<string, unknown> }>+ }>+ /** Canned file contents served to fs_read, keyed by path suffix. */+ files?: Record<string, string>}export const DEFAULT_ASSISTANT_REPLY = 'PONG_BUILTIN_OK the built-in engine answered.'@@ -203,6 +222,39 @@ export function tauriMockInit(opts: TauriMockOptions) {return parts}+ /**+ * SSE frames for one scripted agent turn: prose deltas, then tool_call+ * deltas, then the finish frame. Emitting the tool call as DELTAS (id+name+ * first, arguments after) is deliberate — that is what a real backend does,+ * and it is the accumulator in openai-provider that the agent specs need to+ * exercise, not a pre-assembled call.+ */+ function agentTurnSse(turn: { text?: string; toolCalls?: Array<{ name: string; args: any }> }): 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`+ const parts = [frame({ role: 'assistant' }, null)]+ const text = turn.text || ''+ const size = Math.max(1, Math.ceil(text.length / 8))+ for (let i = 0; i < text.length; i += size) {+ parts.push(frame({ content: text.slice(i, i + size) }, null))+ }+ const calls = turn.toolCalls || []+ calls.forEach((c, idx) => {+ parts.push(frame({ tool_calls: [{ index: idx, id: `call_e2e_${idx}`, type: 'function', function: { name: c.name, arguments: '' } }] }, null))+ parts.push(frame({ tool_calls: [{ index: idx, function: { arguments: JSON.stringify(c.args ?? {}) } }] }, null))+ })+ parts.push(frame({}, calls.length ? 'tool_calls' : 'stop') + 'data: [DONE]\n\n')+ return parts+ }++ /** Which scripted turn the next model call gets. */+ let agentTurnIndex = 0+function router(cmd: string, args: any): Promise<any> {// The MLX wrappers (api/mlx-image.ts invokeMedia) nest their payload under// an `args` key to match the Rust `args: Value` signature — unwrap once so@@ -419,7 +471,10 @@ export function tauriMockInit(opts: TauriMockOptions) {// ── chat streaming: drive the onChunk Channel ─────────────────case 'proxy_localhost_stream_chunked': {const channel = args?.onChunk- const parts = chatSseParts(opts.assistantReply, opts.replyChunks ?? 1)+ const script = opts.agentTurns+ const parts = script && script.length+ ? agentTurnSse(script[Math.min(agentTurnIndex++, script.length - 1)])+ : chatSseParts(opts.assistantReply, opts.replyChunks ?? 1)const gap = opts.replyChunkDelayMs ?? 0// Deliver on a macrotask so the app's `settled` promise is already// being awaited, mirroring the async Rust→WebView channel delivery.@@ -501,6 +556,29 @@ export function tauriMockInit(opts: TauriMockOptions) {return Promise.resolve(null)}+ // ── agent file/shell tools ────────────────────────────────────+ // Enough of the bridge for the ReAct loop to actually complete a step.+ // Every call is recorded so a spec can assert WHAT the agent ran, which+ // is the only way to prove things like "the second npm test really+ // re-ran after the edit" (audit B1) from the outside.+ case 'fs_read': {+ record('__E2E_TOOL_CALLS__', { cmd, path: m?.path })+ const files = opts.files || {}+ const key = Object.keys(files).find((k) => String(m?.path || '').endsWith(k))+ return Promise.resolve({ content: key ? files[key] : '', encoding: 'utf8' })+ }+ case 'fs_write':+ record('__E2E_TOOL_CALLS__', { cmd, path: m?.path })+ return Promise.resolve({ ok: true, path: m?.path })+ case 'fs_list':+ record('__E2E_TOOL_CALLS__', { cmd, path: m?.path })+ return Promise.resolve({ entries: [] })+ case 'shell_execute':+ record('__E2E_TOOL_CALLS__', { cmd, command: m?.command, timeout: m?.timeout })+ return Promise.resolve({ stdout: 'e2e shell ok', stderr: '', exitCode: 0, timedOut: false })+ case 'repo_map':+ return Promise.resolve({ files: [], count: 0 })+default:// Record system-browser opens so specs can assert redirect targets// (pricing CTA, closed-beta link) without leaving the page.