Filter requested extension templates before flag checks#7857
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents shopify app generate extension --template=... from failing due to organization Beta/ExP flag checks on unrelated remote templates by threading the requested template through template-spec fetching and filtering App Management templates before flag evaluation.
Changes:
- Extend
DeveloperPlatformClient.templateSpecificationsto accept an optional{requestedTemplate}and thread it fromgenerate→fetchExtensionTemplates. - In
AppManagementClient, pre-filter templates to the requested identifier before runningallowedTemplates(avoiding BP flag calls for unrelated templates). - Add regression tests ensuring unrelated gated templates do not trigger BP flag requests when a specific template is requested, plus a changeset for
@shopify/app.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/app/src/cli/utilities/developer-platform-client/partners-client.ts | Updates templateSpecifications signature to accept the new optional options parameter. |
| packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts | Filters templates to the requested identifier before running org flag checks. |
| packages/app/src/cli/utilities/developer-platform-client/app-management-client.test.ts | Adds regression coverage ensuring unrelated templates don’t trigger BP flag calls when requesting a specific template. |
| packages/app/src/cli/utilities/developer-platform-client.ts | Introduces TemplateSpecificationsOptions and updates the DeveloperPlatformClient interface signature. |
| packages/app/src/cli/services/generate/fetch-template-specifications.ts | Threads requested template to developerPlatformClient.templateSpecifications. |
| packages/app/src/cli/services/generate/fetch-template-specifications.test.ts | Verifies requestedTemplate is passed through to the platform client. |
| packages/app/src/cli/services/generate.ts | Passes {requestedTemplate: template} into fetchExtensionTemplates. |
| packages/app/src/cli/services/generate.test.ts | Verifies generate passes the requested template when fetching extension templates. |
| .changeset/quiet-crabs-fix.md | Patch changeset describing the user-facing fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const templatesToFilter = options.requestedTemplate | ||
| ? templates.filter((template) => template.identifier === options.requestedTemplate) | ||
| : templates |
There was a problem hiding this comment.
I agree with copilot here, that looks to be the main risk with this change.
There was a problem hiding this comment.
This is actually interesting as i could go two ways.
1. falls back to filtering the full template list with “allow all flags”(currently done). allow all flags: better diagnostic completeness, but may overstate availability.
2. deny all flags / ungated-only: safer semantics, but may under-list available gated templates.
Long term would be a new error based on “known identifiers” vs “available identifiers” but yeah
There was a problem hiding this comment.
IMO we could fall back to the current scenario of showing all templates when there's a mismatch. @isaacroldan I'm curious what you think?
There was a problem hiding this comment.
I think that's the safest solution. The main reason for this PR is because automated runs can't run the organizations query to get the beta flags, so avoidiing that if possible is great.
If the template you specified doesn't exist, we should go back to the default behaviour: Don't show in the list templates you can't really create.
This is mostly a fix for us, normal usage of --template will be authenticated and manual (even if agentic), so it'd be ok to fetch the beta flags
8fc277e to
2630997
Compare
Assisted-By: devx/a755b2ec-b72c-4514-8a02-9c47c628c61b
2630997 to
0323612
Compare

WHY are these changes introduced?
shopify app generate extension --template=discountcan fail when an unrelated extension template in the remote template list is gated by organization Beta/ExP flags.The App Management template path downloads all extension templates and evaluates flags before the requested template is resolved. If any unrelated template has
organizationExpFlags, the CLI can query Business Platform even though the requested template does not need those flags. In auth contexts that cannot call the BP Organizations flag endpoint, that unrelated flag check can fail the command.WHAT is this pull request doing?
--templatethrough extension-template fetching.@shopify/app.How to test your changes?
pnpm --filter @shopify/app exec eslint \ src/cli/services/generate.ts \ src/cli/services/generate.test.ts \ src/cli/services/generate/fetch-template-specifications.ts \ src/cli/services/generate/fetch-template-specifications.test.ts \ src/cli/utilities/developer-platform-client.ts \ src/cli/utilities/developer-platform-client/app-management-client.ts \ src/cli/utilities/developer-platform-client/app-management-client.test.ts \ src/cli/utilities/developer-platform-client/partners-client.ts pnpm --filter @shopify/app vitest --run \ src/cli/services/generate.test.ts \ src/cli/utilities/developer-platform-client/app-management-client.test.ts \ src/cli/services/generate/fetch-template-specifications.test.tsChecklist