Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Component Detection supports detecting libraries from the following ecosystems:
| Ecosystem | Scanning | Graph Creation |
| -------------------------------------------------------------------------------- | ----------------------------------------------- | -------------- |
| [CocoaPods](docs/detectors/cocoapods.md) | ✔ | ✔ |
| [Composer (PHP, experimental)](docs/detectors/composer.md) | ✔ | ✔ |
| [Composer (PHP)](docs/detectors/composer.md) | ✔ | ✔ |
| [Conan](docs/detectors/conan.md) | ✔ | ❌ |
| [Conda (Python)](docs/detectors/conda.md) | ✔ | ✔ |
| [Docker Compose](docs/detectors/dockercompose.md) | ✔ | ❌ |
Expand Down
6 changes: 3 additions & 3 deletions docs/detectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

- [Composer](composer.md)

| Detector | Status |
| ------------------------- | ------------ |
| ComposerComponentDetector | Experimental |
| Detector | Status |
| ------------------------- | ------ |
| ComposerComponentDetector | Stable |

- [Conan](conan.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.Composer;
using Microsoft.Extensions.Logging;

/// <summary>Reads Composer package files and optionally inventories the local PHP environment through Composer.</summary>
public sealed class ComposerComponentDetector : FileComponentDetector, IExperimentalDetector
public sealed class ComposerComponentDetector : FileComponentDetector
{
private const string ComposerLockFileName = "composer.lock";
private const string ComposerManifestFileName = "composer.json";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s
// Experiments
services.AddSingleton<IExperimentService, ExperimentService>();
services.AddSingleton<IExperimentProcessor, DefaultExperimentProcessor>();
services.AddSingleton<IExperimentConfiguration, ComposerExperiment>();
services.AddSingleton<IExperimentConfiguration, SimplePipExperiment>();
services.AddSingleton<IExperimentConfiguration, LinuxApplicationLayerExperiment>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public void AllDetectorsHaveUniqueIds()
}

[TestMethod]
public void ComposerComponentDetector_IsDiscoverableAndExperimental()
public void ComposerComponentDetector_IsDiscoverableAndDefaultOn()
{
var detector = this.detectors.Single(d => d.Id == "Composer");
detector.Should().BeAssignableTo<IExperimentalDetector>();
detector.Should().NotBeAssignableTo<IExperimentalDetector>();
detector.Should().NotBeAssignableTo<IDefaultOffComponentDetector>();
detector.Categories.Should().Equal(nameof(DetectorClass.Composer));
detector.SupportedComponentTypes.Should().Equal(ComponentType.Composer, ComponentType.PhpSdk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Experiments;
using System.Threading.Tasks;
using AwesomeAssertions;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Detectors.Composer;
using Microsoft.ComponentDetection.Detectors.CondaLock;
using Microsoft.ComponentDetection.Detectors.Swift;
using Microsoft.ComponentDetection.Orchestrator.Experiments.Configs;
using Microsoft.ComponentDetection.Orchestrator.Extensions;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -38,54 +35,6 @@ public void ExperimentConfig_HaveDistinctNames()
names.Should().OnlyHaveUniqueItems();
}

[TestMethod]
public void ExperimentConfig_SwiftDetectorIsNotInExperimentGroup()
{
var swiftDetector = new SwiftResolvedComponentDetector(null, null, null);

this.configs.Should().OnlyContain(config => !config.IsInExperimentGroup(swiftDetector));
}

[TestMethod]
public void ExperimentConfig_CondaLockDetectorIsNotInExperimentGroup()
{
var condaLockDetector = new CondaLockComponentDetector(null, null, null);

this.configs.Should().OnlyContain(config => !config.IsInExperimentGroup(condaLockDetector));
}

[TestMethod]
public void ExperimentConfig_ComposerDetectorIsOnlyInComposerExperiment()
{
var detector = new ComposerComponentDetector(null, null, null, null, null, null);
var config = this.configs.Should().ContainSingle(config => config.IsInExperimentGroup(detector)).Which;

config.Should().BeOfType<ComposerExperiment>().Which.Name.Should().Be("Composer");
this.configs.Should().OnlyContain(config => !config.IsInControlGroup(detector));
}

[TestMethod]
public void ExperimentConfig_ComposerExperimentExcludesOtherDetectors()
{
var config = this.configs.OfType<ComposerExperiment>().Single();
var detector = Mock.Of<IComponentDetector>();

config.IsInControlGroup(detector).Should().BeFalse();
config.IsInExperimentGroup(detector).Should().BeFalse();
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
public void ExperimentConfig_ComposerExperimentDoesNotFilterDetectorRuns(int numComponents)
{
var config = this.configs.OfType<ComposerExperiment>().Single();
var detector = new ComposerComponentDetector(null, null, null, null, null, null);

config.ShouldRecord(detector, numComponents).Should().BeTrue();
config.ShouldRecord(Mock.Of<IComponentDetector>(), numComponents).Should().BeTrue();
}

[TestMethod]
public async Task ExperimentConfig_InitShouldNotThrowAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Experiments;
using Microsoft.ComponentDetection.Common.DependencyGraph;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Contracts.BcdeModels;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using Microsoft.ComponentDetection.Detectors.Composer;
using Microsoft.ComponentDetection.Detectors.NuGet;
using Microsoft.ComponentDetection.Orchestrator.Commands;
using Microsoft.ComponentDetection.Orchestrator.Experiments;
Expand Down Expand Up @@ -90,43 +88,6 @@ public void RecordDetectorRun_AddsComponentsToControlAndExperimentGroup()
Times.Once());
}

[TestMethod]
public async Task RecordDetectorRun_ComposerExperimentReportsPackagesAndSdkAsync()
{
var config = new ComposerExperiment();
var detector = new ComposerComponentDetector(null, null, null, null, null, null);
List<ScannedComponent> components =
[
new() { Component = new ComposerComponent("vendor/package", "1.0"), IsDevelopmentDependency = false },
new() { Component = new PhpSdkComponent("php", "8.4.27"), IsDevelopmentDependency = true },
];
this.SetupGraphMock(components);
ExperimentDiff processedDiff = null;
this.experimentProcessorMock
.Setup(processor => processor.ProcessExperimentAsync(config, It.IsAny<ExperimentDiff>()))
.Callback<IExperimentConfiguration, ExperimentDiff>((_, diff) => processedDiff = diff)
.Returns(Task.CompletedTask);
var service = new ExperimentService(
[config],
[this.experimentProcessorMock.Object],
this.graphTranslationServiceMock.Object,
this.loggerMock.Object);

service.RecordDetectorRun(detector, this.componentRecorder, this.scanSettingsMock.Object);
await service.FinishAsync();

this.experimentProcessorMock.Verify(
processor => processor.ProcessExperimentAsync(config, It.IsAny<ExperimentDiff>()),
Times.Once());
processedDiff.AddedIds.Should().BeEquivalentTo(["vendor/package 1.0 - Composer", "php 8.4.27 - PhpSdk"]);
processedDiff.RemovedIds.Should().BeEmpty();
processedDiff.ControlDetectors.Should().BeEmpty();
processedDiff.ExperimentalDetectors.Should().ContainSingle();
var developmentChange = processedDiff.DevelopmentDependencyChanges.Should().ContainSingle().Which;
developmentChange.Id.Should().Be("php 8.4.27 - PhpSdk");
developmentChange.NewValue.Should().BeTrue();
}

[TestMethod]
public async Task RecordDetectorRun_FiltersExperimentsAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class ComposerProcessingTests
[DataRow(true, true, false, true)]
[DataRow(false, true, true, true)]
[DataRow(true, true, true, true)]
public async Task ExperimentalComposer_AlwaysExecutesButOnlyIncludesResultsWhenEnabledAsync(bool enabled, bool manifestOnly, bool unresolved, bool platform)
public async Task Composer_IncludesResultsWithOrWithoutExplicitEnableAsync(bool enabled, bool manifestOnly, bool unresolved, bool platform)
{
var walker = new Mock<IObservableDirectoryWalkerFactory>();
var location = Path.Combine(Path.GetTempPath(), manifestOnly ? "composer.json" : "composer.lock");
Expand Down Expand Up @@ -94,15 +95,15 @@ public async Task ExperimentalComposer_AlwaysExecutesButOnlyIncludesResultsWhenE

result.ResultCode.Should().Be(ProcessingResultCode.Success);
var components = result.ComponentRecorders.SelectMany(value => value.Recorder.GetDetectedComponents()).Select(value => value.Component).ToList();
components.Should().HaveCount(enabled ? expectedCount : 0);
if (enabled && !unresolved)
components.Should().HaveCount(expectedCount);
if (!unresolved)
{
components.OfType<ComposerComponent>().Should().ContainSingle().Which.Version.Should().Be("v1.0.0");
result.ComponentRecorders.Single().Recorder.GetDependencyGraphsByLocation()[location]
.IsDevelopmentDependency("vendor/package v1.0.0 - Composer").Should().BeFalse();
}

if (enabled && platform)
if (platform)
{
components.OfType<PhpSdkComponent>().Select(component => component.Id).Should()
.BeEquivalentTo(["php 8.4.27 - PhpSdk", "php 8.3.15 - PhpSdk", "ext-json 8.4.27 - PhpSdk"]);
Expand All @@ -121,7 +122,7 @@ public async Task ExperimentalComposer_AlwaysExecutesButOnlyIncludesResultsWhenE
detector,
It.Is<ComponentRecorder>(recorder => recorder.GetDetectedComponents().Count() == expectedCount),
settings,
It.Is<DetectorRunResult>(run => run.ComponentsFoundCount == expectedCount && run.IsExperimental == !enabled)),
It.Is<DetectorRunResult>(run => run.ComponentsFoundCount == expectedCount && !run.IsExperimental)),
Times.Exactly(2));
foreach (var projectDirectory in new[] { Path.GetDirectoryName(location), Path.GetDirectoryName(childLocation) })
{
Expand All @@ -131,4 +132,19 @@ public async Task ExperimentalComposer_AlwaysExecutesButOnlyIncludesResultsWhenE
platform ? Times.Exactly(2) : Times.Never());
}
}

