release: bump version to 0.84.0
ci / backend (push) Canceled after 0s
ci / frontend (push) Canceled after 0s
ci / delivery (push) Canceled after 0s

This commit is contained in:
linkong committed 2026-12-04 07:07:19 +08:00
1 parent 3b1b9ef68c
commit e1cc27f13d
241 files changed
+42779 -6027

No files matched your search

+210
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import copy
import json
from types import SimpleNamespace
@@ -362,3 +363,212 @@ async def test_earth_stateless_stream_executes_published_custom_workflow_and_blo
finally:
app.dependency_overrides.clear()
engine.dispose()
@pytest.mark.asyncio
async def test_generic_dag_supports_output_schema_field_routing_and_guardrail_edges():
from app.services.ai import dag_executor
class _RepairAI:
def __init__(self):
self.calls = 0
async def analyze(self, _req):
self.calls += 1
if self.calls == 1:
return SimpleNamespace(content="暂时分析完成,结论是需要补查 need_followup。", model="m1", provider="p1")
return SimpleNamespace(
content=json.dumps({"decision": "need_followup", "reason": "need extra proof"}),
model="m1",
provider="p1",
)
workflow = {
"workflow_id": "custom.routing_test",
"name": "Generic Routing Test",
"published_graph": {
"nodes": [
{"id": "t", "node_type": "trigger", "title": "Start"},
{
"id": "judge",
"node_type": "llm_agent",
"title": "Judge",
"params": {
"output_schema": {
"type": "object",
"properties": {
"decision": {"type": "string", "enum": ["direct", "need_followup"]},
"reason": {"type": "string"},
},
"required": ["decision", "reason"],
}
},
},
{"id": "branch_direct", "node_type": "output", "title": "Direct Branch"},
{"id": "branch_followup", "node_type": "output", "title": "Followup Branch"},
],
"edges": [
{"id": "e1", "source": "t", "target": "judge", "condition": "always"},
{
"id": "e2",
"source": "judge",
"target": "branch_direct",
"condition": "on_field_equals",
"condition_value": "decision=direct",
},
{
"id": "e3",
"source": "judge",
"target": "branch_followup",
"condition": "on_field_equals",
"condition_value": "decision=need_followup",
},
],
},
"bindings": {},
}
ai = _RepairAI()
events = []
async for evt in dag_executor.run_workflow_dag_stream(
db=None,
workflow=workflow,
question="Route test",
ai_client=ai,
):
events.append(evt)
assert ai.calls == 2
node_statuses = {
e["data"]["node_id"]: e["data"]["status"]
for e in events
if e.get("event") == "node" and e["data"]["status"] in {"completed", "skipped"}
}
assert node_statuses["branch_direct"] == "skipped"
assert node_statuses["branch_followup"] == "completed"
@pytest.mark.asyncio
async def test_location_resolve_unknown_runs_real_generic_dag(monkeypatch):
from app.services.ai import dag_executor
from app.services.ai.workflow_registry import BUILTIN_WORKFLOWS
from app.services.location import workflow_tools
monkeypatch.setattr(
workflow_tools,
"lookup_wikidata_facility",
lambda _q: _async_val(SimpleNamespace(candidates=(), attempted_queries=())),
)
monkeypatch.setattr(
workflow_tools,
"lookup_peeringdb_facility",
lambda _q: _async_val(SimpleNamespace(candidates=(), attempted_queries=())),
)
monkeypatch.setattr(
"app.services.compute_center_locations._lookup_ror_organization",
lambda _q: None,
)
monkeypatch.setattr(
workflow_tools,
"_agent_geocoder",
lambda _q: {
"lat": "64.0025",
"lon": "-22.5594",
"display_name": "Keflavik, Iceland",
"address": {"city": "Keflavik", "country": "Iceland"},
},
)
class _Search:
async def search(self, _q, max_results=5):
return [
SimpleNamespace(
title="ISEG2 Verne Global",
url="https://verneglobal.com/iseg2",
snippet="Nebius ISEG2 sits in Keflavik, Iceland.",
source_provider="tavily",
)
]
class _JudgeAI:
def __init__(self):
self.calls = 0
async def is_ready(self):
return True, "minimax", "MiniMax-M3.1-Flash"
async def analyze(self, req):
self.calls += 1
items = (req.context or {}).get("evidence_items") or []
assert items and items[0]["id"] == "E1"
return SimpleNamespace(
content=json.dumps(
{
"decision": "located",
"facility_name": "Verne Global",
"city": "Keflavik",
"country": "Iceland",
"precision": "city",
"confidence": 0.92,
"evidence_ids": ["E1"],
"country_override_reason": "Nebius HQ is NL while cluster sits in Iceland.",
"reasoning": "E1 confirms Keflavik, Iceland.",
}
),
model="MiniMax-M3.1-Flash",
provider="minimax",
)
builtin_loc = copy.deepcopy(next(w for w in BUILTIN_WORKFLOWS if w["workflow_id"] == "location.resolve_unknown"))
workflow = {
"workflow_id": builtin_loc["workflow_id"],
"name": builtin_loc["name"],
"published_graph": builtin_loc["graph"],
"bindings": builtin_loc["bindings"],
}
ai = _JudgeAI()
events = []
async for evt in dag_executor.run_workflow_dag_stream(
db=None,
workflow=workflow,
question="定位 ISEG2",
targets=[{"entity_type": "compute_center", "entity_id": "top500_13", "label": "ISEG2"}],
earth_context={
"name": "ISEG2",
"operator": "Nebius",
"country": "荷兰",
"_location_runtime": {"web_search_client": _Search()},
},
ai_client=ai,
allow_external_tools=True,
):
events.append(evt)
assert ai.calls == 1
statuses = {
e["data"]["node_id"]: e["data"]["status"]
for e in events
if e.get("event") == "node" and e["data"]["status"] in {"completed", "skipped"}
}
assert statuses["l0_normalize"] == "completed"
assert statuses["l1_knowledge"] == "completed"
assert statuses["l2_research_r1"] == "completed"
assert statuses["l2_judge_r1"] == "completed"
assert statuses["l2_research_r2"] == "skipped"
assert statuses["l2_judge_r2"] == "skipped"
assert statuses["l3_geocode"] == "completed"
assert statuses["l3_geo_guardrail"] == "completed"
assert statuses["l4_persist_outcome"] == "completed"
done_ev = next(e["data"] for e in events if e.get("event") == "done")
so = done_ev["structured_output"]
assert so["success"] is True
assert so["best_candidate"]["city"] == "Keflavik"
assert so["best_candidate"]["country"] == "冰岛"
assert so["best_candidate"]["raw_payload"]["citations"] == ["https://verneglobal.com/iseg2"]
assert done_ev["scene_spec"]["fly_to"]["lat"] == pytest.approx(64.0025)
async def _async_val(v):
return v