Skip to content

test: stop the suite from reading — and calling — the developer's own gateway - #97

Open
xizhuomengcontin wants to merge 1 commit into
mainfrom
fix/hermetic-config-in-tests
Open

xizhuomengcontin wants to merge 1 commit into
mainfrom
fix/hermetic-config-in-tests

Conversation

@xizhuomengcontin

@xizhuomengcontin xizhuomengcontin commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Orca-Code-Review — push 1

Severity Count
P0 0
P1 0
P2 0
P3 0

✅ no blocking findings

record, replay, attach and compare all resolve their upstream through upstreamPlan() and
readConfig() with no environment argument. In a test, that reads the real
~/.config/orca/config.json.

On a machine where anyone has run orca setup, that file names a gateway. Any dialect a test did
not override with --upstream-* resolves to it, and the test sends a live request to a third
party's host.

How it showed up

Two tests were red on my machine and green in CI:

cli/test/compare.test.ts > forks every model from the SAME parent run, not from the previous fork
cli/test/e2e.test.ts    > forks from a checkpoint and continues live on a different model

Run alone, in 1.6 seconds:

fake-agent: upstream 401: {"type":"error","error":{"message":"unknown provider error"}}
AssertionError: expected 2 to be greater than 2
 ❯ packages/cli/test/e2e.test.ts:754:32

The test passes --upstream-anthropic <fixture>. It does not pass --upstream-openai, so
resolveUpstream falls through to config.gateway.url for openai and openai-responses
in my case http://155.103.159.98:8317, a real host.

What saved the key is upstreamPlan's unanimity rule, and it is worth naming because it was
the only thing standing there: origins were not all the gateway, so no headers were attached and
the request came back 401. Had the test overridden nothing, every origin would have been the
gateway, goingToGateway would have been true, and the developer's API key would have gone out on
a request generated by npx vitest.

It is not a hang, and not a platform thing

I had previously recorded these two as an unexplained hang that survived raising the timeout to
120s. That was wrong, and the mechanism is ordinary: under a full suite they reach the 30s timeout
because everything is slow at once; run alone they fail immediately with the 401 above. Both pass
with an isolated config home, on Windows and anywhere else.

The repo already knew

compare.test.ts had met this and worked around it inside a single describe:

compareCommand falls back to readConfig(), which reads the real ~/.config/orca. On a
machine where anyone has run orca setup that config has models in it, so this test never
reached the branch it names […] Nothing to do with the platform; CI passes only because CI has
no config.

That is the complete diagnosis, written down, and the fix it got covered one block. The same
fallback was meanwhile calling a real gateway from two other test files.

The change

vitest.setup.ts gives every worker an empty XDG_CONFIG_HOME, so no future test has to remember.
A real empty directory rather than a missing path, so that a test which writes a config stays out
of the developer's own.

  • the local workaround in compare.test.ts retires into it, its history kept in the comment
  • config.test.ts gains the guard that makes a silent failure of the setup file loud:
    readConfig() with no argument must resolve to {}

Tests that legitimately exercise config all pass an explicit env object already, so none of them
are affected.

Measured

Windows, same machine and build: 10 failures before, 8 after — the two gone are exactly these,
and nothing was skipped to get there. prettier --check, tsc --build --force,
scripts/conformance.mjs (63 events, 0 failures) and scripts/fidelity.mjs --check
(0 regressions) are clean.

CI cannot demonstrate this fix — it has no config, which is the point.

🤖 Generated with Claude Code

… gateway

`record`, `replay`, `attach` and `compare` all resolve their upstream through
`upstreamPlan()` and `readConfig()` with no environment argument. In a test,
that reads the real `~/.config/orca/config.json`.

So on a machine where anyone has run `orca setup`, any dialect a test did not
override with `--upstream-*` resolves to that developer's gateway, and the test
sends a live request to it. The fork tests do exactly that:

    fake-agent: upstream 401: {"error":{"message":"unknown provider error"}}
    AssertionError: expected 2 to be greater than 2

`--upstream-anthropic` was overridden; `openai` and `openai-responses` were not,
and fell through to the configured gateway. What saved the key here is
`upstreamPlan`'s unanimity rule — origins were not all the gateway, so no
headers were attached and the request 401'd. Had the test overridden nothing,
every origin would have been the gateway and the key would have gone with it.

`compare.test.ts` had already met this and worked around it inside one
`describe`, with the diagnosis in the comment: *"Nothing to do with the
platform; CI passes only because CI has no config."* That is the whole thing —
it cannot fail in CI, by construction, so it surfaces only as a test that is
red on a contributor's machine and green on everyone else's.

vitest.setup.ts gives every worker an empty XDG_CONFIG_HOME, so no future test
has to remember. The local workaround in compare.test.ts retires into it, and
config.test.ts gains the guard that makes the setup file's failure visible:
`readConfig()` with no argument must resolve to `{}`.

I had these two down as an unexplained hang. They do not hang — under a full
suite they hit the 30s timeout, but run alone each fails in under two seconds
with the 401 above. Both pass with an isolated config home, on Windows and
independently of it.

Windows: 10 failures before, 8 after. Nothing platform-specific about either of
the two, and nothing was skipped to get there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@orcacode-review orcacode-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐳 OrcaCode Review

No findings — nothing to flag in this PR. Great work!

OrcaCode Review — Route Smarter. Ship Safer. Spend Less.
Engine-reported: 1021 calls · 118.7M tokens · 99% cached

❤️ Share · Install OrcaCode Review

Free on GitHub — the review runs on your own OrcaRouter key. If it helped, a shout-out goes a long way.

Share: X · Reddit · LinkedIn
Follow: X · Discord · LinkedIn · OrcaRouter

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