Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert unintentional change to BaselineState #1262

Merged
3 commits merged into from
Feb 6, 2019
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
2 changes: 1 addition & 1 deletion src/ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
* API BREAKING: Remove 'threadFlowLocation.step'
* API BREAKING: 'invocation.workingDirectory' is now a FileLocation object (and not a URI expressed as a string)

## **v2.0.0-csd.2.beta.2018.11.28** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.0.0-csd.2.beta.2018.11.28) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.0.0-csd.2.beta.2018.11.28) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.0.0-csd.2.beta.2018.11.28)) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.0.0-csd.2.beta.2018.11.28))
## **v2.0.0-csd.2.beta.2019.01.09** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.0.0-csd.2.beta.2019.01.09) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.0.0-csd.2.beta.2019.01.09) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.0.0-csd.2.beta.2019.01.09)) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.0.0-csd.2.beta.2019.01.09))
* BUGFIX: Result matching improvements in properties persistence.
* FEATURE: Fortify FPR converter improvements.
* API Non-BREAKING: Remove uniqueness requirement from 'result.locations'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28",
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2019-01-09",
"version": "2.0.0-csd.2.beta.2019-01-09",
"runs": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28",
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2019-01-09",
"version": "2.0.0-csd.2.beta.2019-01-09",
"runs": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28",
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2019-01-09",
"version": "2.0.0-csd.2.beta.2019-01-09",
"runs": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Converters/FxCopConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal Result CreateResult(FxCopLogReader.Context context)
}
else if ("ExcludedInProject".Equals(status))
{
result.BaselineState = BaselineState.Unchanged;
result.BaselineState = BaselineState.Existing;
}

result.RuleId = context.CheckId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28",
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2019-01-09",
"version": "2.0.0-csd.2.beta.2019-01-09",
"runs": [
{
Expand Down
4 changes: 2 additions & 2 deletions src/Sarif.UnitTests/Baseline/DefaultBaselineUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void DefaultBaseline_SameResults_AllExisting()

Run result = defaultBaseliner.CreateBaselinedRun(baseline, next);

result.Results.Should().OnlyContain(r => r.BaselineState == BaselineState.Unchanged);
result.Results.Should().OnlyContain(r => r.BaselineState == BaselineState.Existing);
result.Results.Should().HaveCount(baseline.Results.Count());
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public void DefaultBaseline_ChangedResultOnNonTrackedField_Existing()

Run result = defaultBaseliner.CreateBaselinedRun(baseline, next);

result.Results.Should().OnlyContain(r => r.BaselineState == BaselineState.Unchanged);
result.Results.Should().OnlyContain(r => r.BaselineState == BaselineState.Existing);
result.Results.Should().HaveCount(baseline.Results.Count());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void IdenticalResultMatcher_MatchesResults_DifferingOnIdOrStatus_Single()

Result changedResultA = resultA.Result.DeepClone();
changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
changedResultA.BaselineState = BaselineState.Unchanged;
changedResultA.BaselineState = BaselineState.Existing;

ExtractedResult resultB = new ExtractedResult()
{
Expand All @@ -146,7 +146,7 @@ public void IdenticalResultMatcher_MatchesResults_DifferingOnIdOrStatus_Multiple

Result changedResultA = resultAA.Result.DeepClone();
changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
changedResultA.BaselineState = BaselineState.Unchanged;
changedResultA.BaselineState = BaselineState.Existing;

ExtractedResult resultBA = new ExtractedResult()
{
Expand Down Expand Up @@ -185,7 +185,7 @@ public void IdenticalResultMatcher_MatchesResults_DifferingOnResultMatchingPrope

Result changedResultA = resultAA.Result.DeepClone();
changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
changedResultA.BaselineState = BaselineState.Unchanged;
changedResultA.BaselineState = BaselineState.Existing;
changedResultA.SetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, new Dictionary<string, string> { { "property", "value" } });

ExtractedResult resultBA = new ExtractedResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public void ResultMatchingBaseliner_BaselinesTwoSimpleSarifLogs()


int existingCount = currentLog.Runs[0].Results.Count - 1;
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Unchanged).Count().Should().Be(existingCount);
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Existing).Count().Should().Be(existingCount);

if (existingCount > 0)
{
// In the event that we generated a SARIF run of only a single result, we will not have an 'existing' match
// since we adjusted the sole result value by adding a property to it.
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Unchanged).First().TryGetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, out Dictionary<string, string> CurrentResultProperties).Should().BeTrue();
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Existing).First().TryGetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, out Dictionary<string, string> CurrentResultProperties).Should().BeTrue();
CurrentResultProperties.Should().ContainKey("Run");
CurrentResultProperties["Run"].Should().BeEquivalentTo(currentLog.Runs[0].Id.InstanceGuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public void SarifLogResultMatcher_BaselinesTwoSimpleSarifLogs()

if (currentLog.Runs[0].Results.Count > 1)
{
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Unchanged).Should().HaveCount(currentLog.Runs[0].Results.Count - 1);
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Existing).Should().HaveCount(currentLog.Runs[0].Results.Count - 1);

calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Unchanged).First().TryGetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, out Dictionary<string, string> CurrentResultProperties).Should().BeTrue();
calculatedNextBaseline.Runs[0].Results.Where(r => r.BaselineState == BaselineState.Existing).First().TryGetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, out Dictionary<string, string> CurrentResultProperties).Should().BeTrue();
CurrentResultProperties.Should().ContainKey("Run");
CurrentResultProperties["Run"].Should().BeEquivalentTo(currentLog.Runs[0].Id.InstanceGuid);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.UnitTests/Baseline/StrictBaselineUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public void StrictBaseline_SameResults_AllExisting()
Run baseline = RandomSarifLogGenerator.GenerateRandomRunWithoutDuplicateIssues(random, Result.ValueComparer, random.Next(100)+5);
Run next = baseline.DeepClone();

Run result = strictBaseliner.CreateBaselinedRun(baseline, next);
Run run = strictBaseliner.CreateBaselinedRun(baseline, next);

result.Results.Should().OnlyContain(r => r.BaselineState == BaselineState.Unchanged);
result.Results.Should().HaveCount(baseline.Results.Count());
run.Results.Should().OnlyContain(r => r.BaselineState == BaselineState.Existing);
run.Results.Should().HaveCount(baseline.Results.Count());
}

[Fact]
Expand Down
21 changes: 5 additions & 16 deletions src/Sarif.UnitTests/Readers/IsSuppressedInSourceConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void BaselineState_None()
}

[Fact]
public void BaselineState_UnchangedAndUpdated()
public void BaselineState_Existing()
{
string expected =
@"{
Expand All @@ -113,14 +113,8 @@ public void BaselineState_UnchangedAndUpdated()
{
""message"": {
""text"": ""Some testing occurred.""
},
""baselineState"": ""unchanged""
},
{
""message"": {
""text"": ""Some testing occurred.""
},
""baselineState"": ""updated""
},
""baselineState"": ""existing""
}
]
}
Expand All @@ -135,20 +129,15 @@ public void BaselineState_UnchangedAndUpdated()
new Result
{
Message = new Message { Text = "Some testing occurred."},
BaselineState = BaselineState.Unchanged
},
new Result {
Message = new Message { Text = "Some testing occurred."},
BaselineState = BaselineState.Updated
BaselineState = BaselineState.Existing
}
});
});
actual.Should().BeCrossPlatformEquivalent<SarifLog>(expected);

