Session lists now promote a conversation when it starts working and again when it settles, instead of reacting to every streaming timestamp update. This keeps ordering responsive without bringing back the sidebar churn removed by the recent performance work. Apply the same user-visible order across Recent, project and worktree groups, session switchers, mobile navigation, widgets, the command palette, and the desktop tray. Preserve pinned priority, freeze timestamp fallback ordering, and keep child-session activity scoped to siblings under the same parent so it never moves the root conversation. Seed reconnect snapshots without synthetic jumps, clear ephemeral ranks on deletion and runtime changes, and cover lifecycle transitions, mixed root/child trees, metadata-only updates, and project-group ordering with regression tests.
75 lines
2.9 KiB
TypeScript
75 lines
2.9 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"
|
|
import { resetSessionOrdering, useSessionOrderingStore } from "./session-ordering"
|
|
|
|
beforeEach(() => {
|
|
useGlobalSessionStatusStore.setState({ statusById: new Map() })
|
|
resetSessionOrdering()
|
|
})
|
|
|
|
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("promotes on active and settled lifecycle edges only", () => {
|
|
applyGlobalSessionStatusEvent("/repo", {
|
|
type: "session.status",
|
|
properties: { sessionID: "session-a", status: { type: "busy" } },
|
|
} as Event)
|
|
const busyRank = useSessionOrderingStore.getState().rankById.get("session-a")
|
|
|
|
applyGlobalSessionStatusEvent("/repo", {
|
|
type: "session.status",
|
|
properties: { sessionID: "session-a", status: { type: "retry", attempt: 1, message: "wait", next: 1 } },
|
|
} as Event)
|
|
expect(useSessionOrderingStore.getState().rankById.get("session-a")).toBe(busyRank)
|
|
|
|
applyGlobalSessionStatusEvent("/repo", {
|
|
type: "session.idle",
|
|
properties: { sessionID: "session-a" },
|
|
} as Event)
|
|
const idleRank = useSessionOrderingStore.getState().rankById.get("session-a")
|
|
expect(idleRank).toBeGreaterThan(busyRank ?? 0)
|
|
|
|
applyGlobalSessionStatusEvent("/repo", {
|
|
type: "session.error",
|
|
properties: { sessionID: "session-a" },
|
|
} as Event)
|
|
expect(useSessionOrderingStore.getState().rankById.get("session-a")).toBe(idleRank)
|
|
})
|
|
|
|
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)
|
|
})
|
|
})
|