status button
This commit is contained in:
1 parent
c7547a9125
commit
9e94c05fb6
5 files changed
+109
-23
No files matched your search
@@ -52,10 +52,11 @@ func TestTitle(t *testing.T) {
|
||||
}
|
||||
|
||||
type fakeSlack struct {
|
||||
mu sync.Mutex
|
||||
msgs map[string]string
|
||||
order []string
|
||||
n int
|
||||
mu sync.Mutex
|
||||
msgs map[string]string
|
||||
blocks map[string]string
|
||||
order []string
|
||||
n int
|
||||
}
|
||||
|
||||
func (f *fakeSlack) handler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -69,6 +70,9 @@ func (f *fakeSlack) handler(w http.ResponseWriter, r *http.Request) {
|
||||
f.order = append(f.order, ts)
|
||||
}
|
||||
f.msgs[ts] = r.Form.Get("text")
|
||||
if f.blocks != nil {
|
||||
f.blocks[ts] = r.Form.Get("blocks")
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"ok": true, "channel": "D1", "ts": ts, "text": f.msgs[ts]})
|
||||
}
|
||||
@@ -103,6 +107,49 @@ func TestStreamerSplitsLongReplies(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamerStatusUntilFinished(t *testing.T) {
|
||||
f := &fakeSlack{msgs: map[string]string{"ph": ""}, blocks: map[string]string{}, order: []string{"ph"}}
|
||||
srv := httptest.NewServer(http.HandlerFunc(f.handler))
|
||||
defer srv.Close()
|
||||
api := slack.New("xoxb-test", slack.OptionAPIURL(srv.URL+"/"))
|
||||
|
||||
st := NewStreamer(api, "D1", "root", "ph")
|
||||
st.Update(acp.Update{Kind: "tool_call", Title: "Shell"})
|
||||
st.mu.Lock()
|
||||
st.dirty = true
|
||||
st.mu.Unlock()
|
||||
st.flush(true)
|
||||
|
||||
f.mu.Lock()
|
||||
live := f.blocks["ph"]
|
||||
f.mu.Unlock()
|
||||
for _, want := range []string{`"action_id":"cancel"`, `"value":"ph"`, "Running Shell", "last update from the agent"} {
|
||||
if !strings.Contains(live, want) {
|
||||
t.Fatalf("live reply should contain %s: %s", want, live)
|
||||
}
|
||||
}
|
||||
|
||||
st.Finish("end_turn", nil)
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
if f.blocks["ph"] != "[]" {
|
||||
t.Fatalf("finished reply should drop the status and button: %s", f.blocks["ph"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelButtonCancelsPrompt(t *testing.T) {
|
||||
b := &Bot{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
b.running.Store("C1/ph", cancel)
|
||||
cb := slack.InteractionCallback{Type: slack.InteractionTypeBlockActions}
|
||||
cb.Channel.ID = "C1"
|
||||
cb.ActionCallback.BlockActions = []*slack.BlockAction{{ActionID: "cancel", Value: "ph"}}
|
||||
b.onAction(context.Background(), cb)
|
||||
if ctx.Err() == nil {
|
||||
t.Fatal("Cancel should cancel the reply")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveTarget(t *testing.T) {
|
||||
b := &Bot{}
|
||||
for in, want := range map[string]string{"": "", "auto": "", "Slave-1": "slave-1", "to node-b": "node-b"} {
|
||||
|
||||
Reference in new issue
Block a user