返回 DeepSeek-Reasonix
history_slice_cold_test.go
根目录 / desktop / history_slice_cold_test.go
1 package main
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7 "testing"
8
9 "reasonix/internal/provider"
10 )
11
12 func TestHistorySliceColdPathBeforeControllerReady(t *testing.T) {
13 isolateDesktopUserDirs(t)
14 root := t.TempDir()
15 dir := desktopSessionDir(root)
16 if err := os.MkdirAll(dir, 0o755); err != nil {
17 t.Fatal(err)
18 }
19 messages := make([]provider.Message, 0, 80)
20 for i := range 40 {
21 messages = append(messages,
22 provider.Message{Role: provider.RoleUser, Content: fmt.Sprintf("cold user turn %d large-session marker", i)},
23 provider.Message{Role: provider.RoleAssistant, Content: fmt.Sprintf("cold assistant turn %d large-session marker", i)},
24 )
25 }
26 _, path := saveHistorySliceSession(t, dir, "cold-large.jsonl", messages)
27 app := NewApp()
28 tab := &WorkspaceTab{
29 ID: "cold-large",
30 Scope: "project",
31 WorkspaceRoot: root,
32 SessionPath: path,
33 Ready: false,
34 Ctrl: nil,
35 }
36 app.mu.Lock()
37 app.tabs = map[string]*WorkspaceTab{tab.ID: tab}
38 app.activeTabID = tab.ID
39 app.mu.Unlock()
40
41 page := app.HistorySliceForTab(tab.ID, HistorySliceRequest{Turns: 12})
42 if page.Error != "" {
43 t.Fatalf("cold slice error = %q", page.Error)
44 }
45 if len(page.Entries) == 0 {
46 t.Fatal("cold slice returned no entries before controller ready")
47 }
48 if page.Source != "index" && page.Source != "scan" {
49 t.Fatalf("cold source = %q, want index|scan", page.Source)
50 }
51 }
52
53 func TestHistorySliceReportsErrorInsteadOfEmptySuccess(t *testing.T) {
54 isolateDesktopUserDirs(t)
55 app := NewApp()
56 tab := &WorkspaceTab{
57 ID: "missing",
58 Scope: "project",
59 SessionPath: filepath.Join(t.TempDir(), "does-not-exist.jsonl"),
60 Ready: false,
61 }
62 app.mu.Lock()
63 app.tabs = map[string]*WorkspaceTab{tab.ID: tab}
64 app.activeTabID = tab.ID
65 app.mu.Unlock()
66
67 page := app.HistorySliceForTab(tab.ID, HistorySliceRequest{})
68 if page.Error == "" {
69 t.Fatal("missing session should report Error, not a silent empty success")
70 }
71 if len(page.Entries) != 0 {
72 t.Fatalf("entries = %d, want 0 on error", len(page.Entries))
73 }
74 }
75
75 lines GO