Files
zzet--gortex/internal/graph/provenance_weight_test.go
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

48 lines
1.7 KiB
Go

package graph
import "testing"
func TestProvenanceWeight_Tiers(t *testing.T) {
w := func(origin string) float64 {
return ProvenanceWeight(&Edge{From: "a", To: "b", Kind: EdgeCalls, Origin: origin})
}
cases := []struct {
origin string
want float64
}{
{OriginLSPResolved, provWeightLSP},
{OriginLSPDispatch, provWeightLSP},
{OriginASTResolved, ProvenanceWeightMax},
{OriginASTInferred, provWeightASTInferred},
{OriginTextMatched, ProvenanceWeightMin},
}
for _, c := range cases {
if got := w(c.origin); got != c.want {
t.Errorf("ProvenanceWeight(origin=%q) = %v, want %v", c.origin, got, c.want)
}
}
// LSP and text tiers are attenuated below the ast_resolved baseline.
if !(w(OriginLSPResolved) < ProvenanceWeightMax) {
t.Errorf("lsp tier must weight below ast_resolved baseline")
}
if !(w(OriginTextMatched) < ProvenanceWeightMax) {
t.Errorf("text tier must weight below ast_resolved baseline")
}
}
func TestProvenanceWeight_BackfillsAndNilSafe(t *testing.T) {
// A nil edge weights at the trusted baseline.
if got := ProvenanceWeight(nil); got != ProvenanceWeightMax {
t.Errorf("nil edge = %v, want %v", got, ProvenanceWeightMax)
}
// Unset Origin backfills via DefaultOriginFor: a structural import
// edge is ast_resolved (baseline); a bare call edge with no
// confidence falls to text_matched (the minimum).
if got := ProvenanceWeight(&Edge{Kind: EdgeImports}); got != ProvenanceWeightMax {
t.Errorf("structural import edge = %v, want %v", got, ProvenanceWeightMax)
}
if got := ProvenanceWeight(&Edge{Kind: EdgeCalls}); got != ProvenanceWeightMin {
t.Errorf("bare unresolved call edge = %v, want %v", got, ProvenanceWeightMin)
}
}