Fix scoped plugin config reads for live workers

This commit is contained in:
Paperclip Bot 2026-06-05 08:28:22 +00:00
parent 1b3e1e3745
commit fad3237595
2 changed files with 80 additions and 1 deletions

View file

@ -0,0 +1,76 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
getConfig: vi.fn(),
getConfigExactScope: vi.fn(),
}));
vi.mock("../services/plugin-registry.js", () => ({
pluginRegistryService: () => ({
getConfig: mocks.getConfig,
getConfigExactScope: mocks.getConfigExactScope,
}),
}));
import { buildHostServices } from "../services/plugin-host-services.js";
function createEventBusStub() {
return {
forPlugin() {
return {
emit: vi.fn(),
subscribe: vi.fn(),
clear: vi.fn(),
};
},
} as any;
}
describe("plugin host services config scoping", () => {
beforeEach(() => {
mocks.getConfig.mockReset();
mocks.getConfigExactScope.mockReset();
});
it("does not fall back to legacy global config for company-scoped reads", async () => {
mocks.getConfigExactScope.mockResolvedValue(null);
mocks.getConfig.mockResolvedValue({
configJson: { tokenRef: "global-token-ref" },
});
const services = buildHostServices(
{} as never,
"plugin-record-id",
"paperclip.example",
createEventBusStub(),
);
await expect(
services.config.get({ companyId: "company-a" }),
).resolves.toEqual({});
expect(mocks.getConfigExactScope).toHaveBeenCalledWith("plugin-record-id", "company-a");
expect(mocks.getConfig).not.toHaveBeenCalled();
services.dispose();
});
it("still reads the exact global row for explicit global requests", async () => {
mocks.getConfigExactScope.mockResolvedValue({
configJson: { tokenRef: "global-token-ref" },
});
const services = buildHostServices(
{} as never,
"plugin-record-id",
"paperclip.example",
createEventBusStub(),
);
await expect(
services.config.get({ companyId: null }),
).resolves.toEqual({ tokenRef: "global-token-ref" });
expect(mocks.getConfigExactScope).toHaveBeenCalledWith("plugin-record-id", null);
services.dispose();
});
});