-
Couldn't load subscription status.
- Fork 840
Add project template build tests + CG reporting #6355
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8cfa76d
Started on template build tests.
MackinnonBuck 90572ad
Working restore/build tests + helper script for debugging
MackinnonBuck 504d6c3
Clean up
MackinnonBuck 7876b03
Try updating CI pipeline
MackinnonBuck 965112d
Merge branch 'main' into mbuck/template-cg
MackinnonBuck d9ccb35
Only clear test output if exists
MackinnonBuck 4a3ddca
Add comments, update README, add more tests
MackinnonBuck ef5d2d7
PR feedback
MackinnonBuck 276f333
Add note to README
MackinnonBuck b2e902c
Update test/ProjectTemplates/Microsoft.Extensions.AI.Templates.Integr…
MackinnonBuck fccdf15
Update test/ProjectTemplates/Microsoft.Extensions.AI.Templates.Integr…
MackinnonBuck 57d058c
Merge branch 'main' into mbuck/template-cg
MackinnonBuck fa16de6
Fill out missing exception message
MackinnonBuck 7919312
Merge branch 'main' into mbuck/template-cg
MackinnonBuck 6d2b0d7
Fix test command logging
MackinnonBuck 0c54671
Treat warnings as errors + isolate .editorconfig
MackinnonBuck e66a00b
Generate all possible valid template combinations
MackinnonBuck 25916b9
Remove redundant Aspire args
MackinnonBuck d069189
Explicitly exclude template content from build, just in case
MackinnonBuck 3a6dcb3
Add comments about CG reporting
MackinnonBuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
...ctTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
This file contains hidden or 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,76 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| public class AIChatWebExecutionTests : TemplateExecutionTestBase<AIChatWebExecutionTests>, ITemplateExecutionTestConfigurationProvider | ||
| { | ||
| public AIChatWebExecutionTests(TemplateExecutionTestFixture fixture, ITestOutputHelper outputHelper) | ||
| : base(fixture, outputHelper) | ||
| { | ||
| } | ||
|
|
||
| public static TemplateExecutionTestConfiguration Configuration { get; } = new() | ||
| { | ||
| TemplatePackageName = "Microsoft.Extensions.AI.Templates", | ||
| TestOutputFolderPrefix = "AIChatWeb" | ||
| }; | ||
|
|
||
| [Theory] | ||
| [InlineData("AzureApp", | ||
| "--provider", "azureopenai", | ||
| "--vector-store", "azureaisearch")] | ||
| [InlineData("AzureAppManagedIdentity", | ||
| "--provider", "azureopenai", | ||
| "--vector-store", "azureaisearch", | ||
| "--managed-identity")] | ||
| [InlineData("GitHubModelsWithLocalStore", | ||
| "--provider", "githubmodels", | ||
| "--vector-store", "local")] | ||
| [InlineData("OllamaWithLocalStore", | ||
| "--provider", "ollama", | ||
| "--vector-store", "local")] | ||
| [InlineData("OpenAIWithLocalStore", | ||
| "--provider", "openai", | ||
| "--vector-store", "local")] | ||
| public async Task CreateRestoreAndBuild_BasicTemplate(string projectName, params string[] args) | ||
| { | ||
| var project = await Fixture.CreateProjectAsync( | ||
| templateName: "aichatweb", | ||
| projectName, | ||
| args); | ||
|
|
||
| await Fixture.RestoreProjectAsync(project); | ||
| await Fixture.BuildProjectAsync(project); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("AzureApp", | ||
| "--provider", "azureopenai", | ||
| "--vector-store", "azureaisearch")] | ||
| [InlineData("GitHubModelsWithQdrant", | ||
| "--provider", "githubmodels", | ||
| "--vector-store", "qdrant")] | ||
| [InlineData("OllamaWithLocalStore", | ||
| "--provider", "ollama", | ||
| "--vector-store", "local")] | ||
| [InlineData("OpenAIWithLocalStore", | ||
| "--provider", "ollama", | ||
| "--vector-store", "local")] | ||
| public async Task CreateRestoreAndBuild_AspireTemplate(string projectName, params string[] args) | ||
| { | ||
| var project = await Fixture.CreateProjectAsync( | ||
| templateName: "aichatweb", | ||
| projectName, | ||
| args: ["--aspire", .. args]); | ||
|
|
||
| project.StartupProjectRelativePath = $"{projectName}.AppHost"; | ||
|
|
||
| await Fixture.RestoreProjectAsync(project); | ||
| await Fixture.BuildProjectAsync(project); | ||
| } | ||
| } | ||
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
...plates/Microsoft.Extensions.AI.Templates.IntegrationTests/Infrastructure/DotNetCommand.cs
This file contains hidden or 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,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| public class DotNetCommand : TestCommand | ||
| { | ||
| public DotNetCommand(params ReadOnlySpan<string> args) | ||
| { | ||
| FileName = WellKnownPaths.RepoDotNetExePath; | ||
|
|
||
| foreach (var arg in args) | ||
| { | ||
| Arguments.Add(arg); | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...tes/Microsoft.Extensions.AI.Templates.IntegrationTests/Infrastructure/DotNetNewCommand.cs
This file contains hidden or 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,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| public sealed class DotNetNewCommand : DotNetCommand | ||
| { | ||
| private bool _customHiveSpecified; | ||
|
|
||
| public DotNetNewCommand(params ReadOnlySpan<string> args) | ||
| : base(["new", .. args]) | ||
| { | ||
| } | ||
|
|
||
| public DotNetNewCommand WithCustomHive(string path) | ||
| { | ||
| Arguments.Add("--debug:custom-hive"); | ||
| Arguments.Add(path); | ||
| _customHiveSpecified = true; | ||
| return this; | ||
| } | ||
|
|
||
| public override Task<TestCommandResult> ExecuteAsync(ITestOutputHelper outputHelper) | ||
| { | ||
| if (!_customHiveSpecified) | ||
| { | ||
| // If this exception starts getting thrown in cases where a custom hive is | ||
| // legitimately undesirable, we can add a new 'WithoutCustomHive()' method that | ||
| // just sets '_customHiveSpecified' to 'true'. | ||
| throw new InvalidOperationException($"A {nameof(DotNetNewCommand)} should specify a custom hive with '{nameof(WithCustomHive)}()'."); | ||
| } | ||
|
|
||
| return base.ExecuteAsync(outputHelper); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
....Templates.IntegrationTests/Infrastructure/ITemplateExecutionTestConfigurationProvider.cs
This file contains hidden or 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,9 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| public interface ITemplateExecutionTestConfigurationProvider | ||
| { | ||
| static abstract TemplateExecutionTestConfiguration Configuration { get; } | ||
| } |
27 changes: 27 additions & 0 deletions
27
...ft.Extensions.AI.Templates.IntegrationTests/Infrastructure/MessageSinkTestOutputHelper.cs
This file contains hidden or 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,27 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Xunit.Abstractions; | ||
| using Xunit.Sdk; | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| public sealed class MessageSinkTestOutputHelper : ITestOutputHelper | ||
| { | ||
| private readonly IMessageSink _messageSink; | ||
|
|
||
| public MessageSinkTestOutputHelper(IMessageSink messageSink) | ||
| { | ||
| _messageSink = messageSink; | ||
| } | ||
|
|
||
| public void WriteLine(string message) | ||
| { | ||
| _messageSink.OnMessage(new DiagnosticMessage(message)); | ||
| } | ||
|
|
||
| public void WriteLine(string format, params object[] args) | ||
| { | ||
| _messageSink.OnMessage(new DiagnosticMessage(format, args)); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...es/Microsoft.Extensions.AI.Templates.IntegrationTests/Infrastructure/ProcessExtensions.cs
This file contains hidden or 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,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Diagnostics; | ||
|
|
||
| public static class ProcessExtensions | ||
| { | ||
| public static bool TryGetHasExited(this Process process) | ||
| { | ||
| try | ||
| { | ||
| return process.HasExited; | ||
| } | ||
| catch (InvalidOperationException ex) when (ex.Message.Contains("No process is associated with this object")) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...ectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Infrastructure/Project.cs
This file contains hidden or 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,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| public sealed class Project(string rootPath, string name) | ||
| { | ||
| private string? _startupProjectRelativePath; | ||
| private string? _startupProjectFullPath; | ||
|
|
||
| public string RootPath => rootPath; | ||
|
|
||
| public string Name => name; | ||
|
|
||
| public string? StartupProjectRelativePath | ||
| { | ||
| get => _startupProjectRelativePath; | ||
| set | ||
| { | ||
| if (value is null) | ||
| { | ||
| _startupProjectRelativePath = null; | ||
| _startupProjectFullPath = null; | ||
| } | ||
| else if (!string.Equals(value, _startupProjectRelativePath, StringComparison.Ordinal)) | ||
| { | ||
| _startupProjectRelativePath = value; | ||
| _startupProjectFullPath = Path.Combine(rootPath, _startupProjectRelativePath); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public string StartupProjectFullPath => _startupProjectFullPath ?? rootPath; | ||
| } |
66 changes: 66 additions & 0 deletions
66
...soft.Extensions.AI.Templates.IntegrationTests/Infrastructure/TemplateExecutionTestBase.cs
This file contains hidden or 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,66 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Extensions.AI.Templates.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Represents a test that executes a project template (create, restore, build, and run). | ||
| /// </summary> | ||
| /// <typeparam name="TConfiguration">A type defining global test execution settings.</typeparam> | ||
| [Collection(TemplateExecutionTestCollection.Name)] | ||
| public abstract class TemplateExecutionTestBase<TConfiguration> : IClassFixture<TemplateExecutionTestBase<TConfiguration>.TemplateExecutionTestFixture>, IDisposable | ||
| where TConfiguration : ITemplateExecutionTestConfigurationProvider | ||
| { | ||
| private bool _disposed; | ||
|
|
||
| protected TemplateExecutionTestFixture Fixture { get; } | ||
|
|
||
| protected ITestOutputHelper OutputHelper { get; } | ||
|
|
||
| protected TemplateExecutionTestBase(TemplateExecutionTestFixture fixture, ITestOutputHelper outputHelper) | ||
| { | ||
| Fixture = fixture; | ||
| Fixture.SetCurrentTestOutputHelper(outputHelper); | ||
|
|
||
| OutputHelper = outputHelper; | ||
| } | ||
|
|
||
| protected virtual void Dispose(bool disposing) | ||
| { | ||
| if (_disposed) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _disposed = true; | ||
|
|
||
| if (disposing) | ||
| { | ||
| Fixture.SetCurrentTestOutputHelper(null); | ||
| } | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Dispose(true); | ||
| GC.SuppressFinalize(this); | ||
RussKie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// An implementation of <see cref="TemplateExecutionTestClassFixtureBase"/> that utilizes | ||
| /// the configuration provided by <c>TConfiguration</c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The configuration has to be provided "statically" because the lifetime of the class fixture | ||
| /// is longer than the lifetime of each test class instance. In other words, it's not possible for | ||
| /// an instance of the test class to configure to the fixture directly, as the test class instance | ||
| /// gets created after the fixture has a chance to perform global setup. | ||
| /// </remarks> | ||
| /// <param name="messageSink">The <see cref="IMessageSink"/>The <see cref="IMessageSink"/>.</param> | ||
| public sealed class TemplateExecutionTestFixture(IMessageSink messageSink) | ||
| : TemplateExecutionTestClassFixtureBase(TConfiguration.Configuration, messageSink); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.