From dbdca48e13dcf9e204132219d60c16903b014040 Mon Sep 17 00:00:00 2001 From: Christoph Hegemann Date: Wed, 11 Nov 2026 11:05:10 +0100 Subject: [PATCH] Add a consumer smoke test for the published scip-kotlin-analysis Compiles and runs a standalone project that depends only on the published artifact, so missing api dependencies and references to artifacts outside Maven Central fail CI. Amp-Thread-ID: https://ampcode.com/threads/T-01a1ca08-3e68-7113-8182-d86a4ef63ea7 Co-authored-by: Amp --- .github/workflows/ci.yaml | 5 +++ .../kotlin-analysis-consumer/build.gradle.kts | 16 ++++++++ .../settings.gradle.kts | 13 +++++++ .../src/main/kotlin/Main.kt | 38 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 examples/kotlin-analysis-consumer/build.gradle.kts create mode 100644 examples/kotlin-analysis-consumer/settings.gradle.kts create mode 100644 examples/kotlin-analysis-consumer/src/main/kotlin/Main.kt diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index efc81ba8d..9e68034e8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,6 +40,11 @@ jobs: - name: scip-kotlin-analysis tests run: gradle :scip-kotlin-analysis:test --no-daemon + - name: scip-kotlin-analysis consumer smoke test + run: | + gradle --no-daemon :scip-shared:publishToMavenLocal :scip-kotlin-analysis:publishToMavenLocal + gradle --no-daemon -p examples/kotlin-analysis-consumer run + docker_test: runs-on: ubuntu-latest name: Docker CLI tests diff --git a/examples/kotlin-analysis-consumer/build.gradle.kts b/examples/kotlin-analysis-consumer/build.gradle.kts new file mode 100644 index 000000000..b6f6a18a1 --- /dev/null +++ b/examples/kotlin-analysis-consumer/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + kotlin("jvm") version "2.4.21" + application +} + +val scipVersion = providers.gradleProperty("scipVersion").orElse("0.0.0-SNAPSHOT").get() + +dependencies { + // Deliberately the only dependency: everything the indexer's public API needs + // must come from scip-kotlin-analysis's published metadata. + implementation("org.scip-code:scip-kotlin-analysis:$scipVersion") +} + +application { + mainClass.set("MainKt") +} diff --git a/examples/kotlin-analysis-consumer/settings.gradle.kts b/examples/kotlin-analysis-consumer/settings.gradle.kts new file mode 100644 index 000000000..d01cce615 --- /dev/null +++ b/examples/kotlin-analysis-consumer/settings.gradle.kts @@ -0,0 +1,13 @@ +// A standalone consumer of the published scip-kotlin-analysis artifact. It resolves +// the module only through its published metadata, as library users do, so it catches +// missing `api` dependencies and references to artifacts outside Maven Central. +// +// Run: gradle publishToMavenLocal && gradle -p examples/kotlin-analysis-consumer run +rootProject.name = "kotlin-analysis-consumer" + +dependencyResolutionManagement { + repositories { + mavenLocal { content { includeGroup("org.scip-code") } } + mavenCentral() + } +} diff --git a/examples/kotlin-analysis-consumer/src/main/kotlin/Main.kt b/examples/kotlin-analysis-consumer/src/main/kotlin/Main.kt new file mode 100644 index 000000000..593073b87 --- /dev/null +++ b/examples/kotlin-analysis-consumer/src/main/kotlin/Main.kt @@ -0,0 +1,38 @@ +import java.nio.file.Files +import java.nio.file.Paths +import kotlin.io.path.writeText +import kotlin.system.exitProcess +import org.scip_code.scip.Document +import org.scip_code.scip_java.kotlin_analysis.KotlinAnalysisIndexer + +fun main() { + val sourceroot = Files.createTempDirectory("kotlin-analysis-consumer").toRealPath() + val src = Files.createDirectories(sourceroot.resolve("src")) + src.resolve("Greeter.kt") + .writeText("package demo\n\nclass Greeter(val name: String) { fun greet() = \"Hi \$name\" }\n") + val stdlib = Paths.get(KotlinVersion::class.java.protectionDomain.codeSource.location.toURI()) + + val streamed = mutableListOf() + val documents: List = + KotlinAnalysisIndexer( + sourceroot = sourceroot, + targetroot = sourceroot.resolve("scip-targetroot"), + sourceRoots = listOf(src), + classpath = listOf(stdlib), + callback = { streamed += it }, + ) + .run() + + val symbols = documents.flatMap { doc -> doc.occurrencesList.map { it.symbol } } + if (documents.map { it.relativePath } != listOf("src/Greeter.kt") || + streamed != documents || + "demo/Greeter#" !in symbols || + "kotlin/String#" !in symbols + ) { + System.err.println("Unexpected indexer output:\n$documents") + exitProcess(1) + } + println("Indexed ${documents.size} document with ${symbols.size} occurrences") + // The Analysis API leaves non-daemon threads behind; exit explicitly like scip-java. + exitProcess(0) +}