返回 DeepSeek-Reasonix
chat_tui_web_test.go
根目录 / internal / cli / chat_tui_web_test.go
1 package cli
2
3 import (
4 "strings"
5 "testing"
6
7 "reasonix/internal/agent"
8 "reasonix/internal/control"
9 "reasonix/internal/provider"
10 )
11
12 func TestWebSlashRequestsFrontendHandoff(t *testing.T) {
13 m := newTestChatTUI()
14 m.modelRef = "deepseek/deepseek-v4-flash"
15 ctrl := newOwnedTestController(t, control.Options{SessionDir: t.TempDir()})
16 ctrl.EnsureSessionPath()
17 t.Cleanup(ctrl.Close)
18 m.ctrl = ctrl
19 cmd := m.runSlashCommand("/web")
20 if !m.launchWebOnExit {
21 t.Fatal("/web did not mark the TUI for a Web frontend handoff")
22 }
23 if m.launchWebResumePath != "" {
24 t.Fatalf("fresh /web handoff resume path = %q, want a new Web session", m.launchWebResumePath)
25 }
26 wantID := agent.BranchID(ctrl.SessionPath())
27 if m.launchWebSessionID != wantID {
28 t.Fatalf("fresh /web handoff session id = %q, want %q", m.launchWebSessionID, wantID)
29 }
30 if m.launchWebModelRef != m.modelRef {
31 t.Fatalf("fresh /web handoff model = %q, want %q", m.launchWebModelRef, m.modelRef)
32 }
33 args := strings.Join(webHandoffArgs(m.launchWebResumePath, m.launchWebSessionID, m.launchWebModelRef), " ")
34 if strings.Contains(args, "--resume") || !strings.Contains(args, "--session-id "+wantID) {
35 t.Fatalf("fresh /web handoff args = %q, must not resume the reserved path", args)
36 }
37 if cmd == nil {
38 t.Fatal("/web did not request TUI shutdown")
39 }
40 msg := cmd()
41 if _, ok := msg.(tuiShutdownMsg); !ok {
42 t.Fatalf("/web command returned %T, want tuiShutdownMsg", msg)
43 }
44 }
45
46 func TestWebSlashResumesMaterializedSession(t *testing.T) {
47 m := newTestChatTUI()
48 ctrl := newOwnedTestController(t, control.Options{SessionDir: t.TempDir()})
49 ctrl.EnsureSessionPath()
50 t.Cleanup(ctrl.Close)
51 path := ctrl.SessionPath()
52 sess := agent.NewSession("system")
53 sess.Add(provider.Message{Role: provider.RoleUser, Content: "hello"})
54 if err := sess.Save(path); err != nil {
55 t.Fatal(err)
56 }
57 m.ctrl = ctrl
58
59 if cmd := m.runSlashCommand("/web"); cmd == nil {
60 t.Fatal("/web did not request TUI shutdown")
61 }
62 if m.launchWebResumePath != path {
63 t.Fatalf("materialized /web handoff resume path = %q, want %q", m.launchWebResumePath, path)
64 }
65 if m.launchWebSessionID != agent.BranchID(path) {
66 t.Fatalf("materialized /web handoff session id = %q, want %q", m.launchWebSessionID, agent.BranchID(path))
67 }
68 args := strings.Join(webHandoffArgs(m.launchWebResumePath, m.launchWebSessionID, m.launchWebModelRef), " ")
69 if !strings.Contains(args, "--resume "+path) || strings.Contains(args, "--session-id") {
70 t.Fatalf("materialized /web handoff args = %q, want resume path %q", args, path)
71 }
72 }
73
73 lines GO