187 lines
4.8 KiB
Markdown
187 lines
4.8 KiB
Markdown
# Onyx Integration Tests
|
|
|
|
This directory contains automated integration tests for the Onyx version control system.
|
|
|
|
## Quick Start
|
|
|
|
Run the full integration test suite:
|
|
|
|
```bash
|
|
make integration
|
|
```
|
|
|
|
This will:
|
|
1. Build the `onx` and `onxd` binaries
|
|
2. Create an isolated test environment in `/tmp/onyx-repo-test-{TIMESTAMP}`
|
|
3. Run all integration tests
|
|
4. Clean up automatically
|
|
5. Report results with pass/fail status
|
|
|
|
## What Gets Tested
|
|
|
|
The integration test (`integration_test.sh`) validates all Milestone 2 functionality:
|
|
|
|
### Test Coverage (24 assertions)
|
|
|
|
1. **Repository Initialization** (6 tests)
|
|
- `.git` directory created
|
|
- `.onx` directory created
|
|
- `oplog` file exists
|
|
- `workstreams.json` created with correct structure
|
|
- `.gitignore` created
|
|
- Workstreams uses map structure (not array)
|
|
|
|
2. **Daemon Management** (3 tests)
|
|
- Daemon starts successfully
|
|
- PID file created
|
|
- Status command reports running state
|
|
|
|
3. **Automatic Snapshots** (4 tests)
|
|
- File changes detected
|
|
- Workspace state file updated
|
|
- Git ref created (`refs/onyx/workspaces/current`)
|
|
- Snapshot commit created
|
|
|
|
4. **Save Command** (3 tests)
|
|
- First commit saved successfully
|
|
- Workstreams.json updated
|
|
- Branch ref created (`refs/onyx/workstreams/{name}/commit-1`)
|
|
|
|
5. **Commit Chains** (3 tests)
|
|
- Second commit saves successfully
|
|
- Parent-child relationship established
|
|
- Sequential branch refs created
|
|
|
|
6. **Undo Command** (3 tests)
|
|
- Undo operation executes
|
|
- Oplog contains undo entry
|
|
- **state_before is non-null** (validates the fix!)
|
|
|
|
7. **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` and `bin/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:
|
|
|
|
```bash
|
|
./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:
|
|
```yaml
|
|
# GitHub Actions
|
|
- name: Run Integration Tests
|
|
run: make integration
|
|
```
|
|
|
|
## Debugging Failed Tests
|
|
|
|
If tests fail:
|
|
|
|
1. **Check the test output** - Shows which specific assertion failed
|
|
2. **Review the test directory** - Check `/tmp/onyx-repo-test-*` if cleanup failed
|
|
3. **Run manually** - Execute `./test/integration_test.sh` for more control
|
|
4. **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 creation
|
|
- `assert_file_contains()` - Validate file content
|
|
- `assert_ref_exists()` - Check Git references
|
|
- `assert_command_success()` - Verify command execution
|
|
|
|
## Extending Tests
|
|
|
|
To add new tests:
|
|
|
|
1. Add a new test section in `integration_test.sh`
|
|
2. Use assertion functions for validation
|
|
3. Increment test counters appropriately
|
|
4. Update this README with new coverage
|
|
|
|
Example:
|
|
```bash
|
|
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](../INTEGRATION.md) - Manual integration testing guide
|
|
- [CLAUDE.md](../CLAUDE.md) - Project overview for Claude Code
|
|
- [notes/checklist.md](../notes/checklist.md) - Implementation milestones
|