返回 DeepSeek-Reasonix
read_view_test.go
根目录 / internal / sessioncatalog / read_view_test.go
1 package sessioncatalog
2
3 import (
4 "context"
5 "fmt"
6 "path/filepath"
7 "testing"
8 )
9
10 func TestReadViewFreezesCrossPageOrder(t *testing.T) {
11 c, err := Open(t.Context(), Options{Path: filepath.Join(t.TempDir(), "catalog.sqlite"), DisableRepair: true})
12 if err != nil {
13 t.Fatal(err)
14 }
15 t.Cleanup(func() { _ = c.Close(context.Background()) })
16 for i := range 405 {
17 if err := c.UpsertSession(t.Context(), SessionRecord{Path: fmt.Sprintf("/sessions/%03d.jsonl", i), Directory: "/sessions", Scope: "global", TopicID: "shared", LastActivityAt: int64(i), Health: HealthOK, TurnsState: TurnsValid}); err != nil {
18 t.Fatal(err)
19 }
20 }
21 seen := map[string]bool{}
22 err = c.WithReadView(t.Context(), func(ctx context.Context) error {
23 topics, err := c.ListTopics(ctx, TopicPageRequest{Scope: "global", Limit: 1})
24 if err != nil {
25 return err
26 }
27 if len(topics.Items) != 1 || len(topics.Items[0].Sessions) != 405 {
28 t.Fatalf("topic hydration truncated siblings: topics=%d", len(topics.Items))
29 }
30 cursor := ""
31 for {
32 page, err := c.ListSessions(ctx, SessionPageRequest{Scope: "global", Cursor: cursor, Limit: 200})
33 if err != nil {
34 return err
35 }
36 if page.StaleCursor {
37 t.Fatal("writer invalidated fixed read view")
38 }
39 for _, row := range page.Items {
40 if seen[row.Path] {
41 t.Fatalf("duplicate %s", row.Path)
42 }
43 seen[row.Path] = true
44 }
45 if cursor == "" {
46 if err := c.UpsertSession(t.Context(), SessionRecord{Path: "/sessions/000.jsonl", Directory: "/sessions", Scope: "global", TopicID: "shared", LastActivityAt: 999, Health: HealthOK, TurnsState: TurnsValid}); err != nil {
47 return err
48 }
49 }
50 if page.NextCursor == "" {
51 return nil
52 }
53 cursor = page.NextCursor
54 }
55 })
56 if err != nil || len(seen) != 405 {
57 t.Fatalf("rows=%d err=%v", len(seen), err)
58 }
59 }
60
60 lines GO