Skip to content

test(gateway): isolate instance fixture from caller env and torn reads - #131

Merged
nixuuu merged 1 commit into
devfrom
test/flaky-instance-changes
Nov 5, 2026
Merged

nixuuu merged 1 commit into
devfrom
test/flaky-instance-changes

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Fixes two causes of flaky failures in tests/integration/instance-changes.test.ts. Both are in the test fixture; product code is unchanged.

  1. The caller's environment leaked in. The in-process worker passes its own environment to native harnesses. A shell that sets ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL or CLAUDE_* (for example an agent session) made every native turn look proxied, so the native→proxy→native checks failed. The fixture now removes provider variables (ANTHROPIC_, CLAUDE, CODEX_, OPENAI_, XAI_, GROK_) while it runs and restores them on close.
  2. A half-written line was read (the CI failure). The test polls probe.jsonl while harness processes append to it. A read could catch half a line, and the strict decoder threw Expected a valid JSON string. Grok's instance switches were then never audited, so the audit test saw 4 rows instead of 6. Only lines that end with a newline are parsed now.

No sleeps, retries, raised timeouts or weaker assertions.

Related: #85

The in-process worker hands its own environment to native harnesses, so
the instance fixture inherited the provider variables of whoever ran the
tests. In an agent session (ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL,
CLAUDE_*) every native turn looked proxied and the native→proxy→native
checks failed with proxy: true. The fixture now removes the caller's
provider variables for its lifetime and restores them on close.

The test also polls probe.jsonl while harness processes append to it. A
read in the middle of an append sees a torn last line, and the strict
JSON decode threw "Expected a valid JSON string" (the GROK CI flake on
#115; its switches were then never audited, so the audit test saw 4
rows instead of 6). Only newline-terminated lines are parsed now.

Related: #85
@nixuuu nixuuu changed the title test(gateway): read only complete, proxy-keyed instance probe records test(gateway): isolate instance fixture from caller env and torn reads Nov 5, 2026
@nixuuu
nixuuu merged commit 1004e34 into dev Nov 5, 2026
10 checks passed
@nixuuu
nixuuu deleted the test/flaky-instance-changes branch November 5, 2026 05:47
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