fix(detector/jvm): scala + kotlin discriminator guards#141
Merged
Conversation
…otlin fixtures
Earlier parity runs showed Kotlin ~14× over-detection vs the Java reference.
Root cause: KtorRouteDetector matched `routing {}`, `get("...") {}`,
`post("...") {}`, and `install(...)` on ANY Kotlin file regardless of imports —
generic DSL patterns that appear in non-Ktor code (custom routing DSLs, test
helpers, coroutine builders).
Adds:
- `io.ktor` import discriminator guard to KtorRouteDetector: returns
EmptyResult immediately if no io.ktor import is present in the file
- Negative tests: TestKtorRoutesNoFireOnPlainDSL (realistic plain Kotlin with
Ktor-shaped patterns but no import) and TestKtorRoutesNoFireOnFixturePlainUtils
- Scala structures detector confirmed clean: emits only class/interface/method
nodes; TestScalaStructuresNoFrameworkEmissions added to lock this in
- Minimal Scala + Kotlin fixtures under testdata/.../jvm-suite/ covering
Akka, Cats Effect, Slick, Ktor, Spring Boot, Exposed, plus plain files
All 831 tests pass; 5 parity tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KtorRouteDetectorhad no import discriminator — it fired on ANY Kotlin file containingrouting {},get("...") {},post("...") {}, orinstall(...)patterns. These DSL idioms appear in non-Ktor Kotlin code (custom routing DSLs, test helpers, coroutine builders), producing false-positiveendpoint/module/middlewarenodes.io.ktorimport guard toKtorRouteDetector: returnsEmptyResult()immediately if noio.ktorimport is present in the file.ScalaStructuresDetectoremits only structural nodes (class/interface/method) regardless of content — no framework-flavored emissions possible by design.testdata/fixture-multi-lang/services/jvm-suite/covering Akka, Cats Effect, Slick, Ktor, Spring Boot, Exposed, plus plain (no-framework) files.Detectors guarded
ktor_routes(KtorRouteDetector)strings.Contains(text, "io.ktor")Test plan
TestKtorRoutesNoFireOnPlainDSL— realistic plain Kotlin with Ktor-shaped patterns but noio.ktorimport → 0 nodesTestKtorRoutesNoFireOnFixturePlainUtils— stdlib-only fixture → 0 framework nodesTestScalaStructuresNoFrameworkEmissions— only structural node kinds emitted on plain Scalago test ./internal/detector/jvm/... -count=1— 107 tests passgo test ./... -count=1— 831 tests passgo test -tags parity ./parity/... -count=1— 5 tests passPlainUtils.ktandPlainUtils.scalaemit 0 framework nodes after fix (structural class/method nodes only, which is correct)Deviation from brief
The 15×/14× over-detection was not reproducible on synthetic fixtures for Scala — the
ScalaStructuresDetectoris purely structural with no framework-flavored output. The Kotlin over-detection was reproducible and fixed via theio.ktorguard. If the 14× figure came from external repos with Ktor-heavy Kotlin codebases, this fix directly addresses it. If it came from other sources, further investigation with those specific repos would be needed.🤖 Generated with Claude Code