Skip to content

WC-5233 use patch apis for wrangler preview secret commands - #15043

Open
podonnell-dev wants to merge 3 commits into
cloudflare:mainfrom
podonnell-dev:podonnell/WC-5233-use-patch-apis-preview-secrets
Open

WC-5233 use patch apis for wrangler preview secret commands#15043
podonnell-dev wants to merge 3 commits into
cloudflare:mainfrom
podonnell-dev:podonnell/WC-5233-use-patch-apis-preview-secrets

Conversation

@podonnell-dev

@podonnell-dev podonnell-dev commented Aug 5, 2026

Copy link
Copy Markdown

Fixes WC-5233

Use PATCH APIs for wrangler preview secret commands. Removing the dependence on preview_defaults - all preview secret commands now patch secrets for the latest preview deployment. Also adjusted file conventions to match #14448 more closely

Reviewable, but ask Patrick before merging - we'll be trying to time this release for next week


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: refactor

A picture of a cute animal (not mandatory, but encouraged)


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b3c9db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Minor
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
workers-devprod requested review from a team and jamesopstad and removed request for a team August 5, 2026 16:49
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/preview-secret-per-preview.md: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/preview/api.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/preview.secret.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/commands.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/delete.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/preview.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/secret.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/secrets/bulk.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/secrets/delete.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/secrets/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/secrets/list.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/secrets/put.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/settings.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

PREVIEW_NOT_FOUND_ERR_CODE,
previewNotFoundMessage,
resolvePreviewName,
} from "./index";

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

open to making this easier to distinguish - maybe a shared.ts or something similar

);
}

function mockGetPreviewDeploymentError(code: number) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

diff between this and mockPreviewDeploymentNotFound?

expect,
}) => {
mockStdIn.send("preview-secret");
let patchedPreviewDefaults = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't really need the assertion that we aren't patching preview defaults any more. that's just cruft lying around from the previous design.

Comment on lines +417 to +459
test("reads the latest Preview deployment and lists secrets as JSON", async ({
expect,
}) => {
let requestUrl: string | undefined;
mockGetLatestPreviewDeployment(
{
DB_PASSWORD: { type: "secret_text" },
API_KEY: { type: "secret_text" },
PUBLIC_VAR: { type: "plain_text", text: "visible" },
},
({ url }) => {
requestUrl = url;
}
);
await runWrangler(
"preview secret list --json --worker-name test-worker"
"preview secret list --json --name test-preview --worker-name test-worker"
);
expect(requestUrl).toContain(
"/workers/workers/test-worker/previews/test-preview/deployments/latest"
);
expect(std.out).toContain('"name": "DB_PASSWORD"');
expect(std.out).toContain('"name": "API_KEY"');
expect(std.out).toContain('"type": "secret_text"');
expect(std.out).not.toContain("PUBLIC_VAR");
});

test("should list secrets in pretty format", async ({ expect }) => {
msw.use(
http.get(`*/accounts/:accountId/workers/workers/:workerId`, () =>
HttpResponse.json({
success: true,
result: {
preview_defaults: {
env: {
MY_SECRET: { type: "secret_text" },
PLAIN: { type: "plain_text", text: "not-a-secret" },
},
},
},
})
)
test("should list secrets in pretty format with values masked", async ({
expect,
}) => {
mockGetLatestPreviewDeployment({
MY_SECRET: { type: "secret_text", text: "super-secret-value" },
PLAIN: { type: "plain_text", text: "not-a-secret" },
});
await runWrangler(
"preview secret list --name test-preview --worker-name test-worker"
);
await runWrangler("preview secret list --worker-name test-worker");
expect(std.out).toContain("Worker: test-worker");
expect(std.out).toContain("Previews settings");
expect(std.out).toContain("Secrets");
expect(std.out).toContain("MY_SECRET");
expect(std.out).not.toContain("PLAIN");
expect(std.out).toContain("********");
expect(std.out).not.toContain("super-secret-value");
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe a matrix test for "can handle no text value provided" vs. "masks text value if provided" and "json" vs. "pretty"?

);
});

test("creates a deployment with an empty patch for null-only input", async ({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is skipping over null values current behavior?

if they're all null, should we error as if no input was provided?

export const previewSecretBulkCommand = createCommand({
metadata: {
description:
"Upload multiple secrets to a Worker Preview's latest deployment",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Upload multiple secrets to a Worker Preview's latest deployment",
"Upload multiple secrets to a Worker Preview and create a new deployment",

export const previewSecretDeleteCommand = createCommand({
metadata: {
description:
"Delete a secret variable from a Worker Preview's latest deployment",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Delete a secret variable from a Worker Preview's latest deployment",
"Delete a secret variable from a Worker Preview and create a new deployment",

@GregBrimble GregBrimble left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only other thing I'd consider testing is: no preview name provided and not in a git worktree.

export const noPreviewDeploymentPatchMessage = (previewName: string) =>
`There are currently no deployments for the Preview "${previewName}". Please create a Preview deployment before modifying a secret.`;
export const noPreviewDeploymentListMessage = (previewName: string) =>
`There are currently no deployments for the Preview "${previewName}" - please create a Preview deployment.`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
`There are currently no deployments for the Preview "${previewName}" - please create a Preview deployment.`;
`There are currently no deployments for the Preview "${previewName}". Please create a Preview deployment.`;

✨ consistency ✨

@dario-piotrowicz
dario-piotrowicz requested review from dario-piotrowicz and removed request for jamesopstad August 6, 2026 11:05
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.

3 participants