Add isolated burst and pollution impact evidence, parallel work-order workflows, persisted notifications and graph updates. Checkpoint current code. Known follow-ups remain for large pollution result previews and graceful geometry failure.
66 lines
3.7 KiB
Python
66 lines
3.7 KiB
Python
from datetime import datetime, timezone
|
|
from uuid import uuid4
|
|
|
|
from app.domain.schemas.operational_task import TaskPresentationEventCommand
|
|
from app.mcp.models import QueryResult
|
|
from app.mcp.presentation_preview import saved_presentation_preview
|
|
|
|
|
|
def test_abbreviated_coverage_keeps_publishable_command_without_copying_geometry():
|
|
result = QueryResult(
|
|
source="generate_node_coverage", source_ref="mcp:analysis", evidence_id="mcp:analysis",
|
|
queried_at=datetime.now(timezone.utc), semantics="analysis", origin="system_data", truncated=False,
|
|
data={"result": {"map_payload": {"type": "FeatureCollection", "features": [{"large": "geometry"}]},
|
|
"coverage": {"status": "partial", "groups": {"isolation": {
|
|
"node_ids": ["A", "B"], "mapped_node_count": 1, "missing_node_ids": ["B"],
|
|
}}}}},
|
|
)
|
|
hint = saved_presentation_preview(result)
|
|
assert hint == saved_presentation_preview(result)
|
|
assert hint["groups"]["isolation"] == {"node_count": 2, "mapped_node_count": 1, "missing_node_count": 1}
|
|
command = TaskPresentationEventCommand(
|
|
request_id=uuid4(), run_id=uuid4(), source_session_id="session", command=hint["command"],
|
|
)
|
|
assert command.command.evidence_id == result.evidence_id and command.command.data is None
|
|
assert "geometry" not in str(hint["groups"]) and result.data["result"]["map_payload"]["features"]
|
|
result.evidence_id = None
|
|
assert saved_presentation_preview(result) is None
|
|
|
|
|
|
def test_missing_geometry_does_not_offer_a_broken_overlay_command():
|
|
result = QueryResult(
|
|
source="generate_node_coverage", source_ref="mcp:analysis", evidence_id="mcp:analysis",
|
|
queried_at=datetime.now(timezone.utc), semantics="analysis", origin="system_data", truncated=False,
|
|
data={"result": {"coverage": {"status": "unavailable"}}},
|
|
)
|
|
assert saved_presentation_preview(result) is None
|
|
|
|
|
|
def test_pollution_impact_keeps_a_saved_overlay_reference_for_history():
|
|
result = QueryResult(source="run_contaminant_simulation", source_ref="calculation:pollution",
|
|
evidence_id="pollution:impact", queried_at=datetime.now(timezone.utc), semantics="analysis", origin="synthetic",
|
|
data={"result": {"impact": {"phase": "after_contamination_before_intervention"},
|
|
"map_payload": {"type": "FeatureCollection", "features": [{"geometry": "saved"}]},
|
|
"coverage": {"status": "ready", "groups": {"contaminant_exposure": {"node_ids": ["Q1"], "mapped_node_count": 1}}}}})
|
|
preview = saved_presentation_preview(result)
|
|
assert preview["command"]["evidence_id"] == "pollution:impact"
|
|
assert preview["command"]["title"] == "水污染传播预计影响范围(处置前情景)"
|
|
assert "data" not in preview["command"] and preview["groups"]["contaminant_exposure"]["node_count"] == 1
|
|
result.data["result"]["impact"]["phase"] = "unknown"
|
|
assert saved_presentation_preview(result) is None
|
|
|
|
|
|
def test_burst_impact_hint_uses_saved_evidence_and_distinct_pre_intervention_title():
|
|
result = QueryResult(
|
|
source="run_burst_simulation", source_ref="mcp:burst", evidence_id="mcp:burst",
|
|
queried_at=datetime.now(timezone.utc), semantics="analysis", origin="system_data", truncated=False,
|
|
data={"result": {"impact": {"phase": "after_burst_before_intervention"},
|
|
"map_payload": {"type": "FeatureCollection", "features": [{"large": "geometry"}]}}},
|
|
)
|
|
hint = saved_presentation_preview(result)
|
|
assert hint["command"]["evidence_id"] == "mcp:burst"
|
|
assert "爆管后、处置前" in hint["command"]["title"]
|
|
assert "data" not in hint["command"]
|
|
result.data["result"].pop("impact")
|
|
assert saved_presentation_preview(result) is None
|