dependabot-nuget 0.291.0 → 0.293.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/.editorconfig +1 -0
  3. data/helpers/lib/NuGetUpdater/.gitignore +1 -0
  4. data/helpers/lib/NuGetUpdater/Directory.Build.props +1 -0
  5. data/helpers/lib/NuGetUpdater/Directory.Packages.props +2 -1
  6. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Correlator.cs +197 -0
  7. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/DotNetPackageCorrelation.csproj +12 -0
  8. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/PackageMapper.cs +68 -0
  9. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/PackageSet.cs +11 -0
  10. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/Release.cs +25 -0
  11. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/ReleasesFile.cs +9 -0
  12. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/RuntimePackages.cs +11 -0
  13. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/Sdk.cs +13 -0
  14. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/SemVerComparer.cs +16 -0
  15. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/SemVersionConverter.cs +42 -0
  16. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Cli/DotNetPackageCorrelation.Cli.csproj +16 -0
  17. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Cli/Program.cs +32 -0
  18. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Test/CorrelatorTests.cs +99 -0
  19. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Test/DotNetPackageCorrelation.Test.csproj +18 -0
  20. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Test/EndToEndTests.cs +30 -0
  21. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Test/RuntimePackagesTests.cs +206 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/AnalyzeCommand.cs +6 -4
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/CloneCommand.cs +1 -1
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +19 -4
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +5 -5
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +17 -5
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs +8 -1
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +128 -4
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +8 -0
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +9 -7
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/DependencyFinder.cs +4 -4
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/Extensions.cs +1 -1
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementConverter.cs +19 -1
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/BadRequirementException.cs +9 -0
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Clone/CloneWorker.cs +40 -8
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.targets +2 -2
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +65 -23
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +3 -3
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +99 -2
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/EnsureDotNetPackageCorrelation.targets +25 -0
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +15 -5
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +5 -1
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/MissingFileException.cs +2 -1
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NativeResult.cs +3 -3
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +4 -0
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/BadRequirement.cs +10 -0
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CommitOptions.cs +1 -1
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyFileNotFound.cs +7 -2
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyFileNotParseable.cs +15 -0
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +25 -2
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobRepoNotFound.cs +1 -4
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PrivateSourceAuthenticationFailure.cs +1 -1
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/UnknownError.cs +6 -2
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/UpdateNotPossible.cs +1 -1
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +9 -18
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/UnparseableFileException.cs +12 -0
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/LockFileUpdater.cs +1 -1
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +21 -0
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +6 -30
  60. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs +12 -1
  61. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/DependencyConflictResolver.cs +0 -7
  62. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/DotNetPackageCorrelationManager.cs +46 -0
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +59 -30
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +1 -1
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProjectHelper.cs +4 -4
  66. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTestBase.cs +15 -4
  67. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +15 -9
  68. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Clone/CloneWorkerTests.cs +60 -2
  69. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +20 -3
  70. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +56 -0
  71. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +108 -0
  72. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +16 -12
  73. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/ExpectedDiscoveryResults.cs +1 -0
  74. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/MockNuGetPackage.cs +15 -28
  75. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +5 -4
  76. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +84 -40
  77. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestBase.cs +24 -0
  78. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/ExpectedUpdateOperationResult.cs +1 -1
  79. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +25 -11
  80. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DirsProj.cs +1 -1
  81. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +2 -2
  82. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.LockFile.cs +251 -0
  83. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +14 -8
  84. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +154 -9
  85. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +71 -15
  86. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +38 -20
  87. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/ProjectHelperTests.cs +65 -0
  88. data/helpers/lib/NuGetUpdater/NuGetUpdater.sln +18 -1
  89. data/helpers/lib/NuGetUpdater/global.json +1 -1
  90. data/lib/dependabot/nuget/language.rb +21 -5
  91. data/lib/dependabot/nuget/native_helpers.rb +41 -14
  92. data/lib/dependabot/nuget/package_manager.rb +4 -4
  93. metadata +30 -7
  94. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ErrorType.cs +0 -11
@@ -77,11 +77,11 @@ internal static class ProjectHelper
77
77
  var itemPath = projectRootElement.Items
78
78
  .Where(i => i.ElementName.Equals("None", StringComparison.OrdinalIgnoreCase) ||
79
79
  i.ElementName.Equals("Content", StringComparison.OrdinalIgnoreCase))
