Skip to content

feat(scripts/aigateway-mock): add fixture-backed upstream - #29845

Closed
johnstcn wants to merge 1 commit into
mainfrom
feat/ai-gateway-mock-upstream
Closed

johnstcn wants to merge 1 commit into
mainfrom
feat/ai-gateway-mock-upstream

Conversation

@johnstcn

Copy link
Copy Markdown
Member

Add a standalone local upstream for smoke-testing AI Gateway without provider credentials or inference costs. Run it with go run ./scripts/aigateway-mock; it serves embedded fixtures for Chat Completions, Responses, and Messages in streaming and non-streaming modes.

Record selected headers as JSON, preserving duplicate values and excluding prompts, credentials, and cookies by default. Include repeatable --header options, local setup instructions, and happy-path tests covering all three actor identity headers. This tool is independent of the actor-header stack in #29812.

Verified with race tests and live HTTP requests for all six API/mode combinations, then used as the upstream for 42 successful requests through an isolated Coder dev instance. That run covered default and remapped headers, two authenticated users, spoofed values, and forwarding disabled.

Generated with AI assistance on behalf of @johnstcn.

@johnstcn

Copy link
Copy Markdown
Member Author

Local verification evidence:

$ go test -race -count=1 ./scripts/aigateway-mock
ok github.com/coder/coder/v2/scripts/aigateway-mock 1.012s

$ golangci-lint run --concurrency=2 ./scripts/aigateway-mock
0 issues.

The standalone executable also served all six API/mode combinations over HTTP. With the actor-header stack at 868a5f2dca, an isolated development instance successfully sent 42 gateway requests through this mock. One recorded request from the disposable test admin was:

{"path":"/v1/chat/completions","stream":false,"headers":{"X-Ai-Bridge-Actor-Id":["d9cb9279-5e15-4960-a8ba-4dbe00632a38"],"X-Ai-Bridge-Actor-Metadata-Email":["admin@coder.com"],"X-Ai-Bridge-Actor-Metadata-Username":["admin"],"X-Smoke-Trace":["defaults-admin-completions-False"]}}

The recorded identity replaced forged client values, contained no credentials, and preserved the trace header. Both mock providers were also verified in the dashboard. Service-account coverage in that deployment was unavailable because its license lacked that entitlement.

@johnstcn
johnstcn marked this pull request as ready for review September 24, 2026 11:50
@mtojek

mtojek commented Oct 26, 2026

Copy link
Copy Markdown
Member

stale

@mtojek mtojek closed this Oct 26, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants