Repository navigation
walking skeleton: Cobra root, video list command, test harness (PRINFRA-142) - #3
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
cf330c6 to
f2739c2
Compare
efe76e6 to
9bde38a
Compare
| // Bootstrap formatter created before the Cobra tree so it's available | ||
| // for errors from PersistentPreRunE (auth failures, config loading). | ||
| formatter := output.DefaultJSONFormatter() | ||
|
|
There was a problem hiding this comment.
Formatter is created here (before the Cobra tree) so it's available for errors from PersistentPreRunE — e.g. auth failures. Without this, early errors would have no formatter to render through.
| // 1. Create config provider (BaseURL only — auth is Resolver's job) | ||
| provider := &config.EnvProvider{} | ||
| ctx.config = provider | ||
|
|
There was a problem hiding this comment.
config.Provider is on the execution path (not just defined): PersistentPreRunE creates EnvProvider and passes provider.BaseURL() to the client constructor. When FileProvider replaces this, the wiring stays the same.
| Long: "List videos in your HeyGen account with optional filtering.", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| // Validate --limit if explicitly provided | ||
| if cmd.Flags().Changed("limit") { |
There was a problem hiding this comment.
Using cmd.Flags().Changed() instead of checking limit > 0 — this correctly distinguishes 'not provided' (don't send param, let API use its default) from 'explicitly set to some value'. The codegen pipeline will use this same pattern for all optional flags.
| formatter := output.NewJSONFormatter(&stdout, &stderr) | ||
|
|
||
| // Set env vars for this test | ||
| t.Setenv("HEYGEN_API_KEY", apiKey) |
There was a problem hiding this comment.
This mirrors the production error-rendering path from main(): errors are rendered through formatter.Error() into the stderr buffer. This ensures stderr content in tests matches what users actually see — tests can assert on the exact JSON envelope shape.
9bde38a to
d49db0e
Compare
8ce9be0 to
c1f876d
Compare
d49db0e to
00a632c
Compare
c1f876d to
d8d9792
Compare
00a632c to
3cb6ba2
Compare
d8d9792 to
03876e7
Compare
| func newVideoCmd(ctx *cmdContext) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "video", | ||
| Short: "Manage videos", | ||
| } | ||
| cmd.AddCommand(newVideoListCmd(ctx)) |
There was a problem hiding this comment.
we need help/examples for everything
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List videos", | ||
| Long: "List videos in your HeyGen account with optional filtering.", |
There was a problem hiding this comment.
we need good help/example messages for everything this is critical IMO
There was a problem hiding this comment.
This is handled in the Design - https://www.notion.so/heygen/Design-331449792c69804993e0eb736b024ca2?source=copy_link#045c03f0f92444e782f37343c7f39b18
We will need to manually generate these examples (via an LLM followed by a human review).
jrusso1020
left a comment
There was a problem hiding this comment.
left a comment we need good descriptions, examples etc! in the long case
I think kubectl has some formatting/helpers here
we could create our own wrapper around cobra cmd as well to help enforce this for each commnad and format it well!
|
@jrusso1020 Help examples are covered in the Design doc. Good idea to add an enforcement layer to that. I will add that! |
03876e7 to
c8244dd
Compare
3cb6ba2 to
5f62f7e
Compare
PRINFRA-142 CLI M0: Walking skeleton — `video list` E2E + test harness
Prove the full architecture spine works end-to-end with one hand-written command and establish the test harness. Scope
Why this mattersThis is the validation gate for M0. If Acceptance Criteria
|
Merge activity
|
Cobra root command with PersistentPreRunE that wires config.Provider, auth.Resolver, and client together on the execution path: - main.go: bootstrap JSONFormatter before Cobra tree, all errors (including PersistentPreRunE failures) rendered as JSON envelopes - root.go: cmdContext with client, formatter, config; PersistentPreRunE creates EnvProvider → reads BaseURL() → creates Client - video list: --limit, --token, --folder-id flags, builds canonical RequestSpec with []QueryParam, returns raw JSON via formatter.Data() Test harness mirrors production error-rendering path: - setupTestServer: httptest mock with handler map - runCommand: fresh Cobra tree per test, renders errors through formatter into stderr buffer, extracts exit code from CLIError - Tests: success, auth missing (exit 3), API 401 (exit 3), API 400 (exit 1), flags as query params, server error (exit 1) Verified: heygen video list --limit 2 returns real video JSON from API. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Three fixes from review:
1. Usage errors → exit code 2: SetFlagErrorFunc wraps Cobra flag
parse errors as CLIError{ExitUsage}. Unknown flags, bad types
now correctly return exit 2 with JSON envelope.
2. --limit validation: reject values outside 1-100 with ExitUsage
before hitting the API. --limit -5 and --limit 999 are caught
locally.
3. Remove APIKey() from config.Provider interface: credentials are
exclusively auth.Resolver's responsibility. Provider only owns
BaseURL(). Eliminates dual credential paths that could drift
when M2 adds keyring/file auth.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Linear's GitHub integration auto-links PRs to issues when the issue ID appears in the PR title (e.g., PRINFRA-123). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
67d5604 to
f5a3e9f
Compare

Description
Wires everything from PRs #1 and #2 into a working CLI. After this,
heygen video listworks end-to-end against the real HeyGen API.What happens when you run
heygen video list --limit 5:main.gocreates a JSON formatter before anything else — so even early failures (bad auth, bad flags) get structured JSON error output, never plain text.video listcommand validates--limitis 1-100, builds a RequestSpec, and hands it to the executor.main.gowhere 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:
Manual smoke test:
HEYGEN_API_KEY=<key> ./bin/heygen video list --limit 2returns real video JSON.Linear: PRINFRA-142