fix(redis): validate CLIENT subcommand arity + distinguish string/bulk in test stub#608
fix(redis): validate CLIENT subcommand arity + distinguish string/bulk in test stub#608
Conversation
…k in test stub Addresses coderabbit review on f3a1903. MAJOR: CLIENT subcommand arity (adapter/redis_compat_commands.go) `argsLen` only guarantees CLIENT has one subcommand, so malformed requests silently succeeded: CLIENT SETNAME (missing name) -> OK, no mutation CLIENT GETNAME extra (extra operand) -> name as if no operand CLIENT ID junk -> ID returned CLIENT INFO extra -> INFO returned Each subcommand now validates its exact arg count via a shared checkClientArity helper, returning `ERR wrong number of arguments for 'client|<sub>' command` on mismatch. Each case was also extracted into its own method so the switch body stays under the cyclomatic budget. MINOR: distinguish string from bulk in helloRecordingConn test stub (adapter/redis_hello_test.go) WriteString was recorded as kind="bulk", which meant a future regression swapping WriteBulkString for WriteString in the HELLO reply path would not fail any test. Now recorded as kind="string"; no existing assertions broke since all HELLO key/value writes use WriteBulk / WriteBulkString. Regression tests added: CLIENT SETNAME / GETNAME / ID / INFO arity checks (+4 tests). go test ./adapter -race -run TestClient_|TestHello_ passes; golangci-lint clean.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 32 minutes and 17 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Tightens Redis adapter compatibility by enforcing correct CLIENT subcommand argument counts and improving test stubs to better detect RESP wire-shape regressions.
Changes:
- Add exact-arity validation for
CLIENT SETNAME/GETNAME/ID/INFOvia a shared helper and extract handlers to reduce complexity in the main switch. - Update
helloRecordingConnto recordWriteStringas a distinct kind from bulk strings. - Add regression tests covering wrong-arity
CLIENTsubcommand calls.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
adapter/redis_compat_commands.go |
Introduces checkClientArity and refactors CLIENT subcommand handling to reject malformed arities. |
adapter/redis_hello_test.go |
Improves HELLO reply recording fidelity and adds arity regression tests for CLIENT subcommands. |
| case "SETINFO": | ||
| conn.WriteString("OK") | ||
| case "SETNAME": |
There was a problem hiding this comment.
CLIENT SETINFO still returns OK for any arity (including missing operands). This leaves one CLIENT subcommand with the same silent-success behavior this PR is trying to eliminate and diverges from Redis’ wrong-arity behavior for client|setinfo. Consider validating SETINFO’s expected argument count (or at least rejecting obviously wrong arity) using checkClientArity for consistency.
| if checkClientArity(conn, cmd, "SETNAME", clientSetNameMinArgs) { | ||
| return | ||
| } |
There was a problem hiding this comment.
checkClientArity enforces an exact argument count, but the constant name clientSetNameMinArgs suggests a minimum and can be misread/reused incorrectly later. Rename it to reflect exact arity (e.g., clientSetNameArgCount) or introduce a dedicated exact-arity constant to match the semantics here.
| r.client(conn, redcon.Command{Args: [][]byte{ | ||
| []byte("CLIENT"), []byte("SETNAME"), | ||
| }}) |
There was a problem hiding this comment.
These tests hardcode []byte("CLIENT") even though this file already uses the shared cmdClient constant elsewhere. Using []byte(cmdClient) keeps command spelling consistent and avoids drift/typos if the command constants change.
Copilot review on PR #608: - CLIENT SETINFO still returned OK for any arity including missing operands. That was the last CLIENT subcommand keeping the silent- success behaviour this PR was supposed to eliminate, and it diverged from the real Redis wrong-arity reply for client|setinfo. Now routed through checkClientArity with clientSetInfoArgCount=4 (CLIENT + SETINFO + attr + value), mirroring SETNAME. - Rename clientSetNameMinArgs to clientSetNameArgCount. The helper compares len(cmd.Args) == want, so the "Min" suffix was misleading and invited a future refactor that swaps the helper for a >= check and silently re-introduces the wrong-arity bug. - Replace hardcoded []byte("CLIENT") in the new arity tests with []byte(cmdClient) to stay consistent with the rest of the file and keep the command name in one place. New TestClient_SetInfo_RejectsWrongArity pins all four arity shapes (2, 3, 4, 5 args) so the SETINFO regression cannot be reintroduced.
|
Addressed Copilot review (all 3 comments) in 7d283f6: CLIENT SETINFO arity enforcement. SETINFO was still returning OK for any arity (including missing operands), the last remaining silent-success CLIENT subcommand — exactly what this PR is supposed to eliminate. Now routed through checkClientArity with clientSetInfoArgCount = 4 (CLIENT + SETINFO + attr + value), mirroring SETNAME. New TestClient_SetInfo_RejectsWrongArity pins all four arity shapes (2 / 3 / 4 / 5 args). Constant name clarity. Renamed clientSetNameMinArgs to clientSetNameArgCount. The helper compares len(cmd.Args) == want, so the "Min" suffix misrepresented the semantics and invited a future refactor that could swap the helper for a >= check and silently re-introduce the wrong-arity bug. Added clientSetInfoArgCount as a separate constant for the same reason. Test consistency. Replaced hardcoded []byte("CLIENT") in the arity tests with []byte(cmdClient) so the command name stays in one place. /gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Addresses coderabbit review on f3a1903.
MAJOR: CLIENT subcommand arity (adapter/redis_compat_commands.go)
argsLenonly guarantees CLIENT has one subcommand, so malformed requests silently succeeded:CLIENT SETNAME (missing name) -> OK, no mutation
CLIENT GETNAME extra (extra operand) -> name as if no operand
CLIENT ID junk -> ID returned
CLIENT INFO extra -> INFO returned
Each subcommand now validates its exact arg count via a shared checkClientArity helper, returning
ERR wrong number of arguments for 'client|<sub>' commandon mismatch. Each case was also extracted into its own method so the switch body stays under the cyclomatic budget.MINOR: distinguish string from bulk in helloRecordingConn test stub (adapter/redis_hello_test.go)
WriteString was recorded as kind="bulk", which meant a future regression swapping WriteBulkString for WriteString in the HELLO reply path would not fail any test. Now recorded as kind="string"; no existing assertions broke since all HELLO key/value writes use WriteBulk / WriteBulkString.
Regression tests added: CLIENT SETNAME / GETNAME / ID / INFO arity checks (+4 tests). go test ./adapter -race -run TestClient_|TestHello_ passes; golangci-lint clean.