test: dedupe plugin provider helper suites

This commit is contained in:
Peter Steinberger
2026-03-28 04:26:00 +00:00
parent 7e921050e3
commit 9155f3914a
10 changed files with 259 additions and 105 deletions

View File

@@ -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");
});
});

View File

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