mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-13 17:52:38 +02:00
test(e2e): cover connector PDF docling indexing in journeys
This commit is contained in:
parent
fbfde74cdc
commit
66eebf614f
4 changed files with 251 additions and 138 deletions
|
|
@ -1,17 +1,10 @@
|
|||
import { expect, nativeOneDriveWithChatTest as test } from "../../fixtures";
|
||||
import { streamChatToCompletion } from "../../helpers/api/chat";
|
||||
import {
|
||||
listConnectors,
|
||||
triggerIndex,
|
||||
updateConnectorConfig,
|
||||
} from "../../helpers/api/connectors";
|
||||
import { listConnectors, triggerIndex, updateConnectorConfig } from "../../helpers/api/connectors";
|
||||
import { getEditorContent, listDocuments } from "../../helpers/api/documents";
|
||||
import { CANARY_TOKENS, FAKE_ONEDRIVE_FILES } from "../../helpers/canary";
|
||||
import { openConnectorPopup } from "../../helpers/ui/connector-popup";
|
||||
import {
|
||||
waitForDocumentByTitle,
|
||||
waitForIndexingComplete,
|
||||
} from "../../helpers/waits/indexing";
|
||||
import { waitForDocumentByTitle, waitForIndexingComplete } from "../../helpers/waits/indexing";
|
||||
|
||||
/**
|
||||
* Proves the native OneDrive wiring from Microsoft OAuth fixture -> selection
|
||||
|
|
@ -21,109 +14,132 @@ import {
|
|||
* persisted config and indexing contract the picker ultimately feeds.
|
||||
*/
|
||||
test.describe("Native OneDrive journey", () => {
|
||||
test(
|
||||
"user connects OneDrive, selects a file, indexes it, and chats with the canary token",
|
||||
async ({
|
||||
page,
|
||||
test("user connects OneDrive, selects a file, indexes it, and chats with the canary token", async ({
|
||||
page,
|
||||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
nativeOneDriveConnector,
|
||||
chatThread,
|
||||
}) => {
|
||||
test.setTimeout(240_000); // worker cold-start + Docling + summarize + embed + chunk
|
||||
|
||||
expect(nativeOneDriveConnector.connector_type).toBe("ONEDRIVE_CONNECTOR");
|
||||
expect(nativeOneDriveConnector.is_indexable).toBe(true);
|
||||
expect(nativeOneDriveConnector.config._token_encrypted).toBe(true);
|
||||
expect(nativeOneDriveConnector.config.composio_connected_account_id).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();
|
||||
|
||||
const selectedFiles = [
|
||||
{
|
||||
id: FAKE_ONEDRIVE_FILES.canary.id,
|
||||
name: FAKE_ONEDRIVE_FILES.canary.name,
|
||||
mimeType: FAKE_ONEDRIVE_FILES.canary.mimeType,
|
||||
},
|
||||
{
|
||||
id: FAKE_ONEDRIVE_FILES.pdf.id,
|
||||
name: FAKE_ONEDRIVE_FILES.pdf.name,
|
||||
mimeType: FAKE_ONEDRIVE_FILES.pdf.mimeType,
|
||||
},
|
||||
];
|
||||
// Keep the shared Drive-style body shape. OneDrive currently defaults
|
||||
// these internally because the indexer expects max_files/use_delta_sync.
|
||||
const indexingOptions = {
|
||||
max_files_per_folder: 10,
|
||||
incremental_sync: false,
|
||||
include_subfolders: false,
|
||||
};
|
||||
|
||||
await updateConnectorConfig(request, apiToken, nativeOneDriveConnector.id, {
|
||||
...nativeOneDriveConnector.config,
|
||||
selected_folders: [],
|
||||
selected_files: selectedFiles,
|
||||
indexing_options: indexingOptions,
|
||||
});
|
||||
|
||||
await triggerIndex(request, apiToken, nativeOneDriveConnector.id, searchSpace.id, {
|
||||
files: selectedFiles,
|
||||
indexing_options: indexingOptions,
|
||||
});
|
||||
|
||||
await waitForIndexingComplete(request, apiToken, nativeOneDriveConnector.id, searchSpace.id, {
|
||||
timeoutMs: 240_000,
|
||||
intervalMs: 1_500,
|
||||
minDocuments: 2,
|
||||
});
|
||||
|
||||
await waitForDocumentByTitle(
|
||||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
nativeOneDriveConnector,
|
||||
chatThread,
|
||||
}) => {
|
||||
test.setTimeout(180_000); // worker cold-start + summarize + embed + chunk
|
||||
searchSpace.id,
|
||||
FAKE_ONEDRIVE_FILES.canary.name,
|
||||
{ timeoutMs: 30_000 }
|
||||
);
|
||||
await waitForDocumentByTitle(request, apiToken, searchSpace.id, FAKE_ONEDRIVE_FILES.pdf.name, {
|
||||
timeoutMs: 60_000,
|
||||
});
|
||||
|
||||
expect(nativeOneDriveConnector.connector_type).toBe("ONEDRIVE_CONNECTOR");
|
||||
expect(nativeOneDriveConnector.is_indexable).toBe(true);
|
||||
expect(nativeOneDriveConnector.config._token_encrypted).toBe(true);
|
||||
expect(nativeOneDriveConnector.config.composio_connected_account_id).toBeUndefined();
|
||||
const docs = await listDocuments(request, apiToken, searchSpace.id);
|
||||
const canaryDoc = docs.find((d) => d.title === FAKE_ONEDRIVE_FILES.canary.name);
|
||||
const pdfDoc = docs.find((d) => d.title === FAKE_ONEDRIVE_FILES.pdf.name);
|
||||
|
||||
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();
|
||||
expect(canaryDoc, "OneDrive canary document must exist after indexing").toBeDefined();
|
||||
if (!canaryDoc) throw new Error("unreachable: canaryDoc asserted defined above");
|
||||
expect(canaryDoc.document_type).toBe("ONEDRIVE_FILE");
|
||||
expect(pdfDoc, "OneDrive PDF document must exist after indexing").toBeDefined();
|
||||
if (!pdfDoc) throw new Error("unreachable: pdfDoc asserted defined above");
|
||||
expect(pdfDoc.document_type).toBe("ONEDRIVE_FILE");
|
||||
|
||||
const selectedFiles = [
|
||||
{
|
||||
id: FAKE_ONEDRIVE_FILES.canary.id,
|
||||
name: FAKE_ONEDRIVE_FILES.canary.name,
|
||||
mimeType: FAKE_ONEDRIVE_FILES.canary.mimeType,
|
||||
},
|
||||
];
|
||||
// Keep the shared Drive-style body shape. OneDrive currently defaults
|
||||
// these internally because the indexer expects max_files/use_delta_sync.
|
||||
const indexingOptions = {
|
||||
max_files_per_folder: 10,
|
||||
incremental_sync: false,
|
||||
include_subfolders: false,
|
||||
};
|
||||
const editor = await getEditorContent(request, apiToken, searchSpace.id, canaryDoc.id);
|
||||
expect(
|
||||
editor.source_markdown,
|
||||
`canary token ${CANARY_TOKENS.onedriveCanary} should appear in editor source_markdown; ` +
|
||||
`got first 200 chars: ${editor.source_markdown.slice(0, 200)}`
|
||||
).toContain(CANARY_TOKENS.onedriveCanary);
|
||||
expect(editor.document_type).toBe("ONEDRIVE_FILE");
|
||||
expect(editor.chunk_count).toBeGreaterThan(0);
|
||||
|
||||
await updateConnectorConfig(request, apiToken, nativeOneDriveConnector.id, {
|
||||
...nativeOneDriveConnector.config,
|
||||
selected_folders: [],
|
||||
selected_files: selectedFiles,
|
||||
indexing_options: indexingOptions,
|
||||
});
|
||||
const pdfEditor = await getEditorContent(request, apiToken, searchSpace.id, pdfDoc.id);
|
||||
expect(
|
||||
pdfEditor.source_markdown,
|
||||
`PDF canary token ${CANARY_TOKENS.onedrivePdfCanary} should appear in editor source_markdown; ` +
|
||||
`got first 200 chars: ${pdfEditor.source_markdown.slice(0, 200)}`
|
||||
).toContain(CANARY_TOKENS.onedrivePdfCanary);
|
||||
expect(pdfEditor.document_type).toBe("ONEDRIVE_FILE");
|
||||
expect(pdfEditor.chunk_count).toBeGreaterThan(0);
|
||||
|
||||
await triggerIndex(request, apiToken, nativeOneDriveConnector.id, searchSpace.id, {
|
||||
files: selectedFiles,
|
||||
indexing_options: indexingOptions,
|
||||
});
|
||||
const refreshedConnectors = await listConnectors(request, apiToken, searchSpace.id);
|
||||
const refreshed = refreshedConnectors.find((c) => c.id === nativeOneDriveConnector.id);
|
||||
expect(refreshed?.connector_type).toBe("ONEDRIVE_CONNECTOR");
|
||||
expect(refreshed?.is_indexable).toBe(true);
|
||||
expect(refreshed?.last_indexed_at).not.toBeNull();
|
||||
|
||||
await waitForIndexingComplete(
|
||||
request,
|
||||
apiToken,
|
||||
nativeOneDriveConnector.id,
|
||||
searchSpace.id,
|
||||
{
|
||||
timeoutMs: 150_000,
|
||||
intervalMs: 1_500,
|
||||
minDocuments: 1,
|
||||
}
|
||||
);
|
||||
const chat = await streamChatToCompletion(request, apiToken, {
|
||||
searchSpaceId: searchSpace.id,
|
||||
threadId: chatThread.id,
|
||||
query: "What is in my e2e-onedrive-canary.txt OneDrive file?",
|
||||
});
|
||||
expect(
|
||||
chat.assistantText,
|
||||
"chat agent should surface OneDrive canary token after indexing; " +
|
||||
`got: ${chat.assistantText.slice(0, 200)}`
|
||||
).toContain(CANARY_TOKENS.onedriveCanary);
|
||||
|
||||
await waitForDocumentByTitle(
|
||||
request,
|
||||
apiToken,
|
||||
searchSpace.id,
|
||||
FAKE_ONEDRIVE_FILES.canary.name,
|
||||
{ timeoutMs: 30_000 }
|
||||
);
|
||||
|
||||
const docs = await listDocuments(request, apiToken, searchSpace.id);
|
||||
const canaryDoc = docs.find((d) => d.title === FAKE_ONEDRIVE_FILES.canary.name);
|
||||
|
||||
expect(canaryDoc, "OneDrive canary document must exist after indexing").toBeDefined();
|
||||
if (!canaryDoc) throw new Error("unreachable: canaryDoc asserted defined above");
|
||||
expect(canaryDoc.document_type).toBe("ONEDRIVE_FILE");
|
||||
|
||||
const editor = await getEditorContent(request, apiToken, searchSpace.id, canaryDoc.id);
|
||||
expect(
|
||||
editor.source_markdown,
|
||||
`canary token ${CANARY_TOKENS.onedriveCanary} should appear in editor source_markdown; ` +
|
||||
`got first 200 chars: ${editor.source_markdown.slice(0, 200)}`
|
||||
).toContain(CANARY_TOKENS.onedriveCanary);
|
||||
expect(editor.document_type).toBe("ONEDRIVE_FILE");
|
||||
expect(editor.chunk_count).toBeGreaterThan(0);
|
||||
|
||||
const refreshedConnectors = await listConnectors(request, apiToken, searchSpace.id);
|
||||
const refreshed = refreshedConnectors.find((c) => c.id === nativeOneDriveConnector.id);
|
||||
expect(refreshed?.connector_type).toBe("ONEDRIVE_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 e2e-onedrive-canary.txt OneDrive file?",
|
||||
});
|
||||
expect(
|
||||
chat.assistantText,
|
||||
"chat agent should surface OneDrive canary token after indexing; " +
|
||||
`got: ${chat.assistantText.slice(0, 200)}`
|
||||
).toContain(CANARY_TOKENS.onedriveCanary);
|
||||
}
|
||||
);
|
||||
const pdfChat = await streamChatToCompletion(request, apiToken, {
|
||||
searchSpaceId: searchSpace.id,
|
||||
threadId: chatThread.id,
|
||||
query: "What is in my e2e-onedrive-canary.pdf OneDrive file?",
|
||||
});
|
||||
expect(
|
||||
pdfChat.assistantText,
|
||||
"chat agent should surface OneDrive PDF canary token after indexing; " +
|
||||
`got: ${pdfChat.assistantText.slice(0, 200)}`
|
||||
).toContain(CANARY_TOKENS.onedrivePdfCanary);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue