Spaces:
Running
Running
File size: 2,452 Bytes
79df050 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from datetime import datetime
from core.environment.context_builder import EnvironmentContextBuilder
from services.ai_service import _build_environment_context_text
def test_environment_context_builder_marks_missing_context():
builder = EnvironmentContextBuilder()
result = builder.build({}, now=datetime(2026, 5, 13, 12, 0, 0))
assert result.metadata["freshness"] == "missing"
assert "has_location: False" in result.summary_text
def test_environment_context_builder_includes_latest_location_fields():
builder = EnvironmentContextBuilder()
result = builder.build(
{
"lat": 25.033964,
"lon": 121.564468,
"detailed_address": "台北市信義區市府路45號",
"address_display": "110台北市信義區市府路45號",
"precision": "address",
"poi_label": "台北101",
"road": "市府路",
"house_number": "45",
"tz": "Asia/Taipei",
"locale": "zh-TW",
"heading_cardinal": "NE",
"accuracy_m": 12,
},
now=datetime(2026, 5, 13, 12, 0, 0),
)
assert result.metadata["freshness"] == "latest_available"
assert "detailed_address: 台北市信義區市府路45號" in result.summary_text
assert "precision: address" in result.summary_text
assert "poi_label: 台北101" in result.summary_text
assert "road: 市府路" in result.summary_text
assert "house_number: 45" in result.summary_text
assert "timezone: Asia/Taipei" in result.summary_text
assert "coordinates: 25.033964,121.564468" in result.summary_text
def test_ai_service_environment_context_text_uses_fixed_builder():
text = _build_environment_context_text(
{
"lat": 25.033964,
"lon": 121.564468,
"detailed_address": "台北市信義區市府路45號",
"address_display": "110台北市信義區市府路45號",
"precision": "address",
"poi_label": "台北101",
"road": "市府路",
"house_number": "45",
"tz": "Asia/Taipei",
"locale": "zh-TW",
}
)
assert "snapshot_time_utc:" in text
assert "has_location: True" in text
assert "detailed_address: 台北市信義區市府路45號" in text
assert "precision: address" in text
assert "poi_label: 台北101" in text
assert "readable_context:" in text
|