chore: import upstream snapshot with attribution
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

This commit is contained in:
wehub-resource-sync
2026-07-13 12:33:42 +08:00
commit a06f331eb8
3186 changed files with 689843 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
package main
import "testing"
// TestShouldCompactStore pins the boot-compaction trigger: all three gates
// (majority-dead file, absolute reclaimable floor, disk headroom for the
// VACUUM copy) must hold, and each boundary is exclusive — equality on any
// gate means "don't". Pure-function table so the policy is exercised without
// a store or a filesystem.
func TestShouldCompactStore(t *testing.T) {
const (
gib = int64(1) << 30
tib = uint64(1) << 40
)
cases := []struct {
name string
free int64
total int64
avail uint64
want bool
}{
{name: "all gates hold", free: 2 * gib, total: 3 * gib, avail: tib, want: true},
{name: "the observed live store shape (4.4/6.8 GB)", free: 4707074048, total: 7301444403, avail: tib, want: true},
// Fraction gate: freelist must be a strict MAJORITY of the file.
{name: "exactly half free — no", free: 2 * gib, total: 4 * gib, avail: tib, want: false},
{name: "just under half free — no", free: 2*gib - 1, total: 4 * gib, avail: tib, want: false},
{name: "just over half free — yes", free: 2*gib + 1, total: 4 * gib, avail: tib, want: true},
// Absolute floor: a small file's majority is still not worth minutes
// of exclusive I/O.
{name: "90% free but only 900 MiB — no", free: 900 << 20, total: 1 << 30, avail: tib, want: false},
{name: "exactly 1 GiB free — no (floor is exclusive)", free: gib, total: gib + 2, avail: tib, want: false},
// Headroom gate: available disk must strictly exceed total × 1.5,
// because VACUUM transiently needs up to a full extra copy.
{name: "avail exactly 1.5× — no", free: 2 * gib, total: 3 * gib, avail: uint64(3*gib) + uint64(3*gib)/2, want: false},
{name: "avail just over 1.5× — yes", free: 2 * gib, total: 3 * gib, avail: uint64(3*gib) + uint64(3*gib)/2 + 1, want: true},
{name: "tight disk — no", free: 2 * gib, total: 3 * gib, avail: uint64(3 * gib), want: false},
// Degenerate inputs: an unreadable store reports zeros; never fire.
{name: "zero stats", free: 0, total: 0, avail: tib, want: false},
{name: "zero free", free: 0, total: 4 * gib, avail: tib, want: false},
{name: "zero total", free: 2 * gib, total: 0, avail: tib, want: false},
{name: "negative total", free: 2 * gib, total: -1, avail: tib, want: false},
{name: "zero avail", free: 2 * gib, total: 3 * gib, avail: 0, want: false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := shouldCompactStore(tc.free, tc.total, tc.avail); got != tc.want {
t.Errorf("shouldCompactStore(free=%d, total=%d, avail=%d) = %v, want %v",
tc.free, tc.total, tc.avail, got, tc.want)
}
})
}
}