Skip to content

refactor(coderd/x/chatd/chattest): drop write-only fake state and share the shape check - #30950

Draft
ibetitsmike wants to merge 3 commits into
mike/chattest-fake-shape-error-testsfrom
mike/chattest-fake-write-only-state
Draft

ibetitsmike wants to merge 3 commits into
mike/chattest-fake-shape-error-testsfrom
mike/chattest-fake-write-only-state

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

The OpenAI and Anthropic fakes stored each request in a request field under a mutex that nothing read, and kept the httptest.Server in a field that only their constructors used. This PR deletes both fields, the mutex and its lock blocks. It also merges the three copies of the response-shape switch into one responseShapeError helper, and the two copies of the OpenAI request decode into decodeOpenAIRequest.

Why it is safe

  • Nothing read request, so dropping it and its mutex changes no behavior.
  • responseShapeError returns the same four strings, byte for byte, in the same order. Each writer still checks resp.Error first, writes the same plain-text 500 with http.Error, and keeps its own serializers. The layer below pins the "both" and "empty" errors, and the existing mismatch tests pin the other two: removing any case from the helper fails one of them.
  • decodeOpenAIRequest returns the read or decode error unwrapped, so the 400 body is unchanged, and handleResponses still runs ValidateResponsesAPIInput before the handler. It sets RawBody after decoding, as both copies did, so the field comment no longer claims it is set before.

Review focus

The writers now use switch msg := responseShapeError(...); { case msg != "": ... }, which leaves the streaming and non-streaming cases as they were.

Validation

  • go test ./coderd/x/chatd/chattest/ -count=1: ok before and after
  • go test -race ./coderd/x/chatd/chattest/ -count=1: ok
  • go test ./coderd/x/chatd/ -count=1 -p 4 -parallel 4: ok before and after
  • go vet ./coderd/x/chatd/chattest/: ok
  • golangci-lint run --fix=false ./coderd/x/chatd/chattest/: 0 issues
  • pre-commit hook: passed

Stack

The stack makes the chattest fake tests fail on wrong output, then drops the fakes' write-only state and shares their response-shape check.

  1. test(coderd/x/chatd/chattest): table the OpenAI fake positive tests and fail on error streams #30948 table the OpenAI fake positive tests and fail on error streams
  2. test(coderd/x/chatd/chattest): pin the fake response-shape errors #30949 pin the fake response-shape errors
  3. refactor(coderd/x/chatd/chattest): drop write-only fake state and share the shape check #30950 drop write-only fake state and share the shape check (this PR)

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T17:25:46.546191Z 3c092df Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 9ba797eb2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, posted this comment for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 3c092df197

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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