-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure language server refreshes modules on force refresh (#13278)
Closes #13254 ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13278)
- Loading branch information
1 parent
69631e3
commit c0ad57d
Showing
14 changed files
with
182 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ public class RegistryProviderTests : TestBase | |
{ | ||
private static ServiceBuilder GetServiceBuilder(IFileSystem fileSystem, string registryHost, string repositoryPath, bool extensibilityEnabledBool, bool providerRegistryBool) | ||
{ | ||
var (clientFactory, _) = DataSetsExtensions.CreateMockRegistryClients((registryHost, repositoryPath)); | ||
var clientFactory = RegistryHelper.CreateMockRegistryClient(registryHost, repositoryPath); | ||
|
||
return new ServiceBuilder() | ||
.WithFeatureOverrides(new(ExtensibilityEnabled: extensibilityEnabledBool, ProviderRegistry: providerRegistryBool)) | ||
|
@@ -38,7 +38,7 @@ public async Task Providers_published_to_a_registry_can_be_compiled() | |
|
||
var services = GetServiceBuilder(fileSystem, registry, repository, true, true); | ||
|
||
await DataSetsExtensions.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
await RegistryHelper.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
|
||
var result = await CompilationHelper.RestoreAndCompile(services, """ | ||
provider 'br:example.azurecr.io/test/provider/[email protected]' | ||
|
@@ -69,7 +69,7 @@ public async Task Third_party_namespace_errors_with_configuration() | |
|
||
var services = GetServiceBuilder(fileSystem, registry, repository, true, true); | ||
|
||
await DataSetsExtensions.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
await RegistryHelper.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
|
||
var result = await CompilationHelper.RestoreAndCompile(services, """ | ||
provider 'br:example.azurecr.io/test/provider/[email protected]' with {} | ||
|
@@ -101,7 +101,7 @@ public async Task Third_party_imports_are_enabled_when_feature_is_enabled() | |
|
||
var services = GetServiceBuilder(fileSystem, registry, repository, true, true); | ||
|
||
await DataSetsExtensions.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
await RegistryHelper.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
|
||
var result = await CompilationHelper.RestoreAndCompile(services, @$" | ||
provider 'br:example.azurecr.io/test/provider/[email protected]' | ||
|
@@ -147,7 +147,7 @@ public async Task Third_party_imports_are_disabled_unless_feature_is_enabled() | |
|
||
var services = GetServiceBuilder(fileSystem, registry, repository, false, false); | ||
|
||
await DataSetsExtensions.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
await RegistryHelper.PublishProviderToRegistryAsync(services.Build(), "/types/index.json", $"br:{registry}/{repository}:1.2.3"); | ||
|
||
var result = await CompilationHelper.RestoreAndCompile(services, @$" | ||
provider 'br:example.azurecr.io/test/provider/[email protected]' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Immutable; | ||
using System.IO.Abstractions; | ||
using Bicep.Core.FileSystem; | ||
using Bicep.Core.Registry; | ||
using Bicep.Core.Registry.Providers; | ||
using Bicep.Core.SourceCode; | ||
using Bicep.Core.UnitTests.Features; | ||
using Bicep.Core.UnitTests.Registry; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Bicep.Core.UnitTests.Utils; | ||
|
||
public static class RegistryHelper | ||
{ | ||
public static IContainerRegistryClientFactory CreateMockRegistryClient(string registry, string repository) | ||
{ | ||
return new TestContainerRegistryClientFactoryBuilder() | ||
.RegisterMockRepositoryBlobClient(registry, repository) | ||
.Build().clientFactory; | ||
} | ||
|
||
public static (IContainerRegistryClientFactory factoryMock, ImmutableDictionary<(Uri, string), MockRegistryBlobClient> blobClientMocks) CreateMockRegistryClients(params (string, string)[] clients) | ||
{ | ||
var containerRegistryFactoryBuilder = new TestContainerRegistryClientFactoryBuilder(); | ||
|
||
foreach (var (registryHost, repository) in clients) | ||
{ | ||
containerRegistryFactoryBuilder.RegisterMockRepositoryBlobClient(registryHost, repository); | ||
|
||
} | ||
|
||
return containerRegistryFactoryBuilder.Build(); | ||
} | ||
|
||
public static async Task PublishModuleToRegistry(IContainerRegistryClientFactory clientFactory, string moduleName, string target, string moduleSource, bool publishSource, string? documentationUri = null) | ||
{ | ||
var featureProviderFactory = BicepTestConstants.CreateFeatureProviderFactory(new FeatureProviderOverrides(PublishSourceEnabled: publishSource)); | ||
var dispatcher = ServiceBuilder.Create(s => s.WithDisabledAnalyzersConfiguration() | ||
.AddSingleton(clientFactory) | ||
.AddSingleton(BicepTestConstants.TemplateSpecRepositoryFactory) | ||
.AddSingleton(featureProviderFactory) | ||
).Construct<IModuleDispatcher>(); | ||
|
||
var targetReference = dispatcher.TryGetArtifactReference(ArtifactType.Module, target, RandomFileUri()).IsSuccess(out var @ref) ? @ref | ||
: throw new InvalidOperationException($"Module '{moduleName}' has an invalid target reference '{target}'. Specify a reference to an OCI artifact."); | ||
|
||
var result = CompilationHelper.Compile(moduleSource); | ||
if (result.Template is null) | ||
{ | ||
throw new InvalidOperationException($"Module {moduleName} failed to produce a template."); | ||
} | ||
|
||
var features = featureProviderFactory.GetFeatureProvider(result.BicepFile.FileUri); | ||
BinaryData? sourcesStream = publishSource ? BinaryData.FromStream(SourceArchive.PackSourcesIntoStream(result.Compilation.SourceFileGrouping, features.CacheRootDirectory)) : null; | ||
await dispatcher.PublishModule(targetReference, BinaryData.FromString(result.Template.ToString()), sourcesStream, documentationUri); | ||
} | ||
|
||
public static async Task PublishProviderToRegistryAsync(IDependencyHelper services, string pathToIndexJson, string target) | ||
{ | ||
var dispatcher = services.Construct<IModuleDispatcher>(); | ||
var fileSystem = services.Construct<IFileSystem>(); | ||
|
||
var targetReference = dispatcher.TryGetArtifactReference(ArtifactType.Provider, target, PathHelper.FilePathToFileUrl(pathToIndexJson)).IsSuccess(out var @ref) ? @ref | ||
: throw new InvalidOperationException($"Invalid target reference '{target}'. Specify a reference to an OCI artifact."); | ||
|
||
var tgzStream = await TypesV1Archive.GenerateProviderTarStream(fileSystem, pathToIndexJson); | ||
|
||
await dispatcher.PublishProvider(targetReference, tgzStream); | ||
} | ||
|
||
private static Uri RandomFileUri() => PathHelper.FilePathToFileUrl(Path.GetTempFileName()); | ||
|
||
public static async Task PublishAzProvider(IDependencyHelper services, string pathToIndexJson) | ||
{ | ||
var version = BicepTestConstants.BuiltinAzProviderVersion; | ||
var repository = "bicep/providers/az"; | ||
await PublishProviderToRegistryAsync(services, pathToIndexJson, $"br:{LanguageConstants.BicepPublicMcrRegistry}/{repository}:{version}"); | ||
} | ||
|
||
public static IContainerRegistryClientFactory CreateOciClientForAzProvider() | ||
=> CreateMockRegistryClients((LanguageConstants.BicepPublicMcrRegistry, $"bicep/providers/az")).factoryMock; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.