返回 DeepSeek-Reasonix
history_slice_migration_test.go
根目录 / desktop / history_slice_migration_test.go
1 package main
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7 "strings"
8 "testing"
9
10 "reasonix/internal/store"
11 )
12
13 // TestHistorySliceColdLegacyEventFormat pages an ancient event-record
14 // session through the streaming legacy fallback.
15 func TestHistorySliceColdLegacyEventFormat(t *testing.T) {
16 app := historySliceTestApp(t)
17 tab := newColdHistoryTab(t, app)
18 dir := tabSessionDir(tab)
19 if err := os.MkdirAll(dir, 0o755); err != nil {
20 t.Fatal(err)
21 }
22 path := filepath.Join(dir, "legacy.jsonl")
23 var body strings.Builder
24 for i := range 10 {
25 fmt.Fprintf(&body, "{\"kind\":\"user.message\",\"text\":\"question %d\"}\n", i)
26 fmt.Fprintf(&body, "{\"kind\":\"model.final\",\"content\":\"answer %d\"}\n", i)
27 }
28 if err := os.WriteFile(path, []byte(body.String()), 0o600); err != nil {
29 t.Fatal(err)
30 }
31 tab.SessionPath = path
32
33 pages := collectHistorySlicePages(t, app, "cold", HistorySliceRequest{Turns: 4, Entries: 6})
34 rows := concatHistoryPages(pages)
35 if len(rows) != 20 {
36 t.Fatalf("legacy rows = %d, want 20", len(rows))
37 }
38 if rows[0].Role != "user" || rows[0].Content != "question 0" {
39 t.Fatalf("first legacy row = %+v", rows[0])
40 }
41 if rows[19].Content != "answer 9" {
42 t.Fatalf("last legacy row = %+v", rows[19])
43 }
44 if pages[0].TotalTurns != 10 {
45 t.Fatalf("TotalTurns = %d, want 10", pages[0].TotalTurns)
46 }
47 // No display index may be written for the legacy format.
48 if _, err := os.Stat(store.SessionDisplayIndex(path)); !os.IsNotExist(err) {
49 t.Fatal("legacy event-format sessions must not get a display index")
50 }
51 }
52
52 lines GO