fix(mock): do not persist snapshots on close in playback mode by GeoffreyBooth · Pull Request #5359 · nodejs/undici (original) (raw)
SnapshotAgent.close() unconditionally delegated to the recorder's close(), which saves to disk whenever any snapshots are held, regardless of mode. In playback mode, findSnapshot() mutates each matched snapshot's callCount on every match, so closing a playback agent rewrote the snapshot file even though nothing new was recorded. This produced spurious diffs in committed fixtures (and persisted callCount values, which loadSnapshots() does not reset).
Gate persistence at close() — the only mode-aware layer: record and update modes still save via recorder.close(), while playback only cleans up timers via recorder.destroy(). The public saveSnapshots() is left untouched, so explicit saves continue to work in any mode.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com Signed-off-by: Geoffrey Booth webadmin@geoffreybooth.com