80
- .Where(i => Path.GetFileName(i.Include).Equals(itemFileName, StringComparison.OrdinalIgnoreCase))
81
- .Select(i => Path.GetFullPath(Path.Combine(projectDirectory, i.Include)))
80
+ .Where(i => !string.IsNullOrEmpty(i.Include))
81
+ .Select(i => Path.GetFullPath(Path.Combine(projectDirectory, i.Include.NormalizePathToUnix())))
82
+ .Where(p => Path.GetFileName(p).Equals(itemFileName, StringComparison.OrdinalIgnoreCase))
82
83
  .Where(File.Exists)
83
- .FirstOrDefault()
84
- ?.NormalizePathToUnix();
84
+ .FirstOrDefault();
85
85
  return itemPath;
86
86
  }
87
87
 
@@ -12,7 +12,7 @@ namespace NuGetUpdater.Core.Test.Analyze;
12
12
 
13
13
  using TestFile = (string Path, string Content);
14
14
 
15
- public class AnalyzeWorkerTestBase
15
+ public class AnalyzeWorkerTestBase : TestBase
16
16
  {
17
17
  protected static async Task TestAnalyzeAsync(
18
18
  WorkspaceDiscoveryResult discovery,
@@ -39,7 +39,7 @@ public class AnalyzeWorkerTestBase
39
39
  var discoveryPath = Path.GetFullPath(DiscoveryWorker.DiscoveryResultFileName, directoryPath);
40
40
  var dependencyPath = Path.GetFullPath(relativeDependencyPath, directoryPath);
41
41
 
42
- var worker = new AnalyzeWorker(experimentsManager, new TestLogger());
42
+ var worker = new AnalyzeWorker("TEST-JOB-ID", experimentsManager, new TestLogger());
43
43
  var result = await worker.RunWithErrorHandlingAsync(directoryPath, discoveryPath, dependencyPath);
44
44
  return result;
45
45
  });
@@ -55,8 +55,7 @@ public class AnalyzeWorkerTestBase
55
55
  Assert.Equal(expectedResult.VersionComesFromMultiDependencyProperty, actualResult.VersionComesFromMultiDependencyProperty);
56
56
  ValidateDependencies(expectedResult.UpdatedDependencies, actualResult.UpdatedDependencies);
57
57
  Assert.Equal(expectedResult.ExpectedUpdatedDependenciesCount ?? expectedResult.UpdatedDependencies.Length, actualResult.UpdatedDependencies.Length);
58
- Assert.Equal(expectedResult.ErrorType, actualResult.ErrorType);
59
- Assert.Equal(expectedResult.ErrorDetails, actualResult.ErrorDetails);
58
+ ValidateResult(expectedResult, actualResult);
60
59
 
61
60
  return;
62
61
 
@@ -81,6 +80,18 @@ public class AnalyzeWorkerTestBase
81
80
  }
82
81
  }
83
82
 
83
+ protected static void ValidateResult(ExpectedAnalysisResult? expectedResult, AnalysisResult actualResult)
84
+ {
85
+ if (expectedResult?.Error is not null)
86
+ {
87
+ ValidateError(expectedResult.Error, actualResult.Error);
88
+ }
89
+ else
90
+ {
91
+ Assert.Null(actualResult.Error);
92
+ }
93
+ }
94
+
84
95
  protected static async Task<AnalysisResult> RunAnalyzerAsync(string dependencyName, TestFile[] files, Func<string, Task<AnalysisResult>> action)
85
96
  {
86
97
  // write initial files
@@ -4,6 +4,7 @@ using System.Text.Json;
4
4
  using NuGet;
5
5
 
6
6
  using NuGetUpdater.Core.Analyze;
7
+ using NuGetUpdater.Core.Run.ApiModel;
7
8
 
8
9
  using Xunit;
9
10
 
@@ -1015,8 +1016,7 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
1015
1016
  using var temporaryDirectory = await TemporaryDirectory.CreateWithContentsAsync([]);
1016
1017
  await AnalyzeWorker.WriteResultsAsync(temporaryDirectory.DirectoryPath, "Some.Dependency", new()
1017
1018
  {
1018
- ErrorType = ErrorType.AuthenticationFailure,
1019
- ErrorDetails = "<some package feed>",
1019
+ Error = new PrivateSourceAuthenticationFailure(["<some package feed>"]),
1020
1020
  UpdatedVersion = "",
1021
1021
  UpdatedDependencies = [],
1022
1022
  }, new TestLogger());
@@ -1025,16 +1025,23 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
1025
1025
  // raw result file should look like this:
1026
1026
  // {
1027
1027
  // ...
1028
- // "ErrorType": "AuthenticationFailure",
1028
+ // "Error": {
1029
+ // "error-type": "private_source_authentication_failure",
1030
+ // "error-details": {
1031
+ // "source": "(<some package feed>)"
1032
+ // }
1033
+ // }
1029
1034
  // "ErrorDetails": "<some package feed>",
1030
1035
  // ...
1031
1036
  // }
1032
1037
  var jsonDocument = JsonDocument.Parse(discoveryContents);
1033
- var errorType = jsonDocument.RootElement.GetProperty("ErrorType");
1034
- var errorDetails = jsonDocument.RootElement.GetProperty("ErrorDetails");
1038
+ var error = jsonDocument.RootElement.GetProperty("Error");
1039
+ var errorType = error.GetProperty("error-type");
1040
+ var errorDetails = error.GetProperty("error-details");
1041
+ var errorSource = errorDetails.GetProperty("source");
1035
1042
 
1036
- Assert.Equal("AuthenticationFailure", errorType.GetString());
1037
- Assert.Equal("<some package feed>", errorDetails.GetString());
1043
+ Assert.Equal("private_source_authentication_failure", errorType.GetString());
1044
+ Assert.Equal("(<some package feed>)", errorSource.GetString());
1038
1045
  }
1039
1046
 
1040
1047
  [Fact]
@@ -1110,8 +1117,7 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
1110
1117
  },
1111
1118
  expectedResult: new()
1112
1119
  {
1113
- ErrorType = ErrorType.AuthenticationFailure,
1114
- ErrorDetails = $"({http.BaseUrl.TrimEnd('/')}/index.json)",
1120
+ Error = new PrivateSourceAuthenticationFailure([$"{http.BaseUrl.TrimEnd('/')}/index.json"]),
1115
1121
  UpdatedVersion = string.Empty,
1116
1122
  CanUpdate = false,
1117
1123
  UpdatedDependencies = [],
@@ -95,6 +95,65 @@ public class CloneWorkerTests
95
95
  );
96
96
  }
97
97
 
98
+ [Fact]
99
+ public async Task JobFileParseErrorIsReported_InvalidJson()
100
+ {
101
+ // arrange
102
+ var testApiHandler = new TestApiHandler();
103
+ var testGitCommandHandler = new TestGitCommandHandler();
104
+ var cloneWorker = new CloneWorker("JOB-ID", testApiHandler, testGitCommandHandler);
105
+ using var testDirectory = new TemporaryDirectory();
106
+ var jobFilePath = Path.Combine(testDirectory.DirectoryPath, "job.json");
107
+ await File.WriteAllTextAsync(jobFilePath, "not json");
108
+
109
+ // act
110
+ var result = await cloneWorker.RunAsync(new FileInfo(jobFilePath), new DirectoryInfo(testDirectory.DirectoryPath));
111
+
112
+ // assert
113
+ Assert.Equal(1, result);
114
+ var expectedParseErrorObject = testApiHandler.ReceivedMessages.Single(m => m.Type == typeof(UnknownError));
115
+ var unknownError = (UnknownError)expectedParseErrorObject.Object;
116
+ Assert.Equal("JsonException", unknownError.Details["error-class"]);
117
+ }
118
+
119
+ [Fact]
120
+ public async Task JobFileParseErrorIsReported_BadRequirement()
121
+ {
122
+ // arrange
123
+ var testApiHandler = new TestApiHandler();
124
+ var testGitCommandHandler = new TestGitCommandHandler();
125
+ var cloneWorker = new CloneWorker("JOB-ID", testApiHandler, testGitCommandHandler);
126
+ using var testDirectory = new TemporaryDirectory();
127
+ var jobFilePath = Path.Combine(testDirectory.DirectoryPath, "job.json");
128
+
129
+ // write a job file with a valid shape, but invalid requirement
130
+ await File.WriteAllTextAsync(jobFilePath, """
131
+ {
132
+ "job": {
133
+ "source": {
134
+ "provider": "github",
135
+ "repo": "test/repo"
136
+ },
137
+ "security-advisories": [
138
+ {
139
+ "dependency-name": "Some.Dependency",
140
+ "affected-versions": ["not a valid requirement"]
141
+ }
142
+ ]
143
+ }
144
+ }
145
+ """);
146
+
147
+ // act
148
+ var result = await cloneWorker.RunAsync(new FileInfo(jobFilePath), new DirectoryInfo(testDirectory.DirectoryPath));
149
+
150
+ // assert
151
+ Assert.Equal(1, result);
152
+ var expectedParseErrorObject = testApiHandler.ReceivedMessages.Single(m => m.Type == typeof(BadRequirement));
153
+ var badRequirement = (BadRequirement)expectedParseErrorObject.Object;
154
+ Assert.Equal("not a valid requirement", badRequirement.Details["message"]);
155
+ }
156
+
98
157
  private class TestGitCommandHandlerWithOutputs : TestGitCommandHandler
99
158
  {
100
159
  private readonly string _stdout;
@@ -134,8 +193,7 @@ public class CloneWorkerTests
134
193
  // arrange
135
194
  var testApiHandler = new TestApiHandler();
136
195
  testGitCommandHandler ??= new TestGitCommandHandler();
137
- var testLogger = new TestLogger();
138
- var worker = new CloneWorker(testApiHandler, testGitCommandHandler, testLogger);
196
+ var worker = new CloneWorker("TEST-JOB-ID", testApiHandler, testGitCommandHandler);
139
197
 
140
198
  // act
141
199
  var job = new Job()
@@ -5,7 +5,9 @@ using System.Text.Json;
5
5
 
6
6
  using NuGetUpdater.Core.Discover;
7
7
  using NuGetUpdater.Core.Test.Update;
8
+ using NuGetUpdater.Core.Test.Updater;
8
9
  using NuGetUpdater.Core.Test.Utilities;
10
+ using NuGetUpdater.Core.Updater;
9
11
  using NuGetUpdater.Core.Utilities;
10
12
 
11
13
  using Xunit;
@@ -28,7 +30,7 @@ public class DiscoveryWorkerTestBase : TestBase
28
30
  {
29
31
  await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, directoryPath);
30
32
 
31
- var worker = new DiscoveryWorker(experimentsManager, new TestLogger());
33
+ var worker = new DiscoveryWorker("TEST-JOB-ID", experimentsManager, new TestLogger());
32
34
  var result = await worker.RunWithErrorHandlingAsync(directoryPath, workspacePath);
33
35
  return result;
34
36
  });
@@ -44,8 +46,7 @@ public class DiscoveryWorkerTestBase : TestBase
44
46
  ValidateResultWithDependencies(expectedResult.DotNetToolsJson, actualResult.DotNetToolsJson);
45
47
  ValidateProjectResults(expectedResult.Projects, actualResult.Projects, experimentsManager);
46
48
  Assert.Equal(expectedResult.ExpectedProjectCount ?? expectedResult.Projects.Length, actualResult.Projects.Length);
47
- Assert.Equal(expectedResult.ErrorType, actualResult.ErrorType);
48
- Assert.Equal(expectedResult.ErrorDetails, actualResult.ErrorDetails);
49
+ ValidateDiscoveryOperationResult(expectedResult, actualResult);
49
50
 
50
51
  return;
51
52
 
@@ -67,6 +68,22 @@ public class DiscoveryWorkerTestBase : TestBase
67
68
  }
68
69
  }
69
70
 
71
+ protected static void ValidateDiscoveryOperationResult(ExpectedWorkspaceDiscoveryResult? expectedResult, WorkspaceDiscoveryResult actualResult)
72
+ {
73
+ if (expectedResult?.Error is not null)
74
+ {
75
+ ValidateError(expectedResult.Error, actualResult.Error);
76
+ }
77
+ else if (expectedResult?.ErrorRegex is not null)
78
+ {
79
+ ValidateErrorRegex(expectedResult.ErrorRegex, actualResult.Error);
80
+ }
81
+ else
82
+ {
83
+ Assert.Null(actualResult.Error);
84
+ }
85
+ }
86
+
70
87
  internal static void ValidateProjectResults(ImmutableArray<ExpectedSdkProjectDiscoveryResult> expectedProjects, ImmutableArray<ProjectDiscoveryResult> actualProjects, ExperimentsManager experimentsManager)
