testing · caliber-ai-org — Claude Code rule: what it does, how to install
Defines Vitest testing patterns for Caliber, enforcing colocated test suites, environment isolation, and global LLM mocks.
MIT ★ 1,319 updated 2026-09-24
.cursor/rules/testing.mdcWhat testing does
The rule targets test files matching src/**/__tests__/** across the project. It mandates colocating tests with the source code, such as placing src/llm/__tests__/config.test.ts next to src/llm/config.ts. The test suite uses vitest.config.ts alongside initialization logic in src/test/setup.ts.
Every suite follows a fixed pattern: describe blocks reset mocks via beforeEach(vi.clearAllMocks) before running assertions with expect. Built-in modules like fs and child_process must use vi.mock(), while type assertions rely on vi.mocked(). Any modified environment variables require saving in beforeEach and restoring inside afterEach.
Outbound calls to actual LLM providers are prohibited because src/test/setup.ts mocks model interactions globally.
What it helps with
- colocate Vitest test files alongside application code
- mock LLM provider responses globally in test setups
- isolate environment variable changes between test runs
- measure test coverage using the v8 provider
Example prompts for the agent
- Write a Vitest suite for
src/llm/config.tsfollowing our mock conventions - Run the single test file
src/scoring/__tests__/accuracy.test.ts - Mock
fsandchild_processcalls in this unit test
How to install testing
Manually: put the files in place
.cursor/rules/testing.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/testing.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/testing.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/testing.mdManually: put the files in place
.clinerules/testing.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about testing
How to install testing in Claude Code?
Add the rule file directly at .claude/rules/testing.md within your project repository.
What does the testing rule do?
It guides the agent to write Vitest suites using standard setups, clear mocks, colocated files, and v8 test coverage commands.
How does the rule handle LLM API calls?
All LLM calls are globally mocked in src/test/setup.ts. The rule forbids tests from contacting real model providers directly.
Source text
testing.mdc · MIT
--- description: Vitest testing patterns for Caliber globs: src/**/__tests__/** --- - Vitest config: `vitest.config.ts` · Setup: `src/test/setup.ts` - Run all: `npm run test` · Single: `npx vitest run src/scoring/__tests__/accuracy.test.ts` - Coverage: `npm run test:coverage` (v8 provider) - LLM calls globally mocked in `src/test/setup.ts` — never call real providers - Use `vi.mock()` for `fs`, `child_process` · `vi.mocked()` for type-safe assertions - Tests colocated: `src/llm/__tests__/config.test.ts` tests `src/llm/config.ts` - Pattern: `describe` → `beforeEach(vi.clearAllMocks)` → `it` with `expect` - Environment vars: save in `beforeEach`, restore in `afterEach`
© caliber-ai-org · MIT · caliber-ai-org/ai-setup
Similar IDE rules
All IDE rules for Testing and QA →testing by other authors comes first.