Explorar o código

Align get_transit_preview signature: takes raw birth data like other core functions

- Core get_transit_preview(birth_datetime, latitude, longitude, start_date, end_date, ...)
- _byId variant fetches from DB then calls core
- 102 tests passing
Lukas Goldschmidt hai 1 mes
pai
achega
ab93cd129e
Modificáronse 2 ficheiros con 40 adicións e 48 borrados
  1. 30 32
      src/astro_mcp/tools.py
  2. 10 16
      tests/test_tools.py

+ 30 - 32
src/astro_mcp/tools.py

@@ -480,14 +480,16 @@ async def calculate_synastry_chart(
 
 @mcp.tool()
 async def get_transit_preview(
-    person_id: str,
+    birth_datetime: str,
+    latitude: float,
+    longitude: float,
     start_date: str,
     end_date: str,
     transit_latitude: float | None = None,
     transit_longitude: float | None = None,
     min_significance: float = 0.0,
 ) -> dict[str, Any]:
-    """Daily transit-to-natal aspect snapshot for a person over a time range.
+    """Daily transit-to-natal aspect snapshot over a time range.
 
     For each day, shows which transiting planets are aspecting which natal planets,
     with orb, applying/separating status, and significance score (0-10).
@@ -499,7 +501,9 @@ async def get_transit_preview(
     - Orb tightness (tighter = more significant)
 
     Args:
-        person_id: ID of a person in the persons database.
+        birth_datetime: ISO 8601 birth datetime (UTC).
+        latitude: Birth latitude in decimal degrees.
+        longitude: Birth longitude in decimal degrees.
         start_date: ISO date string for the start of the range (YYYY-MM-DD).
         end_date: ISO date string for the end of the range (YYYY-MM-DD).
         transit_latitude: Current location latitude. Defaults to birth latitude.
@@ -512,16 +516,11 @@ async def get_transit_preview(
     """
     from datetime import datetime, timedelta, timezone
 
-    from . import storage, astrology
+    from . import astrology
 
-    # Get person data
-    person = await storage.get_person(person_id=person_id)
-    if not person:
-        return {"error": f"person not found: {person_id}"}
-
-    birth_dt = person["birth_datetime"]
-    birth_lat = person["latitude"]
-    birth_lon = person["longitude"]
+    birth_dt = birth_datetime
+    birth_lat = latitude
+    birth_lon = longitude
     t_lat = transit_latitude if transit_latitude is not None else birth_lat
     t_lon = transit_longitude if transit_longitude is not None else birth_lon
 
@@ -618,8 +617,9 @@ async def get_transit_preview(
 
     return {
         "input": {
-            "person_id": person_id,
-            "person_name": person["name"],
+            "birth_datetime": birth_datetime,
+            "latitude": latitude,
+            "longitude": longitude,
             "start_date": start_date,
             "end_date": end_date,
             "min_significance": min_significance,
@@ -874,17 +874,13 @@ async def _get_person_birth_data(person_id: str) -> dict[str, Any]:
 @mcp.tool()
 async def calculate_natal_chart_by_id(
     person_id: str,
-    transit_latitude: float | None = None,
-    transit_longitude: float | None = None,
     house_system: str = "placidus",
     orb_limits: dict[str, float] | None = None,
 ) -> dict[str, Any]:
     """Calculate natal chart for a person from the database.
 
     Args:
-        person_id: ID of a person in the persons database.
-        transit_latitude: Override latitude for chart calculation. Defaults to birth latitude.
-        transit_longitude: Override longitude for chart calculation. Defaults to birth longitude.
+        person_id: ID or nickname of a person in the persons database.
         house_system: House system (default: Placidus).
         orb_limits: Optional orb configuration.
 
@@ -896,8 +892,8 @@ async def calculate_natal_chart_by_id(
         return birth
     return await calculate_natal_chart(
         birth_datetime=birth["birth_datetime"],
-        latitude=transit_latitude if transit_latitude is not None else birth["latitude"],
-        longitude=transit_longitude if transit_longitude is not None else birth["longitude"],
+        latitude=birth["latitude"],
+        longitude=birth["longitude"],
         elevation=birth.get("elevation", 0.0),
         house_system=house_system,
         orb_limits=orb_limits,
@@ -1023,29 +1019,31 @@ async def get_transit_preview_by_id(
     end_date: str,
     transit_latitude: float | None = None,
     transit_longitude: float | None = None,
-    orb_limits: dict[str, float] | None = None,
+    min_significance: float = 0.0,
 ) -> dict[str, Any]:
-    """Preview transit events for a person from the database.
+    """Daily transit-to-natal aspect snapshot for a person from the database.
 
     Args:
-        person_id: ID of a person in the persons database.
-        start_date: ISO date string for the start of the range.
-        end_date: ISO date string for the end of the range.
+        person_id: ID or nickname of a person in the persons database.
+        start_date: ISO date string for the start of the range (YYYY-MM-DD).
+        end_date: ISO date string for the end of the range (YYYY-MM-DD).
         transit_latitude: Current location latitude. Defaults to birth latitude.
         transit_longitude: Current location longitude. Defaults to birth longitude.
-        orb_limits: Optional orb configuration.
+        min_significance: Minimum significance score (0-10). Default 0 = all.
 
     Returns:
-        List of transit events.
+        Daily snapshots with active transit-to-natal aspects.
     """
     birth = await _get_person_birth_data(person_id)
     if "error" in birth:
         return birth
     return await get_transit_preview(
-        person_id=person_id,
+        birth_datetime=birth["birth_datetime"],
+        latitude=birth["latitude"],
+        longitude=birth["longitude"],
         start_date=start_date,
         end_date=end_date,
-        transit_latitude=transit_latitude if transit_latitude is not None else birth["latitude"],
-        transit_longitude=transit_longitude if transit_longitude is not None else birth["longitude"],
-        min_significance=0.0,
+        transit_latitude=transit_latitude,
+        transit_longitude=transit_longitude,
+        min_significance=min_significance,
     )

+ 10 - 16
tests/test_tools.py

@@ -453,22 +453,12 @@ class TestPersonManage:
 # ── Tests: get_transit_preview (stub) ───────────────────────────────
 
 class TestTransitPreview:
-    def test_person_not_found(self):
-        from src.astro_mcp import tools
-        result = asyncio.run(
-            tools.get_transit_preview(
-                person_id="nonexistent",
-                start_date="2026-06-01",
-                end_date="2026-07-01",
-            )
-        )
-        assert "error" in result
-
     def test_invalid_date_format(self):
         from src.astro_mcp import tools
         result = asyncio.run(
             tools.get_transit_preview(
-                person_id="test",
+                birth_datetime="1980-01-01T12:00:00Z",
+                latitude=47.0, longitude=8.0,
                 start_date="not-a-date",
                 end_date="2026-07-01",
             )
@@ -479,7 +469,8 @@ class TestTransitPreview:
         from src.astro_mcp import tools
         result = asyncio.run(
             tools.get_transit_preview(
-                person_id="test",
+                birth_datetime="1980-01-01T12:00:00Z",
+                latitude=47.0, longitude=8.0,
                 start_date="2026-07-01",
                 end_date="2026-06-01",
             )
@@ -490,7 +481,8 @@ class TestTransitPreview:
         from src.astro_mcp import tools
         result = asyncio.run(
             tools.get_transit_preview(
-                person_id="test",
+                birth_datetime="1980-01-01T12:00:00Z",
+                latitude=47.0, longitude=8.0,
                 start_date="2026-01-01",
                 end_date="2027-06-01",
             )
@@ -501,13 +493,15 @@ class TestTransitPreview:
         from src.astro_mcp import tools
         result = asyncio.run(
             tools.get_transit_preview(
-                person_id="nonexistent",
+                birth_datetime="1980-01-01T12:00:00Z",
+                latitude=47.0, longitude=8.0,
                 start_date="2026-06-01",
                 end_date="2026-07-01",
                 min_significance=5.0,
             )
         )
-        assert "error" in result  # person not found
+        assert "days" in result
+        assert result["total_aspects"] > 0
 
 
 # ── Tests: _byId tools ───────────────────────────────────────────────