Files
multica/server/internal/integrations/lark/fresh_command_test.go
Wilson-G b92e4a53fb DH-106 为飞书接入补上 /new 会话指令 (MUL-3503) (#4396)
Lark/飞书入站消息新增 /new 首行指令,解析为 force_fresh_session,复用既有 daemon 会话续接门控。

Co-authored-by: Wilson-G <Wilson-G@users.noreply.github.com>
2026-06-24 14:16:22 +08:00

76 lines
1.6 KiB
Go

package lark
import "testing"
func TestParseFreshSessionCommand(t *testing.T) {
tests := []struct {
name string
body string
wantMatch bool
wantBody string
}{
{
name: "new with same-line body",
body: "/new start from scratch",
wantMatch: true,
wantBody: "start from scratch",
},
{
name: "leading blank lines tolerated",
body: "\n\n/new re-check the deploy",
wantMatch: true,
wantBody: "re-check the deploy",
},
{
name: "multi-line body preserved",
body: "/new title\nline one\nline two",
wantMatch: true,
wantBody: "title\nline one\nline two",
},
{
name: "command alone produces empty body",
body: "/new",
wantMatch: true,
wantBody: "",
},
{
name: "prefix of token rejected",
body: "/newness is not a command",
wantMatch: false,
},
{
name: "mid-sentence command rejected",
body: "please /new this run",
wantMatch: false,
},
{
name: "wrong case rejected",
body: "/New help",
wantMatch: false,
},
{
name: "normal body rejected",
body: "help me normally",
wantMatch: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd, ok := parseFreshSessionCommand(tc.body)
if ok != tc.wantMatch {
t.Fatalf("match=%v want %v (cmd=%+v)", ok, tc.wantMatch, cmd)
}
if !tc.wantMatch {
if cmd != nil {
t.Fatalf("expected nil command, got %+v", cmd)
}
return
}
if cmd.Body != tc.wantBody {
t.Errorf("body=%q want %q", cmd.Body, tc.wantBody)
}
})
}
}