File size: 1,940 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import { describe, it, expect } from "vitest";
import { buildAgentSessionKey } from "./resolve-route.js";
describe("Discord Session Key Continuity", () => {
const agentId = "main";
const channel = "discord";
const accountId = "default";
it("generates distinct keys for DM vs Channel (dmScope=main)", () => {
// Scenario: Default config (dmScope=main)
const dmKey = buildAgentSessionKey({
agentId,
channel,
accountId,
peer: { kind: "direct", id: "user123" },
dmScope: "main",
});
const groupKey = buildAgentSessionKey({
agentId,
channel,
accountId,
peer: { kind: "channel", id: "channel456" },
dmScope: "main",
});
expect(dmKey).toBe("agent:main:main");
expect(groupKey).toBe("agent:main:discord:channel:channel456");
expect(dmKey).not.toBe(groupKey);
});
it("generates distinct keys for DM vs Channel (dmScope=per-peer)", () => {
// Scenario: Multi-user bot config
const dmKey = buildAgentSessionKey({
agentId,
channel,
accountId,
peer: { kind: "direct", id: "user123" },
dmScope: "per-peer",
});
const groupKey = buildAgentSessionKey({
agentId,
channel,
accountId,
peer: { kind: "channel", id: "channel456" },
dmScope: "per-peer",
});
expect(dmKey).toBe("agent:main:direct:user123");
expect(groupKey).toBe("agent:main:discord:channel:channel456");
expect(dmKey).not.toBe(groupKey);
});
it("handles empty/invalid IDs safely without collision", () => {
// If ID is missing, does it collide?
const missingIdKey = buildAgentSessionKey({
agentId,
channel,
accountId,
peer: { kind: "channel", id: "" }, // Empty string
dmScope: "main",
});
expect(missingIdKey).toContain("unknown");
// Should still be distinct from main
expect(missingIdKey).not.toBe("agent:main:main");
});
});
|