Skip to content

Commit 73c64da

Browse files
Swift Experimental=>Default-On (#1900)
1 parent 0beda16 commit 73c64da

9 files changed

Lines changed: 11 additions & 157 deletions

File tree

‎docs/detectors/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124

125125
| Detector | Status |
126126
| ------------------------------ | ------------ |
127-
| SwiftResolvedComponentDetector | Experimental |
127+
| SwiftResolvedComponentDetector | Stable |
128128

129129
- [Uv](uv.md)
130130

‎docs/detectors/swift.md‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Swift Package Manager Detection
22

3+
Swift detection is enabled by default, and detected components are included in scan results without additional detector arguments.
4+
35
## Requirements
46

57
Swift Package Manager detection requires the following file to be present in the scan directory:
@@ -14,17 +16,6 @@ The version, the url and commit hash of the dependencies are stored in this file
1416

1517
[This is the only reference in the Apple documentation to the `Package.resolved` file.][1]
1618

17-
## Experiment results
18-
19-
Swift detection is experimental. The registered `SwiftDetectorExperiment` uses an empty control group
20-
and `SwiftResolvedComponentDetector` as its experiment group, so all Swift discoveries are reported as additions.
21-
It does not depend on CocoaPods detection or compare Swift packages against CocoaPods packages.
22-
23-
Enable experiment processing with `CD_DETECTOR_EXPERIMENTS` or `DetectorExperiments.Enable`.
24-
Scans with no Swift components do not produce experiment results. Disabling the Swift detector also disables this experiment.
25-
The CLI writes results to `Experiment_SwiftDetectorExperiment_{timestamp}_{processId}.json`;
26-
hosts that emit `ExperimentResults` custom events must register their own `IExperimentProcessor`.
27-
2819
## Known limitations
2920

3021
Right now the detector does not support parsing `Package.swift` file to get the dependencies.

‎src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Swift;
1515
/// <summary>
1616
/// Detects Swift Package Manager components.
1717
/// </summary>
18-
public class SwiftResolvedComponentDetector : FileComponentDetector, IExperimentalDetector
18+
public class SwiftResolvedComponentDetector : FileComponentDetector
1919
{
2020
// We are only interested in packages coming from remote sources such as git
2121
// The Package Kind is not an enum because the Swift Package Manager contract does not specify the possible values.

‎src/Microsoft.ComponentDetection.Orchestrator/Experiments/Configs/SwiftDetectorExperiment.cs‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s
7474
services.AddSingleton<IExperimentConfiguration, SimplePipExperiment>();
7575
services.AddSingleton<IExperimentConfiguration, CondaLockDetectorExperiment>();
7676
services.AddSingleton<IExperimentConfiguration, LinuxApplicationLayerExperiment>();
77-
services.AddSingleton<IExperimentConfiguration, SwiftDetectorExperiment>();
7877

7978
// Detectors
8079
// CocoaPods

‎test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public void CondaLockComponentDetector_ImplementsIExperimentalDetector()
8383
}
8484

8585
[TestMethod]
86-
public void SwiftResolvedComponentDetector_ImplementsIExperimentalDetector()
86+
public void SwiftResolvedComponentDetector_IsDefaultOn()
8787
{
8888
var swiftDetector = this.detectors.SingleOrDefault(d => d.Id == "Swift");
8989

9090
swiftDetector.Should().NotBeNull("because SwiftResolvedComponentDetector should be registered");
91-
swiftDetector.Should().BeAssignableTo<IExperimentalDetector>("because SwiftResolvedComponentDetector should implement IExperimentalDetector");
91+
swiftDetector.Should().NotBeAssignableTo<IExperimentalDetector>("because SwiftResolvedComponentDetector should be default-on");
9292
swiftDetector.Should().NotBeAssignableTo<IDefaultOffComponentDetector>("because SwiftResolvedComponentDetector should be enabled by default");
9393
}
9494

‎test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentConfigTests.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Experiments;
66
using System.Threading.Tasks;
77
using AwesomeAssertions;
88
using Microsoft.ComponentDetection.Contracts;
9+
using Microsoft.ComponentDetection.Detectors.Swift;
910
using Microsoft.ComponentDetection.Orchestrator.Experiments.Configs;
1011
using Microsoft.ComponentDetection.Orchestrator.Extensions;
1112
using Microsoft.Extensions.DependencyInjection;
@@ -36,9 +37,11 @@ public void ExperimentConfig_HaveDistinctNames()
3637
}
3738

3839
[TestMethod]
39-
public void ExperimentConfig_RegistersSwiftDetectorExperiment()
40+
public void ExperimentConfig_SwiftDetectorIsNotInExperimentGroup()
4041
{
41-
this.configs.OfType<SwiftDetectorExperiment>().Should().ContainSingle();
42+
var swiftDetector = new SwiftResolvedComponentDetector(null, null, null);
43+
44+
this.configs.Should().OnlyContain(config => !config.IsInExperimentGroup(swiftDetector));
4245
}
4346

4447
[TestMethod]

‎test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentServiceTests.cs‎

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Experiments;
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7-
using System.Linq;
87
using System.Threading.Tasks;
98
using AwesomeAssertions;
109
using Microsoft.ComponentDetection.Common.DependencyGraph;
1110
using Microsoft.ComponentDetection.Contracts;
1211
using Microsoft.ComponentDetection.Contracts.BcdeModels;
13-
using Microsoft.ComponentDetection.Contracts.TypedComponent;
14-
using Microsoft.ComponentDetection.Detectors.CocoaPods;
1512
using Microsoft.ComponentDetection.Detectors.NuGet;
16-
using Microsoft.ComponentDetection.Detectors.Swift;
1713
using Microsoft.ComponentDetection.Orchestrator.Commands;
1814
using Microsoft.ComponentDetection.Orchestrator.Experiments;
1915
using Microsoft.ComponentDetection.Orchestrator.Experiments.Configs;
@@ -169,69 +165,6 @@ public async Task FinishAsync_ProcessesExperimentsAsync()
169165
Times.Once());
170166
}
171167

172-
[TestMethod]
173-
public async Task FinishAsync_ProcessesSwiftExperimentWithoutControlDetectorAsync()
174-
{
175-
var config = new SwiftDetectorExperiment();
176-
var swiftDetector = new SwiftResolvedComponentDetector(null, null, null);
177-
var podDetector = new PodComponentDetector(null, null, null);
178-
var service = new ExperimentService(
179-
[config],
180-
[this.experimentProcessorMock.Object],
181-
this.graphTranslationServiceMock.Object,
182-
this.loggerMock.Object);
183-
service.RemoveUnwantedExperimentsbyDetectors([podDetector]);
184-
185-
this.SetupGraphMock([]);
186-
service.RecordDetectorRun(this.detectorMock.Object, this.componentRecorder, this.scanSettingsMock.Object);
187-
188-
var component = new SwiftComponent
189-
{
190-
Name = "alamofire",
191-
Version = "5.9.1",
192-
RepositoryUrl = new Uri("https://github.com/Alamofire/Alamofire"),
193-
CommitHash = "f455c2975872ccd2d9c81594c658af65716e9b9a",
194-
Kind = "remoteSourceControl",
195-
};
196-
this.SetupGraphMock([new ScannedComponent { Component = component }]);
197-
service.RecordDetectorRun(swiftDetector, this.componentRecorder, this.scanSettingsMock.Object);
198-
199-
await service.FinishAsync();
200-
201-
this.experimentProcessorMock.Verify(
202-
x => x.ProcessExperimentAsync(
203-
config,
204-
It.Is<ExperimentDiff>(diff =>
205-
diff.AddedIds.Count == 1 && diff.AddedIds.Contains(component.Id)
206-
&& diff.RemovedIds.Count == 0
207-
&& diff.ControlDetectors.Count == 0
208-
&& diff.ExperimentalDetectors.Count == 1
209-
&& diff.ExperimentalDetectors.Single().DetectorId == swiftDetector.Id)),
210-
Times.Once());
211-
}
212-
213-
[TestMethod]
214-
public async Task FinishAsync_SkipsSwiftExperimentWithoutSwiftComponentsAsync()
215-
{
216-
var config = new SwiftDetectorExperiment();
217-
var service = new ExperimentService(
218-
[config],
219-
[this.experimentProcessorMock.Object],
220-
this.graphTranslationServiceMock.Object,
221-
this.loggerMock.Object);
222-
this.SetupGraphMock(ExperimentTestUtils.CreateRandomComponents());
223-
service.RecordDetectorRun(new PodComponentDetector(null, null, null), this.componentRecorder, this.scanSettingsMock.Object);
224-
225-
this.SetupGraphMock([]);
226-
service.RecordDetectorRun(new SwiftResolvedComponentDetector(null, null, null), this.componentRecorder, this.scanSettingsMock.Object);
227-
228-
await service.FinishAsync();
229-
230-
this.experimentProcessorMock.Verify(
231-
x => x.ProcessExperimentAsync(config, It.IsAny<ExperimentDiff>()),
232-
Times.Never());
233-
}
234-
235168
[TestMethod]
236169
public async Task FinishAsync_SwallowsExceptionsAsync()
237170
{

‎test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/SwiftDetectorExperimentTests.cs‎

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)