Skip to content

feat(cloudflare): per-pull-request previews with void deploy --preview - #831

Open
messenjer wants to merge 13 commits into
voidzero-dev:mainfrom
messenjer:feat/cloudflare-previews
Open

messenjer wants to merge 13 commits into
voidzero-dev:mainfrom
messenjer:feat/cloudflare-previews

Conversation

@messenjer

@messenjer messenjer commented Nov 14, 2026 •

Copy link
Copy Markdown

Part of #467. Related: #471 (a preview reuses an earlier build step's static output with --skip-build, like a production deploy; Worker apps still need a fresh build).

Open questions for maintainers

Two design choices shape the public surface. I'd like your call on them before polishing further:

  1. Workers Previews or aliased version URLs? Cloudflare deploy: preview deployments for pull requests #467 asks for versions upload --preview-alias, and the plumbing for it already exists. This PR uses Workers Previews instead, because Cloudflare now recommends them for branch and pull request testing: aliased version URLs share production resources and can only be removed by deleting the version. The trade-off is that Previews are in open beta, so Void would depend on a beta API and on the cf CLI's previews commands. Are you comfortable with that, or would you rather start with aliases?
  2. Command name for removal. void preview delete <name> adds a top-level preview group. In the Vite ecosystem, "preview" usually means the local server for a build (vite preview, vp preview), so this may read ambiguously. Alternatives: void cloudflare preview delete <name>, or a flag on deploy such as void deploy --platform cloudflare --delete-preview <name>. Which do you prefer?

Summary

Per-pull-request previews for void deploy --platform cloudflare, built on Cloudflare's Workers Previews rather than versions upload --preview-alias. A Preview has a stable URL, never takes production traffic, gets no production secrets, and can be deleted by name. Cloudflare now advises against aliased version URLs for branch previews because they run against production resources.

void deploy --platform cloudflare --preview pr-64 [--json]
  refuse: Worker apps, existing-Worker handoff, --atomic, --provision, --require-email, invalid name
  build (or --skip-build / --dir), stage the static edge Worker and assets
  prepare Build Output with buildContext.isPreview = true
  deployCloudflarePreview            # sends only `previews.deploy`
    cf previews deploy --prebuilt --preview-name=pr-64
  print the URL; with --json, one record on stdout and all logs on stderr

void preview delete pr-64
  deleteCloudflarePreview            # sends only `previews.delete`
    cf previews delete pr-64 --worker=<worker> --force
  "Preview not found" (10025) → success, so a cleanup job can rerun
 packages/deploy-cloudflare/src/
 ├── operations.ts        # + previews.deploy, previews.delete
+└── preview.ts           # deploy/delete and name validation
 packages/void/src/cli/
 ├── args.ts              # + --preview <name>, --json
 ├── cf-build-output.ts   # + isPreview on the static Build Output
 ├── cf-command-values.ts # + decode the cf Preview record
 ├── cf-version-runner.ts # + previews.deploy → cf previews deploy --prebuilt
 ├── cloudflare-operation-process.ts  # + previews.delete
 ├── deploy-cloudflare-static.ts      # + preview branch (no activation)
 ├── output.ts            # + setProgressOutput: --json sends progress to stderr
+├── preview-args.ts, preview-cmd.ts  # void preview delete
 └── help.ts, cli-main.ts # help page, interactive hints

--json output:

{"workerName":"my-app","previewName":"pr-64","previewUrl":"https://pr-64-my-app.team.workers.dev","deploymentId":"…","deploymentUrl":"https://…-my-app.team.workers.dev"}

Decisions:

  • Scope: static sites, SPAs and supported SSGs. Apps that need a Worker are refused before anything is built or uploaded, so a preview never runs migrations, provisions resources or shares production D1/KV/R2. Worker apps are a follow-up.
  • Only CLOUDFLARE_API_TOKEN (and CLOUDFLARE_ACCOUNT_ID) are needed. The URL comes from Cloudflare's response, so CLOUDFLARE_WORKERS_SUBDOMAIN is not needed.
  • If the Worker has preview_urls turned off, Cloudflare returns no URL; the deploy fails and says to set cloudflare.preview_urls in void.config.ts.
  • Names: [a-z0-9-], starting and ending with a letter or digit; <name>-<worker> must fit in 63 characters.
  • Workers Free: 100 Previews per Worker; Cloudflare evicts the least recently deployed one.

Docs: docs/reference/cli/deploy.md, docs/reference/cli.md, a pull request workflow (deploy, comment the URL, delete on close) in docs/integrations/cloudflare.md, and one line in packages/void/skills/void.

Evidence

  • Before: no preview path. CI had to call wrangler directly, scrape the URL from logs and leave aliases behind:
    wrangler versions upload --preview-alias pr-64 + grep -oE "https://pr-64-…workers.dev"
  • After: live run on a throwaway Worker (Workers Free account, CI-style: API token and account ID only):
Step Command Result
Production void deploy --platform cloudflare --dir dist --spa https://<worker>.<subdomain>.workers.dev serves production-1, active version <version> at 100%
Preview, push 1 … --preview pr-1 --json stdout is exactly one JSON line; https://pr-1-<worker>.<subdomain>.workers.dev serves pr-1 push-1; SPA deep links return the shell
Preview, push 2 same command same URL serves pr-1 push-2; the first deployment URL still serves push-1
Second preview … --preview pr-2 --json pr-1 and pr-2 serve side by side
Production check cf workers deployments list after each step still 1 deployment, <version> at 100%, body production-1
Production with a preview present void deploy --platform cloudflare --dir dist --spa deploys normally; the preview is unaffected
Preview URLs off cloudflare.preview_urls: false, then --preview pr-3 exit 1 with the void.config.ts hint, empty stdout
Delete void preview delete pr-1, run twice first deletes (URL → 404), second says "does not exist", exit 0

The live run found and fixed three bugs that unit tests could not catch: the Build Output needed isPreview: true, cf previews delete does not read a name after --, and a missing Preview is error 10025, not 10007.

Tests:

deployCloudflarePreview sends only previews.deploy                      ✓
static --preview: no activateVersion, Cloudflare calls = [whoami, preview] ✓
--json: one record on stdout, logs on stderr                             ✓
preview_urls off → actionable error                                      ✓
Worker app with --preview → refused before any Cloudflare call           ✓
static Build Output with isPreview passes a real `cf previews deploy --dry-run` ✓
cf runner translation, arg parsing, preview delete (incl. 10025/10007)   ✓

vp run check and the full vp test run pass (807 files, 17,052 tests).

Merge Danger

Door: two-way

New flags and a new command; the production deploy path is unchanged apart from an isPreview: false default passed through the static Build Output preparation.

Blast Radius: small

Risk sits in the opt-in --preview path, which depends on Cloudflare Workers Previews (open beta) and the pinned cf CLI's previews commands. A change in either breaks previews, not production deploys.

🤖 Generated with Claude Code

Add `void deploy --platform cloudflare --preview <name> [--json]` and
`void preview delete <name>`, built on Cloudflare Workers Previews.

A Preview is a named, isolated environment of the same Worker with a stable
`<name>-<worker>.<subdomain>.workers.dev` URL. Deploying the same name again
updates it; production traffic, the active deployment, routes and schedules
are never touched, and a Preview gets no production secrets.

- @void/deploy-cloudflare: `previews.deploy` / `previews.delete` operations,
  `deployCloudflarePreview` (sends only `previews.deploy`),
  `deleteCloudflarePreview` (a missing Preview, 10025, counts as deleted) and
  name validation.
- void: the static deploy prepares its Build Output as a Preview build and
  publishes it through `cf previews deploy --prebuilt` instead of activating
  a version. Apps that need a Worker, an existing-Worker handoff, and
  --atomic/--provision/--require-email are refused before anything is built
  or uploaded. A preview never saves an account for the project.
