|
| 1 | +# Dev Proxy Mock Files |
| 2 | + |
| 3 | +This directory contains mock response files for the NeoKai test suite. These files are used by Dev Proxy to simulate Anthropic API responses without making real API calls. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Run one online test with Dev Proxy (helper auto starts/stops proxy) |
| 9 | +NEOKAI_USE_DEV_PROXY=1 bun test packages/daemon/tests/online/convo/multiturn-conversation.test.ts |
| 10 | + |
| 11 | +# Or run all online tests |
| 12 | +NEOKAI_USE_DEV_PROXY=1 bun test packages/daemon/tests/online/ |
| 13 | +``` |
| 14 | + |
| 15 | +### Strict Safety in Dev Proxy Mode |
| 16 | + |
| 17 | +When `NEOKAI_USE_DEV_PROXY=1` is enabled via the online test helper: |
| 18 | + |
| 19 | +- `CLAUDE_CODE_OAUTH_TOKEN` is cleared |
| 20 | +- `ANTHROPIC_AUTH_TOKEN` is cleared |
| 21 | +- `ANTHROPIC_API_KEY` is replaced with a dummy test key |
| 22 | +- Tests fail fast if Dev Proxy is unavailable |
| 23 | + |
| 24 | +This prevents accidental real Anthropic credential usage during mocked runs. |
| 25 | + |
| 26 | +### Verify Requests Hit Dev Proxy |
| 27 | + |
| 28 | +After a test run, either: |
| 29 | + |
| 30 | +```bash |
| 31 | +# Persist logs to .devproxy/devproxy.log during helper-managed stop |
| 32 | +NEOKAI_DEV_PROXY_CAPTURE_LOGS=1 NEOKAI_USE_DEV_PROXY=1 bun test packages/daemon/tests/online/convo/multiturn-conversation.test.ts |
| 33 | +tail -n 120 .devproxy/devproxy.log |
| 34 | + |
| 35 | +# Or read directly from devproxy |
| 36 | +devproxy logs --lines 120 --output text |
| 37 | +``` |
| 38 | + |
| 39 | +Expected signal of a properly mocked request: |
| 40 | + |
| 41 | +- `req ... POST http://127.0.0.1:8000/v1/messages?beta=true` |
| 42 | +- `mock ... MockResponsePlugin: 200 ...` |
| 43 | + |
| 44 | +If you see `pass ... Passed through`, the request did not match a mock. |
| 45 | + |
| 46 | +## Mock Files |
| 47 | + |
| 48 | +| File | Description | Use Case | |
| 49 | +|------|-------------|----------| |
| 50 | +| `mocks.json` | Default mock responses | General testing | |
| 51 | +| `mocks-basic.json` | Simple text responses | Basic conversation tests | |
| 52 | +| `mocks-tool-use.json` | Tool call scenarios | Tool execution tests | |
| 53 | +| `mocks-errors.json` | Error responses | Error handling tests | |
| 54 | +| `mocks-room.json` | Multi-agent scenarios | Room workflow tests | |
| 55 | + |
| 56 | +## Switching Mock Files |
| 57 | + |
| 58 | +Edit `devproxyrc.json`: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "mockResponsePlugin": { |
| 63 | + "mocksFile": "mocks-tool-use.json" |
| 64 | + } |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +Then restart Dev Proxy: |
| 69 | + |
| 70 | +```bash |
| 71 | +bun run test:proxy:restart |
| 72 | +``` |
| 73 | + |
| 74 | +## Scenario Coverage |
| 75 | + |
| 76 | +### mocks-basic.json |
| 77 | + |
| 78 | +| Trigger | Response | |
| 79 | +|---------|----------| |
| 80 | +| Default | Generic greeting message | |
| 81 | +| "What is 2+2?..." | "4" | |
| 82 | +| "What is 1+1?..." | "2" | |
| 83 | +| "What is 3+3?..." | "6" | |
| 84 | +| "Say hello" | Greeting response | |
| 85 | +| "Tell me a joke" | Programmer joke | |
| 86 | +| "room ok" | Room chat acknowledgment | |
| 87 | + |
| 88 | +### mocks-tool-use.json |
| 89 | + |
| 90 | +| Trigger | Tool | Action | |
| 91 | +|---------|------|--------| |
| 92 | +| "Read the file test.txt" | Read | File read operation | |
| 93 | +| "Write a file called output.txt..." | Write | File write operation | |
| 94 | +| "List files in the current directory" | Glob | File listing | |
| 95 | +| "Search for TODO in all files" | Grep | Content search | |
| 96 | +| "Run the command echo hello" | Bash | Command execution | |
| 97 | +| "What is git status?" | Bash | Git status check | |
| 98 | +| "Call the MCP tool to create a task" | mcp_tool_call | MCP tool invocation | |
| 99 | + |
| 100 | +### mocks-errors.json |
| 101 | + |
| 102 | +| Trigger | Status | Error Type | |
| 103 | +|---------|--------|------------| |
| 104 | +| "trigger rate limit" | 429 | rate_limit_error | |
| 105 | +| "trigger server error" | 500 | api_error | |
| 106 | +| "trigger overloaded error" | 529 | overloaded_error | |
| 107 | +| "trigger invalid request" | 400 | invalid_request_error | |
| 108 | +| "trigger authentication error" | 401 | authentication_error | |
| 109 | +| "trigger permission error" | 403 | permission_error | |
| 110 | +| "trigger not found error" | 404 | not_found_error | |
| 111 | +| "trigger context length error" | 400 | invalid_request_error (context) | |
| 112 | +| "trigger tool error" | 200 | Tool error response | |
| 113 | +| "trigger max turns error" | 200 | Max turns message | |
| 114 | + |
| 115 | +### mocks-room.json |
| 116 | + |
| 117 | +| Agent | Scenario | Tools Used | |
| 118 | +|-------|----------|------------| |
| 119 | +| Chat | Simple text response | None | |
| 120 | +| Planner | Phase 1 - Create plan | Write | |
| 121 | +| Planner | Phase 2 - Create tasks | mcp_tool_call | |
| 122 | +| Coder | Implement task | Write | |
| 123 | +| Leader | Submit for review | mcp_tool_call (submit_for_review) | |
| 124 | +| Leader | Complete task | mcp_tool_call (complete_task) | |
| 125 | +| Reviewer | Review PR | Bash (gh pr view) | |
| 126 | + |
| 127 | +## Request Matching Priority |
| 128 | + |
| 129 | +Dev Proxy matches requests in this order: |
| 130 | + |
| 131 | +1. **Exact match** - URL + method + body fragment |
| 132 | +2. **URL match** - URL + method only |
| 133 | +3. **Wildcard match** - URL pattern with wildcards |
| 134 | + |
| 135 | +More specific matches take precedence over general ones. |
| 136 | + |
| 137 | +## Adding New Mocks |
| 138 | + |
| 139 | +1. Choose the appropriate mock file (or create a new one) |
| 140 | +2. Add a new mock entry with: |
| 141 | + - `request.url` - The API endpoint |
| 142 | + - `request.method` - HTTP method (usually POST) |
| 143 | + - `request.bodyFragment` - Optional request body matcher |
| 144 | + - `response.statusCode` - HTTP status code |
| 145 | + - `response.headers` - Response headers |
| 146 | + - `response.body` - Anthropic API response format |
| 147 | + |
| 148 | +Example: |
| 149 | + |
| 150 | +```json |
| 151 | +{ |
| 152 | + "request": { |
| 153 | + "url": "http://127.0.0.1:8000/v1/messages?beta=true", |
| 154 | + "method": "POST", |
| 155 | + "bodyFragment": { |
| 156 | + "messages": [ |
| 157 | + { |
| 158 | + "content": "your trigger phrase here" |
| 159 | + } |
| 160 | + ] |
| 161 | + } |
| 162 | + }, |
| 163 | + "response": { |
| 164 | + "statusCode": 200, |
| 165 | + "headers": [ |
| 166 | + { |
| 167 | + "name": "content-type", |
| 168 | + "value": "application/json" |
| 169 | + } |
| 170 | + ], |
| 171 | + "body": { |
| 172 | + "id": "msg_custom_001", |
| 173 | + "type": "message", |
| 174 | + "role": "assistant", |
| 175 | + "content": [ |
| 176 | + { |
| 177 | + "type": "text", |
| 178 | + "text": "Your response text here" |
| 179 | + } |
| 180 | + ], |
| 181 | + "model": "claude-sonnet-4-20250514", |
| 182 | + "stop_reason": "end_turn", |
| 183 | + "stop_sequence": null, |
| 184 | + "usage": { |
| 185 | + "input_tokens": 10, |
| 186 | + "output_tokens": 10, |
| 187 | + "cache_creation_input_tokens": 0, |
| 188 | + "cache_read_input_tokens": 0, |
| 189 | + "service_tier": "standard" |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | +} |
| 194 | +``` |
| 195 | + |
| 196 | +## Documentation |
| 197 | + |
| 198 | +For more details, see [docs/dev-proxy-integration.md](../docs/dev-proxy-integration.md). |
0 commit comments