sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
@@ -2,6 +2,7 @@ import json
|
||||
import logging
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
@@ -154,6 +155,7 @@ def test_es_query_routing_registration_log_explains_custom_agent_exclusion(caplo
|
||||
def test_formal_markdown_rules_are_scoped_to_ordinary_qa(monkeypatch) -> None:
|
||||
config = _app_config(enabled=False)
|
||||
monkeypatch.setattr(prompt_module, "_ordinary_qa_markdown_format_enabled", lambda: True)
|
||||
monkeypatch.setattr(prompt_module, "_word_heading_numbering_style", lambda: "hybrid_decimal")
|
||||
monkeypatch.setattr(prompt_module, "_get_memory_context", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "get_agent_soul", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "get_skills_prompt_section", lambda *args, **kwargs: "")
|
||||
@@ -169,15 +171,35 @@ def test_formal_markdown_rules_are_scoped_to_ordinary_qa(monkeypatch) -> None:
|
||||
|
||||
assert '<ordinary_qa_markdown_format>' in ordinary_prompt
|
||||
assert "## 一、标题" in ordinary_prompt
|
||||
assert "### (一) 标题" in ordinary_prompt
|
||||
assert "#### 1. 标题" in ordinary_prompt
|
||||
assert "2.1.1" in ordinary_prompt
|
||||
assert "### 1.1 标题" in ordinary_prompt
|
||||
assert "#### 1.1.1 标题" in ordinary_prompt
|
||||
assert "##### 1.1.1.1 标题" in ordinary_prompt
|
||||
assert "###### 1.1.1.1.1 标题" in ordinary_prompt
|
||||
assert "2.1" in ordinary_prompt
|
||||
assert "无序圆点列表" in ordinary_prompt
|
||||
assert '<ordinary_qa_markdown_format>' not in writing_prompt
|
||||
assert '<ordinary_qa_markdown_format>' not in notebook_prompt
|
||||
assert '<ordinary_qa_markdown_format>' not in scheduled_prompt
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("style", "expected"),
|
||||
[
|
||||
("hybrid_decimal", "### 1.1 标题"),
|
||||
("official_chinese", "### (一) 标题"),
|
||||
("decimal", "## 1 标题"),
|
||||
("chapter_section", "### 第一节 标题"),
|
||||
("none", "### 二级标题"),
|
||||
],
|
||||
)
|
||||
def test_formal_markdown_rules_follow_word_numbering_style(monkeypatch, style: str, expected: str) -> None:
|
||||
monkeypatch.setattr(prompt_module, "_word_heading_numbering_style", lambda: style)
|
||||
|
||||
section = prompt_module._build_ordinary_qa_markdown_format_section()
|
||||
|
||||
assert expected in section
|
||||
|
||||
|
||||
def test_formal_markdown_rules_are_disabled_when_switch_is_off(monkeypatch) -> None:
|
||||
config = _app_config(enabled=False)
|
||||
monkeypatch.setattr(prompt_module, "_ordinary_qa_markdown_format_enabled", lambda: False)
|
||||
@@ -227,6 +249,13 @@ def test_message_visualization_rules_are_offline_safe_and_scoped_to_ordinary_qa(
|
||||
assert "flow-json" not in ordinary_prompt
|
||||
assert "chart-json" not in ordinary_prompt
|
||||
assert "禁止在地图数据中放入 URL" in ordinary_prompt
|
||||
assert "不要用 `from`/`to`/`coords`" in ordinary_prompt
|
||||
assert '"coordinates":[[116.4,39.9],[121.47,31.23]]' in ordinary_prompt
|
||||
assert '"color":"red"' in ordinary_prompt
|
||||
assert '"arrow":true' in ordinary_prompt
|
||||
assert '"flow":true' in ordinary_prompt
|
||||
assert "只有用户**明确要求**连线" in ordinary_prompt
|
||||
assert "`lines` 必须为 `[]`" in ordinary_prompt
|
||||
assert "map-json" not in writing_prompt
|
||||
assert "map-json" not in notebook_prompt
|
||||
assert "map-json" not in scheduled_prompt
|
||||
@@ -244,6 +273,7 @@ def test_html_artifact_visualizations_use_local_declarative_contracts(monkeypatc
|
||||
monkeypatch.setattr(prompt_module, "_build_acp_section", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "_build_custom_mounts_section", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "_current_time_context", lambda: "")
|
||||
monkeypatch.setattr("deerflow.html_runtime.map_engine.html_map_engine", lambda: "echarts")
|
||||
|
||||
ordinary_prompt = prompt_module.apply_prompt_template(app_config=config)
|
||||
writing_prompt = prompt_module.apply_prompt_template(app_config=config, writing_mode=True)
|
||||
@@ -255,6 +285,7 @@ def test_html_artifact_visualizations_use_local_declarative_contracts(monkeypatc
|
||||
assert "普通地图请求必须在消息列表中使用 `map-json`" in ordinary_prompt
|
||||
assert 'data-df-flow="process-flow"' in ordinary_prompt
|
||||
assert "流程图不要使用 Mermaid" in ordinary_prompt
|
||||
assert "流程图所在 `.page` 初始隐藏时,运行时会等容器可见后再初始化" in ordinary_prompt
|
||||
assert "AntV G6" in ordinary_prompt
|
||||
assert 'data-df-chart="sales-chart"' in ordinary_prompt
|
||||
assert 'data-df-geo="area-map"' in ordinary_prompt
|
||||
@@ -298,6 +329,27 @@ def test_html_artifact_visualizations_use_local_declarative_contracts(monkeypatc
|
||||
assert '<html_artifact_visualization>' not in writing_prompt
|
||||
|
||||
|
||||
def test_html_map_webpage_setting_switches_the_map_contract(monkeypatch) -> None:
|
||||
config = _app_config(enabled=False)
|
||||
monkeypatch.setattr(prompt_module, "_get_memory_context", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "get_agent_soul", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "get_skills_prompt_section", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "get_deferred_tools_prompt_section", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "_build_acp_section", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "_build_custom_mounts_section", lambda *args, **kwargs: "")
|
||||
monkeypatch.setattr(prompt_module, "_current_time_context", lambda: "")
|
||||
monkeypatch.setattr("deerflow.html_runtime.map_engine.html_map_engine", lambda: "leaflet")
|
||||
|
||||
ordinary_prompt = prompt_module.apply_prompt_template(app_config=config)
|
||||
|
||||
assert 'data-df-map="area-map"' in ordinary_prompt
|
||||
assert "/api/public/html-runtime/leaflet.js" in ordinary_prompt
|
||||
assert "/api/public/html-runtime/leaflet.css" in ordinary_prompt
|
||||
assert "地图网页" in ordinary_prompt
|
||||
assert "禁止 `data-df-geo`" in ordinary_prompt
|
||||
assert "禁止 Leaflet、`data-df-map`" not in ordinary_prompt
|
||||
|
||||
|
||||
def test_markdown_file_deliverable_is_scoped_to_ordinary_qa(monkeypatch) -> None:
|
||||
config = _app_config(enabled=False)
|
||||
monkeypatch.setattr(prompt_module, "_get_memory_context", lambda *args, **kwargs: "")
|
||||
@@ -322,12 +374,13 @@ def test_markdown_file_deliverable_is_scoped_to_ordinary_qa(monkeypatch) -> None
|
||||
def test_html_runtime_exposes_only_local_geojson_maps(monkeypatch) -> None:
|
||||
monkeypatch.setattr(
|
||||
html_runtime,
|
||||
"get_app_config",
|
||||
lambda: SimpleNamespace(
|
||||
html_runtime=SimpleNamespace(
|
||||
base_url="http://gateway.internal/api/public/html-runtime"
|
||||
)
|
||||
),
|
||||
"html_runtime_base_url",
|
||||
lambda: "http://gateway.internal/api/public/html-runtime",
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
html_runtime,
|
||||
"html_map_tile_url",
|
||||
lambda: "https://mt0.google.com/vt/lyrs=m&hl=zh-CN&x={x}&y={y}&z={z}",
|
||||
)
|
||||
app = FastAPI()
|
||||
app.include_router(html_runtime.router)
|
||||
@@ -338,8 +391,11 @@ def test_html_runtime_exposes_only_local_geojson_maps(monkeypatch) -> None:
|
||||
assert "data-df-geo" in runtime.text
|
||||
assert "df-geo-popup" in runtime.text
|
||||
assert "deerflow:geo-map-click" in runtime.text
|
||||
assert "mapTileUrl" not in runtime.text
|
||||
assert client.get("/api/public/html-runtime/leaflet.js").status_code == 404
|
||||
assert "mapTileUrl" in runtime.text
|
||||
assert "https://mt0.google.com/vt/lyrs=m" in runtime.text
|
||||
assert "data-df-map" in runtime.text
|
||||
assert client.get("/api/public/html-runtime/leaflet.js").status_code == 200
|
||||
assert client.get("/api/public/html-runtime/leaflet.css").status_code == 200
|
||||
for filename, media_type in (
|
||||
("bootstrap.min.css", "text/css"),
|
||||
("bootstrap.bundle.min.js", "application/javascript"),
|
||||
@@ -400,6 +456,36 @@ def test_page_quality_rejects_manual_flow_and_accepts_g6_contract() -> None:
|
||||
assert compliant["ok"] is True
|
||||
|
||||
|
||||
def test_page_quality_accepts_g6_flow_on_hidden_logical_page() -> None:
|
||||
scripts = (
|
||||
'<link rel="stylesheet" href="bootstrap.min.css">'
|
||||
'<script defer src="alpine.min.js"></script>'
|
||||
'<script defer src="bootstrap.bundle.min.js"></script>'
|
||||
'<script src="g6.min.js"></script><script src="deerflow-runtime.js"></script>'
|
||||
)
|
||||
report = _quality_report(
|
||||
_report_html(
|
||||
'<style>.page{display:none}.page.active{display:block}</style>'
|
||||
'<nav><a href="#page-overview">概览</a><a href="#page-flow">流程</a></nav>'
|
||||
'<main class="pages">'
|
||||
'<section class="page active" id="page-overview" data-page="overview">概览正文</section>'
|
||||
'<section class="page" id="page-flow" data-page="flow">'
|
||||
'<div id="tech-flow" class="df-flow" style="height:400px"></div>'
|
||||
'<script type="application/json" data-df-flow="tech-flow">'
|
||||
'{"direction":"LR","nodes":[{"id":"a","label":"开始","type":"start"},'
|
||||
'{"id":"b","label":"结束","type":"end"}],'
|
||||
'"edges":[{"source":"a","target":"b"}]}</script>'
|
||||
"</section></main>",
|
||||
scripts,
|
||||
),
|
||||
data_mode="provided",
|
||||
expected_features={"flowchart"},
|
||||
expected_page_count=2,
|
||||
)
|
||||
|
||||
assert report["ok"] is True
|
||||
|
||||
|
||||
def test_page_quality_checks_chart_and_map_runtime_contracts() -> None:
|
||||
report = _quality_report(
|
||||
_report_html("<h2>销售图表与城市地图</h2>"),
|
||||
|
||||
Reference in new issue
Block a user