{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://capp.local/schemas/capp.test-script.v1.schema.json",
  "title": "cApp Test Script v1",
  "description": "Portable, bounded UI automation script for the native cApp Test Runner. Actions target only the selected registered same-origin application surface.",
  "type": "object",
  "additionalProperties": false,
  "required": ["protocol", "steps"],
  "properties": {
    "protocol": { "const": "capp.test-script.v1" },
    "name": { "type": "string", "minLength": 1, "maxLength": 120 },
    "surface": { "type": "string", "minLength": 1, "maxLength": 120, "default": "app" },
    "steps": {
      "type": "array",
      "maxItems": 500,
      "items": { "$ref": "#/$defs/step" }
    }
  },
  "$defs": {
    "point": {
      "oneOf": [
        {
          "type": "array",
          "prefixItems": [{ "type": "number" }, { "type": "number" }],
          "minItems": 2,
          "maxItems": 2
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["x", "y"],
          "properties": {
            "x": { "type": "number" },
            "y": { "type": "number" }
          }
        }
      ]
    },
    "step": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action"],
      "properties": {
        "action": {
          "enum": [
            "move", "hover", "path", "click", "doubleClick", "clickAt", "drag",
            "type", "clear", "select", "check", "uncheck", "focus", "key", "submit",
            "scroll", "scrollIntoView", "wait", "waitFor", "assert", "screenshot"
          ]
        },
        "selector": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "toSelector": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "text": { "type": ["string", "number", "boolean", "null"] },
        "value": { "type": ["string", "number", "boolean", "null"] },
        "key": { "type": "string", "minLength": 1, "maxLength": 64 },
        "code": { "type": "string", "maxLength": 64 },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "exists": { "type": "boolean" },
        "visible": { "type": "boolean" },
        "checked": { "type": "boolean" },
        "textIncludes": { "type": ["string", "number", "boolean"] },
        "textEquals": { "type": ["string", "number", "boolean"] },
        "valueEquals": { "type": ["string", "number", "boolean", "null"] },
        "intoView": { "type": "boolean" },
        "x": { "type": "number" },
        "y": { "type": "number" },
        "toX": { "type": "number" },
        "toY": { "type": "number" },
        "ms": { "type": "number", "minimum": 0, "maximum": 60000 },
        "durationMs": { "type": "number", "minimum": 0, "maximum": 60000 },
        "timeoutMs": { "type": "number", "minimum": 100, "maximum": 60000 },
        "segments": { "type": "integer", "minimum": 2, "maximum": 30 },
        "block": { "enum": ["start", "center", "end", "nearest"] },
        "inline": { "enum": ["start", "center", "end", "nearest"] },
        "points": {
          "type": "array",
          "minItems": 1,
          "maxItems": 200,
          "items": { "$ref": "#/$defs/point" }
        }
      }
    }
  },
  "examples": [
    {
      "protocol": "capp.test-script.v1",
      "name": "Starter UI smoke",
      "surface": "app",
      "steps": [
        { "action": "waitFor", "selector": "body", "visible": true, "timeoutMs": 8000 },
        { "action": "assert", "selector": "body", "exists": true, "visible": true },
        { "action": "screenshot", "name": "loaded" }
      ]
    }
  ]
}
