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

Refactor TypeProperty to better represent ObjectType state #16053

Merged
merged 3 commits into from
Jan 27, 2025

Conversation

levimatheri
Copy link
Contributor

@levimatheri levimatheri commented Jan 10, 2025

Follow up to PR feedback.

With the current ObjectType signature, it's technically possible for AdditionalPropertiesDescription to be non-null even if AdditionalPropertiesType is null. This PR creates a new NamedTypeProperty record that represents a property with a name and a type, which is used for the ObjectType.Properties property.
The TypeProperty record encapsulates the type ref, flags and description, preventing a non-null description with a null type ref being passed into ObjectType.

New ObjectType signature:
public ObjectType(string name, TypeSymbolValidationFlags validationFlags, IEnumerable<NamedTypeProperty> properties, TypeProperty? additionalProperties, Func<ObjectType, FunctionResolver> methodResolverBuilder)

Microsoft Reviewers: Open in CodeFlow

@levimatheri levimatheri requested review from jeskew, a team and Copilot January 10, 2025 19:24

Choose a reason for hiding this comment

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

Copilot reviewed 48 out of 63 changed files in this pull request and generated no comments.

Files not reviewed (15)
  • src/Bicep.Core.UnitTests/Rewriters/ReadOnlyPropertyRemovalRewriterTests.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/TypeSystem/DiscriminatedObjectTypeTests.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/TypeSystem/TypeValidatorAssignabilityTests.cs: Evaluated as low risk
  • src/Bicep.Core.IntegrationTests/TypeSystem/TypeValidationTests.cs: Evaluated as low risk
  • src/Bicep.Core.IntegrationTests/Scenarios/TopLevelResourcePropertiesTests.cs: Evaluated as low risk
  • src/Bicep.Core.IntegrationTests/ScenarioTests.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/Utils/TestTypeHelper.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/TypeSystem/FunctionResolverTests.cs: Evaluated as low risk
  • src/Bicep.Core.IntegrationTests/ScopeTests.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/Rewriters/TypeCasingFixerRewriterTests.cs: Evaluated as low risk
  • src/Bicep.Core.IntegrationTests/ProviderImportTests.cs: Evaluated as low risk
  • src/Bicep.Core.IntegrationTests/Extensibility/FooNamespaceType.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/TypeSystem/TypeHelperTests.cs: Evaluated as low risk
  • src/Bicep.Core/Analyzers/Linter/Common/FindPossibleSecretsVisitor.cs: Evaluated as low risk
  • src/Bicep.Core.UnitTests/Utils/BuiltInTestTypes.cs: Evaluated as low risk
Comments suppressed due to low confidence (1)

src/Bicep.Core.UnitTests/Mock/FakeResourceTypes.cs:5

  • The variable name 'resourcType' is misspelled. It should be 'resourceType'.
var resourcType = ResourceTypeReference.Parse(line);
Copy link
Contributor

github-actions bot commented Jan 10, 2025

Test this change out locally with the following install scripts (Action run 12997297695)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 12997297695
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 12997297695"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 12997297695
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 12997297695"

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Dotnet Test Results

    76 files   -     39      76 suites   - 39   32m 59s ⏱️ - 19m 2s
11 665 tests  -     26  11 665 ✅  -     26  0 💤 ±0  0 ❌ ±0 
27 062 runs   - 13 526  27 062 ✅  - 13 526  0 💤 ±0  0 ❌ ±0 

Results for commit b75451d. ± Comparison against base commit 5da4a85.

This pull request removes 1840 and adds 636 tests. Note that renamed tests count towards both.

		nestedProp1: 1
		nestedProp2: 2
		prop1: true
		prop2: false
	1
	2
	\$'")
	prop1: true
	prop2: false
…
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��K
�0\u0010\u0006�=E�\u0001b���
ݻ\u0011�x�؎X���\u0011\u0002��M\u0017��M\u001f�����L\u0012���^�-�\u001c�����k��F\u001d�y�z�q��z��*!\u0018B؎>I�{kt�F�c�\u001f\u0014�X�����(�T�qB��\*�r�l��\u0012\ksN�*\u0007K.����ˡ����
���tW�-�4���\u0001\(�"�\u0010�B�.��d�������\u0002[Cf �Ay�&������\z6��<o:/7!\u001f�\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��K\u000e� \u0010\u0006`֞�\u0013�\u0019
\u0003��]z\u0005�M|���\u0011�\u0018�.,L\�qS[\u0013����\u0001�#��\u001b��;�M+P��\u0004�\u001b\u0004���x�\u001a\u0019�\u0017``t\͇�;\u0019ѷ�kB+K�����;Ue�&�\u0000FZ\u0012D\u0016�5�0���C~uݱ����7/�m�cA5U��A�Q����+���\u0000�P\u0019�
aN\u0014�\u001f�\u0004�\u0017�����X��$I�d
O\u0001Z\u001b�\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
���\u000b�0\u0014\u0007��+�?`�����C�!#,\u0008���A\u0006Z���?�<D\u0017��Z�>����6�\u000f{;լ�JuYaB!�0\u001a\u001a\u0018����\u0016a\u0012\u0011�\u0002\u0008$�\u0004!�\u0019��\u000e��V�ie��~\u0010
\u001cUg����\u0003\u0000I�\u0010s\u0010��lf�N}{$tn�>GY��\u0006_�kі�}�߾������=ѧ�\u0003e��\u0000ƥ �$\u0008\u0004\u0017m�'�������a�����~��s�L�o�dY�e��	�oQ=\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003�Խ
�0\u0010\u0007��>E�\u0003�$�%Q��"��\u0000�=Q�U�
\u0001��M\u0007qiq�\u001f`~c��.���t��\u0002]�u�R�ٔ���@+�{�\u0011�\u0010a\u001e8�\u0006t�~�Mz\���a�O��A�R��K̄I-�FX�$h\u000e6��Z>T\u00133zv�.�W\u0005zvhNU�^\u000e����р���oƫ��T��\u0007(0ZH)	�\u0000\u0010���L�y��4YW�Ϙ�X,��`����\u001d\u001b�}{�(���}�/5�\u001a\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���
�0\u000c\u0007�}�=A�tMS\u000f�{�\u0015�\u000e�`��
\u0007��\u001d\u0004\u000f\u001b^�&�߱!$%�e�uݦp��Zˌh�J15\u0008�փ�=$\u0014�/ ��X���|�\u0001mݸkXe�Y?H��5Dzȑ3\u000b�hI*CV\u001b�
��h
��k\u000ey�Ͼ�yy�+�7�c
K�4\u001a�~�o����\u0000%P�&6�\u0014��c����L�y�7��(���\u0004X�Pf\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���\u000b�0\u0014\u0007��+���ܞ�����CFX\u0010t��B\u0006Z���?�<D\u0017��Z�>ǽ\u0007��\u001dqw�Y�:IˊxB\u0004.AC�����L��\u0017��\u0012�!���7�p�j]�U����@a]gy\u001a2���*�K\u0002�\u0003�3S:��X�o�>�Y��
�Tע��{��}G���\u0005Ǜ�)�\u0014L���BI\u0006\u0000�J!L7�$�����\u0013Ň�&Z\u001e��m�̱�����eY�5�'���f\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = mcr.microsoft.com, RepositoryPath = unknown/path/az, ExtensionVersion = 0.0.0-placeholder },Azure.RequestFailedException: The artifact does not exist in the registry.
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138,[(BCP192, Error, Unable to restore the artifact with reference "br:mcr.microsoft.com/unknown/path/az:0.0.0-placeholder": The artifact does not exist in the registry.)])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = mcr.microsoft.com, RepositoryPath = unknown/path/az, ExtensionVersion = 0.0.0-placeholder },Azure.RequestFailedException: The artifact does not exist in the registry.
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138,[(BCP192, Error, Unable to restore the artifact with reference "br:mcr.microsoft.com/unknown/path/az:0.0.0-placeholder": The artifact does not exist in the registry.)])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = unknown.registry.azurecr.io, RepositoryPath = bicep/extensions/az, ExtensionVersion = 0.0.0-placeholder },System.AggregateException: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443))
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 51
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 63
   at Bicep.Core.Registry.OciArtifactRegistry.TryRestoreArtifactAsync(RootConfiguration configuration, OciArtifactReference reference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/OciArtifactRegistry.cs:line 495,[(BCP192, Error, Unable to restore the artifact with reference "br:unknown.registry.azurecr.io/bicep/extensions/az:0.0.0-placeholder": Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)))])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = unknown.registry.azurecr.io, RepositoryPath = bicep/extensions/az, ExtensionVersion = 0.0.0-placeholder },System.AggregateException: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443))
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 51
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 63
   at Bicep.Core.Registry.OciArtifactRegistry.TryRestoreArtifactAsync(RootConfiguration configuration, OciArtifactReference reference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\OciArtifactRegistry.cs:line 495,[(BCP192, Error, Unable to restore the artifact with reference "br:unknown.registry.azurecr.io/bicep/extensions/az:0.0.0-placeholder": Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)))])
…

♻️ This comment has been updated with latest results.

@levimatheri levimatheri merged commit cec9878 into main Jan 27, 2025
43 checks passed
@levimatheri levimatheri deleted the levimatheri/refactor-object-type branch January 27, 2025 20:02
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.

2 participants