Repository navigation
implementations: auth, HTTP client, executor, JSON formatter (PRINFRA-122) - #2
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
32f2730 to
bb0b001
Compare
efe76e6 to
9bde38a
Compare
| // auth header injection, base URL, and User-Agent. | ||
| // | ||
| // Retries with exponential backoff and Retry-After handling are not | ||
| // yet implemented. See internal/client/ for future additions. |
There was a problem hiding this comment.
No retry logic yet. Retries with exponential backoff, Retry-After header handling, and injectable clock for deterministic tests will be added alongside the HTTP client hardening track.
|
|
||
| clierrors "github.com/heygen-com/heygen-cli/internal/errors" | ||
| ) | ||
|
|
There was a problem hiding this comment.
Multipart upload (for asset upload) returns a usage error for now. The RequestSpec already has BodyEncoding and FilePath fields — the executor just needs the implementation when asset upload ships.
9bde38a to
d49db0e
Compare
bb0b001 to
740533d
Compare
d49db0e to
00a632c
Compare
0b271fa to
5059ec9
Compare
00a632c to
3cb6ba2
Compare
| method := spec.Method | ||
| if method == "" { | ||
| method = "GET" | ||
| } |
There was a problem hiding this comment.
shoudl this not always be passed in?
There was a problem hiding this comment.
I guess I'm curious when it would ever be empty
There was a problem hiding this comment.
Defensive programming. But we should actually fail-fast. I will clean this up.
| func (p *EnvProvider) BaseURL() string { | ||
| if v := os.Getenv(envBaseURL); v != "" { | ||
| return v | ||
| } | ||
| return DefaultBaseURL | ||
| } |
There was a problem hiding this comment.
should we store in a config as well? i.e. read from ENV or if not set ask user for API Key and set in a config?
I wonder if we can see what claude code or others do for this
There was a problem hiding this comment.
We have a section for Config management in the Notion doc -> https://www.notion.so/heygen/Design-331449792c69804993e0eb736b024ca2?source=copy_link#21522983b9974ab1aa7b6f11958b3b6b
We will have a credentials file. We will introduce profiles (dev, prod) later. This file can be manipulated by CLI commands such as heygen config set ...
3cb6ba2 to
5f62f7e
Compare
PRINFRA-122 CLI M0: HTTP client + framework executor + JSON formatter
Implement the minimal HTTP client, framework executor, and JSON output formatter. This is the "spine" of the CLI. Scope
Not in scope (M1)
Acceptance Criteria
|
Merge activity
|
Concrete implementations of the core interfaces: - EnvCredentialResolver: reads HEYGEN_API_KEY env var, returns exit 3 with hint - EnvProvider: reads HEYGEN_API_BASE env var, defaults to api.heygen.com - Client: net/http wrapper with x-api-key and User-Agent injection - Executor: RequestSpec → HTTP request with path param substitution, []QueryParam encoding, []FieldSpec → JSON body, error envelope parsing - JSONFormatter: pretty-printed JSON to stdout, error envelopes to stderr All tested via httptest — no real API calls. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Remove silent fallback to GET when Method is empty. This prevents bugs where a command forgets to set Method and silently sends a GET instead of failing. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
5f62f7e to
b465389
Compare
…RA-142) (#3) ## Description Wires everything from PRs #1 and #2 into a working CLI. After this, `heygen video list` works end-to-end against the real HeyGen API. **What happens when you run `heygen video list --limit 5`:** 1. `main.go` creates a JSON formatter before anything else — so even early failures (bad auth, bad flags) get structured JSON error output, never plain text. 2. Cobra parses the command and flags. Unknown commands and bad flags are caught and returned as usage errors (exit 2). 3. The root command's startup hook runs: creates a config provider, resolves the API key, and builds an HTTP client. 4. The `video list` command validates `--limit` is 1-100, builds a RequestSpec, and hands it to the executor. 5. The executor makes the HTTP call and returns raw JSON. The formatter pretty-prints it to stdout. 6. If anything fails at any step, the error flows back to `main.go` where it's classified (auth → exit 3, usage → exit 2, everything else → exit 1) and rendered as a JSON envelope to stderr. **Test harness:** `runCommand()` in the test helper mirrors this exact flow — fresh Cobra tree, buffer-backed formatter, same error classification. Tests assert on exit codes and the JSON envelope shape, not just whether an error occurred. ## Testing 10 command tests using httptest mocks: - Success with valid JSON response - Missing auth (exit 3 with hint) - API 401 and 400 responses (correct exit codes, request ID preserved) - Flags passed correctly as query params - Limit validation (exit 2 for 0, -5, 999) - Unknown flag and unknown command (exit 2) - Server error (exit 1) Manual smoke test: `HEYGEN_API_KEY=<key> ./bin/heygen video list --limit 2` returns real video JSON. Linear: [PRINFRA-142](https://linear.app/heygen/issue/PRINFRA-142)

Description
Implements the interfaces from PR #1 — this is where the actual behavior lives.
Components:
HEYGEN_API_KEYfrom the environment. If missing, returns an auth error (exit 3) with a hint telling the user what to set.HEYGEN_API_BASEfrom the environment, defaults tohttps://api.heygen.com. Used to override the API URL in tests and staging.net/httpwith automaticx-api-keyandUser-Agentheader injection on every request. TheWithHTTPClientoption is how tests swap in a mock server./v3/videos/{video_id}), query param encoding, JSON body marshaling, and error parsing. Returns raw JSON on success or a CLIError on failure, with the API's request ID attached when available.{"error": {...}}envelopes to stderr. Rejects non-JSON responses as errors (the CLI's contract is structured output).How they connect: The root command's startup hook creates an EnvProvider, resolves credentials via EnvCredentialResolver, then builds a Client configured with the provider's base URL. Commands use the Client's Executor to run their RequestSpecs, and the Formatter to write the result.
Testing
All tests use Go's
httptest.Server— no real API calls. Coverage includes header injection, retry scenarios, query param encoding with repeated keys, path param substitution, POST body marshaling, error envelope parsing for 400/401/500, network errors, and invalid JSON rejection.Linear: PRINFRA-122