Skip to content

Commit 587fa58

Browse files
yimojclaude
andcommitted
test(onboard): cover all messaging channels and edge cases for preset merge (NVIDIA#5967)
The NVIDIA#5967 fix is channel-agnostic — it iterates the channel→preset registry — but unit coverage only exercised Slack and Discord. Add explicit merge cases for Telegram, Teams, WhatsApp, and WeChat, prune cases for WhatsApp/WeChat, and edge cases for an empty/null/undefined channel list (selection unchanged) and an unknown channel name (no preset), so a future channel-table regression cannot pass on the two already-covered channels alone. Signed-off-by: Yimo Jiang <yimoj@nvidia.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5584fd3 commit 587fa58

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

src/lib/onboard/messaging-policy-presets.test.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
allMessagingChannelPolicyPresets,
88
hasDisabledMessagingPolicyPreset,
99
mergeAppliedPolicyPresetsForDisabledMessagingCleanup,
10+
mergeEnabledMessagingChannelPolicyPresets,
1011
mergePolicyMessagingChannels,
11-
mergeRequiredMessagingChannelPolicyPresets,
1212
pruneDisabledMessagingPolicyPresets,
1313
requiredMessagingChannelPolicyPresets,
1414
} from "./messaging-policy-presets";
@@ -20,7 +20,7 @@ describe("messaging policy presets", () => {
2020
});
2121

2222
it("merges required messaging presets into an existing selection", () => {
23-
expect(mergeRequiredMessagingChannelPolicyPresets(["npm", "pypi"], ["slack"])).toEqual([
23+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm", "pypi"], ["slack"])).toEqual([
2424
"npm",
2525
"pypi",
2626
"slack",
@@ -31,24 +31,24 @@ describe("messaging policy presets", () => {
3131
// WhatsApp, Teams, WeChat) still needs its egress preset merged so policy
3232
// finalization persists it and policy-list marks it applied.
3333
it("merges an enabled channel preset that is not required at create time", () => {
34-
expect(mergeRequiredMessagingChannelPolicyPresets(["npm"], ["discord"])).toEqual([
34+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["discord"])).toEqual([
3535
"npm",
3636
"discord",
3737
]);
3838
expect(requiredMessagingChannelPolicyPresets(["discord"])).toEqual([]);
39-
expect(mergeRequiredMessagingChannelPolicyPresets(["npm"], ["slack", "discord"])).toEqual([
39+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["slack", "discord"])).toEqual([
4040
"npm",
4141
"slack",
4242
"discord",
4343
]);
4444
});
4545

4646
it("does not add a channel preset that is not available to the sandbox", () => {
47+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["slack"], new Set(["npm"]))).toEqual(
48+
["npm"],
49+
);
4750
expect(
48-
mergeRequiredMessagingChannelPolicyPresets(["npm"], ["slack"], new Set(["npm"])),
49-
).toEqual(["npm"]);
50-
expect(
51-
mergeRequiredMessagingChannelPolicyPresets(["npm"], ["discord"], new Set(["npm"])),
51+
mergeEnabledMessagingChannelPolicyPresets(["npm"], ["discord"], new Set(["npm"])),
5252
).toEqual(["npm"]);
5353
});
5454

@@ -108,4 +108,40 @@ describe("messaging policy presets", () => {
108108
mergeAppliedPolicyPresetsForDisabledMessagingCleanup(["npm"], ["npm", "github"], ["slack"]),
109109
).toEqual(["npm"]);
110110
});
111+
112+
// #5967 is channel-agnostic: every non-`requiredAtCreate` channel (Telegram,
113+
// Teams, WhatsApp, WeChat) must merge and prune exactly like Discord. Cover the
114+
// remaining channels explicitly so a future channel-table regression cannot pass
115+
// on Slack/Discord alone.
116+
it("merges every enabled non-required channel preset, not just Slack and Discord (#5967)", () => {
117+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["telegram"])).toEqual([
118+
"npm",
119+
"telegram",
120+
]);
121+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["teams"])).toEqual(["npm", "teams"]);
122+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["whatsapp"])).toEqual([
123+
"npm",
124+
"whatsapp",
125+
]);
126+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["wechat"])).toEqual([
127+
"npm",
128+
"wechat",
129+
]);
130+
});
131+
132+
it("prunes every disabled non-required channel preset (#5967)", () => {
133+
expect(pruneDisabledMessagingPolicyPresets(["npm", "whatsapp"], ["whatsapp"])).toEqual(["npm"]);
134+
expect(pruneDisabledMessagingPolicyPresets(["npm", "wechat"], ["wechat"])).toEqual(["npm"]);
135+
});
136+
137+
it("leaves the selection untouched when no channels are enabled (#5967)", () => {
138+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], [])).toEqual(["npm"]);
139+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], null)).toEqual(["npm"]);
140+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], undefined)).toEqual(["npm"]);
141+
});
142+
143+
it("yields no preset for an unknown channel name (#5967)", () => {
144+
expect(allMessagingChannelPolicyPresets(["nonexistent"])).toEqual([]);
145+
expect(mergeEnabledMessagingChannelPolicyPresets(["npm"], ["nonexistent"])).toEqual(["npm"]);
146+
});
111147
});

0 commit comments

Comments
 (0)