Skip to content

chore: create infrastructure to support backend function in cy.prompt #31803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 3, 2025

Conversation

ryanthemanuel
Copy link
Collaborator

@ryanthemanuel ryanthemanuel commented May 29, 2025

Additional details

This PR creates an infrastructure to communicate to the backend within the cloud-delivered cy-prompt code. It is modeled after Cypress.backend

Steps to test

How has the user experience changed?

PR Tasks

@@ -1826,11 +1826,6 @@ declare namespace Cypress {
*/
prevUntil<E extends Node = HTMLElement>(element: E | JQuery<E>, filter?: string, options?: Partial<Loggable & Timeoutable>): Chainable<JQuery<E>>

/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also took this opportunity to remove these types. We won't officially add them until we are ready to release the experiment

@ryanthemanuel ryanthemanuel requested a review from Copilot May 30, 2025 02:27
Copilot

This comment was marked as outdated.

@ryanthemanuel ryanthemanuel self-assigned this May 30, 2025
Copy link

cypress bot commented May 30, 2025

cypress    Run #62860

Run Properties:  status check passed Passed #62860  •  git commit ad3c467bc9: fix test
Project cypress
Branch Review ryanm/chore/add-prompt-backend
Run status status check passed Passed #62860
Run duration 18m 48s
Commit git commit ad3c467bc9: fix test
Committer Ryan Manuel
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 10
Tests that did not run due to a developer annotating a test with .skip  Pending 1232
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 32187
View all changes introduced in this branch ↗︎
UI Coverage  45.83%
  Untested elements 190  
  Tested elements 165  
Accessibility  92.74%
  Failed rules  3 critical   9 serious   2 moderate   2 minor
  Failed elements 695  

}

promptBackend (eventName, ...args) {
return this.baseBackendRequestHandler('prompt:backend:request', eventName, ...args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious we'd want to introduce so many places in the app where this could diverge vs bundling this logic up in a cloud call that handles what to do as well as telling the app if it should continue with non-cloud logic

Cloud {
   backend (emitEventName: string, eventName, ...args)) {
      if (!cloudService || !cloudService.isSupportedEvent(emitEventName)) {
         return [true, null]
      }

       return [false, cloudService.handleEvent()]
   }
 
}

private baseBackendRequestHandler (emitEventName: string, eventName, ...args) {
    const [isAppBackendRequest, result] = await this.cloud.backend(.....) <-- initialized on start
    if (!isAppBackendRequest) {
       return result
    }

    return new Promise((resolve, reject) => {

    }
)


backend (eventName, ...args) {
    return this.baseBackendRequestHandler('backend:request', eventName, ...args)
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilyrohrbough makes a good point. Do we know if this is mostly for the experiment to iterate faster with plans to move it later to something a bit more stable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point and I've refactored it a bit to minimize what is necessary on the app providing hooks to be more flexible in the cloud

Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like some of the added tests are failing?

}

promptBackend (eventName, ...args) {
return this.baseBackendRequestHandler('prompt:backend:request', eventName, ...args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilyrohrbough makes a good point. Do we know if this is mostly for the experiment to iterate faster with plans to move it later to something a bit more stable

@ryanthemanuel ryanthemanuel changed the title chore: add promptBackend as an additional Cypress-attached function chore: create infrastructure to support backend function in cy.prompt May 30, 2025
let response

try {
response = await Cypress.backendRequestHandler(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but is this supposed to be Cypress.backend or is the backendRequestNamespace missing from this call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this should be backendRequestNamespace not eventName. Will update

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality is right, the name is confusing (wrong)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanthemanuel ryanthemanuel requested a review from Copilot June 3, 2025 20:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds the plumbing for cy.prompt to send and receive backend requests by mirroring Cypress.backend behavior.

  • Introduces a new addSocketListeners API in the cy-prompt server types and manager
  • Hooks the cy-prompt lifecycle into the main socket server
  • Updates driver code with a new backendRequestHandler and refactors the prompt command

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/types/src/config.ts Removed experimentalPromptCommand from config types
packages/server/lib/socket-base.ts Dropped old backend:request handler and registered addSocketListeners
packages/server/lib/cloud/cy-prompt/CyPromptManager.ts Replaced handleBackendRequest with addSocketListeners
packages/driver/src/cypress.ts Added backendRequestHandler, refactored backend alias
packages/driver/src/cy/commands/prompt/index.ts Switched to createCyPrompt and improved error messages
packages/app/src/runner/event-manager.ts Delegated primary-origin socket events to handler
Comments suppressed due to low confidence (5)

packages/types/src/config.ts:33

  • The ReceivedCypressOptions type no longer includes experimentalPromptCommand, but code in project-base.ts still checks this flag. Please re-add experimentalPromptCommand to the Pick<> so the flag remains typed.
& Pick<Cypress.ResolvedConfigOptions, 'chromeWebSecurity' | ... | 'justInTimeCompile'>

packages/server/lib/socket-base.ts:455

  • The backend:request listener was removed, so any non-prompt backend events will no longer be handled. Consider restoring or rewriting the logic to route backend:request events through the new addSocketListeners hook.
socket.on('backend:request', (eventName: string, ...args) => {

packages/driver/src/cy/commands/prompt/index.ts:21

  • [nitpick] Error messages typically start with an uppercase letter. Consider capitalizing the first word for consistency (e.g., Error waiting for cy prompt bundle…).
throw new Error('error waiting for cy prompt bundle to be downloaded and ready')

packages/driver/src/cy/commands/prompt/index.ts:15

  • [nitpick] The name initializedModule is vague; consider renaming to initializedCyPromptDriver or similar to clarify its purpose.
let initializedModule: CyPromptDriverDefaultShape | null = null

packages/app/src/runner/event-manager.ts:801

  • There's no existing unit test covering handlePrimaryOriginSocketEvent integration. Please add a test to verify that primary-origin backend events are properly forwarded.
Cypress.handlePrimaryOriginSocketEvent(Cypress, 'backend:request')

@ryanthemanuel ryanthemanuel merged commit 22737d2 into feat/cy-prompt Jun 3, 2025
87 of 89 checks passed
@ryanthemanuel ryanthemanuel deleted the ryanm/chore/add-prompt-backend branch June 3, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants