diff --git a/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts b/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts index dd04253b4ea8..ea38d1f3760b 100644 --- a/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts +++ b/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts @@ -11,7 +11,18 @@ import type { CloudRunStatus } from '@packages/graphql/src/gen/cloud-source-type const debug = debugLib('cypress:data-context:sources:RelevantRunSpecsDataSource') const RELEVANT_RUN_SPEC_OPERATION_DOC = gql` - query RelevantRunsDataSource_latestRunUpdateSpecData( + fragment RelevantRunSpecsDataSource_Runs on CloudRun { + id + runNumber + status + specs { + id + status + groupIds + } + } + + query RelevantRunSpecsDataSource_Specs( $projectSlug: String! $currentRunNumber: Int! $hasCurrent: Boolean! @@ -24,21 +35,11 @@ const RELEVANT_RUN_SPEC_OPERATION_DOC = gql` id current: runByNumber(runNumber: $currentRunNumber) @include(if: $hasCurrent) { id - runNumber - status - specs { - id - status - } + ...RelevantRunSpecsDataSource_Runs } next: runByNumber(runNumber: $nextRunNumber) @include(if: $hasNext) { id - runNumber - status - specs { - id - status - } + ...RelevantRunSpecsDataSource_Runs } } } @@ -56,7 +57,7 @@ export const SPECS_EMPTY_RETURN: RunSpecReturn = { const INCOMPLETE_STATUSES: CloudSpecStatus[] = ['RUNNING', 'UNCLAIMED'] -type RunSpecReturn = { +export type RunSpecReturn = { runSpecs: CurrentProjectRelevantRunSpecs statuses: { current?: CloudRunStatus @@ -64,6 +65,9 @@ type RunSpecReturn = { } } +//Not ideal typing for this return since the query is not fetching all the fields, but better than nothing +export type RelevantRunSpecsCloudResult = { cloudProjectBySlug: { __typename?: string, current?: Partial, next?: Partial } } & Pick + /** * DataSource to encapsulate querying Cypress Cloud for runs that match a list of local Git commit shas */ @@ -83,9 +87,14 @@ export class RelevantRunSpecsDataSource { } #calculateSpecMetadata (specs: CloudSpecRun[]) { + //mimic logic in Cloud to sum up the count of groups per spec to give the total spec counts + const countGroupsForSpec = (specs: CloudSpecRun[]) => { + return specs.map((spec) => spec.groupIds?.length || 0).reduce((acc, curr) => acc += curr, 0) + } + return { - totalSpecs: specs.length, - completedSpecs: specs.map((spec) => spec.status || 'UNCLAIMED').filter((status) => !INCOMPLETE_STATUSES.includes(status)).length, + totalSpecs: countGroupsForSpec(specs), + completedSpecs: countGroupsForSpec(specs.filter((spec) => !INCOMPLETE_STATUSES.includes(spec.status || 'UNCLAIMED'))), } } @@ -106,10 +115,7 @@ export class RelevantRunSpecsDataSource { debug(`Fetching specs for ${projectSlug} and %o`, runs) - //Not ideal typing for this return since the query is not fetching all the fields, but better than nothing - type CloudResult = { cloudProjectBySlug: { __typename: string, current?: CloudRun, next?: CloudRun } } & Pick - - const result = await this.ctx.cloud.executeRemoteGraphQL({ + const result = await this.ctx.cloud.executeRemoteGraphQL({ fieldName: 'cloudProjectBySlug', operationDoc: RELEVANT_RUN_SPEC_OPERATION_DOC, operation: RELEVANT_RUN_SPEC_UPDATE_OPERATION, diff --git a/packages/data-context/src/sources/RelevantRunsDataSource.ts b/packages/data-context/src/sources/RelevantRunsDataSource.ts index edd7504235b9..6c2277869027 100644 --- a/packages/data-context/src/sources/RelevantRunsDataSource.ts +++ b/packages/data-context/src/sources/RelevantRunsDataSource.ts @@ -10,7 +10,7 @@ import { Poller } from '../polling' const debug = debugLib('cypress:data-context:sources:RelevantRunsDataSource') const RELEVANT_RUN_OPERATION_DOC = gql` - query RelevantRunsDataSource_latestRunUpdateSpecData( + query RelevantRunsDataSource_RunsByCommitShas( $projectSlug: String! $shas: [String!]! ) {