Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make weighted variant test deterministic
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
  • Loading branch information
Copilot and gh-aw-bot authored Oct 7, 2026
commit 202d80b57591d6f7a820376251c277a8424050bc
17 changes: 11 additions & 6 deletions actions/setup/js/pick_experiment.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,18 @@ describe("pick_experiment", () => {
it("distributes variants proportionally across many runs", () => {
const counts = { A: 0, B: 0 };
const N = 1000;
for (let i = 0; i < N; i++) {
const v = pickVariantWeighted(["A", "B"], [70, 30]);
counts[v]++;
let sample = 0;
const random = vi.spyOn(Math, "random").mockImplementation(() => (sample++ + 0.5) / N);
try {
for (let i = 0; i < N; i++) {
const v = pickVariantWeighted(["A", "B"], [70, 30]);
counts[v]++;
}
expect(counts["A"]).toBe(700);
expect(counts["B"]).toBe(300);
} finally {
random.mockRestore();
}
// With weights 70:30 we expect ~70% A and ~30% B. Allow 10% absolute tolerance.
expect(counts["A"] / N).toBeCloseTo(0.7, 1);
expect(counts["B"] / N).toBeCloseTo(0.3, 1);
});
});

Expand Down
Loading