feat: sync

This commit is contained in:
Gab
2026-03-24 13:51:14 +11:00
parent 39bd38040c
commit 4596310485
20 changed files with 1356 additions and 101 deletions

15
scripts/setup-tf-dev.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# ToothFairyAI dev environment setup for tfcode
export TF_WORKSPACE_ID="6586b7e6-683e-4ee6-a6cf-24c19729b5ff"
export TF_API_KEY="EWZooLROIS57EVW3BKGu7Pv6LNe4D6m4gkDjukx3"
export TF_REGION="dev"
echo "ToothFairyAI environment configured:"
echo " Workspace: $TF_WORKSPACE_ID"
echo " Region: $TF_REGION"
echo ""
echo "Run tfcode commands:"
echo " tfcode validate - Test credentials"
echo " tfcode sync - Sync tools from workspace"
echo " tfcode tools list - List synced tools"

136
scripts/test-sync.py Normal file
View File

@@ -0,0 +1,136 @@
#!/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()

60
scripts/test-sync.sh Normal file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
# End-to-end test for tfcode sync
set -e
echo "========================================"
echo "tfcode Sync End-to-End Test"
echo "========================================"
echo
# Step 1: Check Python
echo "Step 1: Checking Python environment..."
if ! command -v python3 &> /dev/null; then
echo "✗ Python 3 not found"
exit 1
fi
echo "✓ Python found: $(python3 --version)"
echo
# Step 2: Install dependencies
echo "Step 2: Installing Python dependencies..."
cd packages/tf-sync
pip install -e . -q 2>/dev/null || pip install toothfairyai pydantic httpx rich -q
echo "✓ Dependencies installed"
cd ../..
echo
# Step 3: Run Python test
echo "Step 3: Running Python sync test..."
python3 scripts/test-sync.py
echo
# Step 4: Test CLI (if bun available)
if command -v bun &> /dev/null; then
echo "Step 4: Testing CLI commands..."
echo
cd packages/tfcode
echo "4a. Testing validate command..."
bun run src/index.ts validate
echo
echo "4b. Testing sync command..."
bun run src/index.ts sync
echo
echo "4c. Testing tools list command..."
bun run src/index.ts tools list
echo
cd ../..
else
echo "Step 4: Skipping CLI test (bun not available)"
fi
echo
echo "========================================"
echo "All tests passed!"
echo "========================================"