Skip to content

Commit 04098be

Browse files
aksOpsclaude
andcommitted
fix(cli): register all 18 detector packages, not just 3
The CLI binary's detector registry was empty for 15 language families because their packages were never imported. Only generic, jvm/java, and python had blank-imports in cli/index.go + cli/plugins.go — every other detector package's init() never fired in production. Symptoms (from benchmark on polyglot-bench): - terraform-aws-eks: 0 Go nodes (155 files discovered) - eshop: 0 Go nodes (1095 files) - nuxt: 0 Go nodes (1412 files) - PSScriptAnalyzer: 0 Go nodes (657 files) - All non-Java/Python projects empty Fix: new cli/detectors_register.go does blank imports of all 18 leaf detector packages (auth, csharp, frontend, generic, golang, iac, jvm/{java,kotlin,scala}, markup, proto, python, script/shell, sql, structured, systems/{cpp,rust}, typescript). Re-bench post-fix: terraform 1556 nodes, eshop 1339, nuxt 4904, etc. All language families now produce output. Detector tuning to right-size the node counts vs Java is the next pass. Adds two regression tests in iac/terraform_real_test.go that exercise the detector on a synthetic terraform-aws-eks slice AND the real main.tf when locally available. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1b5478f commit 04098be

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cli
2+
3+
// Side-effect imports: each detector package's init() registers itself with
4+
// the process-wide Default registry. Without these imports the linker would
5+
// drop the packages and the CLI binary would ship with the registry empty.
6+
//
7+
// Keep this list flat (leaf packages only) and exhaustive — any detector
8+
// package added under internal/detector/ must land here too.
9+
import (
10+
_ "github.com/randomcodespace/codeiq/go/internal/detector/auth"
11+
_ "github.com/randomcodespace/codeiq/go/internal/detector/csharp"
12+
_ "github.com/randomcodespace/codeiq/go/internal/detector/frontend"
13+
_ "github.com/randomcodespace/codeiq/go/internal/detector/generic"
14+
_ "github.com/randomcodespace/codeiq/go/internal/detector/golang"
15+
_ "github.com/randomcodespace/codeiq/go/internal/detector/iac"
16+
_ "github.com/randomcodespace/codeiq/go/internal/detector/jvm/java"
17+
_ "github.com/randomcodespace/codeiq/go/internal/detector/jvm/kotlin"
18+
_ "github.com/randomcodespace/codeiq/go/internal/detector/jvm/scala"
19+
_ "github.com/randomcodespace/codeiq/go/internal/detector/markup"
20+
_ "github.com/randomcodespace/codeiq/go/internal/detector/proto"
21+
_ "github.com/randomcodespace/codeiq/go/internal/detector/python"
22+
_ "github.com/randomcodespace/codeiq/go/internal/detector/script/shell"
23+
_ "github.com/randomcodespace/codeiq/go/internal/detector/sql"
24+
_ "github.com/randomcodespace/codeiq/go/internal/detector/structured"
25+
_ "github.com/randomcodespace/codeiq/go/internal/detector/systems/cpp"
26+
_ "github.com/randomcodespace/codeiq/go/internal/detector/systems/rust"
27+
_ "github.com/randomcodespace/codeiq/go/internal/detector/typescript"
28+
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package iac
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/randomcodespace/codeiq/go/internal/detector"
9+
)
10+
11+
// TestTerraform_RealFile catches the regression where TerraformDetector
12+
// fires on synthetic fixtures but produces zero nodes on the public
13+
// terraform-aws-eks repository (see PR #130 benchmark report).
14+
func TestTerraform_RealFile(t *testing.T) {
15+
// Inline a representative slice of terraform-aws-eks/main.tf.
16+
content := `data "aws_partition" "current" {
17+
count = local.create ? 1 : 0
18+
}
19+
data "aws_caller_identity" "current" {
20+
count = local.create ? 1 : 0
21+
}
22+
23+
resource "aws_eks_cluster" "this" {
24+
count = local.create ? 1 : 0
25+
26+
name = var.name
27+
role_arn = local.cluster_role
28+
version = var.kubernetes_version
29+
}
30+
31+
variable "name" {
32+
type = string
33+
default = "my-cluster"
34+
}
35+
36+
output "cluster_endpoint" {
37+
value = try(aws_eks_cluster.this[0].endpoint, null)
38+
}
39+
40+
module "vpc" {
41+
source = "terraform-aws-modules/vpc/aws"
42+
}
43+
`
44+
d := NewTerraformDetector()
45+
r := d.Detect(&detector.Context{
46+
FilePath: "main.tf",
47+
Language: "terraform",
48+
Content: content,
49+
})
50+
wantMin := 6 // 2 data + 1 resource + 1 var + 1 output + 1 module
51+
if len(r.Nodes) < wantMin {
52+
t.Fatalf("expected >=%d nodes, got %d", wantMin, len(r.Nodes))
53+
}
54+
}
55+
56+
// TestTerraform_AwsEksHEAD verifies the detector against the actual file
57+
// from terraform-aws-eks/main.tf when present. Skips if the local clone
58+
// isn't available.
59+
func TestTerraform_AwsEksHEAD(t *testing.T) {
60+
path := "/home/dev/projects/polyglot-bench/terraform-aws-eks/main.tf"
61+
if _, err := os.Stat(path); err != nil {
62+
t.Skipf("test fixture not present: %s", filepath.Base(path))
63+
}
64+
b, err := os.ReadFile(path)
65+
if err != nil {
66+
t.Fatal(err)
67+
}
68+
d := NewTerraformDetector()
69+
r := d.Detect(&detector.Context{
70+
FilePath: "main.tf",
71+
Language: "terraform",
72+
Content: string(b),
73+
})
74+
if len(r.Nodes) == 0 {
75+
t.Fatalf("expected nodes from main.tf, got 0 (file is %d bytes)", len(b))
76+
}
77+
t.Logf("main.tf: %d nodes", len(r.Nodes))
78+
}

0 commit comments

Comments
 (0)