{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://402rates.com/schemas/agent-test-report-v2.json",
  "title": "Compass synthetic test timeline, version 2",
  "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",
    "scenario"
  ],
  "properties": {
    "report_version": {
      "const": "2.0.0"
    },
    "case_id": {
      "enum": [
        "retry_budget_and_attempt_limit",
        "partial_result_with_continuation"
      ]
    },
    "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",
      "maxItems": 160,
      "items": {
        "type": "object",
        "required": [
          "sequence",
          "at",
          "request_id",
          "type"
        ],
        "properties": {
          "sequence": {
            "type": "integer",
            "minimum": 1
          },
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "state_after": {
      "type": "object",
      "required": [
        "task_id",
        "operation_records",
        "case_state"
      ],
      "properties": {
        "task_id": {
          "type": "string",
          "format": "uuid"
        },
        "operation_records": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "object"
          }
        },
        "case_state": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    "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",
      "required": [
        "status",
        "previous_run_id",
        "previous"
      ],
      "properties": {
        "status": {
          "enum": [
            "not_linked",
            "available",
            "previous_expired_or_unavailable"
          ]
        },
        "previous_run_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "previous": {
          "type": [
            "object",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "scenario": {
      "type": "object",
      "required": [
        "variant"
      ],
      "properties": {
        "variant": {
          "enum": [
            "budget_first",
            "attempts_first",
            "standard"
          ]
        }
      },
      "additionalProperties": true
    }
  },
  "$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"
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "retry_budget_and_attempt_limit"
          }
        }
      },
      "then": {
        "properties": {
          "scenario": {
            "oneOf": [
              {
                "const": {
                  "variant": "budget_first",
                  "budget_credits": 5,
                  "cost_per_independent_attempt": 2,
                  "action_call_limit": 4,
                  "independent_attempts_before_success": 4
                }
              },
              {
                "const": {
                  "variant": "attempts_first",
                  "budget_credits": 10,
                  "cost_per_independent_attempt": 1,
                  "action_call_limit": 3,
                  "independent_attempts_before_success": 4
                }
              }
            ]
          },
          "state_after": {
            "properties": {
              "case_state": {
                "type": "object",
                "required": [
                  "scenario",
                  "simulated_credits",
                  "independent_attempts",
                  "ledger"
                ],
                "additionalProperties": false,
                "properties": {
                  "scenario": {
                    "oneOf": [
                      {
                        "const": {
                          "variant": "budget_first",
                          "budget_credits": 5,
                          "cost_per_independent_attempt": 2,
                          "action_call_limit": 4,
                          "independent_attempts_before_success": 4
                        }
                      },
                      {
                        "const": {
                          "variant": "attempts_first",
                          "budget_credits": 10,
                          "cost_per_independent_attempt": 1,
                          "action_call_limit": 3,
                          "independent_attempts_before_success": 4
                        }
                      }
                    ]
                  },
                  "simulated_credits": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "independent_attempts": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 20
                  },
                  "ledger": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "object",
                      "required": [
                        "action_call",
                        "key_ref",
                        "replayed",
                        "charged_credits",
                        "cumulative_credits"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "action_call": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 20
                        },
                        "key_ref": {
                          "type": "string"
                        },
                        "replayed": {
                          "type": "boolean"
                        },
                        "charged_credits": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "cumulative_credits": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "else": {
        "properties": {
          "scenario": {
            "const": {
              "variant": "standard",
              "expected_record_count": 6,
              "page_size": 3
            }
          },
          "state_after": {
            "properties": {
              "case_state": {
                "type": "object",
                "required": [
                  "scenario",
                  "pages_delivered",
                  "submitted_record_ids"
                ],
                "additionalProperties": false,
                "properties": {
                  "scenario": {
                    "const": {
                      "variant": "standard",
                      "expected_record_count": 6,
                      "page_size": 3
                    }
                  },
                  "pages_delivered": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "object",
                      "required": [
                        "cursor",
                        "record_ids",
                        "at"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "cursor": {
                          "enum": [
                            "first",
                            "second"
                          ]
                        },
                        "record_ids": {
                          "type": "array",
                          "minItems": 3,
                          "maxItems": 3,
                          "items": {
                            "type": "string"
                          }
                        },
                        "at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  },
                  "submitted_record_ids": {
                    "type": "array",
                    "maxItems": 6,
                    "items": {
                      "type": "string",
                      "maxLength": 64
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ]
}
