mirror of https://github.com/openclaw/openclaw.git
test: share zalouser group policy resolver
This commit is contained in:
parent
6d0e4c76ac
commit
1cea43d349
|
|
@ -15,6 +15,33 @@ vi.mock("./send.js", async (importOriginal) => {
|
||||||
const mockSendMessage = vi.mocked(sendMessageZalouser);
|
const mockSendMessage = vi.mocked(sendMessageZalouser);
|
||||||
const mockSendReaction = vi.mocked(sendReactionZalouser);
|
const mockSendReaction = vi.mocked(sendReactionZalouser);
|
||||||
|
|
||||||
|
function getResolveToolPolicy() {
|
||||||
|
const resolveToolPolicy = zalouserPlugin.groups?.resolveToolPolicy;
|
||||||
|
expect(resolveToolPolicy).toBeTypeOf("function");
|
||||||
|
if (!resolveToolPolicy) {
|
||||||
|
throw new Error("resolveToolPolicy unavailable");
|
||||||
|
}
|
||||||
|
return resolveToolPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveGroupToolPolicy(
|
||||||
|
groups: Record<string, { tools: { allow?: string[]; deny?: string[] } }>,
|
||||||
|
groupId: string,
|
||||||
|
) {
|
||||||
|
return getResolveToolPolicy()({
|
||||||
|
cfg: {
|
||||||
|
channels: {
|
||||||
|
zalouser: {
|
||||||
|
groups,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
accountId: "default",
|
||||||
|
groupId,
|
||||||
|
groupChannel: groupId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe("zalouser outbound", () => {
|
describe("zalouser outbound", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockSendMessage.mockClear();
|
mockSendMessage.mockClear();
|
||||||
|
|
@ -93,48 +120,12 @@ describe("zalouser channel policies", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resolves group tool policy by explicit group id", () => {
|
it("resolves group tool policy by explicit group id", () => {
|
||||||
const resolveToolPolicy = zalouserPlugin.groups?.resolveToolPolicy;
|
const policy = resolveGroupToolPolicy({ "123": { tools: { allow: ["search"] } } }, "123");
|
||||||
expect(resolveToolPolicy).toBeTypeOf("function");
|
|
||||||
if (!resolveToolPolicy) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const policy = resolveToolPolicy({
|
|
||||||
cfg: {
|
|
||||||
channels: {
|
|
||||||
zalouser: {
|
|
||||||
groups: {
|
|
||||||
"123": { tools: { allow: ["search"] } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
accountId: "default",
|
|
||||||
groupId: "123",
|
|
||||||
groupChannel: "123",
|
|
||||||
});
|
|
||||||
expect(policy).toEqual({ allow: ["search"] });
|
expect(policy).toEqual({ allow: ["search"] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to wildcard group policy", () => {
|
it("falls back to wildcard group policy", () => {
|
||||||
const resolveToolPolicy = zalouserPlugin.groups?.resolveToolPolicy;
|
const policy = resolveGroupToolPolicy({ "*": { tools: { deny: ["system.run"] } } }, "missing");
|
||||||
expect(resolveToolPolicy).toBeTypeOf("function");
|
|
||||||
if (!resolveToolPolicy) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const policy = resolveToolPolicy({
|
|
||||||
cfg: {
|
|
||||||
channels: {
|
|
||||||
zalouser: {
|
|
||||||
groups: {
|
|
||||||
"*": { tools: { deny: ["system.run"] } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
accountId: "default",
|
|
||||||
groupId: "missing",
|
|
||||||
groupChannel: "missing",
|
|
||||||
});
|
|
||||||
expect(policy).toEqual({ deny: ["system.run"] });
|
expect(policy).toEqual({ deny: ["system.run"] });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue