Use params objects for service APIs#11
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors many SDK/API method signatures to accept single parameter objects instead of multiple positional arguments across service clients (Desktop, Filesystem, LSP, Pty, SSH), the Sandbox client, README/examples, and corresponding tests. No behavioral changes beyond argument reshaping and JSDoc/timeout-unit documentation tweaks. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/services/lsp.test.ts (1)
39-53: Optional: add assertions for the remaining migrated calls in this scenario.This test already verifies key payloads; adding explicit checks for
stop,didClosePath, anddocumentSymbolsPathwould make regression detection tighter.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/services/lsp.test.ts` around lines 39 - 53, The test checks several LSP request payloads but omits assertions for the remaining migrated calls; add explicit assertions against calls[x] using the existing calls array and jsonOf helper to verify the stop request (path "/v1/sandbox/sb-1/lsp/stop"), the didClosePath request (likely payload with language_id, path_to_project, and uri for closed document), and the documentSymbolsPath request (payload including language_id, path_to_project, and uri) so all expected LSP interactions in this scenario are validated; reuse the same assert.equal/assert.deepEqual style as the surrounding assertions to locate these calls in the sequence.src/services/lsp.ts (1)
97-103: Consider extracting shared LSP param types.Multiple inline param object shapes are repeated; centralizing them would reduce drift risk and improve readability.
♻️ Suggested refactor
+type LspProjectParams = { languageId: string; pathToProject: string }; +type LspDocumentUriParams = LspProjectParams & { uri: string }; +type LspDocumentPathParams = LspProjectParams & { path: string }; +type LspDidOpenUriParams = LspDocumentUriParams & { text?: string; version?: number }; +type LspDidOpenPathParams = LspDocumentPathParams & { text?: string; version?: number }; +type LspPositionUriParams = LspDocumentUriParams & { line: number; character: number }; +type LspPositionPathParams = LspDocumentPathParams & { line: number; character: number };- params: { languageId: string; pathToProject: string; uri: string }, + params: LspDocumentUriParams,Also applies to: 128-134, 206-212, 237-243, 268-268, 292-292
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/services/lsp.ts` around lines 97 - 103, Extract the repeated inline parameter object into a single exported type (e.g., LspParams or LspRequestParams) that declares languageId, pathToProject, uri and optional text and version, then replace all inline param object annotations (the various params: { languageId: string; pathToProject: string; uri: string; text?: string; version?: number }) with that new type in the functions/methods in src/services/lsp.ts so the signatures reference the shared type; update imports/exports if needed and run type-check to ensure no other call sites need minor adjustments.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/services/ssh.ts`:
- Around line 44-45: The SSH credential ID is interpolated raw into URL path
strings in src/services/ssh.ts (e.g.,
`/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${params.id}` and two other
occurrences), which can break routing for reserved characters; wrap the ID with
encodeURIComponent(params.id) in all three URL constructions (the
DELETE/GET/other request builders that reference params.id) so the path segments
are safely encoded and do this consistently wherever `params.id` is used in the
file.
---
Nitpick comments:
In `@src/services/lsp.ts`:
- Around line 97-103: Extract the repeated inline parameter object into a single
exported type (e.g., LspParams or LspRequestParams) that declares languageId,
pathToProject, uri and optional text and version, then replace all inline param
object annotations (the various params: { languageId: string; pathToProject:
string; uri: string; text?: string; version?: number }) with that new type in
the functions/methods in src/services/lsp.ts so the signatures reference the
shared type; update imports/exports if needed and run type-check to ensure no
other call sites need minor adjustments.
In `@tests/services/lsp.test.ts`:
- Around line 39-53: The test checks several LSP request payloads but omits
assertions for the remaining migrated calls; add explicit assertions against
calls[x] using the existing calls array and jsonOf helper to verify the stop
request (path "/v1/sandbox/sb-1/lsp/stop"), the didClosePath request (likely
payload with language_id, path_to_project, and uri for closed document), and the
documentSymbolsPath request (payload including language_id, path_to_project, and
uri) so all expected LSP interactions in this scenario are validated; reuse the
same assert.equal/assert.deepEqual style as the surrounding assertions to locate
these calls in the sequence.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 791d1cad-572f-4460-8e40-3e86e9b9fda1
📒 Files selected for processing (16)
README.mdexamples/desktop.tsexamples/ssh.tssrc/client/sandbox.tssrc/services/desktop.tssrc/services/filesystem.tssrc/services/lsp.tssrc/services/process.tssrc/services/pty.tssrc/services/ssh.tstests/client/client-sandbox.test.tstests/services/desktop.test.tstests/services/filesystem.test.tstests/services/lsp.test.tstests/services/pty.test.tstests/services/ssh.test.ts
| `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${params.id}`, | ||
| { method: "DELETE" }, |
There was a problem hiding this comment.
Encode SSH credential IDs before interpolating into URL paths.
params.id is inserted raw into path segments. Reserved characters (e.g., /, ?, #) can alter endpoint targeting. Use encodeURIComponent for all three URL constructions.
🔧 Proposed fix
async deleteAccess(
sandbox: SandboxRef,
params: { id: string },
options: RequestOptions = {},
): Promise<void> {
+ const encodedId = encodeURIComponent(params.id);
await this.transport.request(
- `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${params.id}`,
+ `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${encodedId}`,
{ method: "DELETE" },
options,
);
}
async validateAccess(
sandbox: SandboxRef,
params: { id: string; password: string },
options: RequestOptions = {},
): Promise<SshValidation> {
+ const encodedId = encodeURIComponent(params.id);
const data = await this.transport.requestJson<SshValidation>(
- `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${params.id}/validate`,
+ `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${encodedId}/validate`,
{ method: "POST", body: jsonBody({ password: params.password }) },
options,
);
return normalize(sshValidationSchema, data);
}
async regenerateAccess(
sandbox: SandboxRef,
params: { id: string },
options: RequestOptions = {},
): Promise<SshAccess> {
+ const encodedId = encodeURIComponent(params.id);
const data = await this.transport.requestJson<SshAccess>(
- `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${params.id}/regen`,
+ `/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${encodedId}/regen`,
{ method: "POST" },
options,
);
return normalize(sshAccessSchema, data);
}Also applies to: 64-65, 85-86
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/services/ssh.ts` around lines 44 - 45, The SSH credential ID is
interpolated raw into URL path strings in src/services/ssh.ts (e.g.,
`/v1/sandbox/${sandboxIdOf(sandbox)}/ssh/${params.id}` and two other
occurrences), which can break routing for reserved characters; wrap the ID with
encodeURIComponent(params.id) in all three URL constructions (the
DELETE/GET/other request builders that reference params.id) so the path segments
are safely encoded and do this consistently wherever `params.id` is used in the
file.
Summary
Testing
Summary by CodeRabbit