mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 09:07:39 +00:00
refactor: harden plugin install flow and main DM route pinning
This commit is contained in:
@@ -103,4 +103,32 @@ describe("recordInboundSession", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("skips last-route updates when main DM owner pin mismatches sender", async () => {
|
||||
const { recordInboundSession } = await import("./session.js");
|
||||
const onSkip = vi.fn();
|
||||
|
||||
await recordInboundSession({
|
||||
storePath: "/tmp/openclaw-session-store.json",
|
||||
sessionKey: "agent:main:telegram:1234:thread:42",
|
||||
ctx,
|
||||
updateLastRoute: {
|
||||
sessionKey: "agent:main:main",
|
||||
channel: "telegram",
|
||||
to: "telegram:1234",
|
||||
mainDmOwnerPin: {
|
||||
ownerRecipient: "1234",
|
||||
senderRecipient: "9999",
|
||||
onSkip,
|
||||
},
|
||||
},
|
||||
onRecordError: vi.fn(),
|
||||
});
|
||||
|
||||
expect(updateLastRouteMock).not.toHaveBeenCalled();
|
||||
expect(onSkip).toHaveBeenCalledWith({
|
||||
ownerRecipient: "1234",
|
||||
senderRecipient: "9999",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,8 +16,28 @@ export type InboundLastRouteUpdate = {
|
||||
to: string;
|
||||
accountId?: string;
|
||||
threadId?: string | number;
|
||||
mainDmOwnerPin?: {
|
||||
ownerRecipient: string;
|
||||
senderRecipient: string;
|
||||
onSkip?: (params: { ownerRecipient: string; senderRecipient: string }) => void;
|
||||
};
|
||||
};
|
||||
|
||||
function shouldSkipPinnedMainDmRouteUpdate(
|
||||
pin: InboundLastRouteUpdate["mainDmOwnerPin"] | undefined,
|
||||
): boolean {
|
||||
if (!pin) {
|
||||
return false;
|
||||
}
|
||||
const owner = pin.ownerRecipient.trim().toLowerCase();
|
||||
const sender = pin.senderRecipient.trim().toLowerCase();
|
||||
if (!owner || !sender || owner === sender) {
|
||||
return false;
|
||||
}
|
||||
pin.onSkip?.({ ownerRecipient: pin.ownerRecipient, senderRecipient: pin.senderRecipient });
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function recordInboundSession(params: {
|
||||
storePath: string;
|
||||
sessionKey: string;
|
||||
@@ -41,6 +61,9 @@ export async function recordInboundSession(params: {
|
||||
if (!update) {
|
||||
return;
|
||||
}
|
||||
if (shouldSkipPinnedMainDmRouteUpdate(update.mainDmOwnerPin)) {
|
||||
return;
|
||||
}
|
||||
const targetSessionKey = normalizeSessionStoreKey(update.sessionKey);
|
||||
await updateLastRoute({
|
||||
storePath,
|
||||
|
||||
Reference in New Issue
Block a user