Skip to content

fix: reset the snapshot counter between flaky retries - #1872

Closed
lazerg wants to merge 2 commits into
pestphp:5.xfrom
lazerg:fix/issue-1871-flaky-snapshot-counter
Closed

fix: reset the snapshot counter between flaky retries#1872
lazerg wants to merge 2 commits into
pestphp:5.xfrom
lazerg:fix/issue-1871-flaky-snapshot-counter

Conversation

@lazerg

@lazerg lazerg commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description:

SnapshotRepository::$expectationsCounter is static and keyed by test file plus description, so several toMatchSnapshot() calls in one test resolve to .snap, __2.snap, and so on. Testable::__runTest() replays the closure in the same process on a flaky retry and never clears that key, so attempt 2 looks for __2.snap. It does not exist, gets created from the current value, and the test ends as incomplete on a green suite. Every run after that passes, because attempt 1 still fails against the real baseline and attempt 2 matches the file the first run wrote. On CI the run fails, but it names a __3.snap nobody created instead of the value that actually drifted.

The retry already restores object properties, mock objects and the output buffer before running again. The counter belongs to that cleanup, so it is reset there too, and the retried attempt resolves the same snapshot file as the first one.

Related:

Fixes #1871

@MrPunyapal

Copy link
Copy Markdown
Collaborator

Thanks! Already covered by b8c2265

@MrPunyapal MrPunyapal closed this Aug 25, 2026
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.

[Bug]: flaky() retries increment the snapshot counter, so a mismatching snapshot silently self-heals

2 participants