forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsandbox-channels.test.ts
More file actions
73 lines (62 loc) · 2.82 KB
/
Copy pathsandbox-channels.test.ts
File metadata and controls
73 lines (62 loc) · 2.82 KB
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
72
73
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it } from "vitest";
import {
KNOWN_CHANNELS,
getChannelDef,
getChannelTokenKeys,
knownChannelNames,
listChannels,
} from "../../dist/lib/sandbox-channels";
describe("sandbox-channels KNOWN_CHANNELS", () => {
it("covers telegram, discord, and slack", () => {
expect(knownChannelNames()).toEqual(["telegram", "discord", "slack"]);
});
it("exposes the primary bot-token env var for each channel", () => {
expect(getChannelDef("telegram")?.envKey).toBe("TELEGRAM_BOT_TOKEN");
expect(getChannelDef("discord")?.envKey).toBe("DISCORD_BOT_TOKEN");
expect(getChannelDef("slack")?.envKey).toBe("SLACK_BOT_TOKEN");
});
it("only slack declares a secondary app-token env var", () => {
expect(getChannelDef("telegram")?.appTokenEnvKey).toBeUndefined();
expect(getChannelDef("discord")?.appTokenEnvKey).toBeUndefined();
expect(getChannelDef("slack")?.appTokenEnvKey).toBe("SLACK_APP_TOKEN");
});
it("asks for Slack human member IDs as a comma-separated allowlist", () => {
const slack = getChannelDef("slack");
expect(slack?.userIdEnvKey).toBe("SLACK_ALLOWED_USERS");
expect(slack?.userIdLabel).toBe("Slack Member IDs (comma-separated allowlist)");
expect(slack?.userIdHelp).toContain("comma-separated member IDs");
expect(slack?.userIdHelp).toContain("not the app or bot user ID");
expect(slack?.allowIdsMode).toBe("dm");
});
it("normalises case and whitespace when resolving a channel name", () => {
expect(getChannelDef(" Telegram ")).toBe(KNOWN_CHANNELS.telegram);
expect(getChannelDef("DISCORD")).toBe(KNOWN_CHANNELS.discord);
});
it("returns undefined for unknown channel names", () => {
expect(getChannelDef("mattermost")).toBeUndefined();
expect(getChannelDef("")).toBeUndefined();
});
});
describe("sandbox-channels getChannelTokenKeys", () => {
it("returns just the primary token key for single-token channels", () => {
expect(getChannelTokenKeys(KNOWN_CHANNELS.telegram)).toEqual(["TELEGRAM_BOT_TOKEN"]);
expect(getChannelTokenKeys(KNOWN_CHANNELS.discord)).toEqual(["DISCORD_BOT_TOKEN"]);
});
it("returns primary then app token for slack", () => {
expect(getChannelTokenKeys(KNOWN_CHANNELS.slack)).toEqual([
"SLACK_BOT_TOKEN",
"SLACK_APP_TOKEN",
]);
});
});
describe("sandbox-channels listChannels", () => {
it("materialises an array with the name merged into each entry", () => {
const list = listChannels();
expect(list.map((c) => c.name)).toEqual(["telegram", "discord", "slack"]);
const telegram = list.find((c) => c.name === "telegram");
expect(telegram?.envKey).toBe("TELEGRAM_BOT_TOKEN");
expect(telegram?.allowIdsMode).toBe("dm");
});
});