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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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

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

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

Copy link
Contributor

Dotnet Test Results

    78 files   -     39      78 suites   - 39   31m 50s ⏱️ - 19m 31s
11 584 tests  -     26  11 584 ✅  -     26  0 💤 ±0  0 ❌ ±0 
26 900 runs   - 13 445  26 900 ✅  - 13 445  0 💤 ±0  0 ❌ ±0 

Results for commit 6b4d11f. ± Comparison against base commit 5e79805.

This pull request removes 1842 and adds 630 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
�ӱ
�0\u0010\u0006��>E�\u0001b�Kr*��\u0008.>@lOTl-m�������V0ߘ;���/f[W��%T��`4�	�mҳZ��7��)|�L���1^�}�\u0016��r�\u001fe��~P��U��V
�\u001a@\u0000%\u0000�\u00065\ud957\ude23�\u0016<w�qu�\u0012�Ź�fMw��=�\u001b�n�\u001f�oK��/��_��\u0011F`�Ik\u000c��\u000f��?���Ow\u0019�9�\u0015%\u001bJ�TL���.%=ƞ-\u0008� ��\u0013z�\u0005�\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�0\u0010\u0006�=\u0005'(3Ӗ�\u0005{�^�Q\u0012\u001f�\u0018\u001e��xw���\u0005�
�����L:m�W�{��r{̫Z\u001a�4�bn�%Z��\u000fР@~\u0001\u0001l\u000c\u000b\u0011��O2��\u001b[�Q���\u0007Q\u001a��\�\u0019�J�bE(S�\u0012\u0003n|�0Y��f�Sֺ�+;'/u醆b�a�\u0006����[W�)�\u0000$P�\u0006bR�/\u0000F�|�\u0017�����X{� \u0008�`
OM]�\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
��M\u000b�0\u0018\u0007��\u0014�\u0007�۞�d�!�\u0011\u0016\u0004]c���\u0016j �囇�t�%h�����m�\u001f��u�Nt�\u0014%\u0016��=��F\u000c�y�z�r��z#�(!M�S��I�GY�´2�Y?��\u001d]�Y\u0012P\u0005R�\u0002�\u0018@q\u0001��읻����uu	�<Nj|-oyS�u�O}M�����{�o�'�#3\u00038a��\u0004D�\u0010����L�y��n\u0018\u001d��pu�\u001cv��p�\u0004��'˲,kx/�S��\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\u0000��>E�\u0003�I�\��Ap�"U\u0010\%؀\u0015Z��P��M\u0007qiq�`�1wp\u0017�;��U��*�E�}\u0000�a�7b\u0000��
�%�� "\u00050����NZ<�J\u0015��1j� \u00168�J3\u001dR��%c\u0014K\u0000\u0008�?3�sW�Ν��.a�'����7�YW��״:|�o�\u001a��0��\u000e���?C\u0004" �0�?�L���?�(>.���9�bw�
<uO�eY��^c��\\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��K
�0\u0010\u0006�=EN����M�.�BЂ\u000f�J�bA���Bp��6���\u0019�������q[�C��Lh�
F�\u0006��2z>A�\u0004�\u000b\u00100J)B��&\u0011C�m\u0017VYc�\u000f�%����\u0015\u001a��0�\u0003� E�b\u0013j��\u001aҫ��jp\u0017��\u001c;���\u001a����\u0017͢���[3>�\u001f�\u0013�F\u0002�~�\u000c�G\u0011�HW�����H�A�eY��\u0013���\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��K
�0\u0010\u0006�=E�\u0001�$ͣ
ݻ\u0011�x�؎X��4\u0015
��M\u0017��M\u001f�����LH��po�-�\u000cjK"�dH�ب���]�0�\u0011�o\u0014Q-\u0015G\u0008��O��n\u001bS�Q����x�M�\u0017�0\u001d)\u0019i�\u0019��\u0016Z��K���\u001aW�9'y�AK.�Vv��P����\u0006|�o�\u001e��O#��\u001f (wo�JD�\u0014����L�y�\u001f88��V�6���8B\u001dl��\-<����<ϛ�\u000b�L�x\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
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)))])
…

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