Spaces:
Running
Running
File size: 1,596 Bytes
fb4d8fe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import type { SessionEntry } from "../config/sessions.js";
import { resolveSendPolicy } from "./send-policy.js";
describe("resolveSendPolicy", () => {
it("defaults to allow", () => {
const cfg = {} as OpenClawConfig;
expect(resolveSendPolicy({ cfg })).toBe("allow");
});
it("entry override wins", () => {
const cfg = {
session: { sendPolicy: { default: "allow" } },
} as OpenClawConfig;
const entry: SessionEntry = {
sessionId: "s",
updatedAt: 0,
sendPolicy: "deny",
};
expect(resolveSendPolicy({ cfg, entry })).toBe("deny");
});
it("rule match by channel + chatType", () => {
const cfg = {
session: {
sendPolicy: {
default: "allow",
rules: [
{
action: "deny",
match: { channel: "discord", chatType: "group" },
},
],
},
},
} as OpenClawConfig;
const entry: SessionEntry = {
sessionId: "s",
updatedAt: 0,
channel: "discord",
chatType: "group",
};
expect(resolveSendPolicy({ cfg, entry, sessionKey: "discord:group:dev" })).toBe("deny");
});
it("rule match by keyPrefix", () => {
const cfg = {
session: {
sendPolicy: {
default: "allow",
rules: [{ action: "deny", match: { keyPrefix: "cron:" } }],
},
},
} as OpenClawConfig;
expect(resolveSendPolicy({ cfg, sessionKey: "cron:job-1" })).toBe("deny");
});
});
|