46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, test } from "bun:test"
|
|||
|
|
import type { Event } from "@opencode-ai/sdk/v2/client"
|
||
|
|
import {
|
||
|
|
applyGlobalSessionStatusEvent,
|
||
|
|
applyGlobalSessionStatusSnapshot,
|
||
|
|
useGlobalSessionStatusStore,
|
||
|
|
} from "./global-session-status"
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
useGlobalSessionStatusStore.setState({ statusById: new Map() })
|
||
|
|
})
|
||
|
|
|
||
|
|
describe("global session status index", () => {
|
||
|
|
test("preserves full retry status details from live events", () => {
|
||
|
|
applyGlobalSessionStatusEvent("/repo", {
|
||
|
|
type: "session.status",
|
||
|
|
properties: {
|
||
|
|
sessionID: "session-a",
|
||
|
|
status: { type: "retry", attempt: 2, message: "waiting" },
|
||
|
|
},
|
||
|
|
} as Event)
|
||
|
|
|
||
|
|
expect(useGlobalSessionStatusStore.getState().statusById.get("session-a")?.status).toEqual({
|
||
|
|
type: "retry",
|
||
|
|
attempt: 2,
|
||
|
|
message: "waiting",
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
test("authoritative snapshots clear absent active entries for their directory", () => {
|
||
|
|
applyGlobalSessionStatusSnapshot("/repo", { "session-a": { type: "busy" } }, ["session-a"])
|
||
|
|
expect(useGlobalSessionStatusStore.getState().statusById.get("session-a")?.status.type).toBe("busy")
|
||
|
|
|
||
|
|
applyGlobalSessionStatusSnapshot("/repo", {}, ["session-a"])
|
||
|
|
expect(useGlobalSessionStatusStore.getState().statusById.has("session-a")).toBe(false)
|
||
|
|
})
|
||
|
|
|
||
|
|
test("clears an explicitly idle known session when directory aliases differ", () => {
|
||
|
|
applyGlobalSessionStatusSnapshot("/canonical/repo", { "session-a": { type: "busy" } }, ["session-a"])
|
||
|
|
|
||
|
|
applyGlobalSessionStatusSnapshot("/alias/repo", { "session-a": { type: "idle" } }, ["session-a"])
|
||
|
|
|
||
|
|
expect(useGlobalSessionStatusStore.getState().statusById.has("session-a")).toBe(false)
|
||
|
|
})
|
||
|
|
})
|