-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
fix: Handle more argument types in privileged commands #27166
Conversation
type TypedArray = | ||
| Int8Array | ||
| Uint8Array | ||
| Uint8ClampedArray | ||
| Int16Array | ||
| Uint16Array | ||
| Int32Array | ||
| Uint32Array | ||
| Float32Array | ||
| Float64Array | ||
|
||
type FileReference = string | BufferType | FileReferenceObject | TypedArray |
There was a problem hiding this comment.
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.
// 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)}` | ||
} | ||
|
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
34 flaky tests on run #48405 ↗︎
Details:
commands/net_stubbing.cy.ts • 1 flaky test • 5x-driver-firefox
e2e/origin/commands/assertions.cy.ts • 1 flaky test • 5x-driver-firefox
cypress/cypress.cy.js • 3 flaky tests • 5x-driver-firefox
runs.cy.ts • 1 flaky test • app-e2e
specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e
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. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
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
cypress-documentation
?type definitions
?