Artifact 456d231786f1269470dd26da23320a7f735217b23430e3fd18b349e774cb66a4:
- File
simio/buggify_test.go
— part of check-in
[dfdf391349]
at
2026-10-21 15:55:33
on branch feat/submanifest-reader
— fix(dst): run invariant checks with fault injection suspended
The safety checks ran while simio's Buggify was armed, so the read-path sites in blob decompression and content expansion truncated or flipped the bytes each check expanded. Every seed at the adversarial and hostile levels then reported a blob-integrity violation that was never persisted; CI runs the normal level only, so nothing caught it.
simio.SuspendBuggify switches injection off and returns a resume that restores the previous state with its random stream intact, so a check mid-run does not change the run's later choices. Every exported check in dst/invariants.go suspends for its duration. A guard test arms Buggify over a clean repository and fails without the change.
Also records in the CHANGELOG that ExtractOpts and RepoOpenCmd are no longer comparable. (user: [email protected], size: 1645) [annotate] [blame] [check-ins using] [more...]
package simio import "testing" func TestBuggifyDisabledByDefault(t *testing.T) { // Should never fire when not enabled. for range 1000 { if Buggify(1.0) { t.Fatal("Buggify fired when not enabled") } } } func TestBuggifyEnabledFires(t *testing.T) { EnableBuggify(42) defer DisableBuggify() // With probability 1.0, should always fire. if !Buggify(1.0) { t.Fatal("Buggify(1.0) should always fire when enabled") } // With probability 0.0, should never fire. if Buggify(0.0) { t.Fatal("Buggify(0.0) should never fire") } } func TestBuggifyDeterministic(t *testing.T) { run := func(seed int64) int { EnableBuggify(seed) defer DisableBuggify() count := 0 for range 1000 { if Buggify(0.5) { count++ } } return count } c1 := run(99) c2 := run(99) if c1 != c2 { t.Fatalf("non-deterministic: %d vs %d", c1, c2) } // Different seed should produce different count (with high probability). c3 := run(7) if c1 == c3 { t.Logf("WARNING: different seeds produced same count %d (unlikely)", c1) } } func TestBuggifyDisableStops(t *testing.T) { EnableBuggify(1) if !Buggify(1.0) { t.Fatal("should fire when enabled") } DisableBuggify() if Buggify(1.0) { t.Fatal("should not fire after disable") } } func TestSuspendBuggifyRestores(t *testing.T) { EnableBuggify(1) defer DisableBuggify() resume := SuspendBuggify() inner := SuspendBuggify() if Buggify(1.0) { t.Fatal("should not fire while suspended") } inner() if Buggify(1.0) { t.Fatal("an inner resume must not end the outer suspension") } resume() if !Buggify(1.0) { t.Fatal("should fire again after resume") } }