This document covers the testing infrastructure, patterns, and conventions used in the oh-my-openagent codebase. It explains the test framework, file organization, CI execution strategy, and the use of isolation and mocking for complex system components.
The project utilizes Bun's built-in test runner (bun:test) for all unit and integration tests. The test suite is designed to run in a fast, concurrent environment while strictly checking TypeScript types.
| Aspect | Implementation |
|---|---|
| Framework | bun:test (native Bun test runner) packages/omo-opencode/src/shared/live-server-route.test.ts1 |
| Execution Engine | Bun (standardized via bun-types) test-setup.ts1 |
| Global Setup | test-setup.ts (preloaded via bunfig.toml) bunfig.toml1-2 |
| Loader Config | Treats .md files as text for prompt testing bunfig.toml5-6 |
The test-setup.ts file provides a consistent baseline for every test execution by managing global state and environmental snapshots.
ClaudeSessionState, TaskToastManager, ModelFallbackState, and LiveServerRoute before and after each test test-setup.ts68-73 test-setup.ts107-110process.env and the current working directory, restoring them after each test to prevent side effects test-setup.ts63-64 test-setup.ts79-96installModuleMockLifecycle to ensure all mock.module calls are cleared between runs unless explicitly preserved test-setup.ts41-44 test-setup.ts114-117Sources: test-setup.ts1-119 bunfig.toml1-7
The codebase employs a "mock-heavy" approach for high-level orchestration, particularly within the plugin initialization flow. This allows verification of complex logic without spawning real background processes.
The createPluginModule function is designed for testability by accepting a PluginModuleDeps object, allowing tests to override any internal function packages/omo-opencode/src/testing/create-plugin-module.ts105-106
The live-server-route.test.ts file demonstrates granular mocking of the fetch API and client objects to verify routing logic:
PROBE_ABORT_MS window packages/omo-opencode/src/shared/live-server-route.test.ts179-195 packages/omo-opencode/src/shared/live-server-route.ts10Natural Language to Code Entity Space: Live Route Resolution
Sources: packages/omo-opencode/src/shared/live-server-route.ts12-28 packages/omo-opencode/src/shared/live-server-route.ts85-129 packages/omo-opencode/src/shared/live-server-route.test.ts128-146
Integration tests for the Hashline edit system are located in tests/hashline/. These tests verify the core code manipulation logic using the Vercel AI SDK and various model providers.
The hashline tests are organized into specific suites via package.json scripts:
test:basic: Standard edit operations (insert, delete, replace) tests/hashline/package.json8test:edge: Complex scenarios like overlapping hashes or invalid line IDs tests/hashline/package.json9test:multi: Verifies that the hashline logic remains consistent across different model families (OpenAI, Anthropic, etc.) tests/hashline/package.json10These tests run in an isolated workspace with specific dependencies on @ai-sdk/openai-compatible and zod for schema validation of model outputs tests/hashline/package.json13-17
Sources: tests/hashline/package.json1-19 tests/hashline/bun.lock1-37
The codebase includes a suite of shell-based QA scripts in .agents/skills/opencode-qa/scripts/ that perform end-to-end smoke tests in isolated environments.
To ensure QA runs do not pollute the user's actual environment, the common.sh helper provides oqa_mk_isolated_xdg .agents/skills/opencode-qa/scripts/lib/common.sh75-93
XDG_DATA_HOME, XDG_CONFIG_HOME, and HOME to a temporary directory .agents/skills/opencode-qa/scripts/lib/common.sh85-88oqa_free_port to find available TCP ports for spawning test servers .agents/skills/opencode-qa/scripts/lib/common.sh96-105EXIT signal to trigger oqa_cleanup, which kills spawned servers, tmux sessions, and removes temporary directories .agents/skills/opencode-qa/scripts/lib/common.sh151-175Natural Language to Code Entity Space: QA Sandbox Lifecycle
Sources: .agents/skills/opencode-qa/scripts/lib/common.sh1-175
Refresh this wiki