from __future__ import annotations

from oasyce.services.coordination_context import resolve_coordination_context


def test_resolve_coordination_context_degrades_when_account_state_unavailable(monkeypatch):
    monkeypatch.setattr(
        "oasyce.services.coordination_context.resolve_runtime_actor_trace",
        lambda **_: {
            "principal": {"id": ""},
            "account": {"id": ""},
            "delegate": {"id": ""},
            "session": {"id": "session-1", "agent_id": "autonomy.scheduler", "source": "test"},
            "owner_account": "",
            "device_id": "",
            "agent_id": "autonomy.scheduler",
            "session_id": "session-1",
            "source": "test",
        },
    )

    payload = resolve_coordination_context(
        default_agent_id="autonomy.scheduler",
        session_id="session-1",
        source="test",
    )

    assert payload["owner_account"] == ""
    assert payload["device_id"] == ""
    assert payload["session"]["agent_id"] == "autonomy.scheduler"
    assert payload["agent_id"] == "autonomy.scheduler"
    assert payload["session_id"] == "session-1"
    assert payload["source"] == "test"
