dependabot-nuget 0.403.0 → 0.405.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1398,6 +1398,127 @@ public class EndToEndTests
1398
1398
  Assert.Equal("2.1.0", resolvedInLibrary);
1399
1399
  }
1400
1400
 
1401
+ [Theory]
1402
+ [InlineData("net8.0;net472", ".NETFramework,Version=v4.7.2", "net8.0")]
1403
+ [InlineData("net8.0;net9.0;net472", ".NETFramework,Version=v4.7.2", "net8.0", "net9.0")]
1404
+ public async Task LockFilesPreserveTargetFrameworksThroughProjectReferences(string clientTargetFrameworks, params string[] clientLockFileFrameworks)
1405
+ {
1406
+ using var tempDirectory = await TemporaryDirectory.CreateWithContentsAsync(
1407
+ ("projects.slnx", """
1408
+ <Solution>
1409
+ <Project Path="src/client/client.csproj" />
1410
+ <Project Path="src/common/common.csproj" />
1411
+ </Solution>
1412
+ """),
1413
+ ("src/client/client.csproj", $"""
1414
+ <Project Sdk="Microsoft.NET.Sdk">
1415
+ <PropertyGroup>
1416
+ <TargetFrameworks>{clientTargetFrameworks}</TargetFrameworks>
1417
+ </PropertyGroup>
1418
+ <ItemGroup>
1419
+ <PackageReference Include="Some.Package" Version="1.0.0" />
1420
+ <ProjectReference Include="..\common\common.csproj" />
1421
+ </ItemGroup>
1422
+ </Project>
1423
+ """),
1424
+ ("src/client/packages.lock.json", ""),
1425
+ ("src/common/common.csproj", """
1426
+ <Project Sdk="Microsoft.NET.Sdk">
1427
+ <PropertyGroup>
1428
+ <TargetFramework>netstandard2.0</TargetFramework>
1429
+ </PropertyGroup>
1430
+ <ItemGroup>
1431
+ <PackageReference Include="Common.Package" Version="1.0.0" />
1432
+ </ItemGroup>
1433
+ </Project>
1434
+ """),
1435
+ ("src/common/packages.lock.json", "")
1436
+ );
1437
+ var repoContentsPath = tempDirectory.DirectoryPath;
1438
+ await UpdateWorkerTestBase.MockNuGetPackagesInDirectory([
1439
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "netstandard2.0"),
1440
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "netstandard2.0"),
1441
+ MockNuGetPackage.CreateSimplePackage("Common.Package", "1.0.0", "netstandard2.0"),
1442
+ ], repoContentsPath);
1443
+ var lockFiles = new[]
1444
+ {
1445
+ (Path: "src/common/packages.lock.json", Frameworks: new[] { ".NETStandard,Version=v2.0" }, Package: "Common.Package", UpdatedVersion: "1.0.0"),
1446
+ (Path: "src/client/packages.lock.json", Frameworks: clientLockFileFrameworks, Package: "Some.Package", UpdatedVersion: "2.0.0"),
1447
+ };
1448
+ var (exitCode, output, error) = await ProcessEx.RunDotnetWithoutMSBuildEnvironmentVariablesAsync(
1449
+ ["restore", Path.Join(repoContentsPath, "src", "client", "client.csproj")],
1450
+ repoContentsPath);
1451
+ Assert.True(exitCode == 0, $"Initial restore failed.\n{output}\n{error}");
1452
+ foreach (var (path, frameworks, package, _) in lockFiles)
1453
+ {
1454
+ using var lockFile = JsonDocument.Parse(await File.ReadAllTextAsync(Path.Join(repoContentsPath, path), TestContext.Current.CancellationToken));
1455
+ var dependencies = lockFile.RootElement.GetProperty("dependencies");
1456
+ Assert.Equal(frameworks, dependencies.EnumerateObject().Select(p => p.Name).Order().ToArray());
1457
+ foreach (var framework in frameworks)
1458
+ {
1459
+ Assert.Equal("1.0.0", dependencies.GetProperty(framework).GetProperty(package).GetProperty("resolved").GetString());
1460
+ }
1461
+ }
1462
+ await GitTestHelper.InitializeRepositoryAsync(repoContentsPath, [
1463
+ "projects.slnx",
1464
+ "src/client/client.csproj",
1465
+ "src/client/packages.lock.json",
1466
+ "src/common/common.csproj",
1467
+ "src/common/packages.lock.json",
1468
+ ]);
1469
+
1470
+ var jobId = "TEST-JOB-ID";
1471
+ var experimentsManager = new ExperimentsManager();
1472
+ var logger = new TestLogger();
1473
+ var apiHandler = new TestApiHandler();
1474
+ var worker = new RunWorker(
1475
+ jobId,
1476
+ apiHandler,
1477
+ new DiscoveryWorker(jobId, experimentsManager, logger),
1478
+ new AnalyzeWorker(jobId, experimentsManager, logger),
1479
+ new UpdaterWorker(jobId, experimentsManager, logger),
1480
+ logger);
1481
+ var job = new Job()
1482
+ {
1483
+ Dependencies = ["Some.Package"],
1484
+ SecurityAdvisories = [
1485
+ new()
1486
+ {
1487
+ DependencyName = "Some.Package",
1488
+ AffectedVersions = [Requirement.Parse("= 1.0.0")],
1489
+ PatchedVersions = [Requirement.Parse(">= 2.0.0")],
1490
+ }
1491
+ ],
1492
+ SecurityUpdatesOnly = true,
1493
+ Source = new()
1494
+ {
1495
+ Provider = "github",
1496
+ Repo = "test/repo",
1497
+ Directory = "/",
1498
+ }
1499
+ };
1500
+
1501
+ await worker.RunAsync(job, new DirectoryInfo(repoContentsPath), null, "TEST-COMMIT-SHA", experimentsManager);
1502
+
1503
+ Assert.Contains(apiHandler.ReceivedMessages, m => m.Type == typeof(CreatePullRequest));
1504
+ var createPr = (CreatePullRequest)apiHandler.ReceivedMessages.Single(m => m.Type == typeof(CreatePullRequest)).Object;
1505
+ var updatedFiles = createPr.UpdatedDependencyFiles.ToDictionary(df => Path.Join(df.Directory, df.Name).NormalizePathToUnix(), df => df.Content);
1506
+ Assert.Contains("/src/client/packages.lock.json", updatedFiles.Keys);
1507
+ foreach (var (path, frameworks, package, updatedVersion) in lockFiles)
1508
+ {
1509
+ var lockFileContent = updatedFiles.TryGetValue($"/{path}", out var updatedContent)
1510
+ ? updatedContent
1511
+ : await File.ReadAllTextAsync(Path.Join(repoContentsPath, path), TestContext.Current.CancellationToken);
1512
+ using var lockFile = JsonDocument.Parse(lockFileContent);
1513
+ var dependencies = lockFile.RootElement.GetProperty("dependencies");
1514
+ Assert.Equal(frameworks, dependencies.EnumerateObject().Select(p => p.Name).Order().ToArray());
1515
+ foreach (var framework in frameworks)
1516
+ {
1517
+ Assert.Equal(updatedVersion, dependencies.GetProperty(framework).GetProperty(package).GetProperty("resolved").GetString());
1518
+ }
1519
+ }
1520
+ }
1521
+
1401
1522
  [Fact]
