Skip to content

Commit 483992f

Browse files
committed
Fix file paths and add test mocking for mini agents sequential tests
1 parent aeeaa9e commit 483992f

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

.github/workflows/unittest.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ jobs:
9191
- name: Find Researcher Role Source
9292
run: |
9393
echo "🔍 Hunting for the mysterious 'Researcher' role..."
94+
cd src/praisonai
9495
python -c "
9596
import os
9697
import yaml
9798
import glob
9899
99100
print('📋 Searching for Researcher role in all YAML files:')
100-
yaml_files = glob.glob('tests/*.yaml')
101+
yaml_files = glob.glob('src/praisonai/tests/*.yaml')
101102
102103
for yaml_file in yaml_files:
103104
try:
@@ -139,6 +140,7 @@ jobs:
139140
- name: Trace AutoGen Execution Path
140141
run: |
141142
echo "🔍 Tracing AutoGen execution to find where it diverges..."
143+
cd src/praisonai
142144
python -c "
143145
import os
144146
import sys
@@ -163,7 +165,7 @@ jobs:
163165
164166
# Load the YAML to check what it contains
165167
import yaml
166-
with open('tests/autogen-agents.yaml', 'r') as f:
168+
with open('src/praisonai/tests/autogen-agents.yaml', 'r') as f:
167169
config = yaml.safe_load(f)
168170
169171
framework = agents_gen.framework or config.get('framework')
@@ -209,13 +211,14 @@ jobs:
209211
- name: Debug YAML Loading and Roles
210212
run: |
211213
echo "🔍 Tracing YAML file loading and role creation..."
214+
cd src/praisonai
212215
python -c "
213216
import os
214217
import sys
215218
import yaml
216219
sys.path.insert(0, '.')
217220
218-
print('📁 Available YAML files in tests/:')
221+
print('📁 Available YAML files in src/praisonai/tests/:')
219222
import glob
220223
yaml_files = glob.glob('tests/*.yaml')
221224
for f in yaml_files:
@@ -297,6 +300,7 @@ jobs:
297300
- name: Debug PraisonAIModel API Key Flow
298301
run: |
299302
echo "🔍 Testing PraisonAIModel API key handling..."
303+
cd src/praisonai
300304
python -c "
301305
import os
302306
import sys
@@ -351,12 +355,13 @@ jobs:
351355
- name: Test Direct PraisonAI Execution
352356
run: |
353357
echo "🧪 Testing direct PraisonAI execution (what works locally)..."
354-
python -m praisonai tests/autogen-agents.yaml
358+
python -m praisonai src/praisonai/tests/autogen-agents.yaml
355359
continue-on-error: true
356360

357361
- name: Comprehensive Execution Debug
358362
run: |
359363
echo "🔍 Comprehensive debugging of PraisonAI execution path..."
364+
cd src/praisonai
360365
python -c "
361366
import os
362367
import sys
@@ -376,10 +381,10 @@ jobs:
376381
print(f' {f}')
377382
378383
print()
379-
print('📋 Files in tests/ directory:')
384+
print('📋 Files in src/praisonai/tests/ directory:')
380385
for f in os.listdir('tests'):
381386
if f.endswith('.yaml'):
382-
print(f' tests/{f}')
387+
print(f' src/praisonai/tests/{f}')
383388
384389
# Check if root agents.yaml exists
385390
print()
@@ -401,7 +406,7 @@ jobs:
401406
from praisonai.agents_generator import AgentsGenerator
402407
403408
# Test with full path
404-
test_file = 'tests/autogen-agents.yaml'
409+
test_file = 'src/praisonai/tests/autogen-agents.yaml'
405410
print(f' Using test file: {test_file}')
406411
print(f' File exists: {os.path.exists(test_file)}')
407412
@@ -465,7 +470,7 @@ jobs:
465470
- name: Run Fast Tests
466471
run: |
467472
# Run the fastest, most essential tests
468-
python tests/test_runner.py --pattern fast
473+
cd src/praisonai && python tests/test_runner.py --pattern fast
469474
470475
- name: Run Legacy Example Tests
471476
run: |

src/praisonai/tests/unit/agent/test_mini_agents_sequential.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,36 @@
66

77
import sys
88
import os
9+
import pytest
910
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
1011

1112
from praisonaiagents import Agent, Agents
13+
from unittest.mock import patch
1214

13-
def test_mini_agents_sequential_data_passing():
15+
def mock_completion(*args, **kwargs):
16+
"""Mock completion function to avoid calling actual OpenAI API"""
17+
class MockResponse:
18+
def __init__(self, content):
19+
self.content = content
20+
self.choices = [type('obj', (object,), {'message': type('obj', (object,), {'content': content})})]
21+
22+
if 'messages' in kwargs:
23+
if any('Generate the number 42' in str(m.get('content', '')) for m in kwargs.get('messages', [])):
24+
return MockResponse("42")
25+
elif any('multiply it by 2' in str(m.get('content', '')) for m in kwargs.get('messages', [])):
26+
return MockResponse("84")
27+
return MockResponse("mock response")
28+
29+
@patch('praisonaiagents.llms.PraisonAIModel.chat', side_effect=mock_completion)
30+
@patch('praisonaiagents.llms.PraisonAIModel.stream_chat', side_effect=mock_completion)
31+
def test_mini_agents_sequential_data_passing(mock_stream, mock_chat):
1432
"""Test that output from previous task is passed to next task in Mini Agents"""
1533

1634
print("Testing Mini Agents Sequential Data Passing...")
1735

1836
# Create two agents for sequential processing
19-
agent1 = Agent(instructions="Generate the number 42 as your output. Only return the number 42, nothing else.")
20-
agent2 = Agent(instructions="Take the input number and multiply it by 2. Only return the result number, nothing else.")
37+
agent1 = Agent(instructions="Generate the number 42 as your output. Only return the number 42, nothing else.", model_name="gpt-3.5-turbo")
38+
agent2 = Agent(instructions="Take the input number and multiply it by 2. Only return the result number, nothing else.", model_name="gpt-3.5-turbo")
2139

2240
# Create agents with sequential processing (Mini Agents pattern)
2341
agents = Agents(agents=[agent1, agent2], verbose=True)

0 commit comments

Comments
 (0)