Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

  • Analyze the existing resource detection logic in resource-detection.ts
  • Understand the resolveArmResources API from @azure-tools/typespec-azure-resource-manager
  • Review existing tests to understand expected behavior
  • Investigate resolveArmResources API behavior and document findings
  • Document findings and current limitations in the code
  • Add comprehensive test file resolve-arm-resources-validation.test.ts with:
    • All test cases from resource-detection.test.ts using resolveArmResources API
    • Tests demonstrating all 5 bugs with reference to existing TypeSpec (bar.tsp)
  • All 40 tests pass (1 skipped for expected bug behavior)
  • Code review completed - no critical issues
  • CodeQL security scan passed - no alerts

Summary

The resolveArmResources API (v0.62.0) from @azure-tools/typespec-azure-resource-manager has 5 confirmed bugs that prevent direct replacement of the decorator-based resource detection logic:

Bug Description
#1 Multiple singletons with different @singleton keys are not distinguished
#2 Singleton child resources return incorrect resourceInstancePath
#3 Duplicate resources returned for the same model
#4 Parent is undefined even with @parentResource decorator
#5 Resource type uses parent's type instead of full path

Next Steps

  1. Report bugs to TypeSpec ARM team at https://github.com/Azure/typespec-azure
  2. Wait for fixes in the TypeSpec ARM library
  3. Complete the replacement after fixes are available
Original prompt

This section details on the original issue you should resolve

<issue_title>replace existing resource detection in mgmt emitter with resolveArmResources API</issue_title>
<issue_description>resolveArmResources API is at https://github.com/Azure/typespec-azure/blob/77e7ea23e694af2ef44d2885bf8db75d77c47bfe/packages/typespec-azure-resource-manager/src/resource.ts#L447

We need to replace the logic in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts with resolveArmResources API
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ations

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace existing resource detection with resolveArmResources API Document resolveArmResources API limitations for resource detection replacement Nov 28, 2025
Copilot AI requested a review from live1206 November 28, 2025 08:21
Copilot finished work on behalf of live1206 November 28, 2025 08:21
@live1206
Copy link
Member

live1206 commented Dec 1, 2025

@copilot could you set up a test to demonstrate the bug in resolveArmResources API in this PR?

…gletons

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot could you set up a test to demonstrate the bug in resolveArmResources API in this PR?

Added test file resolve-arm-resources-bug.test.ts in commit 73e7465 that demonstrates the bug. The test shows that when multiple singleton resources are defined with different @singleton keys (Employee with default key and CurrentEmployee with "current" key), resolveArmResources returns all resources with type.name === "Employee" instead of distinguishing CurrentEmployee.

The test file includes:

  • A skipped test (it.skip) showing expected behavior (will pass when bug is fixed)
  • A passing test that validates the current buggy behavior

Copilot finished work on behalf of live1206 December 1, 2025 03:19
@live1206
Copy link
Member

live1206 commented Dec 1, 2025

@copilot apart from the failing case you found before.
Can you try to verify the existing cases in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/emitter/test/resource-detection.test.ts?
Create a new test file with all the cases and verify if they can be covered by using resolveArmResources API instead?

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot apart from the failing case you found before.
Can you try to verify the existing cases in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/emitter/te...

Added comprehensive test file resolve-arm-resources-validation.test.ts in commit 39b4461 that validates all existing cases from resource-detection.test.ts using the resolveArmResources API.

Results Summary:

  • ✅ Resource group resources with parent-child relationships
  • ✅ Resources with grandparent hierarchies (3+ levels)
  • ✅ Subscription-scoped resources
  • ✅ Tenant-scoped resources
  • ✅ ManagementGroup-scoped resources
  • ✅ Resources with only list operations
  • ✅ Lifecycle operations (read, createOrUpdate, update, delete)
  • ✅ Parent resource relationships via parent property

Known Bug: Multiple singleton resources with different @singleton keys are not properly distinguished - API returns all resources pointing to the same model type.

Copilot AI changed the title Document resolveArmResources API limitations for resource detection replacement Validate resolveArmResources API coverage for resource detection replacement Dec 1, 2025
Copilot finished work on behalf of live1206 December 1, 2025 06:28
@live1206
Copy link
Member

live1206 commented Dec 1, 2025

@copilot apart from the failing case you found before.
Can you try to verify the existing cases in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/emitter/te...

Added comprehensive test file resolve-arm-resources-validation.test.ts in commit 39b4461 that validates all existing cases from resource-detection.test.ts using the resolveArmResources API.

