--- name: test description: Use for writing tests, setting up test infrastructure (vitest), or debugging test failures. Examples: "add unit tests for ImapProvider", "set up vitest for the renderer", "write tests for message threading", "test the polling dedup logic". tools: [Bash, Read, Edit, Write] --- # Aero Mail — Test Agent You are responsible for writing and maintaining tests for **Aero Mail**. ## Current state **No test suite exists yet.** The project has `typecheck` scripts but no test runner. Your first task when asked to add tests is to set up **Vitest**. ## Recommended setup ### Main process tests (Node.js) ```bash npm install -D vitest @vitest/coverage-v8 ``` `vitest.config.ts` for main process: ```ts import { defineConfig } from 'vitest/config' export default defineConfig({ test: { environment: 'node', include: ['src/main/**/*.test.ts', 'src/shared/**/*.test.ts'], }, }) ``` ### Renderer tests (JSDOM / happy-dom) ```bash npm install -D @vitest/ui happy-dom @vue/test-utils ``` Vitest config for renderer: ```ts test: { environment: 'happy-dom', include: ['src/renderer/**/*.test.ts'], } ``` ## Priority test targets ### 1. `ImapProvider` polling dedup (`src/main/providers/imap.provider.ts`) The most complex logic — high value, easily regresses. ```ts // Test: notifiedUids TTL prevents duplicate notifications // Test: lastUnseenCount update before lock prevents race // Test: pollFolderTree calls newMailCallback only for new UIDs ``` Mock `imapflow` with `vi.mock('imapflow')`. ### 2. Message threading (`src/renderer/src/utils/threading.ts`) Pure function — easiest to test, no mocks needed. ```ts // Test: threads group by In-Reply-To / References header // Test: single message is its own thread // Test: circular references don't infinite loop ``` ### 3. Body cache LRU (`src/renderer/src/stores/messages.store.ts`) `getCachedBody` / `setCachedBody` are module-level closures — extract to test file or test via store. ```ts // Test: evicts oldest when size >= BODY_CACHE_MAX (100) // Test: TTL expires after 3 hours // Test: access promotes entry to end (LRU order) ``` ### 4. HTML sanitizer (`src/main/lib/html-sanitizer.ts`) ```ts // Test: strips