[wrangler] Let CLOUDFLARE_ACCOUNT_ID override the cached account id in pages project commands - #14983
Open
kdelay wants to merge 1 commit into
Open
[wrangler] Let CLOUDFLARE_ACCOUNT_ID override the cached account id in pages project commands#14983kdelay wants to merge 1 commit into
kdelay wants to merge 1 commit into
Conversation
…n pages project commands
pages project list, create and delete passed the internal Pages cache
(pages.json) straight to requireAuth. Account selection treats
config.account_id as user-authored configuration and ranks it above
CLOUDFLARE_ACCOUNT_ID, so a stale cached account silently won and the
command targeted the wrong account.
Overlay the environment account id on top of the cache before resolving
auth, matching what pages deploy, pages deployment list, pages
deployment delete, pages download config and pages secret already do.
The three existing "should override cached accountId" tests used
vi.mock("getConfigCache", ...), which mocks a module specifier that does
not exist, so the cache was empty and the assertions passed against the
bug. They now seed the real cache with saveToConfigCache and fail
without the fix.
workers-devprod
requested review from
a team and
NuroDev
and removed request for
a team
August 3, 2026 02:21
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
joe345-str
reviewed
Aug 3, 2026
| { once: true } | ||
| ) | ||
| ); | ||
| vi.mock("getConfigCache", () => { |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
| text: `Are you sure you want to delete "an-existing-project"? This action cannot be undone.`, | ||
| result: true, | ||
| }); | ||
| vi.mock("getConfigCache", () => { |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
| import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id"; | ||
| import { msw } from "./../helpers/msw"; | ||
| import { runWrangler } from "./../helpers/run-wrangler"; | ||
| import type { Project } from "./../../pages/types"; |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
| it("should override cached accountId with CLOUDFLARE_ACCOUNT_ID environmental variable if provided", async ({ | ||
| expect, | ||
| }) => { | ||
| vi.mock("getConfigCache", () => { |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
| PAGES_CONFIG_CACHE_FILENAME | ||
| ); | ||
|
|
||
| const accountId = await requireAuth(config); |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
| const config = getConfigCache<PagesConfigCache>( | ||
| PAGES_CONFIG_CACHE_FILENAME | ||
| ); | ||
| const accountId = await requireAuth(config); |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
| const config = getConfigCache<PagesConfigCache>( | ||
| PAGES_CONFIG_CACHE_FILENAME | ||
| ); | ||
| const accountId = await requireAuth(config); |
There was a problem hiding this comment.
Signoff: joe345-str/joeydonner1979@gmail.com
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.
Fixes #14970.
pages project list,pages project createandpages project deletepass the internal Pages cache (pages.json) straight torequireAuth(). Account selection treatsconfig.account_idas user-authored configuration and ranks it aboveCLOUDFLARE_ACCOUNT_ID(getActiveAccountIdinpackages/workers-auth/src/core/factory.ts), so a stale cached account silently wins. In a multi-account setup the command then targets the wrong account and fails withAuthentication error [code: 10000].This overlays the environment account id on top of the cache before resolving auth, so an explicit
CLOUDFLARE_ACCOUNT_IDtakes precedence and the cache stays a fallback. That is what the rest of the Pages commands already do:pages deploy,pages deployment list,pages deployment delete,pages download configandpages secretall build the same{ ...configCache, ...(envAccountId ? { account_id: envAccountId } : {}) }object. Onlyprojects.tswas missing it.On the tests
Each of the three commands already had a test named "should override cached accountId with CLOUDFLARE_ACCOUNT_ID environmental variable if provided", and all three passed against the bug. They seeded the cache with
"getConfigCache"is not a module specifier, so nothing was mocked and the cache was empty — which meantrequireAuthfell through to the env var and the assertion held for the wrong reason. The three tests now seed the real cache withsaveToConfigCache, matching howdeployment-list.test.tstests the same behaviour.Verified by reverting
projects.tstomainand re-running: all three fail, each requesting/accounts/original-account-id/.... With the fix they pass, andpnpm -w test:ci -F wrangler -- src/__tests__/pagesis green (20 files, 283 tests).pnpm checkpasses.CLOUDFLARE_ACCOUNT_IDfor three commands that were inconsistent with the rest ofwrangler pages; no user-facing interface changes.Note
This is a contribution from an AI agent: Claude Code, claude-opus-5.