Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect config.account_id in wrangler dev --remote #6963

Merged
merged 5 commits into from
Oct 16, 2024

Conversation

RamIdeas
Copy link
Contributor

@RamIdeas RamIdeas commented Oct 14, 2024

What this PR solves / how to test

Fixes #6947

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Changeset included
    • Changeset not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: fix

@RamIdeas RamIdeas requested a review from a team as a code owner October 14, 2024 14:11
Copy link

changeset-bot bot commented Oct 14, 2024

🦋 Changeset detected

Latest commit: c08ea41

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

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

@RamIdeas RamIdeas force-pushed the fix-config-accountid-dev-remote branch from 6fd39ba to a473b1c Compare October 14, 2024 14:12
accountId = await requireAuth({});
accountId = await requireAuth(config);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

main fix for wrangler dev --remote

}

return {
accountId: config.account_id ?? (await getAccountId()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix default for startWorker

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean config has a precedent over the env variable?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably use the requireAuth() helper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably use the requireAuth() helper

5396ab5

Does this mean config has a precedent over the env variable?

Yes. Which matches previous behaviour unless I'm mistaken?

Copy link
Contributor

@Skye-31 Skye-31 Oct 15, 2024

Choose a reason for hiding this comment

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

Yes. Which matches previous behaviour unless I'm mistaken

So it does, that behaviour is surprising

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's surprising. IMO order of precedence: cli args > config file > env vars, because env vars can be set across projects, config file per project, cli args per command – the specificity is clear.

I can understand setting an env var inline and expecting that to take precedence (eg CLOUDFLARE_ACCOUNT_ID=1234 npx wrangler deploy) but instead the cli arg should be used for that use-case (eg. npx wrangler deploy --account-id 1234) because that env var could've come from the eg ~/.zshrc file

Copy link
Contributor

Choose a reason for hiding this comment

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

I've never seen --account-id before - it doesn't seem to be documented 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh you're right! We should add one to support per command overrides with higher precedence than the config file

Comment on lines +57 to +59
if (input.dev?.auth) {
return unwrapHook(input.dev.auth, config);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

provide (wrangler.toml) config to the hook fn as param

Copy link
Contributor

github-actions bot commented Oct 14, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-wrangler-6963

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6963/npm-package-wrangler-6963

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-wrangler-6963 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-create-cloudflare-6963 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-kv-asset-handler-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-miniflare-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-pages-shared-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-vitest-pool-workers-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-workers-editor-shared-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-workers-shared-6963

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.80.4 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241004.0
workerd 1.20241011.1 1.20241011.1
workerd --version 1.20241011.1 2024-10-11

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@@ -129,7 +129,7 @@ export interface StartDevWorkerInput {
/** Whether the worker runs on the edge or locally. */
remote?: boolean;
/** Cloudflare Account credentials. Can be provided upfront or as a function which will be called only when required. */
auth?: AsyncHook<CfAccount>;
auth?: AsyncHook<CfAccount, [Pick<Config, "account_id">]>; // provide config.account_id as a hook param
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only the ConfigController has access to the wrangler.toml config so enable it as a hook param for StartDevWorkerInput.dev.auth

@@ -187,6 +187,7 @@ export type StartDevWorkerOptions = Omit<StartDevWorkerInput, "assets"> & {
};
dev: StartDevWorkerInput["dev"] & {
persist: string;
auth?: AsyncHook<CfAccount>; // redefine without config.account_id hook param (can only be provided by ConfigController with access to wrangler.toml, not by other controllers eg RemoteRuntimeContoller)
Copy link
Contributor Author

@RamIdeas RamIdeas Oct 14, 2024

Choose a reason for hiding this comment

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

Other controllers won't have access to the wrangler.toml config file so redefine this without a hook param on StartDevWorkerOptions.dev.auth

Copy link
Contributor

Choose a reason for hiding this comment

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

How will this work if e.g. the remote runtime controller unwraps the hook? Will that not fail?

Copy link
Contributor Author

@RamIdeas RamIdeas Oct 14, 2024

Choose a reason for hiding this comment

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

Only the ConfigController unwraps this hook. The ConfigController overwrites this property with a new hook that does not expect a param – this new hook is then unwrapped by the RemoteRuntimeController

});
const auth = async () => {
if (input.dev?.auth) {
return unwrapHook(input.dev.auth, config);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is the same behaviour. This seems to unconditionally unwrap the hook if provided, even if not in remote mode?

Copy link
Contributor Author

@RamIdeas RamIdeas Oct 14, 2024

Choose a reason for hiding this comment

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

It doesn't unconditionally unwrap the hook. It unconditionally sets the auth property with its own hook which will unwrap the original property when itself is unwrapped. Therefore it is still conditionally unwrapped as before

(This diff answers your other question. https://github.com/cloudflare/workers-sdk/pull/6963/files#r1799613869)

@@ -187,6 +187,7 @@ export type StartDevWorkerOptions = Omit<StartDevWorkerInput, "assets"> & {
};
dev: StartDevWorkerInput["dev"] & {
persist: string;
auth?: AsyncHook<CfAccount>; // redefine without config.account_id hook param (can only be provided by ConfigController with access to wrangler.toml, not by other controllers eg RemoteRuntimeContoller)
Copy link
Contributor

Choose a reason for hiding this comment

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

How will this work if e.g. the remote runtime controller unwraps the hook? Will that not fail?

Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

@RamIdeas RamIdeas added the e2e Run e2e tests on a PR label Oct 15, 2024
@RamIdeas RamIdeas merged commit a5ac45d into main Oct 16, 2024
22 checks passed
@RamIdeas RamIdeas deleted the fix-config-accountid-dev-remote branch October 16, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

🐛 BUG: on by default: –x-dev-env causes issue with multiple accounts
4 participants