cake-contrib / Cake.Issues

:cake: :jigsaw: :mag_right: Cake addin for reading and managing issues from any code analyzer or linter that may occur during the build process
https://cakeissues.net
Other
5 stars 12 forks source link

SARIF report marks issues as updated it multiple issues with same persistent properties #699

Closed christianbumann closed 3 months ago

christianbumann commented 3 months ago

Create a Sarif report with two identical issues which only differs on FileLink marks one as Unchanged and the other as Updated. Both issues should be marked as Unchanged.

How to reproduce

Create a test e.g. in SarifIssueReportGeneratorTests

[Fact]
public void Should_Generate_Report_With_BaseLineState_Unchanged_If_Only_File_Link_Has_Changed_On_Multi_Issues()
{
    // Given
    var fixture = new SarifIssueReportFixture();
    fixture.SarifIssueReportFormatSettings.BaselineGuid = Guid.NewGuid();

    var issues =
        new List<IIssue>
        {
            IssueBuilder
                .NewIssue("Message Foo.", "ProviderType Foo", "ProviderName Foo")
                .InFile(@"a", 10, 12, 1, 2)
                .WithFileLink(new Uri("https://github.com/cake-contrib/Cake.Issues/blob/develop/src/Cake.Issues.MsBuild/BaseMsBuildLogFileFormat.cs"))
                .Create(),

            IssueBuilder
                .NewIssue("Message Foo.", "ProviderType Foo", "ProviderName Foo")
                .InFile(@"a", 20, 22, 1, 2)
                .WithFileLink(new Uri("https://github.com/cake-contrib/Cake.Issues/blob/develop/src/Cake.Issues.MsBuild/BaseMsBuildLogFileFormat.cs"))
                .Create(),

        };

    var existingIssues =
        new List<IIssue>
        {
            IssueBuilder
                .NewIssue("Message Foo.", "ProviderType Foo", "ProviderName Foo")
                .InFile(@"a", 10, 12, 1, 2)
                .WithFileLink(new Uri("https://github.com/cake-contrib/Cake.Issues/blob/master/src/Cake.Issues.MsBuild/BaseMsBuildLogFileFormat.cs"))
                .Create(),

            IssueBuilder
                .NewIssue("Message Foo.", "ProviderType Foo", "ProviderName Foo")
                .InFile(@"a", 20, 22, 1, 2)
                .WithFileLink(new Uri("https://github.com/cake-contrib/Cake.Issues/blob/master/src/Cake.Issues.MsBuild/BaseMsBuildLogFileFormat.cs"))
                .Create(),
        };

    fixture.SarifIssueReportFormatSettings.ExistingIssues.AddRange(existingIssues);

    // When
    var logContents = fixture.CreateReport(issues);

    // Then
    var sarifLog = JsonConvert.DeserializeObject<SarifLog>(logContents);

    var run = sarifLog.Runs.ShouldHaveSingleItem();
    run.Results.Count.ShouldBe(2);
    run.Results[0].BaselineState.ShouldBe(BaselineState.Unchanged);
    run.Results[1].BaselineState.ShouldBe(BaselineState.Unchanged);
}
christianbumann commented 3 months ago

existingIssuesSet should contains 2 items, but there is only 1 item.

https://github.com/cake-contrib/Cake.Issues/blob/15de6704ad99d85ae441643cf372a25235064f9d/src/Cake.Issues.Reporting.Sarif/SarifIssueReportGenerator.cs#L66