Skip to content
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

fix: Handle more argument types in privileged commands #27166

Merged
merged 5 commits into from
Jun 29, 2023

Conversation

chrisbreiding
Copy link
Contributor

Additional details

Privileged command argument comparison was failing with types like ArrayBuffer because the invocation argument hashing was done client-side while the execution argument hashing was done server-side. I moved the execution hashing to the client-side, which ensures that the argument hashes will be equal for equal arguments.

I checked the types of arguments each privileged command accepts and added tests to ensure they are all covered.

PR Tasks

Comment on lines +6367 to +6378
type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array

type FileReference = string | BufferType | FileReferenceObject | TypedArray
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a correction for this type.cy.selectFile() can take a TypedArray as an argument.

Comment on lines +25 to +47
// hashes a string in the same manner as is in the privileged channel.
// unfortunately this can't be shared because we want to reduce the surface
// area in the privileged channel, which uses closured references to
// globally-accessible functions
// source: https://github.com/bryc/code/blob/d0dac1c607a005679799024ff66166e13601d397/jshash/experimental/cyrb53.js
function hash (str) {
const seed = 0
let h1 = 0xdeadbeef ^ seed
let h2 = 0x41c6ce57 ^ seed

for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i)
h1 = Math.imul(h1 ^ ch, 2654435761)
h2 = Math.imul(h2 ^ ch, 1597334677)
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)

return `${4294967296 * (2097151 & h2) + (h1 >>> 0)}`
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved here without change from the server

@@ -25,7 +25,7 @@ export default (Commands, Cypress, cy, state) => {
// privileged commands need to send any and all args, even if not part
// of their API, so they can be compared to the args collected when the
// command is invoked
const userArgs = trimUserArgs([file, encoding, _.isObject(userOptions) ? { ...userOptions } : undefined, ...extras])
const userArgs = [file, encoding, _.isObject(userOptions) ? { ...userOptions } : undefined, ...extras]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trimming (and hashing) the user args has been moved into the runPrivilegedCommand function.

@cypress
Copy link

cypress bot commented Jun 29, 2023

34 flaky tests on run #48405 ↗︎

0 27937 1349 0 Flakiness 34

Details:

attempt to fix test flakiness
Project: cypress Commit: 576168bc29
Status: Passed Duration: 22:30 💡
Started: Jun 29, 2023 3:58 PM Ended: Jun 29, 2023 4:20 PM
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  e2e/origin/commands/assertions.cy.ts • 1 flaky test • 5x-driver-firefox

View Output Video

Test Artifacts
cy.origin assertions > #consoleProps > .should() and .and() 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  runs.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
... > opens the run page if a run is clicked 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

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

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

@chrisbreiding chrisbreiding merged commit e0d814c into develop Jun 29, 2023
76 of 78 checks passed
@chrisbreiding chrisbreiding deleted the issue-27163-privileged-commands-arraybuffer branch June 29, 2023 16:26
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 6, 2023

Released in 12.17.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.17.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cy.task not working with ArrayBuffer
3 participants