diff --git a/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx b/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx index ceccee89c71..21f9af24ffa 100644 --- a/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx +++ b/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx @@ -54,7 +54,7 @@ export const ExplorerNotebookTabCoordinator = () => { const notebookId = tab.metadata?.notebookId if (!ref || !notebookId) return - evictNotebookFromCaches({ queryClient, projectRef: ref, id: notebookId, mode: 'remove' }) + evictNotebookFromCaches({ queryClient, projectRef: ref, id: notebookId }) }, confirmClose: (notebookTabs) => { const dirtyCount = notebookTabs.filter((tab) => { diff --git a/apps/studio/components/interfaces/Explorer/__tests__/ExplorerNotebookTab.assistant-cache-invalidation.test.tsx b/apps/studio/components/interfaces/Explorer/__tests__/ExplorerNotebookTab.assistant-cache-invalidation.test.tsx new file mode 100644 index 00000000000..6762874a9b9 --- /dev/null +++ b/apps/studio/components/interfaces/Explorer/__tests__/ExplorerNotebookTab.assistant-cache-invalidation.test.tsx @@ -0,0 +1,176 @@ +import { QueryClient } from '@tanstack/react-query' +import { screen } from '@testing-library/react' +import { HttpResponse } from 'msw' +import { describe, expect, it, vi } from 'vitest' + +import { ExplorerNotebookTab } from '../ExplorerNotebookTab' +import type { components } from '@/data/api' +import { contentKeys } from '@/data/content/keys' +import { + applyNotebookCacheEffects, + collectNotebookCacheEffects, +} from '@/lib/ai/notebook-cache-invalidation' +import { createAssistantMessageWithUpdateNotebookTool } from '@/lib/ai/test-fixtures' +import { notebooksState } from '@/state/notebooks/notebooks-state' +import type { Notebook } from '@/state/notebooks/types' +import { createTabsState, TabsStateContext } from '@/state/tabs' +import { customRender } from '@/tests/lib/custom-render' +import { addAPIMock } from '@/tests/lib/msw' +import { setupSqlEditorMocks } from '@/tests/lib/sql-editor-test-utils' + +const PROJECT_REF = 'default' +const NOTEBOOK_ID = 'notebook-assistant-cache-test' + +vi.mock('common', async (importOriginal) => { + const actual = await importOriginal() + return { + ...actual, + IS_PLATFORM: true, + useParams: () => ({ ref: 'default', id: 'notebook-assistant-cache-test' }), + useFlag: () => false, + } +}) + +vi.mock('@/components/ui/CodeEditor/CodeEditor', () => ({ + CodeEditor: ({ value }: { value: string }) => ( +