release: bump version to 0.84.0
This commit is contained in:
1 parent
3b1b9ef68c
commit
e1cc27f13d
241 files changed
+42779
-6027
No files matched your search
@@ -767,16 +767,17 @@ async def test_collect_compute_center_location_skips_llm_when_candidates_exist(m
|
||||
country="France",
|
||||
)
|
||||
monkeypatch.setattr(visualization_api, "_load_compute_center_record", AsyncMock(return_value=None))
|
||||
monkeypatch.setattr(
|
||||
visualization_api,
|
||||
"collect_location_candidates",
|
||||
lambda **_kwargs: ([candidate], ["Lyon, France"]),
|
||||
)
|
||||
|
||||
async def _explode(**_kwargs):
|
||||
raise AssertionError("LLM fallback should not run when a normal candidate exists")
|
||||
async def _run_wf(**_kwargs):
|
||||
return {
|
||||
"candidates": [candidate],
|
||||
"attempted_queries": ["Lyon, France"],
|
||||
"workflow_run_id": "run_local_hit",
|
||||
"terminal_status": None,
|
||||
"failure_reason": None,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(visualization_api, "collect_llm_location_fallback_candidate", _explode)
|
||||
monkeypatch.setattr(visualization_api, "run_location_workflow", _run_wf)
|
||||
|
||||
response = await visualization_api.collect_compute_center_location(
|
||||
"epoch_ai_gpu-test",
|
||||
@@ -791,56 +792,43 @@ async def test_collect_compute_center_location_skips_llm_when_candidates_exist(m
|
||||
|
||||
assert response["success"] is True
|
||||
assert response["best_candidate"]["source"] == "nominatim_online_geocode"
|
||||
assert response["workflow_run_id"] == "run_local_hit"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_collect_compute_center_location_uses_llm_when_candidates_empty(monkeypatch):
|
||||
monkeypatch.setattr(visualization_api, "_compute_center_location_web_search_capability", AsyncMock(return_value={"enabled": True}))
|
||||
llm_candidate = compute_center_locations.LocationCandidate(
|
||||
latitude=45.764,
|
||||
longitude=4.8357,
|
||||
display_name="Lyon, France",
|
||||
precision="city",
|
||||
confidence=0.74,
|
||||
query="llm_factcheck:compute_center:Mystery Cluster",
|
||||
query="location_workflow:compute_center:Mystery Cluster",
|
||||
source="llm_location_factcheck",
|
||||
source_note="LLM location factcheck fallback",
|
||||
source_note="Controlled workflow factcheck",
|
||||
matched_fields=("name",),
|
||||
needs_confirmation=True,
|
||||
city="Lyon",
|
||||
country="France",
|
||||
)
|
||||
monkeypatch.setattr(visualization_api, "_load_compute_center_record", AsyncMock(return_value=None))
|
||||
monkeypatch.setattr(
|
||||
visualization_api,
|
||||
"collect_location_candidates",
|
||||
lambda **_kwargs: ([], ["Mystery Cluster, France"]),
|
||||
)
|
||||
|
||||
from app.services.location.llm_fallback import LocationLLMFallbackResult, LocationSearchEvidenceResult
|
||||
|
||||
async def _search_evidence(**_kwargs):
|
||||
return LocationSearchEvidenceResult(
|
||||
evidence=[
|
||||
{
|
||||
"title": "Mystery Cluster source",
|
||||
"url": "https://example.test/mystery",
|
||||
"snippet": "Mystery Cluster is in Lyon.",
|
||||
}
|
||||
async def _run_wf(**kwargs):
|
||||
ctx = kwargs.get("earth_context") or {}
|
||||
assert ctx["name"] == "Mystery Cluster"
|
||||
assert ctx["country"] == "France"
|
||||
return {
|
||||
"candidates": [llm_candidate],
|
||||
"attempted_queries": [
|
||||
"Mystery Cluster, France",
|
||||
"web_search:Mystery Cluster France physical location",
|
||||
],
|
||||
attempted_queries=["web_search:compute_center:Mystery Cluster France physical location"],
|
||||
)
|
||||
"workflow_run_id": "run_mystery_1",
|
||||
"terminal_status": None,
|
||||
"failure_reason": None,
|
||||
}
|
||||
|
||||
async def _fallback(**_kwargs):
|
||||
return LocationLLMFallbackResult(
|
||||
candidates=[llm_candidate],
|
||||
attempted_queries=["llm_factcheck:compute_center:Mystery Cluster"],
|
||||
)
|
||||
|
||||
monkeypatch.setattr(visualization_api, "get_ai_provider_client", AsyncMock(return_value=object()))
|
||||
monkeypatch.setattr(visualization_api, "get_web_search_client", AsyncMock(return_value=object()))
|
||||
monkeypatch.setattr(visualization_api, "collect_location_search_evidence", _search_evidence)
|
||||
monkeypatch.setattr(visualization_api, "collect_llm_location_fallback_candidate", _fallback)
|
||||
monkeypatch.setattr(visualization_api, "run_location_workflow", _run_wf)
|
||||
|
||||
response = await visualization_api.collect_compute_center_location(
|
||||
"epoch_ai_gpu-test",
|
||||
@@ -855,10 +843,10 @@ async def test_collect_compute_center_location_uses_llm_when_candidates_empty(mo
|
||||
assert response["success"] is True
|
||||
assert response["best_candidate"]["source"] == "llm_location_factcheck"
|
||||
assert response["best_candidate"]["needs_confirmation"] is True
|
||||
assert response["workflow_run_id"] == "run_mystery_1"
|
||||
assert response["attempted_queries"] == [
|
||||
"Mystery Cluster, France",
|
||||
"web_search:compute_center:Mystery Cluster France physical location",
|
||||
"llm_factcheck:compute_center:Mystery Cluster",
|
||||
"web_search:Mystery Cluster France physical location",
|
||||
]
|
||||
|
||||
|
||||
@@ -1195,10 +1183,23 @@ async def test_collect_location_endpoint_returns_candidates_for_known_record(mon
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_collect_location_endpoint_returns_failure_reason(monkeypatch):
|
||||
monkeypatch.setattr(visualization_api, "_compute_center_location_web_search_capability", AsyncMock(return_value={"enabled": True}))
|
||||
from types import SimpleNamespace
|
||||
from app.services.location import workflow_tools
|
||||
|
||||
monkeypatch.setattr(compute_center_locations, "_lookup_ror_organization", lambda _query: None)
|
||||
monkeypatch.setattr(compute_center_locations, "_geocode_online", lambda _query: None)
|
||||
|
||||
async def _empty_l1(_query):
|
||||
return SimpleNamespace(candidates=(), attempted_queries=())
|
||||
|
||||
monkeypatch.setattr(workflow_tools, "lookup_wikidata_facility", _empty_l1)
|
||||
monkeypatch.setattr(workflow_tools, "lookup_peeringdb_facility", _empty_l1)
|
||||
monkeypatch.setattr("app.api.v1.settings.get_ai_provider_client", AsyncMock(return_value=None))
|
||||
monkeypatch.setattr(
|
||||
"app.api.v1.settings.get_runtime_web_search_config",
|
||||
AsyncMock(side_effect=RuntimeError("no db settings")),
|
||||
)
|
||||
|
||||
class _ScalarResult:
|
||||
def __init__(self, rows):
|
||||
self._rows = rows
|
||||
@@ -1472,3 +1473,261 @@ async def test_compute_center_location_write_endpoints_require_admin():
|
||||
assert r4.status_code == 403
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_web_search_capability_allows_searxng_without_api_key(monkeypatch):
|
||||
from app.services.ai_tools.schemas import WebSearchConfig, WebSearchProviderConfig
|
||||
|
||||
monkeypatch.setattr(
|
||||
visualization_api,
|
||||
"get_runtime_web_search_config",
|
||||
AsyncMock(
|
||||
return_value=WebSearchConfig(
|
||||
enabled=True,
|
||||
default_provider="searxng",
|
||||
provider="searxng",
|
||||
providers={
|
||||
"searxng": WebSearchProviderConfig(
|
||||
provider="searxng",
|
||||
base_url="http://localhost:8080",
|
||||
api_key="",
|
||||
)
|
||||
},
|
||||
)
|
||||
),
|
||||
)
|
||||
cap = await visualization_api._compute_center_location_web_search_capability(AsyncMock())
|
||||
assert cap["enabled"] is True
|
||||
assert cap["provider"] == "searxng"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_save_location_records_workflow_run_feedback(monkeypatch):
|
||||
from app.services.ai import workflow_evolver
|
||||
|
||||
target_record = _build_record(
|
||||
record_id=88,
|
||||
source="top500",
|
||||
data_type="supercomputer",
|
||||
name="ISEG2",
|
||||
country="荷兰",
|
||||
city="",
|
||||
latitude=0.0,
|
||||
longitude=0.0,
|
||||
metadata={},
|
||||
)
|
||||
feedback_calls = []
|
||||
|
||||
async def _fake_feedback(_db, run_id, *, rating, note=None, actor=None):
|
||||
feedback_calls.append((run_id, rating, note, actor))
|
||||
return {"run_id": run_id, "rating": rating}
|
||||
|
||||
monkeypatch.setattr(workflow_evolver, "record_run_feedback", _fake_feedback)
|
||||
|
||||
class _ScalarResult:
|
||||
def __init__(self, rows):
|
||||
self._rows = rows
|
||||
|
||||
def scalars(self):
|
||||
class _Scalars:
|
||||
def __init__(self, rows):
|
||||
self._rows = rows
|
||||
|
||||
def first(self):
|
||||
return self._rows[0] if self._rows else None
|
||||
|
||||
def all(self):
|
||||
return self._rows
|
||||
|
||||
return _Scalars(self._rows)
|
||||
|
||||
class _FakeSession:
|
||||
def __init__(self):
|
||||
self.saved = []
|
||||
|
||||
async def execute(self, _query):
|
||||
if self.saved:
|
||||
return _ScalarResult(self.saved)
|
||||
return _ScalarResult([target_record])
|
||||
|
||||
async def scalar(self, _query):
|
||||
return None
|
||||
|
||||
def add(self, record):
|
||||
self.saved.append(record)
|
||||
|
||||
async def commit(self):
|
||||
return None
|
||||
|
||||
async def refresh(self, _record):
|
||||
return None
|
||||
|
||||
fake_session = _FakeSession()
|
||||
|
||||
async def override_get_db():
|
||||
yield fake_session
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
app.dependency_overrides[get_current_user] = _override_admin_user
|
||||
transport = ASGITransport(app=app)
|
||||
try:
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
resp = await client.post(
|
||||
"/api/v1/visualization/compute-centers/top500-88/location",
|
||||
json={
|
||||
"source": "top500",
|
||||
"name": "ISEG2",
|
||||
"latitude": 64.0025,
|
||||
"longitude": -22.5594,
|
||||
"precision": "city",
|
||||
"confidence": 0.92,
|
||||
"location_source": "llm_location_factcheck",
|
||||
"country": "冰岛",
|
||||
"workflow_run_id": "run_iseg2_test",
|
||||
"feedback_rating": 1,
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert feedback_calls == [
|
||||
("run_iseg2_test", 1, "Adopted compute-center location for top500-88", "admin:test-admin")
|
||||
]
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
def test_terminal_compute_center_excluded_from_unresolved_and_counted_in_withheld():
|
||||
compute_center_locations.set_compute_center_location_cache({
|
||||
"epoch_ai_gpu:epoch_ibm_dyeus": {
|
||||
"source": "epoch_ai_gpu",
|
||||
"source_id": "epoch_ibm_dyeus",
|
||||
"name": "IBM DYEUS",
|
||||
"country": "United States",
|
||||
"latitude": None,
|
||||
"longitude": None,
|
||||
"precision": "unknown",
|
||||
"confidence": 0.0,
|
||||
"location_source": "agent_terminal_undisclosed",
|
||||
"source_note": "官方未披露物理部署城市",
|
||||
"needs_confirmation": False,
|
||||
"verification_status": "undisclosed",
|
||||
},
|
||||
"epoch_ai_gpu:epoch_planned_site": {
|
||||
"source": "epoch_ai_gpu",
|
||||
"source_id": "epoch_planned_site",
|
||||
"name": "Future AI Fab",
|
||||
"country": "United States",
|
||||
"latitude": None,
|
||||
"longitude": None,
|
||||
"precision": "unknown",
|
||||
"confidence": 0.0,
|
||||
"location_source": "agent_terminal_planned",
|
||||
"source_note": "项目尚在规划中",
|
||||
"needs_confirmation": False,
|
||||
"verification_status": "planned",
|
||||
},
|
||||
})
|
||||
rec_undisclosed = _build_record(
|
||||
record_id=201,
|
||||
source="epoch_ai_gpu",
|
||||
data_type="gpu_cluster",
|
||||
name="IBM DYEUS",
|
||||
country="United States",
|
||||
city="",
|
||||
latitude=0.0,
|
||||
longitude=0.0,
|
||||
metadata={"value": "100", "unit": "TFlop/s"},
|
||||
)
|
||||
rec_undisclosed.source_id = "epoch_ibm_dyeus"
|
||||
rec_planned = _build_record(
|
||||
record_id=202,
|
||||
source="epoch_ai_gpu",
|
||||
data_type="gpu_cluster",
|
||||
name="Future AI Fab",
|
||||
country="United States",
|
||||
city="",
|
||||
latitude=0.0,
|
||||
longitude=0.0,
|
||||
metadata={"value": "200", "unit": "TFlop/s"},
|
||||
)
|
||||
rec_planned.source_id = "epoch_planned_site"
|
||||
rec_unknown = _build_record(
|
||||
record_id=203,
|
||||
source="epoch_ai_gpu",
|
||||
data_type="gpu_cluster",
|
||||
name="Still Unresolved Site",
|
||||
country="United States",
|
||||
city="",
|
||||
latitude=0.0,
|
||||
longitude=0.0,
|
||||
metadata={"value": "300", "unit": "TFlop/s"},
|
||||
)
|
||||
rec_unknown.source_id = "epoch_still_unknown"
|
||||
|
||||
payload = convert_compute_centers_to_geojson([rec_undisclosed, rec_planned, rec_unknown])
|
||||
|
||||
assert [item["source_id"] for item in payload["unresolved"]] == ["epoch_still_unknown"]
|
||||
assert payload["withheld_count"] == 2
|
||||
assert payload["withheld_by_status"] == {"undisclosed": 1, "planned": 1}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_collect_compute_center_location_handles_planned_and_cloud_only_as_terminal(monkeypatch):
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
from app.api.v1 import visualization as vis_api
|
||||
from app.core.security import get_current_user
|
||||
from app.db.session import get_db
|
||||
from app.main import app
|
||||
|
||||
rec = _build_record(
|
||||
record_id=210,
|
||||
source="epoch_ai_gpu",
|
||||
data_type="gpu_cluster",
|
||||
name="Planned Cloud Cluster",
|
||||
country="United States",
|
||||
city="",
|
||||
latitude=0.0,
|
||||
longitude=0.0,
|
||||
metadata={},
|
||||
)
|
||||
rec.source_id = "epoch_planned_cloud"
|
||||
|
||||
async def _fake_load_record(_db, _source_id):
|
||||
return rec
|
||||
|
||||
monkeypatch.setattr(vis_api, "_load_compute_center_record", _fake_load_record)
|
||||
|
||||
async def override_get_db():
|
||||
yield object()
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
app.dependency_overrides[get_current_user] = _override_admin_user
|
||||
transport = ASGITransport(app=app)
|
||||
try:
|
||||
for status_val, reason in (
|
||||
("planned", "项目仍在规划中,暂无具体机房地址"),
|
||||
("cloud_only", "纯云端服务形态,无单一物理部署园区"),
|
||||
):
|
||||
async def _fake_run(**_kwargs):
|
||||
return {
|
||||
"candidates": [],
|
||||
"terminal_status": status_val,
|
||||
"failure_reason": reason,
|
||||
"attempted_queries": [],
|
||||
"workflow_run_id": f"run_{status_val}",
|
||||
}
|
||||
|
||||
monkeypatch.setattr(vis_api, "run_location_workflow", _fake_run)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
resp = await client.post(
|
||||
"/api/v1/visualization/compute-centers/epoch_planned_cloud/collect-location",
|
||||
json={"force": True},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
body = resp.json()
|
||||
assert body["success"] is False
|
||||
assert body["terminal_status"] == status_val
|
||||
assert body["failure_reason"] == reason
|
||||
assert body["workflow_run_id"] == f"run_{status_val}"
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
Reference in new issue
Block a user