Onyx Integration Tests
This directory contains automated integration tests for the Onyx version control system.
Quick Start
Run the full integration test suite:
make integration
This will:
- Build the
onx
andonxd
binaries - Create an isolated test environment in
/tmp/onyx-repo-test-{TIMESTAMP}
- Run all integration tests
- Clean up automatically
- Report results with pass/fail status
What Gets Tested
The integration test (integration_test.sh
) validates all Milestone 2 functionality:
Test Coverage (24 assertions)
-
Repository Initialization (6 tests)
.git
directory created.onx
directory createdoplog
file existsworkstreams.json
created with correct structure.gitignore
created- Workstreams uses map structure (not array)
-
Daemon Management (3 tests)
- Daemon starts successfully
- PID file created
- Status command reports running state
-
Automatic Snapshots (4 tests)
- File changes detected
- Workspace state file updated
- Git ref created (
refs/onyx/workspaces/current
) - Snapshot commit created
-
Save Command (3 tests)
- First commit saved successfully
- Workstreams.json updated
- Branch ref created (
refs/onyx/workstreams/{name}/commit-1
)
-
Commit Chains (3 tests)
- Second commit saves successfully
- Parent-child relationship established
- Sequential branch refs created
-
Undo Command (3 tests)
- Undo operation executes
- Oplog contains undo entry
- state_before is non-null (validates the fix!)
-
Daemon Cleanup (2 tests)
- Daemon stops gracefully
- PID file removed
- Status reports not running
Test Environment
- Location:
/tmp/onyx-repo-test-{UNIX_TIMESTAMP}
- Isolation: Each test run creates a fresh directory
- Cleanup: Automatic cleanup on completion or interruption
- Binaries: Uses
bin/onx
andbin/onxd
from project root
Test Output
The script provides color-coded output:
- 🔵 Blue - Informational messages
- 🟢 Green - Tests that passed
- 🔴 Red - Tests that failed
- 🟡 Yellow - Section headers
Example output:
=====================================
Test 1: Repository Initialization
=====================================
[INFO] Initializing Onyx repository...
[PASS] Directory exists: .git
[PASS] Directory exists: .onx
...
Total Tests: 24
Passed: 24
Failed: 0
========================================
ALL TESTS PASSED! ✓
========================================
Manual Execution
You can run the test script directly:
./test/integration_test.sh
The script will:
- Check for required binaries
- Create test environment
- Run all test suites
- Report detailed results
- Clean up on exit (even if interrupted with Ctrl+C)
CI/CD Integration
The integration test is designed for automated testing:
- Exit Code: Returns 0 on success, 1 on failure
- Isolated: No dependencies on external state
- Deterministic: Should produce same results on each run
- Fast: Completes in ~10 seconds
Example CI usage:
# GitHub Actions
- name: Run Integration Tests
run: make integration
Debugging Failed Tests
If tests fail:
- Check the test output - Shows which specific assertion failed
- Review the test directory - Check
/tmp/onyx-repo-test-*
if cleanup failed - Run manually - Execute
./test/integration_test.sh
for more control - Check logs - Look for daemon errors in test output
Common issues:
- Daemon not stopping: Check for stale processes with
ps aux | grep onxd
- Permission errors: Ensure
/tmp
is writable - Binary not found: Run
make build
first
Test Architecture
The test script uses:
- Assertions: Helper functions for validation
- Counters: Track pass/fail statistics
- Cleanup Trap: Ensures cleanup even on script interruption
- Color Output: Makes results easy to read
Key functions:
assert_file_exists()
- Verify file creationassert_file_contains()
- Validate file contentassert_ref_exists()
- Check Git referencesassert_command_success()
- Verify command execution
Extending Tests
To add new tests:
- Add a new test section in
integration_test.sh
- Use assertion functions for validation
- Increment test counters appropriately
- Update this README with new coverage
Example:
log_section "Test X: New Feature"
log_info "Testing new feature..."
"$ONX_BIN" new-command
assert_file_exists "expected_file"
Requirements
- Go 1.24.2+
- Bash shell
- Write access to
/tmp
make
utility
Related Documentation
- INTEGRATION.md - Manual integration testing guide
- CLAUDE.md - Project overview for Claude Code
- notes/checklist.md - Implementation milestones