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

53 lines
2.1 KiB
Go

package semantic
import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
func TestEnrichBoundReason(t *testing.T) {
assert.Equal(t, EnrichBoundBudget, enrichBoundReason(EnrichStatePartial, &EnrichResult{SymbolsTotal: 100, SymbolsCovered: 40}))
assert.Equal(t, EnrichBoundBudget, enrichBoundReason(EnrichStateCompleted, &EnrichResult{Partial: true, SymbolsTotal: 100, SymbolsCovered: 40}))
assert.Equal(t, EnrichBoundCap, enrichBoundReason(EnrichStateCompleted, &EnrichResult{SymbolsTotal: 100, SymbolsCovered: 35}))
assert.Equal(t, EnrichBoundCompletedAll, enrichBoundReason(EnrichStateCompleted, &EnrichResult{SymbolsTotal: 100, SymbolsCovered: 100}))
assert.Equal(t, EnrichBoundCompletedAll, enrichBoundReason(EnrichStateCompleted, &EnrichResult{SymbolsTotal: 0}))
}
// A completed enrichment that covered only a sliver of its targets must surface
// the coverage figure and a "cap" bounding reason on the status — never a bare
// "completed" that reads as full enrichment.
func TestSetEnrichStatus_CoverageSurfaced(t *testing.T) {
mgr := NewManager(Config{Enabled: true}, zap.NewNop())
res := &EnrichResult{
Provider: "lsp-jdtls",
Language: "java",
EdgesAdded: 156,
EdgesConfirmed: 554,
NodesEnriched: 35,
SymbolsTotal: 1500,
SymbolsCovered: 35,
}
res.CoveragePercent = float64(res.SymbolsCovered) / float64(res.SymbolsTotal) * 100
mgr.setEnrichStatus("petclinic", "lsp-jdtls", "java", EnrichStateCompleted, 0, res, "")
statuses := mgr.EnrichmentStatuses()
var st *EnrichmentStatus
for i := range statuses {
if statuses[i].Provider == "lsp-jdtls" {
st = &statuses[i]
}
}
if assert.NotNil(t, st) {
assert.Equal(t, EnrichStateCompleted, st.State)
assert.Equal(t, 1500, st.SymbolsTotal)
assert.Equal(t, 35, st.SymbolsCovered)
assert.InDelta(t, 2.33, st.CoveragePercent, 0.1)
assert.Equal(t, EnrichBoundCap, st.BoundReason,
"a completed pass covering <100% of targets must report the cap bounding reason")
}
// The reason is back-stamped onto the result too.
assert.Equal(t, EnrichBoundCap, res.BoundReason)
}