Skip to content

TestGen Agent

The TestGen agent receives error detection messages and generates bun:test reproduction tests to confirm that a bug exists.

  • 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-ready queue
  1. Receive an ErrorDetectedMessage from the queue
  2. Fetch the service config to get the repository URL
  3. Build a prompt with the sample event: route, status code, error message, stack trace
  4. Call Workers AI to generate a bun:test file
  5. If the LLM output doesn’t contain valid bun:test imports, use a fallback template

If a Sandbox binding and repository URL are available:

  1. Clone the repository in the Sandbox container
  2. Install dependencies (bun install)
  3. Write the generated test file
  4. Execute the test

Reproduction is confirmed when the test fails — this proves the error can be reproduced in the codebase.

Three artifacts are stored in R2 for each incident:

FileDescription
test-case.tsThe generated reproduction test
test-result.json{ reproductionConfirmed, generatedAt }
sample-event.jsonThe original observability event

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.

MethodPathDescription
POST/generateGenerate a test case from an error message
GET/statusCurrent agent state

src/agents/test-gen.ts