Skip to content

chore: show correct cloud project title in notifications#27095

Merged
lmiller1990 merged 9 commits into
feature/run-notifications-m1from
issue-27089
Jun 22, 2023
Merged

chore: show correct cloud project title in notifications#27095
lmiller1990 merged 9 commits into
feature/run-notifications-m1from
issue-27089

Conversation

@lmiller1990
Copy link
Copy Markdown
Contributor

@lmiller1990 lmiller1990 commented Jun 21, 2023

Additional details

Show the Cloud Project name in the notification. Previously it was the local project, based on the directory name, which is incorrect.

We did not have a central place to fetch and collect cloud project metadata, so I added one. I also made a small refactor - we were duplicating operation and operationDoc in many GraphQL remote requests, so I collapsed them to use a single property, operationDoc. operation is derived from operationDoc via print from the graphql package.

Steps to test

  1. create any project, ensure directory name is NOT the same as cloud project name
  2. trigger a run
  3. observe notification has the correct cloud project name, not the directory based name

How has the user experience changed?

Comply with requirements in the initiative: https://app.clickup.com/18033298/docs/h6amj-43107/h6amj-41927?block=block-7032488f-6f28-4593-a428-dbb17f12c0cd

PR Tasks

@lmiller1990 lmiller1990 marked this pull request as ready for review June 21, 2023 02:33
@cypress
Copy link
Copy Markdown

cypress Bot commented Jun 21, 2023

29 flaky tests on run #48037 ↗︎

0 27897 1349 0 Flakiness 29

Details:

types
Project: cypress Commit: 88c096d8d1
Status: Passed Duration: 21:06 💡
Started: Jun 22, 2023 2:00 AM Ended: Jun 22, 2023 2:22 AM
Flakiness  commands/net_stubbing.cy.ts • 1 flaky test • 5x-driver-firefox

View Output Video

Test Artifacts
network stubbing > intercepting request > can delay and throttle a StaticResponse Output
Flakiness  cypress/cypress.cy.js • 3 flaky tests • 5x-driver-firefox

View Output Video

Test Artifacts
... > correctly returns currentRetry Output
... > correctly returns currentRetry Output
... > correctly returns currentRetry Output
Flakiness  create-from-component.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
... > runs generated spec Output Screenshots Video
Flakiness  specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs Output Screenshots Video
Flakiness  cypress-in-cypress-component.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
Cypress In Cypress CT > default config > redirects to the specs list with error if a spec is not found Output Screenshots Video

The first 5 flaky specs are shown, see all 17 specs in Cypress Cloud.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

this.api.routeToDebug()
}

/**
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems we don't have a centralized place to get info about Cloud projects, so I added this one. Not sure if this is the right pattern - I also think we'd likely want to call this earlier in the code (maybe as soon as we know they are authenticated and they've selected a project?).

Either way, we need to ensure we fetch the cloud project so we can get the name, so I added this function.

async fetchCloudProjectInfo (): Promise<CoreDataShape['cloud'] | undefined> {
const projectSlug = await this.ctx.project.projectId()

if (this.ctx.coreData.cloud.id) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Caching - we only need to fetch this once.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It does not appear that this caching would ever get cleared. Would it? What about running in Global Mode and switching between projects? Or reconnecting a local project to a different Cypress Cloud project?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps clearing out the values in clearCurrentProject above is a start to solve some scenarios. But not sure how to handle the case of someone switching branches that has a different Cloud projectId in the config file or just manually editing the config file.

I would also not want to spread this "reset" logic randomly through the code. I will keep looking for other solutions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought we clear the entire data-context between projects - this may not be the case, let me find out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed this, please see the updated code. We still cache, but the data is it a separate key (cloud) and we have a single place to clear it between projects based on the existing pattern of calling lifecycle.clearCurrentProject()

Copy link
Copy Markdown
Contributor

@astone123 astone123 left a comment

Choose a reason for hiding this comment

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

This worked as expected for me, and I think adding the action to load the cloud data where you did is fine 👍🏻

Copy link
Copy Markdown
Contributor

@warrensplayer warrensplayer left a comment

Choose a reason for hiding this comment

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

Nice job removing that unneeded parameter to executeRemoteGraphQL. That does clean things up a bit.

My main concern is with the caching. (See my other comments).

Secondary concern is with adding GQL stuff to ProjectActions. I cannot think of a better place to put it at the moment and there is a similar pattern in AuthActions.

@lmiller1990
Copy link
Copy Markdown
Contributor Author

Nice job removing that unneeded parameter to executeRemoteGraphQL. That does clean things up a bit.

My main concern is with the caching. (See my other comments).

Secondary concern is with adding GQL stuff to ProjectActions. I cannot think of a better place to put it at the moment and there is a similar pattern in AuthActions.

What do you think about adding a CloudProjectActions / DataSource?

@lmiller1990
Copy link
Copy Markdown
Contributor Author

We will discuss in an internal thread.

@lmiller1990
Copy link
Copy Markdown
Contributor Author

We decided

  1. Adding CloudProjectActions and CloudProjectDataSource? That might keep things nicely separated.
  2. Caching - add a clearCurrentCloudProject.

this.ctx.actions.electron.showSystemNotification(this.projectTitle, body, () => this.onNotificationClick(runNumber))
async #showRunNotification (body: string, runNumber: number) {
try {
const cloudProjectMetadata = this.ctx.coreData.cloudProject.metadata ?? await this.ctx.actions.cloudProject.fetchMetadata()
Copy link
Copy Markdown
Contributor Author

@lmiller1990 lmiller1990 Jun 22, 2023

Choose a reason for hiding this comment

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

I couldn't find a single place that makes sense to call this earlier in the lifecycle, so I'm just calling it when we first show a notification. We cache the data. Said data is cleared when we call clearCloudProject, which is called in the clearCurrentProject() method (where all cleanup between projects occurs).

This does not really feel ideal, but it follows the convention we have (clean up in one place) and at the very least it is simple - you don't need to figure out how / if the cloud metadata is set, it's called right before the data is needed.

My only concern here is this will block showing the notification until the request finishes - that said, we are constantly in sync with the Cloud via the runs polling anyway, so we know the Cloud is alive and responding - worse case scenario is your notification might be delayed by a second or two, which won't be an issue - it's not really real time anyway right now, since we are polling.

@lmiller1990 lmiller1990 merged commit 58fc925 into feature/run-notifications-m1 Jun 22, 2023
@lmiller1990 lmiller1990 deleted the issue-27089 branch June 22, 2023 22:30
@cypress cypress Bot mentioned this pull request Jun 22, 2023
3 tasks
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.

3 participants