merge: integrate dhk-dev into dhk-1
This commit is contained in:
commit
08ce3dda73
106 files changed
+11921
-910
No files matched your search
@@ -5,11 +5,15 @@
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from io import BytesIO
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from fastapi import UploadFile
|
||||
|
||||
from app.gateway.routers.ai_writing import _extract_sample_text
|
||||
from deerflow.agents.ai_writing.nodes import researcher as R
|
||||
from deerflow.agents.ai_writing.nodes import sample_analyzer as S
|
||||
from deerflow.agents.ai_writing.search import get_search_provider
|
||||
from deerflow.agents.ai_writing.search.base import SearchResult
|
||||
from deerflow.agents.ai_writing.search.intranet_stub import IntranetSearchProvider
|
||||
@@ -82,10 +86,10 @@ def _patch(monkeypatch, intranet_url="http://es/api", intranet_cls=_FakeIntranet
|
||||
monkeypatch.setattr(R, "safe_get_stream_writer", lambda: (lambda *a, **k: None))
|
||||
monkeypatch.setattr(R, "use_skill_search_agent", lambda: False)
|
||||
|
||||
async def fake_llm_json(*a, **k):
|
||||
async def fake_stream_llm_json(*a, **k):
|
||||
return {"keywords": ["特朗普竞选"]}
|
||||
|
||||
monkeypatch.setattr(R, "llm_json", fake_llm_json)
|
||||
monkeypatch.setattr(R, "_stream_llm_json", fake_stream_llm_json)
|
||||
# knowledge_base 模式不该加载/编排技能,但仍打桩以防意外路径
|
||||
monkeypatch.setattr(R, "_load_configured_skills",
|
||||
lambda: [SimpleNamespace(name="knowledge-search-v2", description="内网检索")])
|
||||
@@ -158,6 +162,78 @@ async def test_knowledge_base_does_not_orchestrate_skills(monkeypatch):
|
||||
assert out["material_package"]["materials"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sample_analyzer_skips_normal_mode():
|
||||
out = await S.sample_analyzer_node({"writing_mode_type": "normal"}, {"configurable": {}})
|
||||
|
||||
assert out == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sample_analyzer_builds_style_profile(monkeypatch):
|
||||
async def fake_stream_sample_analysis(*_args, **_kwargs):
|
||||
return {
|
||||
"summary": "短段落、评论式表达",
|
||||
"tone": "克制、坚定",
|
||||
"structure": ["先提出问题", "再分层论证"],
|
||||
"language_features": ["多用判断句"],
|
||||
"sentence_style": "短句为主",
|
||||
"opening_style": "开门见山",
|
||||
"ending_style": "总结升华",
|
||||
"imitation_guidance": ["保持评论式节奏"],
|
||||
"avoid_copying": ["不要照抄原句"],
|
||||
"sample_outline": ["问题提出", "原因分析"],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(S, "_stream_sample_analysis", fake_stream_sample_analysis)
|
||||
|
||||
out = await S.sample_analyzer_node({
|
||||
"writing_mode_type": "imitate",
|
||||
"sample_text": "这是样文第一段。\n\n这是样文第二段。",
|
||||
"sample_filename": "demo.md",
|
||||
"user_intent": "写一篇新文章",
|
||||
}, {"configurable": {"model_name": "m1"}})
|
||||
|
||||
assert out["status"] == "researching"
|
||||
assert out["sample_style_profile"]["summary"] == "短段落、评论式表达"
|
||||
assert out["sample_style_profile"]["tone"] == "克制、坚定"
|
||||
assert any(e["type"] == "sample_profile_ready" for e in out["progress_events"])
|
||||
|
||||
|
||||
def test_render_sample_style_section_contains_copy_guardrails():
|
||||
section = S.render_sample_style_section({
|
||||
"writing_mode_type": "imitate",
|
||||
"imitate_strength": "strong",
|
||||
"preserve_sample_structure": True,
|
||||
"sample_style_profile": {
|
||||
"summary": "评论体",
|
||||
"tone": "正式",
|
||||
"structure": ["开头提出问题"],
|
||||
"language_features": ["短句"],
|
||||
"sentence_style": "长短句结合",
|
||||
"opening_style": "开门见山",
|
||||
"ending_style": "总结",
|
||||
"imitation_guidance": ["保留节奏"],
|
||||
"avoid_copying": ["不要照抄"],
|
||||
"sample_outline": ["引入", "展开"],
|
||||
},
|
||||
})
|
||||
|
||||
assert "样文仿写要求" in section
|
||||
assert "不得连续照抄样文原句" in section
|
||||
assert "评论体" in section
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_extract_sample_text_reads_txt_upload():
|
||||
upload = UploadFile(file=BytesIO(" 样文内容 ".encode("utf-8")), filename="sample.txt")
|
||||
|
||||
name, text = await _extract_sample_text(upload)
|
||||
|
||||
assert name == "sample.txt"
|
||||
assert text == "样文内容"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_knowledge_base_empty_result_is_visible(monkeypatch):
|
||||
"""接口成功但 0 条也要在返回里能看出来,而不是只显示"无素材"。"""
|
||||
|
||||
Reference in new issue
Block a user