From 8270c1050d03928d9d6e647f84977522f2d7346a Mon Sep 17 00:00:00 2001 From: Greg Villicana Date: Wed, 2 Dec 2026 10:29:43 -0800 Subject: [PATCH] Promote Composer detection to prod --- README.md | 2 +- docs/detectors/README.md | 6 +-- .../composer/ComposerComponentDetector.cs | 2 +- .../Experiments/Configs/ComposerExperiment.cs | 22 -------- .../Extensions/ServiceCollectionExtensions.cs | 1 - .../ComponentDetectorTests.cs | 4 +- .../Experiments/ExperimentConfigTests.cs | 51 ------------------- .../Experiments/ExperimentServiceTests.cs | 39 -------------- .../Services/ComposerProcessingTests.cs | 26 ++++++++-- 9 files changed, 28 insertions(+), 125 deletions(-) delete mode 100644 src/Microsoft.ComponentDetection.Orchestrator/Experiments/Configs/ComposerExperiment.cs diff --git a/README.md b/README.md index 1073aac64..f4d8658a4 100644 --- a/README.md +++ b/README.md @@ -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) | ✔ | ❌ | diff --git a/docs/detectors/README.md b/docs/detectors/README.md index 0c6363758..ed82a1896 100644 --- a/docs/detectors/README.md +++ b/docs/detectors/README.md @@ -8,9 +8,9 @@ - [Composer](composer.md) -| Detector | Status | -| ------------------------- | ------------ | -| ComposerComponentDetector | Experimental | +| Detector | Status | +| ------------------------- | ------ | +| ComposerComponentDetector | Stable | - [Conan](conan.md) diff --git a/src/Microsoft.ComponentDetection.Detectors/composer/ComposerComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/composer/ComposerComponentDetector.cs index e84897a74..5ccda19e0 100644 --- a/src/Microsoft.ComponentDetection.Detectors/composer/ComposerComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/composer/ComposerComponentDetector.cs @@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.Composer; using Microsoft.Extensions.Logging; /// Reads Composer package files and optionally inventories the local PHP environment through Composer. -public sealed class ComposerComponentDetector : FileComponentDetector, IExperimentalDetector +public sealed class ComposerComponentDetector : FileComponentDetector { private const string ComposerLockFileName = "composer.lock"; private const string ComposerManifestFileName = "composer.json"; diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Experiments/Configs/ComposerExperiment.cs b/src/Microsoft.ComponentDetection.Orchestrator/Experiments/Configs/ComposerExperiment.cs deleted file mode 100644 index 16779c298..000000000 --- a/src/Microsoft.ComponentDetection.Orchestrator/Experiments/Configs/ComposerExperiment.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Microsoft.ComponentDetection.Orchestrator.Experiments.Configs; - -using Microsoft.ComponentDetection.Contracts; -using Microsoft.ComponentDetection.Detectors.Composer; - -/// -/// Validates the against an empty baseline because there is no existing Composer detector. -/// -public class ComposerExperiment : IExperimentConfiguration -{ - /// - public string Name => "Composer"; - - /// - public bool IsInControlGroup(IComponentDetector componentDetector) => false; - - /// - public bool IsInExperimentGroup(IComponentDetector componentDetector) => componentDetector is ComposerComponentDetector; - - /// - public bool ShouldRecord(IComponentDetector componentDetector, int numComponents) => true; -} diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs index 707f04c55..a6ab1f8d6 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs @@ -72,7 +72,6 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s // Experiments services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs index a2ff3efc5..dd2dc557c 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs @@ -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(); + detector.Should().NotBeAssignableTo(); detector.Should().NotBeAssignableTo(); detector.Categories.Should().Equal(nameof(DetectorClass.Composer)); detector.SupportedComponentTypes.Should().Equal(ComponentType.Composer, ComponentType.PhpSdk); diff --git a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentConfigTests.cs b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentConfigTests.cs index 4a3529ed8..433362734 100644 --- a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentConfigTests.cs +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentConfigTests.cs @@ -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; @@ -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().Which.Name.Should().Be("Composer"); - this.configs.Should().OnlyContain(config => !config.IsInControlGroup(detector)); - } - - [TestMethod] - public void ExperimentConfig_ComposerExperimentExcludesOtherDetectors() - { - var config = this.configs.OfType().Single(); - var detector = Mock.Of(); - - 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().Single(); - var detector = new ComposerComponentDetector(null, null, null, null, null, null); - - config.ShouldRecord(detector, numComponents).Should().BeTrue(); - config.ShouldRecord(Mock.Of(), numComponents).Should().BeTrue(); - } - [TestMethod] public async Task ExperimentConfig_InitShouldNotThrowAsync() { diff --git a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentServiceTests.cs b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentServiceTests.cs index d6e423535..ee369f242 100644 --- a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentServiceTests.cs +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentServiceTests.cs @@ -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; @@ -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 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())) - .Callback((_, 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()), - 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() { diff --git a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/ComposerProcessingTests.cs b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/ComposerProcessingTests.cs index 2607f6901..7ceef5399 100644 --- a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/ComposerProcessingTests.cs +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/ComposerProcessingTests.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -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(); var location = Path.Combine(Path.GetTempPath(), manifestOnly ? "composer.json" : "composer.lock"); @@ -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().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().Select(component => component.Id).Should() .BeEquivalentTo(["php 8.4.27 - PhpSdk", "php 8.3.15 - PhpSdk", "ext-json 8.4.27 - PhpSdk"]); @@ -121,7 +122,7 @@ public async Task ExperimentalComposer_AlwaysExecutesButOnlyIncludesResultsWhenE detector, It.Is(recorder => recorder.GetDetectedComponents().Count() == expectedCount), settings, - It.Is(run => run.ComponentsFoundCount == expectedCount && run.IsExperimental == !enabled)), + It.Is(run => run.ComponentsFoundCount == expectedCount && !run.IsExperimental)), Times.Exactly(2)); foreach (var projectDirectory in new[] { Path.GetDirectoryName(location), Path.GetDirectoryName(childLocation) }) { @@ -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(); + walker.Setup(value => value.GetFilteredComponentStreamObservable(It.IsAny(), It.IsAny>(), It.IsAny())) + .Returns(Observable.Throw(new InvalidOperationException("Composer scan failed."))); + var processor = new DetectorProcessingService(walker.Object, Mock.Of(), NullLogger.Instance, Mock.Of()); + var detector = new ComposerComponentDetector(Mock.Of(), walker.Object, Mock.Of(), Mock.Of(), Mock.Of(), NullLogger.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().WithMessage("Composer scan failed."); + } }