From 3f3e3080dd643223af661f4ea3d1e8c31a68edfb Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 23 Nov 2022 22:10:50 -0600 Subject: [PATCH 01/54] fix: v8 improvements - run ci --- package.json | 1 + packages/rewriter/script/worker-shim.js | 9 +--- packages/server/hook-require.js | 6 +-- packages/server/index.js | 9 +--- packages/ts/registerDir.js | 4 +- .../src/snapshot-require.ts | 17 +++---- scripts/after-pack-hook.js | 3 +- scripts/binary/binary-cleanup.js | 42 +++++++++++++++-- .../binary/binary-integrity-check-source.js | 47 +++++++++++++++++++ scripts/binary/binary-integrity-check.js | 22 +++++++++ scripts/binary/build.ts | 9 ++-- .../prod-darwin/snapshot-meta.cache.json | 6 ++- .../v8-snapshot/src/blueprint/set-globals.js | 5 ++ .../src/doctor/determine-deferred.ts | 2 + .../src/doctor/process-script.worker.ts | 2 + .../v8-snapshot/src/doctor/snapshot-doctor.ts | 4 ++ .../v8-snapshot/src/generator/blueprint.ts | 28 +++++++++-- .../src/generator/create-snapshot-script.ts | 3 ++ ...napshot-generate-entry-via-dependencies.ts | 5 ++ .../src/generator/snapshot-generator.ts | 10 ++++ tooling/v8-snapshot/src/setup/config.ts | 16 +++++-- .../v8-snapshot/src/setup/generate-entry.ts | 3 ++ .../src/setup/generate-metadata.ts | 5 ++ tooling/v8-snapshot/src/setup/index.ts | 4 +- .../v8-snapshot/src/setup/install-snapshot.ts | 5 ++ tooling/v8-snapshot/src/types.ts | 3 ++ yarn.lock | 5 ++ 27 files changed, 225 insertions(+), 50 deletions(-) create mode 100644 scripts/binary/binary-integrity-check-source.js create mode 100644 scripts/binary/binary-integrity-check.js diff --git a/package.json b/package.json index 2df9a12a5a8e..dcc0e867b84d 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "prepare": "husky install" }, "dependencies": { + "bytenode": "^1.2.1", "nvm": "0.0.4" }, "devDependencies": { diff --git a/packages/rewriter/script/worker-shim.js b/packages/rewriter/script/worker-shim.js index 2a61bf648282..50d770039d09 100644 --- a/packages/rewriter/script/worker-shim.js +++ b/packages/rewriter/script/worker-shim.js @@ -3,13 +3,8 @@ if (process.env.CYPRESS_INTERNAL_ENV === 'production') { throw new Error(`${__filename} should only run outside of prod`) } -if (require.name !== 'customRequire') { - // Purposefully make this a dynamic require so that it doesn't have the potential to get picked up by snapshotting mechanism - const hook = './hook' +const { hookRequire } = require('@packages/server/hook-require') - const { hookRequire } = require(`@packages/server/${hook}-require`) - - hookRequire(true) -} +hookRequire({ forceTypeScript: true }) require('../lib/threads/worker.ts') diff --git a/packages/server/hook-require.js b/packages/server/hook-require.js index a328364fabf5..1743f4d6b31c 100644 --- a/packages/server/hook-require.js +++ b/packages/server/hook-require.js @@ -9,7 +9,7 @@ function runWithSnapshot (forceTypeScript) { const { snapshotRequire } = require('@packages/v8-snapshot-require') const projectBaseDir = process.env.PROJECT_BASE_DIR - const supportTS = forceTypeScript || typeof global.snapshotResult === 'undefined' || global.supportTypeScript + const supportTS = forceTypeScript || typeof global.getSnapshotResult === 'undefined' || global.supportTypeScript snapshotRequire(projectBaseDir, { diagnosticsEnabled: isDev, @@ -30,8 +30,8 @@ function runWithSnapshot (forceTypeScript) { }) } -const hookRequire = (forceTypeScript) => { - if (['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) || typeof snapshotResult === 'undefined') { +const hookRequire = ({ forceTypeScript }) => { + if (['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) || typeof getSnapshotResult === 'undefined') { require('@packages/ts/register') } else { runWithSnapshot(forceTypeScript) diff --git a/packages/server/index.js b/packages/server/index.js index ad10f8c50a7b..f3a5dde6a2e9 100644 --- a/packages/server/index.js +++ b/packages/server/index.js @@ -3,14 +3,9 @@ const { initializeStartTime } = require('./lib/util/performance_benchmark') const run = async () => { initializeStartTime() - if (require.name !== 'customRequire') { - // Purposefully make this a dynamic require so that it doesn't have the potential to get picked up by snapshotting mechanism - const hook = './hook' + const { hookRequire } = require('./hook-require') - const { hookRequire } = require(`${hook}-require`) - - hookRequire(false) - } + hookRequire({ forceTypeScript: false }) await require('./server-entry') } diff --git a/packages/ts/registerDir.js b/packages/ts/registerDir.js index 51800a1634f3..b82bb0dca496 100644 --- a/packages/ts/registerDir.js +++ b/packages/ts/registerDir.js @@ -8,8 +8,8 @@ const path = require('path') // build has been done correctly module.exports = function (scopeDir) { // Only set up ts-node if we're not using the snapshot - // @ts-ignore snapshotResult is a global defined in the v8 snapshot - if (['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) || typeof snapshotResult === 'undefined') { + // @ts-ignore getSnapshotResult is a global defined in the v8 snapshot + if (['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) || typeof getSnapshotResult === 'undefined') { try { // Prevent double-compiling if we're testing the app and already have ts-node hook installed // TODO(tim): e2e testing does not like this, I guess b/c it's currently using the tsconfig diff --git a/packages/v8-snapshot-require/src/snapshot-require.ts b/packages/v8-snapshot-require/src/snapshot-require.ts index c428425d5eff..9428f5ed440c 100644 --- a/packages/v8-snapshot-require/src/snapshot-require.ts +++ b/packages/v8-snapshot-require/src/snapshot-require.ts @@ -181,8 +181,8 @@ export function snapshotRequire ( // 1. Assign snapshot which is a global if it was embedded const sr: Snapshot = opts.snapshotOverride || - // @ts-ignore global snapshotResult - (typeof snapshotResult !== 'undefined' ? snapshotResult : undefined) + // @ts-ignore global getSnapshotResult + (typeof getSnapshotResult !== 'undefined' ? getSnapshotResult() : undefined) // If we have no snapshot we don't need to hook anything if (sr != null || alwaysHook) { @@ -239,10 +239,7 @@ export function snapshotRequire ( moduleNeedsReload, }) - // @ts-ignore global snapshotResult - // 8. Ensure that the user passed the project base dir since the loader - // cannot resolve modules without it - if (typeof snapshotResult !== 'undefined') { + if (typeof sr !== 'undefined') { const projectBaseDir = process.env.PROJECT_BASE_DIR if (projectBaseDir == null) { @@ -292,8 +289,8 @@ export function snapshotRequire ( // 11. Inject those globals - // @ts-ignore global snapshotResult - snapshotResult.setGlobals( + // @ts-ignore setGlobals is a function on global sr + sr.setGlobals( global, checked_process, checked_window, @@ -307,8 +304,8 @@ export function snapshotRequire ( // @ts-ignore private module var require.cache = Module._cache - // @ts-ignore global snapshotResult - snapshotResult.customRequire.cache = require.cache + // @ts-ignore customRequire is a property of global sr + sr.customRequire.cache = require.cache // 12. Add some 'magic' functions that we can use from inside the // snapshot in order to integrate module loading diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index 239314877b83..83cb7fb03914 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -7,6 +7,7 @@ const path = require('path') const { setupV8Snapshots } = require('@tooling/v8-snapshot') const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses') const { cleanup } = require('./binary/binary-cleanup') +const { getIntegrityCheckSource } = require('./binary/binary-integrity-check') module.exports = async function (params) { console.log('****************************') @@ -63,7 +64,7 @@ module.exports = async function (params) { }, ) - await setupV8Snapshots(params.appOutDir) await cleanup(outputFolder) + await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) } } diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index dc6a70545baf..db8fc44ce7a9 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -6,6 +6,7 @@ const esbuild = require('esbuild') const snapshotMetadata = require('@tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json') const tempDir = require('temp-dir') const workingDir = path.join(tempDir, 'binary-cleanup-workdir') +const bytenode = require('bytenode') fs.ensureDirSync(workingDir) @@ -39,8 +40,6 @@ async function removeEmptyDirectories (directory) { const getDependencyPathsToKeep = async (buildAppDir) => { const unixBuildAppDir = buildAppDir.split(path.sep).join(path.posix.sep) const startingEntryPoints = [ - 'packages/server/index.js', - 'packages/server/hook-require.js', 'packages/server/lib/plugins/child/require_async_child.js', 'packages/server/lib/plugins/child/register_ts_node.js', 'packages/rewriter/lib/threads/worker.js', @@ -114,13 +113,48 @@ const getDependencyPathsToKeep = async (buildAppDir) => { return [...Object.keys(esbuildResult.metafile.inputs), ...entryPoints] } +const createServerEntryPointBundle = async (buildAppDir) => { + const unixBuildAppDir = buildAppDir.split(path.sep).join(path.posix.sep) + const entryPoints = [path.join(unixBuildAppDir, 'packages/server/index.js')] + const esbuildResult = await esbuild.build({ + entryPoints, + bundle: true, + outdir: workingDir, + platform: 'node', + metafile: true, + absWorkingDir: unixBuildAppDir, + external: [ + './transpile-ts', + './server-entry', + ], + }) + + console.log(`copying server entry point bundle from ${path.join(workingDir, 'index.js')} to ${path.join(buildAppDir, 'packages', 'server', 'index.js')}`) + + await fs.copy(path.join(workingDir, 'index.js'), path.join(buildAppDir, 'packages', 'server', 'backup.js')) + await fs.copy(path.join(workingDir, 'index.js'), path.join(buildAppDir, 'packages', 'server', 'index.js')) + + await bytenode.compileFile({ + filename: path.join(buildAppDir, 'packages', 'server', 'index.js'), + output: path.join(buildAppDir, 'packages', 'server', 'index.jsc'), + electron: true, + }) + + return [...Object.keys(esbuildResult.metafile.inputs)].map((input) => `./${input}`) +} + const cleanup = async (buildAppDir) => { // 1. Retrieve all dependencies that still need to be kept in the binary. In theory, we could use the bundles generated here as single files within the binary, // but for now, we just track on the dependencies that get pulled in - const keptDependencies = [...await getDependencyPathsToKeep(buildAppDir), 'package.json', 'packages/server/server-entry.js'] + const keptDependencies = [...await getDependencyPathsToKeep(buildAppDir), 'package.json'] // 2. Gather the dependencies that could potentially be removed from the binary due to being in the snapshot - const potentiallyRemovedDependencies = [...snapshotMetadata.healthy, ...snapshotMetadata.deferred, ...snapshotMetadata.norewrite] + const potentiallyRemovedDependencies = [ + ...snapshotMetadata.healthy, + ...snapshotMetadata.deferred, + ...snapshotMetadata.norewrite, + ...await createServerEntryPointBundle(buildAppDir), + ] // 3. Remove all dependencies that are in the snapshot but not in the list of kept dependencies from the binary await Promise.all(potentiallyRemovedDependencies.map(async (dependency) => { diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js new file mode 100644 index 000000000000..dc8e24a2e416 --- /dev/null +++ b/scripts/binary/binary-integrity-check-source.js @@ -0,0 +1,47 @@ +const origError = Error + +// eslint-disable-next-line no-unused-vars +function integrityCheck (options) { + const originalStackTrace = origError.prepareStackTrace + + origError.prepareStackTrace = function (_, stack) { + return stack + } + + const tempError = new origError + + origError.captureStackTrace(tempError, arguments.callee) + let stack = tempError.stack + + origError.prepareStackTrace = originalStackTrace + + options.stackToMatch.forEach((functionName, index) => { + if (stack[index].getFunctionName() !== functionName) { + throw new Error(`Integrity check failed at index ${ index } with function name ${ functionName } and expected function name ${ stack[index].getFunctionName()}`) + } + }) + + const fs = require('fs') + const crypto = require('crypto') + + // eslint-disable-next-line no-undef + const mainIndexHash = crypto.createHash('md5').update(fs.readFileSync(__resolve_path('./index.js'), 'utf8')).digest('hex') + + if (mainIndexHash !== 'MAIN_INDEX_HASH') { + throw new Error(`Integrity check failed for main index.js file`) + } + + // eslint-disable-next-line no-undef + const bytenodeHash = crypto.createHash('md5').update(fs.readFileSync(__resolve_path('./node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') + + if (bytenodeHash !== 'BYTENODE_HASH') { + throw new Error(`Integrity check failed for main bytenode.js file`) + } + + // eslint-disable-next-line no-undef + const indexJscHash = crypto.createHash('md5').update(fs.readFileSync(__resolve_path('./packages/server/index.jsc'), 'utf8')).digest('hex') + + if (indexJscHash !== 'INDEX_JSC_HASH') { + throw new Error(`Integrity check failed for main server index.jsc file`) + } +} diff --git a/scripts/binary/binary-integrity-check.js b/scripts/binary/binary-integrity-check.js new file mode 100644 index 000000000000..4352c46fa6a2 --- /dev/null +++ b/scripts/binary/binary-integrity-check.js @@ -0,0 +1,22 @@ +const fs = require('fs') +const crypto = require('crypto') +const path = require('path') + +function read ({ part, baseDirectory }) { + const p = require.resolve(`./${part}`) + const s = fs.readFileSync(p, 'utf8') + + const mainIndexHash = crypto.createHash('md5').update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') + const bytenodeHash = crypto.createHash('md5').update(fs.readFileSync(path.join(baseDirectory, './node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') + const indexJscHash = crypto.createHash('md5').update(fs.readFileSync(path.join(baseDirectory, './packages/server/index.jsc'), 'utf8')).digest('hex') + + return s.split('\n').join(`\n `).replace('MAIN_INDEX_HASH', mainIndexHash).replace('BYTENODE_HASH', bytenodeHash).replace('INDEX_JSC_HASH', indexJscHash) +} + +const getIntegrityCheckSource = (baseDirectory) => { + return read({ part: 'binary-integrity-check-source.js', baseDirectory }) +} + +module.exports = { + getIntegrityCheckSource, +} diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 5b39e33f5c1d..53ff06f41f98 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -174,12 +174,9 @@ export async function buildCypressApp (options: BuildCypressAppOpts) { }, { spaces: 2 }) fs.writeFileSync(meta.distDir('index.js'), `\ -${!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) ? -`if (!global.snapshotResult && process.versions?.electron) { - throw new Error('global.snapshotResult is not defined. This binary has been built incorrectly.') -}` : ''} process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production' -require('./packages/server')\ +require('./node_modules/bytenode/lib/index.js') +require('./packages/server/index.js') `) // removeTypeScript @@ -260,6 +257,8 @@ require('./packages/server')\ version, }, { spaces: 2 }) + fs.writeFileSync(meta.distDir('index.js'), fs.readFileSync(meta.distDir('index.js'), 'utf8').replace('server/index.js', 'server/index.jsc')) + try { await execa('electron-builder', args, { stdio: 'inherit', diff --git a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json index 145ff7f48721..f545fe0f9258 100644 --- a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json @@ -62,8 +62,10 @@ "./packages/server/lib/util/process_profiler.ts", "./packages/server/lib/util/suppress_warnings.js", "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/ci-info/index.js", "./packages/server/node_modules/glob/node_modules/minimatch/minimatch.js", "./packages/server/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/is-ci/index.js", "./packages/server/node_modules/mocha/node_modules/debug/src/node.js", "./packages/server/node_modules/signal-exit/index.js", "./process-nextick-args/index.js", @@ -936,6 +938,7 @@ "./packages/server/node_modules/uuid/dist/v4.js", "./packages/server/node_modules/uuid/dist/v5.js", "./packages/server/server-entry.js", + "./packages/server/snapshot-entry.js", "./packages/socket/index.js", "./packages/socket/lib/socket.ts", "./packages/socket/node_modules/socket.io/dist/broadcast-operator.js", @@ -3807,6 +3810,7 @@ "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/legacy-streams.js", "./packages/server/node_modules/@benmalka/foxdriver/package.json", "./packages/server/node_modules/ansi-regex/index.js", + "./packages/server/node_modules/ci-info/vendors.json", "./packages/server/node_modules/cli-table3/index.js", "./packages/server/node_modules/cli-table3/src/cell.js", "./packages/server/node_modules/cli-table3/src/layout-manager.js", @@ -3930,5 +3934,5 @@ "./tooling/v8-snapshot/cache/prod-darwin/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "8b71698b89d3804ed712295c20a140cfcd674fa5c3ad9569530282dd6c3e9906" + "deferredHash": "9b94c93e768da3b93ffc6e07da24a90a3e2f07577d224096b58ec7db5654a1a2" } \ No newline at end of file diff --git a/tooling/v8-snapshot/src/blueprint/set-globals.js b/tooling/v8-snapshot/src/blueprint/set-globals.js index 21dd4ed1b145..0704ce0c35ac 100644 --- a/tooling/v8-snapshot/src/blueprint/set-globals.js +++ b/tooling/v8-snapshot/src/blueprint/set-globals.js @@ -56,4 +56,9 @@ function setGlobals ( console = newConsole __pathResolver = newPathResolver require = nodeRequire + + if (typeof integrityCheck === 'function') { + // eslint-disable-next-line no-undef + integrityCheck({ stackToMatch: ['setGlobals', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) + } } diff --git a/tooling/v8-snapshot/src/doctor/determine-deferred.ts b/tooling/v8-snapshot/src/doctor/determine-deferred.ts index 2b1393397f61..4a809de3e639 100644 --- a/tooling/v8-snapshot/src/doctor/determine-deferred.ts +++ b/tooling/v8-snapshot/src/doctor/determine-deferred.ts @@ -20,6 +20,7 @@ export async function determineDeferred ( forceNoRewrite: Set useHashBasedCache: boolean nodeEnv: string + integrityCheckSource: string | undefined }, ) { const jsonPath = path.join(cacheDir, 'snapshot-meta.json') @@ -73,6 +74,7 @@ export async function determineDeferred ( forceNoRewrite: opts.forceNoRewrite, nodeEnv: opts.nodeEnv, supportTypeScript: opts.nodeModulesOnly, + integrityCheckSource: opts.integrityCheckSource, }) const { diff --git a/tooling/v8-snapshot/src/doctor/process-script.worker.ts b/tooling/v8-snapshot/src/doctor/process-script.worker.ts index 4ba9e393758d..4c30c1e4167d 100644 --- a/tooling/v8-snapshot/src/doctor/process-script.worker.ts +++ b/tooling/v8-snapshot/src/doctor/process-script.worker.ts @@ -74,6 +74,7 @@ export function processScript ({ entryPoint, nodeEnv, supportTypeScript, + integrityCheckSource, }: ProcessScriptOpts): ProcessScriptResult { const bundleContent = getBundle(bundlePath, bundleHash) let snapshotScript @@ -86,6 +87,7 @@ export function processScript ({ baseSourcemapExternalPath: undefined, processedSourcemapExternalPath: undefined, supportTypeScript, + integrityCheckSource, }).script } catch (err: any) { return { outcome: 'failed:assembleScript', error: err } diff --git a/tooling/v8-snapshot/src/doctor/snapshot-doctor.ts b/tooling/v8-snapshot/src/doctor/snapshot-doctor.ts index ae3dfad427b6..03f620c447dd 100644 --- a/tooling/v8-snapshot/src/doctor/snapshot-doctor.ts +++ b/tooling/v8-snapshot/src/doctor/snapshot-doctor.ts @@ -266,6 +266,7 @@ export class SnapshotDoctor { private readonly nodeEnv: string private readonly _scriptProcessor: AsyncScriptProcessor private readonly _warningsProcessor: WarningsProcessor + private readonly integrityCheckSource: string | undefined /** * Creates an instance of the {@link SnapshotDoctor} @@ -284,6 +285,7 @@ export class SnapshotDoctor { this.previousNoRewrite = unpathify(opts.previousNoRewrite) this.forceNoRewrite = unpathify(opts.forceNoRewrite) this.nodeEnv = opts.nodeEnv + this.integrityCheckSource = opts.integrityCheckSource } /** @@ -499,6 +501,7 @@ export class SnapshotDoctor { entryPoint: `./${key}`, nodeEnv: this.nodeEnv, supportTypeScript: this.nodeModulesOnly, + integrityCheckSource: this.integrityCheckSource, }) assert(result != null, 'expected result from script processor') @@ -605,6 +608,7 @@ export class SnapshotDoctor { deferred: deferredArg, norewrite: norewriteArg, supportTypeScript: this.nodeModulesOnly, + integrityCheckSource: this.integrityCheckSource, }) return { warnings, meta: meta as Metadata, bundle } diff --git a/tooling/v8-snapshot/src/generator/blueprint.ts b/tooling/v8-snapshot/src/generator/blueprint.ts index 80f8cd6b7f28..151f9128dcc8 100644 --- a/tooling/v8-snapshot/src/generator/blueprint.ts +++ b/tooling/v8-snapshot/src/generator/blueprint.ts @@ -51,6 +51,7 @@ export type BlueprintConfig = { sourceMap: Buffer | undefined processedSourceMapPath: string | undefined supportTypeScript: boolean + integrityCheckSource: string | undefined } const pathSep = path.sep === '\\' ? '\\\\' : path.sep @@ -101,6 +102,7 @@ export function scriptFromBlueprint (config: BlueprintConfig): { basedir, sourceMap, supportTypeScript, + integrityCheckSource, } = config const normalizedMainModuleRequirePath = forwardSlash(mainModuleRequirePath) @@ -169,14 +171,30 @@ function generateSnapshot() { ${customRequire} ${includeStrictVerifiers ? 'require.isStrict = true' : ''} + ${integrityCheckSource || ''} + customRequire(${normalizedMainModuleRequirePath}, ${normalizedMainModuleRequirePath}) - return { - customRequire, - setGlobals: ${setGlobals}, - } + const result = {} + Object.defineProperties(result, { + customRequire: { + writable: false, + value: customRequire + }, + setGlobals: { + writable: false, + value: ${setGlobals} + } + }) + return result } -var snapshotResult = generateSnapshot.call({}) +const snapshotResult = generateSnapshot.call({}) +Object.defineProperty(this, 'getSnapshotResult', { + writable: false, + value: function () { + return snapshotResult + }, +}) var supportTypeScript = ${supportTypeScript} generateSnapshot = null `, diff --git a/tooling/v8-snapshot/src/generator/create-snapshot-script.ts b/tooling/v8-snapshot/src/generator/create-snapshot-script.ts index 766b44a624f1..d16180667ceb 100644 --- a/tooling/v8-snapshot/src/generator/create-snapshot-script.ts +++ b/tooling/v8-snapshot/src/generator/create-snapshot-script.ts @@ -120,6 +120,7 @@ export function assembleScript ( resolverMap?: Record meta?: Metadata supportTypeScript: boolean + integrityCheckSource: string | undefined }, ): { script: Buffer, processedSourceMap?: string } { const includeStrictVerifiers = opts.includeStrictVerifiers ?? false @@ -179,6 +180,7 @@ export function assembleScript ( basedir, processedSourceMapPath: opts.processedSourcemapExternalPath, supportTypeScript: opts.supportTypeScript, + integrityCheckSource: opts.integrityCheckSource, } // 5. Finally return the rendered script buffer and optionally processed @@ -234,6 +236,7 @@ export async function createSnapshotScript ( resolverMap: opts.resolverMap, meta, supportTypeScript: opts.supportTypeScript, + integrityCheckSource: opts.integrityCheckSource, }, ) diff --git a/tooling/v8-snapshot/src/generator/snapshot-generate-entry-via-dependencies.ts b/tooling/v8-snapshot/src/generator/snapshot-generate-entry-via-dependencies.ts index eb2b92817af9..6db36953a109 100644 --- a/tooling/v8-snapshot/src/generator/snapshot-generate-entry-via-dependencies.ts +++ b/tooling/v8-snapshot/src/generator/snapshot-generate-entry-via-dependencies.ts @@ -20,6 +20,7 @@ class SnapshotEntryGeneratorViaWalk { readonly fullPathToSnapshotEntry: string, readonly nodeModulesOnly: boolean, readonly pathsMapper: PathsMapper, + readonly integrityCheckSource: string | undefined, ) { this.bundlerPath = getBundlerPath() } @@ -59,6 +60,7 @@ class SnapshotEntryGeneratorViaWalk { nodeModulesOnly: this.nodeModulesOnly, sourcemap: false, supportTypeScript: this.nodeModulesOnly, + integrityCheckSource: this.integrityCheckSource, } const { meta } = await createBundleAsync(opts) @@ -78,6 +80,7 @@ type GenerateDepsDataOpts = { entryFile: string nodeModulesOnly?: boolean pathsMapper?: PathsMapper + integrityCheckSource: string | undefined } export type BundlerMetadata = Metadata & { projectBaseDir: string } @@ -94,6 +97,7 @@ export async function generateBundlerMetadata ( fullPathToSnapshotEntry, fullConf.nodeModulesOnly, fullConf.pathsMapper, + config.integrityCheckSource, ) const meta = await generator.getMetadata() @@ -120,6 +124,7 @@ export async function generateSnapshotEntryFromEntryDependencies ( fullPathToSnapshotEntry, fullConf.nodeModulesOnly, fullConf.pathsMapper, + config.integrityCheckSource, ) try { diff --git a/tooling/v8-snapshot/src/generator/snapshot-generator.ts b/tooling/v8-snapshot/src/generator/snapshot-generator.ts index 43f01c22c383..ea96fb392453 100644 --- a/tooling/v8-snapshot/src/generator/snapshot-generator.ts +++ b/tooling/v8-snapshot/src/generator/snapshot-generator.ts @@ -100,6 +100,7 @@ export type GenerationOpts = { nodeEnv: string minify: boolean supportTypeScript: boolean + integrityCheckSource: string | undefined } function getDefaultGenerationOpts (projectBaseDir: string): GenerationOpts { @@ -114,6 +115,7 @@ function getDefaultGenerationOpts (projectBaseDir: string): GenerationOpts { nodeEnv: 'development', minify: false, supportTypeScript: false, + integrityCheckSource: undefined, } } @@ -156,6 +158,8 @@ export class SnapshotGenerator { private readonly nodeEnv: string /** See {@link GenerationOpts} minify */ private readonly minify: boolean + /** See {@link GenerationOpts} integrityCheckSource */ + private readonly integrityCheckSource: string | undefined /** * Path to the Go bundler binary used to generate the bundle with rewritten code * {@link https://github.com/cypress-io/esbuild/tree/thlorenz/snap} @@ -208,6 +212,7 @@ export class SnapshotGenerator { flags: mode, nodeEnv, minify, + integrityCheckSource, }: GenerationOpts = Object.assign( getDefaultGenerationOpts(projectBaseDir), opts, @@ -234,6 +239,7 @@ export class SnapshotGenerator { this._flags = new GeneratorFlags(mode) this.bundlerPath = getBundlerPath() this.minify = minify + this.integrityCheckSource = integrityCheckSource const auxiliaryDataKeys = Object.keys(this.auxiliaryData || {}) @@ -282,6 +288,7 @@ export class SnapshotGenerator { forceNoRewrite: this.forceNoRewrite, useHashBasedCache: this._flags.has(Flag.ReuseDoctorArtifacts), nodeEnv: this.nodeEnv, + integrityCheckSource: this.integrityCheckSource, }, )) } catch (err) { @@ -309,6 +316,7 @@ export class SnapshotGenerator { processedSourcemapExternalPath: this.snapshotScriptPath.replace('snapshot.js', 'processed.snapshot.js.map'), nodeEnv: this.nodeEnv, supportTypeScript: this.nodeModulesOnly, + integrityCheckSource: this.integrityCheckSource, }) } catch (err) { logError('Failed creating script') @@ -388,6 +396,7 @@ export class SnapshotGenerator { forceNoRewrite: this.forceNoRewrite, useHashBasedCache: this._flags.has(Flag.ReuseDoctorArtifacts), nodeEnv: this.nodeEnv, + integrityCheckSource: this.integrityCheckSource, }, )) } catch (err) { @@ -413,6 +422,7 @@ export class SnapshotGenerator { auxiliaryData: this.auxiliaryData, nodeEnv: this.nodeEnv, supportTypeScript: this.nodeModulesOnly, + integrityCheckSource: this.integrityCheckSource, }) } catch (err) { logError('Failed creating script') diff --git a/tooling/v8-snapshot/src/setup/config.ts b/tooling/v8-snapshot/src/setup/config.ts index 7d194723564f..05e4da21b040 100644 --- a/tooling/v8-snapshot/src/setup/config.ts +++ b/tooling/v8-snapshot/src/setup/config.ts @@ -13,6 +13,7 @@ type SnapshotConfig = { metaFile: string usePreviousSnapshotMetadata: boolean minify: boolean + integrityCheckSource: string | undefined } const platformString = process.platform @@ -20,7 +21,7 @@ const platformString = process.platform const snapshotCacheBaseDir = path.resolve(__dirname, '..', '..', 'cache') const projectBaseDir = path.join(__dirname, '..', '..', '..', '..') -const appEntryFile = require.resolve('@packages/server/server-entry.js') +const appEntryFile = require.resolve('@packages/server/snapshot-entry.js') const cypressAppSnapshotDir = (cypressAppPath?: string) => { const electronPackageDir = path.join(projectBaseDir, 'packages', 'electron') @@ -83,14 +84,22 @@ const usePreviousSnapshotMetadata = process.env.V8_SNAPSHOT_FROM_SCRATCH == null * @param {string} env - 'dev' | 'prod' * @returns {SnapshotConfig} config to be used for all snapshot related tasks */ -export function createConfig (env: 'dev' | 'prod' = 'prod', cypressAppPath?: string): SnapshotConfig { +export function createConfig ({ + env = 'prod', + cypressAppPath, + integrityCheckSource, +}: { + env?: 'dev' | 'prod' + cypressAppPath?: string + integrityCheckSource: string | undefined +}): SnapshotConfig { /** * If true only node_module dependencies are included in the snapshot. Otherwise app files are included as well * * Configured via `env` */ const nodeModulesOnly = env === 'dev' - const minify = env === 'prod' + const minify = !process.env.V8_SNAPSHOT_DISABLE_MINIFY && env === 'prod' const snapshotCacheDir = env === 'dev' @@ -118,5 +127,6 @@ export function createConfig (env: 'dev' | 'prod' = 'prod', cypressAppPath?: str snapshotMetaPrevFile, usePreviousSnapshotMetadata, minify, + integrityCheckSource, } } diff --git a/tooling/v8-snapshot/src/setup/generate-entry.ts b/tooling/v8-snapshot/src/setup/generate-entry.ts index 50fba54cbbf7..6a16a879d677 100644 --- a/tooling/v8-snapshot/src/setup/generate-entry.ts +++ b/tooling/v8-snapshot/src/setup/generate-entry.ts @@ -18,12 +18,14 @@ export async function generateEntry ({ pathsMapper, projectBaseDir, snapshotEntryFile, + integrityCheckSource, }: { appEntryFile: string nodeModulesOnly: boolean pathsMapper: (file: string) => string projectBaseDir: string snapshotEntryFile: string + integrityCheckSource: string | undefined }): Promise { logInfo('Creating snapshot generation entry file %o', { nodeModulesOnly }) @@ -37,6 +39,7 @@ export async function generateEntry ({ entryFile: appEntryFile, pathsMapper, nodeModulesOnly, + integrityCheckSource, }, ) diff --git a/tooling/v8-snapshot/src/setup/generate-metadata.ts b/tooling/v8-snapshot/src/setup/generate-metadata.ts index 3b520028a0e3..55707f6b70d9 100644 --- a/tooling/v8-snapshot/src/setup/generate-metadata.ts +++ b/tooling/v8-snapshot/src/setup/generate-metadata.ts @@ -14,11 +14,13 @@ async function createMeta ({ pathsMapper, projectBaseDir, snapshotEntryFile, + integrityCheckSource, }) { return generateBundlerMetadata(projectBaseDir, snapshotEntryFile, { entryFile: appEntryFile, pathsMapper, nodeModulesOnly, + integrityCheckSource, }) } @@ -38,6 +40,7 @@ export async function generateMetadata ({ pathsMapper, projectBaseDir, snapshotEntryFile, + integrityCheckSource, }: { appEntryFile: string metaFile: string @@ -45,6 +48,7 @@ export async function generateMetadata ({ pathsMapper: (file: string) => string projectBaseDir: string snapshotEntryFile: string + integrityCheckSource: string | undefined }): Promise { try { logInfo('Creating snapshot metadata %o', { nodeModulesOnly }) @@ -55,6 +59,7 @@ export async function generateMetadata ({ pathsMapper, projectBaseDir, snapshotEntryFile, + integrityCheckSource, }) ensureDirSync(path.dirname(metaFile)) diff --git a/tooling/v8-snapshot/src/setup/index.ts b/tooling/v8-snapshot/src/setup/index.ts index e6745e6dfa26..4f6b0c39447d 100644 --- a/tooling/v8-snapshot/src/setup/index.ts +++ b/tooling/v8-snapshot/src/setup/index.ts @@ -6,10 +6,10 @@ import { generateEntry } from './generate-entry' import { installSnapshot } from './install-snapshot' import fs from 'fs-extra' -const setupV8Snapshots = async (baseCypressAppPath?: string) => { +const setupV8Snapshots = async ({ cypressAppPath, integrityCheckSource }: { cypressAppPath?: string, integrityCheckSource?: string} = {}) => { try { const args = minimist(process.argv.slice(2)) - const config = createConfig(args.env, baseCypressAppPath) + const config = createConfig({ env: args.env, cypressAppPath, integrityCheckSource }) await consolidateDeps(config) diff --git a/tooling/v8-snapshot/src/setup/install-snapshot.ts b/tooling/v8-snapshot/src/setup/install-snapshot.ts index abdbd34e3939..3c71d7bb3d90 100644 --- a/tooling/v8-snapshot/src/setup/install-snapshot.ts +++ b/tooling/v8-snapshot/src/setup/install-snapshot.ts @@ -35,6 +35,7 @@ function getSnapshotGenerator ({ usePreviousSnapshotMetadata, resolverMap, minify, + integrityCheckSource, }: { nodeModulesOnly: boolean projectBaseDir: string @@ -44,6 +45,7 @@ function getSnapshotGenerator ({ usePreviousSnapshotMetadata: boolean resolverMap: Record minify: boolean + integrityCheckSource: string | undefined }) { const { previousNoRewrite, @@ -66,6 +68,7 @@ function getSnapshotGenerator ({ resolverMap, forceNoRewrite, minify, + integrityCheckSource, }) } @@ -87,6 +90,7 @@ export async function installSnapshot ( snapshotMetaPrevFile, usePreviousSnapshotMetadata, minify, + integrityCheckSource, }, resolverMap, ) { @@ -105,6 +109,7 @@ export async function installSnapshot ( usePreviousSnapshotMetadata, resolverMap, minify, + integrityCheckSource, }) await snapshotGenerator.createScript() diff --git a/tooling/v8-snapshot/src/types.ts b/tooling/v8-snapshot/src/types.ts index 999ef2106e57..19f8d332a229 100644 --- a/tooling/v8-snapshot/src/types.ts +++ b/tooling/v8-snapshot/src/types.ts @@ -85,6 +85,7 @@ export type CreateBundleOpts = { baseSourcemapExternalPath?: string processedSourcemapExternalPath?: string supportTypeScript: boolean + integrityCheckSource: string | undefined } /** @@ -121,6 +122,8 @@ export type ProcessScriptOpts = { nodeEnv: string supportTypeScript: boolean + + integrityCheckSource: string | undefined } /** diff --git a/yarn.lock b/yarn.lock index 684bbf3d4afb..4308a37f78d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11281,6 +11281,11 @@ byte-size@^5.0.1: resolved "https://registry.yarnpkg.com/byte-size/-/byte-size-5.0.1.tgz#4b651039a5ecd96767e71a3d7ed380e48bed4191" integrity sha512-/XuKeqWocKsYa/cBY1YbSJSWWqTi4cFgr9S6OyM7PBaPbr9zvNGwWP33vt0uqGhwDdN+y3yhbXVILEUpnwEWGw== +bytenode@^1.2.1: + version "1.3.6" + resolved "https://registry.yarnpkg.com/bytenode/-/bytenode-1.3.6.tgz#7195a78c5d98b8f50a640d10f9762e733213deea" + integrity sha512-t/e1psHP/r9ipj136i9FUOznv/9el1DcY7mB8nBM1FPDqYTvQY73J8uVwRPciWdKZzZrS5yxEyzNEEnB835Fyg== + bytes@1: version "1.0.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-1.0.0.tgz#3569ede8ba34315fab99c3e92cb04c7220de1fa8" From 7d65a96d0ccfb1187e4676965a57fcb38f9650a1 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 23 Nov 2022 22:27:51 -0600 Subject: [PATCH 02/54] fix: v8 improvements - run ci --- scripts/binary/binary-integrity-check-source.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index dc8e24a2e416..7342990faf22 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -16,8 +16,8 @@ function integrityCheck (options) { origError.prepareStackTrace = originalStackTrace options.stackToMatch.forEach((functionName, index) => { - if (stack[index].getFunctionName() !== functionName) { - throw new Error(`Integrity check failed at index ${ index } with function name ${ functionName } and expected function name ${ stack[index].getFunctionName()}`) + if (stack[index].getFunctionName() !== functionName || !['evalmachine.', ''].includes(stack[index].getFileName())) { + throw new Error(`Integrity check failed at index ${ index } with function name ${ functionName } and expected function name ${stack[index].getFunctionName()} from ${stack[index].getFileName()}`) } }) From fcfa789936071d01daf9088e2ba4cd306508d49d Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 16:05:20 -0600 Subject: [PATCH 03/54] lock things down even more --- .../binary/binary-integrity-check-source.js | 15 +++++++++------ scripts/binary/binary-integrity-check.js | 19 ++++++++++++------- .../v8-snapshot/src/blueprint/set-globals.js | 9 +++++++-- .../v8-snapshot/src/generator/blueprint.ts | 8 ++++++-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 7342990faf22..8fd9ae3463bc 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -1,7 +1,7 @@ const origError = Error // eslint-disable-next-line no-unused-vars -function integrityCheck (options) { +function stackIntegrityCheck (options) { const originalStackTrace = origError.prepareStackTrace origError.prepareStackTrace = function (_, stack) { @@ -20,26 +20,29 @@ function integrityCheck (options) { throw new Error(`Integrity check failed at index ${ index } with function name ${ functionName } and expected function name ${stack[index].getFunctionName()} from ${stack[index].getFileName()}`) } }) +} - const fs = require('fs') - const crypto = require('crypto') +// eslint-disable-next-line no-unused-vars +function fileIntegrityCheck (options) { + const fs = options.require('fs') + const crypto = options.require('crypto') // eslint-disable-next-line no-undef - const mainIndexHash = crypto.createHash('md5').update(fs.readFileSync(__resolve_path('./index.js'), 'utf8')).digest('hex') + const mainIndexHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(options.pathResolver.resolve('./index.js'), 'utf8')).digest('hex') if (mainIndexHash !== 'MAIN_INDEX_HASH') { throw new Error(`Integrity check failed for main index.js file`) } // eslint-disable-next-line no-undef - const bytenodeHash = crypto.createHash('md5').update(fs.readFileSync(__resolve_path('./node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') + const bytenodeHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(options.pathResolver.resolve('./node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') if (bytenodeHash !== 'BYTENODE_HASH') { throw new Error(`Integrity check failed for main bytenode.js file`) } // eslint-disable-next-line no-undef - const indexJscHash = crypto.createHash('md5').update(fs.readFileSync(__resolve_path('./packages/server/index.jsc'), 'utf8')).digest('hex') + const indexJscHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(options.pathResolver.resolve('./packages/server/index.jsc'), 'utf8')).digest('hex') if (indexJscHash !== 'INDEX_JSC_HASH') { throw new Error(`Integrity check failed for main server index.jsc file`) diff --git a/scripts/binary/binary-integrity-check.js b/scripts/binary/binary-integrity-check.js index 4352c46fa6a2..029a5472d3a4 100644 --- a/scripts/binary/binary-integrity-check.js +++ b/scripts/binary/binary-integrity-check.js @@ -2,15 +2,20 @@ const fs = require('fs') const crypto = require('crypto') const path = require('path') -function read ({ part, baseDirectory }) { - const p = require.resolve(`./${part}`) - const s = fs.readFileSync(p, 'utf8') +function read ({ file, baseDirectory }) { + const pathToFile = require.resolve(`./${file}`) + const fileSource = fs.readFileSync(pathToFile, 'utf8') + const secret = require('crypto').randomBytes(48).toString('hex') - const mainIndexHash = crypto.createHash('md5').update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') - const bytenodeHash = crypto.createHash('md5').update(fs.readFileSync(path.join(baseDirectory, './node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') - const indexJscHash = crypto.createHash('md5').update(fs.readFileSync(path.join(baseDirectory, './packages/server/index.jsc'), 'utf8')).digest('hex') + const mainIndexHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') + const bytenodeHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') + const indexJscHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './packages/server/index.jsc'), 'utf8')).digest('hex') - return s.split('\n').join(`\n `).replace('MAIN_INDEX_HASH', mainIndexHash).replace('BYTENODE_HASH', bytenodeHash).replace('INDEX_JSC_HASH', indexJscHash) + return fileSource.split('\n').join(`\n `) + .replaceAll('MAIN_INDEX_HASH', mainIndexHash) + .replaceAll('BYTENODE_HASH', bytenodeHash) + .replaceAll('INDEX_JSC_HASH', indexJscHash) + .replaceAll('HMAC_SECRET', secret) } const getIntegrityCheckSource = (baseDirectory) => { diff --git a/tooling/v8-snapshot/src/blueprint/set-globals.js b/tooling/v8-snapshot/src/blueprint/set-globals.js index 0704ce0c35ac..dd557cb0290c 100644 --- a/tooling/v8-snapshot/src/blueprint/set-globals.js +++ b/tooling/v8-snapshot/src/blueprint/set-globals.js @@ -15,6 +15,11 @@ function setGlobals ( newPathResolver, nodeRequire, ) { + if (typeof stackIntegrityCheck === 'function') { + // eslint-disable-next-line no-undef + stackIntegrityCheck({ stackToMatch: ['setGlobals', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) + } + // Populate the global function trampoline with the real global functions defined on newGlobal. globalFunctionTrampoline = newGlobal @@ -57,8 +62,8 @@ function setGlobals ( __pathResolver = newPathResolver require = nodeRequire - if (typeof integrityCheck === 'function') { + if (typeof fileIntegrityCheck === 'function') { // eslint-disable-next-line no-undef - integrityCheck({ stackToMatch: ['setGlobals', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) + fileIntegrityCheck({ require, pathResolver: __pathResolver }) } } diff --git a/tooling/v8-snapshot/src/generator/blueprint.ts b/tooling/v8-snapshot/src/generator/blueprint.ts index 151f9128dcc8..b11e51260f69 100644 --- a/tooling/v8-snapshot/src/generator/blueprint.ts +++ b/tooling/v8-snapshot/src/generator/blueprint.ts @@ -112,6 +112,8 @@ export function scriptFromBlueprint (config: BlueprintConfig): { const PATH_SEP = '${pathSep}' var snapshotAuxiliaryData = ${auxiliaryData} +${integrityCheckSource || ''} + function generateSnapshot() { // // @@ -171,8 +173,6 @@ function generateSnapshot() { ${customRequire} ${includeStrictVerifiers ? 'require.isStrict = true' : ''} - ${integrityCheckSource || ''} - customRequire(${normalizedMainModuleRequirePath}, ${normalizedMainModuleRequirePath}) const result = {} Object.defineProperties(result, { @@ -192,6 +192,10 @@ const snapshotResult = generateSnapshot.call({}) Object.defineProperty(this, 'getSnapshotResult', { writable: false, value: function () { + if (typeof stackIntegrityCheck === 'function') { + // eslint-disable-next-line no-undef + stackIntegrityCheck({ stackToMatch: ['value', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) + } return snapshotResult }, }) From 90c96c6f62be8406312b1c5028d4159722a041d6 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 16:37:42 -0600 Subject: [PATCH 04/54] Fix build --- packages/server/package.json | 1 + packages/server/snapshot-entry.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 packages/server/snapshot-entry.js diff --git a/packages/server/package.json b/packages/server/package.json index 81f342bef244..89d544152570 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -197,6 +197,7 @@ "lib", "patches", "server-entry.js", + "snapshot-entry.js", "hook-require.js" ], "types": "index.d.ts", diff --git a/packages/server/snapshot-entry.js b/packages/server/snapshot-entry.js new file mode 100644 index 000000000000..75233dfffa64 --- /dev/null +++ b/packages/server/snapshot-entry.js @@ -0,0 +1 @@ +require('./server-entry') From 54931776f294f2ec05366868bd42ed46269e77ff Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 19:46:06 -0600 Subject: [PATCH 05/54] fix build --- scripts/binary/binary-integrity-check.js | 2 +- tooling/v8-snapshot/test/utils/bundle.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/binary/binary-integrity-check.js b/scripts/binary/binary-integrity-check.js index 029a5472d3a4..aea686ac5eb6 100644 --- a/scripts/binary/binary-integrity-check.js +++ b/scripts/binary/binary-integrity-check.js @@ -19,7 +19,7 @@ function read ({ file, baseDirectory }) { } const getIntegrityCheckSource = (baseDirectory) => { - return read({ part: 'binary-integrity-check-source.js', baseDirectory }) + return read({ file: 'binary-integrity-check-source.js', baseDirectory }) } module.exports = { diff --git a/tooling/v8-snapshot/test/utils/bundle.ts b/tooling/v8-snapshot/test/utils/bundle.ts index b7a18eed6900..642dff6d7106 100644 --- a/tooling/v8-snapshot/test/utils/bundle.ts +++ b/tooling/v8-snapshot/test/utils/bundle.ts @@ -20,7 +20,7 @@ export function readSnapshotResult (cacheDir: string) { const sourcemapComment = snapshotFileContent.split('\n').pop() const { snapshotResult, snapshotAuxiliaryData } = eval( - `(function () {\n${snapshotFileContent};\n return { snapshotResult, snapshotAuxiliaryData };})()`, + `(function () {\n${snapshotFileContent};\n return { snapshotResult, snapshotAuxiliaryData };}).bind({})()`, ) return { meta, snapshotResult, snapshotAuxiliaryData, sourcemapComment } From 474b3a4d947d26e0e60ac6325771ed0637e6d585 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 20:25:24 -0600 Subject: [PATCH 06/54] add memory for packaging --- scripts/binary/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 53ff06f41f98..365de3253ea1 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -263,7 +263,7 @@ require('./packages/server/index.js') await execa('electron-builder', args, { stdio: 'inherit', env: { - NODE_OPTIONS: '--max_old_space_size=8192', + NODE_OPTIONS: '--max_old_space_size=16384', }, }) } catch (e) { From e6cde793c343f3967ed7e519838dac6f65adeb54 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 20:54:19 -0600 Subject: [PATCH 07/54] additional tweaking --- .circleci/config.yml | 10 +++++----- scripts/binary/binary-cleanup.js | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 545b328b2e8e..cb6466a3ee13 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ mainBuildFilters: &mainBuildFilters branches: only: - develop - - 'feature/run-all-specs' + - 'ryanm/fix/v8-improvements' # 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 @@ -36,7 +36,7 @@ macWorkflowFilters: &darwin-workflow-filters when: or: - equal: [ develop, << pipeline.git.branch >> ] - - equal: [ 'feature/run-all-specs', << pipeline.git.branch >> ] + - equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ] - matches: pattern: "-release$" value: << pipeline.git.branch >> @@ -45,7 +45,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters when: or: - equal: [ develop, << pipeline.git.branch >> ] - - equal: [ 'feature/run-all-specs', << pipeline.git.branch >> ] + - equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ] - matches: pattern: "-release$" value: << pipeline.git.branch >> @@ -63,7 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters when: or: - equal: [ develop, << pipeline.git.branch >> ] - - equal: [ 'feature/run-all-specs', << pipeline.git.branch >> ] + - equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ] - matches: pattern: "-release$" value: << pipeline.git.branch >> @@ -130,7 +130,7 @@ commands: - run: name: Check current branch to persist artifacts command: | - if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "feature/run-all-specs" ]]; then + if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "ryanm/fix/v8-improvements" ]]; then echo "Not uploading artifacts or posting install comment for this branch." circleci-agent step halt fi diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index db8fc44ce7a9..11052ae083fb 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -131,9 +131,10 @@ const createServerEntryPointBundle = async (buildAppDir) => { console.log(`copying server entry point bundle from ${path.join(workingDir, 'index.js')} to ${path.join(buildAppDir, 'packages', 'server', 'index.js')}`) - await fs.copy(path.join(workingDir, 'index.js'), path.join(buildAppDir, 'packages', 'server', 'backup.js')) await fs.copy(path.join(workingDir, 'index.js'), path.join(buildAppDir, 'packages', 'server', 'index.js')) + console.log(`compiling server entry point bundle to ${path.join(buildAppDir, 'packages', 'server', 'index.jsc')}`) + await bytenode.compileFile({ filename: path.join(buildAppDir, 'packages', 'server', 'index.js'), output: path.join(buildAppDir, 'packages', 'server', 'index.jsc'), From ac5ebdc443839068c6fd5ef1e04664fd6041d44d Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 21:14:58 -0600 Subject: [PATCH 08/54] debug logging --- package.json | 2 +- scripts/binary/binary-cleanup.js | 2 ++ yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index dcc0e867b84d..dea83430a766 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "prepare": "husky install" }, "dependencies": { - "bytenode": "^1.2.1", + "bytenode": "1.3.7", "nvm": "0.0.4" }, "devDependencies": { diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index 11052ae083fb..b0d9afd0f773 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -157,6 +157,8 @@ const cleanup = async (buildAppDir) => { ...await createServerEntryPointBundle(buildAppDir), ] + console.log(`potentially removing ${potentiallyRemovedDependencies.length} dependencies`) + // 3. Remove all dependencies that are in the snapshot but not in the list of kept dependencies from the binary await Promise.all(potentiallyRemovedDependencies.map(async (dependency) => { const typeScriptlessDependency = dependency.replace(/\.ts$/, '.js') diff --git a/yarn.lock b/yarn.lock index 4308a37f78d8..5f99e8dc51ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11281,10 +11281,10 @@ byte-size@^5.0.1: resolved "https://registry.yarnpkg.com/byte-size/-/byte-size-5.0.1.tgz#4b651039a5ecd96767e71a3d7ed380e48bed4191" integrity sha512-/XuKeqWocKsYa/cBY1YbSJSWWqTi4cFgr9S6OyM7PBaPbr9zvNGwWP33vt0uqGhwDdN+y3yhbXVILEUpnwEWGw== -bytenode@^1.2.1: - version "1.3.6" - resolved "https://registry.yarnpkg.com/bytenode/-/bytenode-1.3.6.tgz#7195a78c5d98b8f50a640d10f9762e733213deea" - integrity sha512-t/e1psHP/r9ipj136i9FUOznv/9el1DcY7mB8nBM1FPDqYTvQY73J8uVwRPciWdKZzZrS5yxEyzNEEnB835Fyg== +bytenode@1.3.7: + version "1.3.7" + resolved "https://registry.yarnpkg.com/bytenode/-/bytenode-1.3.7.tgz#72b1426d08910ff0731099e4f40ee2929174ae34" + integrity sha512-TKvemYL2VJQIBE095FIYudjTsLagVBLpKXIYj+MaDUgzhdNL74SM1bizcXgwQs51mnXyO38tlqusDZqY8/XdTQ== bytes@1: version "1.0.0" From 25b870cd3863780eca3a7d373a640be605d5c780 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 21:27:53 -0600 Subject: [PATCH 09/54] debugging --- scripts/binary/build.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 365de3253ea1..883aade00b1e 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -264,6 +264,7 @@ require('./packages/server/index.js') stdio: 'inherit', env: { NODE_OPTIONS: '--max_old_space_size=16384', + DEBUG: 'cypress:snapgen:info', }, }) } catch (e) { From 968e72660d802e67bb1736fc61c0fc485d33b1db Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 22:16:19 -0600 Subject: [PATCH 10/54] code cleanup --- scripts/binary/binary-integrity-check-source.js | 2 +- scripts/binary/build.ts | 2 +- tooling/v8-snapshot/src/blueprint/set-globals.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 8fd9ae3463bc..cdf02292fe42 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -17,7 +17,7 @@ function stackIntegrityCheck (options) { options.stackToMatch.forEach((functionName, index) => { if (stack[index].getFunctionName() !== functionName || !['evalmachine.', ''].includes(stack[index].getFileName())) { - throw new Error(`Integrity check failed at index ${ index } with function name ${ functionName } and expected function name ${stack[index].getFunctionName()} from ${stack[index].getFileName()}`) + throw new Error(`Integrity check failed at index ${ index } with function name ${stack[index].getFunctionName()} and expected function name ${functionName} from ${stack[index].getFileName()}`) } }) } diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 883aade00b1e..ebaa3fd12350 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -263,7 +263,7 @@ require('./packages/server/index.js') await execa('electron-builder', args, { stdio: 'inherit', env: { - NODE_OPTIONS: '--max_old_space_size=16384', + NODE_OPTIONS: '--max_old_space_size=32768', DEBUG: 'cypress:snapgen:info', }, }) diff --git a/tooling/v8-snapshot/src/blueprint/set-globals.js b/tooling/v8-snapshot/src/blueprint/set-globals.js index dd557cb0290c..8450b2229912 100644 --- a/tooling/v8-snapshot/src/blueprint/set-globals.js +++ b/tooling/v8-snapshot/src/blueprint/set-globals.js @@ -17,7 +17,7 @@ function setGlobals ( ) { if (typeof stackIntegrityCheck === 'function') { // eslint-disable-next-line no-undef - stackIntegrityCheck({ stackToMatch: ['setGlobals', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) + stackIntegrityCheck({ stackToMatch: ['value', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) } // Populate the global function trampoline with the real global functions defined on newGlobal. From 51426dd7a43d4db1a0415e8b6fbe65a5d81b0e85 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 27 Nov 2022 22:48:54 -0600 Subject: [PATCH 11/54] fix build --- scripts/binary/build.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index ebaa3fd12350..db256a1e45e7 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -260,9 +260,10 @@ require('./packages/server/index.js') fs.writeFileSync(meta.distDir('index.js'), fs.readFileSync(meta.distDir('index.js'), 'utf8').replace('server/index.js', 'server/index.jsc')) try { - await execa('electron-builder', args, { + execSync(`electron-builder ${args.join(' ')}`, { stdio: 'inherit', env: { + ...process.env, NODE_OPTIONS: '--max_old_space_size=32768', DEBUG: 'cypress:snapgen:info', }, From c071402cb47572aae77170101e56d1577fb17e43 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 28 Nov 2022 08:43:02 -0600 Subject: [PATCH 12/54] use api rather than command line --- scripts/binary/build.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index db256a1e45e7..0fe0cc78b57d 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -19,6 +19,7 @@ import execa from 'execa' import { testStaticAssets } from './util/testStaticAssets' import performanceTracking from '../../system-tests/lib/performance' import verify from '../../cli/lib/tasks/verify' +import * as electronBuilder from 'electron-builder' const globAsync = promisify(glob) @@ -260,12 +261,16 @@ require('./packages/server/index.js') fs.writeFileSync(meta.distDir('index.js'), fs.readFileSync(meta.distDir('index.js'), 'utf8').replace('server/index.js', 'server/index.jsc')) try { - execSync(`electron-builder ${args.join(' ')}`, { - stdio: 'inherit', - env: { - ...process.env, - NODE_OPTIONS: '--max_old_space_size=32768', - DEBUG: 'cypress:snapgen:info', + await electronBuilder.build({ + publish: 'never', + config: { + electronVersion, + directories: { + app: appFolder, + output: outputFolder, + }, + icon: iconFilename, + asar: false, }, }) } catch (e) { From 8ab76e623a8eef8c4d72892fa86dd8d1a01ae3e2 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 28 Nov 2022 09:08:58 -0600 Subject: [PATCH 13/54] bump memory --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index dea83430a766..59b6388d055b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Cypress is a next generation front end testing tool built for the modern web", "private": true, "scripts": { - "binary-build": "node ./scripts/binary.js build", + "binary-build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node ./scripts/binary.js build", "binary-deploy": "node ./scripts/binary.js deploy", "binary-deploy-linux": "./scripts/build-linux-binary.sh", "binary-ensure": "node ./scripts/binary.js ensure", @@ -141,6 +141,7 @@ "commander": "6.2.1", "common-tags": "1.8.0", "conventional-recommended-bump": "6.1.0", + "cross-env": "7.0.3", "debug": "^4.3.2", "dedent": "^0.7.0", "del": "3.0.0", From b4e22614e0f62cfd40407e17e8a790b0b8430d9d Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 28 Nov 2022 14:30:03 -0600 Subject: [PATCH 14/54] fix linux arm64 issue --- scripts/after-pack-hook.js | 1 + scripts/binary/build.ts | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index 83cb7fb03914..94620a21a9b4 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -56,6 +56,7 @@ module.exports = async function (params) { } if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) { + await fs.writeFile(path.join(outputFolder, 'index.js'), await fs.readFile(path.join(outputFolder, 'index.js'), 'utf8').replace('server/index.js', 'server/index.jsc')) await flipFuses( exePathPerPlatform[os.platform()], { diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 0fe0cc78b57d..2abd5112ceee 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -258,8 +258,6 @@ require('./packages/server/index.js') version, }, { spaces: 2 }) - fs.writeFileSync(meta.distDir('index.js'), fs.readFileSync(meta.distDir('index.js'), 'utf8').replace('server/index.js', 'server/index.jsc')) - try { await electronBuilder.build({ publish: 'never', From df39189ad385e993117e8529bb061b9260bbde86 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 28 Nov 2022 15:18:07 -0600 Subject: [PATCH 15/54] fix build --- scripts/after-pack-hook.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index 94620a21a9b4..e233097daf89 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -56,7 +56,9 @@ module.exports = async function (params) { } if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) { - await fs.writeFile(path.join(outputFolder, 'index.js'), await fs.readFile(path.join(outputFolder, 'index.js'), 'utf8').replace('server/index.js', 'server/index.jsc')) + const indexFileContents = await fs.readFile(path.join(outputFolder, 'index.js'), 'utf8') + + await fs.writeFile(path.join(outputFolder, 'index.js'), indexFileContents.replace('server/index.js', 'server/index.jsc')) await flipFuses( exePathPerPlatform[os.platform()], { From 239a9539fb561766ffe575023a28964cc194ccd1 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 11:51:31 -0600 Subject: [PATCH 16/54] harden some of the logic --- packages/server/index.js | 14 +- scripts/after-pack-hook.js | 22 ++- .../binary/binary-integrity-check-source.js | 133 +++++++++++++++--- scripts/binary/binary-integrity-check.js | 6 + scripts/binary/build.ts | 2 +- scripts/binary/smoke.js | 65 ++++++++- .../v8-snapshot/src/blueprint/set-globals.js | 92 ++++++------ .../v8-snapshot/src/generator/blueprint.ts | 7 +- 8 files changed, 270 insertions(+), 71 deletions(-) diff --git a/packages/server/index.js b/packages/server/index.js index f3a5dde6a2e9..572417ec7ff9 100644 --- a/packages/server/index.js +++ b/packages/server/index.js @@ -1,13 +1,19 @@ const { initializeStartTime } = require('./lib/util/performance_benchmark') const run = async () => { - initializeStartTime() + try { + initializeStartTime() - const { hookRequire } = require('./hook-require') + const { hookRequire } = require('./hook-require') - hookRequire({ forceTypeScript: false }) + hookRequire({ forceTypeScript: false }) - await require('./server-entry') + await require('./server-entry') + } catch (error) { + // eslint-disable-next-line no-console + console.error(error) + process.exit(1) + } } module.exports = run() diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index e233097daf89..0824e956c8eb 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -56,9 +56,27 @@ module.exports = async function (params) { } if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) { - const indexFileContents = await fs.readFile(path.join(outputFolder, 'index.js'), 'utf8') + await fs.writeFile(path.join(outputFolder, 'index.js'), `const Module = require('module') +const path = require('path') + +process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production' +try { + require('./node_modules/bytenode/lib/index.js') + const filename = path.join(__dirname, 'packages', 'server', 'index.jsc') + Module._extensions['.jsc']({ + require: module.require, + id: filename, + filename, + loaded: false, + path: path.dirname(filename), + paths: Module._nodeModulePaths(path.dirname(filename)) + }, filename) +} catch (error) { + console.error(error) + process.exit(1) +} +`) - await fs.writeFile(path.join(outputFolder, 'index.js'), indexFileContents.replace('server/index.js', 'server/index.jsc')) await flipFuses( exePathPerPlatform[os.platform()], { diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index cdf02292fe42..d228f156aa94 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -1,48 +1,147 @@ -const origError = Error +const OrigError = Error +const captureStackTrace = Error.captureStackTrace // eslint-disable-next-line no-unused-vars -function stackIntegrityCheck (options) { - const originalStackTrace = origError.prepareStackTrace +const stackIntegrityCheck = function stackIntegrityCheck (options) { + const originalStackTrace = OrigError.prepareStackTrace - origError.prepareStackTrace = function (_, stack) { + OrigError.prepareStackTrace = function (_, stack) { return stack } - const tempError = new origError + const tempError = new OrigError - origError.captureStackTrace(tempError, arguments.callee) - let stack = tempError.stack + captureStackTrace(tempError, arguments.callee) + const stack = tempError.stack - origError.prepareStackTrace = originalStackTrace + OrigError.prepareStackTrace = originalStackTrace - options.stackToMatch.forEach((functionName, index) => { - if (stack[index].getFunctionName() !== functionName || !['evalmachine.', ''].includes(stack[index].getFileName())) { - throw new Error(`Integrity check failed at index ${ index } with function name ${stack[index].getFunctionName()} and expected function name ${functionName} from ${stack[index].getFileName()}`) + if (stack.length !== options.stackToMatch.length) { + throw new Error(`Integrity check failed with expected stack length ${options.stackToMatch.length} but got ${stack.length}`) + } + + for (let index = 0; index < options.stackToMatch.length; index++) { + const expectedFunctionName = options.stackToMatch[index].functionName + const actualFunctionName = stack[index].getFunctionName() + const expectedFileName = options.stackToMatch[index].fileName + const actualFileName = stack[index].getFileName() + + if (expectedFunctionName && !actualFunctionName.endsWith(expectedFunctionName)) { + throw new Error(`Integrity check failed with expected function name ${expectedFunctionName} but got ${actualFunctionName}`) } - }) + + if (!actualFileName.endsWith(expectedFileName)) { + throw new Error(`Integrity check failed with expected file name ${expectedFileName} but got ${actualFileName}`) + } + } +} + +function validateElectron (electron) { + if (electron.app.getAppPath.toString() !== 'function getAppPath() { [native code] }') { + throw new Error(`Integrity check failed for electron.app.getAppPath.toString()`) + } +} + +function validateFs (fs) { + if (fs.readFileSync.toString() !== `function(t,r){const n=splitPath(t);if(!n.isAsar)return g.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const t=o.copyFileOut(a);return e.readFileSync(t,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),e.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) { + throw new Error(`Integrity check failed for fs.readFileSync.toString()`) + } +} + +function validatePath (path) { + if (path.join.toString() !== `PATH_JOIN_TO_STRING`) { + throw new Error(`Integrity check failed for path.join.toString()`) + } +} + +function validateCrypto (crypto) { + if (crypto.createHmac.toString() !== `CRYPTO_CREATE_HMAC_TO_STRING`) { + throw new Error(`Integrity check failed for crypto.createHmac.toString()`) + } + + if (crypto.Hmac.prototype.update.toString() !== `CRYPTO_HMAC_UPDATE_TO_STRING`) { + throw new Error(`Integrity check failed for crypto.Hmac.prototype.update.toString()`) + } + + if (crypto.Hmac.prototype.digest.toString() !== `CRYPTO_HMAC_DIGEST_TO_STRING`) { + throw new Error(`Integrity check failed for crypto.Hmac.prototype.digest.toString()`) + } } // eslint-disable-next-line no-unused-vars function fileIntegrityCheck (options) { - const fs = options.require('fs') - const crypto = options.require('crypto') + const require = options.require + const electron = require('electron') + const fs = require('fs') + const path = require('path') + const crypto = require('crypto') + + validateElectron(electron) + validateFs(fs) + validatePath(path) + validateCrypto(crypto) + + const appPath = electron.app.getAppPath() + + stackIntegrityCheck({ stackToMatch: + [ + { + functionName: 'fileIntegrityCheck', + fileName: '', + }, + { + functionName: 'setGlobals', + fileName: '', + }, + { + functionName: 'snapshotRequire', + fileName: 'evalmachine.', + }, + { + functionName: 'runWithSnapshot', + fileName: 'evalmachine.', + }, + { + functionName: 'hookRequire', + fileName: 'evalmachine.', + }, + { + functionName: 'run', + fileName: 'evalmachine.', + }, + { + fileName: 'evalmachine.', + }, + { + functionName: 'Module._extensions.', + fileName: path.join(appPath, 'node_modules', 'bytenode', 'lib', 'index.js'), + }, + { + fileName: path.join(appPath, 'index.js'), + }, + { + functionName: 'Module._compile', + fileName: 'node:internal/modules/cjs/loader', + }, + ], + }) // eslint-disable-next-line no-undef - const mainIndexHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(options.pathResolver.resolve('./index.js'), 'utf8')).digest('hex') + const mainIndexHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(path.join(appPath, 'index.js'), 'utf8')).digest('hex') if (mainIndexHash !== 'MAIN_INDEX_HASH') { throw new Error(`Integrity check failed for main index.js file`) } // eslint-disable-next-line no-undef - const bytenodeHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(options.pathResolver.resolve('./node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') + const bytenodeHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(path.join(appPath, 'node_modules', 'bytenode', 'lib', 'index.js'), 'utf8')).digest('hex') if (bytenodeHash !== 'BYTENODE_HASH') { throw new Error(`Integrity check failed for main bytenode.js file`) } // eslint-disable-next-line no-undef - const indexJscHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(options.pathResolver.resolve('./packages/server/index.jsc'), 'utf8')).digest('hex') + const indexJscHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(path.join(appPath, 'packages', 'server', 'index.jsc'), 'utf8')).digest('hex') if (indexJscHash !== 'INDEX_JSC_HASH') { throw new Error(`Integrity check failed for main server index.jsc file`) diff --git a/scripts/binary/binary-integrity-check.js b/scripts/binary/binary-integrity-check.js index aea686ac5eb6..52709b6a8cd0 100644 --- a/scripts/binary/binary-integrity-check.js +++ b/scripts/binary/binary-integrity-check.js @@ -2,6 +2,8 @@ const fs = require('fs') const crypto = require('crypto') const path = require('path') +const escapeString = (string) => string.replaceAll(`\``, `\\\``).replaceAll(`$`, `\\$`) + function read ({ file, baseDirectory }) { const pathToFile = require.resolve(`./${file}`) const fileSource = fs.readFileSync(pathToFile, 'utf8') @@ -16,6 +18,10 @@ function read ({ file, baseDirectory }) { .replaceAll('BYTENODE_HASH', bytenodeHash) .replaceAll('INDEX_JSC_HASH', indexJscHash) .replaceAll('HMAC_SECRET', secret) + .replaceAll('PATH_JOIN_TO_STRING', escapeString(path.join.toString())) + .replaceAll('CRYPTO_CREATE_HMAC_TO_STRING', escapeString(crypto.createHmac.toString())) + .replaceAll('CRYPTO_HMAC_UPDATE_TO_STRING', escapeString(crypto.Hmac.prototype.update.toString())) + .replaceAll('CRYPTO_HMAC_DIGEST_TO_STRING', escapeString(crypto.Hmac.prototype.digest.toString())) } const getIntegrityCheckSource = (baseDirectory) => { diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 2abd5112ceee..43c04cfc16b3 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -302,7 +302,7 @@ require('./packages/server/index.js') const executablePath = meta.buildAppExecutable() - await smoke.test(executablePath) + await smoke.test(executablePath, meta.buildAppDir()) } finally { if (usingXvfb) { await xvfb.stop() diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 72b17b259991..2b8d6511165f 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -201,7 +201,69 @@ const runV8SnapshotProjectTest = function (buildAppExecutable, e2e) { return spawn() } -const test = async function (buildAppExecutable) { +const runErroringProjectTest = function (buildAppExecutable, e2e) { + if (shouldSkipProjectTest()) { + console.log('skipping project test') + + return Promise.resolve() + } + + return new Promise((resolve, reject) => { + const env = _.omit(process.env, 'CYPRESS_INTERNAL_ENV') + + if (!canRecordVideo()) { + console.log('cannot record video on this platform yet, disabling') + env.CYPRESS_VIDEO_RECORDING = 'false' + } + + const args = [ + `--run-project=${e2e}`, + `--spec=${e2e}/cypress/e2e/simple_passing.cy.js`, + ] + + if (verify.needsSandbox()) { + args.push('--no-sandbox') + } + + const options = { + stdio: 'inherit', env, + } + + console.log('running project test') + console.log(buildAppExecutable, args.join(' ')) + + return cp.spawn(buildAppExecutable, args, options) + .on('exit', (code) => { + if (code === 0) { + return reject(new Error('running project tests should have failed')) + } + + return resolve() + }) + }) +} + +const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { + if (shouldSkipProjectTest()) { + console.log('skipping failing project test') + + return + } + + const testFile = async (file) => { + const contents = await fs.readFile(file) + + await fs.writeFile(file, `console.log('modified code')\n${contents}`) + await runErroringProjectTest(buildAppExecutable, e2e) + await fs.writeFile(file, contents) + } + + await testFile(path.join(buildAppDir, 'index.js')) + await testFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc')) + await testFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js')) +} + +const test = async function (buildAppExecutable, buildAppDir) { await scaffoldCommonNodeModules() await Fixtures.scaffoldProject('e2e') const e2e = Fixtures.projectPath('e2e') @@ -209,6 +271,7 @@ const test = async function (buildAppExecutable) { await runSmokeTest(buildAppExecutable) await runProjectTest(buildAppExecutable, e2e) await runFailingProjectTest(buildAppExecutable, e2e) + await runIntegrityTest(buildAppExecutable, buildAppDir, e2e) if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) { await runV8SnapshotProjectTest(buildAppExecutable, e2e) } diff --git a/tooling/v8-snapshot/src/blueprint/set-globals.js b/tooling/v8-snapshot/src/blueprint/set-globals.js index 8450b2229912..ce70612cfba4 100644 --- a/tooling/v8-snapshot/src/blueprint/set-globals.js +++ b/tooling/v8-snapshot/src/blueprint/set-globals.js @@ -5,65 +5,71 @@ * Replaces globals that have been stubbed during snapshot creation with the * instances that are present in the app on startup. */ + // eslint-disable-next-line no-unused-vars -function setGlobals ( - newGlobal, - newProcess, - newWindow, - newDocument, - newConsole, - newPathResolver, - nodeRequire, -) { - if (typeof stackIntegrityCheck === 'function') { - // eslint-disable-next-line no-undef - stackIntegrityCheck({ stackToMatch: ['value', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) - } +(function () { + let numberOfSetGlobalsCalls = 0 - // Populate the global function trampoline with the real global functions defined on newGlobal. - globalFunctionTrampoline = newGlobal + return function setGlobals ( + newGlobal, + newProcess, + newWindow, + newDocument, + newConsole, + newPathResolver, + nodeRequire, + ) { + if (numberOfSetGlobalsCalls > 0) { + throw new Error('setGlobals should only be called once') + } - for (let key of Object.keys(global)) { - newGlobal[key] = global[key] - } + numberOfSetGlobalsCalls++ - global = newGlobal + // Populate the global function trampoline with the real global functions defined on newGlobal. + globalFunctionTrampoline = newGlobal - if (typeof newProcess !== 'undefined') { - for (let key of Object.keys(process)) { - newProcess[key] = process[key] + for (let key of Object.keys(global)) { + newGlobal[key] = global[key] } - } - process = newProcess + global = newGlobal - if (typeof newWindow !== 'undefined') { - for (let key of Object.keys(window)) { - newWindow[key] = window[key] + if (typeof newProcess !== 'undefined') { + for (let key of Object.keys(process)) { + newProcess[key] = process[key] + } } - } - window = newWindow + process = newProcess - if (typeof newDocument !== 'undefined') { - for (let key of Object.keys(document)) { - newDocument[key] = document[key] + if (typeof newWindow !== 'undefined') { + for (let key of Object.keys(window)) { + newWindow[key] = window[key] + } + } + + window = newWindow + + if (typeof newDocument !== 'undefined') { + for (let key of Object.keys(document)) { + newDocument[key] = document[key] + } } - } - document = newDocument + document = newDocument - for (let key of Object.keys(console)) { + for (let key of Object.keys(console)) { // eslint-disable-next-line no-console - newConsole[key] = console[key] - } + newConsole[key] = console[key] + } - console = newConsole - __pathResolver = newPathResolver - require = nodeRequire + console = newConsole + __pathResolver = newPathResolver + require = nodeRequire - if (typeof fileIntegrityCheck === 'function') { + if (typeof fileIntegrityCheck === 'function') { // eslint-disable-next-line no-undef - fileIntegrityCheck({ require, pathResolver: __pathResolver }) + fileIntegrityCheck({ require, pathResolver: __pathResolver }) + } } -} +})() diff --git a/tooling/v8-snapshot/src/generator/blueprint.ts b/tooling/v8-snapshot/src/generator/blueprint.ts index b11e51260f69..89cc9eb347a5 100644 --- a/tooling/v8-snapshot/src/generator/blueprint.ts +++ b/tooling/v8-snapshot/src/generator/blueprint.ts @@ -188,14 +188,15 @@ function generateSnapshot() { return result } +let numberOfGetSnapshotResultCalls = 0 const snapshotResult = generateSnapshot.call({}) Object.defineProperty(this, 'getSnapshotResult', { writable: false, value: function () { - if (typeof stackIntegrityCheck === 'function') { - // eslint-disable-next-line no-undef - stackIntegrityCheck({ stackToMatch: ['value', 'snapshotRequire', 'runWithSnapshot', 'hookRequire', 'run'] }) + if (numberOfGetSnapshotResultCalls > 0) { + throw new Error('getSnapshotResult can only be called once') } + numberOfGetSnapshotResultCalls++ return snapshotResult }, }) From b4f81190e5b0e2efd94df3c0a3b5411fb2b065a8 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 14:44:55 -0600 Subject: [PATCH 17/54] minor refactoring --- scripts/after-pack-hook.js | 23 ++------------ scripts/binary/binary-entry-point-source.js | 21 +++++++++++++ .../binary/binary-integrity-check-source.js | 21 +++++++++---- ...y-integrity-check.js => binary-sources.js} | 18 +++++++---- scripts/binary/smoke.js | 30 ++++++++++++++----- 5 files changed, 73 insertions(+), 40 deletions(-) create mode 100644 scripts/binary/binary-entry-point-source.js rename scripts/binary/{binary-integrity-check.js => binary-sources.js} (84%) diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index 0824e956c8eb..9ffc327cfb4b 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -7,7 +7,7 @@ const path = require('path') const { setupV8Snapshots } = require('@tooling/v8-snapshot') const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses') const { cleanup } = require('./binary/binary-cleanup') -const { getIntegrityCheckSource } = require('./binary/binary-integrity-check') +const { getIntegrityCheckSource, getBinaryEntryPointSource } = require('./binary/binary-sources') module.exports = async function (params) { console.log('****************************') @@ -56,26 +56,7 @@ module.exports = async function (params) { } if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) { - await fs.writeFile(path.join(outputFolder, 'index.js'), `const Module = require('module') -const path = require('path') - -process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production' -try { - require('./node_modules/bytenode/lib/index.js') - const filename = path.join(__dirname, 'packages', 'server', 'index.jsc') - Module._extensions['.jsc']({ - require: module.require, - id: filename, - filename, - loaded: false, - path: path.dirname(filename), - paths: Module._nodeModulePaths(path.dirname(filename)) - }, filename) -} catch (error) { - console.error(error) - process.exit(1) -} -`) + await fs.writeFile(path.join(outputFolder, 'index.js'), getBinaryEntryPointSource()) await flipFuses( exePathPerPlatform[os.platform()], diff --git a/scripts/binary/binary-entry-point-source.js b/scripts/binary/binary-entry-point-source.js new file mode 100644 index 000000000000..ddf0469eeebf --- /dev/null +++ b/scripts/binary/binary-entry-point-source.js @@ -0,0 +1,21 @@ +const Module = require('module') +const path = require('path') + +process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production' +try { + require('./node_modules/bytenode/lib/index.js') + const filename = path.join(__dirname, 'packages', 'server', 'index.jsc') + const dirname = path.dirname(filename) + + Module._extensions['.jsc']({ + require: module.require, + id: filename, + filename, + loaded: false, + path: dirname, + paths: Module._nodeModulePaths(dirname), + }, filename) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index d228f156aa94..ee38b4e04658 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -1,5 +1,7 @@ const OrigError = Error const captureStackTrace = Error.captureStackTrace +const toString = Function.prototype.toString +const callFn = Function.call // eslint-disable-next-line no-unused-vars const stackIntegrityCheck = function stackIntegrityCheck (options) { @@ -36,34 +38,40 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { } } +function validateToString () { + if (toString.call !== callFn) { + throw new Error('Integrity check failed for toString.call') + } +} + function validateElectron (electron) { - if (electron.app.getAppPath.toString() !== 'function getAppPath() { [native code] }') { + if (toString.call(electron.app.getAppPath) !== 'function getAppPath() { [native code] }') { throw new Error(`Integrity check failed for electron.app.getAppPath.toString()`) } } function validateFs (fs) { - if (fs.readFileSync.toString() !== `function(t,r){const n=splitPath(t);if(!n.isAsar)return g.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const t=o.copyFileOut(a);return e.readFileSync(t,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),e.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) { + if (toString.call(fs.readFileSync) !== `function(t,r){const n=splitPath(t);if(!n.isAsar)return g.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const t=o.copyFileOut(a);return e.readFileSync(t,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),e.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) { throw new Error(`Integrity check failed for fs.readFileSync.toString()`) } } function validatePath (path) { - if (path.join.toString() !== `PATH_JOIN_TO_STRING`) { + if (toString.call(path.join) !== `PATH_JOIN_TO_STRING`) { throw new Error(`Integrity check failed for path.join.toString()`) } } function validateCrypto (crypto) { - if (crypto.createHmac.toString() !== `CRYPTO_CREATE_HMAC_TO_STRING`) { + if (toString.call(crypto.createHmac) !== `CRYPTO_CREATE_HMAC_TO_STRING`) { throw new Error(`Integrity check failed for crypto.createHmac.toString()`) } - if (crypto.Hmac.prototype.update.toString() !== `CRYPTO_HMAC_UPDATE_TO_STRING`) { + if (toString.call(crypto.Hmac.prototype.update) !== `CRYPTO_HMAC_UPDATE_TO_STRING`) { throw new Error(`Integrity check failed for crypto.Hmac.prototype.update.toString()`) } - if (crypto.Hmac.prototype.digest.toString() !== `CRYPTO_HMAC_DIGEST_TO_STRING`) { + if (toString.call(crypto.Hmac.prototype.digest) !== `CRYPTO_HMAC_DIGEST_TO_STRING`) { throw new Error(`Integrity check failed for crypto.Hmac.prototype.digest.toString()`) } } @@ -76,6 +84,7 @@ function fileIntegrityCheck (options) { const path = require('path') const crypto = require('crypto') + validateToString() validateElectron(electron) validateFs(fs) validatePath(path) diff --git a/scripts/binary/binary-integrity-check.js b/scripts/binary/binary-sources.js similarity index 84% rename from scripts/binary/binary-integrity-check.js rename to scripts/binary/binary-sources.js index 52709b6a8cd0..613890dd7470 100644 --- a/scripts/binary/binary-integrity-check.js +++ b/scripts/binary/binary-sources.js @@ -4,9 +4,18 @@ const path = require('path') const escapeString = (string) => string.replaceAll(`\``, `\\\``).replaceAll(`$`, `\\$`) -function read ({ file, baseDirectory }) { +function read ({ file }) { const pathToFile = require.resolve(`./${file}`) - const fileSource = fs.readFileSync(pathToFile, 'utf8') + + return fs.readFileSync(pathToFile, 'utf8') +} + +const getBinaryEntryPointSource = () => { + return read({ file: 'binary-entry-point-source.js' }) +} + +const getIntegrityCheckSource = (baseDirectory) => { + const fileSource = read({ file: 'binary-integrity-check-source.js' }) const secret = require('crypto').randomBytes(48).toString('hex') const mainIndexHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') @@ -24,10 +33,7 @@ function read ({ file, baseDirectory }) { .replaceAll('CRYPTO_HMAC_DIGEST_TO_STRING', escapeString(crypto.Hmac.prototype.digest.toString())) } -const getIntegrityCheckSource = (baseDirectory) => { - return read({ file: 'binary-integrity-check-source.js', baseDirectory }) -} - module.exports = { + getBinaryEntryPointSource, getIntegrityCheckSource, } diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 2b8d6511165f..294ab2e53698 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -201,7 +201,7 @@ const runV8SnapshotProjectTest = function (buildAppExecutable, e2e) { return spawn() } -const runErroringProjectTest = function (buildAppExecutable, e2e) { +const runErroringProjectTest = function (buildAppExecutable, e2e, testName) { if (shouldSkipProjectTest()) { console.log('skipping project test') @@ -235,7 +235,7 @@ const runErroringProjectTest = function (buildAppExecutable, e2e) { return cp.spawn(buildAppExecutable, args, options) .on('exit', (code) => { if (code === 0) { - return reject(new Error('running project tests should have failed')) + return reject(new Error(`running project tests should have failed for test: ${testName}`)) } return resolve() @@ -250,17 +250,33 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { return } - const testFile = async (file) => { + const testCorruptingFile = async (file) => { const contents = await fs.readFile(file) await fs.writeFile(file, `console.log('modified code')\n${contents}`) - await runErroringProjectTest(buildAppExecutable, e2e) + await runErroringProjectTest(buildAppExecutable, e2e, `corrupting ${file}`) await fs.writeFile(file, contents) } - await testFile(path.join(buildAppDir, 'index.js')) - await testFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc')) - await testFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js')) + await testCorruptingFile(path.join(buildAppDir, 'index.js')) + await testCorruptingFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc')) + await testCorruptingFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js')) + + const testAlteringEntryPoint = async (additionalCode) => { + const packageJsonContents = await fs.readJSON(path.join(buildAppDir, 'package.json')) + + await fs.writeJSON(path.join(buildAppDir, 'package.json'), { + ...packageJsonContents, + main: 'index2.js', + }) + + await fs.writeFile(path.join(buildAppDir, 'index2.js'), `${additionalCode}\nrequire("./index.js")`) + await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point') + await fs.writeJson(path.join(buildAppDir, 'package.json'), packageJsonContents) + await fs.remove(path.join(buildAppDir, 'index2.js')) + } + + await testAlteringEntryPoint('console.log(global.getSnapshotResult())') } const test = async function (buildAppExecutable, buildAppDir) { From b77cf7cb05dab99bcfa6f171233344e3f9a32d41 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 16:20:39 -0600 Subject: [PATCH 18/54] more refactoring --- .../binary/binary-integrity-check-source.js | 10 ++--- scripts/binary/smoke.js | 37 ++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index ee38b4e04658..95e1453807d7 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -5,8 +5,11 @@ const callFn = Function.call // eslint-disable-next-line no-unused-vars const stackIntegrityCheck = function stackIntegrityCheck (options) { + const originalStackTraceLimit = Error.stackTraceLimit const originalStackTrace = OrigError.prepareStackTrace + Error.stackTraceLimit = Infinity + OrigError.prepareStackTrace = function (_, stack) { return stack } @@ -14,9 +17,10 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { const tempError = new OrigError captureStackTrace(tempError, arguments.callee) - const stack = tempError.stack + const stack = tempError.stack.filter((frame) => !frame.getFileName().startsWith('node:internal') && !frame.getFileName().startsWith('node:electron')) OrigError.prepareStackTrace = originalStackTrace + Error.stackTraceLimit = originalStackTraceLimit if (stack.length !== options.stackToMatch.length) { throw new Error(`Integrity check failed with expected stack length ${options.stackToMatch.length} but got ${stack.length}`) @@ -128,10 +132,6 @@ function fileIntegrityCheck (options) { { fileName: path.join(appPath, 'index.js'), }, - { - functionName: 'Module._compile', - fileName: 'node:internal/modules/cjs/loader', - }, ], }) diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 294ab2e53698..e77552f98375 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -201,7 +201,7 @@ const runV8SnapshotProjectTest = function (buildAppExecutable, e2e) { return spawn() } -const runErroringProjectTest = function (buildAppExecutable, e2e, testName) { +const runErroringProjectTest = function (buildAppExecutable, e2e, testName, errorMessage) { if (shouldSkipProjectTest()) { console.log('skipping project test') @@ -226,18 +226,28 @@ const runErroringProjectTest = function (buildAppExecutable, e2e, testName) { } const options = { - stdio: 'inherit', env, + stdio: ['inherit', 'inherit', 'pipe'], env, } console.log('running project test') console.log(buildAppExecutable, args.join(' ')) - return cp.spawn(buildAppExecutable, args, options) - .on('exit', (code) => { + const childProcess = cp.spawn(buildAppExecutable, args, options) + let errorOutput = '' + + childProcess.stderr.on('data', (data) => { + errorOutput += data.toString() + }) + + childProcess.on('exit', (code) => { if (code === 0) { return reject(new Error(`running project tests should have failed for test: ${testName}`)) } + if (!errorOutput.includes(errorMessage)) { + return reject(new Error(`running project tests failed with errors but did not include the expected error message: '${errorMessage}'`)) + } + return resolve() }) }) @@ -250,19 +260,19 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { return } - const testCorruptingFile = async (file) => { + const testCorruptingFile = async (file, errorMessage) => { const contents = await fs.readFile(file) - await fs.writeFile(file, `console.log('modified code')\n${contents}`) - await runErroringProjectTest(buildAppExecutable, e2e, `corrupting ${file}`) + await fs.writeFile(file, Buffer.concat([contents, Buffer.from(`\nconsole.log('modified code')`)])) + await runErroringProjectTest(buildAppExecutable, e2e, `corrupting ${file}`, errorMessage) await fs.writeFile(file, contents) } - await testCorruptingFile(path.join(buildAppDir, 'index.js')) - await testCorruptingFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc')) - await testCorruptingFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js')) + await testCorruptingFile(path.join(buildAppDir, 'index.js'), 'Error: Integrity check failed for main index.js file') + await testCorruptingFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc'), 'Error: Integrity check failed for main server index.jsc file') + await testCorruptingFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js'), 'Error: Integrity check failed for main bytenode.js file') - const testAlteringEntryPoint = async (additionalCode) => { + const testAlteringEntryPoint = async (additionalCode, errorMessage) => { const packageJsonContents = await fs.readJSON(path.join(buildAppDir, 'package.json')) await fs.writeJSON(path.join(buildAppDir, 'package.json'), { @@ -271,12 +281,13 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { }) await fs.writeFile(path.join(buildAppDir, 'index2.js'), `${additionalCode}\nrequire("./index.js")`) - await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point') + await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point', errorMessage) await fs.writeJson(path.join(buildAppDir, 'package.json'), packageJsonContents) await fs.remove(path.join(buildAppDir, 'index2.js')) } - await testAlteringEntryPoint('console.log(global.getSnapshotResult())') + await testAlteringEntryPoint('console.log("simple alteration")', 'Error: Integrity check failed with expected stack length 9 but got 10') + await testAlteringEntryPoint('console.log("accessing " + global.getSnapshotResult())', 'Error: getSnapshotResult can only be called once') } const test = async function (buildAppExecutable, buildAppDir) { From dc0332a3fbc86eb4281553aacf293ba12a435beb Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 16:42:56 -0600 Subject: [PATCH 19/54] Update workflows.yml --- .circleci/workflows.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 3d1585d66cf9..3d78973ebb67 100644 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -27,7 +27,7 @@ mainBuildFilters: &mainBuildFilters branches: only: - develop - - 'feature/run-all-specs' + - 'ryanm/fix/v8-improvements' # 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 @@ -36,7 +36,7 @@ macWorkflowFilters: &darwin-workflow-filters when: or: - equal: [ develop, << pipeline.git.branch >> ] - - equal: [ 'feature/run-all-specs', << pipeline.git.branch >> ] + - equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ] - matches: pattern: "-release$" value: << pipeline.git.branch >> @@ -45,7 +45,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters when: or: - equal: [ develop, << pipeline.git.branch >> ] - - equal: [ 'feature/run-all-specs', << pipeline.git.branch >> ] + - equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ] - matches: pattern: "-release$" value: << pipeline.git.branch >> @@ -63,7 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters when: or: - equal: [ develop, << pipeline.git.branch >> ] - - equal: [ 'astone123/fix-windows-lint', << pipeline.git.branch >> ] + - equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ] - matches: pattern: "-release$" value: << pipeline.git.branch >> @@ -130,7 +130,7 @@ commands: - run: name: Check current branch to persist artifacts command: | - if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "feature/run-all-specs" ]]; then + if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "ryanm/fix/v8-improvements" ]]; then echo "Not uploading artifacts or posting install comment for this branch." circleci-agent step halt fi From 6b5185c9d33249265162ed66d3ab59586411fe45 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 16:43:27 -0600 Subject: [PATCH 20/54] run ci From 5e6f47dd5aa743eb22da6431cc213b471294af53 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 16:44:26 -0600 Subject: [PATCH 21/54] run ci From 42f8935d826228c4a61547a6998a636d2816718b Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 16:45:31 -0600 Subject: [PATCH 22/54] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d55e3c98293c..c8cb79d7fd45 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -72,4 +72,4 @@ workflows: setup-workflow: jobs: - verify-ci-should-run: - context: workflow-setup \ No newline at end of file + context: workflow-setup From 0c2dfaeeb96661b4602cfa6fe441f6e4cc24ab07 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 16:57:01 -0600 Subject: [PATCH 23/54] run ci From d48caa8e4d795d3b10da02522689847615ba18f6 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 17:06:07 -0600 Subject: [PATCH 24/54] limit integrity check to when there are snapshots --- scripts/binary/smoke.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index e77552f98375..2ca1dde7d852 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -298,8 +298,8 @@ const test = async function (buildAppExecutable, buildAppDir) { await runSmokeTest(buildAppExecutable) await runProjectTest(buildAppExecutable, e2e) await runFailingProjectTest(buildAppExecutable, e2e) - await runIntegrityTest(buildAppExecutable, buildAppDir, e2e) if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) { + await runIntegrityTest(buildAppExecutable, buildAppDir, e2e) await runV8SnapshotProjectTest(buildAppExecutable, e2e) } From 528d91bc3f1d709a77b94289e303ad03771c5c84 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 18:37:52 -0600 Subject: [PATCH 25/54] fix build --- .../binary/binary-integrity-check-source.js | 8 +- .../v8-snapshot/src/blueprint/set-globals.js | 6 +- yarn.lock | 104 +++++++++--------- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 95e1453807d7..5577614e752b 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -32,11 +32,11 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { const expectedFileName = options.stackToMatch[index].fileName const actualFileName = stack[index].getFileName() - if (expectedFunctionName && !actualFunctionName.endsWith(expectedFunctionName)) { + if (expectedFunctionName && actualFunctionName !== expectedFunctionName) { throw new Error(`Integrity check failed with expected function name ${expectedFunctionName} but got ${actualFunctionName}`) } - if (!actualFileName.endsWith(expectedFileName)) { + if (expectedFileName && actualFileName !== expectedFileName) { throw new Error(`Integrity check failed with expected file name ${expectedFileName} but got ${actualFileName}`) } } @@ -81,7 +81,7 @@ function validateCrypto (crypto) { } // eslint-disable-next-line no-unused-vars -function fileIntegrityCheck (options) { +function integrityCheck (options) { const require = options.require const electron = require('electron') const fs = require('fs') @@ -99,7 +99,7 @@ function fileIntegrityCheck (options) { stackIntegrityCheck({ stackToMatch: [ { - functionName: 'fileIntegrityCheck', + functionName: 'integrityCheck', fileName: '', }, { diff --git a/tooling/v8-snapshot/src/blueprint/set-globals.js b/tooling/v8-snapshot/src/blueprint/set-globals.js index ce70612cfba4..799b86b0f1cb 100644 --- a/tooling/v8-snapshot/src/blueprint/set-globals.js +++ b/tooling/v8-snapshot/src/blueprint/set-globals.js @@ -67,9 +67,9 @@ __pathResolver = newPathResolver require = nodeRequire - if (typeof fileIntegrityCheck === 'function') { - // eslint-disable-next-line no-undef - fileIntegrityCheck({ require, pathResolver: __pathResolver }) + if (typeof integrityCheck === 'function') { + // eslint-disable-next-line no-undef + integrityCheck({ require, pathResolver: __pathResolver }) } } })() diff --git a/yarn.lock b/yarn.lock index e51c0268d416..1b63b286143b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2470,70 +2470,70 @@ resolved "https://registry.yarnpkg.com/@cypress/sinon-chai/-/sinon-chai-2.9.1.tgz#1705c0341bc286740979b1b1cac89b7f5d34d6bc" integrity sha512-qwFQ1urghF3mv7CFSDw/LEqIQP12qqKLuW7p6mXR92HP5fPNlgNiZVITWVsupDg7JpOEKfeRTVearo9mkk/5eg== -"@cypress/snapbuild-android-arm64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-android-arm64/-/snapbuild-android-arm64-1.0.1.tgz#f4f67ee22e4dcd4738499dc6e16af6dd50dc3268" - integrity sha512-I8gM7t63gL78+NcP1zNQBgzsyp7xRlFiZhMzn5F0LAX/TrT8tZGctZEWNjPbl3M8JLCPtat/HrCbhaP1h+0Y4g== +"@cypress/snapbuild-android-arm64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-android-arm64/-/snapbuild-android-arm64-1.0.2.tgz#43d0e193c13930b8900ade8200a8aa15c0ef73c9" + integrity sha512-msqrFAt4ioonTsAaZbiohfYXPVlsLo3saSiO0Ko7pw9l5O1Zeiqbb6t0hNwl7OC7fYjC7anxc0jePLm0K6/New== -"@cypress/snapbuild-darwin-64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-64/-/snapbuild-darwin-64-1.0.1.tgz#ce4a7b9734fcc569e5084d25deabb8a7e57c5c39" - integrity sha512-wOZgJ1Hp7I5hent4LLmhlh61vomkHUe7J013pjwQ6JJc+PhAjxFc3h6HocvY4IzRXR1JnvL/9yJjmyY090ahKw== +"@cypress/snapbuild-darwin-64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-64/-/snapbuild-darwin-64-1.0.2.tgz#3379c2d3c09440ed29e5ea0c8b84053aa545aa49" + integrity sha512-9qoWohdHKb6HsMdROQBBDlT6CmJXT3FMQSbN1pQpe37S9JxYoFEiJlQ13x+MI58TeqeGrLxoMk1z1bZ78kUBNA== -"@cypress/snapbuild-darwin-arm64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-arm64/-/snapbuild-darwin-arm64-1.0.1.tgz#a98b61d2732941e69315dc83f4e1cec9b6fdd27d" - integrity sha512-gPYdoOzTyVcs93HTgfhMmEgcH5QP95/fAfcLeFSIVaNYhgIMg0YeyysmjLRcHdYaJ7m31px307+q6zvMYY/paw== +"@cypress/snapbuild-darwin-arm64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-arm64/-/snapbuild-darwin-arm64-1.0.2.tgz#d66ff4ada6322186539c669ed269bb47a740f866" + integrity sha512-XYj/paXiw4T4WMpcRnip/RqZNwkJv3Hdwm/KDIyD4lij4TetQuma80JtGa97P5DGZfYwdHpDlBzg6Sy3XlCL7Q== -"@cypress/snapbuild-freebsd-64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-64/-/snapbuild-freebsd-64-1.0.1.tgz#dd3416a8ed04e7994285a441b329e8c141493415" - integrity sha512-wtW0oLRH9qjGp2oAQLEnCNXX8sUHXkY1QAUvV26TWBf7f3WODxZ7MAjSVV8L7wYKRcxUnLebcCQ/sYmbAg00cQ== +"@cypress/snapbuild-freebsd-64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-64/-/snapbuild-freebsd-64-1.0.2.tgz#7890dac920fc79c9deb310b88e0a48aa90ed62cc" + integrity sha512-sFUFXmrVkgmXCsGAElDkvH2iSY+GozAhZqB3pkNh59Acu6baBytbBkW4G6fTUti+YOI9wDxm3nbnYQmGqHAepw== -"@cypress/snapbuild-freebsd-arm64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-arm64/-/snapbuild-freebsd-arm64-1.0.1.tgz#87d821d8216d17efb9c54a73f435b9123067fe9f" - integrity sha512-44wIjpi3BShIFmRJd1VCj2dAO02DNxkzYDp0vdMvNRflBr2pXDWdT/TdTkj4l9vBRymQTGCPS/swjlLACCwoqg== +"@cypress/snapbuild-freebsd-arm64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-arm64/-/snapbuild-freebsd-arm64-1.0.2.tgz#a3e60568cb011d3a4bb06840838361ef33940ec9" + integrity sha512-tQFo2uTCb4QHpPMC6aD0FyR3oJjIjM5IxDqLf0kVDI1x1zJ0fyZgyADo6npXPBpLu9VXW2wHL5yGLmzS7T5FgA== -"@cypress/snapbuild-linux-32@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-32/-/snapbuild-linux-32-1.0.1.tgz#ff5b0abbb84d2e1a726f9cd9145c5cfe4f2f2b1a" - integrity sha512-Mo74hBFwFzr//pX8OuTj3wGxLbngQDAX61gL72HOcgI33gdDXiSyvasuChs8uiH1H3BDxVUvRMxKBSbRVowF4g== +"@cypress/snapbuild-linux-32@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-32/-/snapbuild-linux-32-1.0.2.tgz#16145141473f95401ef317e67f9add58018b9973" + integrity sha512-WiyHQoOVwLhf/KyvMzFQAx1WoPtKg4OX5MbcYks+O6Bl1nT5Sj8nYVm5MkreIeGSIXpCSlN1hjafVidpYx/YlA== -"@cypress/snapbuild-linux-64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-64/-/snapbuild-linux-64-1.0.1.tgz#be1a0a2c83d27594a1f63c95ed26a70236e7e359" - integrity sha512-tYPA+O/BiRwOy97H8t7/tdWXVSBJSBHzxngRUPVioIG7Y7HCw9jkIgDV4U8l9uYhmYgDmHFeq6TaJOxmW7bMBg== +"@cypress/snapbuild-linux-64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-64/-/snapbuild-linux-64-1.0.2.tgz#cf7a37ae3f49082e617394a35c4ff77d92f7e140" + integrity sha512-ibye7rd4XV5qAjXt3ObDM9mnslXz7JO7G2C8Ch12hDkNOu5TaAg8qwDD+M4wpTLonplmr/SM2OH9l8498NfsUg== -"@cypress/snapbuild-linux-arm64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm64/-/snapbuild-linux-arm64-1.0.1.tgz#f1ce2e0d13907fb8f7c936422f510175bcbb9e83" - integrity sha512-y8P0ZVtVtUNTInNWjmxUi0yieD4ci6Gq3zP5uirFO0bwQArEq5IqBAbXuvOY3gu6sMwgnP9bPUTkqOhFPjlJ3w== +"@cypress/snapbuild-linux-arm64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm64/-/snapbuild-linux-arm64-1.0.2.tgz#e3dde3094a78913919bf71786fb62162e30a271c" + integrity sha512-jP1p2+6kpLX+TlCXl3E3xH8roM7wyzH/j2ztkFTqqHo+BqESigkJDgrepV2AwnTssc2i8BGyUr4mMW/09KUNog== -"@cypress/snapbuild-linux-arm@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm/-/snapbuild-linux-arm-1.0.1.tgz#89ffb6ee61eee79f99ceb5b0ac1472b52b3f3811" - integrity sha512-0DPe2yE7ZpCU1y1QPps5Yiry0yvQk9EtOxnhLzI7gbKgyLo2rBekNY2Vp3/ImdiITod6sG0RjaOuFAQl5xaYcw== +"@cypress/snapbuild-linux-arm@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm/-/snapbuild-linux-arm-1.0.2.tgz#67500718f9e8f15838f89e8c0c1dce4f679aac75" + integrity sha512-JZL2A9T7E9ILxgYJhFW1All5P6ERLpKJ78HC1G0Rar9X+cMGVFN6TCJ4rY5lpHlGFg77oIKKo028fCD/ag6lgw== -"@cypress/snapbuild-linux-mips64le@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-mips64le/-/snapbuild-linux-mips64le-1.0.1.tgz#88b82e2381e06ea2f5e871c27c95fc89a9d538eb" - integrity sha512-0F40yjlA0rtuF1jyfcQgAalE8eOTysiiOr6Gpi7JYHKGajWU4/uvA25woT9pwWRyyVznGvXun6O8bSspV0FyvQ== +"@cypress/snapbuild-linux-mips64le@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-mips64le/-/snapbuild-linux-mips64le-1.0.2.tgz#86b29af61536d961951e547247b7903c72ea4614" + integrity sha512-ZdIcO6/lRoxxSBnC7Rytgvi1+H6flWmEVpJN72DSbWOXdq9J3tH5kNfZvBUQMmaUEot0HJocvWJw37JpI5SpQQ== -"@cypress/snapbuild-linux-ppc64le@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-ppc64le/-/snapbuild-linux-ppc64le-1.0.1.tgz#14ebed384a0dd9591439ab9e4142d38626c55e11" - integrity sha512-DxQXKFI8BEjFt0id0joDNHiNIM59kZgJxO10BoArGV/xXMR2VjTHjNQRIoMD/sM6GgpJwC2gF6dRXm9LY9ej0w== +"@cypress/snapbuild-linux-ppc64le@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-ppc64le/-/snapbuild-linux-ppc64le-1.0.2.tgz#0d69e5fc037813227aba9722dd8966a2df68a853" + integrity sha512-AJYB7ImnUVvIwkde0005i+5yW9F7P35XLOAY9GbXng+otwWYMpdH0OO9pLrQW8dV0L2af2ZnxNMxIl78VOFNYw== -"@cypress/snapbuild-windows-32@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-32/-/snapbuild-windows-32-1.0.1.tgz#ca1137ee529d5250a71845de1b7eefd458d64cf9" - integrity sha512-FIBdE1Ie0rfhIpE5cBRwNIjcPxwOPMrZ0ppUIOXxTdBTRaSEOO5/bfsGV6Mntg/XMIJRGUGaIKmBoudcnyhkgA== +"@cypress/snapbuild-windows-32@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-32/-/snapbuild-windows-32-1.0.2.tgz#5b308a25bbbcffbe2f53ceba310b78f8d6a8785b" + integrity sha512-lxMeAuD+aNqoGiK38EclkrnA8uFB9HGe/8N1plq/rJ0PSX9AmsfsjZfcdTStoIK9ATV39J1WO5rdFwPH1SUr+g== -"@cypress/snapbuild-windows-64@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-64/-/snapbuild-windows-64-1.0.1.tgz#0e03d39f91fe7724c353db863154ea8848140004" - integrity sha512-lEg02qY4GgaAg7An1EAJSq2AFb1L7v7sARaofyj/R0kYh8PHyOQAOF2Jn9cfI8ltveJ1mh0Nu/ayg24FpwS/sA== +"@cypress/snapbuild-windows-64@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-64/-/snapbuild-windows-64-1.0.2.tgz#cdca8da74f20e5b2926a06b4d2b91ebbe444694e" + integrity sha512-5GPLRFLKFz6sn/Nh44s7aWpj18LQBmIh086wbVhGk4RlM29C9iDk3xobAy4WNJbAdLXZsutOT7BtkiRRlEfwtw== "@cypress/unique-selector@0.4.4": version "0.4.4" From 9a4157eb49d98c71be04fefb416f46538a457390 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 19:02:49 -0600 Subject: [PATCH 26/54] fix build --- .../binary/binary-integrity-check-source.js | 1 - scripts/binary/build.ts | 22 +++++-------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 5577614e752b..e1b6b3b46349 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -103,7 +103,6 @@ function integrityCheck (options) { fileName: '', }, { - functionName: 'setGlobals', fileName: '', }, { diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 43c04cfc16b3..65a85334d4df 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -235,23 +235,6 @@ require('./packages/server/index.js') console.log(`output folder: ${outputFolder}`) - const args = [ - '--publish=never', - `--c.electronVersion=${electronVersion}`, - `--c.directories.app=${appFolder}`, - `--c.directories.output=${outputFolder}`, - `--c.icon=${iconFilename}`, - // for now we cannot pack source files in asar file - // because electron-builder does not copy nested folders - // from packages/*/node_modules - // see https://github.com/electron-userland/electron-builder/issues/3185 - // so we will copy those folders later ourselves - '--c.asar=false', - ] - - console.log('electron-builder arguments:') - console.log(args.join(' ')) - // Update the root package.json with the next app version so that it is snapshot properly fs.writeJSONSync(path.join(CY_ROOT_DIR, 'package.json'), { ...jsonRoot, @@ -268,6 +251,11 @@ require('./packages/server/index.js') output: outputFolder, }, icon: iconFilename, + // for now we cannot pack source files in asar file + // because electron-builder does not copy nested folders + // from packages/*/node_modules + // see https://github.com/electron-userland/electron-builder/issues/3185 + // so we will copy those folders later ourselves asar: false, }, }) From 35678efb7713f6c24952d1c4691562f13aac4f21 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 19:43:07 -0600 Subject: [PATCH 27/54] fix build --- package.json | 2 +- scripts/binary/smoke.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60636530ce27..b669d7256f0e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Cypress is a next generation front end testing tool built for the modern web", "private": true, "scripts": { - "binary-build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node ./scripts/binary.js build", + "binary-build": "cross-env DEBUG=cypress:*snap* NODE_OPTIONS=--max_old_space_size=16384 node ./scripts/binary.js build", "binary-deploy": "node ./scripts/binary.js deploy", "binary-deploy-linux": "./scripts/build-linux-binary.sh", "binary-ensure": "node ./scripts/binary.js ensure", diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 2ca1dde7d852..4aed1cc914c4 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -282,7 +282,7 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await fs.writeFile(path.join(buildAppDir, 'index2.js'), `${additionalCode}\nrequire("./index.js")`) await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point', errorMessage) - await fs.writeJson(path.join(buildAppDir, 'package.json'), packageJsonContents) + await fs.writeJson(path.join(buildAppDir, 'package.json'), packageJsonContents, { spaces: 2 }) await fs.remove(path.join(buildAppDir, 'index2.js')) } From cb7e3b28c90b85362ca2932425c0bb1cfc900c97 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 20:47:44 -0600 Subject: [PATCH 28/54] attempt to fix tests --- scripts/binary/smoke.js | 16 ++- tooling/v8-snapshot/package.json | 1 + yarn.lock | 162 ++++++++++++++++++------------- 3 files changed, 111 insertions(+), 68 deletions(-) diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 4aed1cc914c4..03aaed663824 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -263,9 +263,15 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { const testCorruptingFile = async (file, errorMessage) => { const contents = await fs.readFile(file) + // Backup state + await fs.move(file, `${file}.bak`) + + // Modify app await fs.writeFile(file, Buffer.concat([contents, Buffer.from(`\nconsole.log('modified code')`)])) await runErroringProjectTest(buildAppExecutable, e2e, `corrupting ${file}`, errorMessage) - await fs.writeFile(file, contents) + + // Restore original state + await fs.move(`${file}.bak`, file) } await testCorruptingFile(path.join(buildAppDir, 'index.js'), 'Error: Integrity check failed for main index.js file') @@ -275,6 +281,10 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { const testAlteringEntryPoint = async (additionalCode, errorMessage) => { const packageJsonContents = await fs.readJSON(path.join(buildAppDir, 'package.json')) + // Backup state + await fs.move(path.join(buildAppDir, 'package.json'), path.join(buildAppDir, 'package.json.bak')) + + // Modify app await fs.writeJSON(path.join(buildAppDir, 'package.json'), { ...packageJsonContents, main: 'index2.js', @@ -282,7 +292,9 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await fs.writeFile(path.join(buildAppDir, 'index2.js'), `${additionalCode}\nrequire("./index.js")`) await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point', errorMessage) - await fs.writeJson(path.join(buildAppDir, 'package.json'), packageJsonContents, { spaces: 2 }) + + // Restore original state + await fs.move(path.join(buildAppDir, 'package.json'), path.join(buildAppDir, 'package.json.bak')) await fs.remove(path.join(buildAppDir, 'index2.js')) } diff --git a/tooling/v8-snapshot/package.json b/tooling/v8-snapshot/package.json index 75def0874106..b629ad239681 100644 --- a/tooling/v8-snapshot/package.json +++ b/tooling/v8-snapshot/package.json @@ -25,6 +25,7 @@ "resolve-from": "^5.0.0", "source-map-js": "^0.6.2", "temp-dir": "^2.0.0", + "terser": "^5.7.0", "tslib": "^2.0.1", "worker-nodes": "^2.3.0" }, diff --git a/yarn.lock b/yarn.lock index 1b63b286143b..cb8e65c5caf8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2470,70 +2470,70 @@ resolved "https://registry.yarnpkg.com/@cypress/sinon-chai/-/sinon-chai-2.9.1.tgz#1705c0341bc286740979b1b1cac89b7f5d34d6bc" integrity sha512-qwFQ1urghF3mv7CFSDw/LEqIQP12qqKLuW7p6mXR92HP5fPNlgNiZVITWVsupDg7JpOEKfeRTVearo9mkk/5eg== -"@cypress/snapbuild-android-arm64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-android-arm64/-/snapbuild-android-arm64-1.0.2.tgz#43d0e193c13930b8900ade8200a8aa15c0ef73c9" - integrity sha512-msqrFAt4ioonTsAaZbiohfYXPVlsLo3saSiO0Ko7pw9l5O1Zeiqbb6t0hNwl7OC7fYjC7anxc0jePLm0K6/New== +"@cypress/snapbuild-android-arm64@1.0.": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-android-arm64/-/snapbuild-android-arm64-1.0.1.tgz#f4f67ee22e4dcd4738499dc6e16af6dd50dc3268" + integrity sha512-I8gM7t63gL78+NcP1zNQBgzsyp7xRlFiZhMzn5F0LAX/TrT8tZGctZEWNjPbl3M8JLCPtat/HrCbhaP1h+0Y4g== -"@cypress/snapbuild-darwin-64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-64/-/snapbuild-darwin-64-1.0.2.tgz#3379c2d3c09440ed29e5ea0c8b84053aa545aa49" - integrity sha512-9qoWohdHKb6HsMdROQBBDlT6CmJXT3FMQSbN1pQpe37S9JxYoFEiJlQ13x+MI58TeqeGrLxoMk1z1bZ78kUBNA== +"@cypress/snapbuild-darwin-64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-64/-/snapbuild-darwin-64-1.0.1.tgz#ce4a7b9734fcc569e5084d25deabb8a7e57c5c39" + integrity sha512-wOZgJ1Hp7I5hent4LLmhlh61vomkHUe7J013pjwQ6JJc+PhAjxFc3h6HocvY4IzRXR1JnvL/9yJjmyY090ahKw== -"@cypress/snapbuild-darwin-arm64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-arm64/-/snapbuild-darwin-arm64-1.0.2.tgz#d66ff4ada6322186539c669ed269bb47a740f866" - integrity sha512-XYj/paXiw4T4WMpcRnip/RqZNwkJv3Hdwm/KDIyD4lij4TetQuma80JtGa97P5DGZfYwdHpDlBzg6Sy3XlCL7Q== +"@cypress/snapbuild-darwin-arm64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-darwin-arm64/-/snapbuild-darwin-arm64-1.0.1.tgz#a98b61d2732941e69315dc83f4e1cec9b6fdd27d" + integrity sha512-gPYdoOzTyVcs93HTgfhMmEgcH5QP95/fAfcLeFSIVaNYhgIMg0YeyysmjLRcHdYaJ7m31px307+q6zvMYY/paw== -"@cypress/snapbuild-freebsd-64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-64/-/snapbuild-freebsd-64-1.0.2.tgz#7890dac920fc79c9deb310b88e0a48aa90ed62cc" - integrity sha512-sFUFXmrVkgmXCsGAElDkvH2iSY+GozAhZqB3pkNh59Acu6baBytbBkW4G6fTUti+YOI9wDxm3nbnYQmGqHAepw== +"@cypress/snapbuild-freebsd-64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-64/-/snapbuild-freebsd-64-1.0.1.tgz#dd3416a8ed04e7994285a441b329e8c141493415" + integrity sha512-wtW0oLRH9qjGp2oAQLEnCNXX8sUHXkY1QAUvV26TWBf7f3WODxZ7MAjSVV8L7wYKRcxUnLebcCQ/sYmbAg00cQ== -"@cypress/snapbuild-freebsd-arm64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-arm64/-/snapbuild-freebsd-arm64-1.0.2.tgz#a3e60568cb011d3a4bb06840838361ef33940ec9" - integrity sha512-tQFo2uTCb4QHpPMC6aD0FyR3oJjIjM5IxDqLf0kVDI1x1zJ0fyZgyADo6npXPBpLu9VXW2wHL5yGLmzS7T5FgA== +"@cypress/snapbuild-freebsd-arm64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-freebsd-arm64/-/snapbuild-freebsd-arm64-1.0.1.tgz#87d821d8216d17efb9c54a73f435b9123067fe9f" + integrity sha512-44wIjpi3BShIFmRJd1VCj2dAO02DNxkzYDp0vdMvNRflBr2pXDWdT/TdTkj4l9vBRymQTGCPS/swjlLACCwoqg== -"@cypress/snapbuild-linux-32@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-32/-/snapbuild-linux-32-1.0.2.tgz#16145141473f95401ef317e67f9add58018b9973" - integrity sha512-WiyHQoOVwLhf/KyvMzFQAx1WoPtKg4OX5MbcYks+O6Bl1nT5Sj8nYVm5MkreIeGSIXpCSlN1hjafVidpYx/YlA== +"@cypress/snapbuild-linux-32@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-32/-/snapbuild-linux-32-1.0.1.tgz#ff5b0abbb84d2e1a726f9cd9145c5cfe4f2f2b1a" + integrity sha512-Mo74hBFwFzr//pX8OuTj3wGxLbngQDAX61gL72HOcgI33gdDXiSyvasuChs8uiH1H3BDxVUvRMxKBSbRVowF4g== -"@cypress/snapbuild-linux-64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-64/-/snapbuild-linux-64-1.0.2.tgz#cf7a37ae3f49082e617394a35c4ff77d92f7e140" - integrity sha512-ibye7rd4XV5qAjXt3ObDM9mnslXz7JO7G2C8Ch12hDkNOu5TaAg8qwDD+M4wpTLonplmr/SM2OH9l8498NfsUg== +"@cypress/snapbuild-linux-64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-64/-/snapbuild-linux-64-1.0.1.tgz#be1a0a2c83d27594a1f63c95ed26a70236e7e359" + integrity sha512-tYPA+O/BiRwOy97H8t7/tdWXVSBJSBHzxngRUPVioIG7Y7HCw9jkIgDV4U8l9uYhmYgDmHFeq6TaJOxmW7bMBg== -"@cypress/snapbuild-linux-arm64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm64/-/snapbuild-linux-arm64-1.0.2.tgz#e3dde3094a78913919bf71786fb62162e30a271c" - integrity sha512-jP1p2+6kpLX+TlCXl3E3xH8roM7wyzH/j2ztkFTqqHo+BqESigkJDgrepV2AwnTssc2i8BGyUr4mMW/09KUNog== +"@cypress/snapbuild-linux-arm64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm64/-/snapbuild-linux-arm64-1.0.1.tgz#f1ce2e0d13907fb8f7c936422f510175bcbb9e83" + integrity sha512-y8P0ZVtVtUNTInNWjmxUi0yieD4ci6Gq3zP5uirFO0bwQArEq5IqBAbXuvOY3gu6sMwgnP9bPUTkqOhFPjlJ3w== -"@cypress/snapbuild-linux-arm@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm/-/snapbuild-linux-arm-1.0.2.tgz#67500718f9e8f15838f89e8c0c1dce4f679aac75" - integrity sha512-JZL2A9T7E9ILxgYJhFW1All5P6ERLpKJ78HC1G0Rar9X+cMGVFN6TCJ4rY5lpHlGFg77oIKKo028fCD/ag6lgw== +"@cypress/snapbuild-linux-arm@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-arm/-/snapbuild-linux-arm-1.0.1.tgz#89ffb6ee61eee79f99ceb5b0ac1472b52b3f3811" + integrity sha512-0DPe2yE7ZpCU1y1QPps5Yiry0yvQk9EtOxnhLzI7gbKgyLo2rBekNY2Vp3/ImdiITod6sG0RjaOuFAQl5xaYcw== -"@cypress/snapbuild-linux-mips64le@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-mips64le/-/snapbuild-linux-mips64le-1.0.2.tgz#86b29af61536d961951e547247b7903c72ea4614" - integrity sha512-ZdIcO6/lRoxxSBnC7Rytgvi1+H6flWmEVpJN72DSbWOXdq9J3tH5kNfZvBUQMmaUEot0HJocvWJw37JpI5SpQQ== +"@cypress/snapbuild-linux-mips64le@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-mips64le/-/snapbuild-linux-mips64le-1.0.1.tgz#88b82e2381e06ea2f5e871c27c95fc89a9d538eb" + integrity sha512-0F40yjlA0rtuF1jyfcQgAalE8eOTysiiOr6Gpi7JYHKGajWU4/uvA25woT9pwWRyyVznGvXun6O8bSspV0FyvQ== -"@cypress/snapbuild-linux-ppc64le@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-ppc64le/-/snapbuild-linux-ppc64le-1.0.2.tgz#0d69e5fc037813227aba9722dd8966a2df68a853" - integrity sha512-AJYB7ImnUVvIwkde0005i+5yW9F7P35XLOAY9GbXng+otwWYMpdH0OO9pLrQW8dV0L2af2ZnxNMxIl78VOFNYw== +"@cypress/snapbuild-linux-ppc64le@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-linux-ppc64le/-/snapbuild-linux-ppc64le-1.0.1.tgz#14ebed384a0dd9591439ab9e4142d38626c55e11" + integrity sha512-DxQXKFI8BEjFt0id0joDNHiNIM59kZgJxO10BoArGV/xXMR2VjTHjNQRIoMD/sM6GgpJwC2gF6dRXm9LY9ej0w== -"@cypress/snapbuild-windows-32@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-32/-/snapbuild-windows-32-1.0.2.tgz#5b308a25bbbcffbe2f53ceba310b78f8d6a8785b" - integrity sha512-lxMeAuD+aNqoGiK38EclkrnA8uFB9HGe/8N1plq/rJ0PSX9AmsfsjZfcdTStoIK9ATV39J1WO5rdFwPH1SUr+g== +"@cypress/snapbuild-windows-32@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-32/-/snapbuild-windows-32-1.0.1.tgz#ca1137ee529d5250a71845de1b7eefd458d64cf9" + integrity sha512-FIBdE1Ie0rfhIpE5cBRwNIjcPxwOPMrZ0ppUIOXxTdBTRaSEOO5/bfsGV6Mntg/XMIJRGUGaIKmBoudcnyhkgA== -"@cypress/snapbuild-windows-64@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-64/-/snapbuild-windows-64-1.0.2.tgz#cdca8da74f20e5b2926a06b4d2b91ebbe444694e" - integrity sha512-5GPLRFLKFz6sn/Nh44s7aWpj18LQBmIh086wbVhGk4RlM29C9iDk3xobAy4WNJbAdLXZsutOT7BtkiRRlEfwtw== +"@cypress/snapbuild-windows-64@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@cypress/snapbuild-windows-64/-/snapbuild-windows-64-1.0.1.tgz#0e03d39f91fe7724c353db863154ea8848140004" + integrity sha512-lEg02qY4GgaAg7An1EAJSq2AFb1L7v7sARaofyj/R0kYh8PHyOQAOF2Jn9cfI8ltveJ1mh0Nu/ayg24FpwS/sA== "@cypress/unique-selector@0.4.4": version "0.4.4" @@ -4219,17 +4219,39 @@ "@babel/runtime" "^7.7.2" regenerator-runtime "^0.13.3" -"@jridgewell/resolve-uri@^3.0.3": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.0.4.tgz#b876e3feefb9c8d3aa84014da28b5e52a0640d72" - integrity sha512-cz8HFjOFfUBtvN+NXYSFMHYRdxZMaEl0XypVrhzxBgadKIXhIkRd8aMeHhmF56Sl7SuS8OnUpQ73/k9LE4VnLg== +"@jridgewell/gen-mapping@^0.3.0": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9" + integrity sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A== + dependencies: + "@jridgewell/set-array" "^1.0.1" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@jridgewell/trace-mapping" "^0.3.9" -"@jridgewell/sourcemap-codec@^1.4.10": - version "1.4.10" - resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.10.tgz#baf57b4e2a690d4f38560171f91783656b7f8186" - integrity sha512-Ht8wIW5v165atIX1p+JvKR5ONzUyF4Ac8DZIQ5kZs9zrb6M8SJNXpx1zn04rn65VjBMygRoMXcyYwNK0fT7bEg== +"@jridgewell/resolve-uri@3.1.0", "@jridgewell/resolve-uri@^3.0.3": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" + integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== + +"@jridgewell/set-array@^1.0.1": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" + integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== -"@jridgewell/trace-mapping@0.3.9", "@jridgewell/trace-mapping@^0.3.0": +"@jridgewell/source-map@^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb" + integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== + dependencies: + "@jridgewell/gen-mapping" "^0.3.0" + "@jridgewell/trace-mapping" "^0.3.9" + +"@jridgewell/sourcemap-codec@1.4.14", "@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.14" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" + integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== + +"@jridgewell/trace-mapping@0.3.9": version "0.3.9" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== @@ -4237,6 +4259,14 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@jridgewell/trace-mapping@^0.3.0", "@jridgewell/trace-mapping@^0.3.9": + version "0.3.17" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" + integrity sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g== + dependencies: + "@jridgewell/resolve-uri" "3.1.0" + "@jridgewell/sourcemap-codec" "1.4.14" + "@kwsites/file-exists@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99" @@ -32449,14 +32479,14 @@ terser@^4.1.2, terser@^4.6.3: source-map "~0.6.1" source-map-support "~0.5.12" -terser@^5.10.0, terser@^5.7.2: - version "5.12.1" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.12.1.tgz#4cf2ebed1f5bceef5c83b9f60104ac4a78b49e9c" - integrity sha512-NXbs+7nisos5E+yXwAD+y7zrcTkMqb0dEJxIGtSKPdCBzopf7ni4odPul2aechpV7EXNvOudYOX2bb5tln1jbQ== +terser@^5.10.0, terser@^5.7.0, terser@^5.7.2: + version "5.16.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.0.tgz#29362c6f5506e71545c73b069ccd199bb28f7f54" + integrity sha512-KjTV81QKStSfwbNiwlBXfcgMcOloyuRdb62/iLFPGBcVNF4EXjhdYBhYHmbJpiBrVxZhDvltE11j+LBQUxEEJg== dependencies: + "@jridgewell/source-map" "^0.3.2" acorn "^8.5.0" commander "^2.20.0" - source-map "~0.7.2" source-map-support "~0.5.20" test-exclude@^5.2.3: From 1a4c52151247125dcb617e7e35737b1dc8f35f7d Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 21:33:55 -0600 Subject: [PATCH 29/54] attempt to fix tests --- scripts/binary/smoke.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 03aaed663824..62cc969ebd91 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -271,7 +271,7 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await runErroringProjectTest(buildAppExecutable, e2e, `corrupting ${file}`, errorMessage) // Restore original state - await fs.move(`${file}.bak`, file) + await fs.move(`${file}.bak`, file, { overwrite: true }) } await testCorruptingFile(path.join(buildAppDir, 'index.js'), 'Error: Integrity check failed for main index.js file') @@ -294,7 +294,7 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point', errorMessage) // Restore original state - await fs.move(path.join(buildAppDir, 'package.json'), path.join(buildAppDir, 'package.json.bak')) + await fs.move(path.join(buildAppDir, 'package.json'), path.join(buildAppDir, 'package.json.bak'), { overwrite: true }) await fs.remove(path.join(buildAppDir, 'index2.js')) } From 1c1ce8941e4cbb23f1afb79c5ec18bdd838fb2f9 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 21:36:01 -0600 Subject: [PATCH 30/54] get more debugging info --- scripts/after-pack-hook.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index 9ffc327cfb4b..b0ae84419eba 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -67,6 +67,11 @@ module.exports = async function (params) { ) await cleanup(outputFolder) - await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) + + try { + await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) + } catch (error) { + console.log(error) + } } } From 76a18b6c113cd0130e7d0293dcf2576ff1af2a2f Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 22:07:08 -0600 Subject: [PATCH 31/54] get more debugging info --- scripts/binary/build.ts | 1 + scripts/binary/smoke.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 65a85334d4df..3065b3f05888 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -260,6 +260,7 @@ require('./packages/server/index.js') }, }) } catch (e) { + console.log(e) if (!skipSigning) { throw e } diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 62cc969ebd91..8462f5002bf8 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -294,7 +294,7 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await runErroringProjectTest(buildAppExecutable, e2e, 'altering entry point', errorMessage) // Restore original state - await fs.move(path.join(buildAppDir, 'package.json'), path.join(buildAppDir, 'package.json.bak'), { overwrite: true }) + await fs.move(path.join(buildAppDir, 'package.json.bak'), path.join(buildAppDir, 'package.json'), { overwrite: true }) await fs.remove(path.join(buildAppDir, 'index2.js')) } From 1720cb8218eee4217e1487600f5cc9f1fdb81a18 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 04:34:37 +0000 Subject: [PATCH 32/54] update cache files --- .../cache/dev-linux/snapshot-meta.cache.json | 18 +++++++++++++++--- .../cache/prod-linux/snapshot-meta.cache.json | 11 ++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json index c5cdce04453a..50210b948f88 100644 --- a/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json @@ -33,6 +33,11 @@ "./node_modules/mocha/node_modules/debug/src/node.js", "./node_modules/morgan/node_modules/debug/src/node.js", "./node_modules/prettier/index.js", + "./node_modules/prettier/parser-babel.js", + "./node_modules/prettier/parser-espree.js", + "./node_modules/prettier/parser-flow.js", + "./node_modules/prettier/parser-meriyah.js", + "./node_modules/prettier/parser-typescript.js", "./node_modules/prettier/third-party.js", "./node_modules/send/node_modules/debug/src/node.js", "./node_modules/stream-parser/node_modules/debug/src/node.js", @@ -45,14 +50,20 @@ "./packages/https-proxy/lib/ca.js", "./packages/net-stubbing/node_modules/debug/src/node.js", "./packages/network/node_modules/minimatch/minimatch.js", + "./packages/server/lib/browsers/utils.ts", + "./packages/server/lib/cloud/exception.ts", + "./packages/server/lib/errors.ts", "./packages/server/lib/modes/record.js", "./packages/server/lib/modes/run.ts", "./packages/server/lib/open_project.ts", "./packages/server/lib/project-base.ts", "./packages/server/lib/socket-ct.ts", + "./packages/server/lib/util/process_profiler.ts", "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/ci-info/index.js", "./packages/server/node_modules/glob/node_modules/minimatch/minimatch.js", "./packages/server/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/is-ci/index.js", "./packages/server/node_modules/mocha/node_modules/debug/src/node.js", "./packages/server/node_modules/signal-exit/index.js", "./process-nextick-args/index.js", @@ -87,6 +98,7 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", + "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -132,7 +144,6 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", - "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3425,6 +3436,7 @@ "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/legacy-streams.js", "./packages/server/node_modules/@benmalka/foxdriver/package.json", "./packages/server/node_modules/ansi-regex/index.js", + "./packages/server/node_modules/ci-info/vendors.json", "./packages/server/node_modules/cli-table3/index.js", "./packages/server/node_modules/cli-table3/src/cell.js", "./packages/server/node_modules/cli-table3/src/layout-manager.js", @@ -3529,5 +3541,5 @@ "./tooling/v8-snapshot/cache/dev-linux/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "6e64b278585907ecd02c6688a3964ef282453f2ca9753603ade51dc14ab6f7ee" -} + "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" +} \ No newline at end of file diff --git a/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json index 18b1a5233bb0..9011d9483932 100644 --- a/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json @@ -57,13 +57,15 @@ "./packages/server/lib/modes/record.js", "./packages/server/lib/modes/run.ts", "./packages/server/lib/open_project.ts", - "./packages/server/lib/util/process_profiler.ts", "./packages/server/lib/project-base.ts", "./packages/server/lib/socket-ct.ts", + "./packages/server/lib/util/process_profiler.ts", "./packages/server/lib/util/suppress_warnings.js", "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/ci-info/index.js", "./packages/server/node_modules/glob/node_modules/minimatch/minimatch.js", "./packages/server/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/is-ci/index.js", "./packages/server/node_modules/mocha/node_modules/debug/src/node.js", "./packages/server/node_modules/signal-exit/index.js", "./process-nextick-args/index.js", @@ -98,6 +100,7 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", + "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -143,7 +146,6 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", - "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -935,6 +937,7 @@ "./packages/server/node_modules/uuid/dist/v4.js", "./packages/server/node_modules/uuid/dist/v5.js", "./packages/server/server-entry.js", + "./packages/server/snapshot-entry.js", "./packages/socket/index.js", "./packages/socket/lib/socket.ts", "./packages/socket/node_modules/socket.io/dist/broadcast-operator.js", @@ -3643,6 +3646,7 @@ "./packages/net-stubbing/node_modules/mime-types/index.js", "./packages/network/lib/allow-destroy.ts", "./packages/network/lib/blocked.ts", + "./packages/network/lib/ca.ts", "./packages/network/lib/concat-stream.ts", "./packages/network/lib/http-utils.ts", "./packages/network/lib/index.ts", @@ -3805,6 +3809,7 @@ "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/legacy-streams.js", "./packages/server/node_modules/@benmalka/foxdriver/package.json", "./packages/server/node_modules/ansi-regex/index.js", + "./packages/server/node_modules/ci-info/vendors.json", "./packages/server/node_modules/cli-table3/index.js", "./packages/server/node_modules/cli-table3/src/cell.js", "./packages/server/node_modules/cli-table3/src/layout-manager.js", @@ -3928,5 +3933,5 @@ "./tooling/v8-snapshot/cache/prod-linux/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "95205f49259fe2d246d45ef15d1499f6e3d1d235d6db892124bbd5423f1ba872" + "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" } \ No newline at end of file From 3ea52dc2972948ec74c9320711f39947de2a4b04 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Wed, 30 Nov 2022 23:06:21 -0600 Subject: [PATCH 33/54] update cache files --- .circleci/workflows.yml | 2 +- package.json | 2 +- .../cache/dev-darwin/snapshot-meta.cache.json | 16 ++++++++++++++-- .../cache/prod-darwin/snapshot-meta.cache.json | 4 ++-- yarn.lock | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 3d78973ebb67..1bc02be01c84 100644 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -1985,7 +1985,7 @@ jobs: <<: *defaultsParameters resource_class: type: string - default: large + default: xlarge resource_class: << parameters.resource_class >> steps: - restore_cached_workspace diff --git a/package.json b/package.json index b669d7256f0e..1e97289012d7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Cypress is a next generation front end testing tool built for the modern web", "private": true, "scripts": { - "binary-build": "cross-env DEBUG=cypress:*snap* NODE_OPTIONS=--max_old_space_size=16384 node ./scripts/binary.js build", + "binary-build": "cross-env DEBUG=cypress:*snap*info NODE_OPTIONS=--max_old_space_size=16384 node ./scripts/binary.js build", "binary-deploy": "node ./scripts/binary.js deploy", "binary-deploy-linux": "./scripts/build-linux-binary.sh", "binary-ensure": "node ./scripts/binary.js ensure", diff --git a/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json index ffd9d19ae017..3e5e70c46abf 100644 --- a/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json @@ -33,6 +33,11 @@ "./node_modules/mocha/node_modules/debug/src/node.js", "./node_modules/morgan/node_modules/debug/src/node.js", "./node_modules/prettier/index.js", + "./node_modules/prettier/parser-babel.js", + "./node_modules/prettier/parser-espree.js", + "./node_modules/prettier/parser-flow.js", + "./node_modules/prettier/parser-meriyah.js", + "./node_modules/prettier/parser-typescript.js", "./node_modules/prettier/third-party.js", "./node_modules/send/node_modules/debug/src/node.js", "./node_modules/stream-parser/node_modules/debug/src/node.js", @@ -45,14 +50,20 @@ "./packages/https-proxy/lib/ca.js", "./packages/net-stubbing/node_modules/debug/src/node.js", "./packages/network/node_modules/minimatch/minimatch.js", + "./packages/server/lib/browsers/utils.ts", + "./packages/server/lib/cloud/exception.ts", + "./packages/server/lib/errors.ts", "./packages/server/lib/modes/record.js", "./packages/server/lib/modes/run.ts", "./packages/server/lib/open_project.ts", "./packages/server/lib/project-base.ts", "./packages/server/lib/socket-ct.ts", + "./packages/server/lib/util/process_profiler.ts", "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/ci-info/index.js", "./packages/server/node_modules/glob/node_modules/minimatch/minimatch.js", "./packages/server/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/is-ci/index.js", "./packages/server/node_modules/mocha/node_modules/debug/src/node.js", "./packages/server/node_modules/signal-exit/index.js", "./process-nextick-args/index.js", @@ -87,6 +98,7 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", + "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -132,7 +144,6 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", - "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3426,6 +3437,7 @@ "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/legacy-streams.js", "./packages/server/node_modules/@benmalka/foxdriver/package.json", "./packages/server/node_modules/ansi-regex/index.js", + "./packages/server/node_modules/ci-info/vendors.json", "./packages/server/node_modules/cli-table3/index.js", "./packages/server/node_modules/cli-table3/src/cell.js", "./packages/server/node_modules/cli-table3/src/layout-manager.js", @@ -3530,5 +3542,5 @@ "./tooling/v8-snapshot/cache/dev-darwin/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "8b71698b89d3804ed712295c20a140cfcd674fa5c3ad9569530282dd6c3e9906" + "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" } \ No newline at end of file diff --git a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json index f545fe0f9258..ca46dfdf990d 100644 --- a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json @@ -100,6 +100,7 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", + "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -145,7 +146,6 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", - "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3934,5 +3934,5 @@ "./tooling/v8-snapshot/cache/prod-darwin/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "9b94c93e768da3b93ffc6e07da24a90a3e2f07577d224096b58ec7db5654a1a2" + "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index cb8e65c5caf8..a664576d6125 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2470,7 +2470,7 @@ resolved "https://registry.yarnpkg.com/@cypress/sinon-chai/-/sinon-chai-2.9.1.tgz#1705c0341bc286740979b1b1cac89b7f5d34d6bc" integrity sha512-qwFQ1urghF3mv7CFSDw/LEqIQP12qqKLuW7p6mXR92HP5fPNlgNiZVITWVsupDg7JpOEKfeRTVearo9mkk/5eg== -"@cypress/snapbuild-android-arm64@1.0.": +"@cypress/snapbuild-android-arm64@1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@cypress/snapbuild-android-arm64/-/snapbuild-android-arm64-1.0.1.tgz#f4f67ee22e4dcd4738499dc6e16af6dd50dc3268" integrity sha512-I8gM7t63gL78+NcP1zNQBgzsyp7xRlFiZhMzn5F0LAX/TrT8tZGctZEWNjPbl3M8JLCPtat/HrCbhaP1h+0Y4g== @@ -31237,7 +31237,7 @@ source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, sourc resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@0.7.4, source-map@^0.7.3, source-map@~0.7.2: +source-map@0.7.4, source-map@^0.7.3: version "0.7.4" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656" integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA== From 250e9f8c2b2ee48f7e922d7ef9d2927d2d9fce1a Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 05:17:40 +0000 Subject: [PATCH 34/54] update cache files --- .../cache/dev-win32/snapshot-meta.cache.json | 19 +++++++++++++++++-- .../cache/prod-win32/snapshot-meta.cache.json | 11 ++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json index dfff2f7f3ece..fb5753ed411b 100644 --- a/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json @@ -33,6 +33,11 @@ "./node_modules/mocha/node_modules/debug/src/node.js", "./node_modules/morgan/node_modules/debug/src/node.js", "./node_modules/prettier/index.js", + "./node_modules/prettier/parser-babel.js", + "./node_modules/prettier/parser-espree.js", + "./node_modules/prettier/parser-flow.js", + "./node_modules/prettier/parser-meriyah.js", + "./node_modules/prettier/parser-typescript.js", "./node_modules/prettier/third-party.js", "./node_modules/send/node_modules/debug/src/node.js", "./node_modules/stream-parser/node_modules/debug/src/node.js", @@ -45,11 +50,20 @@ "./packages/https-proxy/lib/ca.js", "./packages/net-stubbing/node_modules/debug/src/node.js", "./packages/network/node_modules/minimatch/minimatch.js", + "./packages/server/lib/browsers/utils.ts", + "./packages/server/lib/cloud/exception.ts", + "./packages/server/lib/errors.ts", "./packages/server/lib/modes/record.js", "./packages/server/lib/modes/run.ts", + "./packages/server/lib/open_project.ts", + "./packages/server/lib/project-base.ts", + "./packages/server/lib/socket-ct.ts", + "./packages/server/lib/util/process_profiler.ts", "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/ci-info/index.js", "./packages/server/node_modules/glob/node_modules/minimatch/minimatch.js", "./packages/server/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/is-ci/index.js", "./packages/server/node_modules/mocha/node_modules/debug/src/node.js", "./packages/server/node_modules/signal-exit/index.js", "./process-nextick-args/index.js", @@ -84,6 +98,7 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", + "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -129,7 +144,6 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", - "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3424,6 +3438,7 @@ "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/legacy-streams.js", "./packages/server/node_modules/@benmalka/foxdriver/package.json", "./packages/server/node_modules/ansi-regex/index.js", + "./packages/server/node_modules/ci-info/vendors.json", "./packages/server/node_modules/cli-table3/index.js", "./packages/server/node_modules/cli-table3/src/cell.js", "./packages/server/node_modules/cli-table3/src/layout-manager.js", @@ -3529,5 +3544,5 @@ "./tooling/v8-snapshot/cache/dev-win32/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "5a515f98fe67a8a56a035563ff9c8b9e4a9edc4d035907c3fa5fef1bb60f1dfc" + "deferredHash": "6a80733e7a88dda11de7cc3251f5dcfe54fd064d40e39fbc52a55c4d9ae9471c" } \ No newline at end of file diff --git a/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json index 7cc43329313e..b9142ff76711 100644 --- a/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json @@ -57,13 +57,15 @@ "./packages/server/lib/modes/record.js", "./packages/server/lib/modes/run.ts", "./packages/server/lib/open_project.ts", - "./packages/server/lib/util/process_profiler.ts", "./packages/server/lib/project-base.ts", "./packages/server/lib/socket-ct.ts", + "./packages/server/lib/util/process_profiler.ts", "./packages/server/lib/util/suppress_warnings.js", "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/ci-info/index.js", "./packages/server/node_modules/glob/node_modules/minimatch/minimatch.js", "./packages/server/node_modules/graceful-fs/polyfills.js", + "./packages/server/node_modules/is-ci/index.js", "./packages/server/node_modules/mocha/node_modules/debug/src/node.js", "./packages/server/node_modules/signal-exit/index.js", "./process-nextick-args/index.js", @@ -98,6 +100,7 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", + "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -143,7 +146,6 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", - "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -938,6 +940,7 @@ "./packages/server/node_modules/uuid/dist/v4.js", "./packages/server/node_modules/uuid/dist/v5.js", "./packages/server/server-entry.js", + "./packages/server/snapshot-entry.js", "./packages/socket/index.js", "./packages/socket/lib/socket.ts", "./packages/socket/node_modules/socket.io/dist/broadcast-operator.js", @@ -3644,6 +3647,7 @@ "./packages/net-stubbing/node_modules/mime-types/index.js", "./packages/network/lib/allow-destroy.ts", "./packages/network/lib/blocked.ts", + "./packages/network/lib/ca.ts", "./packages/network/lib/concat-stream.ts", "./packages/network/lib/http-utils.ts", "./packages/network/lib/index.ts", @@ -3807,6 +3811,7 @@ "./packages/server/node_modules/@benmalka/foxdriver/node_modules/graceful-fs/legacy-streams.js", "./packages/server/node_modules/@benmalka/foxdriver/package.json", "./packages/server/node_modules/ansi-regex/index.js", + "./packages/server/node_modules/ci-info/vendors.json", "./packages/server/node_modules/cli-table3/index.js", "./packages/server/node_modules/cli-table3/src/cell.js", "./packages/server/node_modules/cli-table3/src/layout-manager.js", @@ -3931,5 +3936,5 @@ "./tooling/v8-snapshot/cache/prod-win32/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "5a515f98fe67a8a56a035563ff9c8b9e4a9edc4d035907c3fa5fef1bb60f1dfc" + "deferredHash": "6a80733e7a88dda11de7cc3251f5dcfe54fd064d40e39fbc52a55c4d9ae9471c" } \ No newline at end of file From 35c8b6f3d60f5296a67dad6e26bbc83805b8ef39 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 08:47:16 -0600 Subject: [PATCH 35/54] update yarn.lock --- .../cache/dev-darwin/snapshot-meta.cache.json | 4 +- .../prod-darwin/snapshot-meta.cache.json | 4 +- tooling/v8-snapshot/package.json | 2 +- yarn.lock | 70 ++++++------------- 4 files changed, 25 insertions(+), 55 deletions(-) diff --git a/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json index 3e5e70c46abf..0ae4c87680fe 100644 --- a/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json @@ -98,7 +98,6 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", - "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -144,6 +143,7 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", + "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3542,5 +3542,5 @@ "./tooling/v8-snapshot/cache/dev-darwin/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" + "deferredHash": "844da7908a41692a3b04716c88e2f0cdad85ece6f94f6ab89fbd1ffe5c332fd2" } \ No newline at end of file diff --git a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json index ca46dfdf990d..b733298b55bb 100644 --- a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json @@ -100,7 +100,6 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", - "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -146,6 +145,7 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", + "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3934,5 +3934,5 @@ "./tooling/v8-snapshot/cache/prod-darwin/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" + "deferredHash": "844da7908a41692a3b04716c88e2f0cdad85ece6f94f6ab89fbd1ffe5c332fd2" } \ No newline at end of file diff --git a/tooling/v8-snapshot/package.json b/tooling/v8-snapshot/package.json index b629ad239681..7bf3d70367ad 100644 --- a/tooling/v8-snapshot/package.json +++ b/tooling/v8-snapshot/package.json @@ -25,7 +25,7 @@ "resolve-from": "^5.0.0", "source-map-js": "^0.6.2", "temp-dir": "^2.0.0", - "terser": "^5.7.0", + "terser": "5.12.1", "tslib": "^2.0.1", "worker-nodes": "^2.3.0" }, diff --git a/yarn.lock b/yarn.lock index a664576d6125..b0b2ec7b7a40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4219,39 +4219,17 @@ "@babel/runtime" "^7.7.2" regenerator-runtime "^0.13.3" -"@jridgewell/gen-mapping@^0.3.0": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9" - integrity sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A== - dependencies: - "@jridgewell/set-array" "^1.0.1" - "@jridgewell/sourcemap-codec" "^1.4.10" - "@jridgewell/trace-mapping" "^0.3.9" - -"@jridgewell/resolve-uri@3.1.0", "@jridgewell/resolve-uri@^3.0.3": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" - integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== - -"@jridgewell/set-array@^1.0.1": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" - integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== - -"@jridgewell/source-map@^0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb" - integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== - dependencies: - "@jridgewell/gen-mapping" "^0.3.0" - "@jridgewell/trace-mapping" "^0.3.9" +"@jridgewell/resolve-uri@^3.0.3": + version "3.0.4" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.0.4.tgz#b876e3feefb9c8d3aa84014da28b5e52a0640d72" + integrity sha512-cz8HFjOFfUBtvN+NXYSFMHYRdxZMaEl0XypVrhzxBgadKIXhIkRd8aMeHhmF56Sl7SuS8OnUpQ73/k9LE4VnLg== -"@jridgewell/sourcemap-codec@1.4.14", "@jridgewell/sourcemap-codec@^1.4.10": - version "1.4.14" - resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" - integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== +"@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.10" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.10.tgz#baf57b4e2a690d4f38560171f91783656b7f8186" + integrity sha512-Ht8wIW5v165atIX1p+JvKR5ONzUyF4Ac8DZIQ5kZs9zrb6M8SJNXpx1zn04rn65VjBMygRoMXcyYwNK0fT7bEg== -"@jridgewell/trace-mapping@0.3.9": +"@jridgewell/trace-mapping@0.3.9", "@jridgewell/trace-mapping@^0.3.0": version "0.3.9" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== @@ -4259,14 +4237,6 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@jridgewell/trace-mapping@^0.3.0", "@jridgewell/trace-mapping@^0.3.9": - version "0.3.17" - resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" - integrity sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g== - dependencies: - "@jridgewell/resolve-uri" "3.1.0" - "@jridgewell/sourcemap-codec" "1.4.14" - "@kwsites/file-exists@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99" @@ -31237,7 +31207,7 @@ source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, sourc resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@0.7.4, source-map@^0.7.3: +source-map@0.7.4, source-map@^0.7.3, source-map@~0.7.2: version "0.7.4" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656" integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA== @@ -32470,6 +32440,16 @@ terser-webpack-plugin@^5.1.3: source-map "^0.6.1" terser "^5.7.2" +terser@5.12.1, terser@^5.10.0, terser@^5.7.2: + version "5.12.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.12.1.tgz#4cf2ebed1f5bceef5c83b9f60104ac4a78b49e9c" + integrity sha512-NXbs+7nisos5E+yXwAD+y7zrcTkMqb0dEJxIGtSKPdCBzopf7ni4odPul2aechpV7EXNvOudYOX2bb5tln1jbQ== + dependencies: + acorn "^8.5.0" + commander "^2.20.0" + source-map "~0.7.2" + source-map-support "~0.5.20" + terser@^4.1.2, terser@^4.6.3: version "4.8.0" resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17" @@ -32479,16 +32459,6 @@ terser@^4.1.2, terser@^4.6.3: source-map "~0.6.1" source-map-support "~0.5.12" -terser@^5.10.0, terser@^5.7.0, terser@^5.7.2: - version "5.16.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.0.tgz#29362c6f5506e71545c73b069ccd199bb28f7f54" - integrity sha512-KjTV81QKStSfwbNiwlBXfcgMcOloyuRdb62/iLFPGBcVNF4EXjhdYBhYHmbJpiBrVxZhDvltE11j+LBQUxEEJg== - dependencies: - "@jridgewell/source-map" "^0.3.2" - acorn "^8.5.0" - commander "^2.20.0" - source-map-support "~0.5.20" - test-exclude@^5.2.3: version "5.2.3" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0" From 401fbdcf50cee95de7915af6eaa850c38fcf4ac1 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 10:27:28 -0600 Subject: [PATCH 36/54] fix build --- package.json | 2 +- scripts/after-pack-hook.js | 7 +------ scripts/binary/binary-integrity-check-source.js | 8 +++++--- scripts/binary/binary-sources.js | 3 ++- scripts/binary/build.ts | 1 - 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 1e97289012d7..60636530ce27 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Cypress is a next generation front end testing tool built for the modern web", "private": true, "scripts": { - "binary-build": "cross-env DEBUG=cypress:*snap*info NODE_OPTIONS=--max_old_space_size=16384 node ./scripts/binary.js build", + "binary-build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node ./scripts/binary.js build", "binary-deploy": "node ./scripts/binary.js deploy", "binary-deploy-linux": "./scripts/build-linux-binary.sh", "binary-ensure": "node ./scripts/binary.js ensure", diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index b0ae84419eba..9ffc327cfb4b 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -67,11 +67,6 @@ module.exports = async function (params) { ) await cleanup(outputFolder) - - try { - await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) - } catch (error) { - console.log(error) - } + await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) } } diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index e1b6b3b46349..5dc05ed44270 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -60,8 +60,10 @@ function validateFs (fs) { } } -function validatePath (path) { - if (toString.call(path.join) !== `PATH_JOIN_TO_STRING`) { +function validatePath (path, crypto) { + const pathJoinHash = crypto.createHmac('md5', 'HMAC_SECRET').update(toString.call(path.join)).digest('hex') + + if (pathJoinHash !== 'PATH_JOIN_HASH') { throw new Error(`Integrity check failed for path.join.toString()`) } } @@ -91,8 +93,8 @@ function integrityCheck (options) { validateToString() validateElectron(electron) validateFs(fs) - validatePath(path) validateCrypto(crypto) + validatePath(path, crypto) const appPath = electron.app.getAppPath() diff --git a/scripts/binary/binary-sources.js b/scripts/binary/binary-sources.js index 613890dd7470..8af858a4ecb2 100644 --- a/scripts/binary/binary-sources.js +++ b/scripts/binary/binary-sources.js @@ -21,13 +21,14 @@ const getIntegrityCheckSource = (baseDirectory) => { const mainIndexHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') const bytenodeHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') const indexJscHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './packages/server/index.jsc'), 'utf8')).digest('hex') + const pathJoinHash = crypto.createHmac('md5', secret).update(path.join.toString()).digest('hex') return fileSource.split('\n').join(`\n `) .replaceAll('MAIN_INDEX_HASH', mainIndexHash) .replaceAll('BYTENODE_HASH', bytenodeHash) .replaceAll('INDEX_JSC_HASH', indexJscHash) .replaceAll('HMAC_SECRET', secret) - .replaceAll('PATH_JOIN_TO_STRING', escapeString(path.join.toString())) + .replaceAll('PATH_JOIN_HASH', pathJoinHash) .replaceAll('CRYPTO_CREATE_HMAC_TO_STRING', escapeString(crypto.createHmac.toString())) .replaceAll('CRYPTO_HMAC_UPDATE_TO_STRING', escapeString(crypto.Hmac.prototype.update.toString())) .replaceAll('CRYPTO_HMAC_DIGEST_TO_STRING', escapeString(crypto.Hmac.prototype.digest.toString())) diff --git a/scripts/binary/build.ts b/scripts/binary/build.ts index 3065b3f05888..65a85334d4df 100644 --- a/scripts/binary/build.ts +++ b/scripts/binary/build.ts @@ -260,7 +260,6 @@ require('./packages/server/index.js') }, }) } catch (e) { - console.log(e) if (!skipSigning) { throw e } From d3c832a93724759180abe47d91392b3c624a99fc Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 10:57:41 -0600 Subject: [PATCH 37/54] fix windows --- .../binary/binary-integrity-check-source.js | 22 ++++++------------- scripts/binary/binary-sources.js | 2 -- scripts/binary/smoke.js | 12 ---------- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 5dc05ed44270..2f48e83ec1fe 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -60,14 +60,6 @@ function validateFs (fs) { } } -function validatePath (path, crypto) { - const pathJoinHash = crypto.createHmac('md5', 'HMAC_SECRET').update(toString.call(path.join)).digest('hex') - - if (pathJoinHash !== 'PATH_JOIN_HASH') { - throw new Error(`Integrity check failed for path.join.toString()`) - } -} - function validateCrypto (crypto) { if (toString.call(crypto.createHmac) !== `CRYPTO_CREATE_HMAC_TO_STRING`) { throw new Error(`Integrity check failed for crypto.createHmac.toString()`) @@ -87,14 +79,12 @@ function integrityCheck (options) { const require = options.require const electron = require('electron') const fs = require('fs') - const path = require('path') const crypto = require('crypto') validateToString() validateElectron(electron) validateFs(fs) validateCrypto(crypto) - validatePath(path, crypto) const appPath = electron.app.getAppPath() @@ -128,30 +118,32 @@ function integrityCheck (options) { }, { functionName: 'Module._extensions.', - fileName: path.join(appPath, 'node_modules', 'bytenode', 'lib', 'index.js'), + // eslint-disable-next-line no-undef + fileName: [appPath, 'node_modules', 'bytenode', 'lib', 'index.js'].join(PATH_SEP), }, { - fileName: path.join(appPath, 'index.js'), + // eslint-disable-next-line no-undef + fileName: [appPath, 'index.js'].join(PATH_SEP), }, ], }) // eslint-disable-next-line no-undef - const mainIndexHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(path.join(appPath, 'index.js'), 'utf8')).digest('hex') + const mainIndexHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync([appPath, 'index.js'].join(PATH_SEP), 'utf8')).digest('hex') if (mainIndexHash !== 'MAIN_INDEX_HASH') { throw new Error(`Integrity check failed for main index.js file`) } // eslint-disable-next-line no-undef - const bytenodeHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(path.join(appPath, 'node_modules', 'bytenode', 'lib', 'index.js'), 'utf8')).digest('hex') + const bytenodeHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync([appPath, 'node_modules', 'bytenode', 'lib', 'index.js'].join(PATH_SEP), 'utf8')).digest('hex') if (bytenodeHash !== 'BYTENODE_HASH') { throw new Error(`Integrity check failed for main bytenode.js file`) } // eslint-disable-next-line no-undef - const indexJscHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(path.join(appPath, 'packages', 'server', 'index.jsc'), 'utf8')).digest('hex') + const indexJscHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync([appPath, 'packages', 'server', 'index.jsc'].join(PATH_SEP), 'utf8')).digest('hex') if (indexJscHash !== 'INDEX_JSC_HASH') { throw new Error(`Integrity check failed for main server index.jsc file`) diff --git a/scripts/binary/binary-sources.js b/scripts/binary/binary-sources.js index 8af858a4ecb2..1550526b0a9f 100644 --- a/scripts/binary/binary-sources.js +++ b/scripts/binary/binary-sources.js @@ -21,14 +21,12 @@ const getIntegrityCheckSource = (baseDirectory) => { const mainIndexHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') const bytenodeHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './node_modules/bytenode/lib/index.js'), 'utf8')).digest('hex') const indexJscHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './packages/server/index.jsc'), 'utf8')).digest('hex') - const pathJoinHash = crypto.createHmac('md5', secret).update(path.join.toString()).digest('hex') return fileSource.split('\n').join(`\n `) .replaceAll('MAIN_INDEX_HASH', mainIndexHash) .replaceAll('BYTENODE_HASH', bytenodeHash) .replaceAll('INDEX_JSC_HASH', indexJscHash) .replaceAll('HMAC_SECRET', secret) - .replaceAll('PATH_JOIN_HASH', pathJoinHash) .replaceAll('CRYPTO_CREATE_HMAC_TO_STRING', escapeString(crypto.createHmac.toString())) .replaceAll('CRYPTO_HMAC_UPDATE_TO_STRING', escapeString(crypto.Hmac.prototype.update.toString())) .replaceAll('CRYPTO_HMAC_DIGEST_TO_STRING', escapeString(crypto.Hmac.prototype.digest.toString())) diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 8462f5002bf8..75a9d2c71ddd 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -202,12 +202,6 @@ const runV8SnapshotProjectTest = function (buildAppExecutable, e2e) { } const runErroringProjectTest = function (buildAppExecutable, e2e, testName, errorMessage) { - if (shouldSkipProjectTest()) { - console.log('skipping project test') - - return Promise.resolve() - } - return new Promise((resolve, reject) => { const env = _.omit(process.env, 'CYPRESS_INTERNAL_ENV') @@ -254,12 +248,6 @@ const runErroringProjectTest = function (buildAppExecutable, e2e, testName, erro } const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { - if (shouldSkipProjectTest()) { - console.log('skipping failing project test') - - return - } - const testCorruptingFile = async (file, errorMessage) => { const contents = await fs.readFile(file) From eb0dcfed7079d81e3eac7dc0c8b5dcb05912cc68 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 17:35:33 +0000 Subject: [PATCH 38/54] update cache --- tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json | 4 ++-- tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json index 50210b948f88..913ff23a3c45 100644 --- a/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/dev-linux/snapshot-meta.cache.json @@ -98,7 +98,6 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", - "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -144,6 +143,7 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", + "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3541,5 +3541,5 @@ "./tooling/v8-snapshot/cache/dev-linux/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" + "deferredHash": "844da7908a41692a3b04716c88e2f0cdad85ece6f94f6ab89fbd1ffe5c332fd2" } \ No newline at end of file diff --git a/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json index 9011d9483932..8b77e61016d4 100644 --- a/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json @@ -100,7 +100,6 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", - "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -146,6 +145,7 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", + "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3933,5 +3933,5 @@ "./tooling/v8-snapshot/cache/prod-linux/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "081a115f9530cbe682cb907deb95bebda392b565e07c05641dfcfa71668569e7" + "deferredHash": "844da7908a41692a3b04716c88e2f0cdad85ece6f94f6ab89fbd1ffe5c332fd2" } \ No newline at end of file From f27b6877d9f5be9940c7a8cf519e879b78f11275 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 11:37:29 -0600 Subject: [PATCH 39/54] Update scripts/binary/binary-cleanup.js --- scripts/binary/binary-cleanup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index b0d9afd0f773..ec1a9bfd110a 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -149,7 +149,7 @@ const cleanup = async (buildAppDir) => { // but for now, we just track on the dependencies that get pulled in const keptDependencies = [...await getDependencyPathsToKeep(buildAppDir), 'package.json'] - // 2. Gather the dependencies that could potentially be removed from the binary due to being in the snapshot + // 2. Create the entry point bundle and then gather the dependencies that could potentially be removed from the binary due to being in the snapshot or in the entry point bundle const potentiallyRemovedDependencies = [ ...snapshotMetadata.healthy, ...snapshotMetadata.deferred, From b19968180306fc8c8b71017eed732d3cfc6d567a Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 11:38:36 -0600 Subject: [PATCH 40/54] Update scripts/binary/binary-cleanup.js --- scripts/binary/binary-cleanup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index ec1a9bfd110a..0a995a26f107 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -116,6 +116,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => { const createServerEntryPointBundle = async (buildAppDir) => { const unixBuildAppDir = buildAppDir.split(path.sep).join(path.posix.sep) const entryPoints = [path.join(unixBuildAppDir, 'packages/server/index.js')] + // Build the binary entry point ignoring anything that happens in the server-entry since that will be in the v8 snapshot const esbuildResult = await esbuild.build({ entryPoints, bundle: true, From bd533d3ab76c0b32f76a178820c1bb8955774894 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 11:39:38 -0600 Subject: [PATCH 41/54] Update scripts/binary/binary-cleanup.js --- scripts/binary/binary-cleanup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index 0a995a26f107..d51ff07b1b1c 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -136,6 +136,7 @@ const createServerEntryPointBundle = async (buildAppDir) => { console.log(`compiling server entry point bundle to ${path.join(buildAppDir, 'packages', 'server', 'index.jsc')}`) + // Use bytenode to compile the entry point bundle. This will save time on the v8 compile step and ensure the integrity of the entry point await bytenode.compileFile({ filename: path.join(buildAppDir, 'packages', 'server', 'index.js'), output: path.join(buildAppDir, 'packages', 'server', 'index.jsc'), From 8d2598a021c993ebe8b72a1086e67edb45542b05 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 17:56:50 +0000 Subject: [PATCH 42/54] update caches --- tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json | 4 ++-- tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json index fb5753ed411b..0b4c1126cd13 100644 --- a/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/dev-win32/snapshot-meta.cache.json @@ -98,7 +98,6 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", - "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -144,6 +143,7 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", + "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3544,5 +3544,5 @@ "./tooling/v8-snapshot/cache/dev-win32/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "6a80733e7a88dda11de7cc3251f5dcfe54fd064d40e39fbc52a55c4d9ae9471c" + "deferredHash": "7a05f23c5bcd4b5daed5b113c4a56ec620c8686ee7d956edecb5b117e41903bb" } \ No newline at end of file diff --git a/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json index b9142ff76711..a45f9fb8389f 100644 --- a/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json @@ -100,7 +100,6 @@ "./node_modules/@babel/types/lib/validators/isPlaceholderType.js", "./node_modules/@babel/types/lib/validators/isType.js", "./node_modules/@babel/types/lib/validators/validate.js", - "./node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/browser.js", "./node_modules/@cypress/commit-info/node_modules/debug/src/index.js", "./node_modules/@cypress/commit-info/node_modules/execa/lib/errname.js", @@ -146,6 +145,7 @@ "./node_modules/@jimp/tiff/dist/index.js", "./node_modules/@jimp/types/dist/index.js", "./node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js", + "./node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js", "./node_modules/@kwsites/file-exists/dist/index.js", "./node_modules/@kwsites/file-exists/dist/src/index.js", "./node_modules/@nodelib/fs.scandir/out/adapters/fs.js", @@ -3936,5 +3936,5 @@ "./tooling/v8-snapshot/cache/prod-win32/snapshot-entry.js" ], "deferredHashFile": "yarn.lock", - "deferredHash": "6a80733e7a88dda11de7cc3251f5dcfe54fd064d40e39fbc52a55c4d9ae9471c" + "deferredHash": "7a05f23c5bcd4b5daed5b113c4a56ec620c8686ee7d956edecb5b117e41903bb" } \ No newline at end of file From 39d02d6d8b7d7983d13d62a30d36ad24f6dffe8f Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 12:58:09 -0600 Subject: [PATCH 43/54] slight refactor --- .../binary/binary-integrity-check-source.js | 53 ++++++++++++------- scripts/binary/smoke.js | 2 +- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 2f48e83ec1fe..db0cb58a176e 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -74,6 +74,14 @@ function validateCrypto (crypto) { } } +function validateFile ({ filePath, crypto, fs, expectedHash, errorMessage }) { + const hash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(filePath, 'utf8')).digest('hex') + + if (hash !== expectedHash) { + throw new Error(errorMessage) + } +} + // eslint-disable-next-line no-unused-vars function integrityCheck (options) { const require = options.require @@ -81,6 +89,7 @@ function integrityCheck (options) { const fs = require('fs') const crypto = require('crypto') + // 1. Validate that the native functions we are using haven't been tampered with validateToString() validateElectron(electron) validateFs(fs) @@ -88,6 +97,7 @@ function integrityCheck (options) { const appPath = electron.app.getAppPath() + // 2. Validate that the stack trace is what we expect stackIntegrityCheck({ stackToMatch: [ { @@ -128,24 +138,31 @@ function integrityCheck (options) { ], }) - // eslint-disable-next-line no-undef - const mainIndexHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync([appPath, 'index.js'].join(PATH_SEP), 'utf8')).digest('hex') - - if (mainIndexHash !== 'MAIN_INDEX_HASH') { - throw new Error(`Integrity check failed for main index.js file`) - } - - // eslint-disable-next-line no-undef - const bytenodeHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync([appPath, 'node_modules', 'bytenode', 'lib', 'index.js'].join(PATH_SEP), 'utf8')).digest('hex') - - if (bytenodeHash !== 'BYTENODE_HASH') { - throw new Error(`Integrity check failed for main bytenode.js file`) - } + // 3. Validate the three pieces of the entry point: the main index file, the bundled jsc file, and the bytenode node module + validateFile({ + // eslint-disable-next-line no-undef + filePath: [appPath, 'index.js'].join(PATH_SEP), + crypto, + fs, + expectedHash: 'MAIN_INDEX_HASH', + errorMessage: 'Error: Integrity check failed for main index.js file', + }) - // eslint-disable-next-line no-undef - const indexJscHash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync([appPath, 'packages', 'server', 'index.jsc'].join(PATH_SEP), 'utf8')).digest('hex') + validateFile({ + // eslint-disable-next-line no-undef + filePath: [appPath, 'node_modules', 'bytenode', 'lib', 'index.js'].join(PATH_SEP), + crypto, + fs, + expectedHash: 'BYTENODE_HASH', + errorMessage: 'Error: Integrity check failed for main bytenode.js file', + }) - if (indexJscHash !== 'INDEX_JSC_HASH') { - throw new Error(`Integrity check failed for main server index.jsc file`) - } + validateFile({ + // eslint-disable-next-line no-undef + filePath: [appPath, 'packages', 'server', 'index.jsc'].join(PATH_SEP), + crypto, + fs, + expectedHash: 'INDEX_JSC_HASH', + errorMessage: 'Error: Integrity check failed for main server index.jsc file', + }) } diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 75a9d2c71ddd..0fa334b95b70 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -239,7 +239,7 @@ const runErroringProjectTest = function (buildAppExecutable, e2e, testName, erro } if (!errorOutput.includes(errorMessage)) { - return reject(new Error(`running project tests failed with errors but did not include the expected error message: '${errorMessage}'`)) + return reject(new Error(`running project tests failed with errors: ${errorOutput} but did not include the expected error message: '${errorMessage}'`)) } return resolve() From fe8b6cd8f5df54f9db4b8b87c6fa387217b0bf73 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 15:37:27 -0600 Subject: [PATCH 44/54] pr comments --- packages/server/index.js | 6 +++--- packages/server/package.json | 6 +++--- packages/server/snapshot-entry.js | 1 - packages/server/{server-entry.js => start-cypress.js} | 0 packages/server/v8-snapshot-entry.js | 1 + scripts/after-pack-hook.js | 5 +++-- scripts/binary/binary-cleanup.js | 10 +++++----- scripts/binary/binary-integrity-check-source.js | 2 +- scripts/binary/binary-sources.js | 6 +++--- .../cache/prod-darwin/snapshot-meta.cache.json | 4 ++-- .../cache/prod-linux/snapshot-meta.cache.json | 4 ++-- .../cache/prod-win32/snapshot-meta.cache.json | 4 ++-- tooling/v8-snapshot/src/setup/config.ts | 2 +- 13 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 packages/server/snapshot-entry.js rename packages/server/{server-entry.js => start-cypress.js} (100%) create mode 100644 packages/server/v8-snapshot-entry.js diff --git a/packages/server/index.js b/packages/server/index.js index 572417ec7ff9..56d877ed6f89 100644 --- a/packages/server/index.js +++ b/packages/server/index.js @@ -1,6 +1,6 @@ const { initializeStartTime } = require('./lib/util/performance_benchmark') -const run = async () => { +const startCypress = async () => { try { initializeStartTime() @@ -8,7 +8,7 @@ const run = async () => { hookRequire({ forceTypeScript: false }) - await require('./server-entry') + await require('./start-cypress') } catch (error) { // eslint-disable-next-line no-console console.error(error) @@ -16,4 +16,4 @@ const run = async () => { } } -module.exports = run() +module.exports = startCypress() diff --git a/packages/server/package.json b/packages/server/package.json index 89d544152570..864e897a08fb 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -194,11 +194,11 @@ }, "files": [ "config", + "hook-require.js", "lib", "patches", - "server-entry.js", - "snapshot-entry.js", - "hook-require.js" + "start-cypress.js", + "v8-snapshot-entry.js" ], "types": "index.d.ts", "productName": "Cypress", diff --git a/packages/server/snapshot-entry.js b/packages/server/snapshot-entry.js deleted file mode 100644 index 75233dfffa64..000000000000 --- a/packages/server/snapshot-entry.js +++ /dev/null @@ -1 +0,0 @@ -require('./server-entry') diff --git a/packages/server/server-entry.js b/packages/server/start-cypress.js similarity index 100% rename from packages/server/server-entry.js rename to packages/server/start-cypress.js diff --git a/packages/server/v8-snapshot-entry.js b/packages/server/v8-snapshot-entry.js new file mode 100644 index 000000000000..30ea9fd9bf3f --- /dev/null +++ b/packages/server/v8-snapshot-entry.js @@ -0,0 +1 @@ +require('./start-cypress') diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index 9ffc327cfb4b..f5a48e322f36 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -6,7 +6,7 @@ const os = require('os') const path = require('path') const { setupV8Snapshots } = require('@tooling/v8-snapshot') const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses') -const { cleanup } = require('./binary/binary-cleanup') +const { buildEntryPointAndCleanup } = require('./binary/binary-cleanup') const { getIntegrityCheckSource, getBinaryEntryPointSource } = require('./binary/binary-sources') module.exports = async function (params) { @@ -66,7 +66,8 @@ module.exports = async function (params) { }, ) - await cleanup(outputFolder) + // Build out the entry point and clean up prior to setting up v8 snapshots so that the state of the binary is correct + await buildEntryPointAndCleanup(outputFolder) await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) } } diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index d51ff07b1b1c..da78053941fe 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -80,7 +80,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => { absWorkingDir: unixBuildAppDir, external: [ './transpile-ts', - './server-entry', + './start-cypress', 'fsevents', 'pnpapi', '@swc/core', @@ -116,7 +116,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => { const createServerEntryPointBundle = async (buildAppDir) => { const unixBuildAppDir = buildAppDir.split(path.sep).join(path.posix.sep) const entryPoints = [path.join(unixBuildAppDir, 'packages/server/index.js')] - // Build the binary entry point ignoring anything that happens in the server-entry since that will be in the v8 snapshot + // Build the binary entry point ignoring anything that happens in start-cypress since that will be in the v8 snapshot const esbuildResult = await esbuild.build({ entryPoints, bundle: true, @@ -126,7 +126,7 @@ const createServerEntryPointBundle = async (buildAppDir) => { absWorkingDir: unixBuildAppDir, external: [ './transpile-ts', - './server-entry', + './start-cypress', ], }) @@ -146,7 +146,7 @@ const createServerEntryPointBundle = async (buildAppDir) => { return [...Object.keys(esbuildResult.metafile.inputs)].map((input) => `./${input}`) } -const cleanup = async (buildAppDir) => { +const buildEntryPointAndCleanup = async (buildAppDir) => { // 1. Retrieve all dependencies that still need to be kept in the binary. In theory, we could use the bundles generated here as single files within the binary, // but for now, we just track on the dependencies that get pulled in const keptDependencies = [...await getDependencyPathsToKeep(buildAppDir), 'package.json'] @@ -231,5 +231,5 @@ const cleanup = async (buildAppDir) => { } module.exports = { - cleanup, + buildEntryPointAndCleanup, } diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index db0cb58a176e..adbff230b59a 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -120,7 +120,7 @@ function integrityCheck (options) { fileName: 'evalmachine.', }, { - functionName: 'run', + functionName: 'startCypress', fileName: 'evalmachine.', }, { diff --git a/scripts/binary/binary-sources.js b/scripts/binary/binary-sources.js index 1550526b0a9f..077ff675dd28 100644 --- a/scripts/binary/binary-sources.js +++ b/scripts/binary/binary-sources.js @@ -4,18 +4,18 @@ const path = require('path') const escapeString = (string) => string.replaceAll(`\``, `\\\``).replaceAll(`$`, `\\$`) -function read ({ file }) { +function read (file) { const pathToFile = require.resolve(`./${file}`) return fs.readFileSync(pathToFile, 'utf8') } const getBinaryEntryPointSource = () => { - return read({ file: 'binary-entry-point-source.js' }) + return read('binary-entry-point-source.js') } const getIntegrityCheckSource = (baseDirectory) => { - const fileSource = read({ file: 'binary-integrity-check-source.js' }) + const fileSource = read('binary-integrity-check-source.js') const secret = require('crypto').randomBytes(48).toString('hex') const mainIndexHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex') diff --git a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json index b733298b55bb..b5b881125887 100644 --- a/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-darwin/snapshot-meta.cache.json @@ -937,8 +937,8 @@ "./packages/server/node_modules/uuid/dist/v3.js", "./packages/server/node_modules/uuid/dist/v4.js", "./packages/server/node_modules/uuid/dist/v5.js", - "./packages/server/server-entry.js", - "./packages/server/snapshot-entry.js", + "./packages/server/start-cypress.js", + "./packages/server/v8-snapshot-entry.js", "./packages/socket/index.js", "./packages/socket/lib/socket.ts", "./packages/socket/node_modules/socket.io/dist/broadcast-operator.js", diff --git a/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json index 8b77e61016d4..702984a5436e 100644 --- a/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-linux/snapshot-meta.cache.json @@ -936,8 +936,8 @@ "./packages/server/node_modules/uuid/dist/v3.js", "./packages/server/node_modules/uuid/dist/v4.js", "./packages/server/node_modules/uuid/dist/v5.js", - "./packages/server/server-entry.js", - "./packages/server/snapshot-entry.js", + "./packages/server/start-cypress.js", + "./packages/server/v8-snapshot-entry.js", "./packages/socket/index.js", "./packages/socket/lib/socket.ts", "./packages/socket/node_modules/socket.io/dist/broadcast-operator.js", diff --git a/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json b/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json index a45f9fb8389f..834a847f8ad6 100644 --- a/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json +++ b/tooling/v8-snapshot/cache/prod-win32/snapshot-meta.cache.json @@ -939,8 +939,8 @@ "./packages/server/node_modules/uuid/dist/v3.js", "./packages/server/node_modules/uuid/dist/v4.js", "./packages/server/node_modules/uuid/dist/v5.js", - "./packages/server/server-entry.js", - "./packages/server/snapshot-entry.js", + "./packages/server/start-cypress.js", + "./packages/server/v8-snapshot-entry.js", "./packages/socket/index.js", "./packages/socket/lib/socket.ts", "./packages/socket/node_modules/socket.io/dist/broadcast-operator.js", diff --git a/tooling/v8-snapshot/src/setup/config.ts b/tooling/v8-snapshot/src/setup/config.ts index 05e4da21b040..ed6d04495bf3 100644 --- a/tooling/v8-snapshot/src/setup/config.ts +++ b/tooling/v8-snapshot/src/setup/config.ts @@ -21,7 +21,7 @@ const platformString = process.platform const snapshotCacheBaseDir = path.resolve(__dirname, '..', '..', 'cache') const projectBaseDir = path.join(__dirname, '..', '..', '..', '..') -const appEntryFile = require.resolve('@packages/server/snapshot-entry.js') +const appEntryFile = require.resolve('@packages/server/v8-snapshot-entry') const cypressAppSnapshotDir = (cypressAppPath?: string) => { const electronPackageDir = path.join(projectBaseDir, 'packages', 'electron') From bb1390e1b4102774911c41dc0e377249982faaf4 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 1 Dec 2022 16:43:59 -0600 Subject: [PATCH 45/54] Update cache-version.txt --- .circleci/cache-version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/cache-version.txt b/.circleci/cache-version.txt index 4a355f62e1a3..fc3ae1411bde 100644 --- a/.circleci/cache-version.txt +++ b/.circleci/cache-version.txt @@ -1,3 +1,3 @@ # Bump this version to force CI to re-create the cache from scratch. -10-31-22 +12-01-22 From 4187ff6ed51d862fdf2b00d052edc394ae6ae0b1 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 10:58:32 -0600 Subject: [PATCH 46/54] Update scripts/binary/binary-integrity-check-source.js --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index adbff230b59a..1fceaa681637 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -5,7 +5,7 @@ const callFn = Function.call // eslint-disable-next-line no-unused-vars const stackIntegrityCheck = function stackIntegrityCheck (options) { - const originalStackTraceLimit = Error.stackTraceLimit + const originalStackTraceLimit = OrigError.stackTraceLimit const originalStackTrace = OrigError.prepareStackTrace Error.stackTraceLimit = Infinity From ab633136fd595fa4fe1be28116b04a38f36f96a8 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 11:22:21 -0600 Subject: [PATCH 47/54] Update scripts/binary/binary-integrity-check-source.js --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 1fceaa681637..b6f1d4b105d4 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -20,7 +20,7 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { const stack = tempError.stack.filter((frame) => !frame.getFileName().startsWith('node:internal') && !frame.getFileName().startsWith('node:electron')) OrigError.prepareStackTrace = originalStackTrace - Error.stackTraceLimit = originalStackTraceLimit + OrigError.stackTraceLimit = originalStackTraceLimit if (stack.length !== options.stackToMatch.length) { throw new Error(`Integrity check failed with expected stack length ${options.stackToMatch.length} but got ${stack.length}`) From 6751287fd9e98eff49e3dacc6aa6a66a0e24d2b7 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 11:25:25 -0600 Subject: [PATCH 48/54] Update scripts/binary/binary-integrity-check-source.js --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index b6f1d4b105d4..01894ab9443f 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -8,7 +8,7 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { const originalStackTraceLimit = OrigError.stackTraceLimit const originalStackTrace = OrigError.prepareStackTrace - Error.stackTraceLimit = Infinity + OrigError.stackTraceLimit = Infinity OrigError.prepareStackTrace = function (_, stack) { return stack From bebcd8a54782ef6ccd46089fc52ad7d1715e6b59 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 12:46:39 -0600 Subject: [PATCH 49/54] Update scripts/binary/binary-integrity-check-source.js Co-authored-by: Emily Rohrbough --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 01894ab9443f..4b6e9420e33a 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -50,7 +50,7 @@ function validateToString () { function validateElectron (electron) { if (toString.call(electron.app.getAppPath) !== 'function getAppPath() { [native code] }') { - throw new Error(`Integrity check failed for electron.app.getAppPath.toString()`) + throw new Error(`Integrity check failed for toString.call(electron.app.getAppPath)`) } } From 30660b03ed9e5d79a21d1205195d08388f60f460 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 12:48:25 -0600 Subject: [PATCH 50/54] Update scripts/binary/binary-integrity-check-source.js Co-authored-by: Emily Rohrbough --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 4b6e9420e33a..03a88ec26a3f 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -56,7 +56,7 @@ function validateElectron (electron) { function validateFs (fs) { if (toString.call(fs.readFileSync) !== `function(t,r){const n=splitPath(t);if(!n.isAsar)return g.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const t=o.copyFileOut(a);return e.readFileSync(t,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),e.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) { - throw new Error(`Integrity check failed for fs.readFileSync.toString()`) + throw new Error(`Integrity check failed for toString.call(fs.readFileSync)`) } } From 5c1f98154e643a23ccddc01e3c02d7700059fcbe Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 13:47:55 -0600 Subject: [PATCH 51/54] pr comments --- scripts/after-pack-hook.js | 5 +++- scripts/binary/binary-cleanup.js | 25 +++++++++++-------- .../binary/binary-integrity-check-source.js | 10 ++++---- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/scripts/after-pack-hook.js b/scripts/after-pack-hook.js index f5a48e322f36..1a2f9a83a391 100644 --- a/scripts/after-pack-hook.js +++ b/scripts/after-pack-hook.js @@ -68,6 +68,9 @@ module.exports = async function (params) { // Build out the entry point and clean up prior to setting up v8 snapshots so that the state of the binary is correct await buildEntryPointAndCleanup(outputFolder) - await setupV8Snapshots({ cypressAppPath: params.appOutDir, integrityCheckSource: getIntegrityCheckSource(outputFolder) }) + await setupV8Snapshots({ + cypressAppPath: params.appOutDir, + integrityCheckSource: getIntegrityCheckSource(outputFolder), + }) } } diff --git a/scripts/binary/binary-cleanup.js b/scripts/binary/binary-cleanup.js index da78053941fe..0b985fe1de9e 100644 --- a/scripts/binary/binary-cleanup.js +++ b/scripts/binary/binary-cleanup.js @@ -110,7 +110,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => { }) } - return [...Object.keys(esbuildResult.metafile.inputs), ...entryPoints] + return [...Object.keys(esbuildResult.metafile.inputs), ...entryPoints, 'package.json'] } const createServerEntryPointBundle = async (buildAppDir) => { @@ -143,25 +143,30 @@ const createServerEntryPointBundle = async (buildAppDir) => { electron: true, }) + // Convert these inputs to a relative file path. Note that these paths are posix paths. return [...Object.keys(esbuildResult.metafile.inputs)].map((input) => `./${input}`) } const buildEntryPointAndCleanup = async (buildAppDir) => { - // 1. Retrieve all dependencies that still need to be kept in the binary. In theory, we could use the bundles generated here as single files within the binary, - // but for now, we just track on the dependencies that get pulled in - const keptDependencies = [...await getDependencyPathsToKeep(buildAppDir), 'package.json'] + const [keptDependencies, serverEntryPointBundleDependencies] = await Promise.all([ + // 1. Retrieve all dependencies that still need to be kept in the binary. In theory, we could use the bundles generated here as single files within the binary, + // but for now, we just track on the dependencies that get pulled in + getDependencyPathsToKeep(buildAppDir), + // 2. Create a bundle for the server entry point. This will be used to start the server in the binary. It returns the dependencies that are pulled in by this bundle that potentially can now be removed + createServerEntryPointBundle(buildAppDir), + ]) - // 2. Create the entry point bundle and then gather the dependencies that could potentially be removed from the binary due to being in the snapshot or in the entry point bundle + // 3. Gather the dependencies that could potentially be removed from the binary due to being in the snapshot or in the entry point bundle const potentiallyRemovedDependencies = [ ...snapshotMetadata.healthy, ...snapshotMetadata.deferred, ...snapshotMetadata.norewrite, - ...await createServerEntryPointBundle(buildAppDir), + ...serverEntryPointBundleDependencies, ] console.log(`potentially removing ${potentiallyRemovedDependencies.length} dependencies`) - // 3. Remove all dependencies that are in the snapshot but not in the list of kept dependencies from the binary + // 4. Remove all dependencies that are in the snapshot but not in the list of kept dependencies from the binary await Promise.all(potentiallyRemovedDependencies.map(async (dependency) => { const typeScriptlessDependency = dependency.replace(/\.ts$/, '.js') @@ -171,10 +176,10 @@ const buildEntryPointAndCleanup = async (buildAppDir) => { } })) - // 4. Consolidate dependencies that are safe to consolidate (`lodash` and `bluebird`) + // 5. Consolidate dependencies that are safe to consolidate (`lodash` and `bluebird`) await consolidateDeps({ projectBaseDir: buildAppDir }) - // 5. Remove various unnecessary files from the binary to further clean things up. Likely, there is additional work that can be done here + // 6. Remove various unnecessary files from the binary to further clean things up. Likely, there is additional work that can be done here await del([ // Remove test files path.join(buildAppDir, '**', 'test'), @@ -226,7 +231,7 @@ const buildEntryPointAndCleanup = async (buildAppDir) => { path.join(buildAppDir, '**', 'yarn.lock'), ], { force: true }) - // 6. Remove any empty directories as a result of the rest of the cleanup + // 7. Remove any empty directories as a result of the rest of the cleanup await removeEmptyDirectories(buildAppDir) } diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 03a88ec26a3f..8a8abe70ac35 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -3,10 +3,9 @@ const captureStackTrace = Error.captureStackTrace const toString = Function.prototype.toString const callFn = Function.call -// eslint-disable-next-line no-unused-vars const stackIntegrityCheck = function stackIntegrityCheck (options) { const originalStackTraceLimit = OrigError.stackTraceLimit - const originalStackTrace = OrigError.prepareStackTrace + const originalPrepareStackTrace = OrigError.prepareStackTrace OrigError.stackTraceLimit = Infinity @@ -19,7 +18,7 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { captureStackTrace(tempError, arguments.callee) const stack = tempError.stack.filter((frame) => !frame.getFileName().startsWith('node:internal') && !frame.getFileName().startsWith('node:electron')) - OrigError.prepareStackTrace = originalStackTrace + OrigError.prepareStackTrace = originalPrepareStackTrace OrigError.stackTraceLimit = originalStackTraceLimit if (stack.length !== options.stackToMatch.length) { @@ -27,9 +26,8 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { } for (let index = 0; index < options.stackToMatch.length; index++) { - const expectedFunctionName = options.stackToMatch[index].functionName + const { functionName: expectedFunctionName, fileName: expectedFileName } = options.stackToMatch[index] const actualFunctionName = stack[index].getFunctionName() - const expectedFileName = options.stackToMatch[index].fileName const actualFileName = stack[index].getFileName() if (expectedFunctionName && actualFunctionName !== expectedFunctionName) { @@ -49,12 +47,14 @@ function validateToString () { } function validateElectron (electron) { + // Hard coded function as this is electron code and there's not an easy way to get the function string at package time. If this fails on an updated version of electron, we'll need to update this. if (toString.call(electron.app.getAppPath) !== 'function getAppPath() { [native code] }') { throw new Error(`Integrity check failed for toString.call(electron.app.getAppPath)`) } } function validateFs (fs) { + // Hard coded function as this is electron code and there's not an easy way to get the function string at package time. If this fails on an updated version of electron, we'll need to update this. if (toString.call(fs.readFileSync) !== `function(t,r){const n=splitPath(t);if(!n.isAsar)return g.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const t=o.copyFileOut(a);return e.readFileSync(t,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),e.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) { throw new Error(`Integrity check failed for toString.call(fs.readFileSync)`) } From adadd796ebee762c639c5f90bbe2bc018f681d13 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 16:34:08 -0600 Subject: [PATCH 52/54] further comments --- .../binary/binary-integrity-check-source.js | 38 +++++++++++++------ scripts/binary/smoke.js | 10 ++--- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 8a8abe70ac35..7fdd7e523641 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -3,6 +3,12 @@ const captureStackTrace = Error.captureStackTrace const toString = Function.prototype.toString const callFn = Function.call +const integrityErrorMessage = ` +We detected an issue with the integrity of the Cypress binary. It may have been compromised and is not safe to run. We recommend re-installing the Cypress binary with: + +\`cypress cache clear && cypress install\` +` + const stackIntegrityCheck = function stackIntegrityCheck (options) { const originalStackTraceLimit = OrigError.stackTraceLimit const originalPrepareStackTrace = OrigError.prepareStackTrace @@ -22,7 +28,8 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { OrigError.stackTraceLimit = originalStackTraceLimit if (stack.length !== options.stackToMatch.length) { - throw new Error(`Integrity check failed with expected stack length ${options.stackToMatch.length} but got ${stack.length}`) + console.error(`Integrity check failed with expected stack length ${options.stackToMatch.length} but got ${stack.length}`) + throw new Error(integrityErrorMessage) } for (let index = 0; index < options.stackToMatch.length; index++) { @@ -31,17 +38,20 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) { const actualFileName = stack[index].getFileName() if (expectedFunctionName && actualFunctionName !== expectedFunctionName) { - throw new Error(`Integrity check failed with expected function name ${expectedFunctionName} but got ${actualFunctionName}`) + console.error(`Integrity check failed with expected function name ${expectedFunctionName} but got ${actualFunctionName}`) + throw new Error(integrityErrorMessage) } if (expectedFileName && actualFileName !== expectedFileName) { - throw new Error(`Integrity check failed with expected file name ${expectedFileName} but got ${actualFileName}`) + console.error(`Integrity check failed with expected file name ${expectedFileName} but got ${actualFileName}`) + throw new Error(integrityErrorMessage) } } } function validateToString () { if (toString.call !== callFn) { + console.error(`Integrity check failed for toString.call`) throw new Error('Integrity check failed for toString.call') } } @@ -49,6 +59,7 @@ function validateToString () { function validateElectron (electron) { // Hard coded function as this is electron code and there's not an easy way to get the function string at package time. If this fails on an updated version of electron, we'll need to update this. if (toString.call(electron.app.getAppPath) !== 'function getAppPath() { [native code] }') { + console.error(`Integrity check failed for toString.call(electron.app.getAppPath)`) throw new Error(`Integrity check failed for toString.call(electron.app.getAppPath)`) } } @@ -56,21 +67,25 @@ function validateElectron (electron) { function validateFs (fs) { // Hard coded function as this is electron code and there's not an easy way to get the function string at package time. If this fails on an updated version of electron, we'll need to update this. if (toString.call(fs.readFileSync) !== `function(t,r){const n=splitPath(t);if(!n.isAsar)return g.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const t=o.copyFileOut(a);return e.readFileSync(t,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),e.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) { - throw new Error(`Integrity check failed for toString.call(fs.readFileSync)`) + console.error(`Integrity check failed for toString.call(fs.readFileSync)`) + throw new Error(integrityErrorMessage) } } function validateCrypto (crypto) { if (toString.call(crypto.createHmac) !== `CRYPTO_CREATE_HMAC_TO_STRING`) { - throw new Error(`Integrity check failed for crypto.createHmac.toString()`) + console.error(`Integrity check failed for toString.call(crypto.createHmac)`) + throw new Error(integrityErrorMessage) } if (toString.call(crypto.Hmac.prototype.update) !== `CRYPTO_HMAC_UPDATE_TO_STRING`) { - throw new Error(`Integrity check failed for crypto.Hmac.prototype.update.toString()`) + console.error(`Integrity check failed for toString.call(crypto.Hmac.prototype.update)`) + throw new Error(integrityErrorMessage) } if (toString.call(crypto.Hmac.prototype.digest) !== `CRYPTO_HMAC_DIGEST_TO_STRING`) { - throw new Error(`Integrity check failed for crypto.Hmac.prototype.digest.toString()`) + console.error(`Integrity check failed for toString.call(crypto.Hmac.prototype.digest)`) + throw new Error(integrityErrorMessage) } } @@ -78,7 +93,8 @@ function validateFile ({ filePath, crypto, fs, expectedHash, errorMessage }) { const hash = crypto.createHmac('md5', 'HMAC_SECRET').update(fs.readFileSync(filePath, 'utf8')).digest('hex') if (hash !== expectedHash) { - throw new Error(errorMessage) + console.error(errorMessage) + throw new Error(integrityErrorMessage) } } @@ -145,7 +161,7 @@ function integrityCheck (options) { crypto, fs, expectedHash: 'MAIN_INDEX_HASH', - errorMessage: 'Error: Integrity check failed for main index.js file', + errorMessage: 'Integrity check failed for main index.js file', }) validateFile({ @@ -154,7 +170,7 @@ function integrityCheck (options) { crypto, fs, expectedHash: 'BYTENODE_HASH', - errorMessage: 'Error: Integrity check failed for main bytenode.js file', + errorMessage: 'Integrity check failed for main bytenode.js file', }) validateFile({ @@ -163,6 +179,6 @@ function integrityCheck (options) { crypto, fs, expectedHash: 'INDEX_JSC_HASH', - errorMessage: 'Error: Integrity check failed for main server index.jsc file', + errorMessage: 'Integrity check failed for main server index.jsc file', }) } diff --git a/scripts/binary/smoke.js b/scripts/binary/smoke.js index 0fa334b95b70..6438ca54e50d 100644 --- a/scripts/binary/smoke.js +++ b/scripts/binary/smoke.js @@ -262,9 +262,9 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await fs.move(`${file}.bak`, file, { overwrite: true }) } - await testCorruptingFile(path.join(buildAppDir, 'index.js'), 'Error: Integrity check failed for main index.js file') - await testCorruptingFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc'), 'Error: Integrity check failed for main server index.jsc file') - await testCorruptingFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js'), 'Error: Integrity check failed for main bytenode.js file') + await testCorruptingFile(path.join(buildAppDir, 'index.js'), 'Integrity check failed for main index.js file') + await testCorruptingFile(path.join(buildAppDir, 'packages', 'server', 'index.jsc'), 'Integrity check failed for main server index.jsc file') + await testCorruptingFile(path.join(buildAppDir, 'node_modules', 'bytenode', 'lib', 'index.js'), 'Integrity check failed for main bytenode.js file') const testAlteringEntryPoint = async (additionalCode, errorMessage) => { const packageJsonContents = await fs.readJSON(path.join(buildAppDir, 'package.json')) @@ -286,8 +286,8 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) { await fs.remove(path.join(buildAppDir, 'index2.js')) } - await testAlteringEntryPoint('console.log("simple alteration")', 'Error: Integrity check failed with expected stack length 9 but got 10') - await testAlteringEntryPoint('console.log("accessing " + global.getSnapshotResult())', 'Error: getSnapshotResult can only be called once') + await testAlteringEntryPoint('console.log("simple alteration")', 'Integrity check failed with expected stack length 9 but got 10') + await testAlteringEntryPoint('console.log("accessing " + global.getSnapshotResult())', 'getSnapshotResult can only be called once') } const test = async function (buildAppExecutable, buildAppDir) { From 5f3a7351474e241ae20cac5ec488f7bd8a146c19 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 16:47:21 -0600 Subject: [PATCH 53/54] update messaging on failures --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index 7fdd7e523641..d3b3f5a7437d 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -4,7 +4,7 @@ const toString = Function.prototype.toString const callFn = Function.call const integrityErrorMessage = ` -We detected an issue with the integrity of the Cypress binary. It may have been compromised and is not safe to run. We recommend re-installing the Cypress binary with: +We detected an issue with the integrity of the Cypress binary. It may have been modified and is not safe to run. We recommend re-installing the Cypress binary with: \`cypress cache clear && cypress install\` ` From 4e8d8e310f436a975da717e9795a5c133aa81d7c Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 2 Dec 2022 19:59:34 -0600 Subject: [PATCH 54/54] update messaging on failures --- scripts/binary/binary-integrity-check-source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/binary/binary-integrity-check-source.js b/scripts/binary/binary-integrity-check-source.js index d3b3f5a7437d..cec2c9316ca9 100644 --- a/scripts/binary/binary-integrity-check-source.js +++ b/scripts/binary/binary-integrity-check-source.js @@ -4,7 +4,7 @@ const toString = Function.prototype.toString const callFn = Function.call const integrityErrorMessage = ` -We detected an issue with the integrity of the Cypress binary. It may have been modified and is not safe to run. We recommend re-installing the Cypress binary with: +We detected an issue with the integrity of the Cypress binary. It may have been modified and cannot run. We recommend re-installing the Cypress binary with: \`cypress cache clear && cypress install\` `