import { describe, expect, it } from "vitest"; import type { AgentRouteBinding } from "../config/types.agents.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { resolveFirstBoundAccountId } from "./bound-account-read.js";
function cfgWithBindings(bindings: AgentRouteBinding[]): OpenClawConfig { return { bindings } as unknown as OpenClawConfig;
}
it("treats group and channel peer kinds as equivalent (matches resolve-route semantics)", () => { const cfg = cfgWithBindings([
{
type: "route",
agentId: "bot-alpha",
match: {
channel: "line",
peer: { kind: "group", id: "*" },
accountId: "bot-alpha-group",
},
},
]); // Caller inferred as `channel` (e.g. Matrix room, Mattermost channel) // should still match a `group` wildcard binding because group/channel are // compatible kinds in the routing model.
expect(
resolveFirstBoundAccountId({
cfg,
channelId: "line",
agentId: "bot-alpha",
peerId: "!roomA:example.org",
peerKind: "channel",
}),
).toBe("bot-alpha-group"); // And vice versa: `channel` binding matches a `group` caller. const cfg2 = cfgWithBindings([
{
type: "route",
agentId: "bot-alpha",
match: {
channel: "line",
peer: { kind: "channel", id: "*" },
accountId: "bot-alpha-channel",
},
},
]);
expect(
resolveFirstBoundAccountId({
cfg: cfg2,
channelId: "line",
agentId: "bot-alpha",
peerId: "groupA",
peerKind: "group",
}),
).toBe("bot-alpha-channel");
});
it("accepts a wildcard peer binding as fallback for peerless callers", () => { // Cron-style peerless caller: we have no peer context to verify kind // safety against, so a wildcard binding is the only available answer and // must not silently regress to undefined. const cfg = cfgWithBindings([
{
type: "route",
agentId: "bot-alpha",
match: {
channel: "matrix",
peer: { kind: "channel", id: "*" },
accountId: "bot-alpha-wildcard",
},
},
]);
expect(
resolveFirstBoundAccountId({
cfg,
channelId: "matrix",
agentId: "bot-alpha",
}),
).toBe("bot-alpha-wildcard");
});
it("skips wildcard peer bindings when the caller's peerKind is unknown", () => { const cfg = cfgWithBindings([
{
type: "route",
agentId: "bot-alpha",
match: {
channel: "matrix",
peer: { kind: "direct", id: "*" },
accountId: "bot-alpha-dm",
},
},
{
type: "route",
agentId: "bot-alpha",
match: { channel: "matrix", accountId: "bot-alpha-default" },
},
]); // Without a peerKind on the caller, we cannot verify kind compatibility // for the wildcard binding — it must be skipped in favor of the channel-only // fallback rather than risk routing to the wrong identity.
expect(
resolveFirstBoundAccountId({
cfg,
channelId: "matrix",
agentId: "bot-alpha",
peerId: "!room:example.org",
}),
).toBe("bot-alpha-default");
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.