mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-12 09:12:40 +02:00
test(e2e): add Slack connector Playwright journey
This commit is contained in:
parent
73b6375688
commit
029f2168b3
5 changed files with 191 additions and 0 deletions
86
surfsense_web/tests/connectors/slack/journey.spec.ts
Normal file
86
surfsense_web/tests/connectors/slack/journey.spec.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
import { expect, slackWithChatTest 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_SLACK_CHANNELS } from "../../helpers/canary";
|
||||||
|
import { openConnectorPopup } from "../../helpers/ui/connector-popup";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proves Slack MCP OAuth -> live MCP tool discovery/call -> chat.
|
||||||
|
*
|
||||||
|
* Slack is live-tool only: the public indexing route returns
|
||||||
|
* indexing_started=false and chat should call Slack MCP tools.
|
||||||
|
*/
|
||||||
|
test.describe("Slack connector journey", () => {
|
||||||
|
test("user connects Slack and chats through live MCP tools with indexing disabled", async ({
|
||||||
|
page,
|
||||||
|
request,
|
||||||
|
apiToken,
|
||||||
|
searchSpace,
|
||||||
|
slackConnector,
|
||||||
|
chatThread,
|
||||||
|
}) => {
|
||||||
|
test.setTimeout(90_000); // worker cold-start + live tool chat
|
||||||
|
|
||||||
|
expect(slackConnector.connector_type).toBe("SLACK_CONNECTOR");
|
||||||
|
expect(slackConnector.is_indexable).toBe(false);
|
||||||
|
expect(slackConnector.config._token_encrypted).toBe(true);
|
||||||
|
expect(slackConnector.config.mcp_service).toBe("slack");
|
||||||
|
expect(slackConnector.config.server_config).toMatchObject({
|
||||||
|
transport: "streamable-http",
|
||||||
|
url: "https://mcp.slack.com/mcp",
|
||||||
|
});
|
||||||
|
expect(slackConnector.config.mcp_oauth).toMatchObject({
|
||||||
|
client_id: "fake-slack-mcp-client-id",
|
||||||
|
token_endpoint: "https://slack.com/api/oauth.v2.user.access",
|
||||||
|
});
|
||||||
|
expect((slackConnector.config.mcp_oauth as Record<string, unknown>).access_token).toBeTruthy();
|
||||||
|
expect(slackConnector.config.access_token).toBeUndefined();
|
||||||
|
expect(slackConnector.config.refresh_token).toBeUndefined();
|
||||||
|
expect(slackConnector.config.team_id).toBe(FAKE_SLACK_CHANNELS.canary.teamId);
|
||||||
|
expect(slackConnector.config.team_name).toBe(FAKE_SLACK_CHANNELS.canary.teamName);
|
||||||
|
|
||||||
|
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("Slack");
|
||||||
|
await expect(connectorDialog.getByText("Slack", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
const beforeDocs = await listDocuments(request, apiToken, searchSpace.id);
|
||||||
|
expect(beforeDocs).toHaveLength(0);
|
||||||
|
|
||||||
|
const disabledIndex = await triggerIndexExpectDisabled(
|
||||||
|
request,
|
||||||
|
apiToken,
|
||||||
|
slackConnector.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 Slack channel "${FAKE_SLACK_CHANNELS.canary.name}"?`,
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
chat.assistantText,
|
||||||
|
`chat agent should surface Slack canary token from live MCP tools; got: ${chat.assistantText.slice(0, 200)}`
|
||||||
|
).toContain(CANARY_TOKENS.slackCanary);
|
||||||
|
|
||||||
|
const eventText = JSON.stringify(chat.events);
|
||||||
|
expect(eventText).toContain("slack_search_channels");
|
||||||
|
|
||||||
|
const refreshedConnectors = await listConnectors(request, apiToken, searchSpace.id);
|
||||||
|
const refreshed = refreshedConnectors.find((c) => c.id === slackConnector.id);
|
||||||
|
expect(refreshed?.connector_type).toBe("SLACK_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);
|
||||||
|
});
|
||||||
|
});
|
||||||
28
surfsense_web/tests/fixtures/connectors/slack.fixture.ts
vendored
Normal file
28
surfsense_web/tests/fixtures/connectors/slack.fixture.ts
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { type ConnectorRow, deleteConnector, runSlackOAuth } from "../../helpers/api/connectors";
|
||||||
|
import { searchSpaceFixtures } from "../search-space.fixture";
|
||||||
|
|
||||||
|
export type SlackFixtures = {
|
||||||
|
/**
|
||||||
|
* A pre-connected Slack connector inside the fixture's `searchSpace`.
|
||||||
|
* OAuth and MCP tool calls use E2E Slack fakes and are cleaned up
|
||||||
|
* automatically after the test.
|
||||||
|
*/
|
||||||
|
slackConnector: ConnectorRow;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const slackFixtures = searchSpaceFixtures.extend<SlackFixtures>({
|
||||||
|
slackConnector: async ({ request, apiToken, searchSpace }, use) => {
|
||||||
|
const { connector } = await runSlackOAuth(request, apiToken, searchSpace.id);
|
||||||
|
if (!connector) {
|
||||||
|
throw new Error(
|
||||||
|
"slackConnector fixture: OAuth completed but no SLACK_CONNECTOR was created. " +
|
||||||
|
"Check the backend log — the Slack MCP fake likely rejected an unmodelled call."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await use(connector);
|
||||||
|
} finally {
|
||||||
|
await deleteConnector(request, apiToken, connector.id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
8
surfsense_web/tests/fixtures/index.ts
vendored
8
surfsense_web/tests/fixtures/index.ts
vendored
|
|
@ -28,6 +28,8 @@
|
||||||
* └─ linearWithChatTest — chatThread
|
* └─ linearWithChatTest — chatThread
|
||||||
* └─ jiraFixtures — jiraConnector
|
* └─ jiraFixtures — jiraConnector
|
||||||
* └─ jiraWithChatTest — chatThread
|
* └─ jiraWithChatTest — chatThread
|
||||||
|
* └─ slackFixtures — slackConnector
|
||||||
|
* └─ slackWithChatTest — chatThread
|
||||||
*
|
*
|
||||||
* To add a new connector (Gmail, Slack, manual upload, etc.):
|
* To add a new connector (Gmail, Slack, manual upload, etc.):
|
||||||
* 1. Add a fixture file under `fixtures/connectors/<name>.fixture.ts`.
|
* 1. Add a fixture file under `fixtures/connectors/<name>.fixture.ts`.
|
||||||
|
|
@ -47,6 +49,7 @@ export { nativeDriveFixtures } from "./connectors/native-drive.fixture";
|
||||||
export { nativeGmailFixtures } from "./connectors/native-gmail.fixture";
|
export { nativeGmailFixtures } from "./connectors/native-gmail.fixture";
|
||||||
export { notionFixtures } from "./connectors/notion.fixture";
|
export { notionFixtures } from "./connectors/notion.fixture";
|
||||||
export { searchSpaceFixtures } from "./search-space.fixture";
|
export { searchSpaceFixtures } from "./search-space.fixture";
|
||||||
|
export { slackFixtures } from "./connectors/slack.fixture";
|
||||||
|
|
||||||
import { type ChatThreadFixtures, chatThreadFixtures } from "./chat-thread.fixture";
|
import { type ChatThreadFixtures, chatThreadFixtures } from "./chat-thread.fixture";
|
||||||
import { composioCalendarFixtures } from "./connectors/composio-calendar.fixture";
|
import { composioCalendarFixtures } from "./connectors/composio-calendar.fixture";
|
||||||
|
|
@ -60,6 +63,7 @@ import { nativeDriveFixtures } from "./connectors/native-drive.fixture";
|
||||||
import { nativeGmailFixtures } from "./connectors/native-gmail.fixture";
|
import { nativeGmailFixtures } from "./connectors/native-gmail.fixture";
|
||||||
import { notionFixtures } from "./connectors/notion.fixture";
|
import { notionFixtures } from "./connectors/notion.fixture";
|
||||||
import { searchSpaceFixtures } from "./search-space.fixture";
|
import { searchSpaceFixtures } from "./search-space.fixture";
|
||||||
|
import { slackFixtures } from "./connectors/slack.fixture";
|
||||||
|
|
||||||
/** Default `test` for specs that just need auth + a clean search space. */
|
/** Default `test` for specs that just need auth + a clean search space. */
|
||||||
export const test = searchSpaceFixtures;
|
export const test = searchSpaceFixtures;
|
||||||
|
|
@ -110,3 +114,7 @@ export const linearWithChatTest = linearFixtures.extend<ChatThreadFixtures>(chat
|
||||||
export const jiraTest = jiraFixtures;
|
export const jiraTest = jiraFixtures;
|
||||||
/** `test` for Jira specs that also need a chat thread. */
|
/** `test` for Jira specs that also need a chat thread. */
|
||||||
export const jiraWithChatTest = jiraFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
|
export const jiraWithChatTest = jiraFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
|
||||||
|
/** `test` for specs that also need a pre-connected Slack connector. */
|
||||||
|
export const slackTest = slackFixtures;
|
||||||
|
/** `test` for Slack specs that also need a chat thread. */
|
||||||
|
export const slackWithChatTest = slackFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
|
||||||
|
|
|
||||||
|
|
@ -542,3 +542,58 @@ export async function runJiraOAuth(
|
||||||
|
|
||||||
return { authUrl: auth_url, finalUrl: location, connector };
|
return { authUrl: auth_url, finalUrl: location, connector };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drives the Slack MCP OAuth flow programmatically.
|
||||||
|
*
|
||||||
|
* The E2E backend keeps SurfSense's generic MCP OAuth routes real and
|
||||||
|
* patches Slack's external discovery/token/MCP tool boundaries.
|
||||||
|
*/
|
||||||
|
export async function runSlackOAuth(
|
||||||
|
request: APIRequestContext,
|
||||||
|
token: string,
|
||||||
|
searchSpaceId: number
|
||||||
|
): Promise<{
|
||||||
|
authUrl: string;
|
||||||
|
finalUrl: string;
|
||||||
|
connector: ConnectorRow | null;
|
||||||
|
}> {
|
||||||
|
const initiateResp = await request.get(
|
||||||
|
`${BACKEND_URL}/api/v1/auth/mcp/slack/connector/add?space_id=${searchSpaceId}`,
|
||||||
|
{ headers: authHeaders(token) }
|
||||||
|
);
|
||||||
|
if (!initiateResp.ok()) {
|
||||||
|
throw new Error(
|
||||||
|
`Slack MCP initiate failed (${initiateResp.status()}): ${await initiateResp.text()}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { auth_url } = (await initiateResp.json()) as { auth_url: string };
|
||||||
|
if (!auth_url) {
|
||||||
|
throw new Error("Slack MCP initiate response missing auth_url");
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = new URL(auth_url).searchParams.get("state");
|
||||||
|
if (!state) {
|
||||||
|
throw new Error(`Slack MCP auth_url missing state: ${auth_url}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const callbackResp = await request.get(
|
||||||
|
`${BACKEND_URL}/api/v1/auth/mcp/slack/connector/callback?code=fake-slack-oauth-code&state=${encodeURIComponent(state)}`,
|
||||||
|
{
|
||||||
|
headers: authHeaders(token),
|
||||||
|
maxRedirects: 0,
|
||||||
|
failOnStatusCode: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (callbackResp.status() >= 400) {
|
||||||
|
throw new Error(
|
||||||
|
`Slack MCP 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 === "SLACK_CONNECTOR") ?? null;
|
||||||
|
|
||||||
|
return { authUrl: auth_url, finalUrl: location, connector };
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ export const CANARY_TOKENS = {
|
||||||
confluenceCanary: "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001",
|
confluenceCanary: "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001",
|
||||||
linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001",
|
linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001",
|
||||||
jiraCanary: "SURFSENSE_E2E_CANARY_TOKEN_JIRA_001",
|
jiraCanary: "SURFSENSE_E2E_CANARY_TOKEN_JIRA_001",
|
||||||
|
slackCanary: "SURFSENSE_E2E_CANARY_TOKEN_SLACK_001",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -143,6 +144,19 @@ export const FAKE_JIRA_ISSUES = {
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake Slack channel IDs that match what the backend MCP fake returns from
|
||||||
|
* slack_search_channels.
|
||||||
|
*/
|
||||||
|
export const FAKE_SLACK_CHANNELS = {
|
||||||
|
canary: {
|
||||||
|
id: "C_FAKE_SLACK_CANARY",
|
||||||
|
name: "slack-e2e-canary",
|
||||||
|
teamId: "T_FAKE_SLACK_TEAM",
|
||||||
|
teamName: "SurfSense E2E Slack Workspace",
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
/** Generate a unique-per-run search space name. Keeps parallel tests isolated. */
|
/** Generate a unique-per-run search space name. Keeps parallel tests isolated. */
|
||||||
export function uniqueSearchSpaceName(prefix = "e2e"): string {
|
export function uniqueSearchSpaceName(prefix = "e2e"): string {
|
||||||
return `${prefix}-${randomUUID().slice(0, 8)}`;
|
return `${prefix}-${randomUUID().slice(0, 8)}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue