fix(cloudflare): destroy actually tears everything down#43
Merged
Conversation
Destroy previously deleted only the Worker and *attempted* the R2 bucket delete — which fails on a non-empty bucket — while reporting success. Every provisioned resource (D1, KV, Hyperdrive, Queues, Vectorize, AI Gateway), the bucket + all its objects, and provisioned DNS records survived, still billing. Now Destroy: - sweeps R2 objects (S3 client, batched DeleteObjects) then deletes the bucket; - deletes every resource recorded in the encrypted cfstate manifest (incl. orphans) via the right CF API per kind, and clears/rewrites the state file; - deletes the DNS records nextdeploy added, matched by value so unrelated sibling records in the zone are never touched; - treats 404s as already-gone (idempotent), and RETURNS AN ERROR listing anything that couldn't be removed — so the operator is never told "done" while resources still exist. Extracts the R2 credential setup into ensureR2Client (shared by deploy + the teardown sweep). Adds tests covering per-kind delete routing and 404-vs-500 handling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ru3K1fyNRnyTXQ95Gmv6Su
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Destroypreviously deleted only the Worker and attempted the R2 bucket delete(which fails on a non-empty bucket) — while logging success. Every provisioned
resource (D1, KV, Hyperdrive, Queues, Vectorize, AI Gateway), the bucket + all
its objects, and provisioned DNS records survived and kept billing, with the
operator told "successfully destroyed."
Now
Destroy:DeleteObjects) then deletes the bucket.cfstatemanifest (incl. orphans) via the right CF API per kind, and clears/rewrites the state file.Extracts the R2 credential setup into
ensureR2Client(shared by deploy + teardown). Tests cover per-kind delete routing and 404-vs-500 handling.🤖 Generated with Claude Code
https://claude.ai/code/session_01Ru3K1fyNRnyTXQ95Gmv6Su