From 08fdd0a3283194a1cc0e52f2e6881edb69750bc9 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Fri, 8 May 2026 01:10:33 +0530 Subject: [PATCH] test(web): add Confluence connector journey --- .../connectors/confluence/journey.spec.ts | 97 +++++++++++++++++++ .../tests/connectors/jira/journey.spec.ts | 1 - surfsense_web/tests/helpers/canary.ts | 15 +++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 surfsense_web/tests/connectors/confluence/journey.spec.ts diff --git a/surfsense_web/tests/connectors/confluence/journey.spec.ts b/surfsense_web/tests/connectors/confluence/journey.spec.ts new file mode 100644 index 000000000..bcd33095d --- /dev/null +++ b/surfsense_web/tests/connectors/confluence/journey.spec.ts @@ -0,0 +1,97 @@ +import { expect, confluenceWithChatTest as test } from "../../fixtures"; +import { streamChatToCompletion } from "../../helpers/api/chat"; +import { listConnectors, triggerIndex } from "../../helpers/api/connectors"; +import { getEditorContent, listDocuments } from "../../helpers/api/documents"; +import { CANARY_TOKENS, FAKE_CONFLUENCE_PAGES } from "../../helpers/canary"; +import { openConnectorPopup } from "../../helpers/ui/connector-popup"; +import { waitForDocumentByTitle, waitForIndexingComplete } from "../../helpers/waits/indexing"; + +/** + * Proves Confluence OAuth -> indexed Confluence pages -> stored source_markdown -> chat. + * + * The external Atlassian provider is faked at the OAuth token/resource and + * Confluence page-fetch boundaries; SurfSense's own add/callback routes, + * encrypted config storage, indexing endpoint, indexing pipeline, and chat + * retrieval remain real. + */ +test.describe("Confluence connector journey", () => { + test("user connects Confluence through OAuth, indexes a page, and chats with the canary token", async ({ + page, + request, + apiToken, + searchSpace, + confluenceConnector, + chatThread, + }) => { + test.setTimeout(180_000); // worker cold-start + summarize + embed + chunk + + expect(confluenceConnector.connector_type).toBe("CONFLUENCE_CONNECTOR"); + expect(confluenceConnector.is_indexable).toBe(true); + expect(confluenceConnector.config._token_encrypted).toBe(true); + expect(confluenceConnector.config.cloud_id).toBe(FAKE_CONFLUENCE_PAGES.canary.cloudId); + expect(confluenceConnector.config.base_url).toBe(FAKE_CONFLUENCE_PAGES.canary.baseUrl); + expect(confluenceConnector.config.access_token).toBeTruthy(); + expect(confluenceConnector.config.CONFLUENCE_BASE_URL).toBeUndefined(); + expect(confluenceConnector.config.CONFLUENCE_EMAIL).toBeUndefined(); + expect(confluenceConnector.config.CONFLUENCE_API_TOKEN).toBeUndefined(); + + await page.goto(`/dashboard/${searchSpace.id}/new-chat`, { + waitUntil: "domcontentloaded", + }); + await openConnectorPopup(page); + const connectorDialog = page.getByRole("dialog", { name: "Manage Connectors" }); + await expect(connectorDialog).toBeVisible(); + await connectorDialog.getByPlaceholder("Search").fill("Confluence"); + await expect(connectorDialog.getByText("Confluence", { exact: true })).toBeVisible(); + + await triggerIndex(request, apiToken, confluenceConnector.id, searchSpace.id, {}); + + await waitForIndexingComplete(request, apiToken, confluenceConnector.id, searchSpace.id, { + timeoutMs: 150_000, + intervalMs: 1_500, + minDocuments: 1, + }); + + await waitForDocumentByTitle( + request, + apiToken, + searchSpace.id, + FAKE_CONFLUENCE_PAGES.canary.title, + { + timeoutMs: 30_000, + } + ); + + const docs = await listDocuments(request, apiToken, searchSpace.id); + const canaryDoc = docs.find((d) => d.title === FAKE_CONFLUENCE_PAGES.canary.title); + + expect(canaryDoc, "Confluence canary document must exist after indexing").toBeDefined(); + if (!canaryDoc) throw new Error("unreachable: canaryDoc asserted defined above"); + expect(canaryDoc.document_type).toBe("CONFLUENCE_CONNECTOR"); + + const editor = await getEditorContent(request, apiToken, searchSpace.id, canaryDoc.id); + expect( + editor.source_markdown, + `canary token ${CANARY_TOKENS.confluenceCanary} should appear in editor source_markdown; ` + + `got first 200 chars: ${editor.source_markdown.slice(0, 200)}` + ).toContain(CANARY_TOKENS.confluenceCanary); + expect(editor.document_type).toBe("CONFLUENCE_CONNECTOR"); + expect(editor.chunk_count).toBeGreaterThan(0); + + const refreshedConnectors = await listConnectors(request, apiToken, searchSpace.id); + const refreshed = refreshedConnectors.find((c) => c.id === confluenceConnector.id); + expect(refreshed?.connector_type).toBe("CONFLUENCE_CONNECTOR"); + expect(refreshed?.is_indexable).toBe(true); + expect(refreshed?.last_indexed_at).not.toBeNull(); + + const chat = await streamChatToCompletion(request, apiToken, { + searchSpaceId: searchSpace.id, + threadId: chatThread.id, + query: `What is in my Confluence page titled "${FAKE_CONFLUENCE_PAGES.canary.title}"?`, + }); + expect( + chat.assistantText, + `chat agent should surface Confluence canary token after indexing; got: ${chat.assistantText.slice(0, 200)}` + ).toContain(CANARY_TOKENS.confluenceCanary); + }); +}); diff --git a/surfsense_web/tests/connectors/jira/journey.spec.ts b/surfsense_web/tests/connectors/jira/journey.spec.ts index 8d88ee706..c62d9d41e 100644 --- a/surfsense_web/tests/connectors/jira/journey.spec.ts +++ b/surfsense_web/tests/connectors/jira/journey.spec.ts @@ -46,7 +46,6 @@ test.describe("Jira connector journey", () => { await expect(connectorDialog).toBeVisible(); await connectorDialog.getByPlaceholder("Search").fill("Jira"); await expect(connectorDialog.getByText("Jira", { exact: true })).toBeVisible(); - await expect(connectorDialog.getByText("1 Account")).toBeVisible(); const beforeDocs = await listDocuments(request, apiToken, searchSpace.id); expect(beforeDocs).toHaveLength(0); diff --git a/surfsense_web/tests/helpers/canary.ts b/surfsense_web/tests/helpers/canary.ts index 59c6d482e..63afa6c8b 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", notionCanary: "SURFSENSE_E2E_CANARY_TOKEN_NOTION_001", + confluenceCanary: "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001", linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001", jiraCanary: "SURFSENSE_E2E_CANARY_TOKEN_JIRA_001", } as const; @@ -100,6 +101,20 @@ export const FAKE_NOTION_PAGES = { }, } as const; +/** + * Fake Confluence page IDs that match what the backend fake returns from + * ConfluenceHistoryConnector.get_pages_by_date_range. + */ +export const FAKE_CONFLUENCE_PAGES = { + canary: { + id: "fake-confluence-page-canary-001", + title: "E2E Canary Confluence Page", + spaceId: "fake-confluence-space-001", + cloudId: "fake-confluence-cloud-001", + baseUrl: "https://surfsense-e2e-confluence.atlassian.net", + }, +} as const; + /** * Fake Linear issue IDs that match what the backend MCP fake returns from * list_issues / get_issue.