Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/crawlers/cargo_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,8 @@ version = "fake"
mod equivalence {
use super::super::oracle::LegacyCargoCrawler;
use super::*;
use crate::crawlers::oracle_support::{mkdir, rows, symlink, write, PermGuard, Rng};
use crate::crawlers::oracle_support::{mkdir, rows, symlink, write, PermGuard};
use crate::test_rng::Rng;

const NAMES: &[&str] = &["serde", "serde-json", "sha-1", "tokio", "dup", "a_b"];
const VERSIONS: &[&str] = &["1.0.0", "1.0.0-rc.1", "0.2.3", "5", "1.0.0+build"];
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/crawlers/composer_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,8 @@ mod tests {
mod equivalence {
use super::super::oracle::LegacyComposerCrawler;
use super::*;
use crate::crawlers::oracle_support::{map_rows, mkdir, rows, symlink, write, Rng};
use crate::crawlers::oracle_support::{map_rows, mkdir, rows, symlink, write};
use crate::test_rng::Rng;

const NAMES: &[&str] = &[
"monolog/monolog",
Expand Down
5 changes: 2 additions & 3 deletions crates/socket-patch-core/src/crawlers/go_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,9 +1696,8 @@ mod tests {
mod equivalence {
use super::super::oracle::LegacyGoCrawler;
use super::*;
use crate::crawlers::oracle_support::{
map_rows, mkdir, rows, symlink, write, PermGuard, Rng,
};
use crate::crawlers::oracle_support::{map_rows, mkdir, rows, symlink, write, PermGuard};
use crate::test_rng::Rng;

const NAMES: &[&str] = &[
"github.com",
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/crawlers/maven_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2909,8 +2909,9 @@ mod tests {
use super::super::oracle::LegacyMavenCrawler;
use super::*;
use crate::crawlers::oracle_support::{
mkdir, rows, symlink, write, write_bytes, PermGuard, Rng,
mkdir, rows, symlink, write, write_bytes, PermGuard,
};
use crate::test_rng::Rng;

const GROUPS: &[&str] = &["org/apache/commons", "com/google/guava", "io/netty"];
const ARTIFACTS: &[&str] = &["commons-lang3", "guava", "netty-all", "dup"];
Expand Down
139 changes: 59 additions & 80 deletions crates/socket-patch-core/src/crawlers/npm_crawler/oracle.rs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions crates/socket-patch-core/src/crawlers/nuget_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2096,9 +2096,8 @@ mod tests {
mod equivalence {
use super::super::oracle::LegacyNuGetCrawler;
use super::*;
use crate::crawlers::oracle_support::{
map_rows, mkdir, rows, symlink, write, PermGuard, Rng,
};
use crate::crawlers::oracle_support::{map_rows, mkdir, rows, symlink, write, PermGuard};
use crate::test_rng::Rng;

const IDS: &[&str] = &["Newtonsoft.Json", "xunit", "System.Text.Json", "Dup", "dup"];
const VERSIONS: &[&str] = &["13.0.3", "2.0.0-RC1", "8.0.0", "1.0.0"];
Expand Down
30 changes: 0 additions & 30 deletions crates/socket-patch-core/src/crawlers/oracle_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,6 @@ use std::path::{Path, PathBuf};

use super::types::CrawledPackage;

/// Deterministic xorshift64* generator (no `rand` dependency).
pub(crate) struct Rng(u64);

impl Rng {
pub(crate) fn new(seed: u64) -> Self {
Self(seed.wrapping_mul(0x9E37_79B9_7F4A_7C15) | 1)
}

pub(crate) fn next(&mut self) -> u64 {
let mut x = self.0;
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
self.0 = x;
x.wrapping_mul(0x2545_F491_4F6C_DD1D)
}

pub(crate) fn below(&mut self, n: usize) -> usize {
(self.next() % n as u64) as usize
}

pub(crate) fn chance(&mut self, pct: usize) -> bool {
self.below(100) < pct
}

pub(crate) fn pick<'a>(&mut self, items: &[&'a str]) -> &'a str {
items[self.below(items.len())]
}
}

/// Restores permissions a generator stripped before the tempdir is removed
/// (declare it AFTER the tempdir so it drops first). Only Unix strips
/// permissions; everywhere else the plan is recorded and ignored.
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/crawlers/python_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7946,8 +7946,9 @@ G=
use super::super::oracle::{self, LegacyPythonCrawler};
use super::*;
use crate::crawlers::oracle_support::{
fifo, map_rows, mkdir, rows, symlink, write, write_bytes, PermGuard, Rng,
fifo, map_rows, mkdir, rows, symlink, write, write_bytes, PermGuard,
};
use crate::test_rng::Rng;

const NAMES: &[&str] = &["requests", "Flask_Cors", "zope.interface", "dup", "Dup"];
const VERSIONS: &[&str] = &["1.0", "2.31.0", "1.0+local", "3.0a1"];
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/crawlers/ruby_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6241,7 +6241,8 @@ mod tests {

#[tokio::test]
async fn find_each_by_purl_matches_per_purl_find_by_purls() {
use crate::crawlers::oracle_support::{mkdir, symlink, write, PermGuard, Rng};
use crate::crawlers::oracle_support::{mkdir, symlink, write, PermGuard};
use crate::test_rng::Rng;

const GEMS: &[&str] = &["rails", "nokogiri", "rack", "rails-html"];
const VERSIONS: &[&str] = &["7.1.0", "1.16.5", "3.0.0"];
Expand Down
18 changes: 1 addition & 17 deletions crates/socket-patch-core/src/patch/copy_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub async fn remove_tree(dir: &Path) -> std::io::Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_rng::Rng;
use std::fs;

#[cfg(unix)]
Expand Down Expand Up @@ -234,23 +235,6 @@ mod tests {
.collect()
}

/// Deterministic xorshift64* — no `rand` dev-dependency.
struct Rng(u64);

impl Rng {
fn next(&mut self) -> u64 {
let mut x = self.0;
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
self.0 = x;
x.wrapping_mul(0x2545_F491_4F6C_DD1D)
}
fn below(&mut self, n: usize) -> usize {
(self.next() % n as u64) as usize
}
}

const SKIP: &str = ".cargo-checksum.json";

/// A random tree under `dir`: nested and empty dirs, files (some
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ fn indexed_pnpm_rewrite_matches_golden_on_random_lock_sets() {
// instead of quietly testing only the plain rewrite path.
let mut outcomes: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
for seed in 1..=300u64 {
let mut rng = Rng(seed.wrapping_mul(0x9E37_79B9_7F4A_7C15) | 1);
let mut rng = Rng::new(seed);
let lock_count = 1 + rng.below(3);
let mut files = BTreeMap::new();
let mut all: Vec<Pkg> = Vec::new();
Expand Down
9 changes: 2 additions & 7 deletions crates/socket-patch-core/src/vendor/go_mod_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,13 +2543,8 @@ replace (
/// Random go.mod-grammar text: directive keywords (and near misses),
/// block opens/closes (balanced or not), comments, blank lines, CRLF.
fn random_go_mod(seed: u64) -> String {
let mut x = seed.wrapping_mul(0x9E37_79B9_7F4A_7C15) | 1;
let mut next = move |n: usize| {
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
(x.wrapping_mul(0x2545_F491_4F6C_DD1D) % n as u64) as usize
};
let mut rng = crate::test_rng::Rng::new(seed);
let mut next = move |n: usize| rng.below(n);
const PIECES: &[&str] = &[
"replace",
"require",
Expand Down
9 changes: 2 additions & 7 deletions crates/socket-patch-core/src/vendor/go_sum_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,8 @@ mod tests {
#[test]
fn lines_form_matches_the_text_form_step_by_step() {
for seed in 1..=3000u64 {
let mut x = seed.wrapping_mul(0x9E37_79B9_7F4A_7C15) | 1;
let mut rng = move |n: usize| {
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
(x.wrapping_mul(0x2545_F491_4F6C_DD1D) % n as u64) as usize
};
let mut r = crate::test_rng::Rng::new(seed);
let mut rng = move |n: usize| r.below(n);
let start = random_go_sum(&mut rng);
let mut text = start.clone();
let mut editor = GoSumEditor::new(start.clone());
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/vex/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,8 @@ mod tests {

#[tokio::test]
async fn judge_installed_record_matches_verify_and_evidence_scan() {
use crate::crawlers::oracle_support::{fifo, mkdir, write, Rng};
use crate::crawlers::oracle_support::{fifo, mkdir, write};
use crate::test_rng::Rng;

let patched = compute_git_sha256_from_bytes(b"patched");
let upstream = compute_git_sha256_from_bytes(b"upstream");
Expand Down
Loading