ローカル画像添付機能をjson-to-pptxに追加#40
Conversation
WalkthroughJSON→PPTX 変換にローカル画像ファイルサポートを追加。CLI、クライアント、MCP サーバーで Changes
Sequence Diagram(s)sequenceDiagram
participant User as User/CLI
participant FS as Filesystem
participant CLI as CLI Handler
participant Client as Client
participant Server as Middleman API
User->>CLI: json-to-pptx-execute --images image.png
CLI->>FS: (optional) validate file exists/readable
CLI->>Client: json_to_pptx_execute_v2(template_id, presentation, image_paths)
Client->>FS: open/read image.png
Client->>Client: infer MIME type, build multipart/form-data
Client->>Server: POST /api/v2/tools/json-to-pptx/execute/form (presentation_json, pptx_template_id, files)
Server-->>Client: 200 { result_data: { pptx_url, ... } }
Client->>CLI: return pptx_url
CLI->>User: print pptx_url
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/test_client_vcr.py (1)
164-165:⚠️ Potential issue | 🔴 Criticalパイプライン失敗の原因:
match_onパラメータの欠落エンドポイントが
/executeから/execute/formに変更され、リクエスト形式がJSONからフォームエンコードに変わったため、このテストにもmatch_onパラメータが必要です。CIの失敗はこれが原因です。🐛 修正案
-@pytest.mark.vcr() +@pytest.mark.vcr(match_on=["method", "scheme", "port", "path", "query"]) def test_json_to_pptx_execute_v2_vcr(client: ToolsClient) -> None:As per coding guidelines, ファイルアップロードを伴うマルチパートリクエストのテストでは、
match_onパラメータを使用してマッチング条件を調整する必要があります。
🤖 Fix all issues with AI agents
In `@tests/cassettes/test_json_to_pptx_execute_v2_vcr.yaml`:
- Around line 1-46:
テストデコレータのVCRマッチ設定が古いままなのでボディ形式(JSON→form)が一致せずCIが失敗しています。tests 内の
test_json_to_pptx_execute_v2_vcr の `@pytest.mark.vcr`()
デコレータを、test_json_to_pptx_execute_v2_with_images_vcr と同じ match_on 設定(ボディ比較を適切に扱う
match_on を含む)に変更して、フォームエンコードされたリクエストボディでのマッチングを許可してください(テスト名:
test_json_to_pptx_execute_v2_vcr、参照テスト:
test_json_to_pptx_execute_v2_with_images_vcr、デコレータ: `@pytest.mark.vcr`)。
🧹 Nitpick comments (3)
tests/test_mcp.py (1)
3-3: Line 287 のfrom pathlib import Pathがモジュールレベルのインポートと重複しています。Line 3 で
Pathがモジュールレベルでインポートされたため、test_mermaid_file_to_image_tool_mcp内(Line 287)のローカルインポートは不要になっています。♻️ 修正案
Line 287 のローカルインポートを削除:
def test_mermaid_file_to_image_tool_mcp(mocker: "MockerFixture") -> None: """mermaid_file_to_imageツールのテスト。""" - from pathlib import Path - mock_client = mocker.patch("middleman_ai.mcp.server.client")src/middleman_ai/mcp/server.py (1)
215-223: 画像パスバリデーションロジックの重複。Lines 68-76 の
md_file_to_pdf内の画像バリデーションと完全に同一のコードです。ヘルパー関数への抽出を検討してください。♻️ 例: ヘルパー関数の抽出
+def _validate_image_paths(image_paths: List[str]) -> None: + """画像パスの存在・ファイル・読み取り権限を検証します。""" + for img_path in image_paths: + img_file = Path(img_path) + if not img_file.exists(): + raise ValueError(f"Image file not found: {img_path}") + if not img_file.is_file(): + raise ValueError(f"Image path is not a file: {img_path}") + if not os.access(img_file, os.R_OK): + raise ValueError(f"Image file not readable: {img_path}")
md_file_to_pdfとjson_to_pptx_executeの両方でif image_paths: _validate_image_paths(image_paths)として利用可能です。tests/test_client.py (1)
620-631:image_pathsを指定した場合のクライアントテストが不足しています。
json_to_pptx_execute_v2はimage_pathsを受け取ってマルチパート送信する新機能がありますが、test_client.pyにはその経路のテストがありません。画像ファイルを渡した場合のfilesパラメータ構成やMIMEタイプ推測を検証するテストを追加することを推奨します。
Summary by CodeRabbit
New Features
Documentation
Tests
Chores