forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmessaging-channel-config.test.ts
More file actions
78 lines (71 loc) · 2.35 KB
/
Copy pathmessaging-channel-config.test.ts
File metadata and controls
78 lines (71 loc) · 2.35 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
74
75
76
77
78
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it } from "vitest";
import {
hydrateMessagingChannelConfig,
MESSAGING_CHANNEL_CONFIG_ENV_KEYS,
readMessagingChannelConfigFromEnv,
sanitizeMessagingChannelConfig,
} from "./messaging-channel-config";
describe("messaging channel config", () => {
it("allowlists the non-secret channel config keys used by onboard", () => {
expect(MESSAGING_CHANNEL_CONFIG_ENV_KEYS).toEqual([
"TELEGRAM_ALLOWED_IDS",
"TELEGRAM_REQUIRE_MENTION",
"DISCORD_SERVER_ID",
"DISCORD_USER_ID",
"DISCORD_REQUIRE_MENTION",
"SLACK_ALLOWED_USERS",
]);
});
it("sanitizes persisted config and rejects malformed reply-mode values", () => {
expect(
sanitizeMessagingChannelConfig({
TELEGRAM_ALLOWED_IDS: " 123,456 ",
TELEGRAM_REQUIRE_MENTION: "yes",
DISCORD_SERVER_ID: "1491590992753590594",
DISCORD_REQUIRE_MENTION: "0",
SLACK_ALLOWED_USERS: " U01ABC2DEF3, U04GHI5JKL6 ",
NVIDIA_API_KEY: "not-channel-config",
}),
).toEqual({
TELEGRAM_ALLOWED_IDS: "123,456",
DISCORD_SERVER_ID: "1491590992753590594",
DISCORD_REQUIRE_MENTION: "0",
SLACK_ALLOWED_USERS: "U01ABC2DEF3, U04GHI5JKL6",
});
});
it("hydrates missing env values but preserves explicit env overrides", () => {
const env: NodeJS.ProcessEnv = {
TELEGRAM_ALLOWED_IDS: "env-user",
};
expect(
hydrateMessagingChannelConfig(
{
TELEGRAM_ALLOWED_IDS: "stored-user",
TELEGRAM_REQUIRE_MENTION: "1",
DISCORD_REQUIRE_MENTION: "maybe",
},
env,
),
).toEqual({
TELEGRAM_ALLOWED_IDS: "env-user",
TELEGRAM_REQUIRE_MENTION: "1",
});
expect(env.TELEGRAM_ALLOWED_IDS).toBe("env-user");
expect(env.TELEGRAM_REQUIRE_MENTION).toBe("1");
expect(env.DISCORD_REQUIRE_MENTION).toBeUndefined();
});
it("reads effective config from env", () => {
expect(
readMessagingChannelConfigFromEnv({
DISCORD_SERVER_ID: "1491590992753590594",
DISCORD_REQUIRE_MENTION: "2",
TELEGRAM_REQUIRE_MENTION: "0",
}),
).toEqual({
DISCORD_SERVER_ID: "1491590992753590594",
TELEGRAM_REQUIRE_MENTION: "0",
});
});
});