{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/testing/layered-test-project.v1.schema.json",
  "title": "RootBlocks Layered Test Project Standard v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "standardId",
    "version",
    "scope",
    "productionLayers",
    "criticalWorkflowsPresent",
    "requiredTestUnits",
    "dependencyRules",
    "workflowTestSplit",
    "waiverPolicy",
    "testDataOwnership",
    "languageProfiles"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.layered-test-project/v1"
    },
    "standardId": {
      "$ref": "#/$defs/id"
    },
    "version": {
      "$ref": "#/$defs/semver"
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["productNeutral", "runtimeNeutral", "materializesTestingCraft"],
      "properties": {
        "productNeutral": {
          "type": "boolean"
        },
        "runtimeNeutral": {
          "type": "boolean"
        },
        "materializesTestingCraft": {
          "const": "rootblocks.testing-craft"
        }
      }
    },
    "productionLayers": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/productionLayer"
      },
      "uniqueItems": true
    },
    "criticalWorkflowsPresent": {
      "type": "boolean"
    },
    "requiredTestUnits": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/testUnit"
      }
    },
    "dependencyRules": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/dependencyRule"
      }
    },
    "workflowTestSplit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "workflowNodeUnitId",
        "workflowRegressionUnitId",
        "mustBeSeparate",
        "fullGraphBehaviorOnlyInRegression",
        "criticalRegressionRequired"
      ],
      "properties": {
        "workflowNodeUnitId": {
          "$ref": "#/$defs/id"
        },
        "workflowRegressionUnitId": {
          "$ref": "#/$defs/id"
        },
        "mustBeSeparate": {
          "type": "boolean"
        },
        "fullGraphBehaviorOnlyInRegression": {
          "type": "boolean"
        },
        "criticalRegressionRequired": {
          "type": "boolean"
        }
      }
    },
    "waiverPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowCombinedNonCriticalWithWaiver",
        "waiverRequiredForCombination",
        "waiverEvidenceRequired",
        "nonWaivableUnits"
      ],
      "properties": {
        "allowCombinedNonCriticalWithWaiver": {
          "type": "boolean"
        },
        "waiverRequiredForCombination": {
          "type": "boolean"
        },
        "waiverEvidenceRequired": {
          "type": "boolean"
        },
        "nonWaivableUnits": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/testUnitType"
          },
          "uniqueItems": true
        }
      }
    },
    "testDataOwnership": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "localByDefault",
        "sharedInfrastructureRequiresProfile",
        "forbidUnownedSharedFolders",
        "sharedInfrastructureUnitId",
        "forbiddenUnownedPathTokens"
      ],
      "properties": {
        "localByDefault": {
          "type": "boolean"
        },
        "sharedInfrastructureRequiresProfile": {
          "type": "boolean"
        },
        "forbidUnownedSharedFolders": {
          "type": "boolean"
        },
        "sharedInfrastructureUnitId": {
          "$ref": "#/$defs/id"
        },
        "forbiddenUnownedPathTokens": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": ["shared", "common", "global-test-data"]
          },
          "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.-]+)?$"
    },
    "productionLayer": {
      "enum": ["domain", "application", "infrastructure", "workflows", "interface"]
    },
    "testUnitType": {
      "enum": [
        "domain-tests",
        "application-tests",
        "infrastructure-tests",
        "workflows-tests",
        "interface-tests",
        "architecture-tests",
        "contract-tests",
        "integration-tests",
        "e2e-tests",
        "workflow-regression-tests"
      ]
    },
    "testUnit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "unitType",
        "materialization",
        "pathPattern",
        "requiredWhen",
        "coversLayers",
        "sourceMapRequired",
        "evidenceRequired",
        "dependencyProfile",
        "testData"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "unitType": {
          "$ref": "#/$defs/testUnitType"
        },
        "materialization": {
          "enum": ["dedicated", "combined"]
        },
        "combinedWith": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/testUnitType"
          },
          "uniqueItems": true
        },
        "waiverRef": {
          "$ref": "#/$defs/id"
        },
        "pathPattern": {
          "type": "string",
          "minLength": 1
        },
        "requiredWhen": {
          "enum": ["always", "when-layer-present", "when-critical-workflow", "when-public-contract", "when-risk-requires"]
        },
        "coversLayers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/productionLayer"
          },
          "uniqueItems": true
        },
        "sourceMapRequired": {
          "type": "boolean"
        },
        "evidenceRequired": {
          "type": "boolean"
        },
        "dependencyProfile": {
          "$ref": "#/$defs/dependencyProfile"
        },
        "testData": {
          "$ref": "#/$defs/testData"
        }
      }
    },
    "dependencyProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowedTestUnits",
        "allowedProductionLayers",
        "forbiddenProductionLayers",
        "forbiddenRuntimeDependencies"
      ],
      "properties": {
        "allowedTestUnits": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/testUnitType"
          },
          "uniqueItems": true
        },
        "allowedProductionLayers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/productionLayer"
          },
          "uniqueItems": true
        },
        "forbiddenProductionLayers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/productionLayer"
          },
          "uniqueItems": true
        },
        "forbiddenRuntimeDependencies": {
          "type": "array",
          "items": {
            "enum": ["builderx", "real-infrastructure", "database-sdk", "cloud-sdk", "messaging-sdk", "host-runtime"]
          },
          "uniqueItems": true
        },
        "integrationProfileRequired": {
          "type": "boolean"
        }
      }
    },
    "dependencyRule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "fromUnit",
        "allowedProductionLayers",
        "forbiddenProductionLayers",
        "forbiddenRuntimeDependencies"
      ],
      "properties": {
        "fromUnit": {
          "$ref": "#/$defs/testUnitType"
        },
        "allowedProductionLayers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/productionLayer"
          },
          "uniqueItems": true
        },
        "forbiddenProductionLayers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/productionLayer"
          },
          "uniqueItems": true
        },
        "forbiddenRuntimeDependencies": {
          "type": "array",
          "items": {
            "enum": ["builderx", "real-infrastructure", "database-sdk", "cloud-sdk", "messaging-sdk", "host-runtime"]
          },
          "uniqueItems": true
        },
        "integrationProfileRequired": {
          "type": "boolean"
        }
      }
    },
    "testData": {
      "type": "object",
      "additionalProperties": false,
      "required": ["localRoots", "sharedRootsAllowed"],
      "properties": {
        "localRoots": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "sharedRoots": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "sharedRootsAllowed": {
          "type": "boolean"
        },
        "sharedInfrastructureProfileRef": {
          "$ref": "#/$defs/id"
        }
      }
    },
    "languageProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["language", "unitMappings"],
      "properties": {
        "language": {
          "enum": ["csharp", "typescript", "javascript", "python", "java", "kotlin", "go", "rust", "php", "ruby", "custom"]
        },
        "unitMappings": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/unitMapping"
          }
        }
      }
    },
    "unitMapping": {
      "type": "object",
      "additionalProperties": false,
      "required": ["unitType", "artifactKind", "defaultPathPattern"],
      "properties": {
        "unitType": {
          "$ref": "#/$defs/testUnitType"
        },
        "artifactKind": {
          "enum": ["project", "module", "package", "source-set", "suite", "custom"]
        },
        "defaultPathPattern": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
