Skip to content
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
7 changes: 7 additions & 0 deletions packages/data-context/src/DataActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CohortsActions,
CodegenActions,
CloudProjectActions,
CurrentRecordingActions,
} from './actions'
import { ErrorActions } from './actions/ErrorActions'
import { EventCollectorActions } from './actions/EventCollectorActions'
Expand All @@ -39,6 +40,7 @@ export class DataActions {
private _codegen: CodegenActions
private _notification: NotificationActions
private _cloudProject: CloudProjectActions
private _currentRecording: CurrentRecordingActions

constructor (private ctx: DataContext) {
this._error = new ErrorActions(this.ctx)
Expand All @@ -59,6 +61,7 @@ export class DataActions {
this._codegen = new CodegenActions(this.ctx)
this._notification = new NotificationActions(this.ctx)
this._cloudProject = new CloudProjectActions(this.ctx)
this._currentRecording = new CurrentRecordingActions(this.ctx)
}

get error () {
Expand Down Expand Up @@ -132,4 +135,8 @@ export class DataActions {
get cloudProject () {
return this._cloudProject
}

get currentRecording () {
return this._currentRecording
}
}
17 changes: 17 additions & 0 deletions packages/data-context/src/actions/CurrentRecordingActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { DataContext } from '..'

export class CurrentRecordingActions {
constructor (private ctx: DataContext) {}

startRun (runId: string) {
this.ctx.update((d) => {
d.currentRecordingInfo.runId = runId
})
}

startInstance (instanceId: string) {
this.ctx.update((d) => {
d.currentRecordingInfo.instanceId = instanceId
})
}
}
1 change: 1 addition & 0 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class ProjectActions {
d.scaffoldedFiles = null
d.app.browserStatus = 'closed'
d.app.browserUserAgent = null
d.currentRecordingInfo = {}
})

// Also clear any data associated with the linked cloud project
Expand Down
1 change: 1 addition & 0 deletions packages/data-context/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './BrowserActions'
export * from './CloudProjectActions'
export * from './CodegenActions'
export * from './CohortsActions'
export * from './CurrentRecordingActions'
export * from './DataEmitterActions'
export * from './DevActions'
export * from './ElectronActions'
Expand Down
7 changes: 7 additions & 0 deletions packages/data-context/src/data/coreDataShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ interface CloudDataShape {
}
}

interface RecordingInfo {
runId?: string
instanceId?: string
}

export interface CoreDataShape {
cliBrowser: string | null
cliTestingType: string | null
Expand Down Expand Up @@ -166,6 +171,7 @@ export interface CoreDataShape {
didBrowserPreviouslyHaveUnexpectedExit: boolean
studioLifecycleManager?: StudioLifecycleManagerShape
cyPromptLifecycleManager?: CyPromptLifecycleManagerShape
currentRecordingInfo: RecordingInfo
}

/**
Expand Down Expand Up @@ -248,6 +254,7 @@ export function makeCoreData (modeOptions: Partial<AllModeOptions> = {}): CoreDa
eventCollectorSource: null,
didBrowserPreviouslyHaveUnexpectedExit: false,
studioLifecycleManager: undefined,
currentRecordingInfo: {},
}

async function machineId (): Promise<string | null> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createTestDataContext } from '../helper'
import type { DataContext } from '../../../src'
import { expect } from 'chai'

describe('CurrentRecordingActions', () => {
let ctx: DataContext

beforeEach(() => {
ctx = createTestDataContext('open')
})

describe('startRun', () => {
it('updates the current run id', () => {
ctx.actions.currentRecording.startRun('12345')

expect(ctx.coreData.currentRecordingInfo.runId).to.equal('12345')
})
})

describe('startInstance', () => {
it('updates the current instance id', () => {
ctx.actions.currentRecording.startInstance('12345')

expect(ctx.coreData.currentRecordingInfo.instanceId).to.equal('12345')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ReportCyPromptErrorOptions {
error: unknown
cyPromptMethod: string
cyPromptMethodArgs?: unknown[]
additionalHeaders?: Record<string, string>
}

interface CyPromptError {
Expand All @@ -33,6 +34,7 @@ export function reportCyPromptError ({
error,
cyPromptMethod,
cyPromptMethodArgs,
additionalHeaders,
}: ReportCyPromptErrorOptions): void {
debug('Error reported:', error)

Expand Down Expand Up @@ -87,7 +89,7 @@ export function reportCyPromptError ({
{
headers: {
'Content-Type': 'application/json',
...cloudApi.cloudHeaders,
...additionalHeaders,
},
},
).catch((e: unknown) => {
Expand Down
21 changes: 13 additions & 8 deletions packages/server/lib/cloud/cy-prompt/CyPromptLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { readFile } from 'fs-extra'
import { ensureCyPromptBundle } from './ensure_cy_prompt_bundle'
import chokidar from 'chokidar'
import { getCloudMetadata } from '../get_cloud_metadata'
import type { CyPromptAuthenticatedUserShape } from '@packages/types'
import type { CyPromptAuthenticatedUserShape, CyPromptServerOptions } from '@packages/types'
import crypto from 'crypto'
import { reportCyPromptError } from '../api/cy-prompt/report_cy-prompt_error'

Expand Down Expand Up @@ -52,13 +52,23 @@ export class CyPromptLifecycleManager {
data.cyPromptLifecycleManager = this
})

const recordingInfo = {
get runId () {
return ctx.coreData.currentRecordingInfo.runId
},
get instanceId () {
return ctx.coreData.currentRecordingInfo.instanceId
},
}

const getProjectOptions = async () => {
return {
user: await ctx.actions.auth.authApi.getUser(),
projectSlug: (await ctx.project.getConfig()).projectId || undefined,
record,
key,
isOpenMode: ctx.isOpenMode,
...(record ? { recordingInfo } : {}),
}
}

Expand All @@ -75,12 +85,12 @@ export class CyPromptLifecycleManager {
reportCyPromptError({
cloudApi: {
cloudUrl,
cloudHeaders,
CloudRequest,
createCloudRequest,
isRetryableError,
asyncRetry,
},
additionalHeaders: cloudHeaders,
cyPromptHash: this.cyPromptHash,
projectSlug: (await ctx.project.getConfig()).projectId || undefined,
error,
Expand Down Expand Up @@ -118,12 +128,7 @@ export class CyPromptLifecycleManager {
}: {
projectId?: string
cloudDataSource: CloudDataSource
getProjectOptions: () => Promise<{
user?: CyPromptAuthenticatedUserShape
projectSlug?: string
record?: boolean
key?: string
}>
getProjectOptions: CyPromptServerOptions['getProjectOptions']
}): Promise<{ cyPromptManager?: CyPromptManager, error?: Error }> {
let cyPromptPath: string
let manifest: Record<string, string>
Expand Down
9 changes: 2 additions & 7 deletions packages/server/lib/cloud/cy-prompt/CyPromptManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CyPromptManagerShape, CyPromptStatus, CyPromptServerDefaultShape, CyPromptServerShape, CyPromptCloudApi, CyPromptCDPClient, CyPromptAuthenticatedUserShape, CyPromptAddSocketListenerOptions } from '@packages/types'
import type { CyPromptManagerShape, CyPromptStatus, CyPromptServerDefaultShape, CyPromptServerShape, CyPromptCloudApi, CyPromptCDPClient, CyPromptAddSocketListenerOptions, CyPromptServerOptions } from '@packages/types'
import type { Router } from 'express'
import Debug from 'debug'
import { requireScript } from '../require_script'
Expand All @@ -12,12 +12,7 @@ interface SetupOptions {
cyPromptHash?: string
projectSlug?: string
cloudApi: CyPromptCloudApi
getProjectOptions: () => Promise<{
user?: CyPromptAuthenticatedUserShape
projectSlug?: string
record?: boolean
key?: string
}>
getProjectOptions: CyPromptServerOptions['getProjectOptions']
manifest: Record<string, string>
}

Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/modes/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ const createRunAndRecordSpecs = (options: any = {}) => {
testingType,
quiet,
autoCancelAfterFailures,
ctx,
} = options
const recordKey = options.key

Expand Down Expand Up @@ -621,6 +622,8 @@ const createRunAndRecordSpecs = (options: any = {}) => {
})
}

ctx.actions.currentRecording.startRun(resp.runId)

const { runUrl, runId, machineId, groupId } = resp
const protocolCaptureMeta = resp.capture || {}

Expand All @@ -645,6 +648,7 @@ const createRunAndRecordSpecs = (options: any = {}) => {
})
.then((resp: any = {}) => {
instanceId = resp.instanceId
ctx.actions.currentRecording.startInstance(instanceId)

// pull off only what we need
const result = _
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/modes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,6 @@ async function ready (options: ReadyOptions) {
trashAssets(config),
])

// @ts-expect-error ctx is protected
const specs = project.ctx.project.specs

if (!specs.length) {
Expand Down Expand Up @@ -1202,6 +1201,7 @@ async function ready (options: ReadyOptions) {
runAllSpecs,
onError,
quiet: options.quiet,
ctx: project.ctx,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type StartWebsocketOptions = Pick<Cfg, 'socketIoCookie' | 'namespace' | 'screens
export class ProjectBase extends EE {
// id is sha256 of projectRoot
public id: string
public ctx: DataContext

protected ctx: DataContext
protected _cfg?: Cfg
protected _server?: ServerBase<any>
protected _automation?: Automation
Expand Down
Loading
Loading