test: consolidate resp write-error cases, honor lock preconditions

Review fixes (Task 8, second pass):

- Fold TestRESPClient_AttemptPipelineLocked_WriteError and
  TestRESPClient_HandshakeLocked_WriteError into one table,
  TestRESPClient_WriteError_BrokenPipe — both exercised the identical
  broken-pipe shape on a pre-set fakeConn.
- Take c.mu.Lock()/Unlock() around every direct call to an internal
  "*Locked" method (ensureConnLocked, attemptPipelineLocked x2,
  handshakeLocked) per each method's own "callers must hold c.mu"
  precondition, even though every such test is single-goroutine.
- TestUnifiedCostMicros case 2: replace a want that called costMicros
  (the function under indirect test) with the literal 11_250_000, hand-
  derived from builtinPricing["gpt-5"] (InputPerM 1.25, OutputPerM 10)
  at 1M prompt + 1M completion tokens.
- TestRedisStore_Get_DownServer_ReturnsError: assert err.Error() contains
  "redisStore: get", not just that an error occurred.

Report corrected: the earlier claim that all new tests were table-driven
was inaccurate (actual split 8/16 at review time); documented as a
deliberate choice, not an oversight — six single-scenario tests stay flat
since a one-row table adds structure without adding coverage.

Gate: go test ./... -count=1 (pass), -race (pass), gofmt (clean), vet
(clean).
This commit is contained in:
2026-08-20 21:42:40 +01:00
parent aee3908bc4
commit 7621733c88
3 changed files with 57 additions and 24 deletions
+3 -1
View File
@@ -1640,7 +1640,9 @@ func TestUnifiedCostMicros(t *testing.T) {
canonical: "unknown-provider/gpt-5",
bare: "gpt-5",
overrides: nil,
want: costMicros("gpt-5", u, nil),
// builtinPricing["gpt-5"] = {InputPerM: 1.25, OutputPerM: 10}:
// (1M prompt * $1.25/M) + (1M completion * $10/M), in micros.
want: 11_250_000,
},
{
name: "neither id priced returns zero",