{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rehearse.kurvball.ca/schema/v1/comparison.schema.json",
  "title": "Rehearse v1: rehearse compare --json",
  "description": "Scenarios run on a base and on a head, compared after what is set aside, each sorted into one verdict.",
  "type": "object",
  "required": [
    "v",
    "ok",
    "base",
    "head",
    "line",
    "counts",
    "scenarios",
    "notRun",
    "gone",
    "announcedUnchanged",
    "byChange"
  ],
  "properties": {
    "v": {
      "$ref": "common.schema.json#/$defs/v"
    },
    "ok": {
      "description": "true when both sides came up, every scenario ran, and nothing fails on the head or changed without saying so.",
      "type": "boolean"
    },
    "base": {
      "$ref": "#/$defs/side"
    },
    "head": {
      "$ref": "#/$defs/side"
    },
    "line": {
      "description": "The comparison in one line, as a gate shows it.",
      "type": "string",
      "examples": [
        "11 as on the base · 1 new · 1 changed and said so · 5 changed without saying so · 1 fails on the head"
      ]
    },
    "counts": {
      "type": "object",
      "required": ["same", "said", "unsaid", "new", "fails", "gone", "notRun"],
      "properties": {
        "same": {
          "type": "integer",
          "minimum": 0
        },
        "said": {
          "type": "integer",
          "minimum": 0
        },
        "announced": {
          "description": "Of said: announced by the change.",
          "type": "integer",
          "minimum": 0
        },
        "edited": {
          "description": "Of said: the scenario's own definition was edited.",
          "type": "integer",
          "minimum": 0
        },
        "unsaid": {
          "type": "integer",
          "minimum": 0
        },
        "new": {
          "type": "integer",
          "minimum": 0
        },
        "fails": {
          "type": "integer",
          "minimum": 0
        },
        "failsOnBoth": {
          "description": "Of fails: failing on the base as well, so not this change's doing.",
          "type": "integer",
          "minimum": 0
        },
        "gone": {
          "type": "integer",
          "minimum": 0
        },
        "notRun": {
          "description": "Scenarios that couldn't be run on a side, so have no verdict.",
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "scenarios": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "scenario",
          "verdict",
          "changed",
          "said",
          "failsOnBase",
          "failsOnHead",
          "differences",
          "setAside"
        ],
        "properties": {
          "scenario": {
            "$ref": "common.schema.json#/$defs/scenarioRef"
          },
          "verdict": {
            "$ref": "common.schema.json#/$defs/verdict"
          },
          "changed": {
            "description": "Whether its observation differs, after what is set aside.",
            "type": "boolean"
          },
          "said": {
            "description": "announced when the change announced it (this wins, since it carries why), else edited when its own definition changed, else null.",
            "enum": ["announced", "edited", null]
          },
          "why": {
            "description": "The announcement's line, when it was announced.",
            "type": ["string", "null"]
          },
          "failsOnBase": {
            "type": "boolean"
          },
          "failsOnHead": {
            "type": "boolean"
          },
          "differences": {
            "type": "array",
            "items": {
              "$ref": "common.schema.json#/$defs/difference"
            }
          },
          "setAside": {
            "$ref": "common.schema.json#/$defs/setAside"
          },
          "failures": {
            "description": "How it fails on the head.",
            "type": "array",
            "items": {
              "$ref": "common.schema.json#/$defs/failure"
            }
          },
          "baseFailures": {
            "description": "How it fails on the base.",
            "type": "array",
            "items": {
              "$ref": "common.schema.json#/$defs/failure"
            }
          },
          "cached": {
            "description": "Whether the base's observation came from the cache.",
            "type": "boolean"
          },
          "observations": {
            "description": "Where the two observations are kept, for the stage.",
            "type": "object",
            "properties": {
              "base": {
                "type": ["string", "null"]
              },
              "head": {
                "type": ["string", "null"]
              }
            }
          },
          "edited": {
            "description": "Whether its own definition changed between base and head, whatever said is.",
            "type": "boolean"
          }
        }
      }
    },
    "gone": {
      "description": "Scenarios on the base that the head no longer has.",
      "type": "array",
      "items": {
        "$ref": "common.schema.json#/$defs/scenarioRef"
      }
    },
    "announcedUnchanged": {
      "description": "Scenarios the change announced that didn't change: a note for the reader, never a failure.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["scenario", "why"],
        "properties": {
          "scenario": {
            "type": "string"
          },
          "why": {
            "type": "string"
          }
        }
      }
    },
    "byChange": {
      "description": "Changes made without saying so, grouped by what changed: one change in many scenarios is one thing to look at.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["path", "scenarios"],
        "properties": {
          "path": {
            "type": "string"
          },
          "scenarios": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "standins": {
      "type": "array",
      "items": {
        "$ref": "common.schema.json#/$defs/standin"
      }
    },
    "ms": {
      "type": "integer",
      "minimum": 0
    },
    "notRun": {
      "description": "Scenarios that couldn't be run on one side while the side itself came up: a world, the sign-in or the runner broke for them. They have no verdict.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["scenario", "side", "step", "says"],
        "properties": {
          "scenario": {
            "$ref": "common.schema.json#/$defs/scenarioRef"
          },
          "side": {
            "enum": ["base", "head"]
          },
          "step": {
            "type": "string",
            "examples": ["world", "signIn", "runner", "driver"]
          },
          "says": {
            "type": "string"
          }
        }
      }
    },
    "refused": {
      "description": "Scenario files Rehearse couldn't read, on either side.",
      "type": "array",
      "items": {
        "allOf": [
          {
            "$ref": "common.schema.json#/$defs/refused"
          },
          {
            "type": "object",
            "required": ["side"],
            "properties": {
              "side": {
                "enum": ["base", "head"]
              }
            }
          }
        ]
      }
    }
  },
  "$defs": {
    "side": {
      "type": "object",
      "required": ["checkout", "ok"],
      "properties": {
        "checkout": {
          "$ref": "common.schema.json#/$defs/checkout"
        },
        "ok": {
          "description": "false when this side couldn't be prepared or its services didn't come up; then no scenario has a verdict.",
          "type": "boolean"
        },
        "step": {
          "type": ["string", "null"]
        },
        "says": {
          "type": ["string", "null"]
        },
        "cached": {
          "description": "How many observations came from the cache.",
          "type": "integer",
          "minimum": 0
        }
      }
    }
  }
}
