"""Fixtures for the MCP wrapper test suite.""" from __future__ import annotations import json from dataclasses import dataclass @dataclass class FakeProc: stdout: str stderr: str = "" returncode: int = 0 def make_runner(envelope: dict | None = None, *, stdout: str | None = None, stderr: str = "", returncode: int = 0): """Return a callable compatible with :func:`subprocess.run`. Records the most recent ``cmd`` on ``runner.calls``. """ calls: list[list[str]] = [] def runner(cmd, capture_output=True, text=True, check=False): # noqa: ARG001 calls.append(list(cmd)) if stdout is not None: s = stdout else: s = json.dumps(envelope if envelope is not None else {"ok": True, "command": "x", "status": "ok"}) return FakeProc(stdout=s, stderr=stderr, returncode=returncode) runner.calls = calls # type: ignore[attr-defined] return runner