返回 DeepSeek-Reasonix
read_view_test.go
根目录 / internal / historycatalog / read_view_test.go
1 package historycatalog
2
3 import (
4 "context"
5 "fmt"
6 "path/filepath"
7 "testing"
8
9 "reasonix/internal/provider"
10 )
11
12 func TestCaptureSearchKeepsRankingAcrossUnrelatedWrites(t *testing.T) {
13 root := t.TempDir()
14 messages := make([]provider.Message, 405)
15 for i := range messages {
16 messages[i] = provider.Message{Role: provider.RoleUser, Content: fmt.Sprintf("snapshot marker %d", i)}
17 }
18 path := filepath.Join(root, "source.jsonl")
19 saveMessages(t, path, messages...)
20 c, err := Open(t.Context(), Options{Path: filepath.Join(t.TempDir(), "history.sqlite")})
21 if err != nil {
22 t.Fatal(err)
23 }
24 t.Cleanup(func() { _ = c.Close(context.Background()) })
25 target := Root{Path: root, Scope: "project", WorkspaceRoot: root}
26 if err := c.ReconcileRoot(t.Context(), target); err != nil {
27 t.Fatal(err)
28 }
29 seen := map[int]bool{}
30 err = c.CaptureSearch(t.Context(), SearchRequest{Query: "snapshot marker", SessionPath: path}, func(candidate Candidate) error {
31 if seen[candidate.MessageIndex] {
32 t.Fatalf("duplicate %d", candidate.MessageIndex)
33 }
34 seen[candidate.MessageIndex] = true
35 if len(seen) == 200 {
36 other := t.TempDir()
37 saveMessages(t, filepath.Join(other, "other.jsonl"), provider.Message{Role: provider.RoleUser, Content: "snapshot snapshot snapshot marker marker"})
38 return c.ReconcileRoot(t.Context(), Root{Path: other, Scope: "global"})
39 }
40 return nil
41 })
42 if err != nil || len(seen) != 405 {
43 t.Fatalf("capture rows=%d err=%v", len(seen), err)
44 }
45 }
46
46 lines GO