Skip to content

fix(client): Keep control calls out of in-process HTTP mocks - #30

Merged
dcramer merged 1 commit into
mainfrom
fix/control-calls-bypass-mocks
Nov 5, 2026
Merged

dcramer merged 1 commit into
mainfrom
fix/control-calls-bypass-mocks

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Found while adding Roach to getsentry/toolkit's MCP evals. That suite starts an MSW server in a vitest setup file, and its onUnhandledRequest throws for anything it does not know. MSW replaces http.request, so the POST …/session call from @sentry/roach/vitest/setup went to MSW. MSW refused it, and every test failed with Roach POST session failed with HTTP 500: Unhandled request. This happened against the live service on 0.2.0.

The client now keeps http.request and https.request as they are when it loads, and sends its control calls with them. When the consumer puts the Roach setup file before the file that starts the mock, which is a config-only change, the control calls reach the service. The tests' own requests still go through the mock and the proxy as before. This also covers nock, which patches the same functions. The README tells consumers about the setup-file order.

The new tests/vitest.test.ts case adds a setup file that makes http.request/https.request throw, and checks that the run still records. Without the client change, the test fails.

Limit: this depends on load order. A mock that starts before the Roach setup file loads, such as one in a global setup or with isolate: false across files, still catches the calls. Vitest's default per-file isolation runs each file in a fresh process, so the toolkit setup works. I confirmed that with two files against the live service.

via @dcramer.

--

View Session [Sentry]

A test project that starts MSW in a setup file broke every test: MSW
replaced http.request, so the session calls of the vitest setup file went
to the mock, which refused them as unhandled requests.

The client now keeps the request functions of node:http and node:https
as it loads. With the Roach setup file before the setup file that starts
the mock, control calls reach the service, and the requests of the tests
still go through the mock and the proxy.

Co-Authored-By: David Cramer <[email protected]>
@dcramer
dcramer merged commit 8eb6ad9 into main Nov 5, 2026
16 checks passed
sentry-junior Bot added a commit to getsentry/toolkit that referenced this pull request Nov 5, 2026
The MCP evals call OpenRouter on every run. Roach, Sentry's shared
recording proxy, now sits in front of those calls: it replays a call it
has a recording for, and records the rest when the run has ROACH_TOKEN.

The setup is config only: roach.json names the OpenRouter host and one
rule for its API, vitest.config.ts adds the Roach global setup and setup
file, and the Eval workflow passes ROACH_TOKEN and moves to Node 24,
which Roach needs. Fork PRs get no secrets, so they only replay.

The Roach setup file loads before setup-env.ts so that MSW does not
catch Roach's own control calls. That needs getsentry/roach#30.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior
sentry-junior Bot deleted the fix/control-calls-bypass-mocks branch November 5, 2026 17:36
dcramer added a commit to getsentry/toolkit that referenced this pull request Nov 6, 2026
The MCP evals (`packages/mcp-server-evals`) call OpenRouter on every
run. This sends those calls through
[Roach](https://github.com/getsentry/roach), Sentry's shared
record/replay proxy. CI replays recorded calls and records only the new
ones.

The change is config only, in the same shape as getsentry/warden#564:

- `roach.json` sets tenant `getsentry/toolkit`, allows
`https://openrouter.ai`, and has one `model` rule for `POST
https://openrouter.ai/api/v1/`. It has no `values` patterns: two CI runs
sent byte-identical requests, and no miss came from a value that changes
between runs. The API key travels in `Authorization`, which Roach
redacts on its own, so there is no `secretEnv`.
- `vitest.config.ts` adds the Roach global setup and setup file. The
Roach setup file goes **before** `src/setup-env.ts`, so MSW, which
throws on unhandled requests, does not catch Roach's own session calls.
- `eval.yml` passes `ROACH_TOKEN` to the eval step and moves the job to
Node 24, because Roach needs 24.14+. The workflow runs on
`pull_request`, not `pull_request_target`, so fork PRs get no secrets
and stay replay-only. The fork policy does not change.
- `@sentry/roach` 0.3.0 is in the catalog, and in
`minimumReleaseAgeExclude` because it was published today. Remove that
entry once 0.3.0 is older than the minimum release age. 0.3.0 includes
getsentry/roach#30 (Roach's session calls get past MSW) and #31
(`ROACH_MODE=off` runs on Node 22). The lockfile change touches only
Roach entries.
- `docs/testing/overview.md` has a short "Eval Recordings" section.

**Record and replay in CI**

Tested on unreleased Roach `main` before 0.3.0 shipped ([run
41970024566](https://github.com/getsentry/toolkit/actions/runs/41970024566)):

| | Attempt 1 (records) | Attempt 2 (replays) |
|---|---|---|
| Replayed | 9 | 207 |
| Live | 227 | 30 |
| Missed | 0 | 0 |
| Refused | 0 | 0 |
| Evals passed | 108/121 | 109/121 |
| Job duration | 5m57s | 3m12s |

All 30 live calls in attempt 2 came from the tests that failed in
attempt 1. Roach drops the recordings of failed tests, so an eval that
keeps failing calls the model live on every run.

The `ROACH_TOKEN` org secret already reaches this workflow (`***` in
both runs).

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0ACFA5JBDX%3A1793830221.324719 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0ACFA5JBDX%3A1793830221.324719)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0ACFA5JBDX%3A1793830221.324719/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant