mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-17 20:50:42 +00:00
fix(plugins): enforce synchronous registration
This commit is contained in:
@@ -81,13 +81,6 @@ function createCliRegistry(params?: {
|
||||
};
|
||||
}
|
||||
|
||||
function createEmptyCliRegistry(params?: { diagnostics?: Array<{ message: string }> }) {
|
||||
return {
|
||||
cliRegistrars: [],
|
||||
diagnostics: params?.diagnostics ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
function createAutoEnabledCliFixture() {
|
||||
const rawConfig = {
|
||||
plugins: {},
|
||||
@@ -310,51 +303,6 @@ describe("registerPluginCliCommands", () => {
|
||||
expect(mocks.loadOpenClawPluginCliRegistry).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("falls back to awaited CLI metadata collection when runtime loading ignored async registration", async () => {
|
||||
const asyncRegistrar = vi.fn(async ({ program }: { program: Command }) => {
|
||||
const asyncCommand = program.command("async-cli").description("Async CLI");
|
||||
asyncCommand.command("run").action(mocks.memoryListAction);
|
||||
});
|
||||
mocks.loadOpenClawPlugins.mockReturnValue(
|
||||
createEmptyCliRegistry({
|
||||
diagnostics: [
|
||||
{
|
||||
message: "plugin register returned a promise; async registration is ignored",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
mocks.loadOpenClawPluginCliRegistry.mockResolvedValue({
|
||||
cliRegistrars: [
|
||||
{
|
||||
pluginId: "async-plugin",
|
||||
register: asyncRegistrar,
|
||||
commands: ["async-cli"],
|
||||
descriptors: [
|
||||
{
|
||||
name: "async-cli",
|
||||
description: "Async CLI",
|
||||
hasSubcommands: true,
|
||||
},
|
||||
],
|
||||
source: "bundled",
|
||||
},
|
||||
],
|
||||
diagnostics: [],
|
||||
});
|
||||
const program = createProgram();
|
||||
program.exitOverride();
|
||||
|
||||
await registerPluginCliCommands(program, {} as OpenClawConfig, undefined, undefined, {
|
||||
mode: "lazy",
|
||||
});
|
||||
|
||||
expect(mocks.loadOpenClawPluginCliRegistry).toHaveBeenCalledTimes(1);
|
||||
await program.parseAsync(["async-cli", "run"], { from: "user" });
|
||||
expect(asyncRegistrar).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.memoryListAction).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("lazy-registers descriptor-backed plugin commands on first invocation", async () => {
|
||||
const program = createProgram();
|
||||
program.exitOverride();
|
||||
|
||||
Reference in New Issue
Block a user