Skip to content

Commit 4a65f77

Browse files
committed
chore: enhance GitHub Actions workflow and test cases
- Added debugging steps to check API key availability and log environment variables in the GitHub Actions workflow. - Updated test cases to remove API key validation checks, ensuring all tests run regardless of API key status. - Renamed test steps for clarity and improved readability. These changes improve the testing process and provide better insights during execution.
1 parent 14ece72 commit 4a65f77

2 files changed

Lines changed: 75 additions & 101 deletions

File tree

.github/workflows/test-core.yml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,64 @@ jobs:
4040
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY || 'sk-test-key-for-github-actions-testing-only-not-real' }}" >> $GITHUB_ENV
4141
echo "OPENAI_API_BASE=${{ secrets.OPENAI_API_BASE || 'https://api.openai.com/v1' }}" >> $GITHUB_ENV
4242
echo "OPENAI_MODEL_NAME=${{ secrets.OPENAI_MODEL_NAME || 'gpt-4o-mini' }}" >> $GITHUB_ENV
43+
echo "LOGLEVEL=DEBUG" >> $GITHUB_ENV
4344
echo "PYTHONPATH=${{ github.workspace }}/src/praisonai-agents:$PYTHONPATH" >> $GITHUB_ENV
4445
46+
- name: Debug API Key Status
47+
run: |
48+
echo "🔍 Checking API key availability..."
49+
if [ -n "${{ secrets.OPENAI_API_KEY }}" ]; then
50+
echo "✅ GitHub secret OPENAI_API_KEY is available"
51+
echo "🔑 API key starts with: $(echo "$OPENAI_API_KEY" | cut -c1-7)..."
52+
else
53+
echo "⚠️ GitHub secret OPENAI_API_KEY is NOT set - using fallback"
54+
echo "🔑 Using fallback key: sk-test-key..."
55+
fi
56+
echo "🌐 API Base: $OPENAI_API_BASE"
57+
echo "🤖 Model: $OPENAI_MODEL_NAME"
58+
echo "🐛 Log Level: $LOGLEVEL"
59+
echo "📊 Environment Check:"
60+
echo " - OPENAI_API_KEY length: ${#OPENAI_API_KEY}"
61+
echo " - OPENAI_API_BASE: $OPENAI_API_BASE"
62+
echo " - OPENAI_MODEL_NAME: $OPENAI_MODEL_NAME"
63+
echo " - LOGLEVEL: $LOGLEVEL"
64+
65+
- name: Debug Python Environment Variables
66+
run: |
67+
python -c "
68+
import os
69+
print('🐍 Python Environment Variable Check:')
70+
api_key = os.environ.get('OPENAI_API_KEY', 'NOT_SET')
71+
if api_key != 'NOT_SET':
72+
print(f' ✅ OPENAI_API_KEY: {api_key[:7]}... (length: {len(api_key)})')
73+
else:
74+
print(' ❌ OPENAI_API_KEY: NOT_SET')
75+
print(f' 🌐 OPENAI_API_BASE: {os.environ.get(\"OPENAI_API_BASE\", \"NOT_SET\")}')
76+
print(f' 🤖 OPENAI_MODEL_NAME: {os.environ.get(\"OPENAI_MODEL_NAME\", \"NOT_SET\")}')
77+
print(f' 📋 All OPENAI env vars:')
78+
for key, value in os.environ.items():
79+
if key.startswith('OPENAI'):
80+
print(f' {key}: {value[:10] if len(value) > 10 else value}...')
81+
"
82+
83+
- name: Validate API Key
84+
run: |
85+
echo "🔑 Testing API key validity with minimal OpenAI call..."
86+
python -c "
87+
import os
88+
try:
89+
from openai import OpenAI
90+
client = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))
91+
response = client.models.list()
92+
print('✅ API Key is VALID - OpenAI responded successfully')
93+
print(f'📊 Available models: {len(list(response.data))} models found')
94+
except Exception as e:
95+
print(f'❌ API Key is INVALID - Error: {e}')
96+
print('🔍 This explains why all API-dependent tests are failing')
97+
print('💡 The GitHub secret OPENAI_API_KEY needs to be updated with a valid key')
98+
"
99+
continue-on-error: true
100+
45101
- name: Run Unit Tests
46102
run: |
47103
cd src/praisonai && python -m pytest tests/unit/ -v --tb=short --disable-warnings --cov=praisonai --cov-report=term-missing
@@ -50,23 +106,20 @@ jobs:
50106
run: |
51107
cd src/praisonai && python -m pytest tests/integration/ -v --tb=short --disable-warnings
52108
53-
- name: Run AutoGen Framework Tests
109+
- name: Test AutoGen Framework
54110
run: |
55111
echo "🤖 Testing AutoGen Framework Integration..."
56-
cd src/praisonai && python tests/test_runner.py --pattern autogen --verbose || echo "⚠️ AutoGen tests completed with issues"
57-
continue-on-error: true
112+
cd src/praisonai && python tests/test_runner.py --pattern autogen --verbose
58113
59-
- name: Run CrewAI Framework Tests
114+
- name: Test CrewAI Framework
60115
run: |
61116
echo "⛵ Testing CrewAI Framework Integration..."
62-
cd src/praisonai && python tests/test_runner.py --pattern crewai --verbose || echo "⚠️ CrewAI tests completed with issues"
63-
continue-on-error: true
117+
cd src/praisonai && python tests/test_runner.py --pattern crewai --verbose
64118
65-
- name: Run Legacy Tests (with skip on invalid API key)
119+
- name: Run Legacy Tests with API Key
66120
run: |
67-
echo "🧪 Running legacy tests - these should skip if API key is invalid..."
68-
cd src/praisonai && OPENAI_API_KEY="sk-test-key-for-github-actions-testing-only-not-real" python -m pytest tests/test.py -v --tb=short --disable-warnings
69-
continue-on-error: true
121+
echo "🧪 Running legacy tests with real API key..."
122+
cd src/praisonai && python -m pytest tests/test.py -v --tb=short --disable-warnings
70123
71124
- name: Upload Coverage Reports
72125
if: matrix.python-version == '3.11'

