Files
zzet--gortex/internal/indexer/extractor_version_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

58 lines
2.1 KiB
Go

package indexer
import (
"reflect"
"testing"
)
// TestStaleLangsDetection proves the per-language extractor-staleness signal:
// only languages whose stored version is behind the current one are flagged
// (so the advisory names the exact languages to reindex — a scoped reindex
// rather than a full cold rebuild), a language the snapshot never recorded is
// never spuriously flagged, and an empty baseline reports nothing.
func TestStaleLangsDetection(t *testing.T) {
t.Run("only_behind_langs", func(t *testing.T) {
stored := map[string]int{"go": 1, "python": 2, "ruby": 1}
current := map[string]int{"go": 2, "python": 2, "ruby": 1, "rust": 3}
got := staleLangsBetween(stored, current)
// go is behind (1<2); python/ruby are current; rust is absent from
// stored (no baseline) so it is NOT flagged.
if want := []string{"go"}; !reflect.DeepEqual(got, want) {
t.Errorf("staleLangsBetween = %v, want %v", got, want)
}
})
t.Run("sorted_multiple", func(t *testing.T) {
stored := map[string]int{"typescript": 1, "go": 1, "python": 1}
current := map[string]int{"typescript": 2, "go": 2, "python": 1}
got := staleLangsBetween(stored, current)
if want := []string{"go", "typescript"}; !reflect.DeepEqual(got, want) {
t.Errorf("staleLangsBetween = %v, want %v (sorted)", got, want)
}
})
t.Run("json_and_empty", func(t *testing.T) {
// An empty / unparseable baseline reports nothing.
if got := ExtractorVersionStaleLangs(""); got != nil {
t.Errorf("empty baseline = %v, want nil", got)
}
if got := ExtractorVersionStaleLangs("not json"); got != nil {
t.Errorf("bad json = %v, want nil", got)
}
// Against the live extractor versions (all baseline 1), a stored go@1
// is not stale.
if got := ExtractorVersionStaleLangs(`{"go":1}`); len(got) != 0 {
t.Errorf("stored at current = %v, want empty", got)
}
})
t.Run("lang_for_file", func(t *testing.T) {
if got := ExtractorLangForFile("internal/auth/token.go"); got != "go" {
t.Errorf("ExtractorLangForFile(.go) = %q, want go", got)
}
if got := ExtractorLangForFile("README.zzz"); got != "" {
t.Errorf("ExtractorLangForFile(unknown) = %q, want \"\"", got)
}
})
}