Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/rotten-glasses-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"wrangler": patch
---

Improves the Wrangler auto-provisioning feature (gated behind the experimental flag `--x-provision`) by:

- Writing back changes to the user's config file (not necessary, but can make it resilient to binding name changes)
- Fixing `--dry-run`, which previously threw an error when your config file had auto provisioned resources
- Improve R2 bindings display to include the `bucket_name` from the config file on upload
- Fixing bindings view for specific versions to not display TOML
127 changes: 81 additions & 46 deletions packages/wrangler/e2e/provision.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert";
import dedent from "ts-dedent";
import { fetch } from "undici";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { afterAll, beforeEach, describe, expect, it } from "vitest";
import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id";
import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test";
import { fetchText } from "./helpers/fetch-text";
Expand Down Expand Up @@ -38,23 +38,27 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
expect(text).toMatchInlineSnapshot(`"Hello World!"`);
});

beforeAll(async () => {
beforeEach(async () => {
await helper.seed({
"wrangler.toml": dedent`
name = "${workerName}"
main = "src/index.ts"
compatibility_date = "2023-01-01"
workers_dev = true
[[kv_namespaces]]
binding = "KV"
[[kv_namespaces]]
binding = "KV"
[[r2_buckets]]
binding = "R2"
[[r2_buckets]]
binding = "R2"
[[d1_databases]]
binding = "D1"
`,
[[r2_buckets]]
binding = "R2_WITH_NAME"
bucket_name = "does-not-exist"
[[d1_databases]]
binding = "D1"
`,
"src/index.ts": dedent`
export default {
fetch(request) {
Expand All @@ -76,32 +80,33 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
await worker.exitCode;
const output = await worker.output;
expect(normalize(output)).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
The following bindings need to be provisioned:
Binding Resource
env.KV KV Namespace
env.D1 D1 Database
env.R2 R2 Bucket
Provisioning KV (KV Namespace)...
🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv"...
✨ KV provisioned 🎉
Provisioning D1 (D1 Database)...
🌀 Creating new D1 Database "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-d1"...
✨ D1 provisioned 🎉
Provisioning R2 (R2 Bucket)...
🌀 Creating new R2 Bucket "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2"...
✨ R2 provisioned 🎉
🎉 All resources provisioned, continuing with deployment...
Your Worker has access to the following bindings:
Binding Resource
env.KV (00000000000000000000000000000000) KV Namespace
env.D1 (00000000-0000-0000-0000-000000000000) D1 Database
env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2) R2 Bucket
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
Current Version ID: 00000000-0000-0000-0000-000000000000"
`);
"Total Upload: xx KiB / gzip: xx KiB
The following bindings need to be provisioned:
Binding Resource
env.KV KV Namespace
env.D1 D1 Database
env.R2 R2 Bucket
Provisioning KV (KV Namespace)...
🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv"...
✨ KV provisioned 🎉
Provisioning D1 (D1 Database)...
🌀 Creating new D1 Database "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-d1"...
✨ D1 provisioned 🎉
Provisioning R2 (R2 Bucket)...
🌀 Creating new R2 Bucket "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2"...
✨ R2 provisioned 🎉
🎉 All resources provisioned, continuing with deployment...
Your Worker has access to the following bindings:
Binding Resource
env.KV (00000000000000000000000000000000) KV Namespace
env.D1 (00000000-0000-0000-0000-000000000000) D1 Database
env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2) R2 Bucket
env.R2_WITH_NAME (does-not-exist) R2 Bucket
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
Current Version ID: 00000000-0000-0000-0000-000000000000"
`);
const urlMatch = output.match(
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
);
Expand Down Expand Up @@ -130,25 +135,55 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
await worker.exitCode;
const output = await worker.output;
expect(normalize(output)).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Your Worker has access to the following bindings:
Binding Resource
env.KV (inherited) KV Namespace
env.D1 (inherited) D1 Database
env.R2 (inherited) R2 Bucket
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
Current Version ID: 00000000-0000-0000-0000-000000000000"
`);
"Total Upload: xx KiB / gzip: xx KiB
Your Worker has access to the following bindings:
Binding Resource
env.KV (inherited) KV Namespace
env.D1 (inherited) D1 Database
env.R2 (inherited) R2 Bucket
env.R2_WITH_NAME (does-not-exist) R2 Bucket
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
Current Version ID: 00000000-0000-0000-0000-000000000000"
`);

const response = await retry(
(resp) => !resp.ok,
async () => await fetch(deployedUrl)
);
await expect(response.text()).resolves.toEqual("Hello World!");
});
it("can inspect current bindings", async () => {
const versionsRaw = await helper.run(
`wrangler versions list --json --x-provision`
);

const versions = JSON.parse(versionsRaw.stdout) as unknown[];

const latest = versions.at(-1) as { id: string };

const versionView = await helper.run(
`wrangler versions view ${latest.id} --x-provision`
);

expect(normalizeOutput(versionView.output)).toMatchInlineSnapshot(`
"Version ID: 00000000-0000-0000-0000-000000000000
Created: TIMESTAMP
Author:
Source: Unknown (version_upload)
Tag: -
Message: -
Handlers: fetch
Compatibility Date: 2023-01-01
Your Worker has access to the following bindings:
Binding Resource
env.KV (00000000000000000000000000000000) KV Namespace
env.D1 (00000000-0000-0000-0000-000000000000) D1 Database
env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2) R2 Bucket
env.R2_WITH_NAME (does-not-exist) R2 Bucket"
`);
});
it("can inherit and provision resources on version upload", async () => {
await helper.seed({
"wrangler.toml": dedent`
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/e2e/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
Source: Unknown (version_upload)
Tag: e2e-upload-assets
Message: Upload via e2e test
------------------------------------------------------------
Compatibility Date: 2023-01-01"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2820,6 +2820,7 @@ describe("normalizeAndValidateConfig()", () => {
MULTIWORKER: false,
REMOTE_BINDINGS: false,
DEPLOY_REMOTE_DIFF_CHECK: false,
AUTOCREATE_RESOURCES: false,
},
() =>
normalizeAndValidateConfig(
Expand Down Expand Up @@ -2977,6 +2978,7 @@ describe("normalizeAndValidateConfig()", () => {
MULTIWORKER: false,
REMOTE_BINDINGS: false,
DEPLOY_REMOTE_DIFF_CHECK: false,
AUTOCREATE_RESOURCES: false,
},
() =>
normalizeAndValidateConfig(
Expand Down Expand Up @@ -3316,6 +3318,7 @@ describe("normalizeAndValidateConfig()", () => {
MULTIWORKER: false,
REMOTE_BINDINGS: false,
DEPLOY_REMOTE_DIFF_CHECK: false,
AUTOCREATE_RESOURCES: false,
},
() =>
normalizeAndValidateConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ describe("dev with remote bindings", { sequential: true }, () => {
name: "EMAIL",
remote: true,
remoteProxyConnectionString,
type: "send_email",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ describe("experimental_getWranglerCommands", () => {
"requiresArg": true,
"type": "string",
},
"experimental-auto-create": Object {
"alias": "x-auto-create",
"default": true,
"describe": "Automatically provision draft bindings with new resources",
"hidden": true,
"type": "boolean",
},
"experimental-provision": Object {
"alias": Array [
"x-provision",
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ describe("metrics", () => {
command: "wrangler docs",
args: {
xRemoteBindings: true,
xAutoCreate: true,
search: ["<REDACTED>"],
},
};
Expand Down
Loading
Loading