-
Notifications
You must be signed in to change notification settings - Fork 237
feat(replay): account for V2 trigger groups #3281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ksvat
wants to merge
1
commit into
main
Choose a base branch
from
account-for-new-trigger-groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,909
−194
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'posthog-js': minor | ||
| --- | ||
|
|
||
| Add session replay trigger groups handling (V2) |
400 changes: 400 additions & 0 deletions
400
packages/browser/src/__tests__/extensions/replay/lazy-sessionrecording.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
284 changes: 284 additions & 0 deletions
284
packages/browser/src/__tests__/extensions/replay/triggerGroups-v1-compat.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,284 @@ | ||
| /** | ||
| * V1 Backward Compatibility Tests | ||
| * | ||
| * These tests ensure that existing V1 trigger configurations continue to work | ||
| * exactly as before when V2 trigger groups are not configured. | ||
| */ | ||
|
|
||
| import { | ||
| ACTIVE, | ||
| allMatchSessionRecordingStatus, | ||
| anyMatchSessionRecordingStatus, | ||
| BUFFERING, | ||
| DISABLED, | ||
| EventTriggerMatching, | ||
| LinkedFlagMatching, | ||
| RecordingTriggersStatus, | ||
| SAMPLED, | ||
| TRIGGER_ACTIVATED, | ||
| TRIGGER_DISABLED, | ||
| TRIGGER_PENDING, | ||
| URLTriggerMatching, | ||
| } from '../../../extensions/replay/external/triggerMatching' | ||
|
|
||
| describe('V1 Backward Compatibility', () => { | ||
| const defaultTriggersStatus: RecordingTriggersStatus = { | ||
| receivedFlags: true, | ||
| isRecordingEnabled: true, | ||
| isSampled: null, | ||
| rrwebError: false, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_DISABLED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_DISABLED, | ||
| } as unknown as EventTriggerMatching, | ||
| linkedFlagMatching: { | ||
| triggerStatus: () => TRIGGER_DISABLED, | ||
| } as unknown as LinkedFlagMatching, | ||
| sessionId: 'test-session', | ||
| } | ||
|
|
||
| describe('anyMatchSessionRecordingStatus (V1)', () => { | ||
| it('should return SAMPLED when isSampled is true', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: true, | ||
| }) | ||
| expect(status).toBe(SAMPLED) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when event trigger activated', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when URL trigger activated', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| }) | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when linked flag activated', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| linkedFlagMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as LinkedFlagMatching, | ||
| }) | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should return BUFFERING when any trigger is pending', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_PENDING, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| expect(status).toBe(BUFFERING) | ||
| }) | ||
|
|
||
| it('should return DISABLED when isSampled is false and no triggers', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: false, | ||
| }) | ||
| expect(status).toBe(DISABLED) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when no sampling configured and no triggers', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: null, | ||
| }) | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
| }) | ||
|
|
||
| describe('allMatchSessionRecordingStatus (V1)', () => { | ||
| it('should return SAMPLED when isSampled is true', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: true, | ||
| }) | ||
| expect(status).toBe(SAMPLED) | ||
| }) | ||
|
|
||
| it('should return BUFFERING when any trigger is pending', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_PENDING, | ||
| } as unknown as EventTriggerMatching, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| }) | ||
| expect(status).toBe(BUFFERING) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when triggers have mixed states with some disabled', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_DISABLED, | ||
| } as unknown as EventTriggerMatching, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| linkedFlagMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as LinkedFlagMatching, | ||
| }) | ||
| // With ALL match, if no triggers configured (DISABLED removed from set), should be ACTIVE | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when all triggers activated', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| linkedFlagMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as LinkedFlagMatching, | ||
| }) | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should return DISABLED when isSampled is false', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: false, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| expect(status).toBe(DISABLED) | ||
| }) | ||
| }) | ||
|
|
||
| describe('V1 Trigger Matching Behavior', () => { | ||
| it('should handle event + sampling with ANY match', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: true, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| // Sampling takes precedence | ||
| expect(status).toBe(SAMPLED) | ||
| }) | ||
|
|
||
| it('should handle event + sampling with ALL match', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: true, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| expect(status).toBe(SAMPLED) | ||
| }) | ||
|
|
||
| it('should handle URL + event with ANY match', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_DISABLED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| // ANY means if URL is activated, should be ACTIVE | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should handle URL + event with ALL match', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_DISABLED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| // ALL means if no triggers are configured (all DISABLED), should be ACTIVE by default | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
| }) | ||
|
|
||
| describe('V1 Edge Cases', () => { | ||
| it('should handle null isSampled with no triggers', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: null, | ||
| }) | ||
| // Should default to ACTIVE | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should handle undefined isSampled with triggers pending', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: undefined, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_PENDING, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| // Should be BUFFERING because trigger is pending | ||
| expect(status).toBe(BUFFERING) | ||
| }) | ||
|
|
||
| it('should return ACTIVE when trigger activated even if sampling false (ANY)', () => { | ||
| const status = anyMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: false, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| }) | ||
| // With ANY match, activated trigger takes precedence - sampling false is only checked at the end | ||
| expect(status).toBe(ACTIVE) | ||
| }) | ||
|
|
||
| it('should prioritize sampling false over activated triggers (ALL)', () => { | ||
| const status = allMatchSessionRecordingStatus({ | ||
| ...defaultTriggersStatus, | ||
| isSampled: false, | ||
| eventTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| } as unknown as EventTriggerMatching, | ||
| urlTriggerMatching: { | ||
| triggerStatus: () => TRIGGER_ACTIVATED, | ||
| urlBlocked: false, | ||
| } as unknown as URLTriggerMatching, | ||
| }) | ||
| expect(status).toBe(DISABLED) | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.