Files
node/test/sea/test-single-executable-application-vfs.js
Manjeet Singh 1b99d7cd8c sea: mount the SEA VFS in workers at layer 0
A single executable application built with "useVfs" mounted the VFS
serving its "assets" in the main thread only, at a mount point numbered
in mount order, so a worker started from a script among the assets
could not load it. On Windows this failed as an invalid package.json
at \.\nul\package.json, because paths under the NUL device open it.

"useVfs" is the --vfs-load of a single executable application: its
"assets" or its "vfsArchive" archive are the source, and its "main" is
the entry point. Mount it at layer 0, the mount point reserved for the
--vfs-load source, whichever provider serves it, and mount it in
workers too, as was already done for an archive. Other mounts are
numbered from 1, as everywhere else.

To keep layer 0 free, reject --vfs-load in every single executable
application rather than only in one built with "vfsArchive": its entry
point is fixed, and resolving modules against its files is what
"useVfs" already does. --build-sea refuses it in "execArgv", and the
executable at startup when it comes from --node-options or from the
execArgv of a worker.

A worker started from a path into a VFS that is not mounted in it, such
as one mounted with vfs.mount() in its parent, now fails with
ERR_VFS_NOT_MOUNTED.

Fixes: https://github.com/nodejs/node/issues/67223
Assisted-by: a coding agent
Signed-off-by: Manjeet Singh <024manjeetsingh@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67239
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Philipp Dunkel <pip@pipobscure.com>
2026-11-11 11:07:06 +00:00

60 lines
1.4 KiB
JavaScript

'use strict';
// This tests the SEA VFS integration - the bundled assets are mounted as a
// virtual file system and the main script runs from inside the mount.
require('../common');
const {
buildSEA,
skipIfBuildSEAIsNotSupported,
} = require('../common/sea');
skipIfBuildSEAIsNotSupported();
const tmpdir = require('../common/tmpdir');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');
tmpdir.refresh();
const outputFile = buildSEA(fixtures.path('sea', 'vfs'));
spawnSyncAndAssert(
outputFile,
{
env: {
...process.env,
NODE_DEBUG_NATIVE: undefined,
},
},
{
stdout: /All SEA VFS tests passed!/,
stderr(stderr) {
if (/ExperimentalWarning: VirtualFileSystem/.test(stderr)) {
throw new Error('SEA VFS should not emit the public VirtualFileSystem warning');
}
},
},
);
// A SEA rejects --vfs-load at startup, so it cannot take the mount point of
// the assets. --build-sea already refuses it in "execArgv", so pass it through
// --node-options instead.
const rejectedFile = buildSEA(fixtures.path('sea', 'vfs'), {
configPath: 'sea-config-vfs-load-rejected.json',
});
spawnSyncAndAssert(
rejectedFile,
['--node-options=--experimental-vfs --vfs-load=.'],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: undefined,
},
},
{
status: 9,
stderr: /--vfs-load cannot be used in a single executable application/,
},
);