test_scheduling_tool_boundaries.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import pytest
  2. from app.core.mcp.gateway import ALLOWED_SCHEDULING_TOOLS, SchedulingPolicy
  3. from app.core.mcp.identity import AgentIdentity
  4. def identity(role):
  5. return AgentIdentity(
  6. subject=f"agent-{role}",
  7. roles=frozenset({role}),
  8. business_domains=frozenset({"sales"}),
  9. environments=frozenset({"test"}),
  10. correlation_id="correlation-a",
  11. )
  12. def test_dangerous_raw_kestra_tools_are_not_exposed():
  13. assert {
  14. "create_candidate_plan",
  15. "deploy_disabled_version",
  16. "run_canary",
  17. "promote_candidate",
  18. "pause_schedule",
  19. "retry_failed_execution",
  20. "backfill_bounded_window",
  21. "rollback_to_previous_version",
  22. } == ALLOWED_SCHEDULING_TOOLS
  23. for forbidden in (
  24. "delete_flow",
  25. "delete_execution",
  26. "change_status",
  27. "put_kv",
  28. "write_file",
  29. "create_yaml",
  30. "configure_connection",
  31. ):
  32. assert forbidden not in ALLOWED_SCHEDULING_TOOLS
  33. def test_viewer_cannot_mutate_and_editor_cannot_promote():
  34. policy = SchedulingPolicy()
  35. with pytest.raises(PermissionError, match="role"):
  36. policy.authorize_tool(
  37. identity("viewer"),
  38. "create_candidate_plan",
  39. domain="sales",
  40. environment="test",
  41. )
  42. with pytest.raises(PermissionError, match="role"):
  43. policy.authorize_tool(
  44. identity("editor"),
  45. "promote_candidate",
  46. domain="sales",
  47. environment="test",
  48. )