fix(ai): gate live test credentials behind an explicit opt-in - #2168
Draft
kevinjosethomas wants to merge 1 commit into
Draft
fix(ai): gate live test credentials behind an explicit opt-in#2168kevinjosethomas wants to merge 1 commit into
kevinjosethomas wants to merge 1 commit into
Conversation
The packages/ai test OAuth helper read ~/.pi/agent/auth.json, refreshed expired OAuth entries against the real provider, and wrote the refreshed tokens back, at import time in every live test module. It now returns undefined without touching the filesystem or network unless PI_LIVE_TESTS=1 is set and PI_TEST_AUTH_FILE names a dedicated test credential file; the real stores under ~/.prime/agent and ~/.pi/agent are refused. test.sh moves both stores aside and clears the opt-in. Linear: ENG-5347
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: ENG-5347 — https://linear.app/primeintellect/issue/ENG-5347
Context
packages/ai/test/oauth.ts(resolveApiKey) read the developer's legacy credential store~/.pi/agent/auth.json, refreshed expired OAuth entries against the real provider token endpoint, and wrote the refreshed tokens back. Thirteen test modules call it at module top level, so a plainvitest --runinpackages/aitouched real credentials before anyskipIfgate, with no opt-in.test.shonly moved~/.prime/agent/auth.jsonaside, not the.pifile the helper used.Root cause: the helper hard-coded the real store path and had no gate. Developer workflow only; the shipped runtime does not import this helper.
Changes
packages/ai/test/oauth.ts:resolveApiKeyreturnsundefinedwithout touching the filesystem or network unlessPI_LIVE_TESTS=1. With the opt-in it reads only the file named byPI_TEST_AUTH_FILE(same JSON shape asauth.json) and writes refreshed tokens back to that file only. PointingPI_TEST_AUTH_FILEat~/.prime/agent/auth.jsonor~/.pi/agent/auth.jsonthrows.packages/ai/test/oauth-test-helper.test.ts: unit test withHOMEset to a temp dir, sentinel stores at both real paths,fetchstubbed andfsspied. Asserts no reads, no network, no writes without the opt-in (or with the opt-in but no test file); reads only the test file and writes only the test file with the opt-in; refuses the real stores.test.sh: moves both~/.prime/agent/auth.jsonand~/.pi/agent/auth.jsonaside (and restores both), and unsetsPI_LIVE_TESTS/PI_TEST_AUTH_FILE.packages/ai/README.md; notes inpackages/coding-agent/docs/development.mdandCONTRIBUTING.md.packages/ai/.changes/eng-5347-test-credential-isolation.md.No model-facing surface changes.
Validation
Local (worktree):
npm run checkclean.test/oauth-test-helper.test.ts5/5 pass.anthropic-tool-name-normalization,anthropic-eager-tool-input-e2e,anthropic-oauth,openai-codex-oauth,github-copilot-oauthrun: 6 passed, 32 skipped.Prime sandbox (
node:24-bookworm, usertester, freshHOMEper run, synthetic sentinel stores at both~/.pi/agent/auth.jsonand~/.prime/agent/auth.json,fetchstubbed, probe test recording behaviour):427ea4c72, no env):resolveApiKey("anthropic")returnedREFRESHED-ACCESS-5347, POSTedrefresh_token=SENTINEL-LEGACY-PI-REFRESH-5347tohttps://platform.claude.com/v1/oauth/token, rewrote~/.pi/agent/auth.jsonwith the refreshed tokens.undefined, zero outbound calls, both stores byte-identical.PI_LIVE_TESTS=1 PI_TEST_AUTH_FILE=$HOME/test-auth.json): refresh POST carried only the test file'sSENTINEL-TEST-FILE-REFRESH-5347; refreshed tokens written to the test file (0600); both real stores untouched.PI_TEST_AUTH_FILE=$HOME/.pi/agent/auth.json): throws "must point at a dedicated test credential file", no reads, no network, no writes.resolveApiKeycaller modules skip (3 passed / 311 skipped, the passes are non-credential cases); stores unchanged afterwards. Helper unit test +anthropic-oauth,openai-codex-oauth,github-copilot-oauth,mcp-oauth: 24/24 pass.test.shwithnpmreplaced by a reporting stub andPI_LIVE_TESTS=1 PI_TEST_AUTH_FILE=/xin the caller env: main leaves~/.pi/agent/auth.jsonpresent and the opt-in set; branch moves both stores aside, unsets both vars, and restores both files afterwards.Live provider suites were not run.
Note
Gate live test credentials behind
PI_LIVE_TESTS=1andPI_TEST_AUTH_FILEopt-inresolveApiKeyin oauth.ts returnsundefinedwithout filesystem or network access unless live tests are explicitly enabled with a dedicated credential file~/.prime/agent/auth.jsonor~/.pi/agent/auth.jsonstores; refreshed OAuth tokens persist to the configured test file with0600permissionsPI_LIVE_TESTSandPI_TEST_AUTH_FILEbefore running the suiteMacroscope summarized 1cc2247.