{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://402rates.com/schemas/agent-test-report-v1.json",
  "title": "Synthetic agent test timeline, version 1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "report_version",
    "case_id",
    "case_version",
    "run_id",
    "task_id",
    "environment",
    "evidence_source",
    "lifecycle",
    "completion_reason",
    "started_at",
    "active_until",
    "ended_at",
    "expires_at",
    "configuration_change",
    "observations",
    "events",
    "state_after",
    "coverage",
    "limitations",
    "comparison"
  ],
  "properties": {
    "report_version": {
      "const": "1.0.0"
    },
    "case_id": {
      "const": "commit_then_confirmation_unavailable"
    },
    "case_version": {
      "const": "1.0.0"
    },
    "run_id": {
      "type": "string",
      "format": "uuid"
    },
    "task_id": {
      "type": "string",
      "format": "uuid"
    },
    "environment": {
      "const": "synthetic"
    },
    "evidence_source": {
      "const": "test_service_observations"
    },
    "lifecycle": {
      "enum": [
        "active",
        "finalized"
      ]
    },
    "completion_reason": {
      "enum": [
        null,
        "caller_finalized",
        "active_deadline_elapsed",
        "action_limit_reached"
      ]
    },
    "started_at": {
      "type": "string",
      "format": "date-time"
    },
    "active_until": {
      "type": "string",
      "format": "date-time"
    },
    "ended_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    },
    "configuration_change": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "provenance",
        "value"
      ],
      "properties": {
        "provenance": {
          "const": "caller_declared"
        },
        "value": {
          "type": [
            "boolean",
            "null"
          ]
        }
      }
    },
    "observations": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "action_calls_received",
        "operation_records_created",
        "idempotent_replays",
        "distinct_action_keys",
        "state_reads",
        "confirmation_replacements",
        "action_calls_rejected"
      ],
      "properties": {
        "action_calls_received": {
          "type": "integer",
          "minimum": 0
        },
        "operation_records_created": {
          "type": "integer",
          "minimum": 0
        },
        "idempotent_replays": {
          "type": "integer",
          "minimum": 0
        },
        "distinct_action_keys": {
          "type": "integer",
          "minimum": 0
        },
        "state_reads": {
          "type": "integer",
          "minimum": 0
        },
        "confirmation_replacements": {
          "type": "integer",
          "minimum": 0
        },
        "action_calls_rejected": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/event"
      },
      "maxItems": 150
    },
    "state_after": {
      "$ref": "#/$defs/state"
    },
    "coverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "exercised",
        "not_exercised"
      ],
      "properties": {
        "exercised": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "not_exercised": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "limitations": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "comparison": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "previous_run_id",
        "previous"
      ],
      "properties": {
        "status": {
          "enum": [
            "not_linked",
            "available",
            "previous_expired_or_unavailable"
          ]
        },
        "previous_run_id": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "previous": {
          "anyOf": [
            {
              "$ref": "#/$defs/previous"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  },
  "$defs": {
    "operation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "operation_id",
        "task_id",
        "item",
        "quantity",
        "created_at",
        "key_ref"
      ],
      "properties": {
        "operation_id": {
          "type": "string",
          "format": "uuid"
        },
        "task_id": {
          "type": "string",
          "format": "uuid"
        },
        "item": {
          "const": "synthetic_order"
        },
        "quantity": {
          "const": 1
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "key_ref": {
          "type": "string",
          "pattern": "^key_[1-9][0-9]*$"
        }
      }
    },
    "state": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "task_id",
        "operation_records"
      ],
      "properties": {
        "task_id": {
          "type": "string",
          "format": "uuid"
        },
        "operation_records": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/operation"
          },
          "maxItems": 20
        }
      }
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sequence",
        "at",
        "request_id",
        "type"
      ],
      "properties": {
        "sequence": {
          "type": "integer",
          "minimum": 1
        },
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "request_id": {
          "type": "string",
          "format": "uuid"
        },
        "type": {
          "enum": [
            "run_started",
            "action_received",
            "action_rejected",
            "action_replayed",
            "operation_created",
            "confirmation_replaced",
            "state_read",
            "run_finalized"
          ]
        },
        "key_ref": {
          "type": "string"
        },
        "input": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "quantity"
          ],
          "properties": {
            "quantity": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10
            }
          }
        },
        "code": {
          "type": "string"
        },
        "operation_id": {
          "type": "string",
          "format": "uuid"
        },
        "state_after": {
          "$ref": "#/$defs/state"
        },
        "mode": {
          "const": "application_error"
        },
        "reason": {
          "enum": [
            "caller_finalized",
            "active_deadline_elapsed",
            "action_limit_reached"
          ]
        }
      }
    },
    "previous": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "report_version",
        "case_id",
        "case_version",
        "run_id",
        "task_id",
        "environment",
        "evidence_source",
        "lifecycle",
        "completion_reason",
        "started_at",
        "active_until",
        "ended_at",
        "expires_at",
        "configuration_change",
        "observations",
        "events",
        "state_after",
        "coverage",
        "limitations"
      ],
      "properties": {
        "report_version": {
          "const": "1.0.0"
        },
        "case_id": {
          "const": "commit_then_confirmation_unavailable"
        },
        "case_version": {
          "const": "1.0.0"
        },
        "run_id": {
          "type": "string",
          "format": "uuid"
        },
        "task_id": {
          "type": "string",
          "format": "uuid"
        },
        "environment": {
          "const": "synthetic"
        },
        "evidence_source": {
          "const": "test_service_observations"
        },
        "lifecycle": {
          "enum": [
            "active",
            "finalized"
          ]
        },
        "completion_reason": {
          "enum": [
            null,
            "caller_finalized",
            "active_deadline_elapsed",
            "action_limit_reached"
          ]
        },
        "started_at": {
          "type": "string",
          "format": "date-time"
        },
        "active_until": {
          "type": "string",
          "format": "date-time"
        },
        "ended_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ]
        },
        "expires_at": {
          "type": "string",
          "format": "date-time"
        },
        "configuration_change": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "provenance",
            "value"
          ],
          "properties": {
            "provenance": {
              "const": "caller_declared"
            },
            "value": {
              "type": [
                "boolean",
                "null"
              ]
            }
          }
        },
        "observations": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "action_calls_received",
            "operation_records_created",
            "idempotent_replays",
            "distinct_action_keys",
            "state_reads",
            "confirmation_replacements",
            "action_calls_rejected"
          ],
          "properties": {
            "action_calls_received": {
              "type": "integer",
              "minimum": 0
            },
            "operation_records_created": {
              "type": "integer",
              "minimum": 0
            },
            "idempotent_replays": {
              "type": "integer",
              "minimum": 0
            },
            "distinct_action_keys": {
              "type": "integer",
              "minimum": 0
            },
            "state_reads": {
              "type": "integer",
              "minimum": 0
            },
            "confirmation_replacements": {
              "type": "integer",
              "minimum": 0
            },
            "action_calls_rejected": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "events": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/event"
          },
          "maxItems": 150
        },
        "state_after": {
          "$ref": "#/$defs/state"
        },
        "coverage": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "exercised",
            "not_exercised"
          ],
          "properties": {
            "exercised": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "not_exercised": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "limitations": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}
