mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:28:28 +00:00
perf(test): fold sender identity checks into channel config suite
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import type { MsgContext } from "../auto-reply/templating.js";
|
||||||
import {
|
import {
|
||||||
buildChannelKeyCandidates,
|
buildChannelKeyCandidates,
|
||||||
normalizeChannelSlug,
|
normalizeChannelSlug,
|
||||||
@@ -8,6 +9,7 @@ import {
|
|||||||
applyChannelMatchMeta,
|
applyChannelMatchMeta,
|
||||||
resolveChannelMatchConfig,
|
resolveChannelMatchConfig,
|
||||||
} from "./channel-config.js";
|
} from "./channel-config.js";
|
||||||
|
import { validateSenderIdentity } from "./sender-identity.js";
|
||||||
|
|
||||||
describe("buildChannelKeyCandidates", () => {
|
describe("buildChannelKeyCandidates", () => {
|
||||||
it("dedupes and trims keys", () => {
|
it("dedupes and trims keys", () => {
|
||||||
@@ -118,6 +120,33 @@ describe("resolveChannelMatchConfig", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("validateSenderIdentity", () => {
|
||||||
|
it("allows direct messages without sender fields", () => {
|
||||||
|
const ctx: MsgContext = { ChatType: "direct" };
|
||||||
|
expect(validateSenderIdentity(ctx)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("requires some sender identity for non-direct chats", () => {
|
||||||
|
const ctx: MsgContext = { ChatType: "group" };
|
||||||
|
expect(validateSenderIdentity(ctx)).toContain(
|
||||||
|
"missing sender identity (SenderId/SenderName/SenderUsername/SenderE164)",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("validates SenderE164 and SenderUsername shape", () => {
|
||||||
|
const ctx: MsgContext = {
|
||||||
|
ChatType: "group",
|
||||||
|
SenderE164: "123",
|
||||||
|
SenderUsername: "@ada lovelace",
|
||||||
|
};
|
||||||
|
expect(validateSenderIdentity(ctx)).toEqual([
|
||||||
|
"invalid SenderE164: 123",
|
||||||
|
'SenderUsername should not include "@": @ada lovelace',
|
||||||
|
"SenderUsername should not include whitespace: @ada lovelace",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("resolveNestedAllowlistDecision", () => {
|
describe("resolveNestedAllowlistDecision", () => {
|
||||||
it("allows when outer allowlist is disabled", () => {
|
it("allows when outer allowlist is disabled", () => {
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import type { MsgContext } from "../auto-reply/templating.js";
|
|
||||||
import { validateSenderIdentity } from "./sender-identity.js";
|
|
||||||
|
|
||||||
describe("validateSenderIdentity", () => {
|
|
||||||
it("allows direct messages without sender fields", () => {
|
|
||||||
const ctx: MsgContext = { ChatType: "direct" };
|
|
||||||
expect(validateSenderIdentity(ctx)).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("requires some sender identity for non-direct chats", () => {
|
|
||||||
const ctx: MsgContext = { ChatType: "group" };
|
|
||||||
expect(validateSenderIdentity(ctx)).toContain(
|
|
||||||
"missing sender identity (SenderId/SenderName/SenderUsername/SenderE164)",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("validates SenderE164 and SenderUsername shape", () => {
|
|
||||||
const ctx: MsgContext = {
|
|
||||||
ChatType: "group",
|
|
||||||
SenderE164: "123",
|
|
||||||
SenderUsername: "@ada lovelace",
|
|
||||||
};
|
|
||||||
expect(validateSenderIdentity(ctx)).toEqual([
|
|
||||||
"invalid SenderE164: 123",
|
|
||||||
'SenderUsername should not include "@": @ada lovelace',
|
|
||||||
"SenderUsername should not include whitespace: @ada lovelace",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user