{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://qzx.yumbale.com/schemas/result-contract-conformance-receipt-v1.schema.json",
  "title": "QZX Result Contract Conformance Receipt v1",
  "description": "Machine-readable receipt for a reviewable QZX Result Contract v1 success/failure evidence pair. Every valid receipt also satisfies the QZX Result Contract v1 core envelope. Schema validity means the receipt is structurally interpretable; it does not mean the submitted implementation conforms.",
  "type": "object",
  "required": [
    "receipt_schema",
    "success",
    "message",
    "warnings",
    "details"
  ],
  "properties": {
    "receipt_schema": {
      "const": "https://qzx.yumbale.com/schemas/result-contract-conformance-receipt-v1.schema.json"
    },
    "success": {
      "type": "boolean"
    },
    "message": {
      "type": "string",
      "minLength": 1,
      "pattern": "\\S"
    },
    "error_code": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]*$"
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "pattern": "\\S"
      }
    },
    "details": {
      "type": "object",
      "required": [
        "report_schema_version",
        "contract_version",
        "contract_schema",
        "profile",
        "mcp_specification",
        "tool_definition",
        "violations",
        "cases"
      ],
      "properties": {
        "report_schema_version": {
          "const": 1
        },
        "contract_version": {
          "const": "v1"
        },
        "contract_schema": {
          "const": "https://qzx.yumbale.com/schemas/result-contract-v1.schema.json"
        },
        "validation_materials": {
          "$ref": "#/$defs/validationMaterials"
        },
        "profile": {
          "enum": [
            "core",
            "mcp-2025-06-18",
            "mcp-2025-11-25",
            "mcp-2026-07-28"
          ]
        },
        "mcp_specification": {
          "enum": [
            null,
            "2025-06-18",
            "2025-11-25",
            "2026-07-28"
          ]
        },
        "tool_definition": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/toolDefinition"
            }
          ]
        },
        "violations": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "cases": {
          "type": "array",
          "minItems": 2,
          "maxItems": 2,
          "prefixItems": [
            {
              "allOf": [
                {
                  "$ref": "#/$defs/case"
                },
                {
                  "properties": {
                    "name": {
                      "const": "success"
                    },
                    "expected_success": {
                      "const": true
                    }
                  }
                }
              ]
            },
            {
              "allOf": [
                {
                  "$ref": "#/$defs/case"
                },
                {
                  "properties": {
                    "name": {
                      "const": "failure"
                    },
                    "expected_success": {
                      "const": false
                    }
                  }
                }
              ]
            }
          ],
          "items": false
        }
      },
      "additionalProperties": false
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "success": {
            "const": false
          }
        },
        "required": [
          "success"
        ]
      },
      "then": {
        "required": [
          "error_code"
        ]
      }
    }
  ],
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "validationMaterial": {
      "type": "object",
      "required": [
        "repository_path",
        "sha256"
      ],
      "properties": {
        "repository_path": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "$ref": "#/$defs/sha256"
        }
      },
      "additionalProperties": false
    },
    "validationMaterials": {
      "type": "object",
      "required": [
        "contract_schema",
        "receipt_schema",
        "core_validator",
        "mcp_validator",
        "evidence_validator"
      ],
      "properties": {
        "contract_schema": {
          "allOf": [
            {
              "$ref": "#/$defs/validationMaterial"
            },
            {
              "properties": {
                "repository_path": {
                  "const": "src/qzx/resources/schemas/result-contract-v1.schema.json"
                }
              }
            }
          ]
        },
        "receipt_schema": {
          "allOf": [
            {
              "$ref": "#/$defs/validationMaterial"
            },
            {
              "properties": {
                "repository_path": {
                  "const": "src/qzx/resources/schemas/result-contract-conformance-receipt-v1.schema.json"
                }
              }
            }
          ]
        },
        "core_validator": {
          "allOf": [
            {
              "$ref": "#/$defs/validationMaterial"
            },
            {
              "properties": {
                "repository_path": {
                  "const": "src/qzx/core/result_contract.py"
                }
              }
            }
          ]
        },
        "mcp_validator": {
          "allOf": [
            {
              "$ref": "#/$defs/validationMaterial"
            },
            {
              "properties": {
                "repository_path": {
                  "const": "scripts/validate_mcp_result_contract.py"
                }
              }
            }
          ]
        },
        "evidence_validator": {
          "allOf": [
            {
              "$ref": "#/$defs/validationMaterial"
            },
            {
              "properties": {
                "repository_path": {
                  "const": "scripts/validate_result_contract_evidence.py"
                }
              }
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "toolDefinition": {
      "type": "object",
      "required": [
        "file",
        "sha256"
      ],
      "properties": {
        "file": {
          "type": "string"
        },
        "sha256": {
          "anyOf": [
            {
              "$ref": "#/$defs/sha256"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "profileFacts": {
      "type": "object",
      "properties": {
        "mcp_specification": {
          "enum": [
            "2025-06-18",
            "2025-11-25",
            "2026-07-28"
          ]
        },
        "mcp_tools_spec": {
          "enum": [
            "https://modelcontextprotocol.io/specification/2025-06-18/server/tools",
            "https://modelcontextprotocol.io/specification/2025-11-25/server/tools",
            "https://modelcontextprotocol.io/specification/2026-07-28/server/tools"
          ]
        },
        "contract": {
          "const": "https://qzx.yumbale.com/schemas/result-contract-v1.schema.json"
        },
        "output_schema_checked": {
          "type": "boolean"
        },
        "output_schema_mode": {
          "enum": [
            null,
            "canonical_ref",
            "canonical_inline",
            "canonical_allof",
            "structural_core"
          ]
        },
        "backcompat_text_matches": {
          "type": "boolean"
        },
        "mcp_is_error_explicit": {
          "type": "boolean"
        },
        "mcp_is_error_effective": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "case": {
      "type": "object",
      "required": [
        "name",
        "file",
        "sha256",
        "expected_success",
        "actual_success",
        "conformant",
        "violations",
        "warnings",
        "profile_facts"
      ],
      "properties": {
        "name": {
          "enum": [
            "success",
            "failure"
          ]
        },
        "file": {
          "type": "string"
        },
        "sha256": {
          "anyOf": [
            {
              "$ref": "#/$defs/sha256"
            },
            {
              "type": "null"
            }
          ]
        },
        "expected_success": {
          "type": "boolean"
        },
        "actual_success": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "conformant": {
          "type": "boolean"
        },
        "violations": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "profile_facts": {
          "$ref": "#/$defs/profileFacts"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
