|
1 | 1 | import { describe, expect, test } from "bun:test" |
2 | | -import type { SessionV2Info } from "@opencode-ai/sdk/v2/client" |
| 2 | +import { QueryClient } from "@tanstack/solid-query" |
| 3 | +import type { Session, SessionV2Info } from "@opencode-ai/sdk/v2/client" |
3 | 4 | import { |
4 | 5 | applyHomeSessionEvent, |
5 | 6 | appendHomeSessionEvent, |
| 7 | + createHomeSessionIndexCache, |
6 | 8 | HOME_V2_SESSION_PAGE_LIMIT, |
7 | 9 | loadHomeSessionIndex, |
8 | 10 | homeSessionIndexSessions, |
@@ -151,4 +153,33 @@ describe("Home V2 session index", () => { |
151 | 153 | expect(homeSessionIndexRefresh("global.disposed", true).refetch).toBe(true) |
152 | 154 | expect(homeSessionIndexRefresh("session.next.moved", true).refetch).toBe(true) |
153 | 155 | }) |
| 156 | + |
| 157 | + test("removes a session from the loaded Home index", () => { |
| 158 | + const queryClient = new QueryClient() |
| 159 | + const cache = createHomeSessionIndexCache(queryClient, "server") |
| 160 | + const sessions = [ |
| 161 | + { id: "a", time: { created: 1, updated: 1 } }, |
| 162 | + { id: "b", time: { created: 1, updated: 1 } }, |
| 163 | + ] as Session[] |
| 164 | + queryClient.setQueryData(cache.indexKey, { sessions, eventSequence: 0 }) |
| 165 | + |
| 166 | + cache.remove("a") |
| 167 | + |
| 168 | + const index = queryClient.getQueryData<{ sessions: Session[] }>(cache.indexKey) |
| 169 | + expect(index?.sessions.map((item) => item.id)).toEqual(["b"]) |
| 170 | + }) |
| 171 | + |
| 172 | + test("keeps the session out of the Home list when the index is not mounted", () => { |
| 173 | + const queryClient = new QueryClient() |
| 174 | + const cache = createHomeSessionIndexCache(queryClient, "server") |
| 175 | + const sessions = [ |
| 176 | + { id: "a", time: { created: 1, updated: 1 } }, |
| 177 | + { id: "b", time: { created: 1, updated: 1 } }, |
| 178 | + ] as Session[] |
| 179 | + |
| 180 | + cache.remove("a") |
| 181 | + |
| 182 | + expect(queryClient.getQueryData(cache.indexKey)).toBeUndefined() |
| 183 | + expect(cache.sessions({ sessions, eventSequence: 0 }, undefined).map((item) => item.id)).toEqual(["b"]) |
| 184 | + }) |
154 | 185 | }) |
0 commit comments