| .. | ||
| helpers | ||
| events.test.ts | ||
| messaging.test.ts | ||
| models.test.ts | ||
| package.json | ||
| permissions.test.ts | ||
| questions.test.ts | ||
| README.md | ||
| session.test.ts | ||
| tools.test.ts | ||
| tsconfig.json | ||
| vitest.config.ts | ||
OpenCode Compatibility Tests
These tests verify that sandbox-agent exposes OpenCode-compatible API endpoints under /opencode and that they are usable with the official @opencode-ai/sdk TypeScript SDK.
Purpose
The goal is to enable sandbox-agent to be used as a drop-in replacement for OpenCode's server, allowing tools and integrations built for OpenCode to work seamlessly with sandbox-agent.
Test Coverage
The tests cover the following OpenCode API surfaces:
Session Management (session.test.ts)
POST /session- Create a new sessionGET /session- List all sessionsGET /session/{id}- Get session detailsPATCH /session/{id}- Update session propertiesDELETE /session/{id}- Delete a session
Messaging (messaging.test.ts)
POST /session/{id}/message- Send a prompt to the sessionPOST /session/{id}/prompt_async- Send async promptGET /session/{id}/message- List messagesGET /session/{id}/message/{messageID}- Get specific messagePOST /session/{id}/abort- Abort session
Event Streaming (events.test.ts)
GET /event- Subscribe to all events (SSE)GET /global/event- Subscribe to global events (SSE)GET /session/status- Get session status
Permissions (permissions.test.ts)
POST /session/{id}/permissions/{permissionID}- Respond to permission request
OpenAPI Coverage (Rust)
cargo test -p sandbox-agent --test opencode_openapi- Compares the Utoipa-generated OpenCode spec against
resources/agent-schemas/artifacts/openapi/opencode.json
Running Tests
# From this directory
pnpm test
# Or from the workspace root
pnpm --filter @sandbox-agent/opencode-compat-tests test
Prerequisites
-
Build the sandbox-agent binary:
cargo build -p sandbox-agent -
Or set
SANDBOX_AGENT_BINenvironment variable to point to a pre-built binary.
Test Approach
Each test:
- Spawns a fresh sandbox-agent instance on a unique port
- Uses
createOpencodeClientfrom@opencode-ai/sdkto connect - Tests the OpenCode-compatible endpoints
- Cleans up the server instance
This ensures tests are isolated and can run in parallel.
Current Status
These tests validate the /opencode compatibility layer and should pass when the endpoints are mounted and responding with OpenCode-compatible shapes.
Implementation Notes
To make sandbox-agent OpenCode-compatible, the following needs to be implemented:
- OpenCode API Routes - Exposed under
/opencode - Request/Response Mapping - OpenCode response shapes with stubbed data where needed
- SSE Event Streaming - OpenCode event format for SSE
- Permission Handling - Accepts OpenCode permission replies
See the OpenCode SDK types at /home/nathan/misc/opencode/packages/sdk/js/src/gen/types.gen.ts for the expected API shapes.