making use of the extended perms and added future work

This commit is contained in:
ari committed 2026-11-01 13:55:25 -05:00
1 parent 296e465f48
commit 22fd8fbce8
19 files changed
+617 -40

No files matched your search

+77
View File
@@ -12,6 +12,7 @@ import (
"testing"
"github.com/slack-go/slack"
"github.com/slack-go/slack/slackevents"
"slackerbot/internal/acp"
"slackerbot/internal/manager"
@@ -247,3 +248,79 @@ func TestManageCommandsInSlack(t *testing.T) {
t.Fatal("reset should drop the channel's own list")
}
}
func TestListenInThreads(t *testing.T) {
log := &slackLog{text: map[string]string{}, under: map[string]string{}}
srv := httptest.NewServer(log)
defer srv.Close()
store, _ := state.Open(filepath.Join(t.TempDir(), "state.json"))
_ = store.AddSession(&model.Session{Channel: "C1", ThreadTS: "1.0", OwnerID: "C1", ACPID: "a"})
b := &Bot{store: store, botID: "UBOT", api: slack.New("xoxb", slack.OptionAPIURL(srv.URL+"/"))}
ctx := context.Background()
say := func(m incoming) string {
if !b.listenCommand(ctx, m) {
return "(went to the agent)"
}
log.mu.Lock()
defer log.mu.Unlock()
last := log.order[len(log.order)-1]
if log.under[last] != m.threadTS {
t.Fatalf("reply went to thread %q, want %q", log.under[last], m.threadTS)
}
return log.text[last]
}
if b.listening("C1", "1.0", "hello") {
t.Fatal("threads only read mentions by default")
}
if got := say(incoming{channel: "C1", threadTS: "1.0", text: "/listen all-messages"}); !strings.Contains(got, "read every reply") {
t.Fatalf("thread toggle: %q", got)
}
if !b.listening("C1", "1.0", "hello") || b.listening("C1", "1.0", "<@UBOT> hello") || b.listening("C1", "9.0", "hello") {
t.Fatal("all-messages should read plain replies in session threads only, and leave mentions to app_mention")
}
if got := say(incoming{channel: "C1", threadTS: "1.0", text: "listen to me carefully"}); got != "(went to the agent)" {
t.Fatalf("plain sentence: %q", got)
}
if got := say(incoming{channel: "C1", threadTS: "9.0", text: "/listen all-messages"}); !strings.Contains(got, "no session") {
t.Fatalf("thread without a session: %q", got)
}
if got := say(incoming{channel: "C1", text: "/listen all-messages"}); !strings.Contains(got, "this channel's threads") {
t.Fatalf("channel default: %q", got)
}
_ = store.AddSession(&model.Session{Channel: "C1", ThreadTS: "2.0", OwnerID: "C1", ACPID: "b"})
if !b.listening("C1", "2.0", "hello") {
t.Fatal("new threads follow the channel default")
}
if got := say(incoming{channel: "D1", dm: true, text: "/listen only-mentions"}); !strings.Contains(got, "every message") {
t.Fatalf("DMs always listen: %q", got)
}
}
func TestStopReactionCancelsPrompt(t *testing.T) {
b := &Bot{}
ctx, cancel := context.WithCancel(context.Background())
b.running.Store("C1/5.0", cancel)
b.onReaction(&slackevents.ReactionAddedEvent{Reaction: "thumbsup", Item: slackevents.Item{Type: "message", Channel: "C1", Timestamp: "5.0"}})
if ctx.Err() != nil {
t.Fatal("other reactions must not cancel")
}
b.onReaction(&slackevents.ReactionAddedEvent{Reaction: "x", Item: slackevents.Item{Type: "message", Channel: "C1", Timestamp: "5.0"}})
if ctx.Err() == nil {
t.Fatal(":x: should cancel the reply")
}
}
func TestCommandsInAssistantThreads(t *testing.T) {
log := &slackLog{text: map[string]string{}, under: map[string]string{}}
srv := httptest.NewServer(log)
defer srv.Close()
store, _ := state.Open(filepath.Join(t.TempDir(), "state.json"))
b := &Bot{store: store, api: slack.New("xoxb", slack.OptionAPIURL(srv.URL+"/"))}
b.onMessage(context.Background(), incoming{user: "U1", channel: "D1", ts: "3.0", threadTS: "2.0", text: "help", dm: true})
log.mu.Lock()
defer log.mu.Unlock()
if len(log.order) != 1 || log.under[log.order[0]] != "2.0" || !strings.Contains(log.text[log.order[0]], "Commands") {
t.Fatalf("the first message of an assistant thread should run commands and answer in the thread: %v %v", log.order, log.under)
}
}