var sarifLog = JsonConvert.DeserializeObject<SarifLog>(actual);
Assert.Equal(SuppressionStates.None, sarifLog.Runs[0].Results[0].SuppressionStates);
Assert.Equal(BaselineState.Unchanged, sarifLog.Runs[0].Results[0].BaselineState);
Assert.Equal(BaselineState.Updated, sarifLog.Runs[0].Results[1].BaselineState);
Assert.Equal(BaselineState.Existing, sarifLog.Runs[0].Results[0].BaselineState);
}
}
}
3 changes: 1 addition & 2 deletions src/Sarif/Autogenerated/BaselineState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace Microsoft.CodeAnalysis.Sarif
public enum BaselineState
{
None,
Unchanged,
Updated,
Existing,
New,
Absent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private Result ConstructExistingResult(
Result result = CurrentResult.Result.DeepClone();
result.CorrelationGuid = PreviousResult.Result.CorrelationGuid;
result.SuppressionStates = PreviousResult.Result.SuppressionStates;
result.BaselineState = BaselineState.Unchanged;
result.BaselineState = BaselineState.Existing;

if (!PreviousResult.Result.TryGetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, out OriginalResultMatchingProperties))
{
Expand Down
3 changes: 1 addition & 2 deletions src/Sarif/Baseline/ResultMatching/SarifLogMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ private SarifLog ConstructSarifLogFromMatchedResults(
Result result = resultPair.CalculateBasedlinedResult(PropertyBagMergeBehavior);

IList<FileData> files =
(PropertyBagMergeBehavior.HasFlag(DictionaryMergeBehavior.InitializeFromOldest) &&
(result.BaselineState == BaselineState.Unchanged || result.BaselineState == BaselineState.Updated))
(PropertyBagMergeBehavior.HasFlag(DictionaryMergeBehavior.InitializeFromOldest) && result.BaselineState == BaselineState.Existing)
? resultPair.PreviousResult.OriginalRun.Files
: resultPair.Run.Files;

Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Baseline/SarifLogBaseliner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Run CreateBaselinedRun(Run baseLine, Run nextLog)
Result newResult = result.DeepClone();

newResult.BaselineState =
baseLine.Results.Contains(result, ResultComparator) ? BaselineState.Unchanged : BaselineState.New;
baseLine.Results.Contains(result, ResultComparator) ? BaselineState.Existing : BaselineState.New;

differencedRun.Results.Add(newResult);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Sarif/CodeGenHints.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,7 @@
"description": "The state of a result relative to a baseline of a previous run.",
"zeroValueName": "None",
"memberNames": [
"Unchanged",
"Updated",
"Existing",
"New",
"Absent"
]
Expand Down
3 changes: 1 addition & 2 deletions src/Sarif/Schemata/sarif-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,7 @@
"description": "The state of a result relative to a baseline of a previous run.",
"enum": [
"new",
"unchanged",
"updated",
"existing",
"absent"
]
},
Expand Down
5 changes: 2 additions & 3 deletions src/Sarif/Visitors/SarifTransformerUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static BaselineState CreateBaselineState(BaselineStateVersionOne v1Baseli
case BaselineStateVersionOne.Absent:
return BaselineState.Absent;
case BaselineStateVersionOne.Existing:
return BaselineState.Unchanged;
return BaselineState.Existing;
case BaselineStateVersionOne.New:
return BaselineState.New;
default:
Expand All @@ -200,8 +200,7 @@ public static BaselineStateVersionOne CreateBaselineStateVersionOne(BaselineStat
{
case BaselineState.Absent:
return BaselineStateVersionOne.Absent;
case BaselineState.Unchanged:
case BaselineState.Updated:
case BaselineState.Existing:
return BaselineStateVersionOne.Existing;
case BaselineState.New:
return BaselineStateVersionOne.New;
Expand Down
48 changes: 8 additions & 40 deletions src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,23 @@ public static SarifLog UpdateToCurrentVersion(

switch (version)
{
case "2.0.0-csd.2.beta.2019-01-24":
{
// SARIF TC31. Nothing to do.
break;
}

case "2.0.0-csd.2.beta.2019-01-09":
{
modifiedLog |= ApplyChangesFromTC31(sarifLog);
break;
// SARIF TC30. Nothing to do.
break;
}

case "2.0.0-csd.2.beta.2018-10-10":
case "2.0.0-csd.2.beta.2018-10-10.1":
case "2.0.0-csd.2.beta.2018-10-10.2":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong. these aren't valid schema references from the JSON. all these versions should refer to the same JSON schema, the point updates are for the SDK backing them (i.e., the semver associated with the nuget package updates).

{
// 2.0.0-csd.2.beta.2018-10-10 == changes through SARIF TC #25
modifiedLog |= ApplyChangesFromTC25ThroughTC30(
// 2.0.0-csd.2.beta.2018-10-10 == changes through SARIF TC #25
modifiedLog |= ApplyChangesFromTC25ThroughTC30(
sarifLog,
out fullyQualifiedLogicalNameToIndexMap,
out fileLocationKeyToIndexMap,
out ruleKeyToIndexMap);
modifiedLog |= ApplyChangesFromTC31(sarifLog);
break;
break;
}

default:
Expand All @@ -79,8 +74,7 @@ public static SarifLog UpdateToCurrentVersion(
out fullyQualifiedLogicalNameToIndexMap,
out fileLocationKeyToIndexMap,
out ruleKeyToIndexMap);
modifiedLog |= ApplyChangesFromTC31(sarifLog);
break;
break;
}
}

Expand Down Expand Up @@ -117,32 +111,6 @@ public static SarifLog UpdateToCurrentVersion(
return transformedSarifLog;
}

private static bool ApplyChangesFromTC31(JObject sarifLog)
{
bool modifiedLog = UpdateSarifLogVersion(sarifLog); ;

if (sarifLog["runs"] is JArray runs)
{
foreach (JObject run in runs)
{
if (run["results"] is JArray results)
{
foreach (JObject result in results)
{
string baselineState = (string)result["baselineState"];

if ("existing".Equals(baselineState))
{
result["baselineState"] = "unchanged";
modifiedLog = true;
}
}
}
}
}
return modifiedLog;
}

private static bool ApplyChangesFromTC25ThroughTC30(
JObject sarifLog,
out Dictionary<string, int> fullyQualifiedLogicalNameToIndexMap,
Expand Down