fix(plugins): forward-port bundled SDK fallback hardening (#107131)

* fix(plugins): avoid bundled SDK fallback races

* fix(ci): satisfy plugin SDK LOC ratchet

* fix(ci): align fallback forward-port guards

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
Peter Steinberger
2026-07-13 21:50:46 -07:00
committed by GitHub
parent 2e58c2bc53
commit 61986571bb
5 changed files with 90 additions and 15 deletions

View File

@@ -598,6 +598,36 @@ describe("getCachedPluginModuleLoader", () => {
]);
});
it("can transform OpenClaw dependencies on a forced source fallback", async () => {
const fromSourceTransformer = vi.fn(() => ({ fromSourceTransform: true }));
const createJiti = vi.fn(() => fromSourceTransformer);
const nativeStub = vi.fn(() => ({ ok: true, moduleExport: { fromNative: true } }));
vi.doMock("./native-module-require.js", () => ({
isJavaScriptModulePath: () => true,
tryNativeRequireJavaScriptModule: nativeStub,
}));
const { getCachedPluginSourceModuleLoader } = await importFreshModule<
typeof import("./plugin-module-loader-cache.js")
>(import.meta.url, "./plugin-module-loader-cache.js?scope=forced-source-native-fallback");
const loader = getCachedPluginSourceModuleLoader({
cache: new Map(),
modulePath: "/repo/dist/extensions/demo/api.js",
importerUrl: "file:///repo/src/plugin-sdk/channel-entry-contract.ts",
loaderFilename: "file:///repo/src/plugin-sdk/channel-entry-contract.ts",
transformOpenClawDependencies: true,
createLoader: asPluginModuleLoaderFactory(createJiti),
});
expect(loader("/repo/dist/extensions/demo/api.js")).toEqual({
fromSourceTransform: true,
});
const options = requireRecord(callArg(createJiti, 0, 1, "jiti options"), "jiti options");
expect(options.tryNative).toBe(false);
expect(options.nativeModules).toEqual([]);
expect(nativeStub).not.toHaveBeenCalled();
});
it("normalizes Windows absolute paths before creating and calling the source transformer", async () => {
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
const fromSourceTransformer = vi.fn(() => ({ fromSourceTransform: true }));