Fix React hook anti-patterns, incorrect mock paths, and unused code
- Replace useState+useEffect sync pattern with useMemo in EdgeSettingsPanel.tsx to eliminate cascading re-renders - Remove redundant draft state in NodeSettingsPanel.tsx and use store data directly, eliminating useEffect sync loop - Fix mock paths in test_tools.py: patch tavily.TavilyClient and pypdf.PdfReader at their source modules (lazy imports) - Remove unused variable assignment in routes.py (god mode reject) - Remove unused node_lookup dicts in dynamic_graph_builder.py - Remove unused imports across test files (Blueprint, CouncilState, pytest, llm assignments) - Remove unused CouncilBlueprint type import in types.test.ts - Run npm audit fix to resolve moderate vulnerability All 107 backend tests and 26 frontend tests pass. Ruff, ESLint, and TypeScript checks are clean. https://claude.ai/code/session_01XqzyT6fhS8sUe9P5fCmuVU
This commit is contained in:
parent
fb0d3ae8f1
commit
7becffcc89
11 changed files with 2332 additions and 65 deletions
|
|
@ -222,7 +222,7 @@ async def approve_god_mode(
|
|||
)
|
||||
|
||||
if request.action == "reject":
|
||||
state = await resume_god_mode(run_id, action="reject")
|
||||
await resume_god_mode(run_id, action="reject")
|
||||
run_store.update(run_id, {"status": "failed", "error": "Rejected by user in God Mode."})
|
||||
return CouncilResultResponse(
|
||||
run_id=run_id,
|
||||
|
|
|
|||
|
|
@ -366,9 +366,6 @@ def build_graph_from_blueprint(
|
|||
if not nodes:
|
||||
raise ValueError("Blueprint has no nodes.")
|
||||
|
||||
# Build node lookup
|
||||
node_lookup = {n["id"]: n for n in nodes}
|
||||
|
||||
# Find entry point: the node that has no incoming edges
|
||||
targets = {e["target"] for e in edges}
|
||||
entry_candidates = [n["id"] for n in nodes if n["id"] not in targets]
|
||||
|
|
@ -559,7 +556,6 @@ def _build_graph_with_checkpointer(
|
|||
if not nodes:
|
||||
raise ValueError("Blueprint has no nodes.")
|
||||
|
||||
node_lookup = {n["id"]: n for n in nodes}
|
||||
targets = {e["target"] for e in edges}
|
||||
entry_candidates = [n["id"] for n in nodes if n["id"] not in targets]
|
||||
if not entry_candidates:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import pytest
|
|||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
|
||||
from models.blueprint import Base, Blueprint
|
||||
from models.blueprint import Base
|
||||
from services.blueprint_service import (
|
||||
create_blueprint,
|
||||
delete_blueprint,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from services.dynamic_graph_builder import (
|
|||
_get_llm,
|
||||
)
|
||||
from services.graph_builder import create_initial_state
|
||||
from state import CouncilState, APPROVAL_THRESHOLD, MAX_ITERATIONS
|
||||
from state import APPROVAL_THRESHOLD, MAX_ITERATIONS
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -321,10 +321,10 @@ class TestModelLookup:
|
|||
|
||||
def test_claude_model_creates_instance(self):
|
||||
with patch("services.dynamic_graph_builder.ChatAnthropic") as MockLLM:
|
||||
llm = _get_llm("claude-3-5-sonnet")
|
||||
_get_llm("claude-3-5-sonnet")
|
||||
MockLLM.assert_called_once()
|
||||
|
||||
def test_gpt4o_model_creates_instance(self):
|
||||
with patch("services.dynamic_graph_builder.ChatOpenAI") as MockLLM:
|
||||
llm = _get_llm("gpt-4o")
|
||||
_get_llm("gpt-4o")
|
||||
MockLLM.assert_called_once()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from state import CouncilState
|
||||
|
||||
|
||||
class TestBuildGraphGodMode:
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import os
|
|||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from state import CouncilState, APPROVAL_THRESHOLD, MAX_ITERATIONS
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import os
|
|||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
|
||||
|
|
@ -24,7 +23,7 @@ class TestWebSearchTool:
|
|||
assert "TAVILY_API_KEY" in result
|
||||
|
||||
@patch.dict(os.environ, {"TAVILY_API_KEY": "test-key"}, clear=False)
|
||||
@patch("tools.web_search.TavilyClient")
|
||||
@patch("tavily.TavilyClient")
|
||||
def test_web_search_returns_formatted_results(self, mock_client_cls):
|
||||
mock_client = MagicMock()
|
||||
mock_client.search.return_value = {
|
||||
|
|
@ -46,7 +45,7 @@ class TestWebSearchTool:
|
|||
assert "Some content here" in result
|
||||
|
||||
@patch.dict(os.environ, {"TAVILY_API_KEY": "test-key"}, clear=False)
|
||||
@patch("tools.web_search.TavilyClient")
|
||||
@patch("tavily.TavilyClient")
|
||||
def test_web_search_handles_empty_results(self, mock_client_cls):
|
||||
mock_client = MagicMock()
|
||||
mock_client.search.return_value = {"results": []}
|
||||
|
|
@ -58,7 +57,7 @@ class TestWebSearchTool:
|
|||
assert "No results" in result
|
||||
|
||||
@patch.dict(os.environ, {"TAVILY_API_KEY": "test-key"}, clear=False)
|
||||
@patch("tools.web_search.TavilyClient")
|
||||
@patch("tavily.TavilyClient")
|
||||
def test_web_search_handles_api_error(self, mock_client_cls):
|
||||
mock_client = MagicMock()
|
||||
mock_client.search.side_effect = Exception("API rate limit")
|
||||
|
|
@ -137,7 +136,7 @@ class TestPdfIngestion:
|
|||
"""Tests for PDF ingestion into ChromaDB."""
|
||||
|
||||
@patch("tools.pdf_reader._get_chroma_collection")
|
||||
@patch("tools.pdf_reader.PdfReader")
|
||||
@patch("pypdf.PdfReader")
|
||||
def test_ingest_pdf_processes_pages(self, mock_pdf_reader_cls, mock_get_collection):
|
||||
# Mock PDF with 2 pages of text
|
||||
mock_page1 = MagicMock()
|
||||
|
|
@ -158,7 +157,7 @@ class TestPdfIngestion:
|
|||
mock_collection.upsert.assert_called_once()
|
||||
|
||||
@patch("tools.pdf_reader._get_chroma_collection")
|
||||
@patch("tools.pdf_reader.PdfReader")
|
||||
@patch("pypdf.PdfReader")
|
||||
def test_ingest_pdf_empty_file(self, mock_pdf_reader_cls, mock_get_collection):
|
||||
mock_reader = MagicMock()
|
||||
mock_reader.pages = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue