tests: stop three ways the suite failed for the wrong reason

gcc -fanalyzer warns on snprintf("%s") between two elements of the same array
it cannot prove disjoint; memmove of the fixed-size element is what the call
did, without the warning.

mcp.py slept a fixed 1.2 s for junction to listen while junction is still
talking to its MCP servers; under load the first POST was refused and the
whole suite failed. It now waits for the port, and an empty call list is a
reported failure instead of an IndexError that leaves a router behind.

mcp_concurrency.py's fake servers kept the default listen backlog of 5. 32
simultaneous calls overflowed it, two came back "MCP server unavailable" and
the fast server looked slow (1.22 s, 38/40 intact). With backlog 128: 40/40
intact, fast answers in 0.05 s.

check_ports.py resolves variables in file order (RDP is a stub port and later a
router port) and sees env-prefixed stub starts; run.sh prints who holds a port
when wait_port gives up.

Full suite: 537 OK, 0 FAIL, PASS. Installed and restarted; /admin, /spend and
/metrics answer 403 from the LAN and 200 on loopback, streams stay clean.
This commit is contained in:
Hermes committed 2026-11-18 23:47:14 +00:00
1 parent beb9f4be16
commit 107de9e39e
5 files changed
+60 -14

No files matched your search

+7 -6
View File
@@ -4374,12 +4374,13 @@ static void handle_client_inner(j_conn *client)
judge_len = 0;
}
for (int k = rule_copy.target_count - 1; k >= 0; k--) {
snprintf(rule_copy.targets[k + slots],
sizeof rule_copy.targets[k + slots], "%s",
rule_copy.targets[k]);
snprintf(rule_copy.target_as[k + slots],
sizeof rule_copy.target_as[k + slots], "%s",
rule_copy.target_as[k]);
/* memmove, not snprintf("%s"): the analyzer cannot prove
* the two array elements do not overlap and warns on every
* build. Copying the fixed-size element is what "%s" did. */
memmove(rule_copy.targets[k + slots],
rule_copy.targets[k], sizeof rule_copy.targets[k]);
memmove(rule_copy.target_as[k + slots],
rule_copy.target_as[k], sizeof rule_copy.target_as[k]);
}
if (judge_pool) {
for (int c = 0; c < judge_pool->count; c++) {
+11 -3
View File
@@ -20,7 +20,7 @@ ASSIGN = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*)=(.+)$")
EXPR = re.compile(r"^\$\(\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\+\s*(\d+)\s*\)\)$")
VAR = re.compile(r"^\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?$")
LISTEN = re.compile(r"\blisten\s+[^:\s]+:(\S+)")
STUB = re.compile(r"^\s*(?:tests/)?stub\s+(\S+)")
STUB = re.compile(r"(?:\S*/)?tests/stub\s+(\S+)")
def assignments(text):
@@ -60,13 +60,21 @@ def main():
sites = {}
unresolved = 0
for name, text in sources.items():
# A variable can be reassigned in the same file (RDP is one port for
# the stub and another for the router later on); resolve in file order
# so each site sees the value it really had.
local = dict(values)
for no, line in enumerate(text.splitlines(), 1):
for var, raw in assignments(line):
v = resolve(raw, local)
if v is not None:
local[var] = v
if "printf" in line:
continue # throwaway configs that are only --check'ed
m = LISTEN.search(line) or STUB.match(line)
m = LISTEN.search(line) or STUB.search(line)
if not m:
continue
port = resolve(m.group(1), values)
port = resolve(m.group(1), local)
if port is None:
unresolved += 1
continue
+28 -4
View File
@@ -14,6 +14,7 @@ HTTP, was ein Agent tatsächlich sieht:
"""
import json
import os
import socket
import subprocess
import sys
import tempfile
@@ -138,6 +139,24 @@ def post(url, payload, timeout=25, headers=None):
return status, body
def wait_port(port, timeout=30.0):
"""Wait for the listener instead of sleeping.
Junction talks to its MCP servers while it starts; a fixed 1.2 s was
enough on an idle box and too short under load, and the first POST then
failed with "connection refused" -- the whole suite failed for a test that
had simply looked too early.
"""
end = time.time() + timeout
while time.time() < end:
try:
with socket.create_connection(("127.0.0.1", port), timeout=0.5):
return True
except OSError:
time.sleep(0.05)
return False
def main():
servers = {}
for name in TOOLS:
@@ -167,7 +186,10 @@ endpoint dummy {{
""")
proc = subprocess.Popen([JUNCTION, "--config", conf],
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
time.sleep(1.2)
if not wait_port(PORT):
proc.kill()
print("FAIL: junction did not listen on", PORT)
sys.exit(1)
base = f"http://127.0.0.1:{PORT}/mcp"
failures = []
@@ -214,8 +236,9 @@ endpoint dummy {{
st, body = post(base, {"jsonrpc": "2.0", "id": 4, "method": "tools/call",
"params": {"name": "tasksd__task_create",
"arguments": {"goal": "Test mit Ümlaut"}}})
if calls[-1] != ("tasksd", "task_create", {"goal": "Test mit Ümlaut"}):
failures.append(f"Argumente verstümmelt: {calls[-1]}")
if not calls or calls[-1] != ("tasksd", "task_create",
{"goal": "Test mit Ümlaut"}):
failures.append(f"Argumente verstümmelt: {calls[-1:] or 'kein Aufruf'}")
# 4. unbekanntes Werkzeug wird abgelehnt
st, body = post(base, {"jsonrpc": "2.0", "id": 5, "method": "tools/call",
@@ -318,7 +341,8 @@ endpoint dummy {{
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
env=env)
try:
time.sleep(1.2)
if not wait_port(PORT + 1):
failures.append("the auth instance did not listen")
base2 = f"http://127.0.0.1:{PORT + 1}/mcp"
st, body = post(base2, {"jsonrpc": "2.0", "id": 1, "method": "tools/list"})
if st == 401 and "mcp_key_required" in body:
+8 -1
View File
@@ -125,7 +125,14 @@ def post(url, payload, timeout=40):
def main():
fast_port, slow_port = freier_port(), freier_port()
for which, port in (("fast", fast_port), ("slow", slow_port)):
srv = ThreadingHTTPServer(("127.0.0.1", port), make_handler(which))
# The default backlog is 5. Thirty-two simultaneous connections then
# overflow the listen queue and two calls fail with "server
# unavailable" -- a property of this fake server, not of junction.
class Srv(ThreadingHTTPServer):
request_queue_size = 128
daemon_threads = True
srv = Srv(("127.0.0.1", port), make_handler(which))
threading.Thread(target=srv.serve_forever, daemon=True).start()
tmp = tempfile.mkdtemp()
+6
View File
@@ -45,6 +45,12 @@ wait_port() {
if (exec 3<>"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then exec 3>&-; return 0; fi
sleep 0.05; i=$((i+1))
done
# A bind failure is otherwise invisible: the stub dies and the check that
# needed it fails with a message about the router's behaviour. Name the
# process that holds the port (measured: a stub could not bind 8380 and
# nothing said who had it).
echo " (port $port never came up; listeners on it:)" >&2
ss -ltnp 2>/dev/null | grep ":$port " | sed 's/^/ /' >&2 || true
return 1
}