feat: 搭建阶段 0 与阶段 1 基础工程

This commit is contained in:
2026-04-02 16:28:44 +08:00
parent 02ec7c3a03
commit a5b079a673
37 changed files with 7379 additions and 0 deletions
@@ -0,0 +1,169 @@
import { describe, expect, it } from "vitest";
import { parseReportSnapshot } from "../src/index";
describe("ReportSchema", () => {
it("accepts a valid report snapshot", () => {
const report = parseReportSnapshot({
report_id: "report-1",
report_version: 1,
task_id: "task-1",
generated_at: "2026-04-02T12:00:00.000Z",
task_status: "Completed",
summary: {
headline: "天猫样本较完整,京东待预热。",
key_points: ["天猫完成候选确认并产出报告。"],
limitations: ["京东本次未进入搜索。"]
},
product_snapshot: {
query: "iPhone 15 Pro",
normalized_product_name: "iPhone 15 Pro",
platform_count: 2,
selected_link_count: 1,
review_sample_count: 60,
analysis_time_range: {
start: "2026-04-02T11:40:00.000Z",
end: "2026-04-02T12:00:00.000Z"
}
},
platform_insights: [
{
platform: "tmall",
execution_status: "completed",
selected_link_count: 1,
price_range: { min: 7999, max: 7999 },
selling_points: [
{
card_id: "card-1",
title: "卖点稳定",
statement: "标题与详情页都突出影像能力。",
confidence: "high",
sample_flag: "sufficient",
source_scope: {
platforms: ["tmall"],
link_count: 1,
review_count: 60
},
evidence_ids: ["evidence-1"]
}
],
positive_themes: [],
negative_themes: [],
store_diff_notes: []
},
{
platform: "jd",
execution_status: "blocked",
selected_link_count: 0,
price_range: null,
selling_points: [],
positive_themes: [],
negative_themes: [],
store_diff_notes: []
}
],
cross_platform_insights: [
{
card_id: "card-2",
title: "跨平台覆盖有限",
statement: "本轮仅天猫形成可发布洞察。",
confidence: "medium",
sample_flag: "partial",
source_scope: {
platforms: ["tmall", "jd"],
link_count: 1,
review_count: 60
},
evidence_ids: ["evidence-1"]
}
],
recommendations: [
{
card_id: "card-3",
title: "优先补齐京东会话",
statement: "建议在下一次任务前先完成京东会话准备。",
confidence: "medium",
sample_flag: "partial",
source_scope: {
platforms: ["jd"],
link_count: 0,
review_count: 0
},
evidence_ids: ["evidence-1"]
}
],
evidence_index: [
{
evidence_id: "evidence-1",
platform: "tmall",
source_type: "product",
source_url: "https://example.com/tmall/iphone-15-pro",
review_ref: null,
snippet: "详情页强调 5 倍长焦与钛金属材质。",
captured_at: "2026-04-02T11:58:00.000Z"
}
],
quality_flags: {
sample_insufficient: false,
partial_platform_failure: false,
blocked_platforms: [],
failed_platforms: []
}
});
expect(report.report_version).toBe(1);
expect(report.platform_insights).toHaveLength(2);
});
it("rejects a strong insight without evidence ids", () => {
expect(() =>
parseReportSnapshot({
report_id: "report-2",
report_version: 1,
task_id: "task-2",
generated_at: "2026-04-02T12:00:00.000Z",
task_status: "Completed",
summary: {
headline: "invalid",
key_points: ["invalid"],
limitations: []
},
product_snapshot: {
query: "x",
normalized_product_name: "x",
platform_count: 1,
selected_link_count: 1,
review_sample_count: 1,
analysis_time_range: {
start: "2026-04-02T11:40:00.000Z",
end: "2026-04-02T12:00:00.000Z"
}
},
platform_insights: [],
cross_platform_insights: [
{
card_id: "card-1",
title: "缺少证据",
statement: "这里没有 evidence ids。",
confidence: "high",
sample_flag: "sufficient",
source_scope: {
platforms: ["tmall"],
link_count: 1,
review_count: 1
},
evidence_ids: []
}
],
recommendations: [],
evidence_index: [],
quality_flags: {
sample_insufficient: false,
partial_platform_failure: false,
blocked_platforms: [],
failed_platforms: []
}
})
).toThrow(/evidence_ids/i);
});
});