{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tenantatlas.local/schemas/test-lane-manifest.schema.json",
  "title": "TestLaneManifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "lanes",
    "artifactDirectory",
    "familyBudgets"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "artifactDirectory": {
      "type": "string",
      "const": "storage/logs/test-lanes"
    },
    "lanes": {
      "type": "array",
      "minItems": 6,
      "maxItems": 6,
      "items": {
        "$ref": "#/$defs/lane"
      },
      "allOf": [
        {
          "contains": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "const": "fast-feedback"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "const": "confidence"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "const": "browser"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "const": "heavy-governance"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "const": "profiling"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "const": "junit"
              }
            }
          }
        }
      ]
    },
    "familyBudgets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/familyBudget"
      }
    }
  },
  "$defs": {
    "lane": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "governanceClass",
        "description",
        "intendedAudience",
        "includedFamilies",
        "excludedFamilies",
        "ownershipExpectations",
        "defaultEntryPoint",
        "parallelMode",
        "selectors",
        "artifacts",
        "budget",
        "dbStrategy"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "governanceClass": {
          "type": "string",
          "enum": [
            "fast",
            "confidence",
            "heavy",
            "support"
          ]
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "intendedAudience": {
          "type": "string",
          "minLength": 1
        },
        "includedFamilies": {
          "$ref": "#/$defs/stringArray"
        },
        "excludedFamilies": {
          "$ref": "#/$defs/stringArray"
        },
        "ownershipExpectations": {
          "type": "string",
          "minLength": 1
        },
        "defaultEntryPoint": {
          "type": "boolean"
        },
        "parallelMode": {
          "type": "string",
          "enum": [
            "required",
            "optional",
            "forbidden"
          ]
        },
        "selectors": {
          "$ref": "#/$defs/selectors"
        },
        "artifacts": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/artifactType"
          },
          "uniqueItems": true
        },
        "budget": {
          "$ref": "#/$defs/budget"
        },
        "dbStrategy": {
          "$ref": "#/$defs/dbStrategy"
        },
        "notes": {
          "type": "string"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "artifacts": {
                "contains": {
                  "const": "profile-top"
                }
              }
            }
          },
          "then": {
            "properties": {
              "parallelMode": {
                "const": "forbidden"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "fast-feedback"
              }
            }
          },
          "then": {
            "properties": {
              "defaultEntryPoint": {
                "const": true
              },
              "parallelMode": {
                "const": "required"
              },
              "budget": {
                "required": [
                  "baselineDeltaTargetPercent"
                ],
                "properties": {
                  "baselineDeltaTargetPercent": {
                    "const": 50
                  }
                }
              },
              "excludedFamilies": {
                "allOf": [
                  {
                    "contains": {
                      "const": "browser"
                    }
                  },
                  {
                    "contains": {
                      "const": "heavy-governance"
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "confidence"
              }
            }
          },
          "then": {
            "properties": {
              "parallelMode": {
                "const": "required"
              },
              "includedFamilies": {
                "allOf": [
                  {
                    "contains": {
                      "const": "unit"
                    }
                  },
                  {
                    "contains": {
                      "const": "non-browser-feature-integration"
                    }
                  }
                ]
              },
              "excludedFamilies": {
                "allOf": [
                  {
                    "contains": {
                      "const": "browser"
                    }
                  },
                  {
                    "contains": {
                      "const": "heavy-governance"
                    }
                  }
                ]
              },
              "selectors": {
                "properties": {
                  "includeSuites": {
                    "contains": {
                      "const": "Unit"
                    }
                  },
                  "excludeSuites": {
                    "contains": {
                      "const": "Browser"
                    }
                  }
                },
                "anyOf": [
                  {
                    "properties": {
                      "includePaths": {
                        "minItems": 1
                      }
                    }
                  },
                  {
                    "properties": {
                      "includeGroups": {
                        "minItems": 1
                      }
                    }
                  },
                  {
                    "properties": {
                      "includeFiles": {
                        "minItems": 1
                      }
                    }
                  }
                ]
              },
              "defaultEntryPoint": {
                "const": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "browser"
              }
            }
          },
          "then": {
            "properties": {
              "governanceClass": {
                "const": "heavy"
              },
              "includedFamilies": {
                "contains": {
                  "const": "browser"
                }
              },
              "selectors": {
                "properties": {
                  "includeSuites": {
                    "contains": {
                      "const": "Browser"
                    }
                  }
                },
                "required": [
                  "includeSuites"
                ]
              },
              "defaultEntryPoint": {
                "const": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "heavy-governance"
              }
            }
          },
          "then": {
            "properties": {
              "defaultEntryPoint": {
                "const": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "profiling"
              }
            }
          },
          "then": {
            "properties": {
              "governanceClass": {
                "const": "support"
              },
              "defaultEntryPoint": {
                "const": false
              },
              "artifacts": {
                "contains": {
                  "const": "profile-top"
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "junit"
              }
            }
          },
          "then": {
            "properties": {
              "governanceClass": {
                "const": "support"
              },
              "defaultEntryPoint": {
                "const": false
              },
              "artifacts": {
                "contains": {
                  "const": "junit-xml"
                }
              }
            }
          }
        }
      ]
    },
    "selectors": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "includeSuites",
        "includePaths",
        "includeGroups",
        "includeFiles",
        "excludeSuites",
        "excludePaths",
        "excludeGroups",
        "excludeFiles"
      ],
      "properties": {
        "includeSuites": {
          "$ref": "#/$defs/stringArray"
        },
        "includePaths": {
          "$ref": "#/$defs/stringArray"
        },
        "includeGroups": {
          "$ref": "#/$defs/stringArray"
        },
        "includeFiles": {
          "$ref": "#/$defs/stringArray"
        },
        "excludeSuites": {
          "$ref": "#/$defs/stringArray"
        },
        "excludePaths": {
          "$ref": "#/$defs/stringArray"
        },
        "excludeGroups": {
          "$ref": "#/$defs/stringArray"
        },
        "excludeFiles": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "anyOf": [
        {
          "properties": {
            "includeSuites": {
              "minItems": 1
            }
          }
        },
        {
          "properties": {
            "includePaths": {
              "minItems": 1
            }
          }
        },
        {
          "properties": {
            "includeGroups": {
              "minItems": 1
            }
          }
        },
        {
          "properties": {
            "includeFiles": {
              "minItems": 1
            }
          }
        }
      ]
    },
    "budget": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "thresholdSeconds",
        "baselineSource",
        "enforcement",
        "lifecycleState"
      ],
      "properties": {
        "thresholdSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "baselineSource": {
          "type": "string",
          "enum": [
            "measured-current-suite",
            "measured-lane"
          ]
        },
        "enforcement": {
          "type": "string",
          "enum": [
            "report-only",
            "warn",
            "hard-fail"
          ]
        },
        "lifecycleState": {
          "type": "string",
          "enum": [
            "draft",
            "measured",
            "documented",
            "enforced"
          ]
        },
        "baselineDeltaTargetPercent": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "notes": {
          "type": "string"
        },
        "reviewCadence": {
          "type": "string"
        }
      }
    },
    "familyBudget": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "familyId",
        "selectorType",
        "selectors",
        "thresholdSeconds",
        "baselineSource",
        "enforcement",
        "lifecycleState"
      ],
      "properties": {
        "familyId": {
          "type": "string",
          "minLength": 1
        },
        "selectorType": {
          "type": "string",
          "enum": [
            "testsuite",
            "path",
            "group",
            "file"
          ]
        },
        "selectors": {
          "$ref": "#/$defs/stringArray",
          "minItems": 1
        },
        "thresholdSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "baselineSource": {
          "type": "string",
          "enum": [
            "measured-current-suite",
            "measured-lane"
          ]
        },
        "enforcement": {
          "type": "string",
          "enum": [
            "report-only",
            "warn",
            "hard-fail"
          ]
        },
        "lifecycleState": {
          "type": "string",
          "enum": [
            "draft",
            "measured",
            "documented",
            "enforced"
          ]
        },
        "notes": {
          "type": "string"
        },
        "reviewCadence": {
          "type": "string"
        }
      }
    },
    "dbStrategy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "connectionMode",
        "resetStrategy",
        "seedsPolicy"
      ],
      "properties": {
        "connectionMode": {
          "type": "string",
          "enum": [
            "sqlite-memory",
            "pgsql",
            "mixed"
          ]
        },
        "resetStrategy": {
          "type": "string",
          "enum": [
            "none",
            "refresh-database",
            "dedicated-suite"
          ]
        },
        "seedsPolicy": {
          "type": "string",
          "enum": [
            "forbidden",
            "restricted",
            "allowed-by-exception"
          ]
        },
        "schemaBaselineCandidate": {
          "type": "boolean",
          "default": false
        }
      }
    },
    "artifactType": {
      "type": "string",
      "enum": [
        "summary",
        "junit-xml",
        "profile-top",
        "budget-report"
      ]
    },
    "stringArray": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true,
      "default": []
    }
  }
}