sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
@@ -14,6 +14,7 @@ from app.gateway.routers import system_settings as ss_router
|
||||
from app.gateway.services import _prepend_prompt_prefix, _prompt_prefix_opted_in
|
||||
from deerflow.agents.lead_agent import prompt as prompt_module
|
||||
from deerflow.config import system_settings as ss
|
||||
from deerflow.sandbox.prompt_policy import get_agent_runtime_policy, get_python_dependency_policy
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -36,6 +37,8 @@ def test_load_returns_defaults_when_missing(tmp_runtime_home: Path) -> None:
|
||||
assert settings.citation_display.reference_mode_enabled is False
|
||||
assert settings.citation_display.cleanup_words == []
|
||||
assert settings.memory.enabled is False
|
||||
assert settings.conversation_context.recent_turn_window_enabled is False
|
||||
assert settings.conversation_context.max_conversation_rounds == 20
|
||||
assert settings.write_file_compatibility.enabled is False
|
||||
assert settings.conversation_context.recent_turn_window_enabled is False
|
||||
|
||||
@@ -94,6 +97,69 @@ def _patch_admin(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(ss_router, "get_optional_user_from_request", _optional)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dependency_delete_prompt_toggle_roundtrip(tmp_runtime_home, monkeypatch):
|
||||
_patch_admin(monkeypatch)
|
||||
assert get_python_dependency_policy() == ""
|
||||
for enabled in (True, False):
|
||||
response = await ss_router.update_prompt_prefix(
|
||||
ss_router.PromptPrefixUpdateRequest(python_dependency_delete_protection_enabled=enabled),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert response.python_dependency_delete_protection_enabled is enabled
|
||||
assert ss.load_system_settings().prompt_prefix.python_dependency_delete_protection_enabled is enabled
|
||||
assert response.enabled is False # Independent of the first-question prefix switch.
|
||||
policy = get_python_dependency_policy()
|
||||
assert bool(policy) is enabled
|
||||
if enabled:
|
||||
assert "允许安装、升级、降级" in policy
|
||||
assert "允许包管理器" in policy
|
||||
assert "不得执行独立的" in policy
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("field", ["python_dependency_delete_protection_enabled", "image_generation_unavailable_hint_enabled"])
|
||||
async def test_nonadmin_cannot_enable_runtime_prompt(tmp_runtime_home, monkeypatch, field):
|
||||
async def ordinary_user(_request):
|
||||
return SimpleNamespace(system_role="user")
|
||||
|
||||
monkeypatch.setattr(ss_router, "get_optional_user_from_request", ordinary_user)
|
||||
with pytest.raises(HTTPException) as error:
|
||||
await ss_router.update_prompt_prefix(
|
||||
ss_router.PromptPrefixUpdateRequest(**{field: True}),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert error.value.status_code == 403
|
||||
assert get_python_dependency_policy() == ""
|
||||
assert get_agent_runtime_policy() == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_image_generation_hint_independent_toggle(tmp_runtime_home, monkeypatch):
|
||||
_patch_admin(monkeypatch)
|
||||
assert get_agent_runtime_policy() == ""
|
||||
await ss_router.update_prompt_prefix(
|
||||
ss_router.PromptPrefixUpdateRequest(python_dependency_delete_protection_enabled=True),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
for enabled in (True, False):
|
||||
response = await ss_router.update_prompt_prefix(
|
||||
ss_router.PromptPrefixUpdateRequest(image_generation_unavailable_hint_enabled=enabled),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert response.image_generation_unavailable_hint_enabled is enabled
|
||||
assert response.python_dependency_delete_protection_enabled is True
|
||||
assert response.enabled is False
|
||||
assert ss.load_system_settings().prompt_prefix.image_generation_unavailable_hint_enabled is enabled
|
||||
policy = get_agent_runtime_policy()
|
||||
assert "<python_dependency_boundary>" in policy
|
||||
assert ("<image_generation_unavailable>" in policy) is enabled
|
||||
if enabled:
|
||||
assert "当前服务暂不支持生成或编辑图片" in policy
|
||||
assert "此限制不影响" in policy
|
||||
assert "绘图提示词" in policy
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_prompt_settings_update_can_enable_markdown_format_without_changing_prefix(
|
||||
tmp_runtime_home: Path,
|
||||
@@ -166,28 +232,6 @@ async def test_admin_can_enable_memory_runtime_switch(
|
||||
assert ss.load_system_settings().memory.enabled is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_can_toggle_write_file_compatibility_without_restart(
|
||||
tmp_runtime_home: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
_patch_admin(monkeypatch)
|
||||
|
||||
enabled = await ss_router.update_write_file_compatibility_setting(
|
||||
ss_router.WriteFileCompatibilityUpdateRequest(enabled=True),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert enabled.enabled is True
|
||||
assert ss.get_write_file_compatibility_settings().enabled is True
|
||||
|
||||
disabled = await ss_router.update_write_file_compatibility_setting(
|
||||
ss_router.WriteFileCompatibilityUpdateRequest(enabled=False),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert disabled.enabled is False
|
||||
assert ss.get_write_file_compatibility_settings().enabled is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_can_enable_recent_turn_context_window(
|
||||
tmp_runtime_home: Path,
|
||||
@@ -202,9 +246,42 @@ async def test_admin_can_enable_recent_turn_context_window(
|
||||
|
||||
assert response.recent_turn_window_enabled is True
|
||||
assert response.recent_turns == 3
|
||||
assert response.max_conversation_rounds == 20
|
||||
assert ss.load_system_settings().conversation_context.recent_turn_window_enabled is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_can_update_conversation_round_limit_without_changing_window(
|
||||
tmp_runtime_home: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
_patch_admin(monkeypatch)
|
||||
ss.save_system_settings(
|
||||
ss.SystemSettings(
|
||||
conversation_context=ss.ConversationContextSettings(
|
||||
recent_turn_window_enabled=True,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
response = await ss_router.update_conversation_context_setting(
|
||||
ss_router.ConversationContextUpdateRequest(max_conversation_rounds=45),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
|
||||
assert response.max_conversation_rounds == 45
|
||||
assert response.recent_turn_window_enabled is True
|
||||
persisted = ss.load_system_settings().conversation_context
|
||||
assert persisted.max_conversation_rounds == 45
|
||||
assert persisted.recent_turn_window_enabled is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [0, 51])
|
||||
def test_conversation_round_limit_rejects_out_of_range_values(value: int) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
ss_router.ConversationContextUpdateRequest(max_conversation_rounds=value)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_non_admin_cannot_enable_recent_turn_context_window(
|
||||
tmp_runtime_home: Path,
|
||||
@@ -226,6 +303,28 @@ async def test_non_admin_cannot_enable_recent_turn_context_window(
|
||||
assert exc_info.value.status_code == 403
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_can_toggle_write_file_compatibility_without_restart(
|
||||
tmp_runtime_home: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
_patch_admin(monkeypatch)
|
||||
|
||||
enabled = await ss_router.update_write_file_compatibility_setting(
|
||||
ss_router.WriteFileCompatibilityUpdateRequest(enabled=True),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert enabled.enabled is True
|
||||
assert ss.get_write_file_compatibility_settings().enabled is True
|
||||
|
||||
disabled = await ss_router.update_write_file_compatibility_setting(
|
||||
ss_router.WriteFileCompatibilityUpdateRequest(enabled=False),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
assert disabled.enabled is False
|
||||
assert ss.get_write_file_compatibility_settings().enabled is False
|
||||
|
||||
|
||||
def test_prepend_prefix_tags_first_human_without_touching_content() -> None:
|
||||
graph_input = {"messages": [HumanMessage(content="评价一下中美贸易")]}
|
||||
out = _prepend_prompt_prefix(graph_input, "你需要站在中方角度")
|
||||
|
||||
Reference in new issue
Block a user