[TestMethod]
public async Task Composer_DoesNotSuppressScanFailuresAsync()
{
var walker = new Mock<IObservableDirectoryWalkerFactory>();
walker.Setup(value => value.GetFilteredComponentStreamObservable(It.IsAny<DirectoryInfo>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IComponentRecorder>()))
.Returns(Observable.Throw<ProcessRequest>(new InvalidOperationException("Composer scan failed.")));
var processor = new DetectorProcessingService(walker.Object, Mock.Of<IExperimentService>(), NullLogger<DetectorProcessingService>.Instance, Mock.Of<IAnsiConsole>());
var detector = new ComposerComponentDetector(Mock.Of<IComponentStreamEnumerableFactory>(), walker.Object, Mock.Of<IEnvironmentVariableService>(), Mock.Of<IFileUtilityService>(), Mock.Of<ICommandLineInvocationService>(), NullLogger<ComposerComponentDetector>.Instance);
var settings = new ScanSettings { SourceDirectory = new DirectoryInfo(Path.GetTempPath()), NoSummary = true };

var scan = async () => await processor.ProcessDetectorsAsync(settings, [detector], new DetectorRestrictions());

await scan.Should().ThrowAsync<InvalidOperationException>().WithMessage("Composer scan failed.");
}
}
Loading