| 1 | package history |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/historycatalog" |
| 10 | "reasonix/internal/provider" |
| 11 | ) |
| 12 | |
| 13 | func TestHistorySurfacesExcludePinnedContextRevisions(t *testing.T) { |
| 14 | sessionDir := t.TempDir() |
| 15 | path := filepath.Join(sessionDir, "pinned.jsonl") |
| 16 | revision := provider.Message{ |
| 17 | Role: provider.RoleUser, Origin: provider.MessageOriginHost, |
| 18 | Content: "<pinned_context_revision>private pinned body</pinned_context_revision>", |
| 19 | } |
| 20 | writeSession(t, path, []provider.Message{revision, {Role: provider.RoleUser, Content: "visible question"}}) |
| 21 | |
| 22 | searcher := NewSearcher(Options{SessionDir: sessionDir}) |
| 23 | hits, err := searcher.Search(context.Background(), SearchRequest{Query: "private pinned body"}) |
| 24 | if err != nil { |
| 25 | t.Fatalf("Search() error = %v", err) |
| 26 | } |
| 27 | if len(hits) != 0 { |
| 28 | t.Fatalf("Search() returned pinned revision hits: %#v", hits) |
| 29 | } |
| 30 | around, err := searcher.Around(context.Background(), AroundRequest{SessionPath: path, MessageIndex: 1, Before: 1, After: 1}) |
| 31 | if err != nil { |
| 32 | t.Fatalf("Around() error = %v", err) |
| 33 | } |
| 34 | if len(around) != 1 || strings.Contains(around[0].Text, "private pinned body") { |
| 35 | t.Fatalf("Around() exposed pinned revision: %#v", around) |
| 36 | } |
| 37 | if _, ok := candidateText([]provider.Message{revision}, historycatalog.Candidate{MessageIndex: 0, Kind: string(KindUserText)}); ok { |
| 38 | t.Fatal("candidateText accepted a stale pinned-revision index entry") |
| 39 | } |
| 40 | } |
| 41 |