71
88
  {
72
89
  if (expectedProjects.IsDefaultOrEmpty)
@@ -115,5 +115,61 @@ public partial class DiscoveryWorkerTests
115
115
  }
116
116
  );
117
117
  }
118
+
119
+ [Theory]
120
+ [InlineData(true)]
121
+ [InlineData(false)]
122
+ public async Task DiscoveryIsMergedWithPackageReferences(bool useDirectDiscovery)
123
+ {
124
+ await TestDiscoveryAsync(
125
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery },
126
+ packages:
127
+ [
128
+ MockNuGetPackage.CreateSimplePackage("Package.A", "1.0.0", "net46"),
129
+ MockNuGetPackage.CreateSimplePackage("Package.B", "2.0.0", "net46"),
130
+ ],
131
+ workspacePath: "src",
132
+ files: [
133
+ ("src/myproj.csproj", """
134
+ <Project Sdk="Microsoft.NET.Sdk">
135
+ <PropertyGroup>
136
+ <TargetFramework>net46</TargetFramework>
137
+ </PropertyGroup>
138
+ <ItemGroup>
139
+ <None Include="..\unexpected-directory\packages.config" />
140
+ <PackageReference Include="Package.B" Version="2.0.0" />
141
+ </ItemGroup>
142
+ </Project>
143
+ """),
144
+ ("unexpected-directory/packages.config", """
145
+ <?xml version="1.0" encoding="utf-8"?>
146
+ <packages>
147
+ <package id="Package.A" version="1.0.0" targetFramework="net46" />
148
+ </packages>
149
+ """),
150
+ ],
151
+ expectedResult: new()
152
+ {
153
+ Path = "src",
154
+ Projects = [
155
+ new()
156
+ {
157
+ FilePath = "myproj.csproj",
158
+ Properties = [new("TargetFramework", "net46", "src/myproj.csproj")],
159
+ TargetFrameworks = ["net46"],
160
+ Dependencies = [
161
+ new("Package.A", "1.0.0", DependencyType.PackagesConfig, TargetFrameworks: ["net46"]),
162
+ new("Package.B", "2.0.0", DependencyType.PackageReference, IsDirect: true, TargetFrameworks: ["net46"]),
163
+ ],
164
+ ReferencedProjectPaths = [],
165
+ ImportedFiles = [],
166
+ AdditionalFiles = [
167
+ "../unexpected-directory/packages.config"
168
+ ],
169
+ }
170
+ ],
171
+ }
172
+ );
173
+ }
118
174
  }
119
175
  }
@@ -1263,5 +1263,113 @@ public partial class DiscoveryWorkerTests
1263
1263
  }
1264
1264
  );
1265
1265
  }
