mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-12 01:02:39 +02:00
refactor(tests): simplify logging messages and enhance manual upload journey tests
This commit is contained in:
parent
66eebf614f
commit
2f540ee065
5 changed files with 117 additions and 7 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import path from "node:path";
|
||||
import type { APIRequestContext, Page } from "@playwright/test";
|
||||
import { expect, test } from "../../fixtures";
|
||||
import { expect, manualUploadWithChatTest as test } from "../../fixtures";
|
||||
import type { ChatThreadRow } from "../../fixtures/chat-thread.fixture";
|
||||
import { streamChatToCompletion } from "../../helpers/api/chat";
|
||||
import { getEditorContent, listDocuments } from "../../helpers/api/documents";
|
||||
import { CANARY_TOKENS } from "../../helpers/canary";
|
||||
import { waitForDocumentByTitle } from "../../helpers/waits/indexing";
|
||||
|
|
@ -9,6 +11,7 @@ type UploadFixture = {
|
|||
path: string;
|
||||
name: string;
|
||||
canary: string;
|
||||
chatQuery: string;
|
||||
};
|
||||
|
||||
type SearchSpace = {
|
||||
|
|
@ -19,12 +22,14 @@ const MD_FILE: UploadFixture = {
|
|||
path: path.join(__dirname, "fixtures", "canary.md"),
|
||||
name: "canary.md",
|
||||
canary: CANARY_TOKENS.manualUploadMdCanary,
|
||||
chatQuery: "What is in my uploaded canary.md markdown file?",
|
||||
};
|
||||
|
||||
const PDF_FILE: UploadFixture = {
|
||||
path: path.join(__dirname, "fixtures", "canary.pdf"),
|
||||
name: "canary.pdf",
|
||||
canary: CANARY_TOKENS.manualUploadPdfCanary,
|
||||
chatQuery: "What is in my uploaded canary.pdf file?",
|
||||
};
|
||||
|
||||
async function uploadAndAssert({
|
||||
|
|
@ -32,12 +37,14 @@ async function uploadAndAssert({
|
|||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
chatThread,
|
||||
file,
|
||||
}: {
|
||||
page: Page;
|
||||
request: APIRequestContext;
|
||||
apiToken: string;
|
||||
searchSpace: SearchSpace;
|
||||
chatThread: ChatThreadRow;
|
||||
file: UploadFixture;
|
||||
}) {
|
||||
await page.goto(`/dashboard/${searchSpace.id}/new-chat`, {
|
||||
|
|
@ -68,6 +75,16 @@ async function uploadAndAssert({
|
|||
const editor = await getEditorContent(request, apiToken, searchSpace.id, uploaded.id);
|
||||
expect(editor.source_markdown).toContain(file.canary);
|
||||
expect(editor.chunk_count).toBeGreaterThan(0);
|
||||
|
||||
const chat = await streamChatToCompletion(request, apiToken, {
|
||||
searchSpaceId: searchSpace.id,
|
||||
threadId: chatThread.id,
|
||||
query: file.chatQuery,
|
||||
});
|
||||
expect(
|
||||
chat.assistantText,
|
||||
`chat agent should surface manual upload canary after indexing; got: ${chat.assistantText.slice(0, 200)}`
|
||||
).toContain(file.canary);
|
||||
}
|
||||
|
||||
test.describe("Manual file upload journey", () => {
|
||||
|
|
@ -76,10 +93,18 @@ test.describe("Manual file upload journey", () => {
|
|||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
chatThread,
|
||||
}) => {
|
||||
test.setTimeout(180_000);
|
||||
|
||||
await uploadAndAssert({ page, request, apiToken, searchSpace, file: MD_FILE });
|
||||
await uploadAndAssert({
|
||||
page,
|
||||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
chatThread,
|
||||
file: MD_FILE,
|
||||
});
|
||||
});
|
||||
|
||||
test("user uploads a PDF (DOCUMENT branch via real Docling)", async ({
|
||||
|
|
@ -87,9 +112,17 @@ test.describe("Manual file upload journey", () => {
|
|||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
chatThread,
|
||||
}) => {
|
||||
test.setTimeout(240_000); // Docling cold-start can take 30-60s on first invocation.
|
||||
|
||||
await uploadAndAssert({ page, request, apiToken, searchSpace, file: PDF_FILE });
|
||||
await uploadAndAssert({
|
||||
page,
|
||||
request,
|
||||
apiToken,
|
||||
searchSpace,
|
||||
chatThread,
|
||||
file: PDF_FILE,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
9
surfsense_web/tests/fixtures/index.ts
vendored
9
surfsense_web/tests/fixtures/index.ts
vendored
|
|
@ -36,6 +36,7 @@
|
|||
* └─ clickupWithChatTest — chatThread
|
||||
* └─ slackFixtures — slackConnector
|
||||
* └─ slackWithChatTest — chatThread
|
||||
* └─ manualUploadWithChatTest — chatThread (no connector; uses base search space)
|
||||
*
|
||||
* To add a new connector (Gmail, Slack, manual upload, etc.):
|
||||
* 1. Add a fixture file under `fixtures/connectors/<name>.fixture.ts`.
|
||||
|
|
@ -144,3 +145,11 @@ export const clickupWithChatTest = clickupFixtures.extend<ChatThreadFixtures>(ch
|
|||
export const slackTest = slackFixtures;
|
||||
/** `test` for Slack specs that also need a chat thread. */
|
||||
export const slackWithChatTest = slackFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
|
||||
/**
|
||||
* `test` for manual upload specs that also need a chat thread.
|
||||
*
|
||||
* Manual upload has no connector fixture — the user uploads files directly via
|
||||
* the Documents-sidebar UI — so this composes chat onto the bare search-space.
|
||||
*/
|
||||
export const manualUploadWithChatTest =
|
||||
searchSpaceFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue