Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add ancestor package.json checks for tmpdir #38285

Closed
wants to merge 1 commit into from

Conversation

richardlau
Copy link
Member

Policy tests can fail if a package.json exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

Refs: #38088
Refs: #35600
Refs: #35633

cc @bmeck

Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Apr 18, 2021
@nodejs-github-bot
Copy link
Collaborator

@richardlau
Copy link
Member Author

richardlau commented Apr 18, 2021

With this change:

$ cat /home/rlau/node-tmp/package.json 
{"main": "dep.js"}
$ NODE_TEST_DIR=/home/rlau/node-tmp node test/pummel/test-policy-integrity.js 
assert.js:145
  throw err;
  ^

AssertionError [ERR_ASSERTION]: This test shouldn't load properties from a package.json above its file location. Found package.json at /home/rlau/node-tmp/package.json.
    at Proxy.requireNoPackageJSONAbove (/home/rlau/sandbox/github/node/test/common/index.js:716:14)
    at Object.<anonymous> (/home/rlau/sandbox/github/node/test/pummel/test-policy-integrity.js:79:8)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: undefined,
  operator: 'fail'
}
$

compared to without:

$ cat /home/rlau/node-tmp/package.json 
{"main": "dep.js"}
$ NODE_TEST_DIR=/home/rlau/node-tmp node test/pummel/test-policy-integrity.js 
permutation 118 failed
{
  config: {
    onError: 'exit',
    shouldSucceed: true,
    entryPath: './worker-spawner.cjs',
    willDeletePolicy: true,
    preloads: [],
    parentPath: './parent.js',
    depPath: './dep.js',
    resources: {
      './dep.js': {
        body: '',
        integrities: [
          'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=',
          'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='
        ]
      },
      './parent.js': {
        body: '\n' +
          '    if (!process.env.DEP_FILE) {\n' +
          '      console.error(\n' +
          "        'missing required DEP_FILE env to determine dependency'\n" +
          '      );\n' +
          '      process.exit(33);\n' +
          '    }\n' +
          '    require(process.env.DEP_FILE)\n' +
          '  ',
        integrities: [
          'sha256-AzbH3oEA96J/+tLSqOJ+LaIt9vdOY+ikShkvKm0VutU=',
          'sha256-R0QVSw9BUI7znwKNvt6BuzkLozhYKTtFNRSENIL5H7k='
        ]
      },
      './worker-spawner.cjs': {
        body: '\n' +
          "  const path = require('path');\n" +
          "  const { Worker } = require('worker_threads');\n" +
          '  if (!process.env.PARENT_FILE) {\n' +
          '    console.error(\n' +
          "      'missing required PARENT_FILE env to determine worker entry point'\n" +
          '    );\n' +
          '    process.exit(33);\n' +
          '  }\n' +
          '  if (!process.env.DELETABLE_POLICY_FILE) {\n' +
          '    console.error(\n' +
          "      'missing required DELETABLE_POLICY_FILE env to check reloading'\n" +
          '    );\n' +
          '    process.exit(33);\n' +
          '  }\n' +
          '  const w = new Worker(path.resolve(process.env.PARENT_FILE));\n' +
          "  w.on('exit', (status) => process.exit(status === 0 ? 0 : 1));\n",
        integrities: [
          'sha256-23P4m8edtJAPTH24RJHIHMEuMVgP7QKcgWBSyj6FxPc=',
          'sha256-XTRkNC3vxo+zvjv7CD8iapeqc7npNN7TwqRR0TOv5lg='
        ]
      }
    }
  },
  manifest: {
    onerror: 'exit',
    resources: {
      'file:///home/rlau/node-tmp/.tmp.0/test-policy-integrity-permutation-118/dep.js': {
        integrity: 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU= sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=',
        dependencies: true
      },
      'file:///home/rlau/node-tmp/.tmp.0/test-policy-integrity-permutation-118/parent.js': {
        integrity: 'sha256-AzbH3oEA96J/+tLSqOJ+LaIt9vdOY+ikShkvKm0VutU= sha256-R0QVSw9BUI7znwKNvt6BuzkLozhYKTtFNRSENIL5H7k=',
        dependencies: true
      },
      'file:///home/rlau/node-tmp/.tmp.0/test-policy-integrity-permutation-118/worker-spawner.cjs': {
        integrity: 'sha256-23P4m8edtJAPTH24RJHIHMEuMVgP7QKcgWBSyj6FxPc= sha256-XTRkNC3vxo+zvjv7CD8iapeqc7npNN7TwqRR0TOv5lg=',
        dependencies: true
      }
    }
  }
}
exit code: 1 signal: null
stdout: 
stderr: 
/home/rlau/sandbox/github/node/test/pummel/test-policy-integrity.js:187
        throw e;
        ^

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

1 !== 0

    at ChildProcess.<anonymous> (/home/rlau/sandbox/github/node/test/pummel/test-policy-integrity.js:170:18)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: 1,
  expected: 0,
  operator: 'strictEqual'
}
$ 

@Trott Trott requested a review from bmeck April 19, 2021 05:01
Trott pushed a commit that referenced this pull request Apr 23, 2021
Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

PR-URL: #38285
Refs: #38088
Refs: #35600
Refs: #35633
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott
Copy link
Member

Trott commented Apr 23, 2021

Landed in f9e07e4

@Trott Trott closed this Apr 23, 2021
@richardlau richardlau deleted the integrity branch April 23, 2021 13:36
targos pushed a commit that referenced this pull request Apr 29, 2021
Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

PR-URL: #38285
Refs: #38088
Refs: #35600
Refs: #35633
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@targos targos mentioned this pull request May 3, 2021
targos pushed a commit that referenced this pull request May 30, 2021
Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

PR-URL: #38285
Refs: #38088
Refs: #35600
Refs: #35633
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jun 5, 2021
Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

PR-URL: #38285
Refs: #38088
Refs: #35600
Refs: #35633
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jun 11, 2021
Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

PR-URL: #38285
Refs: #38088
Refs: #35600
Refs: #35633
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants