Repository navigation
feat(cli): add testsprite api for authenticated raw requests to the CLI API - #500
Shubhdeep12 wants to merge 1 commit into
Conversation
|
Thanks for the PR, @Shubhdeep12! It links an issue, but that issue isn't assigned to you yet: #499 (unassigned). Per our workflow, claim the issue first by commenting |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe CLI adds ChangesRaw API requests
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant CLI as TestSprite CLI
participant Command as api command
participant Client as HttpClient
participant Host as Configured API host
CLI->>Command: Invoke api with path and options
Command->>Client: Send authenticated request
Client->>Host: Send request
Host-->>Client: Return response
Client-->>Command: Return response body or error
Command-->>CLI: Print response body when present
Merge Risk: ⚪ Minimal · up to
|
|
🏆 Season 4 CLI Improvement Bonus: entry recorded. Thanks, @Shubhdeep12! To be counted, this PR needs the following by Oct 29, 11:59 PM PT:
Rewards go to merged PRs judged a genuine improvement, and up to three bonus-eligible PRs count per person. Untick the box to withdraw the entry. This comment refreshes when you edit the PR. Full rules. |
|
Thanks @Shubhdeep12. Closing along with #499, which we're not taking. |
What does this PR do?
Adds
testsprite api <path>: send an authenticated request to any CLI API endpoint and print the JSONresponse, in the spirit of
gh apiand Sentry'ssentry api. It lets scripts and coding agents reach anendpoint no command wraps yet, or a field a command does not show, without copying the API key into
curland losing the CLI's retries, typed errors and exit codes.
--endpoint-url, API key, retries,--debugtracingwith redaction, error envelope, exit codes,
--request-timeout../..and%2e%2esegments — including dotssplit by a tab, which URL parsing silently removes — are refused before anything is sent. A pasted
/api/cli/v1prefix and query strings work.Idempotency-Key, auto-minted and printed liketest run's. Reusing a key with a different body is refused by the server (exit 6, listed in the help).--input <file>goes through the existing guarded reader with a 5 MB cap checked before reading (anoptional
maxBytesonreadSecretFileGuarded; its existing callers are unchanged).--input -explainsthat stdin is not supported.
--dry-runpreviews the request instead of a canned sample (samples exist only for routes the CLI'sown commands call).
api), never the path.Files:
src/commands/api.ts(new), registered insrc/index.ts;src/lib/secret-file.ts(optionalmaxBytes);DOCUMENTATION.md(new "Raw API requests" section + contents entry);README.md(command tablerow);
api --helpadded to the help snapshot suite.Related issue
Closes #499
Type of change
Checklist
mainbranch.npm run lintandnpm run format:checkpass.npm run typecheckpasses.npm testpasses and coverage stays at or above the 80% gate.README.md/DOCUMENTATION.mdwhere relevant.Discord: shubhdeep_chhabra
Notes for reviewers
gh api(GitHub CLI) andsentry api(getsentry/clisrc/commands/api.ts). Deliberatedifference:
gh apiswitches to POST when fields are given; here the method must be explicit, because awrite can start billed runs.
src/commands/api.test.ts, 38 cases; plus one insecret-file.test.tsfor the cap):https://,//host,\\host,javascript:) and./../%2E%2E/backslash/tab-split segments refused;x-api-keyand no idempotency key;--endpoint-url; JSON body plus anauto-minted key printed in JSON mode; an explicit key used and not printed; a 500 retried with the
same key;
--input; an--inputfile over 5 MB refused before sending;--input -explained;a 204 prints nothing; a server 404 keeps its envelope and exit 4;
--dry-runpreview;-Xand the global flags.refused URL /
../%2e%2e, GET with a body, dry-run), and checked the server only ever received requestson the configured host. Input matrix run through the real URL builder: 22 path shapes (encoded and
double-encoded dots,
%2F,%5C, full-width dots,@host,host:port, tabs, line breaks), 14 body/flagshapes and 8 response shapes (201/202/204, empty or HTML 200, envelope-less 500, 404 envelope).
npm run test:coverage: 116 files, 4626 passed;api.ts98.5% statements / 100% lines. ESLint, Prettier,typecheck and the security lint are clean. The
eslint-disablecomments for test temp files follow theexisting spec pattern.
--fieldsPR lands first, it adds--fieldsto the global-options footer of everyhelp screen, so this PR's new
api --helpsnapshot needs regenerating(
npm run build && npx vitest run test/help.snapshot.test.ts -u). There is no text conflict.If-Matchforconditional writes) were left out to keep the surface small. Redirect handling is the shared client's
(see [Hackathon] fix(http): a redirect forwards the API key to the next host #446).
Summary by CodeRabbit
testsprite api <path>for authenticated API requests using the active profile and configured host. Supports GET, POST, PUT, PATCH, and DELETE, with JSON request bodies, response output, and retry handling.