Skip to content

[vitest-pool-workers] Add adminSecretsStore() to cloudflare:test#13073

Merged
penalosa merged 4 commits intomainfrom
penalosa/vitest-12778
Mar 27, 2026
Merged

[vitest-pool-workers] Add adminSecretsStore() to cloudflare:test#13073
penalosa merged 4 commits intomainfrom
penalosa/vitest-12778

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Mar 26, 2026

Fixes #12778.

Secrets store bindings only expose a read-only .get() method, so there was previously no way to seed secret values from within a test. This adds adminSecretsStore() to cloudflare:test — a thin wrapper that returns Miniflare's existing admin API for a secrets store binding, giving tests full control over create/update/delete operations.

import { adminSecretsStore } from "cloudflare:test";
import { env } from "cloudflare:workers";

const admin = adminSecretsStore(env.MY_SECRET);
await admin.create("test-value");

const value = await env.MY_SECRET.get(); // "test-value"

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 26, 2026

🦋 Changeset detected

Latest commit: 0782d74

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

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

⚠️ Issues found

File: .changeset/vitest-pool-workers-secrets-store-persist.md

Issue: Version type should be minor, not patch

The changeset introduces a new exported helper function adminSecretsStore() in the cloudflare:test module. Per the changeset guidelines:

minor: New features, new CLI commands, new configuration options, deprecations...

Adding a new public API (adminSecretsStore()) is a new feature and warrants a minor bump. patch is reserved for bug fixes and small improvements, not new functionality.

The description, code example, and markdown formatting are all good — only the version type needs to be corrected to minor.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 26, 2026

Now I have a thorough understanding of the changes. Let me verify the interface signatures match the actual implementation:

Looking at the miniflare implementation in secret.worker.ts:

  • create(value: string) => Promise<string> - matches
  • update(value: string, id: string) => Promise<string> - matches
  • duplicate(id: string, newName: string) => Promise<string> - matches
  • delete(id: string) => Promise<void> - matches
  • list() returns keys from KVNamespace.list<{ uuid: string }>() which is { name: string; metadata?: { uuid: string } }[] - matches
  • get(id: string) => Promise<string> (returns secret.name) - matches

Everything looks correct. The SecretsStoreSecretAdmin interface in both secrets-store.ts and cloudflare-test.d.ts matches the actual miniflare implementation. The ADMIN_API constant is correctly duplicated with a clear comment about where it's sourced from. The type declarations are well-documented. The test covers the primary use case. The export wiring through test-internal.ts and test.ts follows the established pattern.

LGTM

github run

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 26, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13073

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13073

miniflare

npm i https://pkg.pr.new/miniflare@13073

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13073

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13073

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13073

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13073

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13073

wrangler

npm i https://pkg.pr.new/wrangler@13073

commit: 0782d74

Secrets store bindings only expose .get(), so there was no way to seed
values in vitest-pool-workers tests. This exposes Miniflare's admin API
through a new cloudflare:test import, giving tests create/update/delete
access.

Fixes #12778
@penalosa penalosa force-pushed the penalosa/vitest-12778 branch from 3a466de to fb8cbd1 Compare March 27, 2026 00:54
… coverage

- Export SECRETS_STORE_ADMIN_API constant and SecretsStoreSecretAdmin
  interface from miniflare instead of duplicating them
- Import ADMIN_API from miniflare source (same pattern as devalue import)
- Import SecretsStoreSecretAdmin type from miniflare
- Exercise create, update, list, and delete in the test
@penalosa penalosa marked this pull request as ready for review March 27, 2026 01:19
@penalosa penalosa requested a review from a team as a code owner March 27, 2026 01:19
@penalosa penalosa requested a review from jamesopstad March 27, 2026 01:19
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 27, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

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

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

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 27, 2026
@penalosa penalosa merged commit baec845 into main Mar 27, 2026
50 of 53 checks passed
@penalosa penalosa deleted the penalosa/vitest-12778 branch March 27, 2026 13:22
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

vitest-pool-workers silently ignores secretsStorePersist — secrets store bindings always empty in tests

3 participants