Scope plugin config bridge reads to invocation company

This commit is contained in:
Paperclip Bot 2026-06-05 08:13:45 +00:00
parent 1580e3b755
commit 8969a713a1
2 changed files with 52 additions and 2 deletions

View file

@ -0,0 +1,42 @@
import { describe, expect, it, vi } from "vitest";
import { createHostClientHandlers } from "../../../packages/plugins/sdk/src/host-client-factory.js";
describe("plugin config bridge scoping", () => {
it("falls back to the invocation company scope for config.get when the worker omits companyId", async () => {
const getConfig = vi.fn(async (params: { companyId?: string | null }) => ({
scope: params.companyId ?? null,
}));
const handlers = createHostClientHandlers({
pluginId: "test.plugin",
capabilities: [],
services: {
config: { get: getConfig },
} as never,
});
await expect(
handlers["config.get"]({}, { invocationScope: { companyId: "company-a" } }),
).resolves.toEqual({ scope: "company-a" });
expect(getConfig).toHaveBeenCalledWith({ companyId: "company-a" });
});
it("preserves an explicit global config.get request even inside a company-scoped invocation", async () => {
const getConfig = vi.fn(async (params: { companyId?: string | null }) => ({
scope: params.companyId ?? null,
}));
const handlers = createHostClientHandlers({
pluginId: "test.plugin",
capabilities: [],
services: {
config: { get: getConfig },
} as never,
});
await expect(
handlers["config.get"]({ companyId: null }, { invocationScope: { companyId: "company-a" } }),
).resolves.toEqual({ scope: null });
expect(getConfig).toHaveBeenCalledWith({ companyId: null });
});
});