Repository navigation
Migrate GenerateStaticWebAssetEndpointsManifest to IMultiThreadableTask #54706
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
jankratochvilcz
merged 14 commits into
dotnet:main
from
jankratochvilcz:mt/migrate-generate-static-web-asset-endpoints-manifest
Aug 4, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
518c94c
Migrate GenerateStaticWebAssetEndpointsManifest to IMultiThreadableTask
0ba9617
Add MT-safety unit test for GenerateStaticWebAssetEndpointsManifest
a591136
Guard GetAbsolutePath with IsNullOrEmpty check
jankratochvilcz 13c7650
Address review: revert UpdateExclusionPatternsCache to instance metho…
jankratochvilcz e3c14a6
Update src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsMa…
jankratochvilcz 4f1b318
Update src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsMa…
jankratochvilcz 0ff9e3e
Fix CS0029: use default(AbsolutePath) instead of string for empty Man…
jankratochvilcz acc3440
Guard path absolutization against whitespace-only values
jankratochvilcz e03ec91
Merge main into MT migration
jankratochvilcz a3ad7ef
Address MT migration review feedback
jankratochvilcz e22f5d8
Trigger PR synchronization
jankratochvilcz 4f103fd
Simplify manifest path handling per review feedback
e68a176
Merge remote-tracking branch 'origin/main' into pr54706-work
547ef55
Keep MT test paths under MAX_PATH and document serialization
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
116 changes: 116 additions & 0 deletions
116
...Assets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsManifestMultiThreadingTest.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,116 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #nullable disable | ||
|
|
||
| using Microsoft.AspNetCore.StaticWebAssets.Tasks; | ||
| using Microsoft.Build.Framework; | ||
| using Moq; | ||
|
|
||
| namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; | ||
|
|
||
| // Test parallelization is disabled assembly-wide: the MSTest.Sdk project sets | ||
| // MSTestParallelizeScope=None, which emits [assembly: DoNotParallelize] and runs | ||
| // tests sequentially, isolating the process-CWD mutation this test performs. | ||
| [TestClass] | ||
| public class GenerateStaticWebAssetEndpointsManifestMultiThreadingTest | ||
| { | ||
| // Deliberately short: the layout below nests several levels under the test binary | ||
| // directory and Directory.SetCurrentDirectory is still limited to MAX_PATH on Windows. | ||
| private const string TestRootName = "GSWAEndpointsManifestMT"; | ||
|
|
||
| [TestMethod] | ||
| public void WritesEndpointsManifestAndExclusionCacheRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() | ||
| { | ||
| // Layout: place project and decoy in disjoint subtrees so that the same | ||
| // relative path produces different absolute paths from each root. | ||
| // <testRoot>/p/output/ <-- TaskEnvironment.ProjectDirectory | ||
| // <testRoot>/d/s/ <-- process CWD (the "decoy") | ||
| // <testRoot>/d/s/output/ <-- where the pre-migration code would write | ||
| // Path segments are kept short because Directory.SetCurrentDirectory is limited to | ||
| // MAX_PATH on Windows even when long paths are otherwise enabled. | ||
| var testRoot = Path.Combine(AppContext.BaseDirectory, TestRootName, Guid.NewGuid().ToString("N")[..8]); | ||
| var projectDir = Path.Combine(testRoot, "p"); | ||
| var spawnDir = Path.Combine(testRoot, "d", "s"); | ||
| var projectOutputDir = Path.Combine(projectDir, "output"); | ||
| var spawnOutputDir = Path.Combine(spawnDir, "output"); | ||
| Directory.CreateDirectory(projectOutputDir); | ||
| Directory.CreateDirectory(spawnOutputDir); | ||
|
|
||
| var originalCurrentDirectory = Directory.GetCurrentDirectory(); | ||
| try | ||
| { | ||
| Directory.SetCurrentDirectory(spawnDir); | ||
|
|
||
| var errorMessages = new List<string>(); | ||
| var messages = new List<string>(); | ||
| var buildEngine = new Mock<IBuildEngine>(); | ||
| buildEngine.Setup(e => e.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())) | ||
| .Callback<BuildErrorEventArgs>(args => errorMessages.Add(args.Message)); | ||
| buildEngine.Setup(e => e.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())) | ||
| .Callback<BuildMessageEventArgs>(args => messages.Add(args.Message)); | ||
|
|
||
| var task = new GenerateStaticWebAssetEndpointsManifest | ||
| { | ||
| BuildEngine = buildEngine.Object, | ||
| TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment(projectDir), | ||
| Assets = Array.Empty<ITaskItem>(), | ||
| Endpoints = Array.Empty<ITaskItem>(), | ||
| Source = "MyProject", | ||
| ManifestType = "Build", | ||
| ExclusionPatterns = "**/excluded.txt", | ||
| ManifestPath = Path.Combine("output", "endpoints.json"), | ||
| CacheFilePath = Path.Combine("output", "endpoints.cache"), | ||
| ExclusionPatternsCacheFilePath = Path.Combine("output", "exclusions.cache"), | ||
| }; | ||
|
|
||
| task.Execute().Should().BeTrue(string.Join("; ", errorMessages)); | ||
|
|
||
| var expectedManifest = Path.Combine(projectOutputDir, "endpoints.json"); | ||
| var expectedExclusionCache = Path.Combine(projectOutputDir, "exclusions.cache"); | ||
| File.Exists(expectedManifest).Should().BeTrue("endpoints manifest must be written under TaskEnvironment.ProjectDirectory, not the process CWD"); | ||
| File.Exists(expectedExclusionCache).Should().BeTrue("exclusion-patterns cache must be written under TaskEnvironment.ProjectDirectory, not the process CWD"); | ||
|
|
||
| File.Exists(Path.Combine(spawnOutputDir, "endpoints.json")).Should().BeFalse(); | ||
| File.Exists(Path.Combine(spawnOutputDir, "exclusions.cache")).Should().BeFalse(); | ||
| messages.Should().Contain($"Creating artifact because artifact file '{expectedManifest}' does not exist."); | ||
| } | ||
| finally | ||
| { | ||
| Directory.SetCurrentDirectory(originalCurrentDirectory); | ||
| if (Directory.Exists(testRoot)) | ||
| { | ||
| Directory.Delete(testRoot, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(OperatingSystems.Linux | OperatingSystems.OSX)] | ||
| public void WritesEndpointsManifestWhenPathIsWhitespace() | ||
| { | ||
| var projectDir = Path.Combine(AppContext.BaseDirectory, TestRootName, Guid.NewGuid().ToString("N")[..8], "ws"); | ||
| Directory.CreateDirectory(projectDir); | ||
|
|
||
| try | ||
| { | ||
| var task = new GenerateStaticWebAssetEndpointsManifest | ||
| { | ||
| BuildEngine = new Mock<IBuildEngine>().Object, | ||
| TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment(projectDir), | ||
| Assets = [], | ||
| Endpoints = [], | ||
| Source = "MyProject", | ||
| ManifestType = "Build", | ||
| ManifestPath = " ", | ||
| }; | ||
|
|
||
| task.Execute().Should().BeTrue(); | ||
| File.Exists(Path.Combine(projectDir, " ")).Should().BeTrue(); | ||
| } | ||
| finally | ||
| { | ||
| Directory.Delete(projectDir, recursive: true); | ||
| } | ||
| } | ||
| } |
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.