""" Non-interactive verification script for DeepSeek Proxy Server & Claude Tool Call Bridge. """ import json import urllib.request import sys SERVER_URL = "http://127.0.0.1:8000" def post_json(endpoint, payload): url = f"{SERVER_URL}{endpoint}" data = json.dumps(payload).encode("utf-8") req = urllib.request.Request(url, data=data, method="POST") req.add_header("Content-Type", "application/json") try: with urllib.request.urlopen(req, timeout=30) as resp: return json.loads(resp.read().decode("utf-8")) except Exception as e: print(f"❌ Error POSTing to {endpoint}: {e}") return None def test_health(): print("1. Testing Health Endpoint...") url = f"{SERVER_URL}/health" req = urllib.request.Request(url) with urllib.request.urlopen(req) as resp: data = json.loads(resp.read().decode("utf-8")) assert data.get("status") == "online" print(f" ✅ Health Check OK! Active session: {data.get('active_tab_session_id')}") def test_claude_anthropic_tools(): print("\n2. Testing Anthropic Messages Endpoint (/v1/claude/messages) with Tool Protocol...") payload = { "model": "claude-3-5-sonnet-20241022", "system": "You are a helpful coding assistant.", "tools": [ { "name": "Bash", "description": "Execute a shell command", "input_schema": { "type": "object", "properties": {"command": {"type": "string"}}, "required": ["command"] } }, { "name": "Write", "description": "Write content to a file", "input_schema": { "type": "object", "properties": {"file_path": {"type": "string"}, "content": {"type": "string"}}, "required": ["file_path", "content"] } } ], "messages": [ {"role": "user", "content": "Run the bash command `pwd` to check current directory"} ] } res = post_json("/v1/claude/messages", payload) if not res: print(" ❌ Failed to get response from /v1/claude/messages") sys.exit(1) print(f" Response ID: {res.get('id')}") print(f" Stop Reason: {res.get('stop_reason')}") print(f" Content Blocks: {json.dumps(res.get('content'), indent=2)}") has_tool_use = any(b.get("type") == "tool_use" for b in res.get("content", [])) if has_tool_use: print(" ✅ SUCCESS: Tool use block correctly detected and structured for Claude Code CLI!") else: print(" ⚠️ Note: Model returned text response without invoking tool. Verify content block above.") def test_openai_chat_completions(): print("\n3. Testing OpenAI Chat Completions Endpoint (/v1/chat/completions)...") payload = { "model": "DeepSeek-V3 Standard", "messages": [ {"role": "user", "content": "Reply with exact word: PONG"} ] } res = post_json("/v1/chat/completions", payload) if not res: print(" ❌ Failed to get response from /v1/chat/completions") sys.exit(1) content = res["choices"][0]["message"]["content"] print(f" Resolved Model: {res.get('model')}") print(f" Content Output: {content.strip()}") print(" ✅ SUCCESS: OpenAI ChatCompletions endpoint working 100%!") if __name__ == "__main__": print("=" * 65) print("🚀 RUNNING NON-INTERACTIVE VERIFICATION TEST SUITE") print("=" * 65) test_health() test_openai_chat_completions() test_claude_anthropic_tools() print("\n" + "=" * 65) print("🎉 ALL NON-INTERACTIVE VERIFICATION TESTS COMPLETED!") print("=" * 65)