{
  "spec": "https://p2a.sh/spec/agent-wake/0.1",
  "fixtures_version": "0.1",
  "license": "MIT",
  "layers": [
    "wake_ack",
    "fetch",
    "claim",
    "progress",
    "complete",
    "duplicate",
    "timeout",
    "approval",
    "give_up",
    "test",
    "versioning",
    "retry"
  ],
  "cases": [
    {
      "id": "wake.request.minimal",
      "layer": "wake_ack",
      "actor": "receiver",
      "description": "Required fields only. A 2xx answer accepts the wake and is not a claim.",
      "given": {
        "wake_version": "0.1",
        "type": "request",
        "event_id": "evt_example_0001",
        "request_id": "req_example_0001",
        "binding_id": "bind_example_0001",
        "fetch": "https://platform.example.com/wake/v0.1/requests/req_example_0001"
      },
      "expect": {
        "status": "2xx",
        "claim": false
      }
    },
    {
      "id": "wake.request.preview",
      "layer": "wake_ack",
      "actor": "receiver",
      "description": "Preview text ships with all three integrity fields. The hash covers full_text. text_complete false means the receiver must fetch.",
      "full_text": "The full example message is longer than the preview.",
      "given": {
        "wake_version": "0.1",
        "type": "request",
        "event_id": "evt_example_0002",
        "request_id": "req_example_0002",
        "binding_id": "bind_example_0002",
        "fetch": "https://platform.example.com/wake/v0.1/requests/req_example_0002",
        "text": "The full example message",
        "text_complete": false,
        "text_bytes": 52,
        "text_sha256": "61e547434cde0200436747c76a3836c675627c0801ec3c861ed0bb6bb11f5fe9"
      },
      "expect": {
        "status": "2xx",
        "must_fetch": true
      }
    },
    {
      "id": "wake.preview.invalid",
      "layer": "wake_ack",
      "actor": "receiver",
      "description": "Text without text_sha256 is not a preview. The receiver ignores it and fetches.",
      "given": {
        "wake_version": "0.1",
        "type": "request",
        "event_id": "evt_example_0003",
        "request_id": "req_example_0003",
        "binding_id": "bind_example_0003",
        "text": "Preview without a checksum"
      },
      "expect": {
        "status": "2xx",
        "ignore_preview": true,
        "must_fetch": true
      }
    },
    {
      "id": "fetch.authenticated",
      "layer": "fetch",
      "actor": "operation",
      "description": "The runtime fetches the request from the platform over the authenticated channel. Fetched content is untrusted input.",
      "given": {
        "request_id": "req_example_0002",
        "fetch": "https://platform.example.com/wake/v0.1/requests/req_example_0002"
      },
      "expect": {
        "authenticated": true,
        "untrusted_input": true
      }
    },
    {
      "id": "claim.ok",
      "layer": "claim",
      "actor": "operation",
      "description": "A fresh attempt id takes a lease.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "lease_seconds": 300
      },
      "expect": {
        "result": "lease"
      }
    },
    {
      "id": "claim.same_attempt_idempotent",
      "layer": "claim",
      "actor": "operation",
      "description": "Claiming again with the same attempt id is the same claim.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "lease_seconds": 300
      },
      "expect": {
        "idempotent": true
      }
    },
    {
      "id": "claim.other_attempt_live_lease",
      "layer": "claim",
      "actor": "operation",
      "description": "A different attempt id during a live lease is refused.",
      "given": {
        "request_id": "req_example_0001",
        "live_attempt_id": "att_example_0001",
        "attempt_id": "att_example_0002",
        "lease": "live"
      },
      "expect": {
        "error": "request_already_claimed"
      }
    },
    {
      "id": "claim.reused_attempt",
      "layer": "claim",
      "actor": "operation",
      "description": "Reusing an attempt id after that attempt finished is refused.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "attempt_state": "finished"
      },
      "expect": {
        "error": "attempt_id_already_used"
      }
    },
    {
      "id": "progress.renews_lease",
      "layer": "progress",
      "actor": "operation",
      "description": "A working progress note renews the lease.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "state": "working",
        "note": "example still working"
      },
      "expect": {
        "lease": "renewed"
      }
    },
    {
      "id": "complete.ok",
      "layer": "complete",
      "actor": "operation",
      "description": "A completion stores the result and wakes the sender with a reply.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "outcome": "completed",
        "result": "example result"
      },
      "expect": {
        "stored": true,
        "reply_wake": true
      }
    },
    {
      "id": "complete.retry_same_fingerprint",
      "layer": "complete",
      "actor": "operation",
      "description": "Repeating the same attempt, outcome and result returns the stored completion.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "outcome": "completed",
        "result": "example result"
      },
      "expect": {
        "stored": true,
        "idempotent": true
      }
    },
    {
      "id": "complete.conflict",
      "layer": "complete",
      "actor": "operation",
      "description": "A completion retry that changes the result is refused.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "outcome": "completed",
        "result": "a different example result"
      },
      "expect": {
        "error": "completion_conflict"
      }
    },
    {
      "id": "duplicate.same_event_id",
      "layer": "duplicate",
      "actor": "receiver",
      "description": "A second delivery of the same event id returns 2xx and does not run the work again.",
      "given": {
        "wake_version": "0.1",
        "type": "request",
        "event_id": "evt_example_0001",
        "request_id": "req_example_0001",
        "binding_id": "bind_example_0001",
        "fetch": "https://platform.example.com/wake/v0.1/requests/req_example_0001"
      },
      "expect": {
        "status": "2xx",
        "deliveries": 2,
        "executions": 1
      }
    },
    {
      "id": "duplicate.reactivation",
      "layer": "duplicate",
      "actor": "operation",
      "description": "A new event id for the same request is a new activation. Claiming with the same attempt id stays the same attempt.",
      "given": {
        "request_id": "req_example_0001",
        "previous_event_id": "evt_example_0001",
        "event_id": "evt_example_0007",
        "attempt_id": "att_example_0001"
      },
      "expect": {
        "claim": "same_attempt"
      }
    },
    {
      "id": "timeout.stalled_not_failed",
      "layer": "timeout",
      "actor": "operation",
      "description": "No heartbeat for twice the lease marks the request stalled, not failed. A late complete is still accepted.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "missed_heartbeats": 2,
        "lease_multiple": 2
      },
      "expect": {
        "state": "stalled",
        "failed": false,
        "late_complete": "accepted"
      }
    },
    {
      "id": "approval.needs_approval",
      "layer": "approval",
      "actor": "operation",
      "description": "needs_approval finishes at once, holds no claim, and the sender sees that the owner must answer.",
      "given": {
        "request_id": "req_example_0001",
        "attempt_id": "att_example_0001",
        "outcome": "needs_approval"
      },
      "expect": {
        "claim_held": false,
        "sender_sees": "waiting on owner"
      }
    },
    {
      "id": "give_up.activation_accepted_but_never_claimed",
      "layer": "give_up",
      "actor": "platform",
      "description": "After the published wake limit with no claim, the request fails and the sender is told once.",
      "given": {
        "request_id": "req_example_0001",
        "activations": 5,
        "claims": 0
      },
      "expect": {
        "error": "activation_accepted_but_never_claimed",
        "sender_notices": 1
      }
    },
    {
      "id": "wake.test",
      "layer": "test",
      "actor": "receiver",
      "description": "A test wake has no request id. The receiver answers 2xx and does not claim.",
      "given": {
        "wake_version": "0.1",
        "type": "test",
        "event_id": "evt_example_0004",
        "binding_id": "bind_example_0004"
      },
      "expect": {
        "status": "2xx",
        "claim": false
      }
    },
    {
      "id": "wake.unknown_field",
      "layer": "versioning",
      "actor": "receiver",
      "description": "An unrecognised field is ignored. The receiver still answers 2xx.",
      "given": {
        "wake_version": "0.1",
        "type": "request",
        "event_id": "evt_example_0005",
        "request_id": "req_example_0005",
        "binding_id": "bind_example_0005",
        "extra_example": "ignore"
      },
      "expect": {
        "status": "2xx",
        "ignore_unknown": true
      }
    },
    {
      "id": "wake.version.unsupported",
      "layer": "versioning",
      "actor": "receiver",
      "description": "A wake_version the receiver does not implement must not be claimed. Accepting the HTTP nudge is still 2xx.",
      "given": {
        "wake_version": "9.9",
        "type": "request",
        "event_id": "evt_example_0006",
        "request_id": "req_example_0006",
        "binding_id": "bind_example_0006"
      },
      "expect": {
        "status": "2xx",
        "claim": false
      }
    },
    {
      "id": "retry.410_binding_gone",
      "layer": "retry",
      "actor": "platform",
      "description": "HTTP 410 means the binding is gone. The platform deactivates it and tells the owner.",
      "given": {
        "status": 410,
        "binding_id": "bind_example_0001",
        "host": "receiver.example.com"
      },
      "expect": {
        "binding": "deactivated",
        "owner_told": true
      }
    },
    {
      "id": "retry.429_retry_after",
      "layer": "retry",
      "actor": "platform",
      "description": "HTTP 429 with Retry-After is honoured unless the wait would pass the deadline.",
      "given": {
        "status": 429,
        "retry_after_seconds": 30,
        "host": "receiver.example.com"
      },
      "expect": {
        "honour_retry_after": true
      }
    }
  ]
}
