mirror of
https://github.com/crewAIInc/crewAI.git
synced 2025-12-16 04:18:35 +00:00
Fix lint issues in test script
- 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 <joao@crewai.com>
This commit is contained in:
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user