Skip to content

Commit 4170e74

Browse files
committed
test(e2e): mock + real-endpoint mode for anthropic-tool-results-repro
1 parent 52324c6 commit 4170e74

7 files changed

Lines changed: 538 additions & 288 deletions

File tree

apps/vscode-e2e/AGENTS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,33 @@ await api.setConfiguration({
246246
247247
Always restore the default OpenRouter config in `suiteTeardown` so subsequent suites are unaffected.
248248
249+
### Running an Anthropic-provider test against the real API
250+
251+
Tests that use the Anthropic provider can be authored to flip between mock mode (aimock-backed,
252+
deterministic) and real-endpoint mode (live `/v1/messages`) based on env. `anthropic-opus-4-7`
253+
and `anthropic-tool-results-repro` both follow this pattern.
254+
255+
The test wraps an HTTP proxy server (`withAnthropicProxy(baseUrl, ...)`) that forwards to:
256+
257+
- **Mock mode** (default — no `ANTHROPIC_API_KEY`): aimock, which serves the corresponding JSON
258+
fixture in `fixtures/`. Request shape can be asserted directly because both the prompt and the
259+
response are pinned.
260+
- **Real-endpoint mode** (`ANTHROPIC_API_KEY` set, no aimock active): `https://api.anthropic.com`.
261+
Useful for catching wire-protocol contract issues that only the real API enforces. Tests in
262+
this mode should assert on observable outcomes (task completion, captured error events) rather
263+
than precise request shape, because the model is free to pick any tool sequence.
264+
265+
To run such a test against the real Anthropic API, add `ANTHROPIC_API_KEY=<key>` to
266+
`apps/vscode-e2e/.env.local` and run with the targeted file:
267+
268+
```sh
269+
TEST_FILE=<your-test>.test.js pnpm --filter @roo-code/vscode-e2e test:ci
270+
```
271+
272+
`test:ci` (not `test:ci:mock`) is required so aimock does not start and `AIMOCK_URL` stays unset;
273+
that is what flips the test into real-endpoint mode. `TEST_FILE` is required so unrelated suites
274+
don't burn through the real API.
275+
249276
## Programmatic fixtures (regex matching)
250277
251278
For requests that can't be matched by a stable substring (e.g. "starts with `<environment_details>` but not preceded by a user message"), add a programmatic fixture in `src/runTest.ts` using `mock.addFixture()` with a `RegExp` match. These are only available in replay mode and are not recorded.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"fixtures": [
3+
{
4+
"match": {
5+
"userMessage": "anthropic-tool-results-repro: use only read_file to read the four files",
6+
"sequenceIndex": 0
7+
},
8+
"response": {
9+
"toolCalls": [
10+
{
11+
"name": "read_file",
12+
"arguments": "{\"path\":\"anthropic-tool-results-repro/file-1.txt\"}",
13+
"id": "toolu_repro_190_read_1"
14+
},
15+
{
16+
"name": "read_file",
17+
"arguments": "{\"path\":\"anthropic-tool-results-repro/file-2.txt\"}",
18+
"id": "toolu_repro_190_read_2"
19+
},
20+
{
21+
"name": "read_file",
22+
"arguments": "{\"path\":\"anthropic-tool-results-repro/file-3.txt\"}",
23+
"id": "toolu_repro_190_read_3"
24+
},
25+
{
26+
"name": "read_file",
27+
"arguments": "{\"path\":\"anthropic-tool-results-repro/file-4.txt\"}",
28+
"id": "toolu_repro_190_read_4"
29+
}
30+
]
31+
}
32+
},
33+
{
34+
"match": { "toolCallId": "toolu_repro_190_read_4" },
35+
"response": {
36+
"toolCalls": [
37+
{
38+
"name": "attempt_completion",
39+
"arguments": "{\"result\":\"ANTHROPIC_TOOL_RESULTS_REPRO_DONE\"}",
40+
"id": "toolu_repro_190_done"
41+
}
42+
]
43+
}
44+
}
45+
]
46+
}

0 commit comments

Comments
 (0)