fix(desktop/doubao): drop byteimg and bytednsdoc CDN URLs from cited sources
These ByteDance asset CDNs ship images and static docs that are not real citations, so they pollute the monitoring source list. Filter them at both buildSourceItem and dedupe stages, and add unit coverage via an exported test-only helper bag. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { __doubaoTestUtils } from "./doubao";
|
||||
|
||||
const {
|
||||
buildSourceItem,
|
||||
dedupeSourceItems,
|
||||
isNonCitationAssetDomain,
|
||||
isNonCitationAssetUrl,
|
||||
parseDoubaoStreamBody,
|
||||
} = __doubaoTestUtils;
|
||||
|
||||
describe("doubao adapter helpers", () => {
|
||||
it("filters byteimg and bytednsdoc asset CDN links from source items", () => {
|
||||
expect(isNonCitationAssetDomain("p3-spider-image-sign.byteimg.com")).toBe(true);
|
||||
expect(isNonCitationAssetDomain("lf3-static.bytednsdoc.com")).toBe(true);
|
||||
expect(isNonCitationAssetUrl("https://p11-spider-image-sign.byteimg.com/obj/logo.png")).toBe(true);
|
||||
expect(isNonCitationAssetUrl("https://m.sohu.com/a/1012750625_122649842/")).toBe(false);
|
||||
|
||||
expect(buildSourceItem({
|
||||
url: "https://p3-spider-image-sign.byteimg.com/img/logo.jpeg",
|
||||
title: "logo",
|
||||
site_name: "byteimg.com",
|
||||
})).toBeNull();
|
||||
expect(buildSourceItem({
|
||||
url: "https://example.com/article",
|
||||
title: "真实来源",
|
||||
})).toMatchObject({
|
||||
url: "https://example.com/article",
|
||||
host: "example.com",
|
||||
});
|
||||
});
|
||||
|
||||
it("dedupes and drops asset CDN links parsed from Doubao streams", () => {
|
||||
const body = [
|
||||
"event: STREAM_CHUNK",
|
||||
"data: {\"references\":[{\"url\":\"https://p11-spider-image-sign.byteimg.com/logo.jpeg\",\"title\":\"logo\"},{\"url\":\"https://m.sohu.com/a/1012750625_122649842/\",\"title\":\"真实来源\"}],\"text_block\":{\"text\":\"回答\"}}",
|
||||
"",
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
const summary = parseDoubaoStreamBody(body);
|
||||
expect(summary.search_results).toHaveLength(1);
|
||||
expect(summary.search_results[0]?.url).toBe("https://m.sohu.com/a/1012750625_122649842/");
|
||||
|
||||
expect(dedupeSourceItems([
|
||||
{ url: "https://static.bytednsdoc.com/logo.png", normalized_url: "https://static.bytednsdoc.com/logo.png" },
|
||||
{ url: "https://example.com/a", normalized_url: "https://example.com/a" },
|
||||
])).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user