Skip to content

Commit

Permalink
feat: capture protocol delivery (cypress-io#26421)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Schile <mschile@cypress.io>
Co-authored-by: David Rowe <95636404+davidr-cy@users.noreply.github.com>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
  • Loading branch information
4 people authored May 15, 2023
1 parent 3c6e53f commit d2ef2c1
Show file tree
Hide file tree
Showing 45 changed files with 1,164 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .circleci/cache-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Bump this version to force CI to re-create the cache from scratch.

04-19-22
05-10-22
7 changes: 6 additions & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mainBuildFilters: &mainBuildFilters
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'update-v8-snapshot-cache-on-develop'
- 'feat/protocol'
- 'tgriesser/feat/protocol-delivery'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -42,6 +43,7 @@ macWorkflowFilters: &darwin-workflow-filters
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'feat/protocol', << pipeline.git.branch >> ]
- equal: [ 'tgriesser/feat/protocol-delivery', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -53,6 +55,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'feat/protocol', << pipeline.git.branch >> ]
- equal: [ 'tgriesser/feat/protocol-delivery', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -73,6 +76,7 @@ windowsWorkflowFilters: &windows-workflow-filters
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'feat/protocol', << pipeline.git.branch >> ]
- equal: [ 'tgriesser/feat/protocol-delivery', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -139,7 +143,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "feat/protocol" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "feat/protocol" && "$CIRCLE_BRANCH" != "tgriesser/feat/protocol-delivery" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down Expand Up @@ -201,6 +205,7 @@ commands:
command: |
source ./scripts/ensure-node.sh
yarn gulp buildProd
yarn gulp syncCloudValidations
- run:
name: Build packages
command: |
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module.exports = {
'cli/types/**',
// these fixtures are supposed to fail linting
'npm/eslint-plugin-dev/test/fixtures/**',
// Cloud generated
'system-tests/lib/validations/**',
],
overrides: [
{
Expand Down
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

**/.eslintrc text eol=lf

packages/errors/__snapshot-html__/** linguist-generated=true
packages/errors/__snapshot-html__/** linguist-generated=true
system-tests/lib/validations/** linguist-generated=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,6 @@ tooling/v8-snapshot/cache/dev-win32
tooling/v8-snapshot/cache/prod-darwin
tooling/v8-snapshot/cache/prod-linux
tooling/v8-snapshot/cache/prod-win32

# Cloud API validations
system-tests/lib/validations
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 12.13.0

_Released 05/23/2023 (PENDING)_

**Features:**

- Adds a new cloud api that confirms the uploads of artifacts. Addressed in [#26421](https://github.com/cypress-io/cypress/pull/26421).

## 12.12.0

_Released 05/09/2023_
Expand Down
10 changes: 10 additions & 0 deletions packages/app/src/runner/events/capture-protocol.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
export const addCaptureProtocolListeners = (Cypress: Cypress.Cypress) => {
Cypress.on('log:added', (log) => {
// TODO: UNIFY-1318 - Race condition in unified runner - we should not need this null check
if (!Cypress.runner) {
return
}

const displayProps = Cypress.runner.getDisplayPropsForLog(log)

Cypress.backend('protocol:command:log:added', displayProps)
})

Cypress.on('log:changed', (log) => {
// TODO: UNIFY-1318 - Race condition in unified runner - we should not need this null check
if (!Cypress.runner) {
return
}

const displayProps = Cypress.runner.getDisplayPropsForLog(log)

Cypress.backend('protocol:command:log:changed', displayProps)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/errors/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ export const AllCypressErrors = {
${fmt.highlightSecondary(apiErr)}`
},
CLOUD_CANNOT_UPLOAD_ARTIFACTS: (apiErr: Error) => {
return errTemplate`\
Warning: We encountered an error while confirming the upload of artifacts.
These results will not display artifacts.
This error will not affect or change the exit code.
${fmt.highlightSecondary(apiErr)}`
},
CLOUD_CANNOT_CREATE_RUN_OR_INSTANCE: (apiErr: Error) => {
return errTemplate`\
Warning: We encountered an error communicating with our servers.
Expand Down
7 changes: 6 additions & 1 deletion packages/errors/test/unit/visualSnapshotErrors_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ describe('visual error templates', () => {
}],
}
},
CLOUD_CANNOT_UPLOAD_ARTIFACTS: () => {
return {
default: [makeErr()],
}
},
CLOUD_STALE_RUN: () => {
return {
default: [{
Expand Down Expand Up @@ -600,7 +605,7 @@ describe('visual error templates', () => {
CLOUD_INVALID_RUN_REQUEST: () => {
return {
default: [{
message: 'request should follow postRunRequest@2.0.0 schema',
message: 'Request Validation Error',
errors: [
'data.commit has additional properties',
'data.ci.buildNumber is required',
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ enum ErrorTypeEnum {
CLOUD_CANNOT_CREATE_RUN_OR_INSTANCE
CLOUD_CANNOT_PROCEED_IN_PARALLEL
CLOUD_CANNOT_PROCEED_IN_SERIAL
CLOUD_CANNOT_UPLOAD_ARTIFACTS
CLOUD_CANNOT_UPLOAD_RESULTS
CLOUD_GRAPHQL_ERROR
CLOUD_INVALID_RUN_REQUEST
Expand Down
6 changes: 3 additions & 3 deletions packages/server/lib/browsers/browser-cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Debug from 'debug'
import { _connectAsync, _getDelayMsForRetry } from './protocol'
import * as errors from '../errors'
import { create, CriClient } from './cri-client'
import type { ProtocolManager } from '@packages/types'
import type { ProtocolManagerShape } from '@packages/types'

const debug = Debug('cypress:server:browsers:browser-cri-client')

Expand Down Expand Up @@ -92,7 +92,7 @@ const retryWithIncreasingDelay = async <T>(retryable: () => Promise<T>, browserN

export class BrowserCriClient {
currentlyAttachedTarget: CriClient | undefined
private constructor (private browserClient: CriClient, private versionInfo, public host: string, public port: number, private browserName: string, private onAsynchronousError: Function, private protocolManager?: ProtocolManager) {}
private constructor (private browserClient: CriClient, private versionInfo, public host: string, public port: number, private browserName: string, private onAsynchronousError: Function, private protocolManager?: ProtocolManagerShape) {}

/**
* Factory method for the browser cri client. Connects to the browser and then returns a chrome remote interface wrapper around the
Expand All @@ -104,7 +104,7 @@ export class BrowserCriClient {
* @param onAsynchronousError callback for any cdp fatal errors
* @returns a wrapper around the chrome remote interface that is connected to the browser target
*/
static async create (hosts: string[], port: number, browserName: string, onAsynchronousError: Function, onReconnect?: (client: CriClient) => void, protocolManager?: ProtocolManager): Promise<BrowserCriClient> {
static async create (hosts: string[], port: number, browserName: string, onAsynchronousError: Function, onReconnect?: (client: CriClient) => void, protocolManager?: ProtocolManagerShape): Promise<BrowserCriClient> {
const host = await ensureLiveBrowser(hosts, port, browserName)

return retryWithIncreasingDelay(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { Browser, BrowserInstance } from './types'
import { BrowserCriClient } from './browser-cri-client'
import type { CriClient } from './cri-client'
import type { Automation } from '../automation'
import type { BrowserLaunchOpts, BrowserNewTabOpts, ProtocolManager, RunModeVideoApi } from '@packages/types'
import type { BrowserLaunchOpts, BrowserNewTabOpts, ProtocolManagerShape, RunModeVideoApi } from '@packages/types'
import memory from './memory'

const debug = debugModule('cypress:server:browsers:chrome')
Expand Down Expand Up @@ -569,7 +569,7 @@ export = {
/**
* Clear instance state for the chrome instance, this is normally called in on kill or on exit.
*/
clearInstanceState (protocolManager?: ProtocolManager) {
clearInstanceState (protocolManager?: ProtocolManagerShape) {
debug('closing remote interface client')
// Do nothing on failure here since we're shutting down anyway
browserCriClient?.close().catch()
Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/browsers/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as errors from '../errors'
import type { Browser, BrowserInstance } from './types'
import type { BrowserWindow } from 'electron'
import type { Automation } from '../automation'
import type { BrowserLaunchOpts, Preferences, ProtocolManager, RunModeVideoApi } from '@packages/types'
import type { BrowserLaunchOpts, Preferences, ProtocolManagerShape, RunModeVideoApi } from '@packages/types'
import memory from './memory'
import { BrowserCriClient } from './browser-cri-client'
import { getRemoteDebuggingPort } from '../util/electron-app'
Expand Down Expand Up @@ -232,7 +232,7 @@ export = {
return this._launch(win, url, automation, electronOptions)
},

async _launch (win: BrowserWindow, url: string, automation: Automation, options: ElectronOpts, videoApi?: RunModeVideoApi, protocolManager?: ProtocolManager) {
async _launch (win: BrowserWindow, url: string, automation: Automation, options: ElectronOpts, videoApi?: RunModeVideoApi, protocolManager?: ProtocolManagerShape) {
if (options.show) {
menu.set({ withInternalDevTools: true })
}
Expand Down
Loading

0 comments on commit d2ef2c1

Please sign in to comment.