From df577e62b4702374b872521bf66f89b68ce5af11 Mon Sep 17 00:00:00 2001 From: oabrivard Date: Tue, 10 Mar 2026 08:47:08 +0100 Subject: [PATCH] Fix availability busy slot serialization in REST adapter --- app/main.py | 5 ++++- tests/test_a2a_availability.py | 8 ++------ tests/test_mcp_availability.py | 8 ++------ tests/test_rest_availability.py | 8 ++------ 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/main.py b/app/main.py index b8c5cf8..b02a8c7 100644 --- a/app/main.py +++ b/app/main.py @@ -398,7 +398,10 @@ async def availability(request: AvailabilityRequest) -> AvailabilityResponse: start=result.start, end=result.end, available=result.available, - busy_slots=result.busy_slots, # type: ignore + busy_slots=[ + BusySlot.model_validate(slot, from_attributes=True) + for slot in result.busy_slots + ], checked_calendars=result.checked_calendars, ) except ValueError as exc: diff --git a/tests/test_a2a_availability.py b/tests/test_a2a_availability.py index f5487eb..e96ad2b 100644 --- a/tests/test_a2a_availability.py +++ b/tests/test_a2a_availability.py @@ -6,11 +6,7 @@ from fastapi import Response import app.a2a.router as a2a_module from app.a2a.models import A2ARpcRequest - - -class _Slot(dict): - def __getattr__(self, item: str) -> str: - return self[item] +from app.core.models import CoreBusySlot class _DummyCoreService: @@ -21,7 +17,7 @@ class _DummyCoreService: calendar_ids: list[str] | None, ) -> SimpleNamespace: checked = calendar_ids or ["primary"] - busy_slots = [_Slot(calendar_id=checked[0], start=start, end=end)] + busy_slots = [CoreBusySlot(calendar_id=checked[0], start=start, end=end)] return SimpleNamespace( start=start, end=end, diff --git a/tests/test_mcp_availability.py b/tests/test_mcp_availability.py index a5331c8..9a3dd46 100644 --- a/tests/test_mcp_availability.py +++ b/tests/test_mcp_availability.py @@ -7,16 +7,12 @@ from fastapi import Response import app.a2a.router as a2a_module from app.a2a.models import A2ARpcRequest +from app.core.models import CoreBusySlot import app.main as main_module import app.mcp.server as mcp_server_module import app.mcp.tools as mcp_tools_module -class _Slot(dict): - def __getattr__(self, item: str) -> str: - return self[item] - - class _DummyCoreService: def check_availability( self, @@ -25,7 +21,7 @@ class _DummyCoreService: calendar_ids: list[str] | None, ) -> SimpleNamespace: checked = calendar_ids or ["primary"] - busy_slots = [_Slot(calendar_id=checked[0], start=start, end=end)] + busy_slots = [CoreBusySlot(calendar_id=checked[0], start=start, end=end)] return SimpleNamespace( start=start, end=end, diff --git a/tests/test_rest_availability.py b/tests/test_rest_availability.py index b40aaa5..05f01ba 100644 --- a/tests/test_rest_availability.py +++ b/tests/test_rest_availability.py @@ -4,11 +4,7 @@ import asyncio from types import SimpleNamespace import app.main as main_module - - -class _Slot(dict): - def __getattr__(self, item: str) -> str: - return self[item] +from app.core.models import CoreBusySlot class _DummyCoreService: @@ -20,7 +16,7 @@ class _DummyCoreService: ) -> SimpleNamespace: checked = calendar_ids or ["primary"] busy_slots = [ - _Slot( + CoreBusySlot( calendar_id=checked[0], start=start, end=end,