Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,97 @@ await TestAsync(
]
);
}

[Fact]
public async Task ErrantFileUpdatesDoNotCauseCallToCreatePullRequest()
{
// if an external tool inadvertently updates files on disk without reporting any update operations, don't try
// to create a PR
await TestAsync(
job: new Job()
{
Dependencies = ["Some.Dependency"],
SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")] }],
SecurityUpdatesOnly = true,
Source = CreateJobSource("/src"),
},
files: [
("src/project.csproj", "initial project contents"),
("src/packages.config", "initial packages contents"),
],
discoveryWorker: TestDiscoveryWorker.FromResults(
("/src", new WorkspaceDiscoveryResult()
{
Path = "/src",
Projects = [
new()
{
FilePath = "project.csproj",
Dependencies = [
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
],
ImportedFiles = [],
AdditionalFiles = ["packages.config"],
}
],
})
),
analyzeWorker: new TestAnalyzeWorker(async input =>
{
var repoRoot = input.Item1;
var discovery = input.Item2;
var dependencyInfo = input.Item3;
if (dependencyInfo.Name != "Some.Dependency")
{
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
}

// no update possible but a file was touched on disk
var projectPath = Path.Join(repoRoot, discovery.Path, discovery.Projects.Single().FilePath);
var packagesConfigPath = Path.Join(Path.GetDirectoryName(projectPath), "packages.config");
await File.WriteAllTextAsync(packagesConfigPath, "updated packages contents");

return new AnalysisResult()
{
CanUpdate = false,
UpdatedVersion = "1.0.0",
UpdatedDependencies = [],
};
}),
updaterWorker: new TestUpdaterWorker(async input =>
{
return new UpdateOperationResult()
{
UpdateOperations = [],
};
}),
expectedUpdateHandler: CreateSecurityUpdatePullRequestHandler.Instance,
expectedApiMessages: [
new UpdatedDependencyList()
{
Dependencies = [
new()
{
Name = "Some.Dependency",
Version = "1.0.0",
Requirements = [
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
],
},
],
DependencyFiles = ["/src/packages.config", "/src/project.csproj"],
},
new IncrementMetric()
{
Metric = "updater.started",
Tags = new()
{
["operation"] = "create_security_pr",
}
},
new SecurityUpdateNotFound("Some.Dependency", "1.0.0"),
new MarkAsProcessed("TEST-COMMIT-SHA"),
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task HandleAsync(Job job, DirectoryInfo originalRepoContentsPath, D
}
}

if (updatedDependencyFiles.Length > 0)
if (updateOperationsPerformed.Count > 0 && updatedDependencyFiles.Length > 0)
{
var commitMessage = PullRequestTextGenerator.GetPullRequestCommitMessage(job, [.. updateOperationsPerformed], null);
var prTitle = PullRequestTextGenerator.GetPullRequestTitle(job, [.. updateOperationsPerformed], null);
Expand Down
Loading