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

64 lines
2.4 KiB
Go

package parity
import "testing"
// parityFenceCount is the frozen number of languages held at or beyond their
// captured parity coverage in baseline.json. It is a CI-enforced golden, the
// same discipline as a wire-contract fingerprint: a DROP means a language was
// silently removed from the fence (un-protecting it from regression) and a RISE
// means a new benchmark language was fenced — either way an intentional change
// must bump this constant deliberately, which is the audit trail.
const parityFenceCount = 17
// TestParityCount freezes the at-or-beyond-parity language count. The committed
// baseline is the set of languages whose coverage CI refuses to let regress;
// pinning its size here makes any change to that set a deliberate, reviewed act
// rather than a silent erosion of the fence.
func TestParityCount(t *testing.T) {
b, err := LoadBaseline()
if err != nil {
t.Fatalf("load baseline: %v", err)
}
if got := len(b); got != parityFenceCount {
t.Fatalf("parity fence count = %d, want %d (frozen golden).\n"+
"If a benchmark language was intentionally added or removed, update parityFenceCount.",
got, parityFenceCount)
}
// Every fenced language must carry a real coverage floor in (0, 1]. A zero
// or negative floor fences nothing; a floor above 1 is not a valid ratio.
for lang, cov := range b {
if cov <= 0 {
t.Errorf("language %q baseline %.4f is non-positive — it fences nothing", lang, cov)
}
if cov > 1 {
t.Errorf("language %q baseline %.4f exceeds 1.0 (coverage is a ratio)", lang, cov)
}
}
}
// TestBaselineRepoExhaustive ensures the fence is exactly the benchmark corpus:
// every benchmark language has a baseline floor (none is measured but unfenced),
// and no baseline entry lacks a benchmark repo (no dead fence that is never
// measured). Together with TestParityCount this keeps the fence complete and
// honest as the corpus evolves.
func TestBaselineRepoExhaustive(t *testing.T) {
b, err := LoadBaseline()
if err != nil {
t.Fatalf("load baseline: %v", err)
}
repoLangs := map[string]bool{}
for _, repo := range BenchRepos() {
repoLangs[repo.Language] = true
if _, ok := b[repo.Language]; !ok {
t.Errorf("benchmark language %q (%s) has no baseline entry — unfenced, could regress undetected",
repo.Language, repo.URL)
}
}
for lang := range b {
if !repoLangs[lang] {
t.Errorf("baseline carries %q but no benchmark repo measures it — dead fence entry", lang)
}
}
}