- --json prints one record on stdout (workerName, previewName, previewUrl,
  deploymentId, deploymentUrl); progress goes to stderr through an explicit
  progress stream in output.ts.
- When the Worker has Preview URLs turned off, the deploy fails and points at
  `cloudflare.preview_urls` in void.config.ts.
- Help, interactive hints, CLI reference, a pull request workflow in the
  Cloudflare integration guide, and the skill.

Refs voidzero-dev#467, voidzero-dev#471.
@cpojer
cpojer requested a review from Brooooooklyn November 14, 2026 23:36
Brooooooklyn and others added 11 commits November 26, 2026 17:05
Use top-level type imports, numeric separators, type guards instead of
casts, and no non-null assertions or trailing-slash regex in the preview
code that came in with the merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`void deploy --preview --json` now runs like `void db execute --json`: the
deploy runs in a child whose stdout is our stderr, and only the result the
child writes to fd 3 reaches stdout. Errors, parse errors and output from
void.config.ts no longer mix with the record. The shared runner is renamed
to json-command-process.ts, and the progress-stream plumbing in output.ts,
deploy-helpers.ts and deploy-summary.ts is dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move preview cleanup next to rollback as `void project preview delete
<name> [--platform cloudflare]`, so it does not clash with `vp preview`.
It uses the same Worker and account as rollback and logs. A Preview that
does not exist is not an error; a missing Worker or any other failure
exits 1. The name is checked before any config is read.

The top-level `void preview` command, its help and the uploader opt-out
in the deploy helpers are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before connecting, `deploy --preview` now checks the name with a small
parser (no regex), and needs `cloudflare.name` and a pinned account, so
the deploy and `void project preview delete` reach the same Worker. The
workers.dev length rule is checked against that name.

The upload first reads the Worker's deployment status: cf would create a
missing Worker without asking, so a Worker with no production deployment
stops with nothing uploaded. The staged config keeps only an allow-list
of keys, so a preview gets none of the Worker's bindings, vars or
migrations. A deploy with Preview URLs off reports the deployment it
made and how to turn them on. The cf runner decodes the Preview record
from its parsed stdout JSON.

The preview tail moves to cloudflare-preview.ts. The account save and
queue-cleanup read go back to main's code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document `void deploy --preview` and `void project preview delete`: the
requirements (production first, `cloudflare.name`, a pinned account), the
JSON record, failure output and naming rules. The GitHub Actions example
now passes values through `env:`, skips fork and Dependabot pull requests,
comments once and cleans up from the base branch. Update the deploy help
rows, the skill and the package notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A menu hint with a <...> part now needs input, so Enter on an empty
"delete <name>" no longer runs into a usage error. The menu splits a
hint of several words into separate arguments, so parseProjectArgs
stays strict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a Worker name of 62 or 63 characters no preview name fits on
workers.dev, so say that instead of "use at most 0". The account and
delete messages name the right config file, and the 63-character limit
is shared from @void/deploy-cloudflare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build the cf previews deploy dry run from previewStaticWorkerConfig and
writeCloudflareStaticDeployConfig, the shape a preview deploy uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the interactive menu entry a hint, as zero-trust and security are, so
the shared prompt and argument builder stay unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

Thanks @messenjer, this is a solid base, and the live-run notes in the body helped a lot. I pushed a set of maintainer commits on top of your branch (your commit stays as it is; we'll squash with you as co-author). This comment explains what changed and why.

Your two questions

  1. Previews or aliased version URLs? Previews. Cloudflare says not to use version URLs for branch or PR testing, and an alias also dies when version retention removes its version. Previews have been generally available since 2026-09-22 (only the REST API under them is still labeled beta), and they work on Workers Free. previewAlias stays our internal readiness check.
  2. Command name for removal? void project preview delete <name> [--platform cloudflare]. It sits next to project rollback, uses the same --platform cloudflare rule, and doesn't clash with vp preview. The top-level void preview group is gone.

Flow after the changes

void deploy --platform cloudflare --preview pr-64 [--json]
  parse                 name not empty; refuse --atomic/--provision/--require-email; --json needs --preview
  --json?               run the deploy in a child process (like `void db execute --json`)
                        stdout = exactly one record on success, empty on failure
  before connecting     name rules, cloudflare.name set, account pinned, "<name>-<worker>" <= 63
  build -> stage        staged config is an allow-list: no bindings, vars, migrations
  Build Output          buildContext.isPreview = true
  deployments.status    Worker missing? stop, nothing uploaded ("Deploy production first")
  previews.deploy       cf previews deploy --prebuilt --preview-name=pr-64
  no URL back?          exit 1 with the deployment ID and the preview_urls fix

void project preview delete pr-64 [--platform cloudflare]
  same target as rollback/list/logs
  deleted -> 0 | 10025 (not found) -> 0 | Worker not found / other -> 1

What changed, and why

Change Why
--json runs in a child process; the result goes through fd 3 Errors, parse errors and console.log from void.config.ts could reach stdout. Now stdout is the record or nothing. This replaces setProgressOutput and the progress rerouting.
void preview delete → void project preview delete See Q2.
Check that the Worker exists before uploading cf rc.5 silently creates a missing Worker on previews deploy, so a first preview made an empty production Worker.
Allow-listed staged config for previews cf sends every binding in the Build Output into the Preview. With the allow-list, a static preview truly gets no bindings, vars or secrets, and a new binding kind can't leak in later.
Require cloudflare.name and a pinned account Deploy and cleanup always reach the same Worker.
Name check as a small loop, before any network call Starts with a lowercase letter, [a-z0-9-], no --, doesn't end with -. Also checks that the Worker name itself leaves room.
preview_urls off: the error includes the deployment ID The upload already happened, so the message says what exists and how to fix it.
Merged main and fixed lint Main moved a lot since the PR was opened (cf rc.5, writeRootConfig, token wording).
Docs Fixed the cheat-sheet row (it failed without --platform cloudflare), the heading level in cloudflare.md, main's token wording, and scope notes. Updated the workflow to current action versions, env: values, cancel-in-progress, cleanup from the base branch, and skipping fork/Dependabot PRs.

Live run on a throwaway Workers Free account (cf 1.0.0-rc.5)

Case Result
Preview before any production deploy exit 1, empty stdout, "Deploy production first", no Worker created
--preview pr-1 --json one JSON line on stdout, progress on stderr, URL serves the build, SPA deep links work
Push 2 to pr-1 same URL updates; the old deployment URL still serves push 1
pr-2 next to pr-1, then production all three serve their own content; production keeps 1 deployment at 100%
Preview env only ASSETS and version metadata; production vars not present
Delete pr-1 twice deleted, then "does not exist… Nothing to delete", both exit 0; pr-2 untouched
Delete with a wrong Worker name exit 1, names the Worker and account
preview_urls: false exit 1, empty stdout, message has the deployment ID and the fix

PR body

Please change "Closes #467" to "Part of #467": this covers static sites and SPAs, while #467 also asks about full-stack apps. Also drop "open beta", and change "never shares production D1/KV/R2" to "a static preview gets none of the Worker's bindings, vars or secrets". The commands in the live-run table are now void project preview delete ….

Follow-up (not this PR)

Previews for Worker apps need a product decision first: bind a Preview to one shared staging set of D1/KV/R2 (Cloudflare's advice, fits Workers Free) or to per-PR resources that Void creates and deletes? And should secrets come through cf --secrets-file or the Previews Base config? Two technical notes for that work: cf refuses Workers with triggers or queue consumers, and the Worker Build Output path must carry isPreview too.

@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T10:34:58.227597Z cdf883c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4a4e24de4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@Brooooooklyn
Brooooooklyn marked this pull request as ready for review November 26, 2026 10:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants