internal: (studio) add network agent to the studio session call (#31617)

* internal: (studio) add network agent to the studio session call

* Update packages/server/lib/cloud/api/studio/post_studio_session.ts

Co-authored-by: Matt Schile <mschile@cypress.io>

---------

Co-authored-by: Matt Schile <mschile@cypress.io>
This commit is contained in:
Ryan Manuel
2025-04-30 21:25:34 -05:00
committed by GitHub
parent 602ff2aa77
commit ad353fcc0f
2 changed files with 21 additions and 0 deletions

View File

@@ -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',

View File

@@ -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 () => {