Skip to content

fix(detector/jvm): scala + kotlin discriminator guards#141

Merged
aksOps merged 1 commit into
mainfrom
fix/scala-kotlin-detector-guards
May 13, 2026
Merged

fix(detector/jvm): scala + kotlin discriminator guards#141
aksOps merged 1 commit into
mainfrom
fix/scala-kotlin-detector-guards

Conversation

@aksOps
Copy link
Copy Markdown
Contributor

@aksOps aksOps commented May 13, 2026

Summary

  • Root cause found and fixed: KtorRouteDetector had no import discriminator — it fired on ANY Kotlin file containing routing {}, get("...") {}, post("...") {}, or install(...) patterns. These DSL idioms appear in non-Ktor Kotlin code (custom routing DSLs, test helpers, coroutine builders), producing false-positive endpoint/module/middleware nodes.
  • Added io.ktor import guard to KtorRouteDetector: returns EmptyResult() immediately if no io.ktor import is present in the file.
  • Scala detectors are clean: ScalaStructuresDetector emits only structural nodes (class/interface/method) regardless of content — no framework-flavored emissions possible by design.
  • Added Scala + Kotlin fixtures under testdata/fixture-multi-lang/services/jvm-suite/ covering Akka, Cats Effect, Slick, Ktor, Spring Boot, Exposed, plus plain (no-framework) files.

Detectors guarded

Detector Guard added Discriminator
ktor_routes (KtorRouteDetector) Yes strings.Contains(text, "io.ktor")

Test plan

  • TestKtorRoutesNoFireOnPlainDSL — realistic plain Kotlin with Ktor-shaped patterns but no io.ktor import → 0 nodes
  • TestKtorRoutesNoFireOnFixturePlainUtils — stdlib-only fixture → 0 framework nodes
  • TestScalaStructuresNoFrameworkEmissions — only structural node kinds emitted on plain Scala
  • go test ./internal/detector/jvm/... -count=1 — 107 tests pass
  • go test ./... -count=1 — 831 tests pass
  • go test -tags parity ./parity/... -count=1 — 5 tests pass
  • Plain-file emission count: PlainUtils.kt and PlainUtils.scala emit 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 ScalaStructuresDetector is purely structural with no framework-flavored output. The Kotlin over-detection was reproducible and fixed via the io.ktor guard. 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

…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>
@aksOps aksOps merged commit e544af0 into main May 13, 2026
13 checks passed
@aksOps aksOps deleted the fix/scala-kotlin-detector-guards branch May 13, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant