Files
xinmi/mcp-server/test_stdio_stdout.py
T
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

54 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Regression: MCP stdio entry scripts must not write diagnostics to stdout."""
import subprocess
import sys
import unittest
from pathlib import Path
MCP_SERVER_DIR = Path(__file__).resolve().parent
class StdioStdoutPurityTest(unittest.TestCase):
def test_main_check_only_keeps_stdout_empty(self):
result = subprocess.run(
[sys.executable, "main.py", "--check-only"],
capture_output=True,
timeout=10,
cwd=MCP_SERVER_DIR,
)
self.assertEqual(result.returncode, 0)
self.assertEqual(
result.stdout,
b"",
f"stdout must stay empty for MCP stdio compatibility, got: {result.stdout!r}",
)
self.assertTrue(
result.stderr,
"environment check output should appear on stderr",
)
def test_run_server_startup_keeps_stdout_empty(self):
proc = subprocess.Popen(
[sys.executable, "run_server.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=MCP_SERVER_DIR,
)
try:
stdout, stderr = proc.communicate(timeout=2)
except subprocess.TimeoutExpired:
proc.terminate()
stdout, stderr = proc.communicate(timeout=5)
self.assertEqual(
stdout,
b"",
f"run_server.py must not write to stdout before JSON-RPC, got: {stdout!r}",
)
self.assertTrue(stderr, "startup diagnostics should appear on stderr")
if __name__ == "__main__":
unittest.main()