{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/testing/testing-craft.v1.schema.json",
  "title": "RootBlocks Testing Craft Standard v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "craftId",
    "version",
    "standard",
    "taxonomy",
    "layerMappings",
    "workflowTestSplit",
    "applicationBoundary",
    "architectureBoundaryTests",
    "criticalWorkflowCoverage",
    "sourceMapEvidence",
    "languageProfiles"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.testing-craft/v1"
    },
    "craftId": {
      "$ref": "#/$defs/id"
    },
    "version": {
      "$ref": "#/$defs/semver"
    },
    "standard": {
      "type": "object",
      "additionalProperties": false,
      "required": ["scope", "productNeutral", "runtimeNeutral", "appliesTo"],
      "properties": {
        "scope": {
          "enum": ["global", "organization-extension", "project-extension"]
        },
        "productNeutral": {
          "type": "boolean"
        },
        "runtimeNeutral": {
          "type": "boolean"
        },
        "appliesTo": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": ["generated-projects", "workflow-driven-systems", "component-packages", "manual-governed-projects"]
          },
          "uniqueItems": true
        }
      }
    },
    "taxonomy": {
      "type": "array",
      "minItems": 11,
      "items": {
        "$ref": "#/$defs/testCategoryDefinition"
      },
      "allOf": [
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "domain-core" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "application" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "infrastructure-adapter" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "workflow-node-operation" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "interface" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "architecture-boundary" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "contract" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "integration" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "e2e" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "workflow-regression" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "security" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "static-analysis" } } } },
        { "contains": { "type": "object", "required": ["category"], "properties": { "category": { "const": "performance-load" } } } }
      ]
    },
    "layerMappings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/layerMapping"
      }
    },
    "workflowTestSplit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "nodeOperationSuiteId",
        "regressionSuiteId",
        "mustBeDistinct",
        "nodeOperationScope",
        "regressionScope"
      ],
      "properties": {
        "nodeOperationSuiteId": {
          "$ref": "#/$defs/id"
        },
        "regressionSuiteId": {
          "$ref": "#/$defs/id"
        },
        "mustBeDistinct": {
          "type": "boolean"
        },
        "nodeOperationScope": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": ["node-operation", "variables", "context", "node-result", "error-path", "application-port-fake"]
          },
          "uniqueItems": true
        },
        "regressionScope": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": [
              "full-builderx-execution",
              "path-assertions",
              "trace-assertions",
              "variable-assertions",
              "evidence-output",
              "branch-path",
              "failure-path"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "applicationBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["builderXFree", "infrastructureFree", "usesPortsOrFakes", "forbidsRuntimePackageReferences"],
      "properties": {
        "builderXFree": {
          "type": "boolean"
        },
        "infrastructureFree": {
          "type": "boolean"
        },
        "usesPortsOrFakes": {
          "type": "boolean"
        },
        "forbidsRuntimePackageReferences": {
          "type": "boolean"
        }
      }
    },
    "architectureBoundaryTests": {
      "type": "object",
      "additionalProperties": false,
      "required": ["required", "blocksRelease", "checks"],
      "properties": {
        "required": {
          "type": "boolean"
        },
        "blocksRelease": {
          "type": "boolean"
        },
        "checks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": [
              "forbidden-references",
              "package-ownership",
              "folder-taxonomy",
              "workflow-infrastructure-direct-call",
              "layer-dependency-direction"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "criticalWorkflowCoverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "required",
        "happyPathRequired",
        "branchOrFailurePathRequired",
        "minimumRegressionCases",
        "requiresWorkflowNodeOperationTests",
        "pathAssertionsRequired",
        "evidenceRequired"
      ],
      "properties": {
        "required": {
          "type": "boolean"
        },
        "happyPathRequired": {
          "type": "boolean"
        },
        "branchOrFailurePathRequired": {
          "type": "boolean"
        },
        "minimumRegressionCases": {
          "type": "integer",
          "minimum": 0
        },
        "requiresWorkflowNodeOperationTests": {
          "type": "boolean"
        },
        "pathAssertionsRequired": {
          "type": "boolean"
        },
        "evidenceRequired": {
          "type": "boolean"
        }
      }
    },
    "sourceMapEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "testSourceMapRequired",
        "impactedArtifactIdsRequired",
        "evidenceRequired",
        "runnerResultRequired",
        "evidenceFields"
      ],
      "properties": {
        "testSourceMapRequired": {
          "type": "boolean"
        },
        "impactedArtifactIdsRequired": {
          "type": "boolean"
        },
        "evidenceRequired": {
          "type": "boolean"
        },
        "runnerResultRequired": {
          "type": "boolean"
        },
        "evidenceFields": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": [
              "test-id",
              "suite-id",
              "case-id",
              "source-map-id",
              "impacted-artifact-ids",
              "runner-result",
              "generated-artifact-hash",
              "builderx-trace-hash"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "languageProfiles": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/languageProfile"
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[A-Za-z0-9.-]+)?(\\+[A-Za-z0-9.-]+)?$"
    },
    "testCategory": {
      "enum": [
        "domain-core",
        "application",
        "infrastructure-adapter",
        "workflow-node-operation",
        "interface",
        "architecture-boundary",
        "contract",
        "integration",
        "e2e",
        "workflow-regression",
        "security",
        "static-analysis",
        "performance-load"
      ]
    },
    "testCategoryDefinition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["category", "requiredWhen", "scope", "sourceMapRequired", "evidenceRequired"],
      "properties": {
        "category": {
          "$ref": "#/$defs/testCategory"
        },
        "requiredWhen": {
          "enum": ["always", "when-layer-present", "when-public-contract", "when-critical-workflow", "when-risk-requires"]
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "sourceMapRequired": {
          "type": "boolean"
        },
        "evidenceRequired": {
          "type": "boolean"
        },
        "riskTriggered": {
          "type": "boolean"
        }
      }
    },
    "layerMapping": {
      "type": "object",
      "additionalProperties": false,
      "required": ["layer", "category", "projectOrModule", "sourceMapRequired", "evidenceRequired"],
      "properties": {
        "layer": {
          "enum": ["domain", "application", "infrastructure", "workflows", "interface", "architecture", "contract", "integration", "e2e", "security"]
        },
        "category": {
          "$ref": "#/$defs/testCategory"
        },
        "projectOrModule": {
          "type": "string",
          "minLength": 1
        },
        "sourceMapRequired": {
          "type": "boolean"
        },
        "evidenceRequired": {
          "type": "boolean"
        }
      }
    },
    "languageProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["language", "testFrameworkMapping"],
      "properties": {
        "language": {
          "enum": ["csharp", "typescript", "javascript", "python", "java", "kotlin", "go", "rust", "php", "ruby", "custom"]
        },
        "testFrameworkMapping": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/frameworkMapping"
          }
        }
      }
    },
    "frameworkMapping": {
      "type": "object",
      "additionalProperties": false,
      "required": ["category", "defaultProjectPattern", "runner", "allowedRuntimeDependencies", "forbiddenRuntimeDependencies"],
      "properties": {
        "category": {
          "$ref": "#/$defs/testCategory"
        },
        "defaultProjectPattern": {
          "type": "string",
          "minLength": 1
        },
        "runner": {
          "type": "string",
          "minLength": 1
        },
        "allowedRuntimeDependencies": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "forbiddenRuntimeDependencies": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      }
    }
  }
}
