Skip to content

feat(experimental): seed repeats and add --replay-seed - #11940

Draft
sheremet-va wants to merge 1 commit into
feat/fake-randomfrom
feat/repeat-seeds
Draft

sheremet-va wants to merge 1 commit into
feat/fake-randomfrom
feat/repeat-seeds

Conversation

@sheremet-va

@sheremet-va sheremet-va commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Stacked on #11933. Contains the commit of #11955 until it merges.

Each repeat of a test gets its own seed for context.random and vi.useFakeRandom, so repeats searches for the values that make a test fail. When a repeat fails, Vitest runs its seed 1 more time to check that the failure reproduces, and prints the seed with a command that replays it.

  • --replay-seed <seed> runs the selected tests 1 time with this seed.
  • The seeds test option runs known seeds before the repeats. Each seed adds 1 run, so the repeats of a tag or of --repeats still apply.
  • Seeds that fail at the same place share 1 error block and 1 replay command.
  • Annotations have the retryIndex and repeatIndex of their attempt.
  • The replay command has the --seed of the run and drops --reporter, --outputFile, --ui, --open, --api, --coverage and --update.
  • In a merged report, the replay command has the flags and the seed of the blob that tested the file.
  • New guide: Seeded Tests.
import { expect, test } from 'vitest'

test('one leader per term', { repeats: 199 }, async ({ random }) => {
  const network = new SimulatedNetwork(random.fork('network'))
  const cluster = new Cluster({ nodes: 5, network })

  await cluster.run({ steps: 1_000 })

  expect(cluster.leadersPerTerm()).toBe(1)
})
 FAIL  src/raft.test.ts > one leader per term
AssertionError: expected 2 to be 1 // Object.is equality
 ❯ src/raft.test.ts:9:36

     Failed  136th repeat
       Seed  3fa2c9e1b07d5a44
 Reproduced  2 of 2 runs
     Replay  vitest run src/raft.test.ts -t '^one leader per term$' --seed 158412337095872 --replay-seed 3fa2c9e1b07d5a44
image

@sheremet-va
sheremet-va added this pull request to stack #11934 November 11, 2026 14:16
@netlify

netlify Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit db37ec4
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6b06bb648e54fa31dd835f2a
😎 Deploy Preview https://deploy-preview-11940--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@flakiness-io

flakiness-io Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Test Results Summary

This comment shows the latest test results for this pull request.

Commit Status Test Results CI Runs
db37ec4 ✅ Passed 33279 passed · 239 flaky · 1197 skipped 30 runs
⚠️ 239 flaky

⚠️ Ubuntu 26.04 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 26.04 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 26.04 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 26.04 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 26.04 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 26.04 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 26.04 · vmThreads test/unit/test/retry.test.ts:61 › describe object add(1, 1) › returned value not be less than 2
…and 229 more

View full report

ℹ️ About Flakiness.io in GitHub

Your team has set up Flakiness.io pull request comments. This comment is updated when

  • The first test results arrive for this pull request
  • A later run reports more results for the same commit
  • A new commit is pushed and tested

Flakiness.io rewrites the comment in place, so it always reflects the most recently tested commit.

Comment thread docs/api/test.md Outdated
### repeats

- **Type:** `number`
- **Type:** `number | { count?: number; include?: string[] }`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeats.include feels like weird API to control the used seeds. Maybe it should contain the word seed at least. Right now it looks like test.include. 🤷

@sheremet-va sheremet-va Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, and there is also value in rerunning the same seed multiple times. Maybe we need a new option:

new seed
  repeat x10
    retry x2

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to seeds:

import { test } from 'vitest'

test('one leader per term', { repeats: 199, seeds: ['3fa2c9e1b07d5a44'] }, async ({ random }) => {
  // ...
})

"repeats" still try different seeds each time

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also working on examples to use instead of seeds which is more useful in a controlled environment:

import { test } from 'vitest'

test('the queue keeps every job', {
  repeats: 99,
  examples: [{ jobs: [501] }],
}, ({ random }) => {
  const jobs = random.many('jobs', () => random.int(0, 1000))
  // ...
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add test case where we have test('...', { repeats: { include: ['0123456789abcdef'] }..., and defineConfig({ test: { repeats: 10 } }) or pass --repeats 10 via CLI. Does the test case now run twice, 10 or 11 times?

@sheremet-va sheremet-va Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it, but it should run 12 times right now. repeats makes it so the test runs repeats + 1 time (the initial run + repeats) always, and include adds an additional repeat

@AriPerkkio AriPerkkio Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 or 12 sounds correct to me. By looking at the code I wasn't sure if defining inline repeats here in test() would accidentally override the --repeats=10 / test.repeats: 10 from root too.

@sheremet-va
sheremet-va marked this pull request as draft November 18, 2026 13:58
@sheremet-va
sheremet-va force-pushed the feat/repeat-seeds branch 2 times, most recently from 1c1ee7a to 3bbe4ff Compare November 18, 2026 20:08

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants