Skip to content

sequence.seed does not reproduce shuffled file order #11340

Closed

Description

@zeevox

Describe the bug

With sequence.shuffle.files enabled, the same seed gives different file orders between runs, even with one worker.

I use file shuffling to find tests that depend on another test's state. I expected the seed to let me reproduce the order after a failure.

Minimal reproduction uses 32 trivial tests across 16 directories, with this config:

export default {
  test: {
    include: ['cases/**/*.test.js'],
    maxWorkers: 1,
    isolate: false,
    sequence: {
      shuffle: { files: true },
      seed: 1,
    },
    reporters: ['./order-reporter.mjs'],
  },
}

The reporter prints each file from onTestModuleStart. The first four files from two consecutive runs:

Run 1                 Run 2
d3/f1.test.js          d3/f1.test.js
d12/f0.test.js         d11/f0.test.js
d12/f1.test.js         d11/f1.test.js
d7/f1.test.js          d7/f1.test.js

Ten runs gave ten different orders. The files, config and seed were unchanged.

This appears to come from RandomSequencer.sort, which passes the glob results straight to shuffle(files, sequence.seed). The glob result order can vary, so the seed alone does not determine the final order.

I tried sorting the files by module ID before the shuffle. All ten runs then produced the same order.

Reproduction

https://github.com/zeevox/vitest-shuffle-seed-repro

git clone https://github.com/zeevox/vitest-shuffle-seed-repro.git
cd vitest-shuffle-seed-repro
bun install --frozen-lockfile
bun run reproduce

This runs the same tests ten times with seed 1 and prints each file order. All tests pass. The expected result is one distinct order.

The result depends on filesystem timing. Repeat the command if the order stays the same.

System Info

System:
    OS: macOS 27.2
    CPU: (15) arm64 Apple M5 Pro
    Memory: 13.17 GB / 48.00 GB
    Shell: 5.3.20 - /opt/homebrew/bin/bash
  Binaries:
    Node: 24.21.0 - ~/.local/share/mise/installs/node/24/bin/node
    Yarn: 1.22.22 - ~/.local/share/mise/installs/node/24/bin/yarn
    npm: 12.1.0 - ~/.local/share/mise/installs/node/24/bin/npm
    pnpm: 12.3.4 - ~/.local/share/mise/installs/node/24/bin/pnpm
    bun: 1.4.2 - ~/.local/share/mise/shims/bun
    Deno: 2.9.7 - /opt/homebrew/bin/deno
  Browsers:
    Chrome: 154.0.8037.58
    Firefox: 156.0.1
    Safari: 27.2
  npmPackages:
    vitest: 5.0.1 => 5.0.1

Vite 8.3.0 (from the lockfile). Vitest runs under Node.js; Bun installs dependencies and invokes the scripts.

Used Package Manager

bun

Validations

Activity

  1. added
    p3-minor-bug
    on Sep 24, 2026
  2. added theissue type on Sep 24, 2026
  3. pavstev commented on Nov 3, 2026

    @pavstev

    I reproduced this on main (v5.1.0) with 32 files in 16 directories, maxWorkers: 1, isolate: false and seed: 1: ten runs gave nine different file orders. The fix I tested sorts a copy of the specs by project name, moduleId and pool in RandomSequencer.sort before shuffle; with it, 20 runs gave one order, and so did ten runs with two projects and six runs with --shard=1/2. Two new unit tests in test/unit/test/sequencers.test.ts fail on main and pass with the fix, and the full unit suite plus the shard, cache and group-order e2e tests still pass. The one side effect is that a given seed now gives a different order than in older versions, so the fixed-seed expectation in that file changes. @sheremet-va, you reviewed this approach in #11350, would you add the approved label so I can open the PR?

  4. locked and limited conversation to collaborators on Nov 25, 2026
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

    p3-minor-bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions