Overview
aixyz provides aloadEnv utility from aixyz/test for loading environment variables during tests. Combined with Bun’s built-in test runner, you can write both deterministic and non-deterministic agent tests.
Test File Convention
Place your test file alongside your agent:Writing Tests
app/agent.test.ts
loadEnv()
The loadEnv function from aixyz/test loads environment variables for test runs. It loads .env.test.local (where your OPENAI_API_KEY lives for tests) while .env.local is ignored during testing.
Deterministic vs Non-Deterministic
| Type | Description | CI-Safe |
|---|---|---|
| Deterministic | Validate agent type, tools, config | Yes |
| Non-deterministic | Call LLM and validate response content | No* |
test.skipIf(!process.env.OPENAI_API_KEY) to skip gracefully when no API key is available.
Fully Offline Tests with fake()
Use fake() from aixyz/model to replace the real LLM with a deterministic transform. It returns a LanguageModelV3 that works with ToolLoopAgent — no API key, no network calls:
app/agent.ts
app/agent.test.ts
aixyz/model API reference for full details and the Fake Model Agent template for a complete working example.