Repository navigation
Build: share one test RNG across randomized tests (#1868) - #1882
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
Conversation
The crawler oracle tests, copy_tree's random-tree test, the npm oracle fixture builder and the go.mod / go.sum editor property tests each carried their own copy of the xorshift64* generator that crate::test_rng says is the only one. They now all draw from test_rng::Rng. Seeds and the seed mixing are unchanged, so every test replays exactly the same cases. Test-only; no production code changes. Refs #1868 Assisted-by: Claude Code:claude-opus-5-5
Review follow-up. The crawler and vex oracle tests now import crate::test_rng::Rng instead of a re-export through oracle_support, the npm oracle's Gen calls its Rng directly instead of through forwarding methods, and the pnpm equivalence test seeds with Rng::new rather than spelling the seed mixing out by hand. Same seeds, same cases. Refs #1868 Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f352ebf. Configure here.
|
Ready for review (burn-down agent).
Generated by Claude Code |
|
Burn-down agent: labeled Ready for review at
Generated by Claude Code |
Final review brief (
|
LLM Description written by Claude Code:claude-opus-5-5
Fixes #1868
Root cause
crate::test_rngsays it is the one deterministic RNG the randomized tests share, butsocket-patch-corestill had five more copies of the same xorshift64* generator:crawlers/oracle_support.rs:pub(crate) struct Rng, used by the crawler*_matches_the_async_oracletests andvex::verify.crawlers/npm_crawler/oracle.rs: inlined into theGenfixture builder.patch/copy_tree.rs: a privatestruct Rng(u64).vendor/go_sum_edit.rsandvendor/go_mod_edit.rs: inline closures. The issue didn't list these two.pnpm_equivalence_tests.rsalso wrote outRng::new's seed mixing by hand.Change
oracle_supportcopy. The composer, go, ruby, python, nuget, cargo and maven crawler tests andvex::verifynow importcrate::test_rng::Rngdirectly.npm_crawler::oracle::Genholds atest_rng::Rngand callsself.rng.below/chance/pickdirectly.chancenow takes au64, as it does intest_rng.copy_treeusestest_rng::Rngwith the same raw seed.test_rng::Rng::new(seed).Rng::new(seed).The seeds, the seed mixing (
seed * 0x9E37_79B9_7F4A_7C15 | 1) andchance(p) == next() % 100 < pare all unchanged, so every generated case and case count stays the same. Everything touched is#[cfg(test)]; there is no production change.After this PR,
grep -rn 0x2545_F491_4F6C_DD1D crates/socket-patch-core/srcfinds the generator intest_rng.rsand one other hit incargo_lock_equivalence_tests.rs, where the constant is a seed value, not a generator.Review findings I didn't fix (from
/code-review high)socket-patch-cli/src/commands/scan/hosted.rstest): left as is. The CLI crate can't see core's#[cfg(test)]test_rng, and sharing it would mean exporting a test helper from core's public API or adding a feature. That deserves its own decision.FnMut(usize) -> usizeclosure, which now wrapsRng::below. Switching them to&mut Rngwould rewrite about 40rng(n)calls for no change in behaviour. The issue's goal, no second generator, is met either way.CI cost
No workflow change. A lean PR run is unchanged: ~28 Linux jobs, about 8 min.
Test evidence
ci-ok,clippy, coverage (1)/(2), every lean e2e leg). Bugbot found no issues on f352ebf.cargo fmt --all -- --check: clean.cargo clippy --workspace --all-features -- -D warnings: clean. With--all-targets, the remaining lints are all in lines this PR doesn't touch (for examplepython_crawler.rs:4187,crawler_ruby_e2e.rs, CLItests/prebuilt_common).cargo test -p socket-patch-core --all-features --lib: 6994 passed, 4 failed. The 4 also fail on unmodifiedorigin/mainin this sandbox, which runs as uid 0, so root ignores the read-only dirs they depend on. Running the same test binary as uid 65534 (setpriv --reuid=65534), all 4 pass:copy_tree::relax_loop_must_not_traverse_symlinked_root,vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry,pypi_poetry::wire_write_failure_maps_error_and_leaves_lock_untouched,pypi_requirements::wire_failure_rolls_back_already_written_files.https://claude.ai/code/session_011f9aeSP5GEeiLsq6p3Rmrk
Generated by Claude Code