Skip to content

compartment-mapper: dynamic require of "node:"-prefixed builtins fails #2754

Closed
@boneskull

Description

@boneskull

Describe the bug

While I was careful to add a test case for "dynamic require of a builtin module", that test case only covers a bare module specifier (cluster).

Changing cluster to node:cluster fails the test:

  Rejected promise returned by test. Reason:

  TypeError {
    message: 'Failed to load module "node:cluster" in package "file:///path/to/compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/" (1 underlying failures: The URL must be of scheme file',
  }

  TypeError: Failed to load module "node:cluster" in package "file:///path/to/compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/" (1 underlying failures: The URL must be of scheme file
      at throwAggregateError (file:///path/to/ses/src/module-load.js:557:11)
      at loadNow (file:///path/to/ses/src/module-load.js:654:3)
      at Compartment.importNow (file:///path/to/ses/src/compartment.js:187:5)
      at require (file:///path/to/compartment-mapper/src/parse-cjs-shared-export-wrapper.js:149:33)
      at Proxy.eval (eval at <anonymous> (eval at makeEvaluate (file:///path/to/ses/src/make-evaluate.js:92:27)), <anonymous>:5:1)
      at Object.execute (file:///path/to/compartment-mapper/src/parse-cjs.js:56:13)
      at execute (file:///path/to/ses/src/module-instance.js:101:24)
      at compartmentImportNow (file:///path/to/ses/src/compartment.js:103:3)
      at file:///path/to/ses/src/compartment.js:160:27
      at async file:///path/to/compartment-mapper/test/dynamic-require.test.js:303:25

This is reproducible outside of the @endo/compartment-mapper's test environment (I found it via @lavamoat/node's testing environment; lol).

Steps to reproduce

  1. Modify compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/index.js:

    diff --git a/packages/compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/index.js b/packages/compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/index.js
    index f64a83d77acdc2d1b5b5b9ffe254108d2c0fa567..972b76820199e55ef0c0624417708c4a432a9cb4 100644
    --- a/packages/compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/index.js
    +++ b/packages/compartment-mapper/test/fixtures-dynamic/node_modules/hooked-app/index.js
    @@ -1,5 +1,5 @@
    exports.isOk = require('hooked').isOk;
    
    -const builtin = 'cluster';
    +const builtin = 'node:cluster';
    
    require(builtin);
    \ No newline at end of file
  2. Execute test (from packages/compartment-mapper):

    npx ava test/dynamic-require.test.js -c 1 -m 'inter-package and exit module dynamic require works'
  3. Observe failure akin to the trace pasted above.

Expected behavior

It should be the same behavior as exhibited sans-prefix.

Additional context

This is likely my fault, so I will fix it.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions