diff --git a/packages/server/lib/cloud/api/studio/post_studio_session.ts b/packages/server/lib/cloud/api/studio/post_studio_session.ts index 0bc754a683..93d89cd5de 100644 --- a/packages/server/lib/cloud/api/studio/post_studio_session.ts +++ b/packages/server/lib/cloud/api/studio/post_studio_session.ts @@ -2,6 +2,7 @@ import { asyncRetry, linearDelay } from '../../../util/async_retry' import { isRetryableError } from '../../network/is_retryable_error' import fetch from 'cross-fetch' import os from 'os' +import { agent } from '@packages/network' const pkg = require('@packages/root') const routes = require('../../routes') as typeof import('../../routes') @@ -15,6 +16,8 @@ const _delay = linearDelay(500) export const postStudioSession = async ({ projectId }: GetStudioSessionOptions) => { return await (asyncRetry(async () => { const response = await fetch(routes.apiRoutes.studioSession(), { + // @ts-expect-error - this is supported + agent, method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/packages/server/test/unit/cloud/api/studio/post_studio_session_spec.ts b/packages/server/test/unit/cloud/api/studio/post_studio_session_spec.ts index 52929ee79c..741ce4639c 100644 --- a/packages/server/test/unit/cloud/api/studio/post_studio_session_spec.ts +++ b/packages/server/test/unit/cloud/api/studio/post_studio_session_spec.ts @@ -1,5 +1,8 @@ import { SystemError } from '../../../../../lib/cloud/network/system_error' import { proxyquire } from '../../../../spec_helper' +import os from 'os' +import { agent } from '@packages/network' +import pkg from '@packages/root' describe('postStudioSession', () => { let postStudioSession: typeof import('@packages/server/lib/cloud/api/studio/post_studio_session').postStudioSession @@ -31,6 +34,21 @@ describe('postStudioSession', () => { studioUrl: 'http://localhost:1234/studio/bundle/abc.tgz', protocolUrl: 'http://localhost:1234/capture-protocol/script/def.js', }) + + expect(crossFetchStub).to.have.been.calledOnce + expect(crossFetchStub).to.have.been.calledWith( + 'http://localhost:1234/studio/session', + { + method: 'POST', + agent, + headers: { + 'Content-Type': 'application/json', + 'x-os-name': os.platform(), + 'x-cypress-version': pkg.version, + }, + body: JSON.stringify({ projectSlug: '12345', studioMountVersion: 1, protocolMountVersion: 2 }), + }, + ) }) it('should throw immediately if the response is not ok', async () => {