diff --git a/surfsense_web/tests/connectors/linear/journey.spec.ts b/surfsense_web/tests/connectors/linear/journey.spec.ts new file mode 100644 index 000000000..df55d7a38 --- /dev/null +++ b/surfsense_web/tests/connectors/linear/journey.spec.ts @@ -0,0 +1,83 @@ +import { expect, linearWithChatTest as test } from "../../fixtures"; +import { streamChatToCompletion } from "../../helpers/api/chat"; +import { listConnectors, triggerIndexExpectDisabled } from "../../helpers/api/connectors"; +import { listDocuments } from "../../helpers/api/documents"; +import { CANARY_TOKENS, FAKE_LINEAR_ISSUES } from "../../helpers/canary"; +import { openConnectorPopup } from "../../helpers/ui/connector-popup"; + +/** + * Proves Linear MCP OAuth -> live MCP tool discovery/call -> chat. + * + * Linear is live-tool only: the public indexing route returns + * indexing_started=false and chat should call Linear MCP tools. + */ +test.describe("Linear connector journey", () => { + test("user connects Linear and chats through live MCP tools with indexing disabled", async ({ + page, + request, + apiToken, + searchSpace, + linearConnector, + chatThread, + }) => { + test.setTimeout(90_000); // worker cold-start + live tool chat + + expect(linearConnector.connector_type).toBe("LINEAR_CONNECTOR"); + expect(linearConnector.is_indexable).toBe(false); + expect(linearConnector.config._token_encrypted).toBe(true); + expect(linearConnector.config.mcp_service).toBe("linear"); + expect(linearConnector.config.server_config).toMatchObject({ + transport: "streamable-http", + url: "https://mcp.linear.app/mcp", + }); + expect(linearConnector.config.mcp_oauth).toMatchObject({ + client_id: "fake-linear-mcp-client-id", + token_endpoint: "https://mcp.linear.app/token", + }); + expect((linearConnector.config.mcp_oauth as Record).access_token).toBeTruthy(); + expect(linearConnector.config.access_token).toBeUndefined(); + expect(linearConnector.config.refresh_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 expect(connectorDialog.getByRole("button", { name: "Manage" })).toBeVisible(); + + const beforeDocs = await listDocuments(request, apiToken, searchSpace.id); + expect(beforeDocs).toHaveLength(0); + + const disabledIndex = await triggerIndexExpectDisabled( + request, + apiToken, + linearConnector.id, + searchSpace.id + ); + expect(disabledIndex.message ?? "").toContain("real-time agent tools"); + expect(disabledIndex.message ?? "").toContain("background indexing is disabled"); + + const chat = await streamChatToCompletion(request, apiToken, { + searchSpaceId: searchSpace.id, + threadId: chatThread.id, + query: `What is in my Linear issue titled "${FAKE_LINEAR_ISSUES.canary.title}"?`, + }); + expect( + chat.assistantText, + `chat agent should surface Linear canary token from live MCP tools; got: ${chat.assistantText.slice(0, 200)}` + ).toContain(CANARY_TOKENS.linearCanary); + + const eventText = JSON.stringify(chat.events); + expect(eventText).toContain("list_issues"); + + const refreshedConnectors = await listConnectors(request, apiToken, searchSpace.id); + const refreshed = refreshedConnectors.find((c) => c.id === linearConnector.id); + expect(refreshed?.connector_type).toBe("LINEAR_CONNECTOR"); + expect(refreshed?.is_indexable).toBe(false); + expect(refreshed?.last_indexed_at).toBeNull(); + + const afterDocs = await listDocuments(request, apiToken, searchSpace.id); + expect(afterDocs).toHaveLength(0); + }); +}); diff --git a/surfsense_web/tests/helpers/canary.ts b/surfsense_web/tests/helpers/canary.ts index b750b21b7..6d08c4911 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", + linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001", } as const; /** @@ -98,6 +99,20 @@ export const FAKE_NOTION_PAGES = { }, } as const; +/** + * Fake Linear issue IDs that match what the backend MCP fake returns from + * list_issues / get_issue. + */ +export const FAKE_LINEAR_ISSUES = { + canary: { + id: "fake-linear-issue-canary-001", + identifier: "E2E-101", + title: "E2E Canary Linear Issue", + organizationName: "SurfSense E2E Linear Org", + organizationUrlKey: "surfsense-e2e", + }, +} as const; + /** Generate a unique-per-run search space name. Keeps parallel tests isolated. */ export function uniqueSearchSpaceName(prefix = "e2e"): string { return `${prefix}-${randomUUID().slice(0, 8)}`;