Skip to content

test(attribution): fix order-dependent CI flake in getAttributionTexts#1435

Open
0xfandom wants to merge 1 commit into
Gitlawb:mainfrom
0xfandom:fix/attribution-test-provider-env-isolation
Open

test(attribution): fix order-dependent CI flake in getAttributionTexts#1435
0xfandom wants to merge 1 commit into
Gitlawb:mainfrom
0xfandom:fix/attribution-test-provider-env-isolation

Conversation

@0xfandom
Copy link
Copy Markdown
Contributor

Summary

src/utils/attribution.test.ts has an order-dependent failure that has been intermittently red-lighting smoke-and-tests across unrelated PR branches:

(fail) getAttributionTexts > preserves includeCoAuthoredBy true as an explicit old-default opt-in

Root cause

getAttributionTexts() resolves the active provider + model through getAPIProvider() (→ resolveActiveRouteIdFromEnv) and getMainLoopModel(), both of which read process.env. The suite's beforeEach pinned CLAUDE_CODE_USE_OPENAI=1 + OPENAI_MODEL=gpt-5.5 but left the competing route-selection flags untouched. Sibling test files (gemini / mistral / foundry / codex shim, provider-config) set those flags, and an incomplete env restore there leaks into this suite under interleaved bun test file ordering — the route resolves to gemini/mistral/foundry instead of openai, the co-author name changes, and the Co-Authored-By: OpenClaude (gpt-5.5) … expectation fails.

Because it depends on which file ran immediately before, it surfaced on some PR CI runs and not others (same commit base).

Fix

Capture and clear the full set of routing env vars in beforeEach (CLAUDE_CODE_USE_GEMINI/_MISTRAL/_GITHUB/_BEDROCK/_VERTEX/_FOUNDRY, NVIDIA_NIM, OPENAI_BASE_URL/OPENAI_API_BASE, CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED, alternate *_MODEL), restore in afterEach. The route now resolves deterministically to plain OpenAI + gpt-5.5 regardless of run order. No production code changes.

Test plan

Reproduced + verified each leaker:

env set before suite before fix after fix
CLAUDE_CODE_USE_GEMINI=1 1 fail 20 pass
CLAUDE_CODE_USE_MISTRAL=1 1 fail 20 pass
CLAUDE_CODE_USE_FOUNDRY=1 1 fail 20 pass
both gemini+mistral 20 pass
  • bun test src/utils/attribution.test.ts — 20/20 pass clean and under each leaked-env scenario above.

…er env

`getAttributionTexts` resolves the active provider and model through
`getAPIProvider` (→ `resolveActiveRouteIdFromEnv`) and
`getMainLoopModel`, both of which read process env. The suite's
`beforeEach` pinned `CLAUDE_CODE_USE_OPENAI=1` + `OPENAI_MODEL=gpt-5.5`
but left the competing route-selection flags untouched. Sibling test
files (gemini / mistral / foundry / codex shim, provider config) set
those flags and an incomplete restore there flips our resolved provider
under interleaved `bun test` ordering: the route becomes gemini /
mistral / foundry, the co-author name changes, and

  preserves includeCoAuthoredBy true as an explicit old-default opt-in

fails with a mismatched/empty commit trailer. The failure is
order-dependent, which is why it surfaced intermittently across
unrelated PR branches.

Capture and clear the routing env (`CLAUDE_CODE_USE_GEMINI` /
`_MISTRAL` / `_GITHUB` / `_BEDROCK` / `_VERTEX` / `_FOUNDRY`,
`NVIDIA_NIM`, `OPENAI_BASE_URL` / `OPENAI_API_BASE`,
`CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED`, and the alternate
`*_MODEL` vars) in `beforeEach`, restore them in `afterEach`. The route
now resolves deterministically to plain OpenAI + gpt-5.5 regardless of
run order.

Verified by reproducing the failure (`CLAUDE_CODE_USE_GEMINI=1`,
`CLAUDE_CODE_USE_MISTRAL=1`, `CLAUDE_CODE_USE_FOUNDRY=1` each made the
suite fail before the change) and confirming all 20 tests pass with
each of those env vars set after it.
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