deer-flow/frontend/tests/e2e/web-search-results.spec.ts
yong 8547666a31
feat(search): add DeepSeek web search with configurable thinking (#8299)
* feat(search): add DeepSeek web search with configurable thinking

* fix(search): drain DeepSeek teardown and retain citation spans

Reuse the cancellation-safe context helper so repeated cancellation cannot interrupt HTTP transport cleanup. Preserve validated Unicode citation ranges on retained public sources so the agent can associate claims with their supporting pages. Add regressions for cancellation, timeout, normal completion, invalid ranges, URL screening, and result limits.

* fix(search): preserve DeepSeek citation excerpts through guardrails

* fix(search): share DeepSeek citation excerpts across sources

Group each validated answer range once and associate it with response-local source IDs after URL filtering and result limits. Preserve full-answer PII redaction and existing source-card fields, document the model-facing citation mapping, and repair live-test configuration for both thinking modes. Add HTTP transport, guardrail/budget, attribution, and browser reload regressions.

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-11-18 21:19:41 +08:00

104 lines
3.0 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { mockLangGraphAPI } from "./utils/mock-api";
for (const shape of [
"array",
"webz",
"webz-malformed",
"deepseek-citations",
] as const) {
test(`search source links from ${shape} results survive reload`, async ({
page,
}) => {
const threadId = "00000000-0000-0000-0000-000000005880";
const results: unknown[] = [
{
title: "Renewable energy news",
url: "https://example.com/news",
content: "Matching passage",
published_at: "2026-09-20T12:00:00Z",
source: { domain: "example.com", language: "english", country: "US" },
},
];
if (shape === "webz-malformed") {
results.unshift(null, {
title: { text: "Invalid title" },
url: "https://example.com/invalid",
});
results.push({ title: "Invalid URL", url: 42 });
}
if (shape === "deepseek-citations") {
results[0] = {
source_id: 1,
title: "Renewable energy news",
url: "https://example.com/news",
snippet: "Matching passage",
};
}
const payload =
shape === "array"
? results
: shape === "deepseek-citations"
? {
query: "renewable energy",
total_results: results.length,
results,
answer: "Matching passage",
citations: [{ excerpt: "Matching passage", source_ids: [1] }],
truncated: false,
}
: {
query: "renewable energy",
returned_results: results.length,
results,
};
mockLangGraphAPI(page, {
threads: [
{
thread_id: threadId,
title: "News research",
messages: [
{ type: "human", id: "human", content: "Find recent energy news" },
{
type: "ai",
id: "ai-search",
content: "",
tool_calls: [
{
id: "search-5880",
name: "web_search",
args: { query: "renewable energy" },
},
],
},
{
type: "tool",
id: "search-result",
tool_call_id: "search-5880",
name: "web_search",
content: JSON.stringify(payload),
},
{
type: "ai",
id: "answer",
content: "The news search is complete.",
},
],
},
],
});
await page.goto(`/workspace/chats/${threadId}`);
const link = page.getByRole("link", {
name: "Renewable energy news",
exact: true,
});
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("href", "https://example.com/news");
await expect(link).toHaveAttribute("rel", "noopener noreferrer");
await page.reload();
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("href", "https://example.com/news");
});
}