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

feat(baseline): Allow force creating fresh baseline #2124

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
853cbd9
init
Aug 5, 2022
dc5686f
Merge branch 'master' into baseline-command
richardwerkman Aug 5, 2022
e986e68
Fix unit tests
Aug 5, 2022
89b9cb6
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Aug 5, 2022
5c7705d
Merge branch 'master' of https://github.com/stryker-mutator/stryker-n…
May 26, 2023
68d4e39
Baseline recreate added
Jun 9, 2023
67db04d
merge main
Jun 9, 2023
4871f39
fix merge
Jun 9, 2023
36a4ce9
try to enable baseline by command
Jun 9, 2023
e180534
Fixed command
Jun 23, 2023
f1f6cf3
Fix mutation level
Jun 23, 2023
7dd8a89
merged master
Jun 23, 2023
e44bb01
Remove using
Jun 23, 2023
9ebf7f7
merged master
Sep 1, 2023
e1b4d14
Update docs + try to add target option to command
Sep 15, 2023
ca9b354
Merge master, fix and add tests, consistency (#2712)
danihengeveld Oct 13, 2023
60d6d41
fix using
Oct 13, 2023
02193a7
Merge branch 'master' into baseline-command
richardwerkman Oct 13, 2023
8f39401
Fix: StrykerCLITests info text test (#2713)
danihengeveld Oct 13, 2023
938920d
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Oct 13, 2023
dc0f060
Pass command line arguments and options to subcommands (#2718)
danihengeveld Oct 14, 2023
4d5303b
merged master
Feb 2, 2024
97d5c54
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Feb 2, 2024
0d9a5e6
Fix build
Feb 2, 2024
b530afa
Refactor but I broke it...
Feb 2, 2024
4f6c3cc
Merged master
Feb 16, 2024
a02f5c9
Fix commands
Feb 16, 2024
548d06b
Reset mutation level
Feb 16, 2024
ef6392f
Update docs
Feb 16, 2024
552c9a3
Remove "with-baseline.enabled"
Feb 16, 2024
0d62dda
Update docs and add help text for commands
Feb 16, 2024
e51eebd
Update pipeline docs
Feb 16, 2024
937f26f
merged master
Mar 1, 2024
d0fa85a
.
Mar 1, 2024
d7ac653
Fix tests
Mar 1, 2024
079311a
Merge branch 'master' into baseline-command
richardwerkman Mar 1, 2024
e87f5bb
Fix sonar
Mar 1, 2024
4c21604
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Mar 1, 2024
1202182
merged master
Mar 15, 2024
0380d09
Fix docs
Mar 15, 2024
0ba1d08
Fix unit tests
Mar 15, 2024
0dc89f4
merged
Jun 21, 2024
20cab04
Remove double logging and refactor
Jun 21, 2024
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
37 changes: 15 additions & 22 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ Config file: `"since": { }`

Use git information to test only code changes since the given target. Stryker will only report on mutants within the changed code. All other mutants will not have a result.

If you wish to test only changed sources and tests but would like to have a complete mutation report see [with-baseline](#with-baseline-flag-committish).
If you wish to test only changed sources and tests but would like to have a complete mutation report see [with-baseline](#with-baseline-committish).

Set the diffing target on the command line by passing a committish with the since flag in the format `--since:<committish>`.
Set the diffing target in the config file by setting the [since target](#sincetarget-committish) option.
Expand Down Expand Up @@ -492,33 +492,26 @@ Use [globbing syntax](https://en.wikipedia.org/wiki/Glob_(programming)) for wild

## Baseline

### `baseline` &lt;`command`&gt;
### `with-baseline` &lt;`committish`&gt;
Copy link
Member

@rouke-broersma rouke-broersma Mar 15, 2024

Choose a reason for hiding this comment

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

Suggested change
### `with-baseline` &lt;`committish`&gt;
### `baseline` &lt;`target-version`&gt;


Default: `false`
Command line: `dotnet stryker baseline`
Config file: `"baseline": { }`
Default: `false`
Command line: `with-baseline feat-2`
Config file: `"baseline": { }`
Copy link
Member

@rouke-broersma rouke-broersma Mar 15, 2024

Choose a reason for hiding this comment

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

Suggested change
Default: `false`
Command line: `with-baseline feat-2`
Config file: `"baseline": { }`
Default: `false`
Command: `baseline feat-2`
Command Alias: `with-baseline feat-2`
Config file: `"baseline": { }`


Enabling `with-baseline` saves the mutation report to a storage location such as the filesystem. The mutation report is loaded at the start of the next mutation run. Any changed source code or unit test results in a reset of the mutants affected by the change. For unchanged mutants the previous result is reused. This feature expands on the [since](#since-flag-committish) feature by providing you with a full report after a partial mutation testrun.
Enabling `baseline`, alias `with-baseline`, saves the mutation report to a storage location such as the filesystem. The mutation report is loaded at the start of the next mutation run. Any changed source code or unit test results in a reset of the mutants affected by the change. For unchanged mutants the previous result is reused. This feature expands on the [since](#since-flag-committish) feature by providing you with a full report after a partial mutation testrun. The target of the baseline is a `committish` passed as an extra argument. The target determines which committish is used to establish or locate a baseline.
Copy link
Member

Choose a reason for hiding this comment

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

Why does not still need to be a committish? We are trying to move away from git for baseline.


The report name is based on the current branch name or the [project-info.version](#project-infoversion-committish).

*\* The baseline and since features are mutually exclusive. This feature implicitly enables the [since](#since-flag-committish) feature for now.*

### `target` <`string`>

Default: `false`
Command line: `dotnet stryker baseline --target feat-2`
Config file: `"baseline": { "target": "feat-2" }`

Set the target on the command line by passing a committish with the baseline target option.
*\* The baseline and since features are mutually exclusive. This feature implicitly enables the [since](#since-flag-committish) feature for now.*

### `baseline.fallback-version` &lt;`string`&gt;

Default: [since-target](#since-flag-committish)
Command line: `N/A`
Config file: `"baseline": { "fallback-version": 'develop' }`
Default: [since-target](#since-flag-committish)
Command line: `N/A`
Config file: `"baseline": { "fallback-version": 'develop' }`

When [with-baseline](#with-baseline-flag-committish) is enabled and Stryker cannot find an existing report for the current branch the fallback version is used. When Stryker is still unable to find a baseline we will do a complete instead of partial testrun. The complete testrun will then be saved as the new baseline for the next mutation testrun.
When [with-baseline](#with-baseline-committish) is enabled and Stryker cannot find an existing report for the current branch the fallback version is used. When Stryker is still unable to find a baseline we will do a complete instead of partial testrun. The complete testrun will then be saved as the new baseline for the next mutation testrun.
Copy link
Member

@rouke-broersma rouke-broersma Mar 15, 2024

Choose a reason for hiding this comment

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

Suggested change
When [with-baseline](#with-baseline-committish) is enabled and Stryker cannot find an existing report for the current branch the fallback version is used. When Stryker is still unable to find a baseline we will do a complete instead of partial testrun. The complete testrun will then be saved as the new baseline for the next mutation testrun.
When [baseline](#baseline-target-version) is enabled and Stryker cannot find an existing report for the current version the fallback version is used. When Stryker is still unable to find a baseline with either the current version or the fallback version a complete testrun is performed. The complete testrun will then be saved as the new baseline for the next mutation testrun.


**Example**:
```json
Expand Down Expand Up @@ -553,9 +546,9 @@ new baseline saved to: feat-2

Default: `Disk`
Command line: `N/A`
Config file: `"baseline": { "provider": 'AzureFileStorage'}`
Config file: `"baseline": { "provider": 'AzureFileStorage'}`

Sets the storage provider for the baseline used by [with-baseline](#with-baseline-flag-committish). By default this is set to disk, when the dashboard [reporter](#reporter-string) is enabled this is automatically set to Dashboard.
Sets the storage provider for the baseline used by [with-baseline](#with-baseline-committish). By default this is set to disk, when the dashboard [reporter](#reporter-string) is enabled this is automatically set to Dashboard.

Supported storage providers are:

Expand Down Expand Up @@ -584,7 +577,7 @@ Providing a subfolder is optional but allowed. In the case of a custom subfolder
### `azure-fileshare-sas` &lt;`string`&gt;

Default: `null`
Command line: `dotnet stryker baseline --azure-fileshare-sas "se=2022-08-25T14%3A27Z&sp=rwdl&spr=https&sv=2021-06-08&sr=d&sdd=1&sig=XXXXXXXXXXXXX"`
Command line: `--azure-fileshare-sas "se=2022-08-25T14%3A27Z&sp=rwdl&spr=https&sv=2021-06-08&sr=d&sdd=1&sig=XXXXXXXXXXXXX"`
Config file: `N/A`

When using the azure file storage [provider](#baselineprovider-string) you must pass credentials for the fileshare to Stryker.
Expand All @@ -601,7 +594,7 @@ For more information on how to configure a SAS check the [Azure documentation](h
### `baseline recreate`

Default: `false`
Command line: `dotnet stryker baseline recreate`
Command line: `with-baseline main recreate`
Config file: `N/A`

Sometimes your baseline can get corrupted or out of touch with reality. In that case the baseline can be recreated using this command. This will test all mutations in your project and save the result as the new baseline.
Expand Down
29 changes: 23 additions & 6 deletions docs/stryker-in-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,39 @@ dotnet stryker --break-at 80
Dashboard compare is very useful when running stryker in pipelines because it cuts down on the total runtime by only testing mutations that have changed compared to for example master
The following minimal steps are needed to use dashboard compare

1. Enable --with-baseline and choose the comparison target
1. Choose a storage provider (Dashboard for public projects or Azure File Share for private projects)
1. Enable [with-baseline](https://stryker-mutator.io/docs/stryker-net/configuration#with-baseline-committish)
1. Choose a target branch or commit, as the source of the baseline (usually current branch in your pull request)
1. Choose a [storage provider](https://stryker-mutator.io/docs/stryker-net/configuration#baselineprovider-string) (Dashboard for public projects or Azure File Share for private projects)
1. Set up authentication for the chosen storage provider
1. Set --version to the name of the source branch (usually current branch)
1. Set any other options needed for your chosen storage provider (see: [storage provider docs](https://stryker-mutator.io/docs/stryker-net/configuration#baselineprovider-string))

Example for azure devops with dashboard storage provider:
_Example for azure devops with dashboard storage provider:_
```
dotnet stryker --with-baseline:$(System.PullRequest.TargetBranch) --dashboard-api-key $(Stryker.Dashboard.Api.Key) --version $(System.PullRequest.SourceBranch)
dotnet stryker with-baseline $(System.PullRequest.TargetBranch) --dashboard-api-key $(Stryker.Dashboard.Api.Key) --version $(System.PullRequest.SourceBranch)
```

```json
{
"stryker-config": {
"baseline": {
"provider": "Dashboard"
"provider": "Dashboard",
"fallback-version": "main"
}
}
}
```

_Example for azure devops with azure fileshare storage provider:_
```
dotnet stryker with-baseline $(System.PullRequest.TargetBranch) --azure-fileshare-sas $(Stryker.Azure.Fileshare.SAS)
```

```json
{
"stryker-config": {
"baseline": {
"provider": "AzureFileStorage",
"fallback-version": "main"
}
}
}
Expand Down
23 changes: 0 additions & 23 deletions src/Stryker.CLI/Stryker.CLI.UnitTest/StrykerCLITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,29 +416,6 @@ public void ShouldSupplyWithBaselineWhenPassed(params string[] argName)
_inputs.BaselineEnabledInput.SuppliedInput.Value.ShouldBeTrue();
}

[Theory]
[InlineData("baseline")]
public void ShouldSupplyWithBaselineWhenCommandPassed(params string[] argName)
{
_target.Run(argName);

_strykerRunnerMock.VerifyAll();

_inputs.BaselineEnabledInput.SuppliedInput.Value.ShouldBeTrue();
}

[Theory]
[InlineData("baseline", "recreate")]
public void ShouldSetBaselineRecreateWhenCommandPassed(params string[] argName)
{
_target.Run(argName);

_strykerRunnerMock.VerifyAll();

_inputs.BaselineEnabledInput.SuppliedInput.Value.ShouldBeTrue();
_inputs.BaselineRecreateEnabledInput.SuppliedInput.ShouldBeTrue();
}

[Theory]
[InlineData("-o", null)]
[InlineData("-o:html", "html")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"module": "cli"
},
"baseline": {
"enabled": false,
"fallback-version": "master",
"azure-fileshare-url": "",
"provider": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ stryker-config:
version: master
module: cli
baseline:
enabled: false
fallback-version: master
azure-fileshare-url: ''
provider: ''
Expand Down
8 changes: 4 additions & 4 deletions src/Stryker.CLI/Stryker.CLI.UnitTest/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@
"McMaster.Extensions.CommandLineUtils": "[4.1.1, )",
"NuGet.Protocol": "[6.9.1, )",
"YamlDotNet": "[15.1.2, )",
"stryker": "[4.0.0, )"
"stryker": "[4.0.1, )"
}
},
"stryker": {
Expand Down Expand Up @@ -1638,8 +1638,8 @@
"ShellProgressBar": "[5.2.0, )",
"Spectre.Console": "[0.48.0, )",
"Spectre.Console.Analyzer": "[0.48.0, )",
"Stryker.DataCollector": "[4.0.0, )",
"Stryker.RegexMutators": "[4.0.0, )",
"Stryker.DataCollector": "[1.0.0, )",
"Stryker.RegexMutators": "[1.0.0, )",
"TestableIO.System.IO.Abstractions.Wrappers": "[20.0.28, )"
}
},
Expand Down Expand Up @@ -1918,4 +1918,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void RegisterInitCommand(CommandLineApplication app, IFileSystem fileSyst
{
RegisterCliInputs(initCommandApp);

initCommandApp.HelpOption();

initCommandApp.OnExecute(() =>
{
_console.WriteLine($"Initializing new config file.");
Expand Down Expand Up @@ -72,10 +74,17 @@ public void RegisterBaselineCommand(CommandLineApplication app, IStrykerInputs i
{
app.Command("baseline", baselineCmd =>
{
baselineCmd.AddName("with-baseline");
RegisterCliInputs(baselineCmd);

var committishArg = baselineCmd.Argument("committish", "The committish to compare with the current HEAD. This can be a branch, tag or commit id.");
committishArg.IsRequired(true);
Copy link
Member

@rouke-broersma rouke-broersma Mar 15, 2024

Choose a reason for hiding this comment

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

Are we not using a default target version anymore?


baselineCmd.HelpOption();

baselineCmd.OnExecute(() =>
{
inputs.BaselineTargetInput.SuppliedInput = committishArg.Value;
inputs.BaselineEnabledInput.SuppliedInput = true;
baselineCmd.Description = "Starts a stryker run based on the results of a previous run.";
return strykerCli.StartApp(inputs, args, app, this);
Expand All @@ -85,8 +94,11 @@ public void RegisterBaselineCommand(CommandLineApplication app, IStrykerInputs i
{
RegisterCliInputs(createCmd);

createCmd.HelpOption();

createCmd.OnExecute(() =>
{
inputs.BaselineTargetInput.SuppliedInput = committishArg.Value;
inputs.BaselineEnabledInput.SuppliedInput = true;
createCmd.Description = "Creates a new baseline by doing a full stryker run";
// Enable recreate
Expand Down Expand Up @@ -212,7 +224,6 @@ private void PrepareCliOptions(IStrykerInputs inputs)
AddCliInput(inputs.MutationLevelInput, "mutation-level", "l", category: InputCategory.Mutation);
AddCliInput(inputs.SinceInput, "since", "", optionType: CommandOptionType.SingleOrNoValue, argumentHint: "committish", category: InputCategory.Mutation);
AddCliInput(inputs.BaselineEnabledInput, "with-baseline", "", optionType: CommandOptionType.SingleOrNoValue, argumentHint: "committish", category: InputCategory.Mutation);
AddCliInput(inputs.BaselineTargetInput, "target", "", argumentHint: "committish", category: InputCategory.Mutation);
// Category: Reporting
AddCliInput(inputs.OpenReportInput, "open-report", "o", CommandOptionType.SingleOrNoValue, argumentHint: "report-type", category: InputCategory.Reporting);
AddCliInput(inputs.ReportersInput, "reporter", "r", optionType: CommandOptionType.MultipleValue, category: InputCategory.Reporting);
Expand Down
4 changes: 2 additions & 2 deletions src/Stryker.CLI/Stryker.CLI/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1478,8 +1478,8 @@
"ShellProgressBar": "[5.2.0, )",
"Spectre.Console": "[0.48.0, )",
"Spectre.Console.Analyzer": "[0.48.0, )",
"Stryker.DataCollector": "[4.0.0, )",
"Stryker.RegexMutators": "[4.0.0, )",
"Stryker.DataCollector": "[1.0.0, )",
"Stryker.RegexMutators": "[1.0.0, )",
"TestableIO.System.IO.Abstractions.Wrappers": "[20.0.28, )"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Stryker.Core.UnitTest.Mutators
public class NullCoalescingExpressionMutatorTests : TestBase
{
[Fact]
public void ShouldBeMutationLevelStandard()
public void ShouldBeMutationLevelBasic()
{
var target = new NullCoalescingExpressionMutator();
target.MutationLevel.ShouldBe(MutationLevel.Standard);
target.MutationLevel.ShouldBe(MutationLevel.Basic);
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions src/Stryker.Core/Stryker.Core.UnitTest/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1605,8 +1605,8 @@
"ShellProgressBar": "[5.2.0, )",
"Spectre.Console": "[0.48.0, )",
"Spectre.Console.Analyzer": "[0.48.0, )",
"Stryker.DataCollector": "[4.0.0, )",
"Stryker.RegexMutators": "[4.0.0, )",
"Stryker.DataCollector": "[1.0.0, )",
"Stryker.RegexMutators": "[1.0.0, )",
"TestableIO.System.IO.Abstractions.Wrappers": "[20.0.28, )"
}
},
Expand Down Expand Up @@ -1861,4 +1861,4 @@
}
}
}
}
}
1 change: 0 additions & 1 deletion src/Stryker.Core/Stryker.Core/Options/StrykerInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public StrykerOptions ValidateAll()
var baselineProvider = BaselineProviderInput.Validate(reporters, baselineEnabled);
var sinceEnabled = SinceInput.Validate(BaselineEnabledInput.SuppliedInput);
var sinceTarget = SinceTargetInput.Validate(sinceEnabled);
var projectVersion = ProjectVersionInput.Validate(reporters, baselineEnabled);

_strykerOptionsCache ??= new StrykerOptions()
{
Expand Down
3 changes: 1 addition & 2 deletions src/Stryker.Core/Stryker.Core/StrykerRunner.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -126,7 +127,6 @@ public StrykerRunResult RunMutationTest(IStrykerInputs inputs, ILoggerFactory lo

reporters.OnAllMutantsTested(rootComponent, combinedTestProjectsInfo);


return new StrykerRunResult(options, rootComponent.GetMutationScore());
}
#if !DEBUG
Expand All @@ -136,7 +136,6 @@ public StrykerRunResult RunMutationTest(IStrykerInputs inputs, ILoggerFactory lo
_logger.LogError(ex, "An error occurred during the mutation test run ");
throw;
}

#endif
finally
{
Expand Down
Loading
Loading