Uname:Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64

Base Dir : /var/www/moonbloom

User : wp-moonbloom


403WebShell
403Webshell
Server IP : 85.155.190.233  /  Your IP : 216.73.216.103
Web Server : nginx/1.24.0
System : Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User : wp-moonbloom ( 1001)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/2398465/root/opt/Gemini_Swarm_Core/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/2398465/root/opt/Gemini_Swarm_Core/scripts/test_google_developer_knowledge.py
#!/usr/bin/env python3
import sys
import os
import subprocess
import json

def test_credentials():
    print("Checking GCP key existence...")
    if not os.path.exists('/root/gcp-key.json'):
        print("WARNING: /root/gcp-key.json does not exist. Skipping live integration tests.")
        return None
    print("SUCCESS: /root/gcp-key.json found.")

    print("Testing token load and refresh...")
    try:
        from google.oauth2.credentials import Credentials
        from google.auth.transport.requests import Request
        creds = Credentials.from_authorized_user_file('/root/gcp-key.json')
        auth_req = Request()
        creds.refresh(auth_req)
        print("SUCCESS: Credentials loaded and refreshed. Access token starts with:", creds.token[:10])
        return True
    except Exception as e:
        print(f"ERROR: Failed to refresh credentials: {e}")
        return False

def test_proxy_stdout():
    print("Testing proxy JSON-RPC communication via stdio...")
    try:
        req = {
            "jsonrpc": "2.0",
            "method": "tools/list",
            "params": {},
            "id": 1
        }
        req_str = json.dumps(req) + "\n"

        proxy_path = os.path.join(os.path.dirname(__file__), 'google_developer_knowledge_proxy.py')
        proc = subprocess.Popen(
            [sys.executable, proxy_path],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True
        )

        stdout, stderr = proc.communicate(input=req_str, timeout=15)

        if proc.returncode != 0:
            print(f"ERROR: Proxy exited with code {proc.returncode}")
            print("stderr:", stderr)
            return False

        print("Raw response from proxy stdout:", stdout)
        resp = json.loads(stdout.strip())
        if 'error' in resp:
            print("ERROR: Remote server returned error:", resp['error'])
            return False

        tools = resp.get('result', {}).get('tools', [])
        tool_names = [t['name'] for t in tools]
        print("Found tools:", tool_names)

        required_tools = ['search_documents', 'answer_query', 'get_documents']
        for rt in required_tools:
            if rt not in tool_names:
                print(f"ERROR: Required tool '{rt}' not found in tools list.")
                return False

        print("SUCCESS: All required tools found.")
        return True
    except Exception as e:
        print(f"ERROR during proxy stdio test: {e}")
        return False

def test_proxy_search():
    print("Testing proxy search (search_documents) via stdio...")
    try:
        req = {
            "jsonrpc": "2.0",
            "method": "tools/call",
            "params": {
                "name": "search_documents",
                "arguments": {
                    "query": "Android Jetpack Compose"
                }
            },
            "id": 2
        }
        req_str = json.dumps(req) + "\n"

        proxy_path = os.path.join(os.path.dirname(__file__), 'google_developer_knowledge_proxy.py')
        proc = subprocess.Popen(
            [sys.executable, proxy_path],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True
        )

        stdout, stderr = proc.communicate(input=req_str, timeout=15)

        if proc.returncode != 0:
            print(f"ERROR: Proxy exited with code {proc.returncode}")
            print("stderr:", stderr)
            return False

        print("Raw search response from proxy stdout:", stdout)
        resp = json.loads(stdout.strip())
        if 'error' in resp:
            print("ERROR: Remote server returned error on search:", resp['error'])
            return False

        result = resp.get('result', {})
        print("Search result:", result)
        content = result.get('content', [])
        if not content:
            print("ERROR: Search returned empty or no content.")
            return False

        print("SUCCESS: Search test passed.")
        return True
    except Exception as e:
        print(f"ERROR during proxy search test: {e}")
        return False

if __name__ == '__main__':
    print("=== Starting Google Developer Knowledge MCP Integration Tests ===")
    creds_ok = test_credentials()
    if creds_ok is False:
        sys.exit(1)
    elif creds_ok is None:
        print("=== LIVE TESTS SKIPPED (NO CREDENTIALS) ===")
        sys.exit(0)

    proxy_ok = test_proxy_stdout()
    if not proxy_ok:
        sys.exit(1)

    search_ok = test_proxy_search()
    if not search_ok:
        sys.exit(1)

    print("=== ALL TESTS PASSED SUCCESSFULLY ===")
    sys.exit(0)

Youez - 2016 - github.com/yon3zu
LinuXploit