diff --git a/test/pummel/pummel.status b/test/pummel/pummel.status index a447b56498c123..5ff3cdbe0e5a7a 100644 --- a/test/pummel/pummel.status +++ b/test/pummel/pummel.status @@ -7,8 +7,6 @@ prefix pummel [true] # This section applies to all platforms [$system==win32] -# https://github.com/nodejs/node/issues/40694 -test-policy-integrity: PASS,FLAKY [$system==linux] # https://github.com/nodejs/node/issues/38226 diff --git a/test/pummel/test-policy-integrity-dep.js b/test/pummel/test-policy-integrity-dep.js index 2016fc6ff40dc8..42948ce896e151 100644 --- a/test/pummel/test-policy-integrity-dep.js +++ b/test/pummel/test-policy-integrity-dep.js @@ -60,24 +60,6 @@ const parentBody = { import(process.env.DEP_FILE) `, }; -const workerSpawningBody = ` - const path = require('path'); - const { Worker } = require('worker_threads'); - if (!process.env.PARENT_FILE) { - console.error( - 'missing required PARENT_FILE env to determine worker entry point' - ); - process.exit(33); - } - if (!process.env.DELETABLE_POLICY_FILE) { - console.error( - 'missing required DELETABLE_POLICY_FILE env to check reloading' - ); - process.exit(33); - } - const w = new Worker(path.resolve(process.env.PARENT_FILE)); - w.on('exit', (status) => process.exit(status === 0 ? 0 : 1)); -`; let nextTestId = 1; function newTestId() { @@ -100,12 +82,11 @@ function drainQueue() { if (toSpawn.length) { const config = toSpawn.shift(); const { - shouldSucceed, // = (() => { throw new Error('required')})(), - preloads, // = (() =>{ throw new Error('required')})(), - entryPath, // = (() => { throw new Error('required')})(), - willDeletePolicy, // = (() => { throw new Error('required')})(), - onError, // = (() => { throw new Error('required')})(), - resources, // = (() => { throw new Error('required')})(), + shouldSucceed, + preloads, + entryPath, + onError, + resources, parentPath, depPath, } = config; @@ -118,7 +99,7 @@ function drainQueue() { tmpdir.path, `deletable-policy-${testId}.json` ); - const cliPolicy = willDeletePolicy ? tmpPolicyPath : policyPath; + fs.rmSync(configDirPath, { maxRetries: 3, recursive: true, force: true }); fs.mkdirSync(configDirPath, { recursive: true }); const manifest = { @@ -140,7 +121,7 @@ function drainQueue() { } const manifestBody = JSON.stringify(manifest); fs.writeFileSync(manifestPath, manifestBody); - if (cliPolicy === tmpPolicyPath) { + if (policyPath === tmpPolicyPath) { fs.writeFileSync(tmpPolicyPath, manifestBody); } const spawnArgs = [ @@ -148,7 +129,7 @@ function drainQueue() { [ '--unhandled-rejections=strict', '--experimental-policy', - cliPolicy, + policyPath, ...preloads.flatMap((m) => ['-r', m]), entryPath, '--', @@ -255,7 +236,6 @@ function fileExtensionFormat(extension, packageType) { throw new Error('unknown format ' + extension); } for (const permutation of permutations({ - entry: ['dep'], preloads: [[], ['parent'], ['dep']], onError: ['log', 'exit'], parentExtension: ['.js', '.mjs', '.cjs'], @@ -282,10 +262,9 @@ for (const permutation of permutations({ continue; } const depPath = `./dep${permutation.depExtension}`; - const workerSpawnerPath = './worker-spawner.cjs'; - const entryPath = depPath; + const packageJSON = { - main: entryPath, + main: depPath, type: permutation.packageType, }; if (permutation.packageType === 'no-field') { @@ -310,8 +289,7 @@ for (const permutation of permutations({ if (parentFormat !== 'commonjs') { permutation.preloads = permutation.preloads.filter((_) => _ !== 'parent'); } - const hasParent = - permutation.entry !== 'dep' || permutation.preloads.includes('parent'); + const hasParent = permutation.preloads.includes('parent'); if (hasParent) { resources[parentPath] = { body: parentBody[parentFormat], @@ -328,12 +306,7 @@ for (const permutation of permutations({ throw new Error('unreachable'); } } - if (permutation.entry === 'worker') { - resources[workerSpawnerPath] = { - body: workerSpawningBody, - integrities: hash('sha256', workerSpawningBody), - }; - } + if (permutation.packageType !== 'no-package-json') { let packageBody = JSON.stringify(packageJSON, null, 2); let packageIntegrities = hash('sha256', packageBody); @@ -360,18 +333,15 @@ for (const permutation of permutations({ integrities: packageIntegrities, }; } - const willDeletePolicy = permutation.entry === 'worker'; + if (permutation.onError === 'log') { shouldSucceed = true; } tests.add( JSON.stringify({ - // hasParent, - // original: permutation, onError: permutation.onError, shouldSucceed, - entryPath, - willDeletePolicy, + entryPath: depPath, preloads: permutation.preloads .map((_) => { return { diff --git a/test/pummel/test-policy-integrity-parent.js b/test/pummel/test-policy-integrity-parent.js index 1626a4a4158f90..11b3f353b64d97 100644 --- a/test/pummel/test-policy-integrity-parent.js +++ b/test/pummel/test-policy-integrity-parent.js @@ -60,24 +60,6 @@ const parentBody = { import(process.env.DEP_FILE) `, }; -const workerSpawningBody = ` - const path = require('path'); - const { Worker } = require('worker_threads'); - if (!process.env.PARENT_FILE) { - console.error( - 'missing required PARENT_FILE env to determine worker entry point' - ); - process.exit(33); - } - if (!process.env.DELETABLE_POLICY_FILE) { - console.error( - 'missing required DELETABLE_POLICY_FILE env to check reloading' - ); - process.exit(33); - } - const w = new Worker(path.resolve(process.env.PARENT_FILE)); - w.on('exit', (status) => process.exit(status === 0 ? 0 : 1)); -`; let nextTestId = 1; function newTestId() { @@ -100,12 +82,12 @@ function drainQueue() { if (toSpawn.length) { const config = toSpawn.shift(); const { - shouldSucceed, // = (() => { throw new Error('required')})(), - preloads, // = (() =>{ throw new Error('required')})(), - entryPath, // = (() => { throw new Error('required')})(), - willDeletePolicy, // = (() => { throw new Error('required')})(), - onError, // = (() => { throw new Error('required')})(), - resources, // = (() => { throw new Error('required')})(), + shouldSucceed, + preloads, + entryPath, + willDeletePolicy, + onError, + resources, parentPath, depPath, } = config; @@ -255,7 +237,6 @@ function fileExtensionFormat(extension, packageType) { throw new Error('unknown format ' + extension); } for (const permutation of permutations({ - entry: ['worker', 'parent', 'dep'], preloads: [[], ['parent'], ['dep']], onError: ['log', 'exit'], parentExtension: ['.js', '.mjs', '.cjs'], @@ -282,12 +263,7 @@ for (const permutation of permutations({ continue; } const depPath = `./dep${permutation.depExtension}`; - const workerSpawnerPath = './worker-spawner.cjs'; - const entryPath = { - dep: depPath, - parent: parentPath, - worker: workerSpawnerPath, - }[permutation.entry]; + const entryPath = parentPath; const packageJSON = { main: entryPath, type: permutation.packageType, @@ -314,30 +290,22 @@ for (const permutation of permutations({ if (parentFormat !== 'commonjs') { permutation.preloads = permutation.preloads.filter((_) => _ !== 'parent'); } - const hasParent = - permutation.entry !== 'dep' || permutation.preloads.includes('parent'); - if (hasParent) { - resources[parentPath] = { - body: parentBody[parentFormat], - integrities: hash('sha256', parentBody[parentFormat]), - }; - if (permutation.parentIntegrity === 'invalid') { - resources[parentPath].body += '\n// INVALID INTEGRITY'; - shouldSucceed = false; - } else if (permutation.parentIntegrity === 'missing') { - resources[parentPath].integrities = null; - shouldSucceed = false; - } else if (permutation.parentIntegrity === 'match') { - } else { - throw new Error('unreachable'); - } - } - if (permutation.entry === 'worker') { - resources[workerSpawnerPath] = { - body: workerSpawningBody, - integrities: hash('sha256', workerSpawningBody), - }; + + resources[parentPath] = { + body: parentBody[parentFormat], + integrities: hash('sha256', parentBody[parentFormat]), + }; + if (permutation.parentIntegrity === 'invalid') { + resources[parentPath].body += '\n// INVALID INTEGRITY'; + shouldSucceed = false; + } else if (permutation.parentIntegrity === 'missing') { + resources[parentPath].integrities = null; + shouldSucceed = false; + } else if (permutation.parentIntegrity === 'match') { + } else { + throw new Error('unreachable'); } + if (permutation.packageType !== 'no-package-json') { let packageBody = JSON.stringify(packageJSON, null, 2); let packageIntegrities = hash('sha256', packageBody); @@ -364,18 +332,16 @@ for (const permutation of permutations({ integrities: packageIntegrities, }; } - const willDeletePolicy = permutation.entry === 'worker'; + if (permutation.onError === 'log') { shouldSucceed = true; } tests.add( JSON.stringify({ - // hasParent, - // original: permutation, onError: permutation.onError, shouldSucceed, entryPath, - willDeletePolicy, + willDeletePolicy: false, preloads: permutation.preloads .map((_) => { return { diff --git a/test/pummel/test-policy-integrity-worker.js b/test/pummel/test-policy-integrity-worker.js index 7459486e045c66..7a9b119095bd4f 100644 --- a/test/pummel/test-policy-integrity-worker.js +++ b/test/pummel/test-policy-integrity-worker.js @@ -100,12 +100,11 @@ function drainQueue() { if (toSpawn.length) { const config = toSpawn.shift(); const { - shouldSucceed, // = (() => { throw new Error('required')})(), - preloads, // = (() =>{ throw new Error('required')})(), - entryPath, // = (() => { throw new Error('required')})(), - willDeletePolicy, // = (() => { throw new Error('required')})(), - onError, // = (() => { throw new Error('required')})(), - resources, // = (() => { throw new Error('required')})(), + shouldSucceed, + preloads, + entryPath, + onError, + resources, parentPath, depPath, } = config; @@ -118,7 +117,7 @@ function drainQueue() { tmpdir.path, `deletable-policy-${testId}.json` ); - const cliPolicy = willDeletePolicy ? tmpPolicyPath : policyPath; + fs.rmSync(configDirPath, { maxRetries: 3, recursive: true, force: true }); fs.mkdirSync(configDirPath, { recursive: true }); const manifest = { @@ -140,15 +139,15 @@ function drainQueue() { } const manifestBody = JSON.stringify(manifest); fs.writeFileSync(manifestPath, manifestBody); - if (cliPolicy === tmpPolicyPath) { - fs.writeFileSync(tmpPolicyPath, manifestBody); - } + + fs.writeFileSync(tmpPolicyPath, manifestBody); + const spawnArgs = [ process.execPath, [ '--unhandled-rejections=strict', '--experimental-policy', - cliPolicy, + tmpPolicyPath, ...preloads.flatMap((m) => ['-r', m]), entryPath, '--', @@ -255,7 +254,6 @@ function fileExtensionFormat(extension, packageType) { throw new Error('unknown format ' + extension); } for (const permutation of permutations({ - entry: ['worker'], preloads: [[], ['parent'], ['dep']], onError: ['log', 'exit'], parentExtension: ['.js', '.mjs', '.cjs'], @@ -283,9 +281,8 @@ for (const permutation of permutations({ } const depPath = `./dep${permutation.depExtension}`; const workerSpawnerPath = './worker-spawner.cjs'; - const entryPath = workerSpawnerPath; const packageJSON = { - main: entryPath, + main: workerSpawnerPath, type: permutation.packageType, }; if (permutation.packageType === 'no-field') { @@ -310,30 +307,27 @@ for (const permutation of permutations({ if (parentFormat !== 'commonjs') { permutation.preloads = permutation.preloads.filter((_) => _ !== 'parent'); } - const hasParent = - permutation.entry !== 'dep' || permutation.preloads.includes('parent'); - if (hasParent) { - resources[parentPath] = { - body: parentBody[parentFormat], - integrities: hash('sha256', parentBody[parentFormat]), - }; - if (permutation.parentIntegrity === 'invalid') { - resources[parentPath].body += '\n// INVALID INTEGRITY'; - shouldSucceed = false; - } else if (permutation.parentIntegrity === 'missing') { - resources[parentPath].integrities = null; - shouldSucceed = false; - } else if (permutation.parentIntegrity === 'match') { - } else { - throw new Error('unreachable'); - } - } - if (permutation.entry === 'worker') { - resources[workerSpawnerPath] = { - body: workerSpawningBody, - integrities: hash('sha256', workerSpawningBody), - }; + + resources[parentPath] = { + body: parentBody[parentFormat], + integrities: hash('sha256', parentBody[parentFormat]), + }; + if (permutation.parentIntegrity === 'invalid') { + resources[parentPath].body += '\n// INVALID INTEGRITY'; + shouldSucceed = false; + } else if (permutation.parentIntegrity === 'missing') { + resources[parentPath].integrities = null; + shouldSucceed = false; + } else if (permutation.parentIntegrity === 'match') { + } else { + throw new Error('unreachable'); } + + resources[workerSpawnerPath] = { + body: workerSpawningBody, + integrities: hash('sha256', workerSpawningBody), + }; + if (permutation.packageType !== 'no-package-json') { let packageBody = JSON.stringify(packageJSON, null, 2); let packageIntegrities = hash('sha256', packageBody); @@ -360,18 +354,15 @@ for (const permutation of permutations({ integrities: packageIntegrities, }; } - const willDeletePolicy = permutation.entry === 'worker'; + if (permutation.onError === 'log') { shouldSucceed = true; } tests.add( JSON.stringify({ - // hasParent, - // original: permutation, onError: permutation.onError, shouldSucceed, - entryPath, - willDeletePolicy, + entryPath: workerSpawnerPath, preloads: permutation.preloads .map((_) => { return {