The widget printed "endpoint=opencode-go" because that is the
X-Junction-Endpoint header of the plugin's own /v1/models probe, which
junction routes there by a path rule. It says nothing about where the
conversation goes, and the operator's qwen3.6-35b is routed to kontron and
kompute0..2 - so the line was wrong, not just imprecise.
- read the active model from the config (sp_usage_active -> provider model)
and match /status' rules against it: exact model > glob > catch-all, rules
with a path are another route. The result is the route line:
"route kontron! kompute0 kompute1 kompute2" ("!" = that target's own health
probe is not ok).
- /junction shows model, route and "route health: N/M up, down: ..."; the
/v1/models header block is marked as the probe's route, not the session's.
- the header stats label the probe values (probe-ms=, probe-cache=) and no
longer print the endpoint header as if it were the route.
- side_text(): wrap one line at a time and let a continuation use up to three
rows; passing a multi-line string to one mvwaddnstr() double-counted rows
and cut "route ... kompute1 kompute2" in half.
- test_junction: fake /status gains rules and per-endpoint probe_ok; the test
sets the run's model ("m") and expects "route a b!", "probe-ms=12",
"route health: 1/2 up, down: b" and no "endpoint=" in the stats.
make check: all tests passed.
92 lines
3.0 KiB
Python
92 lines
3.0 KiB
Python
#!/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()
|