tf_code/scripts/test-sync.py
2026-03-24 13:51:14 +11:00

136 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Quick test script for tfcode sync functionality.
Tests credential validation and tool sync directly.
"""
import os
import sys
# Set environment for testing
os.environ["TF_WORKSPACE_ID"] = "6586b7e6-683e-4ee6-a6cf-24c19729b5ff"
os.environ["TF_API_KEY"] = "EWZooLROIS57EVW3BKGu7Pv6LNe4D6m4gkDjukx3"
os.environ["TF_REGION"] = "dev"
def main():
print("=" * 60)
print("tfcode Sync Test")
print("=" * 60)
print()
# Test 1: Load config
print("Test 1: Load Configuration")
print("-" * 40)
try:
from tf_sync.config import load_config, get_region_urls, Region
config = load_config()
print(f"✓ Workspace ID: {config.workspace_id}")
print(f"✓ Region: {config.region.value}")
urls = get_region_urls(config.region)
print(f"✓ API URL: {urls['base_url']}")
print(f"✓ MCP Proxy URL: {urls['mcp_proxy_url']}")
print()
except Exception as e:
print(f"✗ Failed: {e}")
print()
sys.exit(1)
# Test 2: Validate credentials
print("Test 2: Validate Credentials")
print("-" * 40)
try:
from tf_sync.config import validate_credentials
result = validate_credentials(config)
if result.success:
print("✓ Credentials valid")
if result.workspace_name:
print(f" Workspace: {result.workspace_name}")
if result.workspace_id:
print(f" ID: {result.workspace_id}")
else:
print(f"✗ Validation failed: {result.error}")
sys.exit(1)
print()
except Exception as e:
print(f"✗ Failed: {e}")
import traceback
traceback.print_exc()
print()
sys.exit(1)
# Test 3: Sync tools
print("Test 3: Sync Tools")
print("-" * 40)
try:
from tf_sync.tools import sync_tools, ToolType
result = sync_tools(config)
if result.success:
print(f"✓ Synced {len(result.tools)} tools")
print()
if result.by_type:
print("By type:")
for tool_type, count in result.by_type.items():
print(f" {tool_type}: {count}")
print()
# Show first 5 tools
if result.tools:
print("Sample tools:")
for tool in result.tools[:5]:
type_emoji = {
ToolType.MCP_SERVER: "🔌",
ToolType.AGENT_SKILL: "🤖",
ToolType.DATABASE_SCRIPT: "🗄️",
ToolType.API_FUNCTION: "🌐",
}.get(tool.tool_type, "📦")
print(f" {type_emoji} {tool.name} ({tool.tool_type.value})")
if tool.description:
print(f" {tool.description[:60]}...")
print(f" Auth: {tool.auth_via}")
if len(result.tools) > 5:
print(f" ... and {len(result.tools) - 5} more")
else:
print(f"✗ Sync failed: {result.error}")
sys.exit(1)
print()
except Exception as e:
print(f"✗ Failed: {e}")
import traceback
traceback.print_exc()
print()
sys.exit(1)
# Test 4: Sync by type
print("Test 4: Sync MCP Servers Only")
print("-" * 40)
try:
from tf_sync.tools import sync_tools_by_type
result = sync_tools_by_type(config, [ToolType.MCP_SERVER])
if result.success:
print(f"✓ Found {len(result.tools)} MCP servers")
for tool in result.tools:
print(f" - {tool.name}")
else:
print(f"✗ Failed: {result.error}")
print()
except Exception as e:
print(f"✗ Failed: {e}")
print()
print("=" * 60)
print("All tests completed!")
print("=" * 60)
if __name__ == "__main__":
main()