From d87e73f2db50be72d33a4b3c7199af35518b441c Mon Sep 17 00:00:00 2001 From: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:27:20 +0800 Subject: [PATCH] test(javascript): execute the registered Webpack export fixture (#6951) --- .../applicationWorkflowCli.test.ts | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/acceptance/applications/applicationWorkflowCli.test.ts b/tests/acceptance/applications/applicationWorkflowCli.test.ts index b01f553923..2a25b876c2 100644 --- a/tests/acceptance/applications/applicationWorkflowCli.test.ts +++ b/tests/acceptance/applications/applicationWorkflowCli.test.ts @@ -5,6 +5,7 @@ import { createRequire } from "node:module"; import { join, relative, resolve } from "node:path"; import { pathToFileURL } from "node:url"; import { promisify } from "node:util"; +import { runInNewContext } from "node:vm"; import { Client } from "@modelcontextprotocol/client"; import { StdioClientTransport } from "@modelcontextprotocol/client/stdio"; @@ -74,15 +75,6 @@ afterAll(async () => { }); const WEBPACK_FACTORY_BODY = ` const key = "dynamic"; - const __webpack_require__ = { - d(target, definitions) { - for (const name of Object.keys(definitions)) - Object.defineProperty(target, name, { - enumerable: true, - get: definitions[name], - }); - }, - }; exports[key] = 1; exports["dot.key"] = 2; exports[""] = 3; @@ -1106,14 +1098,28 @@ describe("Webpack factory CommonJS export keys", () => { }]);`; await writeFile(join(root, "bundle.js"), bundle); - // Execute the same factory body as CommonJS, outside the analyzer, to - // verify Node's alias behavior and the exact runtime object keys. + // Execute the exact bundle and invoke its registered factory with a loader. + // This also rejects invalid factory syntax before trusting the export oracle. + const actual = runInNewContext(` + globalThis.webpackChunkStaticExports = []; + ${bundle} + const module = { exports: {} }; + const loader = { + d(target, definitions) { + for (const name of Object.keys(definitions)) + Object.defineProperty(target, name, { + enumerable: true, + get: definitions[name], + }); + }, + }; + const [, factories] = globalThis.webpackChunkStaticExports[0]; + factories[1](module, module.exports, loader); + module.exports; + `) as Record; const oracleRoot = await createTestTempDirectory( "rea-webpack-export-oracle-", ); - const oraclePath = join(oracleRoot, "oracle.cjs"); - await writeFile(oraclePath, WEBPACK_FACTORY_BODY); - const actual = requireFixture(oraclePath) as Record; expect(Reflect.ownKeys(actual).sort()).toEqual([ "", "dot.key",