fix(plugins): enforce synchronous registration

This commit is contained in:
Ayaan Zaidi
2026-04-17 08:34:48 +05:30
parent 15b2827fc1
commit 2a283e87a7
17 changed files with 411 additions and 269 deletions

View File

@@ -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();