1266
+
1267
+ [Fact]
1268
+ public async Task PackagesManagedAndRemovedByTheSdkAreReported()
1269
+ {
1270
+ // To avoid a unit test that's tightly coupled to the installed SDK, some files are faked.
1271
+ // First up, the `dotnet-package-correlation.json` is faked to have the appropriate shape to report a
1272
+ // package replacement. Doing this requires a temporary file and environment variable override.
1273
+ using var tempDirectory = new TemporaryDirectory();
1274
+ var packageCorrelationFile = Path.Combine(tempDirectory.DirectoryPath, "dotnet-package-correlation.json");
1275
+ await File.WriteAllTextAsync(packageCorrelationFile, """
1276
+ {
1277
+ "Runtimes": {
1278
+ "1.0.0": {
1279
+ "Packages": {
1280
+ "Dependabot.App.Core.Ref": "1.0.0",
1281
+ "Test.Only.Package": "1.0.0"
1282
+ }
1283
+ },
1284
+ "1.0.1": {
1285
+ "Packages": {
1286
+ "Dependabot.App.Core.Ref": "1.0.1",
1287
+ "Test.Only.Package": "1.0.99"
1288
+ }
1289
+ }
1290
+ }
1291
+ }
1292
+ """);
1293
+ using var tempEnvironment = new TemporaryEnvironment([("DOTNET_PACKAGE_CORRELATION_FILE_PATH", packageCorrelationFile)]);
1294
+
1295
+ // The SDK package handling is detected in a very specific circumstance; an assembly being removed from the
1296
+ // `@(References)` item group in the `_HandlePackageFileConflicts` target. Since we don't want to involve
1297
+ // the real SDK, we fake some required targets.
1298
+ await TestDiscoveryAsync(
1299
+ experimentsManager: new ExperimentsManager() { InstallDotnetSdks = true, UseDirectDiscovery = true },
1300
+ packages: [],
1301
+ workspacePath: "",
1302
+ files:
1303
+ [
1304
+ ("project.csproj", """
1305
+ <Project>
1306
+ <!-- note that the attribute `Sdk="Microsoft.NET.Sdk"` is missing because we don't want the real SDK interfering -->
1307
+
1308
+ <!-- this allows custom targets to be injected for dependency detection -->
1309
+ <Import Project="$(CustomAfterMicrosoftCommonTargets)" Condition="Exists('$(CustomAfterMicrosoftCommonTargets)')" />
1310
+
1311
+ <PropertyGroup>
1312
+ <TargetFramework>net8.0</TargetFramework>
1313
+ </PropertyGroup>
1314
+
1315
+ <ItemGroup>
1316
+ <!-- we need a value in this item group with the appropriate metadata to simulate it having been added by NuGet -->
1317
+ <RuntimeCopyLocalItems Include="TestOnlyAssembly.dll" NuGetPackageId="Test.Only.Package" NuGetPackageVersion="1.0.0" />
1318
+
1319
+ <!-- this represents the assemblies being extracted from the package -->
1320
+ <Reference Include="@(RuntimeCopyLocalItems)" />
1321
+ </ItemGroup>
1322
+
1323
+ <Target Name="_HandlePackageFileConflicts">
1324
+ <!-- this target needs to exist for discovery to work -->
1325
+ <ItemGroup>
1326
+ <!-- this removal is what triggers the package lookup in the correlation file -->
1327
+ <Reference Remove="TestOnlyAssembly.dll" />
1328
+
1329
+ <!-- this addition is what's used for the lookup -->
1330
+ <Reference Include="TestOnlyAssembly.dll" NuGetPackageId="Dependabot.App.Core.Ref" NuGetPackageVersion="1.0.1" />
1331
+ </ItemGroup>
1332
+ </Target>
1333
+
1334
+ <Target Name="ResolveAssemblyReferences" DependsOnTargets="_HandlePackageFileConflicts">
1335
+ <!-- this target needs to exist for discovery to work -->
1336
+ </Target>
1337
+
1338
+ <Target Name="GenerateBuildDependencyFile">
1339
+ <!-- this target needs to exist for discovery to work -->
1340
+ <ItemGroup>
1341
+ <!-- this removal is what removes the regular package reference from the project -->
1342
+ <RuntimeCopyLocalItems Remove="TestOnlyAssembly.dll" />
1343
+ </ItemGroup>
1344
+ </Target>
1345
+
1346
+ <Target Name="ResolvePackageAssets">
1347
+ <!-- this target needs to exist for discovery to work -->
1348
+ </Target>
1349
+ </Project>
1350
+ """)
1351
+ ],
1352
+ expectedResult: new()
1353
+ {
1354
+ Path = "",
1355
+ Projects = [
1356
+ new()
1357
+ {
1358
+ FilePath = "project.csproj",
1359
+ Dependencies = [
1360
+ new("Test.Only.Package", "1.0.99", DependencyType.Unknown, TargetFrameworks: ["net8.0"], IsTransitive: true)
1361
+ ],
1362
+ Properties = [
1363
+ new("TargetFramework", "net8.0", "project.csproj")
1364
+ ],
1365
+ TargetFrameworks = ["net8.0"],
1366
+ ReferencedProjectPaths = [],
1367
+ ImportedFiles = [],
1368
+ AdditionalFiles = [],
1369
+ }
1370
+ ]
1371
+ }
1372
+ );
1373
+ }
1266
1374
  }
1267
1375
  }
@@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
3
3
  using System.Text.Json;
4
4
 
5
5
  using NuGetUpdater.Core.Discover;
6
+ using NuGetUpdater.Core.Run.ApiModel;
6
7
 
7
8
  using Xunit;
8
9
 
@@ -1130,8 +1131,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
1130
1131
  {
1131
1132
  Path = "",
1132
1133
  Projects = [],
1133
- ErrorType = ErrorType.DependencyFileNotParseable,
1134
- ErrorDetails = "project2.csproj",
1134
+ Error = new DependencyFileNotParseable("project2.csproj"),
1135
1135
  });
