Skip to content

[wrangler] Let CLOUDFLARE_ACCOUNT_ID override the cached account id in pages project commands - #14983

Open
kdelay wants to merge 2 commits into
cloudflare:mainfrom
kdelay:fix/pages-project-cmds-env-account-id
Open

[wrangler] Let CLOUDFLARE_ACCOUNT_ID override the cached account id in pages project commands#14983
kdelay wants to merge 2 commits into
cloudflare:mainfrom
kdelay:fix/pages-project-cmds-env-account-id

Conversation

@kdelay

@kdelay kdelay commented Aug 3, 2026

Copy link
Copy Markdown

Fixes #14970.

pages project list, pages project create and pages project delete pass 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 (getActiveAccountId in packages/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 with Authentication error [code: 10000].

This overlays the environment account id on top of the cache before resolving auth, so an explicit CLOUDFLARE_ACCOUNT_ID takes 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 config and pages secret all build the same { ...configCache, ...(envAccountId ? { account_id: envAccountId } : {}) } object. Only projects.ts was 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

vi.mock("getConfigCache", () => ({ account_id: "original-account-id", ... }));

"getConfigCache" is not a module specifier, so nothing was mocked and the cache was empty — which meant requireAuth fell through to the env var and the assertion held for the wrong reason. The three tests now seed the real cache with saveToConfigCache, matching how deployment-list.test.ts tests the same behaviour.

Verified by reverting projects.ts to main and re-running: all three fail, each requesting /accounts/original-account-id/.... With the fix they pass, and pnpm -w test:ci -F wrangler -- src/__tests__/pages is green (20 files, 283 tests). pnpm check passes.


  • 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: this restores the documented precedence of CLOUDFLARE_ACCOUNT_ID for three commands that were inconsistent with the rest of wrangler pages; no user-facing interface changes.

Note

This is a contribution from an AI agent: Claude Code, claude-opus-5.


Open in Devin Review

@kdelay
kdelay requested a review from workers-devprod as a code owner August 3, 2026 02:21
@workers-devprod
workers-devprod requested review from a team and NuroDev and removed request for a team August 3, 2026 02:21
@workers-devprod

workers-devprod commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@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 bugs or issues to report.

Open in Devin Review

Comment thread packages/wrangler/src/__tests__/pages/project-create.test.ts
Comment thread packages/wrangler/src/__tests__/pages/project-delete.test.ts
Comment thread packages/wrangler/src/__tests__/pages/project-list.test.ts
Comment thread packages/wrangler/src/__tests__/pages/project-list.test.ts
Comment thread packages/wrangler/src/pages/projects.ts
Comment thread packages/wrangler/src/pages/projects.ts
Comment thread packages/wrangler/src/pages/projects.ts
@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14983

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@14983

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@14983

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14983

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@14983

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14983

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14983

wrangler

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

commit: 0f5edfe

@kdelay
kdelay force-pushed the fix/pages-project-cmds-env-account-id branch from 42d31a2 to 1ac190e Compare August 4, 2026 00:51
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0f5edfe

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

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@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

devin-ai-integration[bot]

This comment was marked as resolved.

@NuroDev NuroDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM ✅
Thanks @kdelay

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Aug 4, 2026
@kdelay

kdelay commented Aug 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review and for merging main in.

The remaining red checks on 862b25a2 all look unrelated to this diff (which touches only packages/wrangler/src/pages/projects.ts and its three unit test files). Notes in case they save you a click:

  • C3 E2E (pnpm, Windows) - cli fails in pnpm install of the scaffolded React app, not in an assertion: ERR_PNPM_NO_MATURE_MATCHING_VERSION Version 1.2.2 (released 23 hours ago) of @rolldown/binding-android-arm64 does not meet the minimumReleaseAge constraint, reached through create-vite -> vite@8.2.0 -> rolldown@1.2.2. That version was published 2026-08-03 10:30:09 UTC and pnpm-workspace.yaml sets minimumReleaseAge: 1440, so it became installable at 2026-08-04 10:30 UTC. The three attempts that failed ran at 10:06, 10:17 and 10:25 UTC (latest), all before that. A run started after 10:30 UTC should clear it.
  • Vite Plugin E2E and the @cloudflare/vitest-pool-workers task in Tests (*, packages-and-tools) fail the same way: Command failed: pnpm install during fixture setup, with 0 failing assertions. The same signature is on an unrelated branch at the same time (Vite Plugin E2E (Linux) on emily/new-config-miniflare).
  • Tests (Windows, fixtures) fails one @fixture/dev-registry test (supports exported handler fetch over service binding), and Tests (Windows, packages-and-tools) fails miniflare browser-rendering tests. Windows fixtures is also red on emily/new-config-miniflare, there on @fixture/entrypoints-rpc.
  • Wrangler E2E was red on unenv-preset/preset.test.ts > testDns (CAA record data too short), the same test and shard that failed on emily/new-config-miniflare (job). It passed on the re-run.

One thing worth flagging: because turbo stops the run when @cloudflare/vitest-pool-workers fails early, the wrangler test task is terminated before it finishes, so the unit tests in this PR have not actually completed in CI yet. Locally on this branch pnpm -w test:ci -F wrangler -- src/__tests__/pages is 20 files / 283 tests passing and pnpm check is green. Happy to push a rebase to retrigger everything if that is easier than re-running the jobs.

@kdelay

kdelay commented Aug 4, 2026

Copy link
Copy Markdown
Author

Follow-up on my previous note, with one data point that confirms it.

C3 E2E (pnpm, Windows) - cli failed three times while running at 10:06/10:17/10:25 UTC, and the same job passed when it re-ran at 10:51-10:58 UTC on the same commit. That lines up with the minimumReleaseAge: 1440 explanation: @rolldown/binding-android-arm64@1.2.2 was published 2026-08-03T10:30:09Z, so it only became installable at 10:30 UTC today. The remaining red jobs (Vite Plugin E2E on all three OSes, Vite Plugin Playground, @cloudflare/vitest-pool-workers) all fail the same way, inside fixture setup at pnpm install with zero assertion failures, and only for the pnpm fixture variants while the npm variants pass. runCommand in the Vite plugin e2e helpers uses stdio: "pipe", so pnpm's own error text never reaches the log, which is why I can't quote it directly.

I have merged the latest main into the branch (it was three commits behind) so a fresh run would start after that maturity cutoff. Re-verified locally on the merge commit: pnpm -w test:ci -F wrangler -- src/__tests__/pages 20 files / 283 tests pass, pnpm check 201 tasks pass. The diff against main is unchanged, still the five files.

One thing I got wrong and should flag: because the push comes from a fork, the new head's workflows are sitting at "waiting for approval" rather than running, so the merge did not actually retrigger CI on its own. Happy to leave the branch alone from here if you would rather trigger the runs yourself.

kdelay added 2 commits August 11, 2026 21:16
…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.
@petebacondarwin
petebacondarwin force-pushed the fix/pages-project-cmds-env-account-id branch from a47129f to 0f5edfe Compare August 11, 2026 20:16
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@kdelay

kdelay commented Aug 12, 2026

Copy link
Copy Markdown
Author

Thanks for rebasing this. Quick triage on the two reds, since neither of them reaches code this PR touches.

C3 E2E (pnpm@11.5.1, Linux) - cli never started a test. It died in the workspace build (Tasks: 0 successful, 5 total):

@cloudflare/local-explorer-ui:build: [ERROR] Failed to switch pnpm to v10.33.0.
Looks like pnpm CLI is missing at
".../matrix-pnpm/node_modules/.bin/store/v11/links/@/pnpm/10.33.0/.../bin/pnpm"

The job installs pnpm 11.5.1 into PNPM_HOME, then the nested build switches back to the root "packageManager": "pnpm@10.33.0" and resolves the v10 binary under the v11 store layout. Earlier in the same log: [WARN] Detected a pnpm v10 installation layout at PNPM_HOME ... pnpm v11 expects bins in PNPM_HOME/bin. It is not deterministic, though — C3 E2E (pnpm@11.5.1, Linux) - workers ran the same build on this commit and passed.

Vite Plugin Playground (windows-latest, vite-8): Test Files 1 failed | 94 passed | 6 skipped, Tests 286 passed | 8 expected fail | 67 skipped, no assertion failures. The one failure is react-spa/__tests__/experimental-headers-and-redirects/react-spa.spec.ts with Error: Hook timed out in 50000ms at vitest-setup.ts:91, in a suite that ran 601s.

Both check names are red on #15130 too, there failing at miniflare#build.

The jobs that do cover this change are green on 0f5edfed: packages/wrangler/src/__tests__/pages/* runs under Tests (Linux|Windows|macOS, packages-and-tools), and all three passed.

@kdelay

kdelay commented Aug 12, 2026

Copy link
Copy Markdown
Author

Triage update on the one remaining red check, correcting what I wrote in my previous comment: Vite Plugin Playground (windows-latest, vite-8) is not flaky. It now fails deterministically, for a different reason than before, and a re-run will not clear it.

Attempt 2 (2026-08-11 20:17Z) failed with a single Hook timed out in react-spa. Attempt 3 (2026-08-12 13:15Z) failed with 8 suites instead:

Test Files  8 failed | 87 passed | 6 skipped (101)

MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start.
service core:user:worker: This Worker requires compatibility date "2026-08-12",
but the newest date supported by this server binary is "2026-08-11".

The 8 failing suites all come from three fixtures that omit compatibility_date (child-environment, prerendering, worker-♫), so they fall back to DEFAULT_COMPAT_DATE, which packages/vite-plugin-cloudflare/tsdown.config.ts inlines as new Date().toISOString().slice(0, 10) at build time. This branch pins workerd: "1.20260804.1", whose ceiling is one day behind today's build date.

Measured locally against this branch's lockfile, dispatching a trivial Worker per date:

workerd 2026-08-11 2026-08-12 2026-08-13
1.20260804.1 (this branch) ok fails, ceiling 2026-08-11 rejected as future date
1.20260811.1 (main) ok ok rejected as future date

Control: #15143 is unrelated to this change, pins the same 1.20260804.1, and its Vite Plugin Playground (windows-latest, vite-8) failed today at 13:34Z with the identical error and identical counts (8 failed | 87 passed | 6 skipped). The other OS and vite legs on this PR are green only because they last ran on 08-11.

So what clears it here is a branch update: main is 4 commits ahead and carries the workerd bump to 1.20260811.1. I have not pushed that myself, because the last time I pushed to this branch the first-contributor workflow approval gate re-armed and every check went back to un-run, including the Tests (*, packages-and-tools) legs that currently exercise this change. Glad to push a rebase if you would prefer that.

One note that may matter beyond this PR: 1.20260811.1 clears today but rejects 2026-08-13, so the same breakage returns on any branch whose pinned workerd ceiling falls behind the build date.

My diff is unchanged (packages/wrangler/src/pages/projects.ts, three unit test files, one changeset) and its tests are green on this head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

pages project list: cached pages.json.account_id still overrides explicit CLOUDFLARE_ACCOUNT_ID

4 participants