fix: fix the lint check errors of the main branch (#403)

This commit is contained in:
Willem Jiang
2025-07-12 14:43:25 +08:00
committed by GitHub
parent 2363b21447
commit 3c46201ff0
27 changed files with 21 additions and 128 deletions

View File

@@ -1,6 +1,7 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
from .loader import load_yaml_config
from .tools import SELECTED_SEARCH_ENGINE, SearchEngine from .tools import SELECTED_SEARCH_ENGINE, SearchEngine
from .questions import BUILT_IN_QUESTIONS, BUILT_IN_QUESTIONS_ZH_CN from .questions import BUILT_IN_QUESTIONS, BUILT_IN_QUESTIONS_ZH_CN
@@ -45,4 +46,5 @@ __all__ = [
"SearchEngine", "SearchEngine",
"BUILT_IN_QUESTIONS", "BUILT_IN_QUESTIONS",
"BUILT_IN_QUESTIONS_ZH_CN", "BUILT_IN_QUESTIONS_ZH_CN",
load_yaml_config,
] ]

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import sys
from .article import Article from .article import Article
from .jina_client import JinaClient from .jina_client import JinaClient

View File

@@ -4,7 +4,6 @@
from pathlib import Path from pathlib import Path
from typing import Any, Dict from typing import Any, Dict
import os import os
import ssl
import httpx import httpx
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI

View File

@@ -3,11 +3,11 @@
import logging import logging
from langchain.schema import HumanMessage, SystemMessage from langchain.schema import HumanMessage
from src.config.agents import AGENT_LLM_MAP from src.config.agents import AGENT_LLM_MAP
from src.llms.llm import get_llm_by_type from src.llms.llm import get_llm_by_type
from src.prompts.template import env, apply_prompt_template from src.prompts.template import apply_prompt_template
from src.prompt_enhancer.graph.state import PromptEnhancerState from src.prompt_enhancer.graph.state import PromptEnhancerState
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@@ -48,12 +48,12 @@ class VikingDBKnowledgeBaseProvider(Retriever):
if params: if params:
for key in params: for key in params:
if ( if (
type(params[key]) == int type(params[key]) is int
or type(params[key]) == float or type(params[key]) is float
or type(params[key]) == bool or type(params[key]) is bool
): ):
params[key] = str(params[key]) params[key] = str(params[key])
elif type(params[key]) == list: elif type(params[key]) is list:
if not doseq: if not doseq:
params[key] = ",".join(params[key]) params[key] = ",".join(params[key])

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import json
import logging import logging
import os import os
from typing import List, Optional from typing import List, Optional

View File

@@ -1,9 +1,7 @@
from collections import namedtuple from collections import namedtuple
import json import json
import pytest import pytest
import asyncio from unittest.mock import patch, MagicMock
import types
from unittest.mock import patch, MagicMock, AsyncMock
from src.graph.nodes import planner_node from src.graph.nodes import planner_node
from src.graph.nodes import human_feedback_node from src.graph.nodes import human_feedback_node
from src.graph.nodes import coordinator_node from src.graph.nodes import coordinator_node
@@ -39,7 +37,7 @@ def mock_state():
@pytest.fixture @pytest.fixture
def mock_configurable(): def mock_configurable():
mock = MagicMock() mock = MagicMock()
mock.max_search_results = 5 mock.max_search_results = 7
return mock return mock
@@ -668,8 +666,6 @@ def test_coordinator_node_tool_calls_exception_handling(
patch_handoff_to_planner, patch_handoff_to_planner,
patch_logger, patch_logger,
): ):
# tool_calls raises exception in processing
tool_calls = [{"name": "handoff_to_planner", "args": None}]
with ( with (
patch("src.graph.nodes.AGENT_LLM_MAP", {"coordinator": "basic"}), patch("src.graph.nodes.AGENT_LLM_MAP", {"coordinator": "basic"}),
patch("src.graph.nodes.get_llm_by_type") as mock_get_llm, patch("src.graph.nodes.get_llm_by_type") as mock_get_llm,
@@ -1037,24 +1033,6 @@ async def test_execute_agent_step_recursion_limit_env_negative(
) )
@pytest.fixture
def mock_state_with_steps(mock_step, mock_completed_step):
# Simulate a plan with one completed and one unexecuted step
Plan = MagicMock()
Plan.steps = [mock_completed_step, mock_step]
return {
"current_plan": Plan,
"observations": ["obs1"],
"locale": "en-US",
"resources": [],
}
@pytest.fixture
def mock_config():
return MagicMock()
@pytest.fixture @pytest.fixture
def mock_configurable_with_mcp(): def mock_configurable_with_mcp():
mock = MagicMock() mock = MagicMock()
@@ -1297,27 +1275,6 @@ def mock_state_without_resources():
return {"other": "value"} return {"other": "value"}
@pytest.fixture
def mock_config():
return MagicMock()
@pytest.fixture
def mock_configurable():
mock = MagicMock()
mock.max_search_results = 7
return mock
@pytest.fixture
def patch_config_from_runnable_config(mock_configurable):
with patch(
"src.graph.nodes.Configuration.from_runnable_config",
return_value=mock_configurable,
):
yield
@pytest.fixture @pytest.fixture
def patch_get_web_search_tool(): def patch_get_web_search_tool():
with patch("src.graph.nodes.get_web_search_tool") as mock: with patch("src.graph.nodes.get_web_search_tool") as mock:

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest
import sys import sys
import os import os
from typing import Annotated from typing import Annotated

View File

@@ -1,13 +1,8 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import os
import pytest
import sys import sys
import types import types
from pathlib import Path
import builtins
import importlib
from src.config.configuration import Configuration from src.config.configuration import Configuration
# Patch sys.path so relative import works # Patch sys.path so relative import works

View File

@@ -3,8 +3,6 @@
import os import os
import tempfile import tempfile
import yaml
import pytest
from src.config.loader import load_yaml_config, process_dict, replace_env_vars from src.config.loader import load_yaml_config, process_dict, replace_env_vars

View File

@@ -1,6 +1,5 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest
from src.crawler.article import Article from src.crawler.article import Article

View File

@@ -1,9 +1,7 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest
import src.crawler as crawler_module import src.crawler as crawler_module
from src.crawler import Crawler
def test_crawler_sets_article_url(monkeypatch): def test_crawler_sets_article_url(monkeypatch):

View File

@@ -1,8 +1,6 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import os
import types
import pytest import pytest
from src.llms import llm from src.llms import llm

View File

@@ -6,7 +6,6 @@ from unittest.mock import patch, MagicMock
from src.prompt_enhancer.graph.builder import build_graph from src.prompt_enhancer.graph.builder import build_graph
from src.prompt_enhancer.graph.state import PromptEnhancerState from src.prompt_enhancer.graph.state import PromptEnhancerState
from src.config.report_style import ReportStyle
class TestBuildGraph: class TestBuildGraph:
@@ -48,7 +47,7 @@ class TestBuildGraph:
mock_state_graph.return_value = mock_builder mock_state_graph.return_value = mock_builder
mock_builder.compile.return_value = mock_compiled_graph mock_builder.compile.return_value = mock_compiled_graph
result = build_graph() build_graph()
# Verify the correct node function was added # Verify the correct node function was added
mock_builder.add_node.assert_called_once_with("enhancer", mock_enhancer_node) mock_builder.add_node.assert_called_once_with("enhancer", mock_enhancer_node)

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest
from src.prompt_enhancer.graph.state import PromptEnhancerState from src.prompt_enhancer.graph.state import PromptEnhancerState
from src.config.report_style import ReportStyle from src.config.report_style import ReportStyle

View File

@@ -1,9 +1,7 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import os
import pytest import pytest
import requests
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
from src.rag.ragflow import RAGFlowProvider, parse_uri from src.rag.ragflow import RAGFlowProvider, parse_uri
@@ -144,30 +142,6 @@ def test_list_resources_success(mock_get, monkeypatch):
assert resources[1].description == "desc2" assert resources[1].description == "desc2"
@patch("src.rag.ragflow.requests.get")
def test_list_resources_success(mock_get, monkeypatch):
monkeypatch.setenv("RAGFLOW_API_URL", "http://api")
monkeypatch.setenv("RAGFLOW_API_KEY", "key")
provider = RAGFlowProvider()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
"data": [
{"id": "123", "name": "Dataset1", "description": "desc1"},
{"id": "456", "name": "Dataset2", "description": "desc2"},
]
}
mock_get.return_value = mock_response
resources = provider.list_resources()
assert len(resources) == 2
assert resources[0].uri == "rag://dataset/123"
assert resources[0].title == "Dataset1"
assert resources[0].description == "desc1"
assert resources[1].uri == "rag://dataset/456"
assert resources[1].title == "Dataset2"
assert resources[1].description == "desc2"
@patch("src.rag.ragflow.requests.get") @patch("src.rag.ragflow.requests.get")
def test_list_resources_error(mock_get, monkeypatch): def test_list_resources_error(mock_get, monkeypatch):
monkeypatch.setenv("RAGFLOW_API_URL", "http://api") monkeypatch.setenv("RAGFLOW_API_URL", "http://api")

View File

@@ -173,8 +173,8 @@ class TestVikingDBKnowledgeBaseProviderPrepareRequest:
"""Test basic request preparation""" """Test basic request preparation"""
with ( with (
patch("src.rag.vikingdb_knowledge_base.Request") as mock_request, patch("src.rag.vikingdb_knowledge_base.Request") as mock_request,
patch("src.rag.vikingdb_knowledge_base.Credentials") as mock_credentials, patch("src.rag.vikingdb_knowledge_base.Credentials") as _mock_credentials,
patch("src.rag.vikingdb_knowledge_base.SignerV4.sign") as mock_sign, patch("src.rag.vikingdb_knowledge_base.SignerV4.sign") as _mock_sign,
): ):
mock_req_instance = MagicMock() mock_req_instance = MagicMock()

View File

@@ -2,31 +2,17 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import base64 import base64
import json
import os import os
from unittest.mock import AsyncMock, MagicMock, patch, mock_open from unittest.mock import MagicMock, patch, mock_open
from uuid import uuid4
from fastapi.responses import JSONResponse, StreamingResponse
import pytest import pytest
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from fastapi import HTTPException, logger from fastapi import HTTPException
from src.server.app import app, _make_event, _astream_workflow_generator from src.server.app import app, _make_event, _astream_workflow_generator
from src.server.mcp_request import MCPServerMetadataRequest
from src.server.rag_request import RAGResourceRequest
from src.config.report_style import ReportStyle from src.config.report_style import ReportStyle
from langgraph.types import Command from langgraph.types import Command
from langchain_core.messages import ToolMessage from langchain_core.messages import ToolMessage
from langchain_core.messages import AIMessageChunk from langchain_core.messages import AIMessageChunk
from src.server.chat_request import (
ChatRequest,
TTSRequest,
GeneratePodcastRequest,
GeneratePPTRequest,
GenerateProseRequest,
EnhancePromptRequest,
)
@pytest.fixture @pytest.fixture
def client(): def client():

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import asyncio # Ensure asyncio is imported
import pytest import pytest
from pydantic import ValidationError from pydantic import ValidationError
from src.config.report_style import ReportStyle from src.config.report_style import ReportStyle

View File

@@ -1,4 +1,3 @@
import pytest
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from src.tools.crawl import crawl_tool from src.tools.crawl import crawl_tool

View File

@@ -1,10 +1,8 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest from unittest.mock import Mock, call, patch
import logging from src.tools.decorators import create_logged_tool
from unittest.mock import Mock, call, patch, MagicMock
from src.tools.decorators import LoggedToolMixin, create_logged_tool
class MockBaseTool: class MockBaseTool:
@@ -58,7 +56,7 @@ class TestLoggedToolMixin:
tool = LoggedTool() tool = LoggedTool()
with patch("src.tools.decorators.logger.debug") as mock_debug: with patch("src.tools.decorators.logger.debug") as mock_debug:
result = tool._run("test_arg") tool._run("test_arg")
# Verify debug log was called with correct message # Verify debug log was called with correct message
mock_debug.assert_has_calls( mock_debug.assert_has_calls(

View File

@@ -2,7 +2,7 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest import pytest
from unittest.mock import Mock, patch, MagicMock from unittest.mock import patch
from src.tools.python_repl import python_repl_tool from src.tools.python_repl import python_repl_tool

View File

@@ -3,7 +3,7 @@
import os import os
import pytest import pytest
from unittest.mock import patch, MagicMock from unittest.mock import patch
from src.tools.search import get_web_search_tool from src.tools.search import get_web_search_tool
from src.config import SearchEngine from src.config import SearchEngine

View File

@@ -3,7 +3,6 @@
import json import json
import pytest import pytest
from unittest.mock import Mock, patch, AsyncMock, MagicMock from unittest.mock import Mock, patch, AsyncMock, MagicMock
import aiohttp
import requests import requests
from src.tools.tavily_search.tavily_search_api_wrapper import ( from src.tools.tavily_search.tavily_search_api_wrapper import (
EnhancedTavilySearchAPIWrapper, EnhancedTavilySearchAPIWrapper,

View File

@@ -4,7 +4,6 @@
import json import json
import pytest import pytest
from unittest.mock import Mock, patch, AsyncMock from unittest.mock import Mock, patch, AsyncMock
from typing import Dict, Any
from src.tools.tavily_search.tavily_search_results_with_images import ( from src.tools.tavily_search.tavily_search_results_with_images import (
TavilySearchResultsWithImages, TavilySearchResultsWithImages,
) )

View File

@@ -1,7 +1,7 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
from unittest.mock import Mock, patch, MagicMock from unittest.mock import Mock, patch
from langchain_core.callbacks import ( from langchain_core.callbacks import (
CallbackManagerForToolRun, CallbackManagerForToolRun,
AsyncCallbackManagerForToolRun, AsyncCallbackManagerForToolRun,

View File

@@ -1,9 +1,7 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import pytest
import json import json
from unittest.mock import patch
from src.utils.json_utils import repair_json_output from src.utils.json_utils import repair_json_output