fix(plugins): lazily initialize runtime and split plugin-sdk startup imports (#28620)

Merged via squash.

Prepared head SHA: 8bd7d6c13b
Co-authored-by: hmemcpy <601206+hmemcpy@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Igal Tabachnik
2026-03-04 02:58:48 +02:00
committed by GitHub
parent 4b17d6d882
commit a4850b1b8f
17 changed files with 226 additions and 19 deletions

View File

@@ -974,6 +974,37 @@ describe("loadOpenClawPlugins", () => {
);
});
it("preserves runtime reflection semantics when runtime is lazily initialized", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "runtime-introspection",
filename: "runtime-introspection.cjs",
body: `module.exports = { id: "runtime-introspection", register(api) {
const runtime = api.runtime ?? {};
const keys = Object.keys(runtime);
if (!keys.includes("channel")) {
throw new Error("runtime channel key missing");
}
if (!("channel" in runtime)) {
throw new Error("runtime channel missing from has check");
}
if (!Object.getOwnPropertyDescriptor(runtime, "channel")) {
throw new Error("runtime channel descriptor missing");
}
} };`,
});
const registry = loadRegistryFromSinglePlugin({
plugin,
pluginConfig: {
allow: ["runtime-introspection"],
},
});
const record = registry.plugins.find((entry) => entry.id === "runtime-introspection");
expect(record?.status).toBe("loaded");
});
it("prefers dist plugin-sdk alias when loader runs from dist", () => {
const { root, distFile } = createPluginSdkAliasFixture();