Files
zzet--gortex/internal/analysis/processes_java_test.go
T
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

50 lines
2.1 KiB
Go

package analysis
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
// TestScoreEntryPoint_JavaVisibility checks a private Java helper is not
// handed the public-API entry-point boost (it must score below an
// otherwise-identical public method).
func TestScoreEntryPoint_JavaVisibility(t *testing.T) {
pub := &graph.Node{
ID: "S.java::doWork", Kind: graph.KindMethod, Name: "doWork", Language: "java",
Meta: map[string]any{"visibility": "public"},
}
priv := &graph.Node{
ID: "S.java::doWorkImpl", Kind: graph.KindMethod, Name: "doWorkImpl", Language: "java",
Meta: map[string]any{"visibility": "private"},
}
pubScore := scoreEntryPoint(pub, 3, 0)
privScore := scoreEntryPoint(priv, 3, 0)
require.Greater(t, pubScore, privScore, "public method must outscore an identical private one")
}
// TestScoreEntryPoint_JavaEntryBoost checks a stamped Spring handler is
// boosted as a process root, while a stamped JUnit test is not (tests
// stay live for dead-code but are noise as top-level processes).
func TestScoreEntryPoint_JavaEntryBoost(t *testing.T) {
// All three share a name with no entry/util pattern boost, so the
// only score difference comes from the entry-point stamp.
plain := &graph.Node{
ID: "S.java::execute", Kind: graph.KindMethod, Name: "execute", Language: "java",
Meta: map[string]any{"visibility": "public"},
}
handler := &graph.Node{
ID: "C.java::execute", Kind: graph.KindMethod, Name: "execute", Language: "java",
Meta: map[string]any{"visibility": "public", "entry_point": true, "entry_point_kind": "spring:handler"},
}
test := &graph.Node{
ID: "T.java::execute", Kind: graph.KindMethod, Name: "execute", Language: "java",
Meta: map[string]any{"visibility": "public", "entry_point": true, "entry_point_kind": "junit:test"},
}
require.Greater(t, scoreEntryPoint(handler, 3, 0), scoreEntryPoint(plain, 3, 0),
"a stamped Spring handler must outscore a plain method")
require.Equal(t, scoreEntryPoint(test, 3, 0), scoreEntryPoint(plain, 3, 0),
"a JUnit test must not get the process-root boost")
}