mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-31 03:41:51 +00:00
test: dedupe plugin provider helper suites
This commit is contained in:
@@ -31,6 +31,17 @@ describe("gateway request scope", () => {
|
||||
expect(runtimeScope.getPluginRuntimeGatewayRequestScope()).toEqual(expected);
|
||||
}
|
||||
|
||||
async function expectGatewayScopeWithPluginId(pluginId: string) {
|
||||
await withTestGatewayScope(async (runtimeScope) => {
|
||||
await runtimeScope.withPluginRuntimePluginIdScope(pluginId, async () => {
|
||||
expectGatewayScope(runtimeScope, {
|
||||
...TEST_SCOPE,
|
||||
pluginId,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it("reuses AsyncLocalStorage across reloaded module instances", async () => {
|
||||
const first = await importGatewayRequestScopeModule();
|
||||
|
||||
@@ -42,13 +53,6 @@ describe("gateway request scope", () => {
|
||||
});
|
||||
|
||||
it("attaches plugin id to the active scope", async () => {
|
||||
await withTestGatewayScope(async (runtimeScope) => {
|
||||
await runtimeScope.withPluginRuntimePluginIdScope("voice-call", async () => {
|
||||
expectGatewayScope(runtimeScope, {
|
||||
...TEST_SCOPE,
|
||||
pluginId: "voice-call",
|
||||
});
|
||||
});
|
||||
});
|
||||
await expectGatewayScopeWithPluginId("voice-call");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,6 +56,20 @@ function expectFunctionKeys(value: Record<string, unknown>, keys: readonly strin
|
||||
});
|
||||
}
|
||||
|
||||
function expectRunCommandOutcome(params: {
|
||||
runtime: ReturnType<typeof createPluginRuntime>;
|
||||
expected: "resolve" | "reject";
|
||||
commandResult: ReturnType<typeof createCommandResult>;
|
||||
}) {
|
||||
const command = params.runtime.system.runCommandWithTimeout(["echo", "hello"], {
|
||||
timeoutMs: 1000,
|
||||
});
|
||||
if (params.expected === "resolve") {
|
||||
return expect(command).resolves.toEqual(params.commandResult);
|
||||
}
|
||||
return expect(command).rejects.toThrow("boom");
|
||||
}
|
||||
|
||||
describe("plugin runtime command execution", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
@@ -83,12 +97,7 @@ describe("plugin runtime command execution", () => {
|
||||
}
|
||||
|
||||
const runtime = createPluginRuntime();
|
||||
const command = runtime.system.runCommandWithTimeout(["echo", "hello"], { timeoutMs: 1000 });
|
||||
if (expected === "resolve") {
|
||||
await expect(command).resolves.toEqual(commandResult);
|
||||
} else {
|
||||
await expect(command).rejects.toThrow("boom");
|
||||
}
|
||||
await expectRunCommandOutcome({ runtime, expected, commandResult });
|
||||
expect(runCommandWithTimeoutMock).toHaveBeenCalledWith(["echo", "hello"], { timeoutMs: 1000 });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user