Skip to content

internal: (studio) persist telemetry session ID in URL #32170

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

Merged
merged 17 commits into from
Aug 12, 2025

Conversation

astone123
Copy link
Contributor

Additional details

This PR adds the studio session ID to the URL parameters for studio so that the session ID survives a page refresh. Right now if the user is in studio and they refresh the page, the ID is lost and no telemetry events are sent until a new studio session is opened.

Steps to test

Enable debug logging for cloud studio, open a studio session, verify that telemetry events are successfully sent. Refresh the page and verify that they are still successfully sent. Verify that when you close studio, the session ID gets removed from the URL. Also verify that when you open studio again, a new session ID is generated.

PR Tasks

Copy link

cypress bot commented Aug 6, 2025

cypress    Run #64511

Run Properties:  status check passed Passed #64511  •  git commit 83db37a16d: Merge branch 'develop' into studio-persist-session
Project cypress
Branch Review studio-persist-session
Run status status check passed Passed #64511
Run duration 19m 54s
Commit git commit 83db37a16d: Merge branch 'develop' into studio-persist-session
Committer Adam Stone-Lord
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 13
Tests that did not run due to a developer annotating a test with .skip  Pending 1101
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 26538
View all changes introduced in this branch ↗︎
UI Coverage  44.99%
  Untested elements 187  
  Tested elements 157  
Accessibility  97.71%
  Failed rules  4 critical   8 serious   2 moderate   2 minor
  Failed elements 110  

cursor[bot]

This comment was marked as outdated.

@astone123 astone123 changed the base branch from release/15.0.0 to develop August 11, 2025 15:36
const suiteId = hashParams.get('suiteId')
const visitUrl = hashParams.get('url')
const newTestLineNumber = hashParams.get('newTestLineNumber') ? Number(hashParams.get('newTestLineNumber')) : undefined
const cloudStudioSessionId = hashParams.get('cloudStudioSessionId')
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are already in the context of studio, suggest renaming the url parameter sessionId.

@@ -432,20 +460,12 @@ export const useStudioStore = defineStore('studioRecorder', {
},

_getUrlParams () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does _getUrlParams call getUrlParams? Can we just keep _getUrlParams and update it for the sessionId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the logic from _getUrlParams into that function so that we could also call it here when studio state is initialized to grab the value from the url params https://github.com/cypress-io/cypress/pull/32170/files#diff-89b06d274623cbdd0fb8c318c957b3c3659dacee52c0be410100b1ac83283d09R131-R133

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, I would just remove _getUrlParams then and just use getUrlParams directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest updating the url tests in studio.cy.ts to also test for the sessionId.

Copy link
Contributor

@mschile mschile left a comment

Choose a reason for hiding this comment

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

Added a few comments.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@astone123 astone123 requested a review from mschile August 12, 2025 12:35
@@ -694,7 +694,7 @@ describe('studio functionality', () => {
it('does not remove the studio url parameters when saving test changes', () => {
launchStudio()

cy.location().its('hash').should('contain', 'testId=r3').and('contain', 'studio=')
cy.location().its('hash').should('contain', 'testId=r3').and('contain', 'studio=').and('contain', 'sessionId=')
Copy link

Choose a reason for hiding this comment

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

Bug: URL Assertion Omission in Studio Mode

Multiple cy.location().its('hash') assertions in studio.cy.ts were not updated to include a check for the sessionId URL parameter. When Studio is active, the sessionId parameter should be present in the URL, but these assertions incorrectly omit this check, unlike other similar assertions updated in the same commit.

Additional Locations (2)
Fix in Cursor Fix in Web

@@ -227,6 +250,10 @@ export const useStudioStore = defineStore('studioRecorder', {
this._initialUrl = studio.url
}

if (studio.sessionId) {
this.sessionId = studio.sessionId
}
Copy link

Choose a reason for hiding this comment

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

Bug: Inconsistent URL Parameter Handling

The sessionId is redundantly initialized from URL parameters during store state creation and again in the setup method. This is inconsistent with how other URL parameters (testId, suiteId, newTestLineNumber) are handled, which are only set in the setup method. This redundancy could lead to a programmatically set sessionId being overwritten or cause timing issues.

Fix in Cursor Fix in Web

@astone123 astone123 requested a review from mschile August 12, 2025 17:47
@AtofStryker AtofStryker merged commit 0f4384b into develop Aug 12, 2025
85 of 90 checks passed
@AtofStryker AtofStryker deleted the studio-persist-session branch August 12, 2025 18:35
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.

3 participants