from __future__ import annotations
import requests
from behave import given, then
@given("the budgeting advisor is connected to the household's finances")
def step_advisor_connected(context):
pass
@given("the household's Monarch session has expired")
def step_session_expired(context):
requests.post(f"{context.mock_base}/configure", json={"session_expired": True})
@then("the advisor reports that re-authentication is required")
def step_assert_reauth_required(context):
result = (
getattr(context, "overview_result", None)
or getattr(context, "spending_result", None)
or getattr(context, "history_result", None)
or getattr(context, "triage_result", None)
or getattr(context, "inspect_result", None)
or getattr(context, "progress_result", None)
or getattr(context, "forecast_result", None)
or getattr(context, "trend_result", None)
or getattr(context, "scan_result", None)
or getattr(context, "audit_result", None)
or getattr(context, "inventory_result", None)
or getattr(context, "budget_review_result", None)
or getattr(context, "allocation_result", None)
or getattr(context, "rr_result", None)
)
assert result is not None, (
"No tool result found — make sure the When step ran before this Then step."
)
error = result.get("error", "")
assert "auth" in str(error).lower() or "re-authenticate" in str(error).lower(), (
f"Expected an auth/re-authenticate error, got: {result!r}"
)
def call_tool(context, tool_name: str, arguments: dict | None = None):
if context.mcp_start_error is not None:
raise AssertionError(
f"Cannot call tool {tool_name!r}: MCP server failed to start — "
f"{context.mcp_start_error}"
) from context.mcp_start_error
return context.mcp_client.call_tool(tool_name, arguments or {})