1402
1523
  public async Task FindRootDirectory_ExpandsDirectoryThroughProjChain()
1403
1524
  {
@@ -1245,5 +1245,38 @@ public class MiscellaneousTests
1245
1245
  IgnoredUpdateTypes = [ConditionUpdateType.SemVerMajor, ConditionUpdateType.SemVerMinor],
1246
1246
  },
1247
1247
  ];
1248
+
1249
+ // with limited group update types; only major is explicitly allowed => minor and patch are ignored
1250
+ yield return
1251
+ [
1252
+ // job
1253
+ new Job()
1254
+ {
1255
+ Source = new()
1256
+ {
1257
+ Provider = "github",
1258
+ Repo = "some/repo"
1259
+ },
1260
+ },
1261
+ // dependency
1262
+ new Dependency("Some.Dependency", "1.0.0", DependencyType.PackageReference),
1263
+ // groupMatcher
1264
+ new GroupMatcher()
1265
+ {
1266
+ Patterns = ["Some.*"],
1267
+ ExcludePatterns = [],
1268
+ UpdateTypes = [GroupUpdateType.Major],
1269
+ },
1270
+ // expectedDependencyInfo
1271
+ new DependencyInfo()
1272
+ {
1273
+ Name = "Some.Dependency",
1274
+ Version = "1.0.0",
1275
+ IsVulnerable = false,
1276
+ IgnoredVersions = [],
1277
+ Vulnerabilities = [],
1278
+ IgnoredUpdateTypes = [ConditionUpdateType.SemVerMinor, ConditionUpdateType.SemVerPatch],
1279
+ },
1280
+ ];
1248
1281
  }
1249
1282
  }
@@ -961,6 +961,284 @@ public class RefreshSecurityUpdatePullRequestHandlerTests : UpdateHandlersTestsB
961
961
  );
962
962
  }
963
963
 
964
+ [Fact]
965
+ public async Task DoesNotClosePullRequest_WhenEarlierDirectoryAlreadyUpdatedIt()
966
+ {
967
+ await TestAsync(
968
+ job: new Job()
969
+ {
970
+ Dependencies = ["Some.Dependency"],
971
+ ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
972
+ Source = CreateJobSource("/src", "/tests"),
973
+ SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")], PatchedVersions = [Requirement.Parse("2.0.0")] }],
974
+ SecurityUpdatesOnly = true,
975
+ UpdatingAPullRequest = true,
976
+ },
977
+ files: [
978
+ ("src/project.csproj", "initial contents"),
979
+ ("tests/tests.csproj", "initial contents"),
980
+ ],
981
+ discoveryWorker: TestDiscoveryWorker.FromResults(
982
+ ("/src", new WorkspaceDiscoveryResult()
983
+ {
984
+ Path = "/src",
985
+ Projects = [
986
+ new()
987
+ {
988
+ FilePath = "project.csproj",
989
+ Dependencies = [
990
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
991
+ ],
992
+ ImportedFiles = [],
993
+ AdditionalFiles = [],
994
+ }
995
+ ],
996
+ }),
997
+ ("/tests", new WorkspaceDiscoveryResult()
998
+ {
999
+ Path = "/tests",
1000
+ Projects = [
1001
+ new()
1002
+ {
1003
+ FilePath = "tests.csproj",
1004
+ Dependencies = [
1005
+ new("Some.Dependency", "2.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
1006
+ ],
1007
+ ImportedFiles = [],
1008
+ AdditionalFiles = [],
1009
+ }
1010
+ ],
1011
+ })
1012
+ ),
1013
+ analyzeWorker: new TestAnalyzeWorker(input =>
1014
+ {
1015
+ var discovery = input.Item2;
1016
+ return Task.FromResult(new AnalysisResult()
1017
+ {
1018
+ CanUpdate = discovery.Path == "/src",
1019
+ UpdatedVersion = "2.0.0",
1020
+ UpdatedDependencies = [],
1021
+ });
1022
+ }),
1023
+ updaterWorker: new TestUpdaterWorker(async input =>
1024
+ {
1025
+ var repoRoot = input.Item1;
1026
+ var workspacePath = input.Item2;
1027
+
1028
+ await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
1029
+
1030
+ return new UpdateOperationResult()
1031
+ {
1032
+ UpdateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project.csproj"] }],
1033
+ };
1034
+ }),
1035
+ expectedUpdateHandler: RefreshSecurityUpdatePullRequestHandler.Instance,
1036
+ expectedApiMessages: [
1037
+ new UpdatedDependencyList()
1038
+ {
1039
+ Dependencies = [
1040
+ new()
1041
+ {
1042
+ Name = "Some.Dependency",
1043
+ Version = "1.0.0",
1044
+ Requirements = [
1045
+ new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
1046
+ ],
1047
+ },
1048
+ ],
1049
+ DependencyFiles = ["/src/project.csproj"],
1050
+ },
1051
+ new IncrementMetric()
1052
+ {
1053
+ Metric = "updater.started",
1054
+ Tags = new()
1055
+ {
1056
+ ["operation"] = "update_security_pr",
1057
+ }
1058
+ },
1059
+ new UpdatePullRequest()
1060
+ {
1061
+ DependencyNames = ["Some.Dependency"],
1062
+ DependencyGroup = null,
1063
+ UpdatedDependencyFiles = [
1064
+ new()
1065
+ {
1066
+ Directory = "/src",
1067
+ Name = "project.csproj",
1068
+ Content = "updated contents",
1069
+ }
1070
+ ],
1071
+ BaseCommitSha = "TEST-COMMIT-SHA",
1072
+ CommitMessage = EndToEndTests.TestPullRequestCommitMessage,
1073
+ PrTitle = EndToEndTests.TestPullRequestTitle,
1074
+ PrBody = EndToEndTests.TestPullRequestBody,
1075
+ },
1076
+ new UpdatedDependencyList()
1077
+ {
1078
+ Dependencies = [
1079
+ new()
1080
+ {
1081
+ Name = "Some.Dependency",
1082
+ Version = "2.0.0",
1083
+ Requirements = [
1084
+ new() { Requirement = "2.0.0", File = "/tests/tests.csproj", Groups = ["dependencies"] },
1085
+ ],
1086
+ },
1087
+ ],
1088
+ DependencyFiles = ["/tests/tests.csproj"],
1089
+ },
1090
+ new IncrementMetric()
1091
+ {
1092
+ Metric = "updater.started",
1093
+ Tags = new()
1094
+ {
1095
+ ["operation"] = "update_security_pr",
1096
+ }
1097
+ },
1098
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
1099
+ ]
1100
+ );
1101
+ }
1102
+
1103
+ [Fact]
1104
+ public async Task DoesNotClosePullRequest_WhenUpToDateDirectoryIsFollowedByDirectoryNeedingUpdate()
1105
+ {
1106
+ await TestAsync(
1107
+ job: new Job()
1108
+ {
1109
+ Dependencies = ["Some.Dependency"],
1110
+ ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
1111
+ Source = CreateJobSource("/tests", "/src"),
1112
+ SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")], PatchedVersions = [Requirement.Parse("2.0.0")] }],
1113
+ SecurityUpdatesOnly = true,
1114
+ UpdatingAPullRequest = true,
1115
+ },
1116
+ files: [
1117
+ ("src/project.csproj", "initial contents"),
1118
+ ("tests/tests.csproj", "initial contents"),
1119
+ ],
1120
+ discoveryWorker: TestDiscoveryWorker.FromResults(
1121
+ ("/src", new WorkspaceDiscoveryResult()
1122
+ {
1123
+ Path = "/src",
1124
+ Projects = [
1125
+ new()
1126
+ {
1127
+ FilePath = "project.csproj",
1128
+ Dependencies = [
1129
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
1130
+ ],
1131
+ ImportedFiles = [],
1132
+ AdditionalFiles = [],
1133
+ }
1134
+ ],
1135
+ }),
1136
+ ("/tests", new WorkspaceDiscoveryResult()
1137
+ {
1138
+ Path = "/tests",
1139
+ Projects = [
1140
+ new()
1141
+ {
1142
+ FilePath = "tests.csproj",
1143
+ Dependencies = [
1144
+ new("Some.Dependency", "2.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
1145
+ ],
1146
+ ImportedFiles = [],
1147
+ AdditionalFiles = [],
1148
+ }
1149
+ ],
1150
+ })
1151
+ ),
1152
+ analyzeWorker: new TestAnalyzeWorker(input =>
1153
+ {
1154
+ var discovery = input.Item2;
1155
+ return Task.FromResult(new AnalysisResult()
1156
+ {
1157
+ CanUpdate = discovery.Path == "/src",
1158
+ UpdatedVersion = "2.0.0",
1159
+ UpdatedDependencies = [],
1160
+ });
1161
+ }),
1162
+ updaterWorker: new TestUpdaterWorker(async input =>
1163
+ {
1164
+ var repoRoot = input.Item1;
1165
+ var workspacePath = input.Item2;
1166
+
1167
+ await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
1168
+
1169
+ return new UpdateOperationResult()
1170
+ {
1171
+ UpdateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project.csproj"] }],
1172
+ };
1173
+ }),
1174
+ expectedUpdateHandler: RefreshSecurityUpdatePullRequestHandler.Instance,
1175
+ expectedApiMessages: [
1176
+ new UpdatedDependencyList()
1177
+ {
1178
+ Dependencies = [
1179
+ new()
1180
+ {
1181
+ Name = "Some.Dependency",
1182
+ Version = "2.0.0",
1183
+ Requirements = [
1184
+ new() { Requirement = "2.0.0", File = "/tests/tests.csproj", Groups = ["dependencies"] },
1185
+ ],
1186
+ },
1187
+ ],
1188
+ DependencyFiles = ["/tests/tests.csproj"],
1189
+ },
1190
+ new IncrementMetric()
1191
+ {
1192
+ Metric = "updater.started",
1193
+ Tags = new()
1194
+ {
1195
+ ["operation"] = "update_security_pr",
1196
+ }
1197
+ },
1198
+ new UpdatedDependencyList()
1199
+ {
1200
+ Dependencies = [
1201
+ new()
1202
+ {
1203
+ Name = "Some.Dependency",
1204
+ Version = "1.0.0",
1205
+ Requirements = [
1206
+ new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
1207
+ ],
1208
+ },
1209
+ ],
1210
+ DependencyFiles = ["/src/project.csproj"],
1211
+ },
1212
+ new IncrementMetric()
1213
+ {
1214
+ Metric = "updater.started",
1215
+ Tags = new()
1216
+ {
1217
+ ["operation"] = "update_security_pr",
1218
+ }
1219
+ },
1220
+ new UpdatePullRequest()
1221
+ {
1222
+ DependencyNames = ["Some.Dependency"],
1223
+ DependencyGroup = null,
1224
+ UpdatedDependencyFiles = [
1225
+ new()
1226
+ {
1227
+ Directory = "/src",
1228
+ Name = "project.csproj",
1229
+ Content = "updated contents",
1230
+ }
1231
+ ],
1232
+ BaseCommitSha = "TEST-COMMIT-SHA",
1233
+ CommitMessage = EndToEndTests.TestPullRequestCommitMessage,
1234
+ PrTitle = EndToEndTests.TestPullRequestTitle,
1235
+ PrBody = EndToEndTests.TestPullRequestBody,
1236
+ },
1237
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
1238
+ ]
1239
+ );
1240
+ }
1241
+
964
1242
  [Fact]
965
1243
  public async Task RecreatesPullRequest()
966
1244
  {