{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xinp-hub.github.io/pydiggs/schemas/preview/diggs-conformance-1.0-beta.3.schema.json",
  "title": "diggs-conformance 1.0-beta.3",
  "description": "Evidence that one submission passed or failed one class of the pyDIGGS conformance suite. Preview: this beta may change before 1.0. The document holds no time and no machine detail, so the same challenge and submission always give the same document. 1.0-beta.3 adds the optional source_export, which only the evidence of an import challenge made from another product's export has; a document without it means what a 1.0-beta.2 document means. A document that matches this schema is well formed, no more: pydiggs conformance verify grades the submission again and compares, and for a source_export it also reads the challenge's file and grades it as an export.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "format",
    "schema_version",
    "suite_version",
    "tool",
    "tier",
    "statement",
    "class",
    "product",
    "challenge",
    "submission",
    "verdict",
    "stages"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "const": "diggs-conformance"
    },
    "schema_version": {
      "const": "1.0-beta.3"
    },
    "suite_version": {
      "type": "string",
      "description": "The version of the classes, scenarios, checks and tolerances that graded the submission: the suite that made the challenge. A release may grade a challenge of an earlier suite, by that suite's rules, and then writes that suite's version here."
    },
    "tool": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "version"
      ],
      "properties": {
        "name": {
          "const": "pydiggs"
        },
        "version": {
          "type": "string"
        }
      }
    },
    "tier": {
      "enum": [
        "self-tested"
      ],
      "description": "self-tested: a local run. It shows that the file passed, not which software wrote it."
    },
    "statement": {
      "type": "string",
      "description": "What this evidence does and does not show."
    },
    "class": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "family",
        "direction",
        "title",
        "level",
        "diggs_version"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "family": {
          "type": "string"
        },
        "direction": {
          "enum": [
            "export",
            "import"
          ]
        },
        "title": {
          "type": "string"
        },
        "level": {
          "enum": [
            "core"
          ]
        },
        "diggs_version": {
          "type": "string"
        }
      }
    },
    "product": {
      "type": "object",
      "description": "The software under test, as its vendor declared it when the challenge was made.",
      "additionalProperties": false,
      "required": [
        "name",
        "version"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      }
    },
    "challenge": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "seed",
        "token",
        "sha256"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "The challenge's stable identity: SHA-256 of canonical JSON (sorted keys, no whitespace) of challenge.json's suite_version, class, diggs_version, seed, token and product, and of its source_export when it has one. The same in every pyDIGGS release."
        },
        "seed": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._-]{1,64}$"
        },
        "token": {
          "type": "string",
          "description": "Derived from the seed; it appears in the project's name."
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of challenge.json as written, its file digests included; another pyDIGGS release may write the files, and so this digest, differently."
        }
      }
    },
    "source_export": {
      "type": "object",
      "description": "Only on the evidence of an import challenge made from another product's export (pydiggs conformance new <family>-import --from-export): the DIGGS file in the importing product's challenge is that export, not the suite's own file. It names the export by digest, never by path, and is copied from the challenge, whose id covers it. It is the importing party's statement: verify confirms that the challenge's file has export_sha256 and passes the export class for this challenge's seed; the product and evidence_sha256 are confirmed only against the exporter's own evidence (pydiggs conformance matrix). Without this member the file was the suite's own.",
      "additionalProperties": false,
      "required": [
        "product",
        "export_sha256",
        "evidence_sha256",
        "suite_version"
      ],
      "properties": {
        "product": {
          "type": "object",
          "description": "The exporting product, as its own evidence declares it.",
          "additionalProperties": false,
          "required": [
            "name",
            "version"
          ],
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          }
        },
        "export_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 of the exported DIGGS file, which is the challenge.xml of the importing product's challenge; the submission.sha256 of the exporter's evidence."
        },
        "evidence_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 of the exporter's evidence document, as the file was given when the challenge was made. pydiggs conformance new graded the export again against it at that moment; nothing in this document proves that afterwards, and the matrix compares this digest with the exporter's evidence in its folder."
        },
        "suite_version": {
          "type": "string",
          "description": "The suite version that graded the export; the same as this document's.",
          "minLength": 1,
          "maxLength": 200
        }
      }
    },
    "submission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "sha256",
        "bytes"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "The file's name, without its folder."
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "bytes": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "verdict": {
      "enum": [
        "pass",
        "fail"
      ],
      "description": "pass when every required stage passed."
    },
    "stages": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "required",
          "status",
          "passed",
          "total",
          "failed",
          "items",
          "items_truncated"
        ],
        "properties": {
          "id": {
            "enum": [
              "readable",
              "validation",
              "core",
              "fidelity",
              "values",
              "robustness"
            ]
          },
          "title": {
            "type": "string"
          },
          "required": {
            "type": "boolean",
            "description": "Whether the stage decides the verdict."
          },
          "status": {
            "enum": [
              "pass",
              "fail",
              "skipped"
            ]
          },
          "passed": {
            "type": "integer",
            "minimum": 0
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "failed": {
            "type": "integer",
            "minimum": 0,
            "description": "How many things failed in all; for the validation stage, the number of validation errors."
          },
          "items": {
            "type": "array",
            "maxItems": 200,
            "description": "What failed, at most 200 (items_truncated says whether there were more). File text is kept as it is; escape it before showing it. expected and got are in SI units.",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "check",
                "id",
                "message"
              ],
              "properties": {
                "check": {
                  "type": "string",
                  "description": "A conformance check id, or the rule id of a validation finding."
                },
                "id": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                },
                "expected": {
                  "type": "string"
                },
                "got": {
                  "type": "string"
                }
              }
            }
          },
          "items_truncated": {
            "type": "boolean"
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "required": [
          "source_export"
        ]
      },
      "then": {
        "properties": {
          "class": {
            "properties": {
              "direction": {
                "const": "import"
              }
            }
          }
        }
      }
    }
  ]
}
