TestGen Agent
The TestGen agent receives error detection messages and generates bun:test reproduction tests to confirm that a bug exists.
Responsibilities
Section titled “Responsibilities”- Generate TypeScript test files from error context using LLM
- Execute tests in isolated Sandbox containers
- Confirm reproduction (test must fail to prove the bug)
- Store artifacts in R2 and publish to the
triage-readyqueue
How It Works
Section titled “How It Works”Test Generation
Section titled “Test Generation”- Receive an
ErrorDetectedMessagefrom the queue - Fetch the service config to get the repository URL
- Build a prompt with the sample event: route, status code, error message, stack trace
- Call Workers AI to generate a
bun:testfile - If the LLM output doesn’t contain valid
bun:testimports, use a fallback template
Sandbox Execution
Section titled “Sandbox Execution”If a Sandbox binding and repository URL are available:
- Clone the repository in the Sandbox container
- Install dependencies (
bun install) - Write the generated test file
- Execute the test
Reproduction is confirmed when the test fails — this proves the error can be reproduced in the codebase.
Artifacts
Section titled “Artifacts”Three artifacts are stored in R2 for each incident:
| File | Description |
|---|---|
test-case.ts | The generated reproduction test |
test-result.json | { reproductionConfirmed, generatedAt } |
sample-event.json | The original observability event |
Failure Handling
Section titled “Failure Handling”If the test passes (bug not reproduced), the incident is marked needs_human. A human developer should investigate whether the test generation was faulty or if the error is transient.
HTTP Endpoints
Section titled “HTTP Endpoints”| Method | Path | Description |
|---|---|---|
POST | /generate | Generate a test case from an error message |
GET | /status | Current agent state |