#!/usr/bin/env python3 """A stand-in for junction, for tests/test_junction. It answers exactly what the plugin reads: the X-Junction-Mcp identity header on /mcp (with 405, as the real one does for a GET), the status JSON only under the /v1/status alias (so the fallback is exercised), and /v1/models with the routing headers (so the header statistics have something to show). No token is required; the test is about reading the headers and the JSON, not about authentication. """ import json import sys from http.server import BaseHTTPRequestHandler, HTTPServer STATUS = { "uptime_s": 1211, "requests": {"ok": 11, "fail": 0}, "queue": {"inflight": 1, "waiting": 0, "max_inflight": 32}, "endpoints": [ {"name": "a", "probe_ok": 1, "exhausted": 0, "p95_ms": 500}, {"name": "b", "probe_ok": 0, "exhausted": 1, "p95_ms": 900}, {"name": "c", "probe_ok": 1, "exhausted": 0, "p95_ms": 300}, ], # the route of the test's model ("m"), and a catch-all behind it "rules": [ {"line": 1, "model": "m", "path": "", "targets": "a as /models/x, b as /models/y", "block": False}, {"line": 2, "model": "", "path": "/v1/models", "targets": "c", "block": False}, {"line": 3, "model": "", "path": "", "targets": "c", "block": False}, ], "mcp": [ {"name": "tasksd", "ok": 1, "fail": 0, "tools": 9}, {"name": "skilld", "ok": 1, "fail": 0, "tools": 10}, {"name": "memoryd", "ok": 1, "fail": 0, "tools": 7}, {"name": "wikid", "ok": 0, "fail": 1, "tools": 0}, {"name": "koder", "ok": 1, "fail": 0, "tools": 12}, ], } MODELS = { "object": "list", "data": [ {"id": "qwen3.6-35b"}, {"id": "beam-free"}, {"id": "iceman-contributor-free"}, ], } class Handler(BaseHTTPRequestHandler): def log_message(self, *args): pass def json(self, obj, headers=()): body = json.dumps(obj).encode() self.send_response(200) self.send_header("Content-Type", "application/json") for k, v in headers: self.send_header(k, v) self.send_header("Content-Length", str(len(body))) self.end_headers() self.wfile.write(body) def do_GET(self): if self.path == "/mcp": self.send_response(405) self.send_header("X-Junction-Mcp", "1") self.send_header("Content-Length", "0") self.end_headers() elif self.path == "/v1/status": self.json(STATUS) elif self.path == "/v1/models": self.json(MODELS, [ ("X-Junction-Endpoint", "fake"), ("X-Junction-Ms", "12"), ("X-Junction-Cache", "off"), ]) else: self.send_response(404) self.send_header("Content-Length", "0") self.end_headers() def main(): port = int(sys.argv[1]) if len(sys.argv) > 1 else 18099 HTTPServer(("127.0.0.1", port), Handler).serve_forever() if __name__ == "__main__": main()