market-assistant/backend/pipeline/tests/test_brief_compact.py
hub-gif 6280e436d8 feat(pipeline): JD 流水线 CSV 纯中文表头与模块目录重构
- 统一 csv_schema 与搜索/合并/评价/商详导出为纯中文列名,入库与视图按中文表头解析

- 竞品分析报告兼容新旧表头;新增 csv_header_rewrite 与 rewrite_pipeline_csv_headers 管理命令

- 调整 pipeline 至 jd、llm、reporting、demos 子包并更新任务与测试引用

- 新增购买者优惠摘要抽取、合并表 regen/ingest 命令、0016 迁移及相关测试

Made-with: Cursor
2026-04-15 16:02:29 +08:00

53 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""brief_compact矩阵裁剪后仍保留 matrix_overview_for_llm。"""
from __future__ import annotations
from django.test import SimpleTestCase
from pipeline.reporting.brief_compact import (
compact_brief_for_llm,
matrix_overview_for_llm,
)
class BriefCompactTests(SimpleTestCase):
def test_matrix_overview_always_in_compact_output(self) -> None:
brief = {
"keyword": "",
"matrix_by_group": [
{
"group": "饼干",
"sku_count": 2,
"skus": [
{"brand": "A牌", "sku_id": "1"},
{"brand": "B牌", "sku_id": "2"},
],
}
],
}
out = compact_brief_for_llm(brief, max_chars=120_000)
self.assertEqual(len(out["matrix_overview_for_llm"]), 1)
self.assertEqual(out["matrix_overview_for_llm"][0]["group"], "饼干")
self.assertIn("A牌", out["matrix_overview_for_llm"][0]["distinct_brands_sample"])
def test_overview_preserved_when_matrix_omitted(self) -> None:
brief = {
"matrix_by_group": [
{
"group": f"G{i}",
"sku_count": 2,
"skus": [
{"brand": "B", "sku_id": str(j)}
for j in range(2)
],
}
for i in range(40)
],
"consumer_feedback_by_matrix_group": [],
}
out = compact_brief_for_llm(brief, max_chars=200)
self.assertTrue(out.get("matrix_by_group_omitted"))
self.assertEqual(len(out["matrix_overview_for_llm"]), 40)
def test_matrix_overview_for_llm_empty_without_matrix(self) -> None:
self.assertEqual(matrix_overview_for_llm({}), [])