-
Notifications
You must be signed in to change notification settings - Fork 850
Make .NET SDK check in aspire doctor based on apphost language #15018
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9612cdc
Make .NET SDK check in aspire doctor based on apphost language
davidfowl 02e56ea
Only run .NET SDK check when a .NET apphost is positively detected
davidfowl 9916ca0
Add recurseLimit to FindFirstFile and limit .NET SDK filesystem scan …
JamesNK 043fcbb
Comments
JamesNK 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
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
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
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,168 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Cli.Projects; | ||
| using Aspire.Cli.Tests.TestServices; | ||
| using Aspire.Cli.Tests.Utils; | ||
| using Aspire.Cli.Utils.EnvironmentChecker; | ||
| using Microsoft.AspNetCore.InternalTesting; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
|
|
||
| namespace Aspire.Cli.Tests.Commands; | ||
|
|
||
| public class DotNetSdkCheckTests(ITestOutputHelper outputHelper) | ||
| { | ||
| [Fact] | ||
| public async Task CheckAsync_SkipsCheck_WhenNoAppHostFound() | ||
| { | ||
| // No apphost in settings — skip .NET SDK check entirely | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace, | ||
| sdkCheckResult: (false, null, "10.0.100"), | ||
| languageDiscovery: new TestLanguageDiscovery()); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
|
|
||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CheckAsync_SkipsCheck_WhenNonDotNetAppHostFound() | ||
| { | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace, | ||
| appHostFileName: "apphost.ts", | ||
| sdkCheckResult: (false, null, "10.0.100")); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
|
|
||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CheckAsync_RunsCheck_WhenDotNetAppHostFound() | ||
| { | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace, appHostFileName: "MyAppHost.csproj"); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CheckAsync_ReturnsFail_WhenDotNetAppHostFound_AndSdkNotInstalled() | ||
| { | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace, | ||
| appHostFileName: "MyAppHost.csproj", | ||
| sdkCheckResult: (false, null, "10.0.100")); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
|
|
||
| Assert.Single(results); | ||
| Assert.Equal(EnvironmentCheckStatus.Fail, results[0].Status); | ||
| Assert.Contains(".NET SDK not found", results[0].Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CheckAsync_SkipsCheck_WhenNoSettingsFileExists() | ||
| { | ||
| // No settings.json — can't determine language, skip .NET check | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
|
|
||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CheckAsync_SkipsCheck_WhenLanguageNotRecognized() | ||
| { | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace, appHostFileName: "unknown.xyz"); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
|
|
||
| // Unrecognized file — skip .NET check | ||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("MyAppHost.csproj", true)] | ||
| [InlineData("apphost.cs", true)] | ||
| [InlineData("readme.txt", false)] | ||
| [InlineData("src/MyAppHost.csproj", true)] | ||
| [InlineData("src/AppHost/apphost.cs", true)] | ||
| [InlineData("src/deep/nested/readme.txt", false)] | ||
| [InlineData("a/b/c/d/e/f/apphost.cs", false)] | ||
| public async Task CheckAsync_FallsBackToFileSystemScan_WhenNoSettingsFile(string relativePath, bool shouldRunCheck) | ||
| { | ||
| using var workspace = TemporaryWorkspace.Create(outputHelper); | ||
| var check = CreateDotNetSdkCheck(workspace); | ||
|
|
||
| // Create the file on disk (with nested directories) so FindFirstFile can discover it | ||
| var filePath = Path.Combine(workspace.WorkspaceRoot.FullName, relativePath.Replace('/', Path.DirectorySeparatorChar)); | ||
| Directory.CreateDirectory(Path.GetDirectoryName(filePath)!); | ||
| await File.WriteAllTextAsync(filePath, ""); | ||
|
|
||
| var results = await check.CheckAsync().DefaultTimeout(); | ||
|
|
||
| if (shouldRunCheck) | ||
| { | ||
| Assert.Single(results); | ||
| Assert.Equal(EnvironmentCheckStatus.Pass, results[0].Status); | ||
| } | ||
| else | ||
| { | ||
| Assert.Empty(results); | ||
| } | ||
| } | ||
|
|
||
| private static readonly LanguageInfo s_typeScriptLanguage = new( | ||
| LanguageId: new LanguageId(KnownLanguageId.TypeScript), | ||
| DisplayName: "TypeScript (Node.js)", | ||
| PackageName: "Aspire.Hosting.CodeGeneration.TypeScript", | ||
| DetectionPatterns: ["apphost.ts"], | ||
| CodeGenerator: "TypeScript", | ||
| AppHostFileName: "apphost.ts"); | ||
|
|
||
| private static CliExecutionContext CreateExecutionContext(TemporaryWorkspace workspace) => | ||
| new( | ||
| workingDirectory: workspace.WorkspaceRoot, | ||
| hivesDirectory: workspace.WorkspaceRoot.CreateSubdirectory(".aspire-hives"), | ||
| cacheDirectory: workspace.WorkspaceRoot.CreateSubdirectory(".aspire-cache"), | ||
| sdksDirectory: workspace.WorkspaceRoot.CreateSubdirectory(".aspire-sdks"), | ||
| logsDirectory: workspace.WorkspaceRoot.CreateSubdirectory(".aspire-logs"), | ||
| logFilePath: "test.log"); | ||
|
|
||
| private static DotNetSdkCheck CreateDotNetSdkCheck( | ||
| TemporaryWorkspace workspace, | ||
| string? appHostFileName = null, | ||
| (bool Success, string? HighestVersion, string MinimumRequired)? sdkCheckResult = null, | ||
| ILanguageDiscovery? languageDiscovery = null) | ||
| { | ||
| var appHostFile = appHostFileName is not null | ||
| ? new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, appHostFileName)) | ||
| : null; | ||
|
|
||
| var sdkInstaller = new TestDotNetSdkInstaller(); | ||
| if (sdkCheckResult is var (success, highest, minimum)) | ||
| { | ||
| sdkInstaller.CheckAsyncCallback = _ => (success, highest, minimum); | ||
| } | ||
|
|
||
| var projectLocator = new TestProjectLocator | ||
| { | ||
| GetAppHostFromSettingsAsyncCallback = _ => Task.FromResult(appHostFile) | ||
| }; | ||
|
|
||
| var executionContext = CreateExecutionContext(workspace); | ||
|
|
||
| return new DotNetSdkCheck( | ||
| sdkInstaller, | ||
| projectLocator, | ||
| languageDiscovery ?? new TestLanguageDiscovery(s_typeScriptLanguage), | ||
| executionContext, | ||
| NullLogger<DotNetSdkCheck>.Instance); | ||
| } | ||
| } |
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
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.