|
| 1 | +# Cursor SDK Test Generator |
| 2 | + |
| 3 | +A local Cursor SDK example that points an agent at source files, generates unit tests, runs them, and feeds failures back into the agent until the tests pass or the iteration limit is reached. |
| 4 | + |
| 5 | +This example demonstrates: |
| 6 | + |
| 7 | +- TypeScript/JavaScript test generation for Vitest or Jest projects, |
| 8 | +- Python test generation for Pytest projects, |
| 9 | +- deterministic test execution outside the agent loop, |
| 10 | +- an Ink TUI with file selection, live progress, model selection, cancellation, and diff review. |
| 11 | + |
| 12 | +## Getting Started |
| 13 | + |
| 14 | +Use Node.js 22 or newer. |
| 15 | + |
| 16 | +Install dependencies: |
| 17 | + |
| 18 | +```bash |
| 19 | +pnpm install |
| 20 | +``` |
| 21 | + |
| 22 | +Set a Cursor API key: |
| 23 | + |
| 24 | +```bash |
| 25 | +export CURSOR_API_KEY="crsr_..." |
| 26 | +``` |
| 27 | + |
| 28 | +Generate tests for a TypeScript file and auto-accept the result: |
| 29 | + |
| 30 | +```bash |
| 31 | +pnpm dev -- examples/sample.ts --yes |
| 32 | +``` |
| 33 | + |
| 34 | +Generate tests for a Python file: |
| 35 | + |
| 36 | +```bash |
| 37 | +pnpm dev -- examples/sample.py --lang python --yes |
| 38 | +``` |
| 39 | + |
| 40 | +Start the interactive TUI by omitting files: |
| 41 | + |
| 42 | +```bash |
| 43 | +pnpm dev |
| 44 | +``` |
| 45 | + |
| 46 | +## CLI Options |
| 47 | + |
| 48 | +```bash |
| 49 | +test-gen [files...|globs...] [options] |
| 50 | + |
| 51 | + -C, --cwd <path> Workspace root. Defaults to cwd. |
| 52 | + --lang <ts|js|python> Override language detection. |
| 53 | + --framework <name> Override framework detection: vitest, jest, pytest. |
| 54 | + --max-iters <n> Test repair iterations. Defaults to 3. |
| 55 | + --allow-source-edits Let the agent fix source bugs during repair. |
| 56 | + --overwrite Overwrite existing test files. |
| 57 | + -y, --yes Auto-accept generated test files. |
| 58 | + -m, --model <id> Model id. Defaults to CURSOR_MODEL or composer-2. |
| 59 | +``` |
| 60 | + |
| 61 | +## Notes |
| 62 | + |
| 63 | +The agent writes or repairs tests, but this app runs the tests itself with the detected framework. That keeps the pass/fail signal deterministic and makes it easy to stream test output into the TUI. |
| 64 | + |
| 65 | +If your package manager ignores native dependency build scripts and the SDK reports a missing `sqlite3` binding, approve or rebuild the native dependency before running the agent loop. |
| 66 | + |
| 67 | +Cloud execution, coverage-guided test generation, mutation testing, and languages beyond TypeScript/JavaScript/Python are intentionally out of scope for this example. |
0 commit comments