{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rehearse.kurvball.ca/schema/v1/file-scenario.schema.json",
  "title": "*.rehearse.yaml",
  "description": "A file scenario: an input, a run, and the output it writes, compared by its own layout. Placeholders: {{input}} (the input file), {{output}} (a scratch folder for the output), {{here}} (this file's folder), {{checkout}}, {{manifest}}, {{world}}, {{person}}, and each service's {{<name>_url}}.",
  "type": "object",
  "required": ["name", "run", "output"],
  "properties": {
    "name": {
      "description": "What it tries, in plain words.",
      "type": "string",
      "minLength": 1
    },
    "describe": {
      "type": "string"
    },
    "world": {
      "type": "string"
    },
    "person": {
      "type": "string"
    },
    "services": {
      "description": "Services that must be up while it runs.",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "covers": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "input": {
      "description": "The input: a file beside this one, or a command that writes {{input}}.",
      "type": "object",
      "properties": {
        "file": {
          "type": "string"
        },
        "command": {
          "type": "string"
        },
        "name": {
          "description": "The input file's name in the scratch folder, when a command writes it. Default input.",
          "type": "string"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "run": {
      "description": "The command that turns the input into the output, run in the checkout.",
      "type": "string",
      "minLength": 1
    },
    "cwd": {
      "description": "Where run runs, relative to the checkout.",
      "type": "string"
    },
    "env": {
      "type": "object",
      "additionalProperties": {
        "type": ["string", "number", "boolean"]
      }
    },
    "timeout": {
      "description": "Seconds. Default 120.",
      "type": "number",
      "exclusiveMinimum": 0
    },
    "output": {
      "oneOf": [
        {
          "$ref": "#/$defs/output"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/output"
          },
          "minItems": 1
        }
      ]
    },
    "setAside": {
      "type": "object",
      "properties": {
        "columns": {
          "description": "Columns never compared, such as a generated id or a timestamp.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "values": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "keep": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "output": {
      "type": "object",
      "required": ["file", "layout"],
      "properties": {
        "file": {
          "description": "The output file, relative to {{output}}, or an absolute path such as {{checkout}}/out/report.csv.",
          "type": "string"
        },
        "layout": {
          "enum": ["csv", "tsv", "json", "lines", "fixed", "zip"]
        },
        "header": {
          "description": "csv and tsv: whether the first row names the columns. Default true.",
          "type": "boolean"
        },
        "columns": {
          "description": "csv and tsv without a header: the columns' names. fixed: each column's name, start and width.",
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "required": ["name", "start", "width"],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "start": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "width": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "additionalProperties": false
              }
            ]
          }
        },
        "unordered": {
          "description": "Compare rows (or array items) without their order.",
          "type": "boolean"
        },
        "entries": {
          "description": "zip: the layout of each entry, by glob. Entries no glob matches are compared as lines. skip compares only that an entry is there (for one that carries its own render time, such as a PDF); zip reads an archive inside the archive.",
          "type": "object",
          "additionalProperties": {
            "enum": ["csv", "tsv", "json", "lines", "zip", "skip"]
          }
        }
      },
      "additionalProperties": false
    }
  }
}
