mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 05:54:43 +00:00
fix(gateway): canonicalize notification wake session
This commit is contained in:
@@ -355,6 +355,8 @@ describe("notifications changed events", () => {
|
||||
beforeEach(() => {
|
||||
enqueueSystemEventMock.mockClear();
|
||||
requestHeartbeatNowMock.mockClear();
|
||||
loadSessionEntryMock.mockClear();
|
||||
loadSessionEntryMock.mockImplementation((sessionKey: string) => buildSessionLookup(sessionKey));
|
||||
});
|
||||
|
||||
it("enqueues notifications.changed posted events", async () => {
|
||||
@@ -418,6 +420,31 @@ describe("notifications changed events", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("canonicalizes notifications session key before enqueue and wake", async () => {
|
||||
loadSessionEntryMock.mockReturnValueOnce({
|
||||
...buildSessionLookup("node-node-n5"),
|
||||
canonicalKey: "agent:main:node-node-n5",
|
||||
});
|
||||
const ctx = buildCtx();
|
||||
await handleNodeEvent(ctx, "node-n5", {
|
||||
event: "notifications.changed",
|
||||
payloadJSON: JSON.stringify({
|
||||
change: "posted",
|
||||
key: "notif-5",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(loadSessionEntryMock).toHaveBeenCalledWith("node-node-n5");
|
||||
expect(enqueueSystemEventMock).toHaveBeenCalledWith(
|
||||
"Notification posted (node=node-n5 key=notif-5)",
|
||||
{ sessionKey: "agent:main:node-node-n5", contextKey: "notification:notif-5" },
|
||||
);
|
||||
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({
|
||||
reason: "notifications-event",
|
||||
sessionKey: "agent:main:node-node-n5",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores notifications.changed payloads missing required fields", async () => {
|
||||
const ctx = buildCtx();
|
||||
await handleNodeEvent(ctx, "node-n3", {
|
||||
|
||||
@@ -467,7 +467,8 @@ export const handleNodeEvent = async (ctx: NodeEventContext, nodeId: string, evt
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
const sessionKey = normalizeNonEmptyString(obj.sessionKey) ?? `node-${nodeId}`;
|
||||
const sessionKeyRaw = normalizeNonEmptyString(obj.sessionKey) ?? `node-${nodeId}`;
|
||||
const { canonicalKey: sessionKey } = loadSessionEntry(sessionKeyRaw);
|
||||
const packageName = normalizeNonEmptyString(obj.packageName);
|
||||
const title = compactNotificationEventText(normalizeNonEmptyString(obj.title) ?? "");
|
||||
const text = compactNotificationEventText(normalizeNonEmptyString(obj.text) ?? "");
|
||||
|
||||
Reference in New Issue
Block a user