Slack: implement replyToMode threading for tool path

- 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
This commit is contained in:
Austin Mudd
2026-01-08 16:04:52 -08:00
committed by Peter Steinberger
parent 29e6f13b29
commit b4663ed11c
11 changed files with 475 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { isSlackRoomAllowedByPolicy } from "./monitor.js";
import { isSlackRoomAllowedByPolicy, resolveSlackThreadTs } from "./monitor.js";
describe("slack groupPolicy gating", () => {
it("allows when policy is open", () => {
@@ -53,3 +53,83 @@ describe("slack groupPolicy gating", () => {
).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);
});
});
});