File size: 1,525 Bytes
600f3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import asyncio
import os
import json
from unittest.mock import AsyncMock, MagicMock, patch
import sys

# Mock gradio
sys.modules['gradio'] = MagicMock()
# Mock git
sys.modules['git'] = MagicMock()

import app

async def test_jules_comm_fallbacks():
    # Mocking get_all_tools and run_manual_agent
    app.get_all_tools = AsyncMock(return_value=[MagicMock(name="create_session")])
    
    async def mock_run_manual_agent(*args, **kwargs):
        # We check the prompt in messages
        messages = args[2]
        system_msg = args[3]
        
        # system_msg in handle_jules_comm is fixed, we care about prompt in messages
        prompt_content = messages[0].content
        print(f"Agent Prompt: {prompt_content}")
        
        # Check if fallback values are present in the prompt
        assert "hf upload fallback_prof/fallback_space" in prompt_content
        assert "fallback_token" in prompt_content
        
        yield "Thinking...", None
        yield "Created session sessions/123", "sessions/123"

    app.run_manual_agent = mock_run_manual_agent
    
    # Test with manual fallbacks and no log file
    await app.handle_jules_comm(
        repo_url="https://github.com/owner/repo",
        branch="main",
        log_file="",
        hf_prof_fallback="fallback_prof",
        hf_space_fallback="fallback_space",
        hf_token_fallback="fallback_token"
    )
    
    print("\nJules communication fallback test PASSED!")

if __name__ == "__main__":
    asyncio.run(test_jules_comm_fallbacks())