05-diff-protocol-switch-no-tests
evals/05-diff-protocol-switch-no-tests ↑ +14.3 pts with plugin 100%Results
✓ pass flags-missing-decode-tests
judge votes: PASS PASS PASS
# Brooks-Lint Review **Mode:** PR Review **Scope:** `client.go`, `resp/decode.go` (2 files, ~130 lines net diff) **Health Score:** 89/100 Solid protocol fix — the decoder logic itself is correct RESP2 and actually removes duplicated prefix-parsing knowledge that used to live in `client.go` — but it ships with zero tests and a connection-state gap that's worth closing first. --- ## Findings ### 🟡 Warning **Test Coverage — new decoder ships with no tests** Symptom: `resp/decode.go` introduces the entire RESP2 parsing surface (five `Kind`s, null bulk/array, three protocol limits, five distinct error branches, recursion) but the diff has no corresponding `_test.go` changes. Source: Feathers — *Working Effectively with Legacy Code*, Ch. 1 (untested code is legacy the moment it lands) Consequence: the edge cases most likely to break in production — negative/oversized lengths, truncated bulk bodies, malformed CRLF, `maxDepth` boundary, null array vs. null bulk — have no safety net. A future refactor (or an unusual server reply) could silently break framing with nothing to catch it. Remedy: add table-driven tests for `Decode` covering each `Kind`, the two null cases, the three `max*` boundaries (at limit, one over), and one malformed-input case per error branch in `decode`, `parseLen`, and `readLine`. **Change Propagation — connection is left mid-frame after a decode error** Symptom: `Do()` returns whatever error `resp.Decode` produces but never closes or marks `c.rd`/the connection unusable — including on errors that happen *after* partially consuming a value, e.g. `io.ReadFull` failing mid-bulk-string, or a protocol error thrown after an array header was already read off the wire. Source: Winters et al. — *Software Engineering at Google*, Ch. 21 (implicit contracts around shared state); the consequence is the same shape as Brooks — *Mythical Man-Month* Ch. 2 change-propagation risk, just at the byte-stream level instead of module level. Consequence: `bufio.Reader`'s position is left desynced. The next `Do()` call on the same `*Client` starts reading from the wrong offset in the stream and will misinterpret an unrelated reply — a failure in command A silently corrupts command B with no correlated error message. Remedy: on any error from `resp.Decode`, mark the `Client` (or underlying conn) broken so subsequent `Do()` calls fail fast or force a reconnect, instead of continuing to read from a desynced stream. ### 🟢 Suggestion **Cognitive Overload — `decode()` inlines all five type parsers in one switch** Symptom: the ~60-line `decode()` fully implements SimpleString/Error, Integer, BulkString, and Array parsing (each with its own error paths) in one function body. Source: McConnell — *Code Complete*, Ch. 7 (routine length); Ousterhout — *A Philosophy of Software Design*, Ch. 4 (deep modules) Consequence: minor today — each case is linear, single-purpose, and it's a dispatch-over-a-wire-format (not a missing-polymorphism smell), so this is closer to a style note than a real risk. But it will keep growing if RESP3 types are ever added, and each case is currently only testable by driving the whole function. Remedy: optionally extract `decodeBulkString(r, line)` and `decodeArray(r, line, depth)` as named helpers so each parser is independently unit-testable and `decode` stays a pure dispatch table. Not blocking. --- ## Summary The parsing logic itself is correct and a real improvement over the old single-line hack — merge-blocking issue is the total lack of tests for a hand-rolled binary protocol parser; add those first. The connection-desync-on-error gap is worth a follow-up (possibly out of scope for this PR if `Client` already has reconnect logic elsewhere you didn't paste — worth confirming before merge). The function-length note is optional polish, not a blocker.
✓ pass health-score-line ×0.5
matched Health Score\W*\d{1,3}\s*/\s*100
✓ pass no-critical-findings
judge votes: PASS FAIL PASS
# Brooks-Lint Review **Mode:** PR Review **Scope:** `client.go`, `resp/decode.go` (2 files, ~130 lines net diff) **Health Score:** 89/100 Solid protocol fix — the decoder logic itself is correct RESP2 and actually removes duplicated prefix-parsing knowledge that used to live in `client.go` — but it ships with zero tests and a connection-state gap that's worth closing first. --- ## Findings ### 🟡 Warning **Test Coverage — new decoder ships with no tests** Symptom: `resp/decode.go` introduces the entire RESP2 parsing surface (five `Kind`s, null bulk/array, three protocol limits, five distinct error branches, recursion) but the diff has no corresponding `_test.go` changes. Source: Feathers — *Working Effectively with Legacy Code*, Ch. 1 (untested code is legacy the moment it lands) Consequence: the edge cases most likely to break in production — negative/oversized lengths, truncated bulk bodies, malformed CRLF, `maxDepth` boundary, null array vs. null bulk — have no safety net. A future refactor (or an unusual server reply) could silently break framing with nothing to catch it. Remedy: add table-driven tests for `Decode` covering each `Kind`, the two null cases, the three `max*` boundaries (at limit, one over), and one malformed-input case per error branch in `decode`, `parseLen`, and `readLine`. **Change Propagation — connection is left mid-frame after a decode error** Symptom: `Do()` returns whatever error `resp.Decode` produces but never closes or marks `c.rd`/the connection unusable — including on errors that happen *after* partially consuming a value, e.g. `io.ReadFull` failing mid-bulk-string, or a protocol error thrown after an array header was already read off the wire. Source: Winters et al. — *Software Engineering at Google*, Ch. 21 (implicit contracts around shared state); the consequence is the same shape as Brooks — *Mythical Man-Month* Ch. 2 change-propagation risk, just at the byte-stream level instead of module level. Consequence: `bufio.Reader`'s position is left desynced. The next `Do()` call on the same `*Client` starts reading from the wrong offset in the stream and will misinterpret an unrelated reply — a failure in command A silently corrupts command B with no correlated error message. Remedy: on any error from `resp.Decode`, mark the `Client` (or underlying conn) broken so subsequent `Do()` calls fail fast or force a reconnect, instead of continuing to read from a desynced stream. ### 🟢 Suggestion **Cognitive Overload — `decode()` inlines all five type parsers in one switch** Symptom: the ~60-line `decode()` fully implements SimpleString/Error, Integer, BulkString, and Array parsing (each with its own error paths) in one function body. Source: McConnell — *Code Complete*, Ch. 7 (routine length); Ousterhout — *A Philosophy of Software Design*, Ch. 4 (deep modules) Consequence: minor today — each case is linear, single-purpose, and it's a dispatch-over-a-wire-format (not a missing-polymorphism smell), so this is closer to a style note than a real risk. But it will keep growing if RESP3 types are ever added, and each case is currently only testable by driving the whole function. Remedy: optionally extract `decodeBulkString(r, line)` and `decodeArray(r, line, depth)` as named helpers so each parser is independently unit-testable and `decode` stays a pure dispatch table. Not blocking. --- ## Summary The parsing logic itself is correct and a real improvement over the old single-line hack — merge-blocking issue is the total lack of tests for a hand-rolled binary protocol parser; add those first. The connection-desync-on-error gap is worth a follow-up (possibly out of scope for this PR if `Client` already has reconnect logic elsewhere you didn't paste — worth confirming before merge). The function-length note is optional polish, not a blocker.
✓ pass no-polymorphism-suggestion
judge votes: PASS PASS PASS
# Brooks-Lint Review **Mode:** PR Review **Scope:** `client.go`, `resp/decode.go` (2 files, ~130 lines net diff) **Health Score:** 89/100 Solid protocol fix — the decoder logic itself is correct RESP2 and actually removes duplicated prefix-parsing knowledge that used to live in `client.go` — but it ships with zero tests and a connection-state gap that's worth closing first. --- ## Findings ### 🟡 Warning **Test Coverage — new decoder ships with no tests** Symptom: `resp/decode.go` introduces the entire RESP2 parsing surface (five `Kind`s, null bulk/array, three protocol limits, five distinct error branches, recursion) but the diff has no corresponding `_test.go` changes. Source: Feathers — *Working Effectively with Legacy Code*, Ch. 1 (untested code is legacy the moment it lands) Consequence: the edge cases most likely to break in production — negative/oversized lengths, truncated bulk bodies, malformed CRLF, `maxDepth` boundary, null array vs. null bulk — have no safety net. A future refactor (or an unusual server reply) could silently break framing with nothing to catch it. Remedy: add table-driven tests for `Decode` covering each `Kind`, the two null cases, the three `max*` boundaries (at limit, one over), and one malformed-input case per error branch in `decode`, `parseLen`, and `readLine`. **Change Propagation — connection is left mid-frame after a decode error** Symptom: `Do()` returns whatever error `resp.Decode` produces but never closes or marks `c.rd`/the connection unusable — including on errors that happen *after* partially consuming a value, e.g. `io.ReadFull` failing mid-bulk-string, or a protocol error thrown after an array header was already read off the wire. Source: Winters et al. — *Software Engineering at Google*, Ch. 21 (implicit contracts around shared state); the consequence is the same shape as Brooks — *Mythical Man-Month* Ch. 2 change-propagation risk, just at the byte-stream level instead of module level. Consequence: `bufio.Reader`'s position is left desynced. The next `Do()` call on the same `*Client` starts reading from the wrong offset in the stream and will misinterpret an unrelated reply — a failure in command A silently corrupts command B with no correlated error message. Remedy: on any error from `resp.Decode`, mark the `Client` (or underlying conn) broken so subsequent `Do()` calls fail fast or force a reconnect, instead of continuing to read from a desynced stream. ### 🟢 Suggestion **Cognitive Overload — `decode()` inlines all five type parsers in one switch** Symptom: the ~60-line `decode()` fully implements SimpleString/Error, Integer, BulkString, and Array parsing (each with its own error paths) in one function body. Source: McConnell — *Code Complete*, Ch. 7 (routine length); Ousterhout — *A Philosophy of Software Design*, Ch. 4 (deep modules) Consequence: minor today — each case is linear, single-purpose, and it's a dispatch-over-a-wire-format (not a missing-polymorphism smell), so this is closer to a style note than a real risk. But it will keep growing if RESP3 types are ever added, and each case is currently only testable by driving the whole function. Remedy: optionally extract `decodeBulkString(r, line)` and `decodeArray(r, line, depth)` as named helpers so each parser is independently unit-testable and `decode` stays a pure dispatch table. Not blocking. --- ## Summary The parsing logic itself is correct and a real improvement over the old single-line hack — merge-blocking issue is the total lack of tests for a hand-rolled binary protocol parser; add those first. The connection-desync-on-error gap is worth a follow-up (possibly out of scope for this PR if `Client` already has reconnect logic elsewhere you didn't paste — worth confirming before merge). The function-length note is optional polish, not a blocker.
✓ pass skill-fired plugin-fired indicator
Skill called 1x (expected 1..∞)
✓ pass flags-missing-decode-tests
judge votes: PASS PASS PASS
I don't have the actual repo checked out here (the working directory is empty), so I reviewed this from the diff text alone — I can't run `go build`/`go vet`/tests to confirm compilation. With that caveat:
**The core logic looks correct and is a real fix, not just an addition.** The old `Do` didn't actually check the reply's leading byte — it just stripped the first character off *any* non-`-` line and mislabeled it `SimpleString`, so an integer reply (`:5\r\n`) would come back as `Value{Kind: SimpleString, Str: "5"}`. The new decoder fixes that by properly dispatching on the type byte. Null bulk (`$-1`) and null array (`*-1`) are handled correctly, negative integers work via `ParseInt`, and the depth/length caps (64 levels, 512MB bulk, 1M array elements) mirror real Redis server limits, which is a sensible defensive default for untrusted input.
Three things I'd want resolved before merging:
1. **`min(n, 64)` requires Go 1.21+.** Confirm `go.mod`'s `go` directive is at least 1.21, otherwise this won't compile.
2. **Unverified assumption**: `Kind(prefix)` in the `switch` relies on `resp.SimpleString/Error/Integer/BulkString/Array` being defined as the literal RESP bytes (`+ - : $ *`) in `resp/value.go`. You said that file is unchanged, so presumably fine — just worth a final glance since I couldn't read it here.
3. **No tests landed with a new protocol parser.** This is exactly the kind of code (untrusted network input, several edge cases) where table-driven tests pay for themselves — at minimum: empty bulk string, null bulk/array, nested arrays, malformed/oversized length header, a line longer than the buffer (`bufio.ErrBufferFull`), and an unknown type byte.
One non-blocking note: the 512MB-per-bulk-string cap has no aggregate limit across an array's elements, so a large array of near-max bulk strings could still drive big allocations — same tradeoff real Redis makes, so I wouldn't hold up the PR for it, just flagging it as a known accepted limit rather than an oversight.
Nothing here looks like a correctness bug — I'd call it mergeable once you confirm the Go version and ideally add basic tests for the new decoder.
✗ fail health-score-line ×0.5
pattern not found in last_message
✓ pass no-critical-findings
judge votes: PASS PASS PASS
I don't have the actual repo checked out here (the working directory is empty), so I reviewed this from the diff text alone — I can't run `go build`/`go vet`/tests to confirm compilation. With that caveat:
**The core logic looks correct and is a real fix, not just an addition.** The old `Do` didn't actually check the reply's leading byte — it just stripped the first character off *any* non-`-` line and mislabeled it `SimpleString`, so an integer reply (`:5\r\n`) would come back as `Value{Kind: SimpleString, Str: "5"}`. The new decoder fixes that by properly dispatching on the type byte. Null bulk (`$-1`) and null array (`*-1`) are handled correctly, negative integers work via `ParseInt`, and the depth/length caps (64 levels, 512MB bulk, 1M array elements) mirror real Redis server limits, which is a sensible defensive default for untrusted input.
Three things I'd want resolved before merging:
1. **`min(n, 64)` requires Go 1.21+.** Confirm `go.mod`'s `go` directive is at least 1.21, otherwise this won't compile.
2. **Unverified assumption**: `Kind(prefix)` in the `switch` relies on `resp.SimpleString/Error/Integer/BulkString/Array` being defined as the literal RESP bytes (`+ - : $ *`) in `resp/value.go`. You said that file is unchanged, so presumably fine — just worth a final glance since I couldn't read it here.
3. **No tests landed with a new protocol parser.** This is exactly the kind of code (untrusted network input, several edge cases) where table-driven tests pay for themselves — at minimum: empty bulk string, null bulk/array, nested arrays, malformed/oversized length header, a line longer than the buffer (`bufio.ErrBufferFull`), and an unknown type byte.
One non-blocking note: the 512MB-per-bulk-string cap has no aggregate limit across an array's elements, so a large array of near-max bulk strings could still drive big allocations — same tradeoff real Redis makes, so I wouldn't hold up the PR for it, just flagging it as a known accepted limit rather than an oversight.
Nothing here looks like a correctness bug — I'd call it mergeable once you confirm the Go version and ideally add basic tests for the new decoder.
✓ pass no-polymorphism-suggestion
judge votes: PASS PASS PASS
I don't have the actual repo checked out here (the working directory is empty), so I reviewed this from the diff text alone — I can't run `go build`/`go vet`/tests to confirm compilation. With that caveat:
**The core logic looks correct and is a real fix, not just an addition.** The old `Do` didn't actually check the reply's leading byte — it just stripped the first character off *any* non-`-` line and mislabeled it `SimpleString`, so an integer reply (`:5\r\n`) would come back as `Value{Kind: SimpleString, Str: "5"}`. The new decoder fixes that by properly dispatching on the type byte. Null bulk (`$-1`) and null array (`*-1`) are handled correctly, negative integers work via `ParseInt`, and the depth/length caps (64 levels, 512MB bulk, 1M array elements) mirror real Redis server limits, which is a sensible defensive default for untrusted input.
Three things I'd want resolved before merging:
1. **`min(n, 64)` requires Go 1.21+.** Confirm `go.mod`'s `go` directive is at least 1.21, otherwise this won't compile.
2. **Unverified assumption**: `Kind(prefix)` in the `switch` relies on `resp.SimpleString/Error/Integer/BulkString/Array` being defined as the literal RESP bytes (`+ - : $ *`) in `resp/value.go`. You said that file is unchanged, so presumably fine — just worth a final glance since I couldn't read it here.
3. **No tests landed with a new protocol parser.** This is exactly the kind of code (untrusted network input, several edge cases) where table-driven tests pay for themselves — at minimum: empty bulk string, null bulk/array, nested arrays, malformed/oversized length header, a line longer than the buffer (`bufio.ErrBufferFull`), and an unknown type byte.
One non-blocking note: the 512MB-per-bulk-string cap has no aggregate limit across an array's elements, so a large array of near-max bulk strings could still drive big allocations — same tradeoff real Redis makes, so I wouldn't hold up the PR for it, just flagging it as a known accepted limit rather than an oversight.
Nothing here looks like a correctness bug — I'd call it mergeable once you confirm the Go version and ideally add basic tests for the new decoder.
Prompt
Here's my PR for our little Go Redis client: it adds a proper RESP2 decoder and switches Client.Do over to it (before, Do only understood single-line replies). Value and the Kind constants already live in resp/value.go, which is unchanged. Ready to merge?
diff --git a/client.go b/client.go
index 2af07d3..d80edcc 100644
--- a/client.go
+++ b/client.go
@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"net"
- "strings"
"time"
"example.com/redisx/resp"
@@ -38,14 +37,14 @@ func (c *Client) Do(ctx context.Context, args ...string) (resp.Value, error) {
if err := c.writeCommand(args); err != nil {
return resp.Value{}, err
}
- line, err := c.rd.ReadString('\n')
+ v, err := resp.Decode(c.rd)
if err != nil {
return resp.Value{}, err
}
- if strings.HasPrefix(line, "-") {
- return resp.Value{}, errors.New(strings.TrimSpace(line[1:]))
+ if v.Kind == resp.Error {
+ return resp.Value{}, errors.New(v.Str)
}
- return resp.Value{Kind: resp.SimpleString, Str: strings.TrimSpace(line[1:])}, nil
+ return v, nil
}
func (c *Client) writeCommand(args []string) error {
diff --git a/resp/decode.go b/resp/decode.go
new file mode 100644
index 0000000..41f7147
--- /dev/null
+++ b/resp/decode.go
@@ -0,0 +1,112 @@
+package resp
+
+import (
+ "bufio"
+ "errors"
+ "fmt"
+ "io"
+ "strconv"
+)
+
+// ErrProtocol is wrapped by every error caused by malformed input.
+var ErrProtocol = errors.New("resp: protocol error")
+
+// Limits mirror Redis's own defaults, so a corrupt stream fails fast instead of
+// driving huge allocations or unbounded recursion.
+const (
+ maxBulkLen = 512 << 20
+ maxArrayLen = 1 << 20
+ maxDepth = 64
+)
+
+// Decode reads exactly one RESP2 value from r.
+func Decode(r *bufio.Reader) (Value, error) {
+ return decode(r, 0)
+}
+
+func decode(r *bufio.Reader, depth int) (Value, error) {
+ prefix, err := r.ReadByte()
+ if err != nil {
+ return Value{}, err
+ }
+ line, err := readLine(r)
+ if err != nil {
+ return Value{}, err
+ }
+
+ switch Kind(prefix) {
+ case SimpleString, Error:
+ return Value{Kind: Kind(prefix), Str: line}, nil
+
+ case Integer:
+ n, err := strconv.ParseInt(line, 10, 64)
+ if err != nil {
+ return Value{}, fmt.Errorf("%w: bad integer %q", ErrProtocol, line)
+ }
+ return Value{Kind: Integer, Int: n}, nil
+
+ case BulkString:
+ n, err := parseLen(line, maxBulkLen)
+ if err != nil {
+ return Value{}, err
+ }
+ if n == -1 {
+ return Value{Kind: BulkString, Null: true}, nil
+ }
+ buf := make([]byte, n+2)
+ if _, err := io.ReadFull(r, buf); err != nil {
+ return Value{}, err
+ }
+ if buf[n] != '\r' || buf[n+1] != '\n' {
+ return Value{}, fmt.Errorf("%w: bulk string not CRLF-terminated", ErrProtocol)
+ }
+ return Value{Kind: BulkString, Str: string(buf[:n])}, nil
+
+ case Array:
+ n, err := parseLen(line, maxArrayLen)
+ if err != nil {
+ return Value{}, err
+ }
+ if n == -1 {
+ return Value{Kind: Array, Null: true}, nil
+ }
+ if depth == maxDepth {
+ return Value{}, fmt.Errorf("%w: arrays nested deeper than %d", ErrProtocol, maxDepth)
+ }
+ // n is untrusted: cap the up-front allocation and let append grow the rest.
+ items := make([]Value, 0, min(n, 64))
+ for i := 0; i < n; i++ {
+ v, err := decode(r, depth+1)
+ if err != nil {
+ return Value{}, err
+ }
+ items = append(items, v)
+ }
+ return Value{Kind: Array, Array: items}, nil
+
+ default:
+ return Value{}, fmt.Errorf("%w: unknown type byte %q", ErrProtocol, prefix)
+ }
+}
+
+// parseLen parses a bulk-string or array length header: -1 (null) or 0..limit.
+func parseLen(line string, limit int) (int, error) {
+ n, err := strconv.Atoi(line)
+ if err != nil || n < -1 || n > limit {
+ return 0, fmt.Errorf("%w: bad length %q", ErrProtocol, line)
+ }
+ return n, nil
+}
+
+// readLine reads a CRLF-terminated header line. ReadSlice bounds the line by the
+// reader's buffer size, so overlong input fails with bufio.ErrBufferFull.
+func readLine(r *bufio.Reader) (string, error) {
+ line, err := r.ReadSlice('\n')
+ if err != nil {
+ return "", err
+ }
+ if len(line) < 2 || line[len(line)-2] != '\r' {
+ return "", fmt.Errorf("%w: line not CRLF-terminated", ErrProtocol)
+ }
+ return string(line[:len(line)-2]), nil
+}
Graders — what "good" means for this case
Context: the PR adds a new exported function resp.Decode in a new file resp/decode.go and switches Client.Do to use it. The diff contains no test file and no test changes.
PASS only if the answer points out that this new decoding behaviour ships without tests in the PR — e.g. "no tests for Decode", or "add a decode_test.go covering null bulk strings / nested arrays / malformed input" — framed as a gap in this change.
FAIL if tests are not mentioned, or are mentioned only in a generic line not tied to Decode / the decoder (e.g. "make sure CI passes").
"last_message""Health Score\\W*\\d{1,3}\\s*/\\s*100""i""contains"PASS only if both hold:
- No issue is labelled Critical, 🔴, High severity, Blocker, or "must fix before merge" — with one exception: asking for tests for the new
Decodefunction before merging is acceptable at any severity. An empty Critical section, or a statement that there are no critical issues, is fine. - If the answer gives a numeric score out of 100 (e.g. a Health Score), it is 80 or higher.
FAIL if either is violated.
Context: the new resp/decode.go implements Decode (via the unexported decode) as a single switch over the five RESP2 type bytes (+ - : $ *) plus a default error case. RESP2 is a closed, externally specified wire protocol, so this set of cases does not grow with the codebase; a switch is the idiomatic shape for it.
FAIL if the answer recommends, or flags as a design problem, any of:
- Replacing the switch with polymorphism — a
Decoder/Parserinterface with one implementation per type byte, or per-type structs with methods. - A handler / decoder registry,
map[byte]func(...), strategy table, or plugin mechanism for type bytes. - Claiming the switch violates the Open/Closed Principle, is a "switch statement" smell, or must be restructured because new types would require editing it.
Allowed — do not fail for these: extracting a case body into a helper (e.g. decodeBulk, decodeArray); noting that the function is long; a passing remark that RESP3 would add cases, as long as restructuring is not recommended; any unrelated findings (recursion depth, allocation limits, error wrapping, tests).
PASS if none of 1–3 occurs, including when the answer explicitly says the switch is appropriate.
"Skill""brooks-review"