src/praisonai/tests/test.py

Lines changed: 12 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,153 +11,74 @@
1111
import collections.abc
1212
collections.MutableMapping = collections.abc.MutableMapping
1313

14-
def _should_skip_api_test():
15-
"""Check if API tests should be skipped due to invalid/test API key"""
16-
api_key = os.environ.get('OPENAI_API_KEY', '')
17-
return (not api_key or
18-
api_key.startswith('sk-test-') or
19-
api_key == 'nokey' or
20-
api_key == 'test-key' or # Handle truncated test key
21-
'fallback' in api_key or
22-
'testing-only' in api_key or
23-
'not-real' in api_key)
24-
2514
class TestPraisonAIFramework(unittest.TestCase):
2615
def test_main_with_agents_advanced(self):
27-
if _should_skip_api_test():
28-
self.skipTest("Skipping API test due to invalid/test API key")
29-
3016
praisonai = PraisonAI(agent_file="tests/agents-advanced.yaml")
3117
result = praisonai.run()
3218
print(f"Result: {result}")
3319
self.assertIsNotNone(result)
3420

3521
def test_main_with_autogen_framework(self):
36-
if _should_skip_api_test():
37-
self.skipTest("Skipping API test due to invalid/test API key")
38-
3922
praisonai = PraisonAI(agent_file="tests/autogen-agents.yaml")
4023
result = praisonai.run()
4124
print(f"Result: {result}")
4225
self.assertIsNotNone(result)
4326

4427
def test_main_with_custom_framework(self):
45-
if _should_skip_api_test():
46-
self.skipTest("Skipping API test due to invalid/test API key")
47-
4828
praisonai = PraisonAI(agent_file="tests/crewai-agents.yaml")
4929
result = praisonai.run()
5030
print(f"Result: {result}")
5131
self.assertIsNotNone(result)
5232

5333
def test_main_with_internet_search_tool(self):
54-
if _should_skip_api_test():
55-
self.skipTest("Skipping API test due to invalid/test API key")
56-
5734
praisonai = PraisonAI(agent_file="tests/search-tool-agents.yaml")
5835
result = praisonai.run()
5936
print(f"Result: {result}")
6037
self.assertIsNotNone(result)
6138

