Skip to content

feat(wizard-ci): read the e2e gateway key from POSTHOG_GATEWAY_TOKEN - #4192

Merged
johncwaters merged 1 commit into
mainfrom
johnw/e2e-gateway-key
Sep 24, 2026
Merged

johncwaters merged 1 commit into
mainfrom
johnw/e2e-gateway-key

Conversation

@johncwaters

Copy link
Copy Markdown
Contributor

Problem

Feedback wanted: ready to merge. Local-only change; the CI path (WIZARD_CI_GATEWAY_TOKEN_FILE) is unchanged.

Running wizard-ci --e2e locally needed a minted phe_ gateway token in a file: a browser login, a weekly mint quota, a 24h expiry, and the mint refuses programs it doesn't know yet (program_unknown for feature-flags). A project secret key (phs_ with the admin-granted llm_gateway:read scope) works against the gateway directly and bills its own team, while the run and its MCP actions still target the project you pick.

No token-issuing or mint code: the runner only forwards a key you already hold, and a key spends only its own team's gateway wallet, so this opens no new inference path.

Changes

  • services/wizard-ci/e2e.ts: reads POSTHOG_GATEWAY_TOKEN first (the name pr-evaluator already uses), then falls back to WIZARD_CI_GATEWAY_TOKEN_FILE, so a stale file entry in .env never wins. The harness only reads a file, so the key goes into a 0600 file in a mkdtemp directory. The variable is kept out of the child env, and the directory is removed after the run or on SIGINT/SIGTERM. Fails early with a clear message when neither is set.
  • .env.example: documents POSTHOG_GATEWAY_TOKEN, plus op run --env-file .env -- pnpm wizard-ci ... for keeping an op:// reference in .env instead of the key.

How did you test this code?

All on the team test project, feature-flags/next-js/15-app-router-saas --e2e, wizard b70460a8 with no local gateway allowlist:

  • WIZARD_CI_GATEWAY_TOKEN_FILE pointing at the service key: pass (all 12 feature-flag checks)
  • POSTHOG_GATEWAY_TOKEN via op run with an op:// reference: pass, temp directory removed
  • POSTHOG_GATEWAY_TOKEN via op run with WIZARD_CI_GATEWAY_TOKEN_FILE=/nonexistent/...: pass, which shows the env var takes precedence
  • SIGINT mid-run: temp directory removed, no stray processes
  • Neither set: exits 2 with the new message
  • tsc --noEmit clean

Local e2e runs needed a minted phe_ gateway token in a file, which meant a
browser login, a weekly mint quota and a 24h expiry. A project secret key
(phs_ with the llm_gateway:read scope) works against the gateway directly,
so it can live in .env or be injected with `op run`.

The runner prefers POSTHOG_GATEWAY_TOKEN, writes it to a 0600 file in a
temporary directory for the harness (which only reads
WIZARD_CI_GATEWAY_TOKEN_FILE), keeps the variable out of the child env, and
removes the directory after the run or on SIGINT/SIGTERM. CI still sets only
the file variable, so its path is unchanged.

Constraint: the wizard harness reads the gateway credential only from a file
Rejected: calling `op read` from the runner | CI has no op CLI, and `op run` needs no code
Directive: keep POSTHOG_GATEWAY_TOKEN ahead of the file variable so a stale .env file entry never wins
Confidence: high
Scope-risk: narrow
@johncwaters
johncwaters marked this pull request as ready for review September 24, 2026 20:55
@johncwaters
johncwaters requested a review from a team as a code owner September 24, 2026 20:55
Comment thread .env.example

# AI gateway key for model calls: a phs_ project secret key with the llm_gateway:read scope.
# With `op run --env-file .env -- pnpm wizard-ci ...` this can be an op:// reference instead of the key.
POSTHOG_GATEWAY_TOKEN=phs_...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
POSTHOG_GATEWAY_TOKEN=phs_...
POSTHOG_GATEWAY_TOKEN=op://...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's just defualt to the good path kek

@johncwaters
johncwaters merged commit 61ddc0d into main Sep 24, 2026
11 checks passed
@johncwaters
johncwaters deleted the johnw/e2e-gateway-key branch September 24, 2026 20:59
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.

2 participants