Major Changes: - Simplified OpenAgent execution philosophy (universal agent, delegate sparingly) - Reorganized context into 3-tier structure: standards/, workflows/, system/ - Improved approval gate wording for clarity - Enhanced .gitignore with comprehensive Node.js patterns - Added comprehensive plugin development guide Context Reorganization: - Consolidated scattered files into organized structure with Quick Reference sections - Emphasis on lazy loading for token efficiency (60-80% token savings) - New standards: code.md, docs.md, tests.md, patterns.md, analysis.md - New workflows: delegation.md, sessions.md, task-breakdown.md, review.md - New system: context-guide.md (master reference) Delegation Improvements: - Removed complex XML-style routing rules - Simplified to clear when/how structure with 7 delegation criteria - Added Perspective and Simulation as delegation triggers - Clearer delegation template and process Documentation Enhancements: - Added building-plugins.md (1,274 lines - comprehensive plugin guide) - Updated how-context-works.md with research-backed architecture - Enhanced slash-commands-and-subagents.md with path resolution findings Content Preservation: - context-discovery.md → system/context-guide.md + workflows/sessions.md - context-management.md → workflows/sessions.md - essential-patterns.md → standards/patterns.md - session-management.md → workflows/sessions.md
3 KiB
3 KiB
Testing Standards
Quick Reference
Golden Rule: If you can't test it easily, refactor it
AAA Pattern: Arrange → Act → Assert
Test (✅ DO):
- Happy path, edge cases, error cases
- Business logic, public APIs
Don't Test (❌ DON'T):
- Third-party libraries, framework internals
- Simple getters/setters, private details
Coverage: Critical (100%), High (90%+), Medium (80%+)
Principles
Test behavior, not implementation: Focus on what code does, not how Keep tests simple: One assertion per test, clear names, minimal setup Independent tests: No shared state, run in any order Fast and reliable: Quick execution, no flaky tests, deterministic
Test Structure (AAA Pattern)
test('calculateTotal returns sum of item prices', () => {
// Arrange - Set up test data
const items = [{ price: 10 }, { price: 20 }, { price: 30 }];
// Act - Execute code
const result = calculateTotal(items);
// Assert - Verify result
expect(result).toBe(60);
});
What to Test
✅ DO Test
- Happy path (normal usage)
- Edge cases (boundaries, empty, null, undefined)
- Error cases (invalid input, failures)
- Business logic (core functionality)
- Public APIs (exported functions)
❌ DON'T Test
- Third-party libraries
- Framework internals
- Simple getters/setters
- Private implementation details
Coverage Goals
- Critical: Business logic, data transformations (100%)
- High: Public APIs, user-facing features (90%+)
- Medium: Utilities, helpers (80%+)
- Low: Simple wrappers, configs (optional)
Testing Pure Functions
function add(a, b) { return a + b; }
test('add returns sum', () => {
expect(add(2, 3)).toBe(5);
expect(add(-1, 1)).toBe(0);
expect(add(0, 0)).toBe(0);
});
Testing with Dependencies
// Testable with dependency injection
function createUserService(database) {
return {
getUser: (id) => database.findById('users', id)
};
}
// Test with mock
test('getUser retrieves from database', () => {
const mockDb = {
findById: jest.fn().mockReturnValue({ id: 1, name: 'John' })
};
const service = createUserService(mockDb);
const user = service.getUser(1);
expect(mockDb.findById).toHaveBeenCalledWith('users', 1);
expect(user).toEqual({ id: 1, name: 'John' });
});
Test Naming
// ✅ Good: Descriptive, clear expectation
test('calculateDiscount returns 10% off for premium users', () => {});
test('validateEmail returns false for invalid format', () => {});
test('createUser throws error when email exists', () => {});
// ❌ Bad: Vague, unclear
test('it works', () => {});
test('test user', () => {});
Best Practices
✅ Test one thing per test ✅ Use descriptive test names ✅ Keep tests independent ✅ Mock external dependencies ✅ Test edge cases and errors ✅ Make tests readable ✅ Run tests frequently ✅ Fix failing tests immediately
Golden Rule: If you can't test it easily, refactor it.