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
fix(code): Tests fuer das Entfernen des Arbeitsverzeichnisses (A8)
purple8e4030c9a289
diff --git a/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts b/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.tsnew file mode 100644index 00000000..f7405435--- /dev/null+++ b/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts@@ -0,0 +1,112 @@+/**+ * @vitest-environment jsdom+ *+ * A8 (2.6.8), the second surface: the Coding Agent header.+ *+ * The Remove control in the explorer column is the main one, but that column+ * collapses and remembers that it was collapsed (uiStore). A user sitting in+ * front of a collapsed column sees a folder in the header and no way to let it+ * go, which is exactly the report we got: two people searched, a moderator said+ * "There isn't one". So the header, which always shows the folder, also carries+ * the way to give it back.+ *+ * CodexView is mounted for real here. Everything that talks to a model, a+ * bridge or a microphone is mocked away, because none of it is what this file+ * is about.+ *+ * Run: npx vitest run src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import { createElement } from 'react'+import { render, screen, fireEvent, cleanup, act } from '@testing-library/react'++vi.mock('../../../hooks/useCodex', () => ({+ useCodex: () => ({ sendInstruction: () => {}, stopCodex: () => {}, isRunning: false }),+}))+vi.mock('../../../api/backend', () => ({+ checkGitInstalled: async () => ({ installed: true, download_url: '' }),+ openExternal: () => {},+ backendCall: async () => ({ entries: [], truncated: false }),+ isTauri: () => false,+ isMacOS: () => false,+}))+vi.mock('../ChatInput', () => ({ ChatInput: () => null }))+vi.mock('../ExplorerPanel', () => ({ ExplorerPanel: () => null }))+vi.mock('../../models/ModelSelector', () => ({ ModelSelector: () => null }))+vi.mock('../TokenCounter', () => ({ TokenCounter: () => null }))+vi.mock('../ContextDropdown', () => ({ ContextDropdown: () => null }))+vi.mock('../PluginsDropdown', () => ({ PluginsDropdown: () => null }))+vi.mock('../SmallModelModeToggle', () => ({ SmallModelModeToggle: () => null }))+vi.mock('../StagedChangesPanel', () => ({ StagedChangesPanel: () => null }))+vi.mock('../CodexConfirmDialog', () => ({ CodexConfirmDialog: () => null }))++const { CodexView } = await import('../CodexView')+const { useCodexStore } = await import('../../../stores/codexStore')+const { useGenerationStore } = await import('../../../stores/generationStore')+const { useChatStore } = await import('../../../stores/chatStore')++const WINDOWS_PATH = 'C:\\Users\\dielitakira\\Documents\\huge-tree'++const show = () => render(createElement(CodexView))+const removeButton = () => screen.queryByTestId('codex-remove-folder')++beforeEach(() => {+ useCodexStore.setState({ workingDirectory: '', threads: {} })+ useGenerationStore.setState({ generating: {} })+ useChatStore.setState({ conversations: [], activeConversationId: null })+})+afterEach(() => cleanup())++describe('the header shows the folder, so it also gives it back', () => {+ it('carries a Remove control while a folder is set', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ expect(removeButton()).not.toBeNull()+ })++ it('carries none while the agent is in its sandbox', () => {+ show()+ // Negative control: bound to the folder, not always painted.+ expect(removeButton()).toBeNull()+ })++ it('a click empties the store and the header falls back to the sandbox label', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ const { container } = show()+ expect(container.textContent).toContain(WINDOWS_PATH)++ fireEvent.click(removeButton()!)+ expect(useCodexStore.getState().workingDirectory).toBe('')+ expect(container.textContent).not.toContain(WINDOWS_PATH)+ expect(container.textContent).toContain('sandbox')+ })++ it('the empty transcript then says how to pick a new folder', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ expect(screen.queryByTestId('codex-no-folder-hint')).toBeNull()++ fireEvent.click(removeButton()!)+ const hint = screen.getByTestId('codex-no-folder-hint')+ expect(hint.textContent).toContain('Select folder...')+ expect(hint.textContent).toContain('agent-workspace')+ })++ it('is locked with a reason while a coding turn is in flight', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ useGenerationStore.setState({ generating: { 'conv-1': true } })+ show()+ const button = removeButton() as HTMLButtonElement+ expect(button.disabled).toBe(true)+ expect(button.getAttribute('title')).toContain('Wait for the current run to finish')++ fireEvent.click(button)+ expect(useCodexStore.getState().workingDirectory).toBe(WINDOWS_PATH)+ })++ it('and unlocked again once nothing is running', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ expect((removeButton() as HTMLButtonElement).disabled).toBe(false)+ })+})diff --git a/src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts b/src/components/chat/__tests__/the-working-directory-can-be-removed.test.tsnew file mode 100644index 00000000..d78fcea8--- /dev/null+++ b/src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts@@ -0,0 +1,165 @@+/**+ * @vitest-environment jsdom+ *+ * A8 (2.6.8), the surface half: there has to be a visible way out of a folder.+ *+ * Two Windows 11 users in Cloud mode looked for one on 01. and 02.09. and found+ * nothing, a moderator confirmed "There isn't one", and one of them was ready+ * to reinstall the app to get rid of a tree he had opened by mistake. The store+ * half is pinned in src/stores/__tests__/codexStore-working-directory.test.ts;+ * this file mounts the explorer column for real and checks the four things the+ * reports were actually about:+ *+ * - the control EXISTS and is visible whenever a folder is set,+ * - it does not depend on Cloud versus Local, because that is where both+ * reporters were standing,+ * - clicking it empties the store, so the picker and the run agree,+ * - what is left behind says how to pick a new folder instead of going quiet.+ *+ * Plus the one thing a Remove button must not do: fire in the middle of a run.+ * The folder is global, so it would move the ground under every open chat.+ *+ * Run: npx vitest run src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import { createElement } from 'react'+import { render, screen, fireEvent, cleanup, act } from '@testing-library/react'++// The tree calls the Tauri bridge on mount. There is no bridge here and the+// listing is not what this file is about: one empty directory, always.+vi.mock('../../../api/backend', () => ({+ backendCall: vi.fn(async () => ({ entries: [], truncated: false })),+ isTauri: () => false,+ isMacOS: () => false,+}))+// The plan pieces at the bottom of the column pull in half the agent stack and+// have their own tests.+vi.mock('../PlanBar', () => ({ PlanBar: () => null }))+vi.mock('../PlanApprovalBar', () => ({ PlanApprovalBar: () => null }))+vi.mock('../FilePreview', () => ({ FilePreview: () => null }))++const { ExplorerPanel } = await import('../ExplorerPanel')+const { useCodexStore } = await import('../../../stores/codexStore')+const { useGenerationStore } = await import('../../../stores/generationStore')+const { useUIStore } = await import('../../../stores/uiStore')+const { useModelStore } = await import('../../../stores/modelStore')++const WINDOWS_PATH = 'C:\\Users\\helpslowlydying\\Documents\\My Projects'++const show = () => render(createElement(ExplorerPanel, { onApprovePlan: () => {} }))+const removeButton = () => screen.queryByTestId('explorer-remove-folder')++beforeEach(() => {+ useCodexStore.setState({ workingDirectory: '', threads: {} })+ useGenerationStore.setState({ generating: {} })+ useUIStore.setState({ explorerCollapsed: false })+ useModelStore.setState({ activeModel: null })+})+afterEach(() => cleanup())++describe('the way out of a folder is on screen', () => {+ it('shows a Remove control once a folder is set', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ expect(removeButton()).not.toBeNull()+ })++ it('shows nothing to remove while there is no folder', () => {+ show()+ // Negative control: the control is bound to the folder, not always painted.+ expect(removeButton()).toBeNull()+ })++ it('is there in Cloud mode', () => {+ useModelStore.setState({ activeModel: 'lu-cloud::zai-org/GLM-5.3-Flash' })+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ expect(removeButton()).not.toBeNull()+ })++ it('and in Local mode, the column never asked which one it was', () => {+ useModelStore.setState({ activeModel: 'ollama::qwen3:14b' })+ act(() => useCodexStore.getState().setWorkingDirectory('/home/dave/repo'))+ show()+ expect(removeButton()).not.toBeNull()+ })+})++describe('clicking it actually lets go', () => {+ it('empties the store, Windows path and all', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ fireEvent.click(removeButton()!)+ expect(useCodexStore.getState().workingDirectory).toBe('')+ })++ it('unpins the open thread, so the run stops walking the old tree', () => {+ act(() => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)+ })+ show()+ fireEvent.click(removeButton()!)+ expect(useCodexStore.getState().getThread('conv-1')!.workingDirectory).toBe('')+ })++ it('leaves an empty state that says how to pick a new folder', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ show()+ // Negative control: the hint is not sitting there the whole time.+ expect(screen.queryByTestId('explorer-no-folder')).toBeNull()++ fireEvent.click(removeButton()!)+ const empty = screen.getByTestId('explorer-no-folder')+ expect(empty.textContent).toContain('Select folder...')+ expect(empty.textContent).toContain('agent-workspace')+ })++ it('the path itself is gone from the column, not just from the store', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ const { container } = show()+ expect(container.textContent).toContain(WINDOWS_PATH)++ fireEvent.click(removeButton()!)+ expect(container.textContent).not.toContain(WINDOWS_PATH)+ })+})++describe('a run in flight holds it', () => {+ it('locks the control and says why, instead of hiding it', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ useGenerationStore.setState({ generating: { 'conv-1': true } })+ show()+ const button = removeButton()!+ expect(button).not.toBeNull()+ expect((button as HTMLButtonElement).disabled).toBe(true)+ expect(button.getAttribute('title')).toContain('Wait for the current run to finish')+ })++ it('a locked click changes nothing', () => {+ act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))+ useGenerationStore.setState({ generating: { 'conv-1': true } })+ show()+ fireEvent.click(removeButton()!)+ expect(useCodexStore.getState().workingDirectory).toBe(WINDOWS_PATH)+ })++ it('a thread the store still calls running counts as a run too', () => {+ act(() => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)+ useCodexStore.getState().setThreadStatus('conv-1', 'running')+ })+ show()+ expect((removeButton() as HTMLButtonElement).disabled).toBe(true)+ })++ it('and an idle thread does not, the lock is about runs and nothing else', () => {+ act(() => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)+ })+ show()+ expect((removeButton() as HTMLButtonElement).disabled).toBe(false)+ })+})diff --git a/src/stores/__tests__/codexStore-working-directory.test.ts b/src/stores/__tests__/codexStore-working-directory.test.tsnew file mode 100644index 00000000..2b2efbc5--- /dev/null+++ b/src/stores/__tests__/codexStore-working-directory.test.ts@@ -0,0 +1,168 @@+/**+ * A8 (2.6.8): giving the working directory back.+ *+ * Two users on Windows 11 in Cloud mode reported the same thing within a day of+ * each other: a folder opened by mistake could not be closed again. One of them+ * had attached the agent to a huge tree and was ready to reinstall the app over+ * it, the other sat in front of "I'm sorry, but I'm unable to proceed without a+ * working directory". A moderator confirmed the state of things with three+ * words: "There isn't one."+ *+ * There were two halves to it, and this file pins both:+ *+ * 1. the store had no way to clear `workingDirectory`, and the value is+ * persisted, so a restart brought the folder straight back,+ * 2. `initThread` copies the folder into the thread ONCE and the run resolver+ * prefers the thread over the store, so even a cleared store left the+ * running conversation attached to the old tree. The same drift made a+ * mis-click permanent: picking a second folder did not move the agent.+ *+ * Windows paths are checked verbatim on purpose. Both reporters are on Windows,+ * and this store must never touch a backslash or a drive letter.+ *+ * Run: npx vitest run src/stores/__tests__/codexStore-working-directory.test.ts+ */+import { describe, it, expect, beforeEach } from 'vitest'++// zustand/persist reads window.localStorage; the vitest env is 'node'. Assigned+// before the store import below, which is why that import is not hoisted.+const backing = new Map<string, string>()+;(globalThis as unknown as { window: unknown }).window = globalThis+globalThis.localStorage = {+ getItem: (k: string) => backing.get(k) ?? null,+ setItem: (k: string, v: string) => void backing.set(k, String(v)),+ removeItem: (k: string) => void backing.delete(k),+ clear: () => backing.clear(),+ key: (i: number) => [...backing.keys()][i] ?? null,+ get length() { return backing.size },+} as Storage++const { useCodexStore } = await import('../codexStore')++const KEY = 'locally-uncensored-codex'+const persisted = () => JSON.parse(localStorage.getItem(KEY) ?? '{}')++/** What the reporters actually typed at: a drive letter, backslashes, a space. */+const WINDOWS_PATH = 'C:\\Users\\helpslowlydying\\Documents\\My Projects'++beforeEach(() => {+ localStorage.clear()+ useCodexStore.setState({ workingDirectory: '', threads: {} })+})++describe('the folder can be given back', () => {+ it('clears the store', () => {+ useCodexStore.getState().setWorkingDirectory('/home/dave/repo')+ // Negative control: without this the next assertion passes on a store that+ // never held a folder in the first place.+ expect(useCodexStore.getState().workingDirectory).toBe('/home/dave/repo')++ useCodexStore.getState().clearWorkingDirectory()+ expect(useCodexStore.getState().workingDirectory).toBe('')+ })++ it('writes the empty string to disk, so a restart does not resurrect the folder', () => {+ useCodexStore.getState().setWorkingDirectory('/home/dave/repo')+ expect(persisted().state.workingDirectory).toBe('/home/dave/repo')++ useCodexStore.getState().clearWorkingDirectory()+ expect(persisted().state.workingDirectory).toBe('')+ // The key must still BE there. Deleting it would let an older persisted+ // value win on the next rehydrate, which is the bug all over again.+ expect(Object.keys(persisted().state)).toContain('workingDirectory')+ })++ it('unpins the open thread, which is where the folder actually reaches the run', () => {+ useCodexStore.getState().setWorkingDirectory('/home/dave/repo')+ useCodexStore.getState().initThread('conv-1', '/home/dave/repo')+ // Negative control: the thread really did carry the folder before.+ expect(useCodexStore.getState().getThread('conv-1')!.workingDirectory).toBe('/home/dave/repo')++ useCodexStore.getState().clearWorkingDirectory()+ expect(useCodexStore.getState().getThread('conv-1')!.workingDirectory).toBe('')+ })++ it('unpins every open thread, not just the one in front', () => {+ useCodexStore.getState().setWorkingDirectory('/repo')+ useCodexStore.getState().initThread('conv-1', '/repo')+ useCodexStore.getState().initThread('conv-2', '/repo')++ useCodexStore.getState().clearWorkingDirectory()+ const threads = useCodexStore.getState().threads+ expect(Object.values(threads).map((t) => t.workingDirectory)).toEqual(['', ''])+ })++ it('leaves the rest of the thread alone: events, status and id survive', () => {+ const id = useCodexStore.getState().initThread('conv-1', '/repo')+ useCodexStore.getState().addEvent('conv-1', {+ id: 'e1', type: 'instruction', content: 'do the thing', timestamp: 1,+ })+ useCodexStore.getState().setThreadStatus('conv-1', 'error')++ useCodexStore.getState().clearWorkingDirectory()+ const thread = useCodexStore.getState().getThread('conv-1')!+ expect(thread.id).toBe(id)+ expect(thread.events).toHaveLength(1)+ expect(thread.status).toBe('error')+ })+})++describe('a mis-click is not permanent either', () => {+ it('picking a second folder moves the open thread with it', () => {+ useCodexStore.getState().setWorkingDirectory('/wrong/huge/tree')+ useCodexStore.getState().initThread('conv-1', '/wrong/huge/tree')++ useCodexStore.getState().setWorkingDirectory('/right/repo')+ expect(useCodexStore.getState().getThread('conv-1')!.workingDirectory).toBe('/right/repo')+ })++ it('a set that changes nothing keeps the same threads object, so nobody re-renders', () => {+ useCodexStore.getState().setWorkingDirectory('/repo')+ useCodexStore.getState().initThread('conv-1', '/repo')+ const before = useCodexStore.getState().threads++ useCodexStore.getState().setWorkingDirectory('/repo')+ expect(useCodexStore.getState().threads).toBe(before)+ })+})++describe('Windows paths are carried through byte for byte', () => {+ it('stores the drive letter and the backslashes unchanged', () => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ const stored = useCodexStore.getState().workingDirectory+ expect(stored).toBe(WINDOWS_PATH)+ // Negative control against a well-meaning normalizer: no forward slashes,+ // no trailing-separator trim, no lowercasing of the drive letter.+ expect(stored).not.toContain('/')+ expect(stored.startsWith('C:\\')).toBe(true)+ })++ it('survives the round trip through localStorage unchanged', () => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ expect(persisted().state.workingDirectory).toBe(WINDOWS_PATH)+ })++ it('pins and unpins a Windows path on the thread', () => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)+ expect(useCodexStore.getState().getThread('conv-1')!.workingDirectory).toBe(WINDOWS_PATH)++ useCodexStore.getState().clearWorkingDirectory()+ expect(useCodexStore.getState().getThread('conv-1')!.workingDirectory).toBe('')+ })+})++describe('R1 DOWNGRADE-KONTRAKT still holds', () => {+ it('removing the folder adds no new persisted key and no version bump', () => {+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)+ useCodexStore.getState().chooseCodexMode('x', 'plan', false)+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)+ useCodexStore.getState().clearWorkingDirectory()++ const raw = persisted()+ expect(Object.keys(raw.state).sort()).toEqual(['modeByConversation', 'workingDirectory'])+ expect(raw.version ?? 0).toBe(0)+ // Negative control: the threads that were just unpinned stay off the disk.+ expect(raw.state.threads).toBeUndefined()+ })+})