mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 21:21:10 +00:00
Plugins: fail fast on channel and binding collisions (#45628)
* Plugins: reject duplicate channel ids * Bindings: reject duplicate adapter registration * Plugins: fail on export id mismatch
This commit is contained in:
@@ -198,4 +198,24 @@ describe("session binding service", () => {
|
||||
placements: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects duplicate adapter registration for the same channel account", () => {
|
||||
registerSessionBindingAdapter({
|
||||
channel: "discord",
|
||||
accountId: "default",
|
||||
bind: async (input) => createRecord(input),
|
||||
listBySession: () => [],
|
||||
resolveByConversation: () => null,
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
registerSessionBindingAdapter({
|
||||
channel: "Discord",
|
||||
accountId: "DEFAULT",
|
||||
bind: async (input) => createRecord(input),
|
||||
listBySession: () => [],
|
||||
resolveByConversation: () => null,
|
||||
}),
|
||||
).toThrow("Session binding adapter already registered for discord:default");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -148,15 +148,22 @@ function resolveAdapterCapabilities(
|
||||
const ADAPTERS_BY_CHANNEL_ACCOUNT = new Map<string, SessionBindingAdapter>();
|
||||
|
||||
export function registerSessionBindingAdapter(adapter: SessionBindingAdapter): void {
|
||||
const key = toAdapterKey({
|
||||
channel: adapter.channel,
|
||||
accountId: adapter.accountId,
|
||||
});
|
||||
ADAPTERS_BY_CHANNEL_ACCOUNT.set(key, {
|
||||
const normalizedAdapter = {
|
||||
...adapter,
|
||||
channel: adapter.channel.trim().toLowerCase(),
|
||||
accountId: normalizeAccountId(adapter.accountId),
|
||||
};
|
||||
const key = toAdapterKey({
|
||||
channel: normalizedAdapter.channel,
|
||||
accountId: normalizedAdapter.accountId,
|
||||
});
|
||||
const existing = ADAPTERS_BY_CHANNEL_ACCOUNT.get(key);
|
||||
if (existing && existing !== adapter) {
|
||||
throw new Error(
|
||||
`Session binding adapter already registered for ${normalizedAdapter.channel}:${normalizedAdapter.accountId}`,
|
||||
);
|
||||
}
|
||||
ADAPTERS_BY_CHANNEL_ACCOUNT.set(key, normalizedAdapter);
|
||||
}
|
||||
|
||||
export function unregisterSessionBindingAdapter(params: {
|
||||
|
||||
Reference in New Issue
Block a user