Skip to content

[stable/5.2] Skip releases that don't support the running Node when picking the auto-upgrade target - #9224

Open
craigmichaelmartin wants to merge 4 commits into
stable/5.2from
patch-backport/stable/5.2/auto-upgrade-supported-node
Open

craigmichaelmartin wants to merge 4 commits into
stable/5.2from
patch-backport/stable/5.2/auto-upgrade-supported-node

Conversation

@craigmichaelmartin

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Auto-upgrade moves the CLI to the newest non-deprecated release in its major without reading that release's engines. The next minor requires Node ^22.20.0 || >=24.5.0, so a 5.2 CLI on Node 22.12 to 22.19, 23.x or 24.0 to 24.4 would auto-upgrade into a release that doesn't support its Node: npm installs it with an EBADENGINE warning, and Yarn 1 refuses the install every day. Only a CLI that already has this check can skip such a release, so it needs to ship as a 5.2 patch before that minor.

WHAT is this pull request doing?

Backports the auto-upgrade fix from f56ab6b on main to stable/5.2 unchanged, with its patch changeset under the same file name (.changeset/auto-upgrade-supported-node.md). The version check now skips releases whose engines.node doesn't admit the running Node, so auto-upgrade stays on the newest release that supports it. Releases that declare no engines stay eligible, and the registry response the check already downloads carries engines, so there's no extra request. No package versions change here: the release workflow opens the version bump once this merges.

f56ab6b also carries an unrelated minor change (the payments extension enforce_authorization_expiry setting), which belongs in the next minor, so this backport leaves it out. Patch provenance fails on purpose for that reason: it accepts only a whole landing, and a maintainer merges this one.

How to manually test your changes?

Once a release that raises the Node floor is on npm, run any command on Node 22.19 with DEBUG=1 after clearing the CLI's version cache: the auto-upgrade target in the debug output is the newest release that still supports Node 22.19.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

🤖 Generated with Claude Code

…icking the auto-upgrade target

Backports the auto-upgrade part of f56ab6b on main: cli-version-check.ts, its tests and the
auto-upgrade-supported-node changeset. That landing also carries an unrelated minor change (the
payments extension enforce_authorization_expiry setting), which stays out of this patch line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@craigmichaelmartin
craigmichaelmartin requested a review from a team as a code owner December 4, 2026 16:59
@github-actions github-actions Bot added the Area: @shopify/cli @shopify/cli package issues label Dec 4, 2026
craigmichaelmartin added a commit that referenced this pull request Dec 4, 2026
The check's compare and commits API calls got HTTP 403 on a GitHub-hosted runner (#9224), so it
failed before judging the backport. It now reads everything with git, without a token:

- One fetch brings every commit and tree of main, the line and the pull request, without file
  contents, so merge bases and histories are exact and the depth retries go away. Git fetches a
  file's text when the check first reads it.
- The line's cut is git merge-base, still required to be one of main's landings.
- A changeset the line has had since its cut comes from git log over the line's history since the
  cut, instead of the commits and compare API calls.
- A failed read of a file's text fails the check, instead of reading as a missing file.
- The job's token gets no permissions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dmerand dmerand 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.

The backport matches main's change line for line, and it correctly leaves out the payments change. The changeset keeps main's file name. The 36 tests in cli-version-check.test.ts pass for me at this head, and Patch provenance fails as the description says it will.

One gap below. It is on main too, but it matters most on this line: this patch is the protection that must be in place before the minor that raises the Node floor.

