feat(tpagectl): implement preview get subcommand #579

Merged
fuzzy merged 2 commits from feat/cli-preview-get into main 2026-08-07 04:14:43 +00:00
Owner

What

Implements preview get end to end: the daemon's missing GET /api/v1/sites/{name}/preview/{branch} endpoint plus the tpagectl preview get subcommand. This completes the Phase 4 preview command group.

Daemon

  • SiteService.Preview(ctx, siteName, branch) returns a specific preview deployment, ErrNotFound when the site, deployment, or preview is missing (a non-preview deployment, e.g. a production tag, is treated as not found).
  • New GET /api/v1/sites/{name}/preview/*branch handler (#233): owner-scoped (403), 404, 200 with the Deployment. Uses a wildcard branch segment so test/* branch names route correctly.
  • Tests: service (found / non-preview / unknown site / unknown branch), handler 200/404.

CLI

  • Flags (#232): --site (required), --branch (required).
  • GET (#233): /api/v1/sites/{name}/preview/{branch} decoded into a previewRecord.
  • Display (#234): block — branch, status, commit SHA, deployed at, and the preview URL (site URL + /preview/{branch}).
  • Friendly 404 (preview "X" for site "Y" not found); missing --site/--branch errors.
  • Tests: happy path (status + URL), 404, missing --site, missing --branch.

Why

Phase 4 roadmap task #235; the final preview command.

Testing

  • Daemon: service Preview (found/non-preview/unknown site/unknown branch), handler 200/404 tests
  • CLI: happy path, 404, missing --site/--branch
  • go test -race ./... passes (19 packages)
  • golangci-lint run clean
  • pre-commit hooks pass (gofmt, go mod tidy, go test)

Breaking Changes

None. SiteService gains Preview.

Notes

All four preview subcommands are now implemented, so the preview package's errNotImplemented stub sentinel and its test are removed. The per-preview endpoint also supports the deferred site get preview display (#181) as a follow-up.

Closes #232
Closes #233
Closes #234
Closes #235

## What Implements `preview get` end to end: the daemon's missing `GET /api/v1/sites/{name}/preview/{branch}` endpoint plus the tpagectl `preview get` subcommand. This completes the Phase 4 preview command group. **Daemon** - `SiteService.Preview(ctx, siteName, branch)` returns a specific preview deployment, `ErrNotFound` when the site, deployment, or preview is missing (a non-preview deployment, e.g. a production tag, is treated as not found). - New `GET /api/v1/sites/{name}/preview/*branch` handler (#233): owner-scoped (403), 404, 200 with the `Deployment`. Uses a **wildcard** branch segment so `test/*` branch names route correctly. - Tests: service (found / non-preview / unknown site / unknown branch), handler 200/404. **CLI** - **Flags** (#232): `--site` (required), `--branch` (required). - **GET** (#233): `/api/v1/sites/{name}/preview/{branch}` decoded into a `previewRecord`. - **Display** (#234): block — branch, status, commit SHA, deployed at, and the preview URL (site URL + `/preview/{branch}`). - Friendly 404 (`preview "X" for site "Y" not found`); missing `--site`/`--branch` errors. - Tests: happy path (status + URL), 404, missing `--site`, missing `--branch`. ## Why Phase 4 roadmap task #235; the final preview command. ## Testing - [x] Daemon: service Preview (found/non-preview/unknown site/unknown branch), handler 200/404 tests - [x] CLI: happy path, 404, missing `--site`/`--branch` - [x] `go test -race ./...` passes (19 packages) - [x] `golangci-lint run` clean - [x] pre-commit hooks pass (gofmt, go mod tidy, go test) ## Breaking Changes None. `SiteService` gains `Preview`. ## Notes All four preview subcommands are now implemented, so the preview package's `errNotImplemented` stub sentinel and its test are removed. The per-preview endpoint also supports the deferred `site get` preview display (#181) as a follow-up. Closes #232 Closes #233 Closes #234 Closes #235
Add the daemon GET /api/v1/sites/{name}/preview/{branch} endpoint and the
tpagectl preview get subcommand. This completes the Phase 4 preview
command group.

Daemon: SiteService.Preview returns a specific preview deployment,
ErrNotFound when the site, deployment, or preview is missing. The handler
is owner-scoped and uses a wildcard branch segment so branch names with
slashes (test/*) route correctly.

CLI: preview get takes --site and --branch (required), fetches the
preview, and prints its status, commit, deployed time, and URL. The
preview package stub sentinel and its test are removed now that all
preview subcommands are implemented.
docs(roadmap): mark preview get subcommand complete
All checks were successful
Test and Release / lint (pull_request) Successful in 4m34s
Test and Release / test (pull_request) Successful in 24m0s
6b8a0db91c
Record completion of the tpagectl preview get subcommand and its daemon
endpoint: --site/--branch flags, GET /api/v1/sites/{name}/preview/{branch},
and status/URL display. This completes the Phase 4 preview command group.

closes #232
closes #233
closes #234
closes #235
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-08-07 03:40:47 +00:00
the.auditor left a comment

Summary

preview get: daemon GET /api/v1/sites/{name}/preview/{branch} + tpagectl subcommand, completing the Phase 4 preview group. Verified: go test -race ./... passes (19 packages) and golangci-lint run ./... is clean. Closes #232-235.

Verified correctness: Service.Preview rejects non-preview deployments (a production v* tag returns ErrNotFound, covered by TestPreviewNonPreviewDeployment); wildcard *branch routing with leading-slash strip is consistent with deletePreview (#577); the previewURL helper is reused within the package.

No blocking issues; no new issues filed (remaining items are recurring gaps already tracked).

References (covered by existing issues)

  1. internal/tpagectl/preview/get.go – the 404→friendly mapping is now a tenth inline copy (extends #565/#561); non-404 passthrough remains untested (#571); Preview filters with isPreviewDeployment (!HasPrefix("v")), so a production deployment at a non-v tag would be returned as a "preview" — reinforces the #568/#575 question.

Praise

  • The non-preview guard is a good semantic safeguard against fetching production deployments through the preview endpoint
  • Wildcard routing consistent with preview delete, reusable for the deferred site get preview display (#181)
  • Clean block output (status/commit/deployed/url)
  • errNotImplemented removal tidily completes the group; webhook fake updated
  • Strong coverage: service found/non-preview/unknown-branch/unknown-site, handler 200/404, CLI happy/404/missing --site/--branch
## Summary `preview get`: daemon `GET /api/v1/sites/{name}/preview/{branch}` + tpagectl subcommand, completing the Phase 4 preview group. Verified: `go test -race ./...` passes (19 packages) and `golangci-lint run ./...` is clean. Closes #232-235. Verified correctness: `Service.Preview` rejects non-preview deployments (a production `v*` tag returns `ErrNotFound`, covered by `TestPreviewNonPreviewDeployment`); wildcard `*branch` routing with leading-slash strip is consistent with `deletePreview` (#577); the `previewURL` helper is reused within the package. No blocking issues; no new issues filed (remaining items are recurring gaps already tracked). ## References (covered by existing issues) 1. `internal/tpagectl/preview/get.go` – the 404→friendly mapping is now a tenth inline copy (extends #565/#561); non-404 passthrough remains untested (#571); `Preview` filters with `isPreviewDeployment` (`!HasPrefix("v")`), so a production deployment at a non-`v` tag would be returned as a "preview" — reinforces the #568/#575 question. ## Praise - The non-preview guard is a good semantic safeguard against fetching production deployments through the preview endpoint - Wildcard routing consistent with `preview delete`, reusable for the deferred `site get` preview display (#181) - Clean block output (status/commit/deployed/url) - `errNotImplemented` removal tidily completes the group; webhook fake updated - Strong coverage: service found/non-preview/unknown-branch/unknown-site, handler 200/404, CLI happy/404/missing `--site`/`--branch`
fuzzy merged commit 6b8a0db91c into main 2026-08-07 04:14:43 +00:00
fuzzy deleted branch feat/cli-preview-get 2026-08-07 04:14:43 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/thwap-pagesd!579
No description provided.