Skip to content

Commit d1f41d4

Browse files
authored
Merge pull request #105 from hydro13/docs/testing-strategy-architecture
docs: add Testing Strategy section to ARCHITECTURE.md
2 parents d868492 + b7c5d29 commit d1f41d4

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

ARCHITECTURE.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,87 @@ Shell communicates with main process through `contextBridge` (defined in
241241
- **API routes:** kebab-case paths (`/tabs/list`, `/workspace/move-tab`)
242242
- **MCP tools:** snake_case (`tandem_click`, `tandem_read_page`)
243243

244+
## Testing Strategy
245+
246+
### Framework and Configuration
247+
248+
Vitest with v8 coverage. Configuration in `vitest.config.ts`:
249+
250+
```
251+
include: src/**/tests/**/*.test.ts
252+
setup: src/api/tests/setup.ts (patches supertest for IPv4/IPv6)
253+
coverage: v8, reporters: text + html + json-summary
254+
```
255+
256+
Key commands:
257+
258+
| Command | Purpose |
259+
|---------|---------|
260+
| `npm test` | Run all tests once (`vitest run`) |
261+
| `npm run verify` | Compile + lint + test + consistency check |
262+
| `npx vitest run --coverage` | Tests with coverage report |
263+
264+
### Test Location Convention
265+
266+
Tests live alongside their domain in `src/<domain>/tests/<name>.test.ts`:
267+
268+
```
269+
src/
270+
├── bookmarks/
271+
│ ├── manager.ts
272+
│ └── tests/
273+
│ └── bookmarks.test.ts
274+
├── api/
275+
│ ├── routes/
276+
│ │ ├── tabs.ts
277+
│ │ └── content.ts
278+
│ └── tests/
279+
│ └── routes/
280+
│ ├── tabs.test.ts
281+
│ └── content.test.ts
282+
└── mcp/
283+
├── tools/
284+
│ ├── tabs.ts
285+
│ └── content.ts
286+
└── tests/
287+
├── tabs.test.ts
288+
└── content.test.ts
289+
```
290+
291+
API route tests mirror route filenames under `src/api/tests/routes/`.
292+
MCP tool tests mirror tool filenames under `src/mcp/tests/`.
293+
294+
### Test Categories
295+
296+
| Category | Location | Files | What they test |
297+
|----------|----------|-------|----------------|
298+
| Manager unit tests | `src/<domain>/tests/` | 22 | Core manager logic (bookmarks, history, config, tabs, etc.) |
299+
| API route tests | `src/api/tests/routes/` | 15 | HTTP endpoints via supertest, auth, error handling |
300+
| MCP tool tests | `src/mcp/tests/` | 31 | Tool registration, argument validation, manager delegation |
301+
| Security tests | `src/security/tests/` | 11 | Shield layers, threat detection, crypto, evolution engine |
302+
| Extension tests | `src/extensions/tests/` | 4 | Extension loading, action polyfill, native messaging, trust |
303+
| Utility tests | `src/utils/tests/` | 4 | Logger, constants, security helpers, general utils |
304+
305+
87 test files total.
306+
307+
### Writing New Tests
308+
309+
1. Create `src/<domain>/tests/<feature>.test.ts`
310+
2. Mock Electron — `vi.mock('electron')` (most managers need `BrowserWindow`)
311+
3. Mock the filesystem — `vi.mock('fs/promises')` for managers that persist to `~/.tandem/`
312+
4. Test the public API — the same methods that routes and MCP tools call
313+
5. Verify both success and error paths — use `handleRouteError` patterns for API tests
314+
315+
### CI Integration
316+
317+
| Workflow | Trigger | What it does |
318+
|----------|---------|--------------|
319+
| `verify.yml` | Every push and PR | `npm run verify` + coverage upload to Codecov |
320+
| `codeql.yml` | PRs to main + weekly (Monday 04:00 UTC) | CodeQL security analysis |
321+
322+
Both checks must pass before merge. Coverage is tracked via Codecov with a
323+
README badge.
324+
244325
## Key Design Constraints
245326

246327
1. **Local-first** — no data leaves the machine through Tandem

0 commit comments

Comments
 (0)