fix: keep worktree sessions in the right group
Prevents stale worktree lists from overwriting newly created worktrees Uses the created worktree path when selecting linked worktree sessions
This commit is contained in:
@@ -5,6 +5,7 @@ import type { QuestionRequest } from "@/types/question"
|
||||
// Mock SDK client that records permission.reply / question.reply calls
|
||||
const replyCalls: Array<{ method: string; params: Record<string, unknown> }> = []
|
||||
const scopedClientDirectories: string[] = []
|
||||
const registeredSessionDirectories: Array<{ sessionID: string; directory: string }> = []
|
||||
let sessionRevertResult: { data?: unknown; error?: unknown; response?: { status?: number } } = {}
|
||||
let questionReplyError: unknown | null = null
|
||||
|
||||
@@ -139,14 +140,18 @@ mock.module("./input-store", () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
// Mock useGlobalSessionsStore (imported but not used in permission functions)
|
||||
mock.module("@/stores/useGlobalSessionsStore", () => ({
|
||||
useGlobalSessionsStore: {},
|
||||
useGlobalSessionsStore: {
|
||||
getState: () => ({
|
||||
upsertSession: () => {},
|
||||
}),
|
||||
},
|
||||
}))
|
||||
|
||||
// Mock sync-refs (imported but not used in permission functions)
|
||||
mock.module("./sync-refs", () => ({
|
||||
registerSessionDirectory: () => {},
|
||||
registerSessionDirectory: (sessionID: string, directory: string) => {
|
||||
registeredSessionDirectories.push({ sessionID, directory })
|
||||
},
|
||||
}))
|
||||
|
||||
import { create, type StoreApi } from "zustand"
|
||||
|
||||
@@ -335,16 +335,16 @@ export async function createSession(
|
||||
parentID: parentID ?? undefined,
|
||||
}, directoryOverride ?? dir())
|
||||
|
||||
const sessionDirectory = (session as { directory?: string }).directory ?? directoryOverride ?? null
|
||||
// Pre-populate routing index so SSE events arriving before session.created
|
||||
// can be routed to the correct child store
|
||||
if (sessionDirectory) {
|
||||
registerSessionDirectory(session.id, sessionDirectory)
|
||||
}
|
||||
useSessionUIStore.getState().setCurrentSession(session.id, sessionDirectory)
|
||||
useSessionUIStore.getState().markSessionAsOpenChamberCreated(session.id)
|
||||
useGlobalSessionsStore.getState().upsertSession(session)
|
||||
return session
|
||||
const sessionDirectory = (session as { directory?: string | null }).directory ?? null
|
||||
// Pre-populate routing index so SSE events arriving before session.created
|
||||
// can be routed to the correct child store
|
||||
if (sessionDirectory) {
|
||||
registerSessionDirectory(session.id, sessionDirectory)
|
||||
}
|
||||
useSessionUIStore.getState().setCurrentSession(session.id, sessionDirectory)
|
||||
useSessionUIStore.getState().markSessionAsOpenChamberCreated(session.id)
|
||||
useGlobalSessionsStore.getState().upsertSession(session)
|
||||
return session
|
||||
} catch (error) {
|
||||
console.error("[session-actions] createSession failed", error)
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user