mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 10:41:23 +00:00
refactor: move browser runtime seams behind plugin metadata
This commit is contained in:
79
src/node-host/plugin-node-host.test.ts
Normal file
79
src/node-host/plugin-node-host.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
|
||||
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import {
|
||||
invokeRegisteredNodeHostCommand,
|
||||
listRegisteredNodeHostCapsAndCommands,
|
||||
} from "./plugin-node-host.js";
|
||||
|
||||
afterEach(() => {
|
||||
resetPluginRuntimeStateForTest();
|
||||
});
|
||||
|
||||
describe("plugin node-host registry", () => {
|
||||
it("lists plugin-declared caps and commands", () => {
|
||||
const registry = createEmptyPluginRegistry();
|
||||
registry.nodeHostCommands = [
|
||||
{
|
||||
pluginId: "browser",
|
||||
pluginName: "Browser",
|
||||
command: {
|
||||
command: "browser.proxy",
|
||||
cap: "browser",
|
||||
handle: vi.fn(async () => "{}"),
|
||||
},
|
||||
source: "test",
|
||||
},
|
||||
{
|
||||
pluginId: "photos",
|
||||
pluginName: "Photos",
|
||||
command: {
|
||||
command: "photos.proxy",
|
||||
cap: "photos",
|
||||
handle: vi.fn(async () => "{}"),
|
||||
},
|
||||
source: "test",
|
||||
},
|
||||
{
|
||||
pluginId: "browser-dup",
|
||||
pluginName: "Browser Dup",
|
||||
command: {
|
||||
command: "browser.inspect",
|
||||
cap: "browser",
|
||||
handle: vi.fn(async () => "{}"),
|
||||
},
|
||||
source: "test",
|
||||
},
|
||||
];
|
||||
setActivePluginRegistry(registry);
|
||||
|
||||
expect(listRegisteredNodeHostCapsAndCommands()).toEqual({
|
||||
caps: ["browser", "photos"],
|
||||
commands: ["browser.inspect", "browser.proxy", "photos.proxy"],
|
||||
});
|
||||
});
|
||||
|
||||
it("dispatches plugin-declared node-host commands", async () => {
|
||||
const handle = vi.fn(async (paramsJSON?: string | null) => paramsJSON ?? "");
|
||||
const registry = createEmptyPluginRegistry();
|
||||
registry.nodeHostCommands = [
|
||||
{
|
||||
pluginId: "browser",
|
||||
pluginName: "Browser",
|
||||
command: {
|
||||
command: "browser.proxy",
|
||||
cap: "browser",
|
||||
handle,
|
||||
},
|
||||
source: "test",
|
||||
},
|
||||
];
|
||||
setActivePluginRegistry(registry);
|
||||
|
||||
await expect(invokeRegisteredNodeHostCommand("browser.proxy", '{"ok":true}')).resolves.toBe(
|
||||
'{"ok":true}',
|
||||
);
|
||||
await expect(invokeRegisteredNodeHostCommand("missing.command", null)).resolves.toBeNull();
|
||||
expect(handle).toHaveBeenCalledWith('{"ok":true}');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user