返回 DeepSeek-Reasonix
session_organization_manual_order_test.go
根目录 / desktop / session_organization_manual_order_test.go
1 package main
2
3 import (
4 "fmt"
5 "path/filepath"
6 "reflect"
7 "testing"
8 "time"
9
10 "reasonix/desktop/internal/workspacestate"
11 "reasonix/internal/session"
12 )
13
14 func TestManualOrderStartsFromShownOrderAndKeepsNewSessionsInFirstPage(t *testing.T) {
15 isolateDesktopUserDirs(t)
16 root := t.TempDir()
17 app := NewApp()
18 t.Cleanup(app.closeSessionServices)
19 app.ctx = t.Context()
20 installNoopRuntimeEvents(app)
21 app.desktopSessions.root = filepath.Join(root, "desktop-sessions-v5", "by-id")
22 app.desktopSessions.workspaceState = workspacestate.NewStore(filepath.Join(root, "desktop", "workspace-state-v1.json"))
23 workspaceID, err := app.ensureDesktopWorkspace(t.Context(), "project", root)
24 if err != nil {
25 t.Fatal(err)
26 }
27 create := func(id string) {
28 t.Helper()
29 if _, err := app.desktopSessionService("").Create(t.Context(), session.CreateOptions{SessionID: id, CWD: root, Origin: session.SessionOriginNew}); err != nil {
30 t.Fatal(err)
31 }
32 if err := app.workspaceRegistry().AttachSession(t.Context(), "", workspaceID, id, ""); err != nil {
33 t.Fatal(err)
34 }
35 time.Sleep(5 * time.Millisecond)
36 }
37 shown := func(limit int) []string {
38 t.Helper()
39 page, err := app.unifiedProjectTopics(ProjectTopicPageRequest{Scope: "project", WorkspaceRoot: root, Limit: limit, SortMode: "updated"})
40 if err != nil {
41 t.Fatal(err)
42 }
43 app.ReleaseReadSnapshot(page.SnapshotID)
44 ids := []string{}
45 for _, row := range page.Items {
46 if row.Session == nil {
47 t.Fatalf("row without a session identity: %#v", row)
48 }
49 ids = append(ids, row.Session.SessionID)
50 }
51 return ids
52 }
53 ids := []string{}
54 for i := range 12 {
55 id := fmt.Sprintf("history-%02d", i)
56 create(id)
57 ids = append([]string{id}, ids...)
58 }
59 if got := shown(12); !reflect.DeepEqual(got, ids) {
60 t.Fatalf("activity order = %v, want %v", got, ids)
61 }
62
63 workspace := SessionOrganizationWorkspace{Scope: "project", WorkspaceRoot: root}
64 current, err := app.GetSessionOrganization(workspace)
65 if err != nil {
66 t.Fatal(err)
67 }
68 ref := func(id string) *SessionSelector {
69 return &SessionSelector{Ref: &session.SessionRef{HostID: localDesktopHostID, SessionID: id}}
70 }
71 moved, err := app.UpdateSessionOrganization(workspace, current.Revision, SessionOrganizationMutation{
72 Kind: "move", Target: ref("history-00"), Anchor: ref("history-11"), Position: "before", SortMode: "updated",
73 })
74 if err != nil || !moved.Applied || !moved.ManualOrderEnabled {
75 t.Fatalf("move = %#v, %v", moved, err)
76 }
77 want := append([]string{"history-00"}, ids[:len(ids)-1]...)
78 if got := shown(12); !reflect.DeepEqual(got, want) {
79 t.Fatalf("first manual move reordered the rest of the list: %v, want %v", got, want)
80 }
81
82 create("fresh")
83 if got := shown(5); len(got) == 0 || got[0] != "fresh" {
84 t.Fatalf("new session is outside the first sidebar page: %v", got)
85 }
86 }
87
87 lines GO