ci: enforce code formatting checks for backend and frontend (#1536)

This commit is contained in:
greatmengqi
2026-03-29 15:34:38 +08:00
committed by GitHub
parent 06a623f9c8
commit 084dc7e748
105 changed files with 8253 additions and 7369 deletions
+1 -4
View File
@@ -600,10 +600,7 @@ class TestChannelManager:
await manager.stop()
mock_client.runs.wait.assert_not_called()
assert outbound_received[0].text == (
"Invalid channel session assistant_id 'bad agent!'. "
"Use 'lead_agent' or a custom agent name containing only letters, digits, and hyphens."
)
assert outbound_received[0].text == ("Invalid channel session assistant_id 'bad agent!'. Use 'lead_agent' or a custom agent name containing only letters, digits, and hyphens.")
_run(go())
@@ -56,10 +56,7 @@ def test_billing_not_duplicated_on_second_call(model):
payload = {"system": [{"type": "text", "text": "prompt"}]}
model._apply_oauth_billing(payload)
model._apply_oauth_billing(payload)
billing_count = sum(
1 for b in payload["system"]
if isinstance(b, dict) and OAUTH_BILLING_HEADER in b.get("text", "")
)
billing_count = sum(1 for b in payload["system"] if isinstance(b, dict) and OAUTH_BILLING_HEADER in b.get("text", ""))
assert billing_count == 1
+1 -8
View File
@@ -65,14 +65,7 @@ class TestClientInit:
def test_custom_params(self, mock_app_config):
mock_middleware = MagicMock()
with patch("deerflow.client.get_app_config", return_value=mock_app_config):
c = DeerFlowClient(
model_name="gpt-4",
thinking_enabled=False,
subagent_enabled=True,
plan_mode=True,
agent_name="test-agent",
middlewares=[mock_middleware]
)
c = DeerFlowClient(model_name="gpt-4", thinking_enabled=False, subagent_enabled=True, plan_mode=True, agent_name="test-agent", middlewares=[mock_middleware])
assert c._model_name == "gpt-4"
assert c._thinking_enabled is False
assert c._subagent_enabled is True
@@ -132,18 +132,13 @@ def test_build_middlewares_uses_resolved_model_name_for_vision(monkeypatch):
monkeypatch.setattr(lead_agent_module, "_create_summarization_middleware", lambda: None)
monkeypatch.setattr(lead_agent_module, "_create_todo_list_middleware", lambda is_plan_mode: None)
middlewares = lead_agent_module._build_middlewares(
{"configurable": {"model_name": "stale-model", "is_plan_mode": False, "subagent_enabled": False}},
model_name="vision-model",
custom_middlewares=[MagicMock()]
)
middlewares = lead_agent_module._build_middlewares({"configurable": {"model_name": "stale-model", "is_plan_mode": False, "subagent_enabled": False}}, model_name="vision-model", custom_middlewares=[MagicMock()])
assert any(isinstance(m, lead_agent_module.ViewImageMiddleware) for m in middlewares)
# verify the custom middleware is injected correctly
assert len(middlewares) > 0 and isinstance(middlewares[-2], MagicMock)
def test_create_summarization_middleware_uses_configured_model_alias(monkeypatch):
monkeypatch.setattr(
lead_agent_module,
+9 -5
View File
@@ -33,6 +33,7 @@ class TestMemoryStorageInterface:
def test_abstract_methods(self):
"""Should raise TypeError when trying to instantiate abstract class."""
class TestStorage(MemoryStorage):
pass
@@ -45,6 +46,7 @@ class TestFileMemoryStorage:
def test_get_memory_file_path_global(self, tmp_path):
"""Should return global memory file path when agent_name is None."""
def mock_get_paths():
mock_paths = MagicMock()
mock_paths.memory_file = tmp_path / "memory.json"
@@ -58,6 +60,7 @@ class TestFileMemoryStorage:
def test_get_memory_file_path_agent(self, tmp_path):
"""Should return per-agent memory file path when agent_name is provided."""
def mock_get_paths():
mock_paths = MagicMock()
mock_paths.agent_memory_file.return_value = tmp_path / "agents" / "test-agent" / "memory.json"
@@ -68,9 +71,7 @@ class TestFileMemoryStorage:
path = storage._get_memory_file_path("test-agent")
assert path == tmp_path / "agents" / "test-agent" / "memory.json"
@pytest.mark.parametrize(
"invalid_name", ["", "../etc/passwd", "agent/name", "agent\\name", "agent name", "agent@123", "agent_name"]
)
@pytest.mark.parametrize("invalid_name", ["", "../etc/passwd", "agent/name", "agent\\name", "agent name", "agent@123", "agent_name"])
def test_validate_agent_name_invalid(self, invalid_name):
"""Should raise ValueError for invalid agent names that don't match the pattern."""
storage = FileMemoryStorage()
@@ -79,6 +80,7 @@ class TestFileMemoryStorage:
def test_load_creates_empty_memory(self, tmp_path):
"""Should create empty memory when file doesn't exist."""
def mock_get_paths():
mock_paths = MagicMock()
mock_paths.memory_file = tmp_path / "non_existent_memory.json"
@@ -125,10 +127,10 @@ class TestFileMemoryStorage:
# First load
memory1 = storage.load()
assert memory1["facts"][0]["content"] == "initial fact"
# Update file directly
memory_file.write_text('{"version": "1.0", "facts": [{"content": "updated fact"}]}')
# Reload should get updated data
memory2 = storage.reload()
assert memory2["facts"][0]["content"] == "updated fact"
@@ -141,6 +143,7 @@ class TestGetMemoryStorage:
def reset_storage_instance(self):
"""Reset the global storage instance before and after each test."""
import deerflow.agents.memory.storage as storage_mod
storage_mod._storage_instance = None
yield
storage_mod._storage_instance = None
@@ -167,6 +170,7 @@ class TestGetMemoryStorage:
def test_get_memory_storage_thread_safety(self):
"""Should safely initialize the singleton even with concurrent calls."""
results = []
def get_storage():
# get_memory_storage is called concurrently from multiple threads while
# get_memory_config is patched once around thread creation. This verifies