summaryrefslogtreecommitdiff
path: root/tests/test_compose_mml_tool.py
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-09-13 14:12:41 +0900
committertanaka takashi <isazaka@gmail.com>2026-09-13 14:13:04 +0900
commit97b34627667fd699f4e0e054533eb89a205a2878 (patch)
tree1d4549d56b7c53be9ecb583db9bb1a5593e54126 /tests/test_compose_mml_tool.py
parent3b5bd2f8fd15bcc13542ff5ffd3c35453af9a9df (diff)
feat: return composed WAV as MCP audio content
Replace the server-local wav_path result with a protocol-native multimedia response. - Split internal composition execution from MCP ToolResult serialization so filesystem paths never enter public payloads. - Return every successfully composed WAV as AudioContent with the audio/wav MIME type, regardless of file size. - Keep structured audio metadata, duration, note sequence, and validation details alongside the multimedia content. - Use CallToolResult.isError as the authoritative MCP execution status while retaining compose success and validate valid as domain fields. - Treat invalid compose/API requests and runtime failures as tool errors, while invalid MML discovered by validate remains a successful validation operation. - Sanitize synthesis, file-write, audio-serialization, and unexpected failure responses so internal paths and exception details are not exposed. - Add protocol-level coverage for base64 round trips, content block types, error semantics, ResourceLink absence, and path non-disclosure. - Update existing tests for the separated execution layer and path-free result contract. - Document AudioContent and isError behavior in the README, MCP schema, and design specification. - Require the tested FastMCP 3.4.4 API line and exclude the incompatible 4.x major version. Verification: 487 tests passed; ruff check passed; git diff --check passed; uv lock --check passed; and a manual MCP call returned TextContent plus AudioContent with no wav_path.
Diffstat (limited to 'tests/test_compose_mml_tool.py')
-rw-r--r--tests/test_compose_mml_tool.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/tests/test_compose_mml_tool.py b/tests/test_compose_mml_tool.py
index c33e737..4f904e4 100644
--- a/tests/test_compose_mml_tool.py
+++ b/tests/test_compose_mml_tool.py
@@ -1,7 +1,5 @@
"""Exhaustive tests for the compose_mml MCP tool."""
-from pathlib import Path
-
VALID_PPMCK = """#TITLE "Test"
A t120 l4 o4 v15 q2
c e g c
@@ -27,8 +25,10 @@ VALID_PYXEL = """0: T120 L4 O4 V100 @1
def test_compose_ppmck(compose_mml, tmp_output_dir):
result = compose_mml(action="compose", mml=VALID_PPMCK, mode="ppmck")
assert result["success"] is True
- assert result["wav_path"] is not None
- assert Path(result["wav_path"]).exists()
+ assert result["audio"]["mime_type"] == "audio/wav"
+ assert result["audio"]["size_bytes"] > 44
+ assert "wav_path" not in result
+ assert list(tmp_output_dir.rglob("output.wav"))
assert result["duration_sec"] > 0
assert result["note_sequence"] is not None
assert "validation" in result
@@ -39,8 +39,9 @@ def test_compose_ppmck(compose_mml, tmp_output_dir):
def test_compose_pyxel(compose_mml, tmp_output_dir):
result = compose_mml(action="compose", mml=VALID_PYXEL, mode="pyxel")
assert result["success"] is True
- assert result["wav_path"] is not None
- assert Path(result["wav_path"]).exists()
+ assert result["audio"]["mime_type"] == "audio/wav"
+ assert "wav_path" not in result
+ assert list(tmp_output_dir.rglob("output.wav"))
assert result["duration_sec"] > 0
@@ -95,7 +96,7 @@ def test_synthesis_templates_compose(compose_mml, tmp_output_dir):
f"{mode}/{template} synthesis failed: {result['validation']}"
)
assert result["duration_sec"] > 0
- assert Path(result["wav_path"]).exists()
+ assert result["audio"]["size_bytes"] > 44
def test_template_invalid_fallback(compose_mml):
@@ -131,7 +132,8 @@ def test_compose_unknown_mode(compose_mml):
def test_compose_with_syntax_error(compose_mml):
result = compose_mml(action="compose", mml="A t0\n c", mode="ppmck")
assert result["success"] is False
- assert result["wav_path"] is None
+ assert result["audio"] is None
+ assert "wav_path" not in result
assert result["duration_sec"] == 0
assert any(e["severity"] == "error" for e in result["validation"]["errors"])
@@ -168,8 +170,7 @@ def test_compose_normalize(compose_mml, tmp_output_dir):
on = compose_mml(action="compose", mml=base, mode="pyxel", normalize=True)
off = compose_mml(action="compose", mml=base, mode="pyxel", normalize=False)
assert on["success"] and off["success"]
- assert Path(on["wav_path"]).exists()
- assert Path(off["wav_path"]).exists()
+ assert len(list(tmp_output_dir.rglob("output.wav"))) == 2
def test_compose_creates_timestamped_output_directory(compose_mml, tmp_output_dir):
@@ -182,14 +183,9 @@ def test_compose_creates_timestamped_output_directory(compose_mml, tmp_output_di
assert result1["success"] is True
assert result2["success"] is True
- path1 = result1["wav_path"]
- path2 = result2["wav_path"]
- assert path1 is not None
- assert path2 is not None
- assert path1 != path2, "Two compose calls produced the same output directory"
-
- p1 = Path(path1)
- p2 = Path(path2)
+ paths = sorted(tmp_output_dir.rglob("output.wav"))
+ assert len(paths) == 2
+ p1, p2 = paths
assert p1.exists()
assert p2.exists()
assert p1.name == "output.wav"