SANDBOX-1809: test- add handler unit tests for sandbox agent - #9
Conversation
- Cover auth enforcement: missing header, wrong scheme, wrong token - Cover assign state machine: unassigned→assigned, 409 on repeat - Cover health endpoint: 200 alive, 503 dead - Integration test for warm-pool flow (assign then exec) SANDBOX-1809 Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Feny Mehta <fbm3307@gmail.com>
|
@coderabbitai help |
|
@coderabbitai review |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
Status, support, documentation and community
|
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds ChangesSandbox Handler HTTP Endpoint Tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/sandbox/handler_test.go`:
- Around line 26-27: Replace all calls to httptest.NewRequest with
httptest.NewRequestWithContext throughout the test file to satisfy the
golangci-lint noctx rule. For each instance of httptest.NewRequest in the file
(including at lines 26, 43, 62, 80, 97, 112, 129, 147, 165, 185, 203, 223, 239,
256, 262, 276, 293, 312, 318, 337, and 343), change the function call to
httptest.NewRequestWithContext and add a context.Background() as the first
parameter before the existing parameters (http.MethodGet, URL path, and body).
This ensures all request constructions pass the required context parameter and
comply with the enforced linting rules.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 2ae92b8f-565c-440b-bde4-63c6ff5bcd7f
📒 Files selected for processing (1)
pkg/sandbox/handler_test.go
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
codeready-toolchain/mcp-common(manual)codeready-toolchain/mcp-server-devsandbox(manual)codeready-toolchain/api(manual)codeready-toolchain/toolchain-common(manual)codeready-toolchain/host-operator(manual)codeready-toolchain/toolchain-e2e(manual)
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**
⚙️ CodeRabbit configuration file
-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.
Files:
pkg/sandbox/handler_test.go
🧬 Code graph analysis (1)
pkg/sandbox/handler_test.go (3)
pkg/sandbox/handler.go (10)
NewAgentState(25-30)IsAssigned(33-37)GetToken(40-44)Error(63-63)Handler(66-69)NewHandler(72-74)ErrorResponse(77-79)HandleHealth(89-98)HandleExec(102-147)HandleAssign(151-168)pkg/agent/types.go (3)
ExecRequest(5-8)ExecResponse(11-16)AssignRequest(19-21)pkg/sandbox/bash.go (1)
Close(120-128)
🪛 golangci-lint (2.12.2)
pkg/sandbox/handler_test.go
[error] 26-26: net/http/httptest.NewRequest must not be called. use net/http/httptest.NewRequestWithContext
(noctx)
[error] 43-43: net/http/httptest.NewRequest must not be called. use net/http/httptest.NewRequestWithContext
(noctx)
[error] 62-62: net/http/httptest.NewRequest must not be called. use net/http/httptest.NewRequestWithContext
(noctx)
Address CodeRabbit review comment — replace httptest.NewRequest with httptest.NewRequestWithContext(context.Background(), ...) across all test request constructions, consistent with the noctx linter enabled in other codeready-toolchain repos. Co-authored-by: Cursor <cursoragent@cursor.com>
- Add testContext(t) helper using context.WithTimeout(t.Context(), 5s) instead of context.Background() to prevent tests from hanging indefinitely (rajivnathan review) - Add error body assertion to "rejects malformed authorization header" test for consistency with other auth failure subtests (rajivnathan review) - Rename "executes command with correct token" to "executes command and returns stdout" for clarity Co-authored-by: Cursor <cursoragent@cursor.com>
Assisted by: Cursor
Summary by CodeRabbit
/health,/execauthorization and input validation,/assigntoken assignment with conflict/validation behavior, and an end-to-end assign-then-exec flow that verifies status codes and key response fields (stdout/stderr/exitCode/durationMs).