Files
OBLITERATUS/tests/test_mcp_probe_failures.py
Joseph Magly 002e6e56e1 feat: complete local readiness across UI, MCP and memory admission
Integrate bounded admission, UI ownership and controls, opt-in durable MCP execution, rank-local TP2 groundwork, regression hardening and operator guides. Physical larger-memory and two-host qualification remain separate.
2026-10-20 17:58:20 -04:00

63 lines
2.4 KiB
Python

"""Independent interoperability probes must reject false success evidence."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from obliteratus import mcp_probe as probe
@pytest.mark.parametrize(("payload", "message"), [
({"jsonrpc": "1.0", "id": 1, "result": {}}, "protocol contamination"),
({"jsonrpc": "2.0", "id": 1, "error": {"code": -32000}}, "RPC error"),
])
def test_raw_probe_rejects_invalid_initialization(payload, message):
script = "import sys; sys.stdin.readline(); print(" + repr(json.dumps(payload)) + ", flush=True)"
with pytest.raises(ValueError, match=message):
probe.raw_probe(Path("/unused"), ["-u", "-c", script], 2)
def test_raw_probe_rejects_disconnected_server():
with pytest.raises(ValueError, match="disconnected"):
probe.raw_probe(Path("/unused"), ["-c", "pass"], 2)
def test_raw_probe_enforces_timeout_without_waiting_for_server_exit():
script = "import sys; sys.stdin.readline(); sys.stdin.read()"
with pytest.raises(TimeoutError, match="probe timeout"):
probe.raw_probe(Path("/unused"), ["-u", "-c", script], 1)
def test_raw_probe_bounds_unterminated_response(monkeypatch):
monkeypatch.setattr(probe, "MAX_FRAME", 64)
script = "import sys; sys.stdin.readline(); sys.stdout.write('x' * 256); sys.stdout.flush()"
with pytest.raises(ValueError, match="frame ceiling"):
probe.raw_probe(Path("/unused"), ["-u", "-c", script], 2)
def test_raw_probe_rejects_incomplete_tool_catalog():
script = (
"import sys,json\n"
"for line in sys.stdin:\n"
" request=json.loads(line)\n"
" if 'id' not in request: continue\n"
" result={'protocolVersion':'2025-11-25'} if request['method']=='initialize' else {'tools':[]}\n"
" print(json.dumps({'jsonrpc':'2.0','id':request['id'],'result':result}),flush=True)\n"
)
with pytest.raises(ValueError, match="unexpected tool list"):
probe.raw_probe(Path("/unused"), ["-u", "-c", script], 2)
def test_probe_main_redacts_failure_and_emits_no_success(monkeypatch, capsys):
def fail(root):
raise ValueError("sensitive-probe-value")
monkeypatch.setattr(probe, "fixture", fail)
assert probe.main(["--client", "raw"]) == 1
captured = capsys.readouterr()
assert captured.out == ""
assert "no successful interoperability evidence" in captured.err
assert "sensitive-probe-value" not in captured.err