-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathsmoke_test.py
More file actions
86 lines (69 loc) · 2.67 KB
/
Copy pathsmoke_test.py
File metadata and controls
86 lines (69 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
import argparse
import json
import subprocess
REQUESTS = [
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "container-smoke-test", "version": "1.0"},
},
},
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}},
]
def validate_responses(responses):
if not all(isinstance(response, dict) for response in responses):
raise ValueError("expected each stdout payload to be a JSON object")
response_ids = [response.get("id") for response in responses]
if len(responses) != 2 or set(response_ids) != {1, 2}:
raise ValueError(f"expected response IDs 1 and 2 only, got {response_ids}")
by_id = {response["id"]: response for response in responses}
server_info = by_id[1].get("result", {}).get("serverInfo", {})
if server_info.get("name") != "funasr":
raise ValueError(f"unexpected serverInfo: {server_info}")
tools = by_id[2].get("result", {}).get("tools", [])
tool_names = {tool.get("name") for tool in tools}
if "transcribe_audio" not in tool_names:
raise ValueError(f"transcribe_audio missing from tools/list: {tool_names}")
def parse_responses(stdout):
responses = []
for line_number, raw_line in enumerate(stdout.splitlines(), start=1):
line = raw_line.strip()
if not line:
continue
try:
responses.append(json.loads(line))
except json.JSONDecodeError as error:
raise ValueError(
f"non-JSON stdout on line {line_number}: {line[:120]}"
) from error
return responses
def run_smoke_test(image, timeout):
payload = "".join(f"{json.dumps(request)}\n" for request in REQUESTS)
completed = subprocess.run(
["docker", "run", "--rm", "-i", image],
input=payload,
text=True,
capture_output=True,
check=False,
timeout=timeout,
)
if completed.returncode != 0:
raise RuntimeError(
f"container exited with {completed.returncode}: {completed.stderr.strip()}"
)
responses = parse_responses(completed.stdout)
validate_responses(responses)
def main():
parser = argparse.ArgumentParser(description="Smoke-test the FunASR MCP image")
parser.add_argument("image", help="Local or remote container image reference")
parser.add_argument("--timeout", type=int, default=60)
args = parser.parse_args()
run_smoke_test(args.image, args.timeout)
print(f"MCP container smoke test passed: {args.image}")
if __name__ == "__main__":
main()