52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
|
|
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);
|
||
|
|
});
|
||
|
|
});
|