Files
coder/agent
Andrew Aquino d5d15fcbee test: assert client_session_id extra headers at the SDK layer (#32780)
Fixes the `TestAgent_APIClientSessionID` flake
([CLIENT-1118](https://linear.app/codercom/issue/CLIENT-1118)) by
replacing the test with a deterministic one at the layer it was
protecting.

`loggermw.Logger` writes the request log after `next.ServeHTTP` returns,
so `conn.ListeningPorts` could get its response before the entry
carrying `client_session_id` reached the sink. The test covered two
things:

- **Baggage header to `client_session_id` on the request log.** Already
covered deterministically by `Test_Middleware_Agent` in
`coderd/tracing`, using the agent's middleware order.
- **`SetExtraHeaders` reaching per-request agent API calls.** Each API
request builds its own HTTP client, so the extra headers are how the ID
reaches the agent. This moves to `workspacesdk` as
`TestAgentConnAPIRequestsSendExtraHeaders`: a fake agent handler records
the `baggage` header before it responds, so the value is available when
`ListeningPorts` returns. It fails if the extra-header copy in
`apiRequestWithOptions` is removed.

`TestAgent_APIClientSessionID` and `agent/api_test.go` are removed.

<details>
<summary>Decision log</summary>

First revision wrapped the sink check in `testutil.Eventually`. Review
asked for a deterministic test instead of a retry loop. Options
considered:

- A (chosen): split by layer, as above.
- B: keep the agent test and wait on a sink channel. No polling, but
still waits on an event that happens after the response.
- C: stop the agent API server with `Shutdown` so `Close` waits for
handlers. A production change only for a test.
- D: assert inside the request through a test-only hook in the agent
router.

Running the SDK fake handler through `tracing.Middleware` was also
considered and skipped: the test writes the header itself, so parsing it
would mostly test the test's own input and duplicate `coderd/tracing`
coverage.

Verification: new test red with the header copy removed and green with
it; `go test -race ./codersdk/workspacesdk -run
'^TestAgentConnAPIRequestsSendExtraHeaders$' -count=20`; `make
pre-commit`.
</details>

---
<sub>Generated with Coder Agents.</sub>
2026-12-01 09:27:30 -08:00
..
…