| .. | ||
| dummy-repo | ||
| core-functionality-test.js | ||
| README.md | ||
| repo-to-container-sync-test.js | ||
| run-tests.sh | ||
| simple-deletion-test.js | ||
| sync-test-framework.js | ||
| test-suite.js | ||
Claude Sandbox E2E Tests
This directory contains end-to-end tests for the Claude Sandbox file synchronization functionality. These tests verify that file operations (create, modify, delete) are properly synced between the container and the shadow repository, and that the web UI receives appropriate notifications.
Overview
The tests create a temporary git repository, start a claude-sandbox instance, perform file operations inside the container, and verify that:
- Files are properly synced to the shadow repository
- Git properly tracks additions, modifications, and deletions
- The web UI receives sync notifications
- File content is accurately preserved
Test Structure
Core Components
sync-test-framework.js- Main testing framework that manages sandbox lifecycledummy-repo/- Template files for creating test repositoriesrepo-to-container-sync-test.js- Verifies one-to-one sync from repo to containercore-functionality-test.js- Essential functionality tests (recommended)simple-deletion-test.js- Focused test for deletion trackingtest-suite.js- Comprehensive test suite with all scenariosrun-tests.sh- Shell script for automated test execution
Test Categories
- Repository to Container Sync - Verifying one-to-one sync from local repo to container
- File Addition - Creating new files and verifying sync
- File Modification - Modifying existing files and tracking changes
- File Deletion - Deleting files and ensuring proper removal
- Directory Operations - Creating nested directories and files
- Web UI Notifications - Verifying real-time sync events
Running Tests
Quick Test (Recommended)
# Run core functionality tests
node core-functionality-test.js
Individual Tests
# Test repository to container sync
node repo-to-container-sync-test.js
# Test deletion functionality specifically
node simple-deletion-test.js
# Run comprehensive test suite
node test-suite.js
Automated Test Runner
# Run all tests with cleanup
./run-tests.sh
Prerequisites
- Node.js (for running test scripts)
- Docker (for claude-sandbox containers)
- Built claude-sandbox project (
npm run build)
Test Process
-
Setup Phase
- Creates temporary git repository with dummy files
- Starts claude-sandbox instance
- Connects to web UI for monitoring sync events
-
Test Execution
- Performs file operations inside the container
- Waits for synchronization to complete
- Verifies shadow repository state
- Checks git status and file content
-
Cleanup Phase
- Terminates sandbox processes
- Removes containers and temporary files
Key Features Tested
Repository to Container Sync
- ✅ One-to-one file mapping from test repo to container
- ✅ No extra files in container (only test repo files)
- ✅ File content integrity verification
- ✅ Git repository properly initialized
- ✅ Correct branch creation
File Synchronization
- ✅ New file creation and content sync
- ✅ File modification and content updates
- ✅ File deletion and proper removal
- ✅ Directory creation and nested files
- ✅ Large file handling
- ✅ Special characters in filenames
Git Integration
- ✅ Staging of additions (
Astatus) - ✅ Tracking of modifications (
Mstatus) - ✅ Detection of deletions (
Dstatus) - ✅ Proper git commit workflow
Web UI Integration
- ✅ Real-time sync event notifications
- ✅ Change summary reporting
- ✅ WebSocket communication
Troubleshooting
Common Issues
Container startup timeout
- Increase timeout values in test framework
- Check Docker daemon is running
- Verify claude-sandbox image exists
Git lock conflicts
- Tests automatically handle concurrent git operations
- Temporary
.git/index.lockfiles are cleaned up
Port conflicts
- Tests use dynamic port allocation
- Multiple tests can run sequentially
WebSocket connection issues
- Framework includes connection retry logic
- Fallback to polling if WebSocket fails
Test Failure Analysis
Tests provide detailed error messages indicating:
- Which specific operation failed
- Expected vs actual file states
- Git status differences
- Sync event discrepancies
Development
Adding New Tests
- Create test function in appropriate test file
- Use framework methods for file operations:
await framework.addFile("path/file.txt", "content"); await framework.modifyFile("path/file.txt", "new content"); await framework.deleteFile("path/file.txt"); - Verify results using assertion methods:
const exists = await framework.shadowFileExists("file.txt"); const content = await framework.getShadowFileContent("file.txt"); const gitStatus = await framework.getGitStatus();
Framework API
File Operations
addFile(path, content)- Create new filemodifyFile(path, content)- Update existing filedeleteFile(path)- Remove filemoveFile(from, to)- Rename/move filecreateDirectory(path)- Create directory
Verification Methods
shadowFileExists(path)- Check file existencegetShadowFileContent(path)- Read file contentgetGitStatus()- Get git status outputwaitForSync()- Wait for synchronization
Event Monitoring
receivedSyncEvents- Array of sync notifications- WebSocket connection automatically established
Integration with CI/CD
These tests are designed to run in automated environments:
# Example GitHub Actions workflow
- name: Run E2E Tests
run: |
npm run build
cd e2e-tests
./run-tests.sh
The tests provide proper exit codes (0 for success, 1 for failure) and detailed logging for debugging purposes.