Skip to content

internal: only capture anonymous studio started analytics when cloud studio is disabled #31665

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 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions packages/server/lib/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,21 +431,26 @@ export class ProjectBase extends EE {

const studio = await this.ctx.coreData.studioLifecycleManager?.getStudio()

try {
studio?.captureStudioEvent({
type: StudioMetricsTypes.STUDIO_STARTED,
machineId: await this.ctx.coreData.machineId,
projectId: this.cfg.projectId,
browser: this.browser ? {
name: this.browser.name,
family: this.browser.family,
channel: this.browser.channel,
version: this.browser.version,
} : undefined,
cypressVersion: pkg.version,
})
} catch (error) {
debug('Error capturing studio event:', error)
const isCloudStudio = !!(process.env.CYPRESS_ENABLE_CLOUD_STUDIO || process.env.CYPRESS_LOCAL_STUDIO_PATH)

// only capture studio started event if the user is accessing legacy studio
if (!isCloudStudio) {
try {
studio?.captureStudioEvent({
type: StudioMetricsTypes.STUDIO_STARTED,
machineId: await this.ctx.coreData.machineId,
projectId: this.cfg.projectId,
browser: this.browser ? {
name: this.browser.name,
family: this.browser.family,
channel: this.browser.channel,
version: this.browser.version,
} : undefined,
cypressVersion: pkg.version,
})
} catch (error) {
debug('Error capturing studio event:', error)
}
}

if (this.spec && studio?.protocolManager) {
Expand Down
57 changes: 57 additions & 0 deletions packages/server/test/unit/project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,63 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
expect(this.project['_protocolManager']).to.be.undefined
})

it('does not capture studio started event if the user is accessing cloud studio', async function () {
process.env.CYPRESS_ENABLE_CLOUD_STUDIO = 'true'
process.env.CYPRESS_LOCAL_STUDIO_PATH = 'false'

const mockAccessStudioAI = sinon.stub().resolves(true)
const mockCaptureStudioEvent = sinon.stub().resolves()

this.project.spec = {}

this.project._cfg = this.project._cfg || {}
this.project._cfg.projectId = 'test-project-id'
this.project.ctx.coreData.user = { email: 'test@example.com' }
this.project.ctx.coreData.machineId = Promise.resolve('test-machine-id')

const studioManager = new StudioManager()

studioManager.canAccessStudioAI = mockAccessStudioAI
studioManager.captureStudioEvent = mockCaptureStudioEvent
const studioLifecycleManager = new StudioLifecycleManager()

this.project.ctx.coreData.studioLifecycleManager = studioLifecycleManager

studioLifecycleManager.studioManagerPromise = Promise.resolve(studioManager)

studioLifecycleManager.isStudioReady = sinon.stub().returns(true)

// Create a browser object
this.project.browser = {
name: 'chrome',
family: 'chromium',
}

this.project.options = { browsers: [this.project.browser] }

sinon.stub(browsers, 'closeProtocolConnection').resolves()

sinon.stub(browsers, 'connectProtocolToBrowser').resolves()
sinon.stub(this.project, 'protocolManager').get(() => {
return this.project['_protocolManager']
}).set((protocolManager) => {
this.project['_protocolManager'] = protocolManager
})

let studioInitPromise

this.project.server.startWebsockets.callsFake(async (automation, config, callbacks) => {
studioInitPromise = callbacks.onStudioInit()
})

this.project.startWebsockets({}, {})

const { canAccessStudioAI } = await studioInitPromise

expect(canAccessStudioAI).to.be.false
expect(mockCaptureStudioEvent).not.to.be.called
})

it('passes onStudioDestroy callback', async function () {
// Set up minimal required properties
this.project.ctx = this.project.ctx || {}
Expand Down
Loading