# Run with Prometheus promtool 3.5.0: promtool test rules alerts.test.yml
# All inputs are synthetic. One sample per minute, counters start at zero.
rule_files:
  - alerts.yml
evaluation_interval: 1m
tests:
  - name: sustained errors fire only after the pending window and recover
    interval: 1m
    input_series:
      - series: 'mcp_tool_calls_total{service_name="sales-mcp",environment="production",tool="find_account",outcome="success"}'
        values: '0+90x10 1000+100x20'
      - series: 'mcp_tool_calls_total{service_name="sales-mcp",environment="production",tool="find_account",outcome="error"}'
        values: '0+10x10 100+0x20'
      - series: 'mcp_tool_calls_total{service_name="sales-mcp",environment="staging",tool="find_account",outcome="success"}'
        values: '0+10000x30'
    alert_rule_test:
      - eval_time: 2m
        alertname: MCPToolErrorRateHigh
        exp_alerts: []
      - eval_time: 10m
        alertname: MCPToolErrorRateHigh
        exp_alerts:
          - exp_labels:
              service_name: sales-mcp
              environment: production
              tool: find_account
              severity: warning
            exp_annotations:
              summary: "Sustained MCP tool errors"
      - eval_time: 25m
        alertname: MCPToolErrorRateHigh
        exp_alerts: []
  - name: healthy low-volume zero-traffic missing and transient series do not page
    interval: 1m
    input_series:
      - series: 'mcp_tool_calls_total{service_name="healthy",environment="production",tool="find_account",outcome="success"}'
        values: '0+99x20'
      - series: 'mcp_tool_calls_total{service_name="healthy",environment="production",tool="find_account",outcome="error"}'
        values: '0+1x20'
      - series: 'mcp_tool_calls_total{service_name="low-volume",environment="production",tool="find_account",outcome="success"}'
        values: '0+1x20'
      - series: 'mcp_tool_calls_total{service_name="low-volume",environment="production",tool="find_account",outcome="error"}'
        values: '0+1x20'
      - series: 'mcp_tool_calls_total{service_name="zero",environment="production",tool="find_account",outcome="success"}'
        values: '0+0x20'
      - series: 'mcp_tool_calls_total{service_name="zero",environment="production",tool="find_account",outcome="error"}'
        values: '0+0x20'
      - series: 'mcp_tool_calls_total{service_name="brief-spike",environment="production",tool="find_account",outcome="success"}'
        values: '0+100x8 900 1800 1900+100x10'
      - series: 'mcp_tool_calls_total{service_name="brief-spike",environment="production",tool="find_account",outcome="error"}'
        values: '0+0x8 100 200 200+0x10'
    alert_rule_test:
      - eval_time: 10m
        alertname: MCPToolErrorRateHigh
        exp_alerts: []
      - eval_time: 20m
        alertname: MCPToolErrorRateHigh
        exp_alerts: []
      - eval_time: 13m
        alertname: MCPToolErrorRateHigh
        exp_alerts: []
      - eval_time: 14m
        alertname: MCPToolErrorRateHigh
        exp_alerts: []
      - eval_time: 20m
        alertname: MCPToolLatencyHigh
        exp_alerts: []
  - name: latency histogram fires for a slow tool but not a fast tool
    interval: 1m
    input_series:
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="slow_lookup",le="1"}'
        values: '0+20x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="slow_lookup",le="2"}'
        values: '0+50x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="slow_lookup",le="5"}'
        values: '0+99x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="slow_lookup",le="+Inf"}'
        values: '0+100x20'
      - series: 'mcp_tool_duration_seconds_count{service_name="sales-mcp",environment="production",tool="slow_lookup"}'
        values: '0+100x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="fast_lookup",le="1"}'
        values: '0+90x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="fast_lookup",le="2"}'
        values: '0+96x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="fast_lookup",le="5"}'
        values: '0+100x20'
      - series: 'mcp_tool_duration_seconds_bucket{service_name="sales-mcp",environment="production",tool="fast_lookup",le="+Inf"}'
        values: '0+100x20'
      - series: 'mcp_tool_duration_seconds_count{service_name="sales-mcp",environment="production",tool="fast_lookup"}'
        values: '0+100x20'
    alert_rule_test:
      - eval_time: 2m
        alertname: MCPToolLatencyHigh
        exp_alerts: []
      - eval_time: 10m
        alertname: MCPToolLatencyHigh
        exp_alerts:
          - exp_labels:
              service_name: sales-mcp
              environment: production
              tool: slow_lookup
              severity: warning
            exp_annotations:
              summary: "Sustained MCP tool latency"
