From 30631a65a178b489fa68433913b1f453c103d932 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 20 Sep 2025 21:33:20 +0000 Subject: [PATCH] Fix lint issues in test script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use crew variable to avoid F841 unused variable error - Remove API key logging to address CodeQL security alert - Make path portable using os.path.join Co-Authored-By: João --- test_tracing_auth.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/test_tracing_auth.py b/test_tracing_auth.py index 2f7ed979b..a26b5da72 100644 --- a/test_tracing_auth.py +++ b/test_tracing_auth.py @@ -3,44 +3,49 @@ Test script for issue #3559 - TraceBatchManager authentication handling """ +import os import sys -sys.path.insert(0, '/home/ubuntu/repos/crewAI/src') + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) def test_tracing_auth_issue(): """Test that tracing authentication issue is fixed""" - + try: - from crewai.events.listeners.tracing.trace_batch_manager import TraceBatchManager - from crewai.cli.authentication.token import AuthError from unittest.mock import patch - + + from crewai.cli.authentication.token import AuthError + from crewai.events.listeners.tracing.trace_batch_manager import ( + TraceBatchManager, + ) + print("Test 1: TraceBatchManager creation without authentication") - + with patch( "crewai.events.listeners.tracing.trace_batch_manager.get_auth_token", side_effect=AuthError("No token found, make sure you are logged in") ): batch_manager = TraceBatchManager() - print(f"✓ TraceBatchManager created successfully with empty API key: '{batch_manager.plus_api.api_key}'") - + print("✓ TraceBatchManager created successfully with empty API key") + batch = batch_manager.initialize_batch({"user_id": "test"}, {"crew_name": "test"}) if batch is not None: print(f"✓ Batch initialized successfully: {batch.batch_id}") else: print("✗ Batch initialization returned None") return False - + except Exception as e: print(f"✗ TraceBatchManager test failed: {e}") import traceback traceback.print_exc() return False - + try: - from crewai import Agent, Crew, Task, LLM - + from crewai import LLM, Agent, Crew, Task + print("\nTest 2: Crew creation without authentication") - + with patch( "crewai.events.listeners.tracing.trace_batch_manager.get_auth_token", side_effect=AuthError("No token found, make sure you are logged in") @@ -51,27 +56,27 @@ def test_tracing_auth_issue(): backstory="A test agent for reproducing the bug", llm=LLM(model="gpt-4o-mini", api_key="fake-key") ) - + task = Task( description="Say hello world", expected_output="A greeting message", agent=agent ) - + crew = Crew( agents=[agent], tasks=[task], verbose=False ) - - print("✓ Crew created successfully without authentication errors") - + + print(f"✓ Crew created successfully without authentication errors: {len(crew.agents)} agents, {len(crew.tasks)} tasks") + except Exception as e: print(f"✗ Crew creation test failed: {e}") import traceback traceback.print_exc() return False - + return True if __name__ == "__main__":