gnodet-bot commented on code in PR #13094: URL: https://github.com/apache/maven/pull/13094#discussion_r3978486993
########## its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8766SpiWorkspaceReaderTest.java: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.it; + +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Integration test for the {@code WorkspaceReader} SPI in maven-api-spi. + * + * <p>Verifies that SPI workspace readers with {@code isApplicableForPluginResolution() == false} + * are discovered and active, but are <em>not</em> consulted during plugin resolution. + * + * @since 4.1.0 + */ +class MavenITmng8766SpiWorkspaceReaderTest extends AbstractMavenIntegrationTestCase { + + @Test + void testSpiWorkspaceReaderFilteredFromPluginResolution() throws Exception { + Path testDir = extractResources("mng-8766-spi-workspace-reader"); + + // First, install the extension + Verifier verifier = newVerifier(testDir.resolve("extension")); + verifier.addCliArgument("install"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + // Run the project that uses the extension — process-resources triggers plugin resolution + verifier = newVerifier(testDir.resolve("project")); + verifier.addCliArgument("process-resources"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + // Verify the SPI workspace reader was created (proves discovery works) + verifier.verifyTextInLog("[SPI-WR] created"); + + // The SPI workspace reader should be called for artifact resolution in the main session + // (e.g., during project dependency resolution, model building, etc.) + List<String> logLines = verifier.loadLogLines(); Review Comment: 💡 The comment says the SPI reader "should be called for artifact resolution" but there's no `assertTrue` verifying it *was* called for regular dependency resolution (e.g. `findArtifact` for `junit:junit`). The test only asserts the negative case (not called for plugin resolution). Adding a positive assertion would make the test truly verify both directions of the contract and catch regressions where SPI readers are silently dropped from the main chain entirely. ```suggestion // The SPI workspace reader should be called for artifact resolution in the main session // (e.g., during project dependency resolution, model building, etc.) List<String> logLines = verifier.loadLogLines(); boolean hasFindArtifactCalls = logLines.stream().anyMatch(line -> line.contains("[SPI-WR] findArtifact(")); assertTrue( hasFindArtifactCalls, "SPI workspace reader should be consulted during regular artifact resolution"); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
