fix(ui): open a chat draft when a chat scratch directory is forwarded
'New session in the current directory' callers (shortcut, menu, composer) forward the current session's directory even when that session is a chat. Its managed scratch directory names no project, but it counted as an explicit project target, so a plus pressed inside a chat session opened a project draft. Chat scratch overrides now resolve to a chat draft.
This commit is contained in:
@@ -592,6 +592,32 @@ describe('openNewSessionDraft project binding', () => {
|
|||||||
expect(useSessionUIStore.getState().newSessionDraft.target).toBe('chat');
|
expect(useSessionUIStore.getState().newSessionDraft.target).toBe('chat');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a chat scratch directory forwarded as override opens a chat draft', () => {
|
||||||
|
// "New session in the current directory" callers forward the current
|
||||||
|
// session's directory even when that session is a chat; its scratch
|
||||||
|
// directory names no project.
|
||||||
|
useSessionUIStore.getState().openNewSessionDraft({
|
||||||
|
directoryOverride: '/Users/tester/.config/openchamber/chats/ses_chat',
|
||||||
|
});
|
||||||
|
const draft = useSessionUIStore.getState().newSessionDraft;
|
||||||
|
|
||||||
|
expect(draft.target).toBe('chat');
|
||||||
|
expect(draft.directoryOverride).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a chat scratch override opens Chat even when the recorded target is a project', () => {
|
||||||
|
getDeferredSafeStorage().setItem(
|
||||||
|
DRAFT_TARGET_KEY,
|
||||||
|
JSON.stringify({ projectId: projectB.id, directory: projectB.path, target: 'project' }),
|
||||||
|
);
|
||||||
|
|
||||||
|
useSessionUIStore.getState().openNewSessionDraft({
|
||||||
|
directoryOverride: '/Users/tester/.config/openchamber/chats/ses_chat',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(useSessionUIStore.getState().newSessionDraft.target).toBe('chat');
|
||||||
|
});
|
||||||
|
|
||||||
test('falls back to Chat when the last project target no longer exists', () => {
|
test('falls back to Chat when the last project target no longer exists', () => {
|
||||||
getDeferredSafeStorage().setItem(
|
getDeferredSafeStorage().setItem(
|
||||||
DRAFT_TARGET_KEY,
|
DRAFT_TARGET_KEY,
|
||||||
|
|||||||
@@ -1115,9 +1115,15 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
|||||||
const currentDirectory = normalizePath(useDirectoryStore.getState().currentDirectory ?? null)
|
const currentDirectory = normalizePath(useDirectoryStore.getState().currentDirectory ?? null)
|
||||||
const persistedTarget = readPersistedDraftTarget()
|
const persistedTarget = readPersistedDraftTarget()
|
||||||
|
|
||||||
const explicitDirectory = options?.directoryOverride !== undefined
|
// Callers that forward "the current session's directory" forward it for
|
||||||
|
// chat sessions too, and a chat session's scratch directory names no
|
||||||
|
// project. Treating it as an explicit project target would force a project
|
||||||
|
// draft rooted in scratch; it is a request for another chat.
|
||||||
|
const rawExplicitDirectory = options?.directoryOverride !== undefined
|
||||||
? normalizePath(options.directoryOverride)
|
? normalizePath(options.directoryOverride)
|
||||||
: null
|
: null
|
||||||
|
const explicitDirectoryIsChat = rawExplicitDirectory !== null && isChatDirectoryPath(rawExplicitDirectory)
|
||||||
|
const explicitDirectory = explicitDirectoryIsChat ? null : rawExplicitDirectory
|
||||||
const persistedProjectById = persistedTarget?.projectId
|
const persistedProjectById = persistedTarget?.projectId
|
||||||
? projects.find((p) => p.id === persistedTarget.projectId) ?? null
|
? projects.find((p) => p.id === persistedTarget.projectId) ?? null
|
||||||
: null
|
: null
|
||||||
@@ -1138,7 +1144,7 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
|||||||
|
|
||||||
let target = isVSCodeRuntime() ? "project" : options?.target
|
let target = isVSCodeRuntime() ? "project" : options?.target
|
||||||
if (!target) {
|
if (!target) {
|
||||||
const hasExplicitProjectTarget = options?.directoryOverride !== undefined
|
const hasExplicitProjectTarget = (options?.directoryOverride !== undefined && !explicitDirectoryIsChat)
|
||||||
|| (options?.selectedProjectId !== undefined && options.selectedProjectId !== CHAT_DRAFT_PROJECT_ID)
|
|| (options?.selectedProjectId !== undefined && options.selectedProjectId !== CHAT_DRAFT_PROJECT_ID)
|
||||||
|| isVSCodeRuntime()
|
|| isVSCodeRuntime()
|
||||||
target = options?.selectedProjectId === CHAT_DRAFT_PROJECT_ID
|
target = options?.selectedProjectId === CHAT_DRAFT_PROJECT_ID
|
||||||
|
|||||||
Reference in New Issue
Block a user