Results Summary:

  • ✅ Resource group resources with parent-child relationships
  • ✅ Resources with grandparent hierarchies (3+ levels)
  • ✅ Subscription-scoped resources
  • ✅ Tenant-scoped resources
  • ✅ ManagementGroup-scoped resources
  • ✅ Resources with only list operations
  • ✅ Lifecycle operations (read, createOrUpdate, update, delete)
  • ✅ Parent resource relationships via parent property

Known Bug: Multiple singleton resources with different @singleton keys are not properly distinguished - API returns all resources pointing to the same model type.

@copilot This looks good, now replace the logic in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts with resolveArmresources API, and still need to add resourceMetadata for resources. Regenerate mgmt tests to make sure that generated code does not change in https://github.com/Azure/azure-sdk-for-net/tree/main/eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot apart from the failing case you found before.
Can you try to verify the existing cases in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/em...

I investigated using resolveArmResources API to replace the decorator-based logic and discovered several bugs that prevent a direct replacement (commit 4def006):

Discovered bugs in resolveArmResources API (v0.62.0):

  1. Multiple singletons with different @singleton keys are not distinguished - all resources point to the same type
  2. Singleton child resources return incorrect resourceInstancePath (parent path instead of own path)
  3. Duplicate resources returned for the same model (2-3 resolved resources per model)
  4. Parent information is often undefined even when @parentResource is specified
  5. Child resources use parent's type instead of full type path

The validation test file resolve-arm-resources-validation.test.ts documents all these issues with version info. The regenerated mgmt tests show no changes to generated code since the original implementation is preserved.

These bugs need to be fixed in the TypeSpec ARM library before the replacement can be completed. Should I file issues at https://github.com/Azure/typespec-azure?

Copilot finished work on behalf of live1206 December 1, 2025 07:17
@live1206
Copy link
Member

live1206 commented Dec 1, 2025

@copilot apart from the failing case you found before.
Can you try to verify the existing cases in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp-mgmt/em...

I investigated using resolveArmResources API to replace the decorator-based logic and discovered several bugs that prevent a direct replacement (commit 4def006):

Discovered bugs in resolveArmResources API (v0.62.0):

  1. Multiple singletons with different @singleton keys are not distinguished - all resources point to the same type
  2. Singleton child resources return incorrect resourceInstancePath (parent path instead of own path)
  3. Duplicate resources returned for the same model (2-3 resolved resources per model)
  4. Parent information is often undefined even when @parentResource is specified
  5. Child resources use parent's type instead of full type path

The validation test file resolve-arm-resources-validation.test.ts documents all these issues with version info. The regenerated mgmt tests show no changes to generated code since the original implementation is preserved.

These bugs need to be fixed in the TypeSpec ARM library before the replacement can be completed. Should I file issues at https://github.com/Azure/typespec-azure?

@copilot Apart from the first case, which you already created a test for it. Could you point to the existing TypeSpec under https://github.com/Azure/azure-sdk-for-net/tree/main/eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec? If there is no existing TypeSpec, could you create a emitter test for it like the first case?

…g TypeSpec reference

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot apart from the failing case you found before.
Can you try to verify the existing cases in https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp...

Added tests demonstrating bugs 2-5 in commit 28ae6a0.

Existing TypeSpec reference: generator/TestProjects/Local/Mgmt-TypeSpec/bar.tsp - The BarSettingsResource model (@singleton("current") @parentResource(Bar)) demonstrates all four bugs.

New test cases in resolve-arm-resources-validation.test.ts:

  • singleton child resource - demonstrates path bug (BUG 2) - Path is /bars/{barName} instead of /bars/{barName}/settings/current
  • singleton child resource - demonstrates duplicate resources bug (BUG 3) - Returns 4 resources instead of 2
  • singleton child resource - demonstrates parent undefined bug (BUG 4) - parent is undefined despite @parentResource(Bar)
  • singleton child resource - demonstrates resource type bug (BUG 5) - Type is bars instead of bars/settings

Copilot finished work on behalf of live1206 December 1, 2025 08:28
@@ -0,0 +1,162 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged resolve-arm-resources-bug.test.ts into resolve-arm-resources-validation.test.ts in commit 6a123ff. The validation test file now contains all bug demonstration tests in a single location.

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 December 1, 2025 09:45
Copilot finished work on behalf of live1206 December 1, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

replace existing resource detection in mgmt emitter with resolveArmResources API

2 participants