1136
1136
  }
1137
1137
 
@@ -1142,8 +1142,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
1142
1142
  var discoveryResultPath = Path.Combine(temporaryDirectory.DirectoryPath, DiscoveryWorker.DiscoveryResultFileName);
1143
1143
  await DiscoveryWorker.WriteResultsAsync(temporaryDirectory.DirectoryPath, discoveryResultPath, new()
1144
1144
  {
1145
- ErrorType = ErrorType.AuthenticationFailure,
1146
- ErrorDetails = "<some package feed>",
1145
+ Error = new PrivateSourceAuthenticationFailure(["<some package feed>"]),
1147
1146
  Path = "/",
1148
1147
  Projects = [],
1149
1148
  });
@@ -1152,16 +1151,22 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
1152
1151
  // raw result file should look like this:
1153
1152
  // {
1154
1153
  // ...
1155
- // "ErrorType": "AuthenticationFailure",
1156
- // "ErrorDetails": "<some package feed>",
1154
+ // "Error": {
1155
+ // "error-type": "private_source_authentication_failure",
1156
+ // "error-detail": {
1157
+ // "source": "(<some package feed>)"
1158
+ // }
1159
+ // }
1157
1160
  // ...
1158
1161
  // }
1159
1162
  var jsonDocument = JsonDocument.Parse(discoveryContents);
1160
- var errorType = jsonDocument.RootElement.GetProperty("ErrorType");
1161
- var errorDetails = jsonDocument.RootElement.GetProperty("ErrorDetails");
1163
+ var error = jsonDocument.RootElement.GetProperty("Error");
1164
+ var errorType = error.GetProperty("error-type");
1165
+ var errorDetail = error.GetProperty("error-details");
1166
+ var errorSource = errorDetail.GetProperty("source");
1162
1167
 
1163
- Assert.Equal("AuthenticationFailure", errorType.GetString());
1164
- Assert.Equal("<some package feed>", errorDetails.GetString());
1168
+ Assert.Equal("private_source_authentication_failure", errorType.GetString());
1169
+ Assert.Equal("(<some package feed>)", errorSource.GetString());
1165
1170
  }
1166
1171
 
1167
1172
  [Theory]
@@ -1236,8 +1241,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
1236
1241
  ],
1237
1242
  expectedResult: new()
1238
1243
  {
1239
- ErrorType = ErrorType.AuthenticationFailure,
1240
- ErrorDetails = $"({http.BaseUrl.TrimEnd('/')}/index.json)",
1244
+ Error = new PrivateSourceAuthenticationFailure([$"{http.BaseUrl.TrimEnd('/')}/index.json"]),
1241
1245
  Path = "",
1242
1246
  Projects = [],
1243
1247
  }
@@ -12,6 +12,7 @@ public record ExpectedWorkspaceDiscoveryResult : NativeResult
12
12
  public int? ExpectedProjectCount { get; init; }
13
13
  public ExpectedDependencyDiscoveryResult? GlobalJson { get; init; }
14
14
  public ExpectedDependencyDiscoveryResult? DotNetToolsJson { get; init; }
15
+ public string? ErrorRegex { get; init; } = null;
15
16
  }
16
17
 
17
18
  public record ExpectedSdkProjectDiscoveryResult : ExpectedDependencyDiscoveryResult
@@ -388,6 +388,17 @@ namespace NuGetUpdater.Core.Test
388
388
  return WellKnownPackages[key];
389
389
  }
390
390
 
391
+ public static MockNuGetPackage GetMicrosoftNETCoreAppRefPackage(int majorRuntimeVersion)
392
+ {
393
+ return WellKnownReferencePackage("Microsoft.NETCore.App", $"net{majorRuntimeVersion}.0",
394
+ [
395
+ ("data/FrameworkList.xml", Encoding.UTF8.GetBytes($"""
396
+ <FileList TargetFrameworkIdentifier=".NETCoreApp" TargetFrameworkVersion="{majorRuntimeVersion}.0" FrameworkName="Microsoft.NETCore.App" Name=".NET Runtime">
397
+ </FileList>
398
+ """))
399
+ ]);
400
+ }
401
+
391
402
  public static MockNuGetPackage WellKnownHostPackage(string packageName, string targetFramework, (string Path, byte[] Content)[]? files = null)
