Skip to content

Commit

Permalink
Improving baseliner (#2290)
Browse files Browse the repository at this point in the history
* Improving baseliner

* Adding test  to verify new behavior
  • Loading branch information
eddynaka authored Feb 24, 2021
1 parent 9c24de0 commit ba447a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public Result CalculateBasedlinedResult(DictionaryMergeBehavior propertyBagMerge
{
// Baseline result and current result have been matched => existing.
result = ConstructExistingResult(resultMatchingProperties, out originalResultMatchingProperties);

var previousResult = new Result { Locations = PreviousResult.Result.Locations };
var currenResult = new Result { Locations = CurrentResult.Result.Locations };

if (previousResult.ValueGetHashCode() != currenResult.ValueGetHashCode())
{
result.BaselineState = BaselineState.Updated;
}
}
else if (PreviousResult == null && CurrentResult != null)
{
Expand Down
24 changes: 23 additions & 1 deletion src/Test.UnitTests.Sarif/Baseline2/MatchedResultsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,29 @@ private struct FirstDetectionTimeTestCase
},
ExpectedBaselineState = BaselineState.Unchanged,
ExpectedFirstDetectionTime = previousRunEndTime
}
},
new FirstDetectionTimeTestCase
{
Name = "Updated, new location",
PreviousResult = new Result
{
Locations = new []
{
new Location { PhysicalLocation = new PhysicalLocation { ArtifactLocation = new ArtifactLocation{ Uri = new Uri("a.sarif", UriKind.Relative)}}}
}
},
PreviousRun = new Run(),
CurrentResult = new Result
{
Locations = new []
{
new Location { PhysicalLocation = new PhysicalLocation { ArtifactLocation = new ArtifactLocation{ Uri = new Uri("a.sarif", UriKind.Relative)}}},
new Location { PhysicalLocation = new PhysicalLocation { ArtifactLocation = new ArtifactLocation{ Uri = new Uri("b.sarif", UriKind.Relative)}}},
}
}, // Matches because the result matcher looks at only certain properties, and Provenance isn't one of them.
CurrentRun = new Run(),
ExpectedBaselineState = BaselineState.Updated,
},
};

[Fact]
Expand Down

0 comments on commit ba447a1

Please sign in to comment.