返回 DeepSeek-Reasonix
rename_canonical_test.go
根目录 / internal / cli / rename_canonical_test.go
1 package cli
2
3 import (
4 "fmt"
5 "strings"
6 "testing"
7
8 "reasonix/internal/i18n"
9 )
10
11 func TestRenameCurrentCanonicalSessionWritesTitleEvent(t *testing.T) {
12 m, ctrl, service, _ := newCanonicalTakeoverTUI(t)
13
14 m.runRenameCommand("/rename testname")
15
16 out := strings.Join(m.transcript, "\n")
17 if !strings.Contains(out, fmt.Sprintf(i18n.M.RenameDoneFmt, "testname")) {
18 t.Fatalf("transcript missing rename confirmation:\n%s", out)
19 }
20 ref, _ := ctrl.SessionRef()
21 snapshot, err := service.Query().Snapshot(t.Context(), ref)
22 if err != nil {
23 t.Fatal(err)
24 }
25 if snapshot.Projection.Title != "testname" {
26 t.Fatalf("canonical title = %q, want testname", snapshot.Projection.Title)
27 }
28 }
29
30 func TestRenameIndexedCanonicalSessionWritesTitleEvent(t *testing.T) {
31 m, _, service, held := newCanonicalTakeoverTUI(t)
32 if err := service.SetTitle(t.Context(), held, "before"); err != nil {
33 t.Fatal(err)
34 }
35 index := 0
36 for i, entry := range mergedResumeEntries(m.ctrl.SessionDir(), resumeListCap) {
37 if entry.target.ref == held {
38 index = i + 1
39 }
40 }
41 if index == 0 {
42 t.Fatal("held session missing from the resume list")
43 }
44
45 m.runRenameCommand(fmt.Sprintf("/rename %d after rename", index))
46
47 out := strings.Join(m.transcript, "\n")
48 if !strings.Contains(out, fmt.Sprintf(i18n.M.RenameDoneFmt, "after rename")) {
49 t.Fatalf("transcript missing rename confirmation:\n%s", out)
50 }
51 snapshot, err := service.Query().Snapshot(t.Context(), held)
52 if err != nil {
53 t.Fatal(err)
54 }
55 if snapshot.Projection.Title != "after rename" {
56 t.Fatalf("canonical title = %q, want %q", snapshot.Projection.Title, "after rename")
57 }
58 }
59
59 lines GO