mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:08:27 +00:00
fix: require explicit system event session keys
This commit is contained in:
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { prependSystemEvents } from "../auto-reply/reply/session-updates.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { resolveMainSessionKey } from "../config/sessions.js";
|
||||
import {
|
||||
enqueueSystemEvent,
|
||||
peekSystemEvents,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
} from "./system-events.js";
|
||||
|
||||
const cfg = {} as unknown as ClawdbotConfig;
|
||||
const mainKey = resolveMainSessionKey(cfg);
|
||||
|
||||
describe("system events (session routing)", () => {
|
||||
beforeEach(() => {
|
||||
@@ -21,14 +23,14 @@ describe("system events (session routing)", () => {
|
||||
contextKey: "discord:reaction:added:msg:user:✅",
|
||||
});
|
||||
|
||||
expect(peekSystemEvents()).toEqual([]);
|
||||
expect(peekSystemEvents(mainKey)).toEqual([]);
|
||||
expect(peekSystemEvents("discord:group:123")).toEqual([
|
||||
"Discord reaction added: ✅",
|
||||
]);
|
||||
|
||||
const main = await prependSystemEvents({
|
||||
cfg,
|
||||
sessionKey: "main",
|
||||
sessionKey: mainKey,
|
||||
isMainSession: true,
|
||||
isNewSession: false,
|
||||
prefixedBodyBase: "hello",
|
||||
@@ -49,16 +51,9 @@ describe("system events (session routing)", () => {
|
||||
expect(peekSystemEvents("discord:group:123")).toEqual([]);
|
||||
});
|
||||
|
||||
it("defaults system events to main", async () => {
|
||||
enqueueSystemEvent("Node: Mac Studio");
|
||||
|
||||
const main = await prependSystemEvents({
|
||||
cfg,
|
||||
sessionKey: "main",
|
||||
isMainSession: true,
|
||||
isNewSession: false,
|
||||
prefixedBodyBase: "ping",
|
||||
});
|
||||
expect(main).toBe("System: Node: Mac Studio\n\nping");
|
||||
it("requires an explicit session key", () => {
|
||||
expect(() =>
|
||||
enqueueSystemEvent("Node: Mac Studio", { sessionKey: " " }),
|
||||
).toThrow("sessionKey");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user