392
403
  {
393
404
  string key = $"{packageName}/{targetFramework}";
@@ -437,34 +448,10 @@ namespace NuGetUpdater.Core.Test
437
448
  WellKnownReferencePackage("Microsoft.AspNetCore.App", "net7.0"),
438
449
  WellKnownReferencePackage("Microsoft.AspNetCore.App", "net8.0"),
439
450
  WellKnownReferencePackage("Microsoft.AspNetCore.App", "net9.0"),
440
- WellKnownReferencePackage("Microsoft.NETCore.App", "net6.0",
441
- [
442
- ("data/FrameworkList.xml", Encoding.UTF8.GetBytes("""
443
- <FileList TargetFrameworkIdentifier=".NETCoreApp" TargetFrameworkVersion="6.0" FrameworkName="Microsoft.NETCore.App" Name=".NET Runtime">
444
- </FileList>
445
- """))
446
- ]),
447
- WellKnownReferencePackage("Microsoft.NETCore.App", "net7.0",
448
- [
449
- ("data/FrameworkList.xml", Encoding.UTF8.GetBytes("""
450
- <FileList TargetFrameworkIdentifier=".NETCoreApp" TargetFrameworkVersion="7.0" FrameworkName="Microsoft.NETCore.App" Name=".NET Runtime">
451
- </FileList>
452
- """))
453
- ]),
454
- WellKnownReferencePackage("Microsoft.NETCore.App", "net8.0",
455
- [
456
- ("data/FrameworkList.xml", Encoding.UTF8.GetBytes("""
457
- <FileList TargetFrameworkIdentifier=".NETCoreApp" TargetFrameworkVersion="8.0" FrameworkName="Microsoft.NETCore.App" Name=".NET Runtime">
458
- </FileList>
459
- """))
460
- ]),
461
- WellKnownReferencePackage("Microsoft.NETCore.App", "net9.0",
462
- [
463
- ("data/FrameworkList.xml", Encoding.UTF8.GetBytes("""
464
- <FileList TargetFrameworkIdentifier=".NETCoreApp" TargetFrameworkVersion="9.0" FrameworkName="Microsoft.NETCore.App" Name=".NET Runtime">
465
- </FileList>
466
- """))
467
- ]),
451
+ GetMicrosoftNETCoreAppRefPackage(6),
452
+ GetMicrosoftNETCoreAppRefPackage(7),
453
+ GetMicrosoftNETCoreAppRefPackage(8),
454
+ GetMicrosoftNETCoreAppRefPackage(9),
468
455
  WellKnownReferencePackage("Microsoft.WindowsDesktop.App", "net6.0"),
469
456
  WellKnownReferencePackage("Microsoft.WindowsDesktop.App", "net7.0"),
470
457
  WellKnownReferencePackage("Microsoft.WindowsDesktop.App", "net8.0"),
@@ -1729,11 +1729,12 @@ public class RunWorkerTests
1729
1729
  experimentsManager ??= new ExperimentsManager();
1730
1730
  var testApiHandler = new TestApiHandler();
1731
1731
  var logger = new TestLogger();
1732
- discoveryWorker ??= new DiscoveryWorker(experimentsManager, logger);
1733
- analyzeWorker ??= new AnalyzeWorker(experimentsManager, logger);
1734
- updaterWorker ??= new UpdaterWorker(experimentsManager, logger);
1732
+ var jobId = "TEST-JOB-ID";
1733
+ discoveryWorker ??= new DiscoveryWorker(jobId, experimentsManager, logger);
1734
+ analyzeWorker ??= new AnalyzeWorker(jobId, experimentsManager, logger);
1735
+ updaterWorker ??= new UpdaterWorker(jobId, experimentsManager, logger);
1735
1736
 
1736
- var worker = new RunWorker(testApiHandler, discoveryWorker, analyzeWorker, updaterWorker, logger);
1737
+ var worker = new RunWorker(jobId, testApiHandler, discoveryWorker, analyzeWorker, updaterWorker, logger);
1737
1738
  var repoContentsPathDirectoryInfo = new DirectoryInfo(tempDirectory.DirectoryPath);
1738
1739
  var actualResult = await worker.RunAsync(job, repoContentsPathDirectoryInfo, "TEST-COMMIT-SHA");
1739
1740
  var actualApiMessages = testApiHandler.ReceivedMessages.ToArray();