runTests
Execute tests in the sandbox environment with automatic test runner detection
Overview
The runTests
method executes tests in the sandbox environment and automatically detects the appropriate test runner (e.g., npm test, pytest, cargo test, etc.). This method supports both streaming and non-streaming execution modes.
Method Signature
Parameters
The Git branch to run tests on. If not specified, tests will run on the current branch.
Optional conversation history to provide context for the test execution. This can help the agent understand previous interactions and make more informed decisions about test execution.
Optional callbacks for streaming updates during test execution.
Return Value
Returns a Promise<AgentResponse>
containing the test execution results:
The ID of the sandbox where tests were executed
Standard output from the test execution
Standard error output from the test execution
Exit code from the test execution (0 indicates success)
Examples
Basic Test Execution
Run Tests on Specific Branch
Streaming Test Execution
Run Tests with Context
Test Runner Detection
The runTests
method automatically detects and uses the appropriate test runner based on the project structure:
- Node.js: Runs
npm test
oryarn test
- Python: Runs
pytest
,python -m unittest
, orpython -m pytest
- Rust: Runs
cargo test
- Go: Runs
go test
- And more: Supports various other testing frameworks
Error Handling
Notes
- The method requires an active sandbox environment
- Test execution is performed within the sandbox, ensuring a clean and isolated environment
- The agent will attempt to install dependencies if they’re missing
- Streaming callbacks provide real-time feedback during test execution
- The method works with both Codex and Claude agents