{
  "_comment": "Runnable test vectors for the Collar Guardrail policy engine. Each vector is an input and the verdict shape the engine must produce. Feed them to the API or the local engine. Any mismatch is a bug.",

  "slippage_guard": [
    {
      "name": "within tolerance, silent",
      "input": {"oracle_price": 100.0, "pool_price": 100.5, "max_slippage_bps": 100},
      "expect": {"decision": "allow", "has_advisory": false}
    },
    {
      "name": "above half tolerance, advisory",
      "input": {"oracle_price": 100.0, "pool_price": 100.6, "max_slippage_bps": 100},
      "expect": {"decision": "allow", "has_advisory": true, "advisory_contains": "more than half your tolerance"}
    },
    {
      "name": "above tolerance, deny",
      "input": {"oracle_price": 100.0, "pool_price": 101.5, "max_slippage_bps": 100},
      "expect": {"decision": "deny", "reason_contains": "outside your tolerance"}
    },
    {
      "name": "above hard floor, deny regardless of tolerance",
      "input": {"oracle_price": 100.0, "pool_price": 106.0, "max_slippage_bps": 1000},
      "expect": {"decision": "deny", "reason_contains": "safety floor"}
    },
    {
      "name": "symmetric downside is caught too",
      "input": {"oracle_price": 100.0, "pool_price": 98.5, "max_slippage_bps": 100},
      "expect": {"decision": "deny"}
    }
  ],

  "tier_limits": [
    {
      "name": "tier 1 exact limit",
      "input": {"tier": 1, "notional_usd": 5000.00},
      "expect": {"decision": "allow", "reason_not_contains": "exceeds"}
    },
    {
      "name": "tier 1 just over",
      "input": {"tier": 1, "notional_usd": 5000.01},
      "expect": {"decision": "deny", "reason_contains": "Tier 1 limit"}
    },
    {
      "name": "tier 2 exact limit",
      "input": {"tier": 2, "notional_usd": 25000.00},
      "expect": {"decision": "allow"}
    },
    {
      "name": "tier 3 exact limit",
      "input": {"tier": 3, "notional_usd": 100000.00},
      "expect": {"decision": "allow"}
    },
    {
      "name": "tier 3 just over",
      "input": {"tier": 3, "notional_usd": 100000.01},
      "expect": {"decision": "deny", "reason_contains": "Tier 3 limit"}
    }
  ],

  "price_resolution": [
    {
      "name": "oracle available, no fallback",
      "input": {"asset": "NVDA", "oracle_price": 218.5, "v4_price": 218.4},
      "expect": {"price_source": "oracle", "price_usd": 218.5}
    },
    {
      "name": "oracle paused, v4 available",
      "input": {"asset": "NVDA", "oracle_price": null, "v4_price": 218.4},
      "expect": {"price_source": "uniswap_v4", "price_usd": 218.4}
    },
    {
      "name": "both unavailable, deny",
      "input": {"asset": "NVDA", "oracle_price": null, "v4_price": null},
      "expect": {"decision": "deny", "price_source": "unavailable", "reason_contains": "No live price available"}
    }
  ],

  "advisory_contract": [
    {
      "name": "reason classification, advisory vs blocking",
      "input": {
        "reasons": [
          "ADVISORY: No live oracle price configured for NVDA — using fallback",
          "Calculated trade value $22,200.00 exceeds Tier 1 limit of $5,000.00"
        ],
        "decision": "DENY"
      },
      "expect": {
        "primary_reason_starts_with": "Calculated trade value",
        "primary_reason_does_not_start_with": "ADVISORY:"
      }
    },
    {
      "name": "only advisories, fall back to first",
      "input": {
        "reasons": ["ADVISORY: only advisory here"],
        "decision": "DENY"
      },
      "expect": {
        "primary_reason": "ADVISORY: only advisory here"
      }
    }
  ],

  "rate_limiting": [
    {
      "name": "tier 1 within window",
      "input": {"tier": 1, "trades_in_last_60s": 3},
      "expect": {"outcome": "ok"}
    },
    {
      "name": "tier 1 above warn threshold",
      "input": {"tier": 1, "trades_in_last_60s": 6},
      "expect": {"outcome": "warn", "reason_contains": "wallet cluster"}
    },
    {
      "name": "tier 1 above deny threshold",
      "input": {"tier": 1, "trades_in_last_60s": 16},
      "expect": {"outcome": "deny", "reason_contains": "wallet cluster"}
    },
    {
      "name": "tier 3 within warn threshold",
      "input": {"tier": 3, "trades_in_last_60s": 15},
      "expect": {"outcome": "ok"}
    },
    {
      "name": "tier 3 above deny threshold",
      "input": {"tier": 3, "trades_in_last_60s": 51},
      "expect": {"outcome": "deny"}
    }
  ],

  "daily_loss_guard": [
    {
      "name": "profit, no trigger",
      "input": {"cluster_net_flow_usd_24h": 500.0},
      "expect": {"decision": "allow"}
    },
    {
      "name": "small loss, no trigger",
      "input": {"cluster_net_flow_usd_24h": -150.0},
      "expect": {"decision": "allow"}
    },
    {
      "name": "moderate loss, warn",
      "input": {"cluster_net_flow_usd_24h": -300.0},
      "expect": {"decision": "warn", "reason_contains": "Consider slowing down"}
    },
    {
      "name": "hard loss limit hit",
      "input": {"cluster_net_flow_usd_24h": -1200.0},
      "expect": {"decision": "deny", "reason_contains": "Daily loss limit hit"}
    }
  ],

  "market_hours": [
    {"name": "Saturday", "input_utc": "2024-01-06T15:00:00Z", "expect_market_closed": true},
    {"name": "Sunday", "input_utc": "2024-01-07T15:00:00Z", "expect_market_closed": true},
    {"name": "Monday before open", "input_utc": "2024-01-08T10:00:00Z", "expect_market_closed": true},
    {"name": "Monday exactly 14:30", "input_utc": "2024-01-08T14:30:00Z", "expect_market_closed": false},
    {"name": "Friday exactly 21:00", "input_utc": "2024-01-05T21:00:00Z", "expect_market_closed": true},
    {"name": "Wednesday peak", "input_utc": "2024-01-03T15:00:00Z", "expect_market_closed": false},
    {"name": "Thanksgiving", "input_utc": "2024-11-28T15:00:00Z", "expect_market_closed": true},
    {"name": "Black Friday early close 17:59", "input_utc": "2024-11-29T17:59:00Z", "expect_market_closed": false},
    {"name": "Black Friday early close 18:00", "input_utc": "2024-11-29T18:00:00Z", "expect_market_closed": true},
    {"name": "Christmas", "input_utc": "2024-12-25T15:00:00Z", "expect_market_closed": true},
    {"name": "Christmas Eve early close 18:00", "input_utc": "2024-12-24T18:00:00Z", "expect_market_closed": true},
    {"name": "MLK Day", "input_utc": "2024-01-15T15:00:00Z", "expect_market_closed": true},
    {"name": "Memorial Day", "input_utc": "2024-05-27T15:00:00Z", "expect_market_closed": true},
    {"name": "Labor Day", "input_utc": "2024-09-02T15:00:00Z", "expect_market_closed": true},
    {"name": "Juneteenth", "input_utc": "2024-06-19T15:00:00Z", "expect_market_closed": true},
    {"name": "Independence Day", "input_utc": "2024-07-04T15:00:00Z", "expect_market_closed": true},
    {"name": "New Year's Day", "input_utc": "2024-01-01T15:00:00Z", "expect_market_closed": true}
  ],

  "risk_score": [
    {
      "name": "clean small trade",
      "input": {"notional": 100, "tier": 3, "trade_count": 1, "blocked": false, "verified": true},
      "expect": {"score_max": 15}
    },
    {
      "name": "over tier limit",
      "input": {"notional": 1000000, "tier": 1, "trade_count": 1, "blocked": false, "verified": true},
      "expect": {"score_max": 100, "score_min": 30}
    },
    {
      "name": "at deny rate threshold",
      "input": {"notional": 100, "tier": 1, "trade_count": 15, "blocked": false, "verified": true},
      "expect": {"score_min": 30}
    },
    {
      "name": "unverified + blocked",
      "input": {"notional": 100, "tier": 1, "trade_count": 1, "blocked": true, "verified": false},
      "expect": {"score_min": 40}
    }
  ],

  "contract_mismatch": [
    {
      "name": "registered asset, correct contract",
      "input": {"asset": "NVDA", "contract_address": "0xd0601CE157Db5bdC3162BbaC2a2C8aF5320D9EEC"},
      "expect": {"decision_any": true}
    },
    {
      "name": "registered asset, wrong contract",
      "input": {"asset": "NVDA", "contract_address": "0x1111111111111111111111111111111111111111"},
      "expect": {"decision": "deny", "reason_contains": "Contract address mismatch"}
    }
  ],

  "kill_switch": [
    {
      "name": "kill switch active",
      "input": {"killswitch_set": true},
      "expect": {"decision": "deny", "reason_contains": "kill-switch"}
    }
  ]
}
