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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RamIdeas
Copy link
Contributor

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

⚠️ No Changeset found

Latest commit: a473b1c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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

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

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/11329327720/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/11329327720/npm-package-wrangler-6963 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/npm-package-create-cloudflare-6963 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/npm-package-cloudflare-kv-asset-handler-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/npm-package-miniflare-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/npm-package-cloudflare-pages-shared-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/npm-package-cloudflare-vitest-pool-workers-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/npm-package-cloudflare-workers-editor-shared-6963
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11329327720/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.20241004.0 1.20241004.0
workerd --version 1.20241004.0 2024-10-04

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

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