|
| 1 | +# Helicone E2E Tests |
| 2 | + |
| 3 | +End-to-end integration tests for the Helicone AI Gateway. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This test suite validates the Helicone AI Gateway functionality by making real HTTP requests to the gateway running on port 8793. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- Node.js 20+ |
| 12 | +- Yarn |
| 13 | +- Helicone AI Gateway running on port 8793 |
| 14 | + |
| 15 | +## Getting Started |
| 16 | + |
| 17 | +### 1. Install Dependencies |
| 18 | + |
| 19 | +```bash |
| 20 | +cd e2e |
| 21 | +yarn install |
| 22 | +``` |
| 23 | + |
| 24 | +### 2. Start the Gateway |
| 25 | + |
| 26 | +From the root of the Helicone project: |
| 27 | + |
| 28 | +```bash |
| 29 | +cd worker |
| 30 | +npx wrangler dev --var WORKER_TYPE:AI_GATEWAY_API --port 8793 --test-scheduled |
| 31 | +``` |
| 32 | + |
| 33 | +Or use the convenience script: |
| 34 | + |
| 35 | +```bash |
| 36 | +./worker/run_all_workers.sh |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. Run Tests |
| 40 | + |
| 41 | +```bash |
| 42 | +# Run all tests |
| 43 | +yarn test |
| 44 | + |
| 45 | +# Run gateway tests only |
| 46 | +yarn test:gateway |
| 47 | + |
| 48 | +# Run in watch mode |
| 49 | +yarn test:watch |
| 50 | + |
| 51 | +# Run with coverage |
| 52 | +yarn test:coverage |
| 53 | +``` |
| 54 | + |
| 55 | +## Configuration |
| 56 | + |
| 57 | +Create a `.env` file in the `e2e` directory to customize settings: |
| 58 | + |
| 59 | +```bash |
| 60 | +GATEWAY_URL=http://localhost:8793 |
| 61 | +``` |
| 62 | + |
| 63 | +## Test Structure |
| 64 | + |
| 65 | +``` |
| 66 | +e2e/ |
| 67 | +├── lib/ # Shared utilities |
| 68 | +│ ├── constants.ts # Test constants and config |
| 69 | +│ ├── http-client.ts # HTTP client wrapper |
| 70 | +│ └── test-helpers.ts # Common test helpers |
| 71 | +├── tests/ |
| 72 | +│ ├── setup.ts # Jest setup file |
| 73 | +│ └── gateway/ # Gateway-specific tests |
| 74 | +│ ├── health.test.ts # Health check tests |
| 75 | +│ └── chat-completion.test.ts # Chat completion tests |
| 76 | +├── jest.config.ts # Jest configuration |
| 77 | +├── tsconfig.json # TypeScript configuration |
| 78 | +└── package.json |
| 79 | +``` |
| 80 | + |
| 81 | +## Writing Tests |
| 82 | + |
| 83 | +### Example Test |
| 84 | + |
| 85 | +```typescript |
| 86 | +import { gatewayClient } from "../../lib/http-client"; |
| 87 | +import { GATEWAY_ENDPOINTS } from "../../lib/constants"; |
| 88 | +import { createChatCompletionRequest } from "../../lib/test-helpers"; |
| 89 | + |
| 90 | +describe("My Feature", () => { |
| 91 | + it("should work correctly", async () => { |
| 92 | + const requestBody = createChatCompletionRequest({ |
| 93 | + model: "gpt-4o-mini", |
| 94 | + messages: [{ role: "user", content: "Hello" }], |
| 95 | + }); |
| 96 | + |
| 97 | + const response = await gatewayClient.post( |
| 98 | + GATEWAY_ENDPOINTS.CHAT_COMPLETIONS, |
| 99 | + requestBody |
| 100 | + ); |
| 101 | + |
| 102 | + expect(response.status).toBe(200); |
| 103 | + }); |
| 104 | +}); |
| 105 | +``` |
| 106 | + |
| 107 | +## Available Test Utilities |
| 108 | + |
| 109 | +### HTTP Client |
| 110 | + |
| 111 | +```typescript |
| 112 | +import { gatewayClient } from "../../lib/http-client"; |
| 113 | + |
| 114 | +// Make requests |
| 115 | +await gatewayClient.post("/endpoint", data); |
| 116 | +await gatewayClient.get("/endpoint"); |
| 117 | + |
| 118 | +// Custom headers |
| 119 | +gatewayClient.setHeaders({ "X-Custom": "value" }); |
| 120 | +gatewayClient.resetHeaders(); |
| 121 | +``` |
| 122 | + |
| 123 | +### Test Helpers |
| 124 | + |
| 125 | +```typescript |
| 126 | +import { |
| 127 | + createChatCompletionRequest, |
| 128 | + validateChatCompletionResponse, |
| 129 | + retry, |
| 130 | + sleep, |
| 131 | +} from "../../lib/test-helpers"; |
| 132 | + |
| 133 | +// Create request body |
| 134 | +const request = createChatCompletionRequest({ |
| 135 | + model: "gpt-4o-mini", |
| 136 | + messages: [{ role: "user", content: "Hello" }], |
| 137 | +}); |
| 138 | + |
| 139 | +// Validate response |
| 140 | +validateChatCompletionResponse(response); |
| 141 | + |
| 142 | +// Retry with backoff |
| 143 | +await retry(() => apiCall(), { maxAttempts: 3 }); |
| 144 | +``` |
| 145 | + |
| 146 | +## Troubleshooting |
| 147 | + |
| 148 | +### Gateway Not Running |
| 149 | + |
| 150 | +If tests fail with connection errors: |
| 151 | + |
| 152 | +1. Ensure the gateway is running: `npx wrangler dev --var WORKER_TYPE:AI_GATEWAY_API --port 8793` |
| 153 | +2. Check the port is correct: `lsof -i :8793` |
| 154 | +3. Verify the gateway URL in `.env` |
| 155 | + |
| 156 | +### Timeout Errors |
| 157 | + |
| 158 | +If tests timeout: |
| 159 | + |
| 160 | +1. Increase timeout in `jest.config.ts`: `testTimeout: 60000` |
| 161 | +2. Check gateway logs for errors |
| 162 | +3. Verify network connectivity |
| 163 | + |
| 164 | +### Authentication Errors |
| 165 | + |
| 166 | +Tests use mock authentication headers. If you see auth errors: |
| 167 | + |
| 168 | +1. Check `lib/constants.ts` for header configuration |
| 169 | +2. Verify the gateway is configured for local testing |
| 170 | +3. Update test headers as needed |
| 171 | + |
| 172 | +## CI/CD Integration |
| 173 | + |
| 174 | +Add to your CI pipeline: |
| 175 | + |
| 176 | +```yaml |
| 177 | +- name: Install E2E dependencies |
| 178 | + run: cd e2e && yarn install |
| 179 | + |
| 180 | +- name: Start Gateway |
| 181 | + run: | |
| 182 | + cd worker |
| 183 | + npx wrangler dev --var WORKER_TYPE:AI_GATEWAY_API --port 8793 & |
| 184 | + sleep 10 |
| 185 | +
|
| 186 | +- name: Run E2E tests |
| 187 | + run: cd e2e && yarn test |
| 188 | +``` |
0 commit comments