6239
def test_main_with_built_in_tool(self):
63-
if _should_skip_api_test():
64-
self.skipTest("Skipping API test due to invalid/test API key")
65-
66-
praisonai = PraisonAI(agent_file="tests/inbuilt-tool-agents.yaml")
40+
praisonai = PraisonAI(agent_file="tests/built-in-tools-agents.yaml")
6741
result = praisonai.run()
6842
print(f"Result: {result}")
6943
self.assertIsNotNone(result)
7044

7145

7246
class TestPraisonAICommandLine(unittest.TestCase):
7347
def run_command(self, command):
74-
result = subprocess.run(
75-
command,
76-
stdout=subprocess.PIPE,
77-
stderr=subprocess.STDOUT,
78-
shell=True,
79-
text=True,
80-
env=os.environ.copy() # Fix: Inherit environment variables
81-
)
82-
return result.stdout
48+
"""Helper method to run CLI commands"""
49+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
50+
return result.stdout + result.stderr
8351

8452
def test_praisonai_command(self):
85-
if _should_skip_api_test():
86-
self.skipTest("Skipping API test due to invalid/test API key")
87-
8853
# Test basic praisonai command
8954
command = "praisonai --framework autogen --auto create a 2-agent team to write a simple python game"
9055
result = self.run_command(command)
9156
print(f"Result: {result}")
9257
self.assertIn('TERMINATE', result)
9358

9459
def test_praisonai_init_command(self):
95-
if _should_skip_api_test():
96-
self.skipTest("Skipping API test due to invalid/test API key")
97-
9860
# Test praisonai --init command
9961
command = "praisonai --framework autogen --init create a 2-agent team to write a simple python game"
10062
result = self.run_command(command)
10163
print(f"Result: {result}")
10264
self.assertIn('created successfully', result)
10365

10466
class TestExamples(unittest.TestCase):
105-
def test_basic_example(self):
106-
if _should_skip_api_test():
107-
self.skipTest("Skipping due to no valid API key provided")
108-
109-
# Test the basic example function
110-
try:
111-
result = main()
112-
self.assertIsNotNone(result)
113-
# Check if result contains expected success indicators or output
114-
self.assertTrue(
115-
isinstance(result, str) and (
116-
"completed successfully" in result or
117-
"Task Output" in result or
118-
len(result.strip()) > 0
119-
),
120-
f"Expected meaningful result, got: {result}"
121-
)
122-
except Exception as e:
123-
# Fallback skip for API errors
124-
if any(error in str(e) for error in ['Invalid API Key', 'AuthenticationError', '401']):
125-
self.skipTest(f"Skipping due to API key issue: {e}")
126-
else:
127-
raise
128-
12967
def test_advanced_example(self):
130-
if _should_skip_api_test():
131-
self.skipTest("Skipping due to no valid API key provided")
132-
133-
# Test the advanced example function
134-
try:
135-
result = advanced()
136-
self.assertIsNotNone(result)
137-
# Check if result contains expected success indicators or output
138-
self.assertTrue(
139-
isinstance(result, str) and (
140-
"completed successfully" in result or
141-
"Task Output" in result or
142-
len(result.strip()) > 0
143-
),
144-
f"Expected meaningful result, got: {result}"
145-
)
146-
except Exception as e:
147-
# Fallback skip for API errors
148-
if any(error in str(e) for error in ['Invalid API Key', 'AuthenticationError', '401']):
149-
self.skipTest(f"Skipping due to API key issue: {e}")
150-
else:
151-
raise
68+
result = advanced()
69+
print(f"Result: {result}")
70+
self.assertIsNotNone(result)
15271

15372
def test_auto_example(self):
154-
if _should_skip_api_test():
155-
self.skipTest("Skipping API test due to invalid/test API key")
156-
15773
result = auto()
15874
print(f"Result: {result}")
15975
self.assertIsNotNone(result)
16076

77+
def test_basic_example(self):
78+
result = main()
79+
print(f"Result: {result}")
80+
self.assertIsNotNone(result)
81+
16182
if __name__ == '__main__':
16283
# runner = XMLTestRunner(output='test-reports')
16384
unittest.main()

0 commit comments

Comments
 (0)