Files
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

40 lines
1.8 KiB
Go

package analysis
import (
"testing"
"github.com/zzet/gortex/internal/graph"
)
// TestAnalyzeImpact_LowerBound_InterfaceDispatch: a changed method that
// implements an interface has callers that may dispatch through the interface,
// so its blast radius is a floor, not an exact count.
func TestAnalyzeImpact_LowerBound_InterfaceDispatch(t *testing.T) {
g := graph.New()
g.AddNode(&graph.Node{ID: "pkg.T.M", Kind: graph.KindMethod, Name: "M"})
g.AddNode(&graph.Node{ID: "pkg.caller", Kind: graph.KindFunction, Name: "caller"})
g.AddEdge(&graph.Edge{From: "pkg.caller", To: "pkg.T.M", Kind: graph.EdgeCalls, Origin: graph.OriginASTResolved})
g.AddEdge(&graph.Edge{From: "pkg.T.M", To: "iface::I.M", Kind: graph.EdgeImplements, Origin: graph.OriginASTResolved})
res := AnalyzeImpact(g, []string{"pkg.T.M"}, nil, nil)
if !res.LowerBound {
t.Fatalf("expected LowerBound=true, got summary=%q boundaries=%+v", res.Summary, res.Boundaries)
}
if len(res.Boundaries) != 1 || res.Boundaries[0].Reason != graph.BoundaryInterfaceDispatch {
t.Errorf("expected one interface_dispatch boundary, got %+v", res.Boundaries)
}
}
// TestAnalyzeImpact_NoBoundary: a plain function with no dispatch participation
// reports an exact count (no lower-bound flag).
func TestAnalyzeImpact_NoBoundary(t *testing.T) {
g := graph.New()
g.AddNode(&graph.Node{ID: "pkg.f", Kind: graph.KindFunction, Name: "f"})
g.AddNode(&graph.Node{ID: "pkg.g", Kind: graph.KindFunction, Name: "g"})
g.AddEdge(&graph.Edge{From: "pkg.g", To: "pkg.f", Kind: graph.EdgeCalls, Origin: graph.OriginASTResolved})
res := AnalyzeImpact(g, []string{"pkg.f"}, nil, nil)
if res.LowerBound || len(res.Boundaries) != 0 {
t.Errorf("expected no lower bound, got LowerBound=%v boundaries=%+v", res.LowerBound, res.Boundaries)
}
}