fix(01-review): sweep #1 stopRecording nulls mediaStream first to prevent rotation race

This commit is contained in:
2026-05-16 10:52:59 +02:00
parent a6e2d09de8
commit 08a79a61ac
2 changed files with 46 additions and 3 deletions

View File

@@ -111,6 +111,25 @@ describe('segment rotation (D-13 restart-segments)', () => {
expect(getSegments()).toEqual([]);
});
it('resetBuffer preserves segments do NOT survive (sweep #1 stop-race adjacent)', () => {
// Sweep #1 documented that stopRecording() previously raced
// onSegmentStopped: the timer was cleared but onSegmentStopped's
// mediaStream != null branch would still spawn a new segment. The
// fix nulls mediaStream FIRST. resetBuffer is the orthogonal
// mechanism for clearing the buffer (used by onUserStoppedSharing
// AND between tests). This test pins the contract that resetBuffer
// never leaves a partial segment behind.
pushSegmentForTest(makeSegmentBlob(0xa));
pushSegmentForTest(makeSegmentBlob(0xb));
pushSegmentForTest(makeSegmentBlob(0xc));
expect(getSegments()).toHaveLength(MAX_SEGMENTS);
resetBuffer();
expect(getSegments()).toHaveLength(0);
// Subsequent pushes start from an empty buffer — no eviction needed.
pushSegmentForTest(makeSegmentBlob(0xd));
expect(getSegments()).toHaveLength(1);
});
it('getSegments returns a snapshot — mutating the result does not corrupt internal state', () => {
pushSegmentForTest(makeSegmentBlob(0x1));
pushSegmentForTest(makeSegmentBlob(0x2));