| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/config" |
| 8 | "reasonix/internal/provider" |
| 9 | "reasonix/internal/session" |
| 10 | ) |
| 11 | |
| 12 | func headlessRunFixture(t *testing.T, root, id string) { |
| 13 | t.Helper() |
| 14 | service, err := session.NewService("headless-source", session.NewFilesystemPersistence(root)) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | t.Cleanup(func() { _ = service.Shutdown(t.Context()) }) |
| 19 | runtime, err := service.Create(t.Context(), session.CreateOptions{SessionID: id, Kind: session.SessionKindHeadlessRun}) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | payload, _ := json.Marshal(map[string]any{"message": provider.Message{ID: "user", Role: provider.RoleUser, Content: "list the tools of the server"}}) |
| 24 | if _, err := runtime.Session().AppendBatch(t.Context(), "message", []session.Event{{Kind: "message/complete", Payload: payload}}); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | if err := service.Close(t.Context(), runtime.Ref()); err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestHistoricalCatalogOmitsHeadlessRunStores(t *testing.T) { |
| 33 | isolateDesktopUserDirs(t) |
| 34 | coldV4MigrationFixture(t, config.SessionStoreDir(), "ordinary-conversation") |
| 35 | headlessRunFixture(t, config.SessionStoreDir(), "0123456789abcdef0123456789abcdef") |
| 36 | app := newHistoricalLifecycleApp(t) |
| 37 | installSessionCatalogForTest(t, app, config.SessionDir(), "global", "") |
| 38 | |
| 39 | management, err := app.ListHistoricalSessions() |
| 40 | if err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | if len(management.Items) != 1 { |
| 44 | t.Errorf("historical management lists %d sources, want only the conversation: %+v", len(management.Items), management.Items) |
| 45 | } |
| 46 | page, err := app.ListProjectTopics(ProjectTopicPageRequest{Scope: "global", Limit: 50}) |
| 47 | if err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | if len(page.Items) != 1 || page.Items[0].Source == nil || page.Items[0].Source.Path == "" || |
| 51 | page.Items[0].Label == "0123456789abcdef0123456789abcdef" { |
| 52 | t.Errorf("sidebar rows = %+v, want only the ordinary conversation", page.Items) |
| 53 | } |
| 54 | if rows := app.listSessionsFromDir(config.SessionDir(), ""); len(rows) != 1 { |
| 55 | t.Errorf("history rows = %+v, want only the ordinary conversation", rows) |
| 56 | } |
| 57 | } |
| 58 |