const eligibleVersions = Object.keys(metadata.versions).filter((version) => !metadata.versions[version]?.deprecated)
const eligibleVersions = Object.keys(metadata.versions).filter((version) => {
const release = metadata.versions[version]
return !release?.deprecated && supportsRunningNode(release?.engines?.node)

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.

Worth fixing before the minor that raises the Node floor: this filter runs only when this CLI fetches. The target goes to npm-package-@shopify/cli@5.x:registry:<hash>, a key that every installed 5.x CLI shares, and versionToAutoUpgrade reads it with no Node check.

A common case: the fixed CLI is installed globally, and an app's package.json pins an older 5.x @shopify/cli. The older CLI's prerun lookup writes the unfiltered target to that key. The next global command reads it from the cache, sends no request, and auto-upgrades into a release that excludes its Node. One CLI does the same when the user switches Node versions within a day.

I proved it at this head with a temporary test. I seeded both keys with a newer release whose engines.node excludes the running Node, as an older CLI would. Then checkForNewVersionInBackground() sent 0 requests, and versionToAutoUpgrade() returned the excluded release.

Suggested fix, on main first and then here: add the running Node to the current-major key, for example a :node:${process.version} suffix, everywhere the key is written or read, getCachedCurrentMajorCLIVersion included. Older CLIs keep writing the old key, so they can't feed the new one. The cost is one more registry request per Node version per day.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, confirmed. The fix follows your suggestion: the target is now cached under a key that names the running Node, everywhere it's read or written, getCachedCurrentMajorCLIVersion included, so older CLIs can't feed it. Two new tests cover an older CLI's cached target and a Node switch, and both fail without the fix.

The same gap reached shopify upgrade and the upgrade notice, which read a cached latest that an older CLI wrote without its Node range. A cached latest now counts only when the lookup cached its range too. Otherwise the lookup runs again.

Both fixes are in one pull request for main, and you're requested on it: "Stop auto-upgrade and shopify upgrade from acting on another CLI's update check". Its backport to stable/5.2 comes after this one and the shopify upgrade backport, before 5.2.2.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/common/version.d.ts
@@ -1 +1 @@
-export declare const CLI_KIT_VERSION = "5.2.0";
\ No newline at end of file
+export declare const CLI_KIT_VERSION = "5.2.1";
\ No newline at end of file
packages/cli-kit/dist/private/node/cli-version-cache.d.ts
@@ -1,25 +1,5 @@
 import { PackageVersionKey } from './conf-store.js';
 export declare function resolveCLIRegistry(): Promise<string>;
 export declare function getCLIVersionCacheKey(registry: string, versionRange?: string): PackageVersionKey;
-export declare function getCLINodeRangeCacheKey(registry: string): PackageVersionKey;
 export declare function getPublicCLIVersionCacheKey(registry: string, versionRange?: string): PackageVersionKey;
-export declare function getCachedCLIVersion(versionRange?: string, registry?: string | undefined): string | undefined;
-/**
- * The cache entry for the Node range in a release's `engines`. It names the release, because other lookups refresh
- * the latest version on their own and must not inherit another release's range.
- *
- * @param version - The release the range belongs to.
- * @param nodeRange - Its `engines.node`, if it declares one.
- * @returns The value to cache under {@link getCLINodeRangeCacheKey}.
- */
-export declare function cliNodeRangeCacheValue(version: string, nodeRange: string | undefined): string;
-/**
- * The Node range in the `engines` of `version`, from a fresh entry the version lookup cached for that release.
- * Undefined when the release declares none, or when nothing fresh is cached for it.
- */
-export declare function getCachedCLINodeRange(version: string, registry?: string | undefined): string | undefined;
-/**
- * Whether a release whose `engines.node` is `nodeRange` supports the running Node. A release that declares no range
- * supports it.
- */
-export declare function supportsRunningNode(nodeRange: string | undefined): boolean;
\ No newline at end of file
+export declare function getCachedCLIVersion(versionRange?: string, registry?: string | undefined): string | undefined;
\ No newline at end of file
packages/cli-kit/dist/private/node/cli-version-check.d.ts
@@ -1,14 +1,8 @@
 interface CLIVersions {
     latest?: string;
     currentMajor?: string;
-    /** The Node range in the latest release's `engines`, when it declares one. */
-    latestNodeRange?: string;
 }
 export declare function getCachedCurrentMajorCLIVersion(): string | undefined;
-/**
- * The Node range in the `engines` of the cached latest release, when the version lookup cached one for it.
- */
-export declare function getCachedLatestCLINodeRange(): string | undefined;
 export declare function checkForCLIVersions({ includeCurrentMajor }?: {
     includeCurrentMajor?: boolean | undefined;
 }): Promise<CLIVersions>;
packages/cli-kit/dist/private/node/session.d.ts
@@ -61,53 +61,21 @@ export interface OAuthSession {
     appManagement?: string;
     userId: string;
 }
-/**
- * What a command analytics user ID identifies:
- *
- * - `account`: a Shopify account UUID.
- * - `store_admin_user`: the numeric ID of a user of a store's admin.
- * - `preview_store_shop`: the shop ID that a preview store created without an account reports.
- * - `credential`: a pseudonym derived from a token or a password.
- */
-export type UserIdKind = 'account' | 'store_admin_user' | 'preview_store_shop' | 'credential';
-/** A command analytics user ID and what it identifies. `kind` is `undefined` when that is not known. */
-interface AnalyticsUserId {
-    id: string;
-    kind: UserIdKind | undefined;
-}
 type AuthMethod = 'partners_token' | 'service_account_token' | 'device_auth' | 'theme_access_token' | 'custom_app_token' | 'none';
 /**
- * Retrieves a stable user identifier for analytics, and what it identifies, from one decision, so that the kind always
- * describes the ID that is returned.
+ * Retrieves a stable user identifier for analytics, or `'unknown'` if none applies.
  *
  * Evaluation order:
- * 1. If an automation token or theme token variable is set, returns a deterministic UUID derived from that secret, of
- *    kind `credential`.
- * 2. Otherwise, if `setLastSeenUserIdAfterAuth` was called (e.g. after OAuth), returns that ID and the kind recorded
- *    with it.
- * 3. Otherwise, if a persisted CLI session ID is available, returns it, of kind `account`.
- * 4. Otherwise returns `'unknown'`, of no kind.
- *
- * @returns A Promise that resolves to the user ID and its kind.
- */
-export declare function getLastSeenUserIdWithKindAfterAuth(): Promise<AnalyticsUserId>;
-/**
- * Retrieves a stable user identifier for analytics, or `'unknown'` if none applies. The ID is the one that
- * `getLastSeenUserIdWithKindAfterAuth` returns, in the same evaluation order.
+ * 1. If an app automation token or theme token is used, returns a deterministic UUID
+ *    derived from that secret.
+ * 2. Otherwise, if `setLastSeenUserIdAfterAuth` was called (e.g. after OAuth), returns that value.
+ * 3. Otherwise, if a persisted CLI session id is available, returns it.
+ * 4. Otherwise returns `'unknown'`.
  *
  * @returns A Promise that resolves to the user ID as a string.
  */
 export declare function getLastSeenUserIdAfterAuth(): Promise<string>;
-/**
- * Records the user ID of the command analytics event and what that ID identifies.
- *
- * `getLastSeenUserIdWithKindAfterAuth` returns the kind only together with this ID. A token variable takes precedence
- * over both, so that the kind never describes an ID that the event does not report.
- *
- * @param id - The user ID.
- * @param kind - What the user ID identifies. `undefined` records that it is not known.
- */
-export declare function setLastSeenUserIdAfterAuth(id: string, kind: UserIdKind | undefined): void;
+export declare function setLastSeenUserIdAfterAuth(id: string): void;
 /**
  * Retrieves the last seen authentication method used in the current session.
  *
packages/cli-kit/dist/public/node/base-command.d.ts
@@ -15,14 +15,6 @@ declare abstract class BaseCommand extends Command {
     static descriptionWithMarkdown?: string;
     static jsonOutputSchema?: JsonOutputSchema;
     static get requiresSyncAnalytics(): boolean;
-    /**
-     * Whether the command's error messages are left out of the analytics event sent to the event collector, because they
-     * can quote flag values that hold user data. The value is read before the flags are parsed, so it also covers an
-     * error raised by flag parsing.
-     *
-     * @returns `true` to leave the command's error messages out.
-     */
-    static get withholdsErrorMessageFromAnalytics(): boolean;
     static nonTTYFlagRequirements(_flags: FlagOutput): NonTTYFlagRequirement[];
     static descriptionForHelp(): string | undefined;
     /** @deprecated Use descriptionForHelp instead. */
packages/cli-kit/dist/public/node/metadata.d.ts
@@ -43,13 +43,6 @@ declare const coreData: RuntimeMetadataManager<CmdFieldsFromMonorail, {
         startTopic?: string;
         startArgs: string[];
         requiresSyncAnalytics?: boolean;
-        withholdsErrorMessageFromAnalytics?: boolean;
-    };
-    graphqlExecute: {
-        operation_type?: "query" | "mutation" | "unknown";
-        query_source?: "inline" | "file";
-        allow_mutations_flag_used?: boolean;
-        variables_used?: boolean;
     };
 } & {
     environmentFlags: string;
@@ -72,13 +65,6 @@ export declare const getAllPublicMetadata: () => Partial<CmdFieldsFromMonorail>,
         startTopic?: string;
         startArgs: string[];
         requiresSyncAnalytics?: boolean;
-        withholdsErrorMessageFromAnalytics?: boolean;
-    };
-    graphqlExecute: {
-        operation_type?: "query" | "mutation" | "unknown";
-        query_source?: "inline" | "file";
-        allow_mutations_flag_used?: boolean;
-        variables_used?: boolean;
     };
 } & {
     environmentFlags: string;
@@ -100,13 +86,6 @@ export declare const getAllPublicMetadata: () => Partial<CmdFieldsFromMonorail>,
         startTopic?: string;
         startArgs: string[];
         requiresSyncAnalytics?: boolean;
-        withholdsErrorMessageFromAnalytics?: boolean;
-    };
-    graphqlExecute: {
-        operation_type?: "query" | "mutation" | "unknown";
-        query_source?: "inline" | "file";
-        allow_mutations_flag_used?: boolean;
-        variables_used?: boolean;
     };
 } & {
     environmentFlags: string;
packages/cli-kit/dist/public/node/session.d.ts
@@ -20,11 +20,8 @@ export type AccountInfo = UserAccountInfo | ServiceAccountInfo | UnknownAccountI
  * Records the user ID that should be attached to command analytics for this process.
  *
  * @param userId - User identifier to report on the command analytics event.
- * @param kind - What the user ID identifies: a Shopify account UUID (`account`), the numeric ID of a user of a store's
- * admin (`store_admin_user`), the shop ID that a preview store created without an account reports
- * (`preview_store_shop`), or a pseudonym derived from a token or a password (`credential`). Omit it when it is not known.
  */
-export declare function setLastSeenUserId(userId: string, kind?: 'account' | 'store_admin_user' | 'preview_store_shop' | 'credential'): void;
+export declare function setLastSeenUserId(userId: string): void;
 /**
  * Finds a stored Shopify account session by alias without changing the current session.
  *
packages/cli-kit/dist/public/node/store-auth-session.d.ts
@@ -103,17 +103,6 @@ export declare function clearStoredStoreAppSession(store: string, userIdOrStorag
  * @returns An Admin session, or undefined when no usable session is cached.
  */
 export declare function getStoreAuthAdminSession(store: string, storage?: LocalStorage<StoreAuthSessionSchema>): AdminSession | undefined;
-/**
- * What the user ID of a stored store auth session identifies, for command analytics.
- *
- * - A standard session's user ID is the numeric ID of a user of the store's admin.
- * - A preview store created without an account reports its shop ID as the user ID.
- * - A preview store created with a placeholder account reports that account's UUID.
- *
- * @param session - The stored store auth session.
- * @returns The kind of the session's user ID.
- */
-export declare function storedSessionUserIdKind(session: StoredStoreAppSession): 'account' | 'store_admin_user' | 'preview_store_shop';
 /**
  * Check whether a stored store auth session is expired, including the refresh margin.
  *

This branch has not been deployed

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

Labels

Area: @shopify/cli @shopify/cli package issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants