Quick Reference for Test Organization and Writing
All Ralph CLI tests live in the /tests directory. This guide covers organization rules, file naming patterns, and test writing conventions.
Central location for all test files, maintaining separation between tests and production code.
Contents:
- Integration/E2E tests -
*.mjsfiles - Unit tests -
test-*.jsfiles - Test fixtures -
fixtures/subdirectory - Test helpers -
helpers/subdirectory - Mock implementations -
mocks/subdirectory
Purpose: Centralized testing ensures consistency and prevents test files from being scattered across the codebase.
- Place ALL test files in
/testsdirectory - Use
.mjsextension for integration and E2E tests - Use
test-*.jsnaming pattern for unit tests - Use subdirectories (
fixtures/,helpers/,mocks/) for supporting files - Keep test file names descriptive -
test-complexity.js,integration-metrics.mjs
- Never place test files in
/lib,/bin, or source directories - Don't mix test files with production code
- Don't use inconsistent naming conventions
- Don't create test files in project root
tests/
├── *.mjs # Integration and E2E tests
│ ├── cli-smoke.mjs # CLI smoke tests
│ ├── agent-loops.mjs # Agent loop behavior
│ ├── integration.mjs # Main integration suite
│ ├── e2e-workflow.mjs # End-to-end workflows
│ └── real-agents.mjs # Real agent execution
│
├── test-*.js # Unit tests
│ ├── test-analyzer.js # Code analyzer tests
│ ├── test-committer.js # Git committer tests
│ ├── test-complexity.js # Complexity analysis
│ ├── test-executor.js # Story executor tests
│ └── test-realistic-scenarios.js # Realistic workflows
│
├── fixtures/ # Test fixtures and sample data
├── helpers/ # Test utility functions
└── mocks/ # Mock implementations
# Smoke tests - fast validation
npm test
# Agent health check
npm run test:ping# All integration tests
npm run test:all
# Specific integration tests
npm run test:checkpoint # Checkpoint system
npm run test:switcher # Agent switching
npm run test:risk # Risk analysis
npm run test:actions # Actions workflow
npm run test:notify # Notifications
npm run test:metrics # Metrics collection
npm run test:doctor # Doctor diagnostics
npm run test:watch # File watching
npm run test:ui-api # UI API# Real agent execution (expensive, uses API credits)
npm run test:real
# End-to-end workflow tests
npm run test:e2eimport { describe, it } from 'node:test';
import assert from 'node:assert';
describe('Feature Name', () => {
it('should do something', async () => {
// Arrange
const input = setupTestData();
// Act
const result = await featureUnderTest(input);
// Assert
assert.strictEqual(result.status, 'success');
});
});const assert = require('assert');
const { describe, it } = require('node:test');
describe('Module Name', () => {
it('should handle edge case', () => {
// Arrange
const input = edgeCaseData();
// Act
const result = moduleUnderTest(input);
// Assert
assert.ok(result.isValid);
});
});import { readFileSync } from 'fs';
import { join } from 'path';
const fixture = readFileSync(
join(import.meta.dirname, 'fixtures/sample-prd.md'),
'utf-8'
);import { setupTestRepo, cleanupTestRepo } from './helpers/git-helpers.js';
describe('Git operations', () => {
beforeEach(() => setupTestRepo());
afterEach(() => cleanupTestRepo());
it('should commit changes', async () => {
// Test logic
});
});- Root Guide: /AGENTS.md - Core Ralph agent rules
- Full Testing Guide: TESTING.md - Comprehensive test documentation
- Package Structure: CLAUDE.md § Package Structure - Testing rules
Key Takeaways:
- All tests in
/testsdirectory - Never place tests in source directories - Use
.mjsfor integration - Integration/E2E tests - Use
test-*.jsfor unit tests - Unit test naming pattern - Organize with subdirectories - fixtures/, helpers/, mocks/
- Run
npm testfor smoke tests - Fast validation without agents - Run
npm run test:allfor integration - Full test suite with agents