Skip to content

Use crate::test_rng::Rng in every randomized test: three more xorshift64* copies sit beside the module that claims to be the only one #1868

Closed

Description

[agent] Filed by the scheduled architecture audit (audit-core). Register: register.

Kind: refactor (test-only). Register ID: A29.

Problem

test_rng.rs calls itself "the one deterministic RNG the randomized tests share". There are three more copies of the same xorshift64* generator:

  • crawlers/oracle_support.rs L10-L38:`` pub(crate) struct Rng, with the same `new`/`next`/`below`/`pick` and a `chance(pct: usize)` spelled `below(100) < pct`. `test_rng` spells it `next() % 100 < percent` with a `u64` argument.
  • patch/copy_tree.rs L237-L251: a private struct Rng(u64) with next and below.
  • crawlers/npm_crawler/oracle.rs L1056-L1068:``` next/`below` inlined into a fixture builder.

All four produce the same stream for the same state (the same shifts and multiplier), so a single type serves every caller.

Proposed change

  • Delete the three copies. Use crate::test_rng::Rng in the crawler oracle tests, copy_tree's randomized test and the npm oracle builder.
  • Keep test_rng's chance(u64) and change the crawler callers' argument type.
  • Seeds stay the same, so every generated case is unchanged.

Size

4 files, about −50 lines, all #[cfg(test)].

Acceptance criteria

  • No production change.
  • Every randomized test in crawlers/* (the *_matches_the_async_oracle tests), patch::copy_tree and npm_crawler passes with the same seeds and the same case counts.
  • grep -rn "0x2545_F491_4F6C_DD1D" crates/socket-patch-core/src returns one hit, in test_rng.rs.

Not in scope (noted in the register)

The eight crawlers/**/oracle.rs files, 2,978 lines with oracle_support.rs, keep the pre-blocking-pool crawlers as equivalence oracles. cargo_crawler/oracle.rs already differs from production: it reads with tokio::fs::read_to_string, which follows FIFOs and links, while production uses read_regular_to_string_sync. Whether to delete these oracles is a separate question.

Activity

  1. added
    arch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)
    refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code
    on Oct 30, 2026
  2. mikolalysenko commented on Oct 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue (CI / test-harness lane; root cause: randomized tests re-implement xorshift64* instead of using crate::test_rng::Rng). Branch: agent/fix-ci-test-rng-dedup. Claim-ID: 2026-10-30T03:51:12Z-ec26d9

    Note: on 5ca5623 there are two more copies in core beyond the three listed, as inline closures in vendor/go_sum_edit.rs and vendor/go_mod_edit.rs. I'll fold those in too.


    Generated by Claude Code

  3. mikolalysenko commented on Oct 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Draft PR: #1882


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)priority:p3refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions