From 9933bddf083531e54965bc8c9c8a8ab09c63e826 Mon Sep 17 00:00:00 2001 From: Priyanka Punukollu Date: Wed, 25 Feb 2026 20:49:19 -0600 Subject: [PATCH] test(real-estate): add bedroom/price filter + structured error tests (8 total) - test_search_listings_bedroom_filter: min_beds=3 returns only 3+ bed listings and records the filter in result.filters_applied. - test_search_listings_price_filter: max_price=400000 excludes listings above threshold and records filter in result.filters_applied. - test_structured_error_code: all error paths return nested {code, message} dict with a REAL_ESTATE_* code. - Updated test_feature_flag_disabled: assert nested error dict with REAL_ESTATE_FEATURE_DISABLED code. - Updated test_unknown_location_graceful_error: assert nested error dict with REAL_ESTATE_PROVIDER_UNAVAILABLE code. All 8 tests pass in < 1s. Made-with: Cursor --- agent/evals/test_real_estate.py | 122 ++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/agent/evals/test_real_estate.py b/agent/evals/test_real_estate.py index 89834f095..a68883f92 100644 --- a/agent/evals/test_real_estate.py +++ b/agent/evals/test_real_estate.py @@ -173,8 +173,10 @@ async def test_feature_flag_disabled(): ]: result = await coro assert result["success"] is False - assert result["error"] == "FEATURE_DISABLED", ( - f"Expected FEATURE_DISABLED, got: {result}" + # Error is now a nested dict with {code, message} + assert isinstance(result["error"], dict), f"Expected dict error, got: {result['error']}" + assert result["error"]["code"] == "REAL_ESTATE_FEATURE_DISABLED", ( + f"Expected REAL_ESTATE_FEATURE_DISABLED, got: {result}" ) # Restore for other tests @@ -200,7 +202,117 @@ async def test_unknown_location_graceful_error(): result = await search_listings("Atlantis") assert result["success"] is False - assert result["error"] == "NO_LISTINGS_FOUND" - assert "Atlantis" in result["message"] + # Error is now a nested dict with {code, message} + assert isinstance(result["error"], dict) + assert result["error"]["code"] == "REAL_ESTATE_PROVIDER_UNAVAILABLE" + assert "Atlantis" in result["error"]["message"] # Message must name at least one supported city so user knows what to try - assert any(city in result["message"].lower() for city in ["austin", "denver", "seattle"]) + assert any(city in result["error"]["message"].lower() for city in ["austin", "denver", "seattle"]) + + +# --------------------------------------------------------------------------- +# Test 6 — bedroom filter: min_beds=3 returns only 3+ bed listings +# --------------------------------------------------------------------------- + +@pytest.mark.asyncio +async def test_search_listings_bedroom_filter(): + """ + GIVEN the real estate feature is enabled + WHEN search_listings('Austin', min_beds=3) is called + THEN every returned listing has bedrooms >= 3. + """ + _set_flag("true") + from tools.real_estate import search_listings, cache_clear + cache_clear() + + result = await search_listings("Austin", min_beds=3) + + assert result["success"] is True, f"Expected success, got: {result}" + listings = result["result"]["listings"] + assert len(listings) >= 1, "Expected at least 1 listing with 3+ beds in Austin" + + for listing in listings: + assert listing["bedrooms"] >= 3, ( + f"Listing {listing['id']} has {listing['bedrooms']} beds — should be >= 3" + ) + + # filters_applied must be recorded in the result + assert result["result"]["filters_applied"].get("min_beds") == 3 + + +# --------------------------------------------------------------------------- +# Test 7 — price filter: max_price excludes listings above threshold +# --------------------------------------------------------------------------- + +@pytest.mark.asyncio +async def test_search_listings_price_filter(): + """ + GIVEN the real estate feature is enabled + WHEN search_listings('Austin', max_price=400000) is called + THEN every returned listing has price <= 400000. + """ + _set_flag("true") + from tools.real_estate import search_listings, cache_clear + cache_clear() + + max_price = 400_000 + result = await search_listings("Austin", max_price=max_price) + + assert result["success"] is True, f"Expected success, got: {result}" + listings = result["result"]["listings"] + + for listing in listings: + assert listing["price"] <= max_price, ( + f"Listing {listing['id']} priced at ${listing['price']:,} " + f"exceeds max_price ${max_price:,}" + ) + + assert result["result"]["filters_applied"].get("max_price") == max_price + + +# --------------------------------------------------------------------------- +# Test 8 — structured error code: all errors use nested {code, message} shape +# --------------------------------------------------------------------------- + +@pytest.mark.asyncio +async def test_structured_error_code(): + """ + GIVEN the real estate feature is enabled + WHEN any function encounters an error condition + THEN the error field is a dict with 'code' and 'message' keys + and the code is one of the expected REAL_ESTATE_* values. + """ + _set_flag("true") + from tools.real_estate import ( + get_neighborhood_snapshot, + search_listings, + get_listing_details, + cache_clear, + ) + cache_clear() + + valid_codes = { + "REAL_ESTATE_PROVIDER_UNAVAILABLE", + "REAL_ESTATE_FEATURE_DISABLED", + } + + # Test 1: unknown location in snapshot + r1 = await get_neighborhood_snapshot("Atlantis") + assert r1["success"] is False + assert isinstance(r1["error"], dict), "error must be a dict" + assert "code" in r1["error"], "error must have 'code' key" + assert "message" in r1["error"], "error must have 'message' key" + assert r1["error"]["code"] in valid_codes + + # Test 2: unknown location in search + r2 = await search_listings("Atlantis") + assert r2["success"] is False + assert isinstance(r2["error"], dict) + assert r2["error"]["code"] in valid_codes + assert len(r2["error"]["message"]) > 10, "message must be non-empty" + + # Test 3: unknown listing ID in detail lookup + r3 = await get_listing_details("xxx-999") + assert r3["success"] is False + assert isinstance(r3["error"], dict) + assert r3["error"]["code"] in valid_codes