From c9feec85edaa3d734c57cf4cc180abd584991c0b Mon Sep 17 00:00:00 2001 From: nitinkoberoii Date: Wed, 25 Nov 2026 02:40:30 +0530 Subject: [PATCH 1/2] fix(mcp): serialize UUID parameters in fixes and knowledge subclients --- proofline/_mcp.py | 33 +++++++-- proofline/fixes.py | 57 +++++++++------ proofline/knowledge.py | 78 ++++++++++++++------ tests/test_http.py | 158 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+), 47 deletions(-) diff --git a/proofline/_mcp.py b/proofline/_mcp.py index f80c5e00..d21993f7 100644 --- a/proofline/_mcp.py +++ b/proofline/_mcp.py @@ -4,6 +4,7 @@ import json from typing import Any, NotRequired, TypedDict, cast +from uuid import UUID import httpx2 @@ -27,12 +28,24 @@ def _refused() -> ProoflineError: return ProoflineError(0, "urn:proofline:sdk:mcp", "Invalid or refused MCP response.") +def _serialize_mcp_value(val: Any) -> Any: + if isinstance(val, UUID): + return str(val) + if isinstance(val, list): + return [_serialize_mcp_value(x) for x in val] + if isinstance(val, tuple): + return [_serialize_mcp_value(x) for x in val] + if isinstance(val, dict): + return {key: _serialize_mcp_value(v) for key, v in val.items()} + return val + + def _body(method: str, params: dict[str, Any] | None, identity: int | None) -> bytes: value: dict[str, Any] = {"jsonrpc": "2.0", "method": method} if identity is not None: value["id"] = identity if params is not None: - value["params"] = params + value["params"] = _serialize_mcp_value(params) data = json.dumps(value).encode("utf-8") if len(data) > 8192: raise ValueError("MCP request exceeds 8192 bytes.") @@ -96,10 +109,15 @@ def __init__(self, http: httpx2.Client) -> None: self._http = http def _call( - self, name: str, args: dict[str, Any], *, organization_id: str | None = None + self, name: str, args: dict[str, Any], *, organization_id: UUID | str | None = None ) -> KnowledgeResult: if organization_id is not None: - args = {**args, "organization_id": organization_id} + args = { + **args, + "organization_id": ( + str(organization_id) if isinstance(organization_id, UUID) else organization_id + ), + } call = _body("tools/call", {"name": name, "arguments": args}, 2) frames = [ ( @@ -145,10 +163,15 @@ def __init__(self, http: httpx2.AsyncClient) -> None: self._http = http async def _call( - self, name: str, args: dict[str, Any], *, organization_id: str | None = None + self, name: str, args: dict[str, Any], *, organization_id: UUID | str | None = None ) -> KnowledgeResult: if organization_id is not None: - args = {**args, "organization_id": organization_id} + args = { + **args, + "organization_id": ( + str(organization_id) if isinstance(organization_id, UUID) else organization_id + ), + } call = _body("tools/call", {"name": name, "arguments": args}, 2) frames = [ ( diff --git a/proofline/fixes.py b/proofline/fixes.py index 85e437b5..919a9aa5 100644 --- a/proofline/fixes.py +++ b/proofline/fixes.py @@ -3,13 +3,18 @@ from __future__ import annotations from typing import Any +from uuid import UUID from ._mcp import AsyncMcpTools, KnowledgeResult, McpTools class FixesClient(McpTools): def list_open_findings( - self, repository: str, pull_request_number: int, *, organization_id: str | None = None + self, + repository: str, + pull_request_number: int, + *, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return self._call( "list_open_findings", @@ -18,24 +23,26 @@ def list_open_findings( ) def get_fix_context( - self, finding_id: str, *, organization_id: str | None = None + self, finding_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return self._call( - "get_fix_context", {"finding_id": finding_id}, organization_id=organization_id + "get_fix_context", + {"finding_id": str(finding_id) if isinstance(finding_id, UUID) else finding_id}, + organization_id=organization_id, ) def request_reverification( self, - review_id: str, - finding_ids: list[str], + review_id: UUID | str, + finding_ids: list[UUID | str], commit_sha: str, *, note: str | None = None, - organization_id: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: args: dict[str, Any] = { - "review_id": review_id, - "finding_ids": finding_ids, + "review_id": str(review_id) if isinstance(review_id, UUID) else review_id, + "finding_ids": [str(f) if isinstance(f, UUID) else f for f in finding_ids], "commit_sha": commit_sha, } if note is not None: @@ -43,16 +50,22 @@ def request_reverification( return self._call("request_reverification", args, organization_id=organization_id) def get_reverification( - self, request_id: str, *, organization_id: str | None = None + self, request_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return self._call( - "get_reverification", {"request_id": request_id}, organization_id=organization_id + "get_reverification", + {"request_id": str(request_id) if isinstance(request_id, UUID) else request_id}, + organization_id=organization_id, ) class AsyncFixesClient(AsyncMcpTools): async def list_open_findings( - self, repository: str, pull_request_number: int, *, organization_id: str | None = None + self, + repository: str, + pull_request_number: int, + *, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return await self._call( "list_open_findings", @@ -61,24 +74,26 @@ async def list_open_findings( ) async def get_fix_context( - self, finding_id: str, *, organization_id: str | None = None + self, finding_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return await self._call( - "get_fix_context", {"finding_id": finding_id}, organization_id=organization_id + "get_fix_context", + {"finding_id": str(finding_id) if isinstance(finding_id, UUID) else finding_id}, + organization_id=organization_id, ) async def request_reverification( self, - review_id: str, - finding_ids: list[str], + review_id: UUID | str, + finding_ids: list[UUID | str], commit_sha: str, *, note: str | None = None, - organization_id: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: args: dict[str, Any] = { - "review_id": review_id, - "finding_ids": finding_ids, + "review_id": str(review_id) if isinstance(review_id, UUID) else review_id, + "finding_ids": [str(f) if isinstance(f, UUID) else f for f in finding_ids], "commit_sha": commit_sha, } if note is not None: @@ -86,8 +101,10 @@ async def request_reverification( return await self._call("request_reverification", args, organization_id=organization_id) async def get_reverification( - self, request_id: str, *, organization_id: str | None = None + self, request_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return await self._call( - "get_reverification", {"request_id": request_id}, organization_id=organization_id + "get_reverification", + {"request_id": str(request_id) if isinstance(request_id, UUID) else request_id}, + organization_id=organization_id, ) diff --git a/proofline/knowledge.py b/proofline/knowledge.py index 2a301cf5..9c88d03a 100644 --- a/proofline/knowledge.py +++ b/proofline/knowledge.py @@ -1,11 +1,19 @@ """Published knowledge operations through the scoped MCP server.""" +from __future__ import annotations + +from uuid import UUID + from ._mcp import AsyncMcpTools, KnowledgeResult, McpTools, _repository class KnowledgeClient(McpTools): def list_wiki_pages( - self, repository: str, *, commit: str | None = None, organization_id: str | None = None + self, + repository: str, + *, + commit: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return self._call( "list_wiki_pages", _repository(repository, commit), organization_id=organization_id @@ -17,7 +25,7 @@ def get_wiki_page( page_key: str, *, commit: str | None = None, - organization_id: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return self._call( "get_wiki_page", @@ -31,7 +39,7 @@ def ask_codebase( question: str, *, commit: str | None = None, - organization_id: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return self._call( "ask_codebase", @@ -40,37 +48,53 @@ def ask_codebase( ) def get_architecture_document( - self, environment_id: str, *, organization_id: str | None = None + self, environment_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: + env_id = str(environment_id) if isinstance(environment_id, UUID) else environment_id return self._call( "get_architecture_document", - {"environment_id": environment_id}, + {"environment_id": env_id}, organization_id=organization_id, ) - def get_plan(self, plan_id: str, *, organization_id: str | None = None) -> KnowledgeResult: - return self._call("get_plan", {"plan_id": plan_id}, organization_id=organization_id) + def get_plan( + self, plan_id: UUID | str, *, organization_id: UUID | str | None = None + ) -> KnowledgeResult: + return self._call( + "get_plan", + {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, + organization_id=organization_id, + ) def start_plan_implementation( - self, plan_id: str, *, organization_id: str | None = None + self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return self._call( - "start_plan_implementation", {"plan_id": plan_id}, organization_id=organization_id + "start_plan_implementation", + {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, + organization_id=organization_id, ) def get_plan_implementation( - self, implementation_id: str, *, organization_id: str | None = None + self, implementation_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: + impl_id = ( + str(implementation_id) if isinstance(implementation_id, UUID) else implementation_id + ) return self._call( "get_plan_implementation", - {"implementation_id": implementation_id}, + {"implementation_id": impl_id}, organization_id=organization_id, ) class AsyncKnowledgeClient(AsyncMcpTools): async def list_wiki_pages( - self, repository: str, *, commit: str | None = None, organization_id: str | None = None + self, + repository: str, + *, + commit: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return await self._call( "list_wiki_pages", _repository(repository, commit), organization_id=organization_id @@ -82,7 +106,7 @@ async def get_wiki_page( page_key: str, *, commit: str | None = None, - organization_id: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return await self._call( "get_wiki_page", @@ -96,7 +120,7 @@ async def ask_codebase( question: str, *, commit: str | None = None, - organization_id: str | None = None, + organization_id: UUID | str | None = None, ) -> KnowledgeResult: return await self._call( "ask_codebase", @@ -105,31 +129,41 @@ async def ask_codebase( ) async def get_architecture_document( - self, environment_id: str, *, organization_id: str | None = None + self, environment_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: + env_id = str(environment_id) if isinstance(environment_id, UUID) else environment_id return await self._call( "get_architecture_document", - {"environment_id": environment_id}, + {"environment_id": env_id}, organization_id=organization_id, ) async def get_plan( - self, plan_id: str, *, organization_id: str | None = None + self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - return await self._call("get_plan", {"plan_id": plan_id}, organization_id=organization_id) + return await self._call( + "get_plan", + {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, + organization_id=organization_id, + ) async def start_plan_implementation( - self, plan_id: str, *, organization_id: str | None = None + self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return await self._call( - "start_plan_implementation", {"plan_id": plan_id}, organization_id=organization_id + "start_plan_implementation", + {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, + organization_id=organization_id, ) async def get_plan_implementation( - self, implementation_id: str, *, organization_id: str | None = None + self, implementation_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: + impl_id = ( + str(implementation_id) if isinstance(implementation_id, UUID) else implementation_id + ) return await self._call( "get_plan_implementation", - {"implementation_id": implementation_id}, + {"implementation_id": impl_id}, organization_id=organization_id, ) diff --git a/tests/test_http.py b/tests/test_http.py index 0af9d60f..71b664af 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -2586,3 +2586,161 @@ def respond(request: Request, index: int) -> Reply: assert len(exported.rows) == 1 assert exported.rows[0]["claim"] == row["claim"] assert exported.next_cursor == "next-page" + + +@MODES +async def test_mcp_uuid_parameters_serialize(mode: str) -> None: + observed: list[dict[str, Any]] = [] + + def respond(request: Request, index: int) -> Reply: + body = json.loads(request.body) + if body["method"] == "initialize": + return Reply( + body={"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2025-11-25"}} + ) + if body["method"] == "notifications/initialized": + return Reply(status=202, body=b"") + params = body["params"] + observed.append(params) + return Reply( + body={ + "jsonrpc": "2.0", + "id": 2, + "result": { + "content": [{"type": "text", "text": "{}"}], + "structuredContent": {"arguments": params["arguments"]}, + }, + } + ) + + cases = [ + # Knowledge methods: + ( + "knowledge", + "list_wiki_pages", + ("owner/name",), + {"commit": "a" * 40, "organization_id": ORG}, + {"repository": "owner/name", "commit": "a" * 40, "organization_id": str(ORG)}, + ), + ( + "knowledge", + "get_wiki_page", + ("owner/name", "index"), + {"commit": "a" * 40, "organization_id": ORG}, + { + "repository": "owner/name", + "commit": "a" * 40, + "page_key": "index", + "organization_id": str(ORG), + }, + ), + ( + "knowledge", + "ask_codebase", + ("owner/name", "How?"), + {"commit": "a" * 40, "organization_id": ORG}, + { + "repository": "owner/name", + "commit": "a" * 40, + "question": "How?", + "organization_id": str(ORG), + }, + ), + ( + "knowledge", + "get_architecture_document", + (ASSESSMENT,), + {"organization_id": ORG}, + {"environment_id": str(ASSESSMENT), "organization_id": str(ORG)}, + ), + ( + "knowledge", + "get_plan", + (REVIEW,), + {"organization_id": ORG}, + {"plan_id": str(REVIEW), "organization_id": str(ORG)}, + ), + ( + "knowledge", + "start_plan_implementation", + (REVIEW,), + {"organization_id": ORG}, + {"plan_id": str(REVIEW), "organization_id": str(ORG)}, + ), + ( + "knowledge", + "get_plan_implementation", + (REVIEW,), + {"organization_id": ORG}, + {"implementation_id": str(REVIEW), "organization_id": str(ORG)}, + ), + # Fixes methods: + ( + "fixes", + "list_open_findings", + ("owner/name", 7), + {"organization_id": ORG}, + {"repository": "owner/name", "pull_request_number": 7, "organization_id": str(ORG)}, + ), + ( + "fixes", + "get_fix_context", + (FINDING,), + {"organization_id": ORG}, + {"finding_id": str(FINDING), "organization_id": str(ORG)}, + ), + ( + "fixes", + "request_reverification", + (REVIEW, [FINDING], "a" * 40), + {"note": "fixed", "organization_id": ORG}, + { + "review_id": str(REVIEW), + "finding_ids": [str(FINDING)], + "commit_sha": "a" * 40, + "note": "fixed", + "organization_id": str(ORG), + }, + ), + ( + "fixes", + "get_reverification", + (REVIEW,), + {"organization_id": ORG}, + {"request_id": str(REVIEW), "organization_id": str(ORG)}, + ), + ] + + with Server(respond) as server: + async with session(mode, server.url) as client: + + async def invoke(group: str, name: str, *args: Any, **kwargs: Any) -> Any: + result = getattr(getattr(client, group), name)(*args, **kwargs) + return await result if inspect.isawaitable(result) else result + + for group, name, args, kwargs, expected in cases: + observed.clear() + answer = await invoke(group, name, *args, **kwargs) + assert answer["structuredContent"]["arguments"] == expected + assert len(observed) == 1 + assert observed[0]["name"] == name + assert observed[0]["arguments"] == expected + + +@MODES +async def test_mcp_unserializable_object_raises_type_error(mode: str) -> None: + class CustomObject: + pass + + with Server(lambda request, index: Reply(status=200, body=b"{}")) as server: + async with session(mode, server.url) as client: + + async def invoke(group: str, name: str, *args: Any, **kwargs: Any) -> Any: + result = getattr(getattr(client, group), name)(*args, **kwargs) + return await result if inspect.isawaitable(result) else result + + with pytest.raises(TypeError, match="is not JSON serializable"): + await invoke("fixes", "get_fix_context", CustomObject(), organization_id=ORG) # type: ignore[arg-type] + + with pytest.raises(TypeError, match="is not JSON serializable"): + await invoke("knowledge", "get_plan", CustomObject(), organization_id=ORG) # type: ignore[arg-type] From 8c070419b73589ccbbe480884c511c1ede85fa7c Mon Sep 17 00:00:00 2001 From: nitinkoberoii Date: Wed, 25 Nov 2026 03:40:41 +0530 Subject: [PATCH 2/2] resolved proofline reviews --- proofline/_mcp.py | 32 ++++++++------------------------ proofline/fixes.py | 29 +++++++++++------------------ proofline/knowledge.py | 36 ++++++++---------------------------- tests/test_http.py | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 70 deletions(-) diff --git a/proofline/_mcp.py b/proofline/_mcp.py index d21993f7..8f3f59b3 100644 --- a/proofline/_mcp.py +++ b/proofline/_mcp.py @@ -28,16 +28,10 @@ def _refused() -> ProoflineError: return ProoflineError(0, "urn:proofline:sdk:mcp", "Invalid or refused MCP response.") -def _serialize_mcp_value(val: Any) -> Any: - if isinstance(val, UUID): - return str(val) - if isinstance(val, list): - return [_serialize_mcp_value(x) for x in val] - if isinstance(val, tuple): - return [_serialize_mcp_value(x) for x in val] - if isinstance(val, dict): - return {key: _serialize_mcp_value(v) for key, v in val.items()} - return val +def _json_default(obj: Any) -> Any: + if isinstance(obj, UUID): + return str(obj) + raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable") def _body(method: str, params: dict[str, Any] | None, identity: int | None) -> bytes: @@ -45,8 +39,8 @@ def _body(method: str, params: dict[str, Any] | None, identity: int | None) -> b if identity is not None: value["id"] = identity if params is not None: - value["params"] = _serialize_mcp_value(params) - data = json.dumps(value).encode("utf-8") + value["params"] = params + data = json.dumps(value, default=_json_default).encode("utf-8") if len(data) > 8192: raise ValueError("MCP request exceeds 8192 bytes.") return data @@ -112,12 +106,7 @@ def _call( self, name: str, args: dict[str, Any], *, organization_id: UUID | str | None = None ) -> KnowledgeResult: if organization_id is not None: - args = { - **args, - "organization_id": ( - str(organization_id) if isinstance(organization_id, UUID) else organization_id - ), - } + args = {**args, "organization_id": organization_id} call = _body("tools/call", {"name": name, "arguments": args}, 2) frames = [ ( @@ -166,12 +155,7 @@ async def _call( self, name: str, args: dict[str, Any], *, organization_id: UUID | str | None = None ) -> KnowledgeResult: if organization_id is not None: - args = { - **args, - "organization_id": ( - str(organization_id) if isinstance(organization_id, UUID) else organization_id - ), - } + args = {**args, "organization_id": organization_id} call = _body("tools/call", {"name": name, "arguments": args}, 2) frames = [ ( diff --git a/proofline/fixes.py b/proofline/fixes.py index 919a9aa5..9b4c00ad 100644 --- a/proofline/fixes.py +++ b/proofline/fixes.py @@ -2,6 +2,7 @@ from __future__ import annotations +from collections.abc import Sequence from typing import Any from uuid import UUID @@ -26,23 +27,21 @@ def get_fix_context( self, finding_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return self._call( - "get_fix_context", - {"finding_id": str(finding_id) if isinstance(finding_id, UUID) else finding_id}, - organization_id=organization_id, + "get_fix_context", {"finding_id": finding_id}, organization_id=organization_id ) def request_reverification( self, review_id: UUID | str, - finding_ids: list[UUID | str], + finding_ids: Sequence[UUID | str], commit_sha: str, *, note: str | None = None, organization_id: UUID | str | None = None, ) -> KnowledgeResult: args: dict[str, Any] = { - "review_id": str(review_id) if isinstance(review_id, UUID) else review_id, - "finding_ids": [str(f) if isinstance(f, UUID) else f for f in finding_ids], + "review_id": review_id, + "finding_ids": finding_ids, "commit_sha": commit_sha, } if note is not None: @@ -53,9 +52,7 @@ def get_reverification( self, request_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return self._call( - "get_reverification", - {"request_id": str(request_id) if isinstance(request_id, UUID) else request_id}, - organization_id=organization_id, + "get_reverification", {"request_id": request_id}, organization_id=organization_id ) @@ -77,23 +74,21 @@ async def get_fix_context( self, finding_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return await self._call( - "get_fix_context", - {"finding_id": str(finding_id) if isinstance(finding_id, UUID) else finding_id}, - organization_id=organization_id, + "get_fix_context", {"finding_id": finding_id}, organization_id=organization_id ) async def request_reverification( self, review_id: UUID | str, - finding_ids: list[UUID | str], + finding_ids: Sequence[UUID | str], commit_sha: str, *, note: str | None = None, organization_id: UUID | str | None = None, ) -> KnowledgeResult: args: dict[str, Any] = { - "review_id": str(review_id) if isinstance(review_id, UUID) else review_id, - "finding_ids": [str(f) if isinstance(f, UUID) else f for f in finding_ids], + "review_id": review_id, + "finding_ids": finding_ids, "commit_sha": commit_sha, } if note is not None: @@ -104,7 +99,5 @@ async def get_reverification( self, request_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return await self._call( - "get_reverification", - {"request_id": str(request_id) if isinstance(request_id, UUID) else request_id}, - organization_id=organization_id, + "get_reverification", {"request_id": request_id}, organization_id=organization_id ) diff --git a/proofline/knowledge.py b/proofline/knowledge.py index 9c88d03a..7d071fa0 100644 --- a/proofline/knowledge.py +++ b/proofline/knowledge.py @@ -50,40 +50,30 @@ def ask_codebase( def get_architecture_document( self, environment_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - env_id = str(environment_id) if isinstance(environment_id, UUID) else environment_id return self._call( "get_architecture_document", - {"environment_id": env_id}, + {"environment_id": environment_id}, organization_id=organization_id, ) def get_plan( self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - return self._call( - "get_plan", - {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, - organization_id=organization_id, - ) + return self._call("get_plan", {"plan_id": plan_id}, organization_id=organization_id) def start_plan_implementation( self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return self._call( - "start_plan_implementation", - {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, - organization_id=organization_id, + "start_plan_implementation", {"plan_id": plan_id}, organization_id=organization_id ) def get_plan_implementation( self, implementation_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - impl_id = ( - str(implementation_id) if isinstance(implementation_id, UUID) else implementation_id - ) return self._call( "get_plan_implementation", - {"implementation_id": impl_id}, + {"implementation_id": implementation_id}, organization_id=organization_id, ) @@ -131,39 +121,29 @@ async def ask_codebase( async def get_architecture_document( self, environment_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - env_id = str(environment_id) if isinstance(environment_id, UUID) else environment_id return await self._call( "get_architecture_document", - {"environment_id": env_id}, + {"environment_id": environment_id}, organization_id=organization_id, ) async def get_plan( self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - return await self._call( - "get_plan", - {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, - organization_id=organization_id, - ) + return await self._call("get_plan", {"plan_id": plan_id}, organization_id=organization_id) async def start_plan_implementation( self, plan_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: return await self._call( - "start_plan_implementation", - {"plan_id": str(plan_id) if isinstance(plan_id, UUID) else plan_id}, - organization_id=organization_id, + "start_plan_implementation", {"plan_id": plan_id}, organization_id=organization_id ) async def get_plan_implementation( self, implementation_id: UUID | str, *, organization_id: UUID | str | None = None ) -> KnowledgeResult: - impl_id = ( - str(implementation_id) if isinstance(implementation_id, UUID) else implementation_id - ) return await self._call( "get_plan_implementation", - {"implementation_id": impl_id}, + {"implementation_id": implementation_id}, organization_id=organization_id, ) diff --git a/tests/test_http.py b/tests/test_http.py index 71b664af..a2f2dfb8 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -2702,6 +2702,19 @@ def respond(request: Request, index: int) -> Reply: "organization_id": str(ORG), }, ), + ( + "fixes", + "request_reverification", + (REVIEW, (FINDING,), "a" * 40), + {"note": "fixed", "organization_id": ORG}, + { + "review_id": str(REVIEW), + "finding_ids": [str(FINDING)], + "commit_sha": "a" * 40, + "note": "fixed", + "organization_id": str(ORG), + }, + ), ( "fixes", "get_reverification", @@ -2744,3 +2757,27 @@ async def invoke(group: str, name: str, *args: Any, **kwargs: Any) -> Any: with pytest.raises(TypeError, match="is not JSON serializable"): await invoke("knowledge", "get_plan", CustomObject(), organization_id=ORG) # type: ignore[arg-type] + + # Passing a set for finding_ids still raises TypeError + with pytest.raises(TypeError, match="is not JSON serializable"): + await invoke( + "fixes", + "request_reverification", + REVIEW, + {FINDING}, # type: ignore[arg-type] + "a" * 40, + organization_id=ORG, + ) + + # Cyclic containers still raise ValueError + cyclic: list[Any] = [] + cyclic.append(cyclic) + with pytest.raises(ValueError, match="Circular reference detected"): + await invoke( + "fixes", + "request_reverification", + REVIEW, + cyclic, + "a" * 40, + organization_id=ORG, + )