refactor(cli): update API endpoints to v1 versioning and add dynamic port configuration to mock server
- Update mock-cli-server.py to use dynamic port allocation (8020-8050 range) - Add socket-based port availability checking - Generate dynamic config file at cli-dev/cli-staging-config-dynamic.yaml - Remove docstring header and shebang - Update endpoint paths: /v1/marketplace/gpus → /v1/marketplace/gpu/list, /v1/agent/workflows → /v1/agents/workflows - Standardize all CLI command API
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
CLI Mock Server for Testing
|
||||
Provides mock responses for CLI testing without affecting production
|
||||
"""
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
import uvicorn
|
||||
import json
|
||||
import socket
|
||||
from datetime import datetime
|
||||
|
||||
app = FastAPI(title="CLI Mock Server", version="1.0.0")
|
||||
@@ -29,7 +23,7 @@ async def mock_v1_health():
|
||||
"python_version": "3.13.5"
|
||||
}
|
||||
|
||||
@app.get("/v1/marketplace/gpus")
|
||||
@app.get("/v1/marketplace/gpu/list")
|
||||
async def mock_marketplace_gpus():
|
||||
return [
|
||||
{
|
||||
@@ -62,7 +56,7 @@ async def mock_marketplace_offers():
|
||||
}
|
||||
]
|
||||
|
||||
@app.get("/v1/agent/workflows")
|
||||
@app.get("/v1/agents/workflows")
|
||||
async def mock_agent_workflows():
|
||||
return [
|
||||
{
|
||||
@@ -83,6 +77,32 @@ async def mock_blockchain_status():
|
||||
"tx_count": 678
|
||||
}
|
||||
|
||||
def find_available_port(start_port=8020, max_port=8050):
|
||||
for port in range(start_port, max_port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
if s.connect_ex(('127.0.0.1', port)) != 0:
|
||||
return port
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Starting CLI Mock Server on port 8001...")
|
||||
uvicorn.run(app, host="127.0.0.1", port=8001, log_level="info")
|
||||
port = find_available_port()
|
||||
if port:
|
||||
print(f"Starting CLI Mock Server on port {port}...")
|
||||
|
||||
# Write config for CLI to use
|
||||
config_path = "/home/oib/windsurf/aitbc/cli-dev/cli-staging-config-dynamic.yaml"
|
||||
with open(config_path, "w") as f:
|
||||
f.write(f"""coordinator_url: http://127.0.0.1:{port}
|
||||
api_key: null
|
||||
output_format: table
|
||||
config_file: {config_path}
|
||||
test_mode: true
|
||||
timeout: 30
|
||||
debug: true
|
||||
staging: true
|
||||
""")
|
||||
print(f"Created config file for this port at {config_path}")
|
||||
|
||||
uvicorn.run(app, host="127.0.0.1", port=port, log_level="info")
|
||||
else:
|
||||
print("Error: Could not find an available port in range 8020-8050")
|
||||
|
||||
Reference in New Issue
Block a user