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
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package rerank
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestSourceBiasSignal_BoostsSourceWhenTestCoOccurs(t *testing.T) {
|
|
g := newTestGraph()
|
|
src := addFileNode(g, "auth/token.go", "ValidateToken", graph.KindFunction)
|
|
tst := addFileNode(g, "auth/token_test.go", "TestValidateToken", graph.KindFunction)
|
|
cands := []*Candidate{candidateFor(src, 0, -1), candidateFor(tst, 1, -1)}
|
|
ctx := &Context{Graph: g}
|
|
ctx.prepare(cands)
|
|
sig := SourceBiasSignal{}
|
|
|
|
if got := sig.Contribute("validate token", cands[0], ctx); got != 1.0 {
|
|
t.Errorf("source with co-occurring test got %v, want 1.0", got)
|
|
}
|
|
if got := sig.Contribute("validate token", cands[1], ctx); got != 0 {
|
|
t.Errorf("test candidate got %v, want 0", got)
|
|
}
|
|
}
|
|
|
|
func TestSourceBiasSignal_NoBoostWithoutTest(t *testing.T) {
|
|
g := newTestGraph()
|
|
src := addFileNode(g, "auth/token.go", "ValidateToken", graph.KindFunction)
|
|
other := addFileNode(g, "auth/session.go", "NewSession", graph.KindFunction)
|
|
cands := []*Candidate{candidateFor(src, 0, -1), candidateFor(other, 1, -1)}
|
|
ctx := &Context{Graph: g}
|
|
ctx.prepare(cands)
|
|
sig := SourceBiasSignal{}
|
|
|
|
if got := sig.Contribute("q", cands[0], ctx); got != 0 {
|
|
t.Errorf("source without co-occurring test got %v, want 0 (batch-relative)", got)
|
|
}
|
|
}
|
|
|
|
func TestTestNameStem(t *testing.T) {
|
|
cases := map[string]string{
|
|
"TestValidateToken": "validatetoken",
|
|
"validate_token_test": "validate_token",
|
|
"Test_Validate": "validate",
|
|
"ValidateSpec": "validate",
|
|
"describeAuthSpec": "describeauth",
|
|
}
|
|
for in, want := range cases {
|
|
if got := testNameStem(in); got != want {
|
|
t.Errorf("testNameStem(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSourceBiasSignal_NilSafety(t *testing.T) {
|
|
sig := SourceBiasSignal{}
|
|
if got := sig.Contribute("q", nil, &Context{}); got != 0 {
|
|
t.Errorf("nil candidate got %v, want 0", got)
|
|
}
|
|
if got := sig.Contribute("q", &Candidate{Node: &graph.Node{Name: "X", FilePath: "x.go"}}, nil); got != 0 {
|
|
t.Errorf("nil ctx got %v, want 0", got)
|
|
}
|
|
}
|