- Add shared hasRepliedRef state between auto-reply and tool paths - Extract buildSlackThreadingContext helper in agent-runner.ts - Extract resolveThreadTsFromContext helper in slack-actions.ts - Update docs with clear replyToMode table (off/first/all) - Add tests for first mode behavior across multiple messages
136 lines
3.3 KiB
TypeScript
136 lines
3.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { isSlackRoomAllowedByPolicy, resolveSlackThreadTs } from "./monitor.js";
|
|
|
|
describe("slack groupPolicy gating", () => {
|
|
it("allows when policy is open", () => {
|
|
expect(
|
|
isSlackRoomAllowedByPolicy({
|
|
groupPolicy: "open",
|
|
channelAllowlistConfigured: false,
|
|
channelAllowed: false,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("blocks when policy is disabled", () => {
|
|
expect(
|
|
isSlackRoomAllowedByPolicy({
|
|
groupPolicy: "disabled",
|
|
channelAllowlistConfigured: true,
|
|
channelAllowed: true,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("blocks allowlist when no channel allowlist configured", () => {
|
|
expect(
|
|
isSlackRoomAllowedByPolicy({
|
|
groupPolicy: "allowlist",
|
|
channelAllowlistConfigured: false,
|
|
channelAllowed: true,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("allows allowlist when channel is allowed", () => {
|
|
expect(
|
|
isSlackRoomAllowedByPolicy({
|
|
groupPolicy: "allowlist",
|
|
channelAllowlistConfigured: true,
|
|
channelAllowed: true,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("blocks allowlist when channel is not allowed", () => {
|
|
expect(
|
|
isSlackRoomAllowedByPolicy({
|
|
groupPolicy: "allowlist",
|
|
channelAllowlistConfigured: true,
|
|
channelAllowed: false,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("resolveSlackThreadTs", () => {
|
|
const threadTs = "1234567890.123456";
|
|
|
|
describe("replyToMode=off", () => {
|
|
it("returns baseThreadTs when in a thread", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "off",
|
|
baseThreadTs: threadTs,
|
|
hasReplied: false,
|
|
}),
|
|
).toBe(threadTs);
|
|
});
|
|
|
|
it("returns baseThreadTs even after replies (stays in thread)", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "off",
|
|
baseThreadTs: threadTs,
|
|
hasReplied: true,
|
|
}),
|
|
).toBe(threadTs);
|
|
});
|
|
|
|
it("returns undefined when not in a thread", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "off",
|
|
baseThreadTs: undefined,
|
|
hasReplied: false,
|
|
}),
|
|
).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("replyToMode=first", () => {
|
|
it("returns baseThreadTs for first reply", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "first",
|
|
baseThreadTs: threadTs,
|
|
hasReplied: false,
|
|
}),
|
|
).toBe(threadTs);
|
|
});
|
|
|
|
it("returns undefined for subsequent replies (goes to main channel)", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "first",
|
|
baseThreadTs: threadTs,
|
|
hasReplied: true,
|
|
}),
|
|
).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("replyToMode=all", () => {
|
|
it("returns baseThreadTs for first reply", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "all",
|
|
baseThreadTs: threadTs,
|
|
hasReplied: false,
|
|
}),
|
|
).toBe(threadTs);
|
|
});
|
|
|
|
it("returns baseThreadTs for subsequent replies (all go to thread)", () => {
|
|
expect(
|
|
resolveSlackThreadTs({
|
|
replyToMode: "all",
|
|
baseThreadTs: threadTs,
|
|
hasReplied: true,
|
|
}),
|
|
).toBe(threadTs);
|
|
});
|
|
});
|
|
});
|