mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-25 10:03:33 +00:00
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:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user