Fix resolveArmResources incorrectly merging cross-scope LegacyOperations into a single resource#4072
Fix resolveArmResources incorrectly merging cross-scope LegacyOperations into a single resource#4072
Conversation
Add scope prefix comparison to isResourceOperationMatch when resource names are not explicitly provided. This prevents operations at different scopes (e.g., subscription vs tenant) from being incorrectly merged into a single resource when they share the same model. When a resource name is explicitly provided via the ResourceName parameter of LegacyOperations, matching continues to use the name for grouping, allowing intentional cross-scope merging. Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
|
/azp run typespec-azure - PR Tools |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
All changed packages have been documented.
Show changes
|
commit: |
|
@copilot the consistency check is reporting a divergence between your branch and main. Please pull the latest, fix any conflicts and push the results. |
…ss-scope-legacyoperations
Merged latest from main (commit |
|
You can try these changes here
|
|
/azp run typespec-azure - PR Tools |
|
Azure Pipelines successfully started running 1 pipeline(s). |
resolveArmResourcesmerges cross-scopeLegacyOperationsinto a single resource when they share the same modelisResourceOperationMatchmatches by resource name + provider + types but ignores scope prefixisResourceOperationMatchwhen resource names are not explicitly providedResolvedResourceOperationsandResolvedResourceInfointerfaces to trackresourceNameIsExplicitresolveArmResourceOperationsto pass explicit name flag through matchingisResourceOperationMatchwith scope prefix comparisonOriginal prompt
This section details on the original issue you should resolve
<issue_title>resolveArmResources incorrectly merges cross-scope LegacyOperations into a single resource</issue_title>
<issue_description>## Description
resolveArmResourcesin@azure-tools/typespec-azure-resource-managerincorrectly merges cross-scopeLegacyOperationsthat share the same model into a single resource, instead of separating them into distinct resources per scope.This affects real-world patterns like the Support SDK, where
SupportTicketDetails(decorated with@subscriptionResource) is used by both subscription-scoped (SupportTickets) and tenant-scoped (SupportTicketsNoSubscription) interfaces viaLegacyOperations.Reproduction
Expected behavior
resolveArmResourcesshould produce 2 separate resources (one per scope):resourceInstancePath: "/subscriptions/{subscriptionId}/providers/.../supportTickets/{supportTicketName}",scope: "Subscription", and its own lifecycle read + list operationsresourceInstancePath: "/providers/.../supportTickets/{supportTicketName}",scope: "Tenant", and its own lifecycle read + list operationsActual behavior
resolveArmResourcesreturns 1 merged resource:The operations from both scopes are merged into a single resource. The individual operations do retain their correct paths (e.g.,
lifecycle.read[1]has the tenant path/providers/.../supportTickets/{name}), but the resource-levelscopeis"Subscription"and only the subscriptionresourceInstancePathis used.Affected package
packages/typespec-azure-resource-manager/src/resource.ts—resolveArmResourcesfunction</issue_description>
<agent_instructions>@copilot The matching of operations with a ResolvedResource in resolveArmResources should use the resourceName whenever it is explicitly provided as a parameter to the operation template. However, if the resourceName is simply the default (derived from the resource model), matching should depend on the scope. SPecifically, operations at the tenant level should not be matched with subscription-level operations.
Please add some tests that check these rules, ensure that they fail in the mentioned case, and then update the logic for matching in resolveArmResources to make the succeed. As always, make sure that all tests are passing, that there are no formatting errors and no misspellings and that you update your pr with the latest from the main rbanch.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@markcowl @ArcturusZhang This is unexpected, but there is a workaround until the logic is fixed. You can explicitly supply the resource name, which ch...💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.