From 998857c526e5ab9f08487900b266a07ecc93cd8a Mon Sep 17 00:00:00 2001 From: Stokes Player Date: Thu, 19 Jan 2023 09:06:10 -0500 Subject: [PATCH 1/3] bug: update query names for better logging --- .../src/sources/RelevantRunSpecsDataSource.ts | 46 +++++++++++-------- .../src/sources/RelevantRunsDataSource.ts | 2 +- 2 files changed, 27 insertions(+), 21 deletions(-) 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!]! ) { From c8848e8cc841479f82a9b47c0e6964019ba9f5c0 Mon Sep 17 00:00:00 2001 From: Stokes Player Date: Thu, 19 Jan 2023 10:05:38 -0500 Subject: [PATCH 2/3] Fixing completed count to use group status --- .../src/sources/RelevantRunSpecsDataSource.ts | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts b/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts index ea38d1f3760b..d57aa005e0be 100644 --- a/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts +++ b/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts @@ -4,7 +4,7 @@ import debugLib from 'debug' import { isEqual } from 'lodash' import type { DataContext } from '../DataContext' -import type { CloudSpecStatus, Query, RelevantRun, CurrentProjectRelevantRunSpecs, CloudSpecRun, CloudRun } from '../gen/graphcache-config.gen' +import type { CloudSpecStatus, Query, RelevantRun, CurrentProjectRelevantRunSpecs, CloudSpecRun, CloudRun, CloudRunGroup, CloudRunGroupStatusEnum } from '../gen/graphcache-config.gen' import { Poller } from '../polling' import type { CloudRunStatus } from '@packages/graphql/src/gen/cloud-source-types.gen' @@ -20,6 +20,10 @@ const RELEVANT_RUN_SPEC_OPERATION_DOC = gql` status groupIds } + groups { + id + status + } } query RelevantRunSpecsDataSource_Specs( @@ -86,15 +90,26 @@ export class RelevantRunSpecsDataSource { return this.#cached.runSpecs } - #calculateSpecMetadata (specs: CloudSpecRun[]) { + #calculateSpecMetadata (specs: CloudSpecRun[], groups: CloudRunGroup[]) { //mimic logic in Cloud to sum up the count of groups per spec to give the total spec counts - const countGroupsForSpec = (specs: CloudSpecRun[]) => { + const countGroupsForSpecs = (specs: CloudSpecRun[]) => { return specs.map((spec) => spec.groupIds?.length || 0).reduce((acc, curr) => acc += curr, 0) } + const groupStatusById = groups.reduce>((acc, curr) => { + acc[curr.id] = curr.status + + return acc + }, {}) + return { - totalSpecs: countGroupsForSpec(specs), - completedSpecs: countGroupsForSpec(specs.filter((spec) => !INCOMPLETE_STATUSES.includes(spec.status || 'UNCLAIMED'))), + totalSpecs: countGroupsForSpecs(specs), + completedSpecs: + specs.flatMap((spec) => spec.groupIds) // pull out the group ids + .filter((groupId): groupId is string => !!groupId) //make sure there are no undefined values + .map((groupId) => groupStatusById[groupId]) //find the status for that group + .filter((status) => !INCOMPLETE_STATUSES.includes(status || 'UNCLAIMED')) //filter to only "complete" statuses + .length, //count them } } @@ -154,7 +169,7 @@ export class RelevantRunSpecsDataSource { if (cloudProject.current && cloudProject.current.runNumber && cloudProject.current.status) { runSpecsToReturn.runSpecs.current = { - ...this.#calculateSpecMetadata(cloudProject.current.specs || []), + ...this.#calculateSpecMetadata(cloudProject.current.specs || [], cloudProject.current.groups || []), runNumber: cloudProject.current.runNumber, } @@ -163,7 +178,7 @@ export class RelevantRunSpecsDataSource { if (cloudProject.next && cloudProject.next.runNumber && cloudProject.next.status) { runSpecsToReturn.runSpecs.next = { - ...this.#calculateSpecMetadata(cloudProject.next.specs || []), + ...this.#calculateSpecMetadata(cloudProject.next.specs || [], cloudProject.next.groups || []), runNumber: cloudProject.next.runNumber, } From 0646f201a6f542d3a38e7095054d6ba50245a30a Mon Sep 17 00:00:00 2001 From: Stokes Player Date: Thu, 19 Jan 2023 10:23:07 -0500 Subject: [PATCH 3/3] Revert last commit. Incorrect logic --- .../src/sources/RelevantRunSpecsDataSource.ts | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts b/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts index d57aa005e0be..ea38d1f3760b 100644 --- a/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts +++ b/packages/data-context/src/sources/RelevantRunSpecsDataSource.ts @@ -4,7 +4,7 @@ import debugLib from 'debug' import { isEqual } from 'lodash' import type { DataContext } from '../DataContext' -import type { CloudSpecStatus, Query, RelevantRun, CurrentProjectRelevantRunSpecs, CloudSpecRun, CloudRun, CloudRunGroup, CloudRunGroupStatusEnum } from '../gen/graphcache-config.gen' +import type { CloudSpecStatus, Query, RelevantRun, CurrentProjectRelevantRunSpecs, CloudSpecRun, CloudRun } from '../gen/graphcache-config.gen' import { Poller } from '../polling' import type { CloudRunStatus } from '@packages/graphql/src/gen/cloud-source-types.gen' @@ -20,10 +20,6 @@ const RELEVANT_RUN_SPEC_OPERATION_DOC = gql` status groupIds } - groups { - id - status - } } query RelevantRunSpecsDataSource_Specs( @@ -90,26 +86,15 @@ export class RelevantRunSpecsDataSource { return this.#cached.runSpecs } - #calculateSpecMetadata (specs: CloudSpecRun[], groups: CloudRunGroup[]) { + #calculateSpecMetadata (specs: CloudSpecRun[]) { //mimic logic in Cloud to sum up the count of groups per spec to give the total spec counts - const countGroupsForSpecs = (specs: CloudSpecRun[]) => { + const countGroupsForSpec = (specs: CloudSpecRun[]) => { return specs.map((spec) => spec.groupIds?.length || 0).reduce((acc, curr) => acc += curr, 0) } - const groupStatusById = groups.reduce>((acc, curr) => { - acc[curr.id] = curr.status - - return acc - }, {}) - return { - totalSpecs: countGroupsForSpecs(specs), - completedSpecs: - specs.flatMap((spec) => spec.groupIds) // pull out the group ids - .filter((groupId): groupId is string => !!groupId) //make sure there are no undefined values - .map((groupId) => groupStatusById[groupId]) //find the status for that group - .filter((status) => !INCOMPLETE_STATUSES.includes(status || 'UNCLAIMED')) //filter to only "complete" statuses - .length, //count them + totalSpecs: countGroupsForSpec(specs), + completedSpecs: countGroupsForSpec(specs.filter((spec) => !INCOMPLETE_STATUSES.includes(spec.status || 'UNCLAIMED'))), } } @@ -169,7 +154,7 @@ export class RelevantRunSpecsDataSource { if (cloudProject.current && cloudProject.current.runNumber && cloudProject.current.status) { runSpecsToReturn.runSpecs.current = { - ...this.#calculateSpecMetadata(cloudProject.current.specs || [], cloudProject.current.groups || []), + ...this.#calculateSpecMetadata(cloudProject.current.specs || []), runNumber: cloudProject.current.runNumber, } @@ -178,7 +163,7 @@ export class RelevantRunSpecsDataSource { if (cloudProject.next && cloudProject.next.runNumber && cloudProject.next.status) { runSpecsToReturn.runSpecs.next = { - ...this.#calculateSpecMetadata(cloudProject.next.specs || [], cloudProject.next.groups || []), + ...this.#calculateSpecMetadata(cloudProject.next.specs || []), runNumber: cloudProject.next.runNumber, }