From 7303e3ebb32b28ce560872492d298c344158329e Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Fri, 8 May 2026 12:28:26 +0530 Subject: [PATCH] test(e2e): wire Dropbox Playwright fixtures --- surfsense_backend/tests/e2e/fakes/chat_llm.py | 35 ++++++++++++ .../connectors/native-dropbox.fixture.ts | 32 +++++++++++ surfsense_web/tests/fixtures/index.ts | 13 ++++- surfsense_web/tests/helpers/api/connectors.ts | 56 +++++++++++++++++++ surfsense_web/tests/helpers/canary.ts | 13 +++++ 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 surfsense_web/tests/fixtures/connectors/native-dropbox.fixture.ts diff --git a/surfsense_backend/tests/e2e/fakes/chat_llm.py b/surfsense_backend/tests/e2e/fakes/chat_llm.py index 5f38b3b65..acfc0e77a 100644 --- a/surfsense_backend/tests/e2e/fakes/chat_llm.py +++ b/surfsense_backend/tests/e2e/fakes/chat_llm.py @@ -20,6 +20,8 @@ CALENDAR_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_CALENDAR_001" CALENDAR_CANARY_SUMMARY = "E2E Canary Calendar Event" ONEDRIVE_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_ONEDRIVE_001" ONEDRIVE_CANARY_FILE = "e2e-onedrive-canary.txt" +DROPBOX_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_DROPBOX_001" +DROPBOX_CANARY_FILE = "e2e-dropbox-canary.txt" NOTION_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_NOTION_001" NOTION_CANARY_TITLE = "E2E Canary Notion Page" CONFLUENCE_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001" @@ -137,6 +139,10 @@ class FakeChatLLM(BaseChatModel): latest_human, ("onedrive", ONEDRIVE_CANARY_FILE, ONEDRIVE_CANARY_TOKEN), ) + wants_dropbox = _contains_any( + latest_human, + ("dropbox", DROPBOX_CANARY_FILE, DROPBOX_CANARY_TOKEN), + ) wants_notion = _contains_any( latest_human, ("notion", "page", NOTION_CANARY_TITLE), @@ -183,6 +189,11 @@ class FakeChatLLM(BaseChatModel): or "fake-onedrive-canary" in prompt_text or ONEDRIVE_CANARY_TOKEN in prompt_text ) + has_dropbox_evidence = ( + DROPBOX_CANARY_FILE in prompt_text + or "id:fake-dropbox-canary" in prompt_text + or DROPBOX_CANARY_TOKEN in prompt_text + ) has_notion_evidence = ( NOTION_CANARY_TITLE in prompt_text or NOTION_CANARY_TOKEN in prompt_text ) @@ -228,6 +239,8 @@ class FakeChatLLM(BaseChatModel): return f"Gmail content found: {GMAIL_CANARY_TOKEN}" if wants_onedrive and has_onedrive_evidence: return f"OneDrive content found: {ONEDRIVE_CANARY_TOKEN}" + if wants_dropbox and has_dropbox_evidence: + return f"Dropbox content found: {DROPBOX_CANARY_TOKEN}" if wants_drive and has_drive_evidence: return f"Drive content found: {DRIVE_CANARY_TOKEN}" if ( @@ -239,6 +252,7 @@ class FakeChatLLM(BaseChatModel): and not has_gmail_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Notion content found: {NOTION_CANARY_TOKEN}" @@ -251,6 +265,7 @@ class FakeChatLLM(BaseChatModel): and not has_gmail_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Confluence content found: {CONFLUENCE_CANARY_TOKEN}" @@ -263,6 +278,7 @@ class FakeChatLLM(BaseChatModel): and not has_gmail_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Jira content found: {JIRA_CANARY_TOKEN}" @@ -275,6 +291,7 @@ class FakeChatLLM(BaseChatModel): and not has_gmail_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Linear content found: {LINEAR_CANARY_TOKEN}" @@ -287,6 +304,7 @@ class FakeChatLLM(BaseChatModel): and not has_gmail_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Calendar content found: {CALENDAR_CANARY_TOKEN}" @@ -298,6 +316,7 @@ class FakeChatLLM(BaseChatModel): and not has_notion_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Gmail content found: {GMAIL_CANARY_TOKEN}" @@ -310,9 +329,23 @@ class FakeChatLLM(BaseChatModel): and not has_calendar_evidence and not has_gmail_evidence and not has_drive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"OneDrive content found: {ONEDRIVE_CANARY_TOKEN}" + if ( + has_dropbox_evidence + and not has_confluence_evidence + and not has_jira_evidence + and not has_linear_evidence + and not has_notion_evidence + and not has_calendar_evidence + and not has_gmail_evidence + and not has_drive_evidence + and not has_onedrive_evidence + and not has_slack_evidence + ): + return f"Dropbox content found: {DROPBOX_CANARY_TOKEN}" if ( has_drive_evidence and not has_confluence_evidence @@ -321,6 +354,7 @@ class FakeChatLLM(BaseChatModel): and not has_notion_evidence and not has_gmail_evidence and not has_onedrive_evidence + and not has_dropbox_evidence and not has_slack_evidence ): return f"Drive content found: {DRIVE_CANARY_TOKEN}" @@ -334,6 +368,7 @@ class FakeChatLLM(BaseChatModel): and not has_gmail_evidence and not has_drive_evidence and not has_onedrive_evidence + and not has_dropbox_evidence ): return f"Slack content found: {SLACK_CANARY_TOKEN}" return NO_RELEVANT_CONTENT_SENTINEL diff --git a/surfsense_web/tests/fixtures/connectors/native-dropbox.fixture.ts b/surfsense_web/tests/fixtures/connectors/native-dropbox.fixture.ts new file mode 100644 index 000000000..aa6945acf --- /dev/null +++ b/surfsense_web/tests/fixtures/connectors/native-dropbox.fixture.ts @@ -0,0 +1,32 @@ +import { + type ConnectorRow, + deleteConnector, + runNativeDropboxOAuth, +} from "../../helpers/api/connectors"; +import { searchSpaceFixtures } from "../search-space.fixture"; + +export type NativeDropboxFixtures = { + /** + * A pre-connected native Dropbox connector inside the fixture's + * `searchSpace`. OAuth uses E2E Dropbox fakes and is cleaned up + * automatically after the test. + */ + nativeDropboxConnector: ConnectorRow; +}; + +export const nativeDropboxFixtures = searchSpaceFixtures.extend({ + nativeDropboxConnector: async ({ request, apiToken, searchSpace }, use) => { + const { connector } = await runNativeDropboxOAuth(request, apiToken, searchSpace.id); + if (!connector) { + throw new Error( + "nativeDropboxConnector fixture: OAuth completed but no DROPBOX_CONNECTOR was created. " + + "Check the backend log — the Dropbox fake likely rejected an unmodelled call." + ); + } + try { + await use(connector); + } finally { + await deleteConnector(request, apiToken, connector.id); + } + }, +}); diff --git a/surfsense_web/tests/fixtures/index.ts b/surfsense_web/tests/fixtures/index.ts index e1099762c..de3913c15 100644 --- a/surfsense_web/tests/fixtures/index.ts +++ b/surfsense_web/tests/fixtures/index.ts @@ -22,6 +22,8 @@ * └─ nativeCalendarWithChatTest — chatThread * └─ nativeOneDriveFixtures — nativeOneDriveConnector * └─ nativeOneDriveWithChatTest — chatThread + * └─ nativeDropboxFixtures — nativeDropboxConnector + * └─ nativeDropboxWithChatTest — chatThread * └─ notionFixtures — notionConnector * └─ notionWithChatTest — chatThread * └─ confluenceFixtures — confluenceConnector @@ -48,11 +50,12 @@ export { jiraFixtures } from "./connectors/jira.fixture"; export { linearFixtures } from "./connectors/linear.fixture"; export { nativeCalendarFixtures } from "./connectors/native-calendar.fixture"; export { nativeDriveFixtures } from "./connectors/native-drive.fixture"; +export { nativeDropboxFixtures } from "./connectors/native-dropbox.fixture"; export { nativeGmailFixtures } from "./connectors/native-gmail.fixture"; export { nativeOneDriveFixtures } from "./connectors/native-onedrive.fixture"; export { notionFixtures } from "./connectors/notion.fixture"; -export { searchSpaceFixtures } from "./search-space.fixture"; export { slackFixtures } from "./connectors/slack.fixture"; +export { searchSpaceFixtures } from "./search-space.fixture"; import { type ChatThreadFixtures, chatThreadFixtures } from "./chat-thread.fixture"; import { composioCalendarFixtures } from "./connectors/composio-calendar.fixture"; @@ -63,11 +66,12 @@ import { jiraFixtures } from "./connectors/jira.fixture"; import { linearFixtures } from "./connectors/linear.fixture"; import { nativeCalendarFixtures } from "./connectors/native-calendar.fixture"; import { nativeDriveFixtures } from "./connectors/native-drive.fixture"; +import { nativeDropboxFixtures } from "./connectors/native-dropbox.fixture"; import { nativeGmailFixtures } from "./connectors/native-gmail.fixture"; import { nativeOneDriveFixtures } from "./connectors/native-onedrive.fixture"; import { notionFixtures } from "./connectors/notion.fixture"; -import { searchSpaceFixtures } from "./search-space.fixture"; import { slackFixtures } from "./connectors/slack.fixture"; +import { searchSpaceFixtures } from "./search-space.fixture"; /** Default `test` for specs that just need auth + a clean search space. */ export const test = searchSpaceFixtures; @@ -106,6 +110,11 @@ export const nativeOneDriveTest = nativeOneDriveFixtures; /** `test` for native OneDrive specs that also need a chat thread. */ export const nativeOneDriveWithChatTest = nativeOneDriveFixtures.extend(chatThreadFixtures); +/** `test` for specs that also need a pre-connected native Dropbox connector. */ +export const nativeDropboxTest = nativeDropboxFixtures; +/** `test` for native Dropbox specs that also need a chat thread. */ +export const nativeDropboxWithChatTest = + nativeDropboxFixtures.extend(chatThreadFixtures); /** `test` for specs that also need a pre-connected Notion connector. */ export const notionTest = notionFixtures; /** `test` for Notion specs that also need a chat thread. */ diff --git a/surfsense_web/tests/helpers/api/connectors.ts b/surfsense_web/tests/helpers/api/connectors.ts index a638d18b6..9f0e1e31c 100644 --- a/surfsense_web/tests/helpers/api/connectors.ts +++ b/surfsense_web/tests/helpers/api/connectors.ts @@ -312,6 +312,62 @@ export async function runNativeOneDriveOAuth( return { authUrl: auth_url, finalUrl: location, connector }; } +/** + * Drives the native Dropbox OAuth flow programmatically. + * + * The Dropbox authorization URL is off-origin, so the helper extracts the + * signed state and calls the backend callback directly. The E2E backend fakes + * Dropbox's token and account HTTP responses inside that callback. + */ +export async function runNativeDropboxOAuth( + request: APIRequestContext, + token: string, + searchSpaceId: number +): Promise<{ + authUrl: string; + finalUrl: string; + connector: ConnectorRow | null; +}> { + const initiateResp = await request.get( + `${BACKEND_URL}/api/v1/auth/dropbox/connector/add?space_id=${searchSpaceId}`, + { headers: authHeaders(token) } + ); + if (!initiateResp.ok()) { + throw new Error( + `native Dropbox initiate failed (${initiateResp.status()}): ${await initiateResp.text()}` + ); + } + const { auth_url } = (await initiateResp.json()) as { auth_url: string }; + if (!auth_url) { + throw new Error("native Dropbox initiate response missing auth_url"); + } + + const state = new URL(auth_url).searchParams.get("state"); + if (!state) { + throw new Error(`native Dropbox auth_url missing state: ${auth_url}`); + } + + const callbackResp = await request.get( + `${BACKEND_URL}/api/v1/auth/dropbox/connector/callback?code=fake-dropbox-oauth-code&state=${encodeURIComponent(state)}`, + { + headers: authHeaders(token), + maxRedirects: 0, + failOnStatusCode: false, + } + ); + if (callbackResp.status() >= 400) { + throw new Error( + `native Dropbox callback failed (${callbackResp.status()}): ${await callbackResp.text()}` + ); + } + const location = callbackResp.headers().location ?? auth_url; + + const connectors = await listConnectors(request, token, searchSpaceId); + const connector = connectors.find((c) => c.connector_type === "DROPBOX_CONNECTOR") ?? null; + + return { authUrl: auth_url, finalUrl: location, connector }; +} + /** * Drives the native Google Gmail OAuth flow programmatically. * diff --git a/surfsense_web/tests/helpers/canary.ts b/surfsense_web/tests/helpers/canary.ts index 82c41f339..167cd94d9 100644 --- a/surfsense_web/tests/helpers/canary.ts +++ b/surfsense_web/tests/helpers/canary.ts @@ -21,6 +21,7 @@ export const CANARY_TOKENS = { gmailCanary: "SURFSENSE_E2E_CANARY_TOKEN_GMAIL_001", calendarCanary: "SURFSENSE_E2E_CANARY_TOKEN_CALENDAR_001", onedriveCanary: "SURFSENSE_E2E_CANARY_TOKEN_ONEDRIVE_001", + dropboxCanary: "SURFSENSE_E2E_CANARY_TOKEN_DROPBOX_001", notionCanary: "SURFSENSE_E2E_CANARY_TOKEN_NOTION_001", confluenceCanary: "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001", linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001", @@ -63,6 +64,18 @@ export const FAKE_ONEDRIVE_FILES = { }, } as const; +/** + * Fake Dropbox file paths that match the Dropbox-shaped backend fake in + * dropbox_files.json. Dropbox selected-file indexing accepts path_lower via id. + */ +export const FAKE_DROPBOX_FILES = { + canary: { + id: "/e2e-dropbox-canary.txt", + name: "e2e-dropbox-canary.txt", + mimeType: "text/plain", + }, +} as const; + /** * Fake Gmail message IDs that match what the backend fake returns from * GMAIL_FETCH_EMAILS / GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID.