Skip to main content
rule CX Codex

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

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/testing.mdc
Open on GitHub

What 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.ts following our mock conventions
  • Run the single test file src/scoring/__tests__/accuracy.test.ts
  • Mock fs and child_process calls in this unit test

How to install testing

Manually: put the files in place

.cursor/rules/testing.mdc

Frontmatter: description, globs, alwaysApply

Step 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.

testing jarrodwatts The testing rule sets conventions for TypeScript test files and the __tests__ directory. Use it to guide checks for success cases, failures, and edge conditions. CX Codex +1 ★ 1,064repo stars testing sangrokjung testing enforces a strict TDD workflow in Claude Code with an 80% coverage floor, Playwright E2E suites, and three test tiers. CX Codex +1 ★ 880repo stars testing justxor testing sets automated test standards for Claude Code: Arrange-Act-Assert structure, banned sleep calls, and strict boundaries for mocks. CX Codex +1 ★ 353repo stars testing Aaronontheweb Defines xUnit testing conventions for .NET: project configurations, test isolation, coverage thresholds, and integration test setup. CX Codex +1 ★ 138repo stars vitest-testing secondsky vitest-testing — a skill for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode that loads Vitest knowledge into the agent for unit and integration testing in TypeScript and JavaScript projects. CX Codex +1 1,300installs safe-action-testing next-safe-action safe-action-testing tells the agent how to write Vitest tests for next-safe-action actions and hooks: validation, middleware, server errors. CX Codex +1 1,200installs testing-best-practices agent-skills testing-best-practices — a rule set for unit and integration tests and TDD: 34 rules in 7 categories, TypeScript with Jest and Vitest. Useful while writing tests or reviewing someone else's. CX Codex +1 975installs encore-testing encoredev encore-testing guides your agent through writing and running automated tests for Encore.ts with encore test and vitest or jest. Useful when an endpoint or service needs coverage without hand-rolling test databases. CX Codex +1 846installs vitest-testing-patterns curiositech vitest-testing-patterns provides Vitest and React Testing Library conventions for coding agents. Useful for writing component tests, API route checks, and dependency mocks. CX Codex +1 373installs storybook-testing OrchestKit The storybook-testing Claude Code skill guides component testing in Storybook 10. It covers story authoring, visual checks, CI setup, and migration from Storybook 9. CX Codex +1 224installs

From the same set17

The whole set →
caliber-onboarding caliber-onboarding — a rule for Claude Code and Codex that checks whether Caliber configs are synced before the agent responds to your first message. If sync is not set up, it offers to run /setup-caliber in about 30 seconds. CX Codex +1 ★ 1,319repo stars llm-layer llm-layer pins the conventions for model-provider code: the LLMProvider interface, config lookup, seat-based handling and usage tracking. Scoped to src/llm/**. CX Codex +1 ★ 1,319repo stars caliber-conventions The caliber-conventions rule sets conventions for Caliber TypeScript CLI development. Use it to guide an agent working on project code, tests, and commits. CX Codex +1 ★ 1,319repo stars testing-patterns testing-patterns is a Claude Code rule for Vitest conventions: test locations, LLM mocks, and running a single spec. CX Codex +1 ★ 1,319repo stars scoring-patterns scoring-patterns defines coding rules for the src/scoring/** directory. It keeps scoring checks deterministic without external network calls or random values. CX Codex +1 ★ 1,319repo stars llm-patterns The llm-patterns rule sets patterns for LLM providers in a project. Use it when provider interfaces, model settings, CLI errors, or streamed responses need consistent handling. CX Codex +1 ★ 1,319repo stars caliber-pre-commit caliber-pre-commit — a commit-time rule: it checks for the Caliber git hook and, when the hook is absent, syncs and stages your agent config files. CX Codex +1 ★ 1,319repo stars find-skills find-skills discovers community skills from the Caliber registry and installs them directly into your coding session. CX Codex +1 ★ 1,319repo stars

Project sponsors

Companies that keep this analytics open