Running Tests
All tests
bun testWith coverage
bun test --coverageWatch mode
bun test --watchSpecific package
bun test packages/corebun test packages/daemonbun test packages/cliSpecific file
bun test packages/daemon/src/services/policy-engine.test.tsTest Structure
Tests live alongside source files or in __tests__ directories. Bun’s built-in test runner is used (no Jest or Vitest).
import { describe, test, expect, beforeEach } from "bun:test";
describe("PolicyEngine", () => { let engine: PolicyEngine;
beforeEach(() => { engine = new PolicyEngine(); });
test("matches exact tool name", () => { const rule = { action: "allow", tool: "Read" }; expect(engine.evaluate("Read", {}, [rule])).toBe("allow"); });});Key Areas to Test
Policy engine
The policy engine (packages/daemon/src/services/policy-engine.ts) is the most critical component for testing. Cover:
- Exact tool name matching
- Glob pattern matching (wildcards, negation, arrays)
- Argument pattern matching
- Priority ordering across multiple policies
- Default action fallback
- Session-scoped vs global policies
Workflow executor
The workflow runner has complex state management. Test:
- Sequential step execution
- Parallel branch completion (all, any, none)
- Conditional branching
- Loop iteration with variable scoping
- Error recovery strategies (continue, fail, retry)
- Cancellation mid-execution
- Variable substitution across steps
Auth service
- Password hashing and verification (Argon2)
- TOTP generation and verification
- Session token creation and validation
- Rate limiting behavior
- Bootstrap password flow
Provider integration
- tmux session creation and cleanup
- Input forwarding (text and key sequences)
- Event emission and handling
- Billing mode environment scrubbing
Pre-commit
Always run the full quality check before submitting:
bun run pre-commitThis runs linting, type checking, and all tests.
What’s next
- Development Setup: Local environment setup
- Adding a Provider: Provider implementation guide