返回 DeepSeek-Reasonix
session_source_rows_test.go
根目录 / desktop / session_source_rows_test.go
1 package main
2
3 import (
4 "os"
5 "path/filepath"
6 "reasonix/internal/agent"
7 "reasonix/internal/config"
8 "reasonix/internal/provider"
9 "testing"
10 )
11
12 func TestIndependentLegacyHeadsAdoptOneWithoutHidingSibling(t *testing.T) {
13 isolateDesktopUserDirs(t)
14 path := filepath.Join(config.SessionDir(), "independent-heads.jsonl")
15 legacy := agent.NewSession("system")
16 legacy.Add(provider.Message{ID: "question", Role: provider.RoleUser, Content: "question"})
17 legacy.Add(provider.Message{ID: "answer", Role: provider.RoleAssistant, Content: "answer"})
18 if err := legacy.Save(path); err != nil {
19 t.Fatal(err)
20 }
21 if _, err := legacy.ForkHead(path, legacy.Snapshot()[2].ID, agent.HeadKindFork, "child"); err != nil {
22 t.Fatal(err)
23 }
24 legacy.Add(provider.Message{ID: "child", Role: provider.RoleUser, Content: "child only"})
25 if err := legacy.Save(path); err != nil {
26 t.Fatal(err)
27 }
28 before, err := os.ReadFile(path)
29 if err != nil {
30 t.Fatal(err)
31 }
32 app := NewApp()
33 t.Cleanup(app.closeSessionServices)
34 rows := expandSessionSourceRows(ProjectNode{Key: "source", Kind: "global_topic", TopicID: "same", SessionPath: path})
35 if len(rows) != 2 || projectNodeSessionKey(rows[0]) == projectNodeSessionKey(rows[1]) {
36 t.Fatalf("heads=%+v", rows)
37 }
38 // Display metadata stays lightweight and is transferred when the selected
39 // source is explicitly prepared.
40 if err := app.SetSessionPinned(SessionSelector{Source: rows[0].Source}, true); err != nil {
41 t.Fatal(err)
42 }
43 state, err := app.workspaceRegistry().Load(t.Context())
44 if err != nil {
45 t.Fatal(err)
46 }
47 if len(state.SourceMappings) != 0 {
48 t.Fatalf("pinning converted historical content: %+v", state.SourceMappings)
49 }
50 app.historicalImports.mu.Lock()
51 app.historicalImports.initialize(app.bootContext())
52 app.historicalImports.sources[rows[0].Source.SourceKey] = historicalSource{path: path, format: "legacy", scope: "global", head: rows[0].Source.HeadID}
53 app.historicalImports.views[rows[0].Source.SourceKey] = historicalImportViewFromSource(rows[0].Source.SourceKey, app.historicalImports.sources[rows[0].Source.SourceKey])
54 app.historicalImports.mu.Unlock()
55 if _, err := app.ImportHistoricalSession(rows[0].Source.SourceKey); err != nil {
56 t.Fatal(err)
57 }
58 state, err = app.workspaceRegistry().Load(t.Context())
59 if err != nil {
60 t.Fatal(err)
61 }
62 if _, ok := state.SourceMappings[rows[0].Source.SourceKey]; !ok {
63 t.Fatal("explicit preparation did not adopt the selected head")
64 }
65 if _, ok := state.SourceMappings[rows[1].Source.SourceKey]; ok {
66 t.Fatal("sibling was adopted")
67 }
68 after, err := os.ReadFile(path)
69 if err != nil || string(before) != string(after) {
70 t.Fatal("source transcript changed during adoption")
71 }
72 }
73
73 lines GO