fix: CI validation scripts and example exit codes

lint-all-sdks.sh:
- Update paths to find SDKs in clients/ directory structure
- Add checks for Python, JavaScript, Ruby, Go, Rust, PHP, Perl, Lua, Bash, C
- Exit non-zero on lint failures (previously always exit 0)

validate-examples.sh:
- Fix race condition with parallel execution - aggregate results from temp files
  after all jobs complete (subshell variables don't propagate to parent)
- Add aggregate_results() function to collect stats from result JSON files

Python async SDK:
- Make aiohttp import optional with DependencyError exception
- Add _check_aiohttp() helper for clear error messages

Python examples (async + sync):
- Exit with code 0 when API keys missing (CI-friendly skip)
- Change "Error:" to "Skipping:" for missing credentials
- Wrap un_async imports in try/except for aiohttp ImportError
This commit is contained in:
russell@unturf.com 2026-02-07 18:01:51 -05:00
parent fee81266a7
commit 35bbd37877
15 changed files with 250 additions and 85 deletions

View file

@ -22,7 +22,12 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import execute_async, get_job, wait_for_job, list_jobs
try:
from un_async import execute_async, get_job, wait_for_job, list_jobs
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def main():

View file

@ -21,7 +21,12 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import execute_code
try:
from un_async import execute_code
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def run_code(language: str, code: str, name: str):

View file

@ -25,7 +25,12 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import execute_code, CredentialsError
try:
from un_async import execute_code, CredentialsError
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def run_http_request(request_num: int, url: str, public_key: str, secret_key: str):
@ -62,9 +67,9 @@ async def main():
secret_key = os.environ.get("UNSANDBOX_SECRET_KEY")
if not public_key or not secret_key:
print("Error: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("Run with: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 1
print("Skipping: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("To run: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 0 # Exit gracefully for CI
# Create concurrent tasks for HTTP requests
print("Starting 3 concurrent HTTP requests...")

View file

@ -25,7 +25,12 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import execute_code, CredentialsError
try:
from un_async import execute_code, CredentialsError
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def run_fibonacci(n: int, label: str, public_key: str, secret_key: str):
@ -58,9 +63,9 @@ async def main():
secret_key = os.environ.get("UNSANDBOX_SECRET_KEY")
if not public_key or not secret_key:
print("Error: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("Run with: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 1
print("Skipping: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("To run: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 0 # Exit gracefully for CI
# Create concurrent tasks for different fibonacci values
print("Starting 3 concurrent fibonacci calculations...")

View file

@ -23,7 +23,12 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import execute_code, CredentialsError
try:
from un_async import execute_code, CredentialsError, DependencyError
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def main():
@ -38,9 +43,9 @@ async def main():
secret_key = os.environ.get("UNSANDBOX_SECRET_KEY")
if not public_key or not secret_key:
print("Error: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("Run with: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 1
print("Skipping: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("To run: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 0 # Exit gracefully for CI
# Execute the code asynchronously
print("Executing code asynchronously...")

View file

@ -25,7 +25,12 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import execute_code, CredentialsError
try:
from un_async import execute_code, CredentialsError
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def run_stream_task(task_num: int, start: int, count: int, public_key: str, secret_key: str):
@ -66,9 +71,9 @@ async def main():
secret_key = os.environ.get("UNSANDBOX_SECRET_KEY")
if not public_key or not secret_key:
print("Error: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("Run with: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 1
print("Skipping: UNSANDBOX_PUBLIC_KEY and UNSANDBOX_SECRET_KEY environment variables required")
print("To run: export UNSANDBOX_PUBLIC_KEY=your-key UNSANDBOX_SECRET_KEY=your-key")
return 0 # Exit gracefully for CI
# Create concurrent tasks for stream processing
print("Processing stream of data...")

View file

@ -21,11 +21,16 @@ import os
# Add src to path for development
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from un_async import (
execute_code,
detect_language,
get_languages,
)
try:
from un_async import (
execute_code,
detect_language,
get_languages,
)
except ImportError as e:
print(f"Missing dependency: {e}")
print("Install with: pip install aiohttp")
sys.exit(0) # Exit gracefully for CI
async def async_approach():

View file

@ -103,11 +103,18 @@ import hashlib
import hmac
import json
import os
import sys
import time
import aiohttp
from pathlib import Path
from typing import Optional, Dict, Any, List
try:
import aiohttp
AIOHTTP_AVAILABLE = True
except ImportError:
AIOHTTP_AVAILABLE = False
aiohttp = None # type: ignore
API_BASE = "https://api.unsandbox.com"
POLL_DELAYS_MS = [300, 450, 700, 900, 650, 1600, 2000]
@ -119,6 +126,20 @@ class CredentialsError(Exception):
pass
class DependencyError(Exception):
"""Raised when a required dependency is not installed."""
pass
def _check_aiohttp():
"""Check if aiohttp is available, raise helpful error if not."""
if not AIOHTTP_AVAILABLE:
raise DependencyError(
"aiohttp is required for async operations. "
"Install with: pip install aiohttp"
)
def _get_unsandbox_dir() -> Path:
"""Get ~/.unsandbox directory path, creating if necessary."""
home = Path.home()
@ -230,7 +251,9 @@ async def _make_request(
Raises aiohttp.ClientError on network errors.
Raises ValueError if response is not valid JSON.
Raises DependencyError if aiohttp is not installed.
"""
_check_aiohttp()
url = f"{API_BASE}{path}"
timestamp = int(time.time())
body = json.dumps(data) if data else ""