Download src/config/sessions/explicit-session-key-normalization.test.ts from Darochin/openskynet: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/Darochin/openskynet/resolve/main/src/config/sessions/explicit-session-key-normalization.test.ts
- Command line
-
hf download hf://Darochin/openskynet/src/config/sessions/explicit-session-key-normalization.test.ts
-
curl -L -o explicit-session-key-normalization.test.ts https://huggingface.co/Darochin/openskynet/resolve/main/src/config/sessions/explicit-session-key-normalization.test.ts
1.75 kB
| import { describe, expect, it } from "vitest"; | |
| import type { MsgContext } from "../../auto-reply/templating.js"; | |
| import { normalizeExplicitSessionKey } from "./explicit-session-key-normalization.js"; | |
| function makeCtx(overrides: Partial<MsgContext>): MsgContext { | |
| return { | |
| Body: "", | |
| From: "", | |
| To: "", | |
| ...overrides, | |
| } as MsgContext; | |
| } | |
| describe("normalizeExplicitSessionKey", () => { | |
| it("dispatches discord keys through the provider normalizer", () => { | |
| expect( | |
| normalizeExplicitSessionKey( | |
| "agent:fina:discord:channel:123456", | |
| makeCtx({ | |
| Surface: "discord", | |
| ChatType: "direct", | |
| From: "discord:123456", | |
| SenderId: "123456", | |
| }), | |
| ), | |
| ).toBe("agent:fina:discord:direct:123456"); | |
| }); | |
| it("infers the provider from From when explicit provider fields are absent", () => { | |
| expect( | |
| normalizeExplicitSessionKey( | |
| "discord:dm:123456", | |
| makeCtx({ | |
| ChatType: "direct", | |
| From: "discord:123456", | |
| SenderId: "123456", | |
| }), | |
| ), | |
| ).toBe("discord:direct:123456"); | |
| }); | |
| it("uses Provider when Surface is absent", () => { | |
| expect( | |
| normalizeExplicitSessionKey( | |
| "agent:fina:discord:dm:123456", | |
| makeCtx({ | |
| Provider: "Discord", | |
| ChatType: "direct", | |
| SenderId: "123456", | |
| }), | |
| ), | |
| ).toBe("agent:fina:discord:direct:123456"); | |
| }); | |
| it("lowercases and passes through unknown providers unchanged", () => { | |
| expect( | |
| normalizeExplicitSessionKey( | |
| "Agent:Fina:Slack:DM:ABC", | |
| makeCtx({ | |
| Surface: "slack", | |
| From: "slack:U123", | |
| }), | |
| ), | |
| ).toBe("agent:fina:slack:dm:abc"); | |
| }); | |
| }); | |