Files
coder/coderd
Michael Suchacz 9ede7ceed6 refactor(coderd/x/chatd): extract the recording boundary parser and table its tests (#30953)
`stopAndStoreRecording` parsed the recording response's Content-Type
inline and logged through a local `warn` closure that copied three
recording fields into every call. This PR moves the parse into
`recordingBoundary`, replaces the closure with `p.logger.With(...)`, and
replaces the two PostgreSQL-backed tests
`TestStopAndStoreRecording_MalformedContentType` and `_MissingBoundary`
with a table test, `TestRecordingBoundary`. The layer above extracts the
multipart parts loop the same way.

**Why it is safe**

- Warning messages and fields are unchanged: `With` puts its fields
before the per-call fields, as the closure did. One log line changes:
the debug line "skipping unknown part content type" now also carries the
recording, parent chat and workspace IDs.
- The caller still checks the header before the workspace lookup and
returns an empty result on failure.
- The deleted tests checked only that the result was empty. With an
empty body, that result is the same whether or not the parse-error or
missing-boundary branch runs, so both tests passed when I disabled those
branches with `go test -overlay`. `TestRecordingBoundary` asserts the
boundary, the ok flag and the exact warning, and fails on both mutants.

**Review focus**

`if !ok { return result }` in `stopAndStoreRecording`. No test pins it.
Falling through on an empty body returns the same empty result; it
differs only in that it also runs the workspace lookup
(`GetWorkspaceByID`) and logs a second warning, `error reading next
multipart part`. So the line needs a reading check.

**Validation**

- `go test ./coderd/x/chatd/ -run
'TestStopAndStoreRecording|TestWaitAgent|TestRecordingBoundary' -count=1
-p 4 -parallel 4`: ok
- `go vet ./coderd/x/chatd/`: ok
- `golangci-lint run --fix=false ./coderd/x/chatd/`: 0 issues
- pre-commit hook: passed

**Stack**

The stack moves the recording response parsing out of
`stopAndStoreRecording` into two functions with table tests, and drops
seven PostgreSQL-backed parse tests.

1. #30953 extract the recording boundary parser and table its tests
(this PR)
2. #30954 extract the recording multipart parser and table its tests

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-27 20:51:11 +00:00
..