{
  "id": "starter-branch-create",
  "name": "Create a disposable Starter branch",
  "start": { "path": "/tidbs/{{starterClusterId}}/branches" },
  "risk": "mutating",
  "completionMutation": {
    "guardId": "starter-branch-create",
    "recoveryPath": "/tidbs/{{starterClusterId}}/branches"
  },
  "variables": {
    "branchName": {
      "env": ["E2E_STARTER_BRANCH_NAME"],
      "default": "{{clusterName}}-branch",
      "required": true
    }
  },
  "initialization": ["Open Branches and, if {{branchName}} already exists, do not create a duplicate."],
  "goal": [
    "Create exactly one branch named {{branchName}} from main at the current point in time when it is absent.",
    "Wait until {{branchName}} is visible and Active."
  ],
  "success": {
    "evidence": [
      { "kind": "url", "matches": "/tidbs/[^/]+/branches(?:[/?]|$)" },
      { "kind": "visibleText", "text": "{{branchName}}", "timeoutMs": 60000 },
      {
        "kind": "responseArrayContains",
        "pathMatches": "^/api/v1/serverless/orgs/[^/]+/projects/[^/]+/clusters/{{starterClusterId}}/branches$",
        "arrayPath": "branches",
        "where": { "display_name": "{{branchName}}", "state": "READY" },
        "pagination": { "pageParameter": "page_token", "sizeParameter": "page_size", "totalPath": "total" },
        "capture": { "variable": "starterBranchId", "path": "id" },
        "timeoutMs": 180000
      }
    ]
  },
  "recovery": ["After one accepted create request, only observe; never submit Create again."],
  "limits": { "maxDurationMs": 240000, "maxActions": 22 },
  "safety": {
    "backgroundReadStubs": [
      {
        "pathMatches": "^/external/metrics/",
        "json": { "status": "success", "data": { "resultType": "matrix", "result": [] } }
      }
    ],
    "deny": [
      "Do not create a differently named branch.",
      "Do not reset, rename, connect to, or delete any branch or cluster."
    ],
    "networkGuards": [
      {
        "id": "starter-branch-create",
        "method": "POST",
        "pathMatches": "^/api/v1/serverless/orgs/[^/]+/projects/[^/]+/clusters/[^/]+/branches$",
        "bodyEquals": { "display_name": "{{branchName}}" },
        "resourceIdentity": {
          "requestPathMatches": "^/api/v1/serverless/orgs/[^/]+/projects/[^/]+/clusters/([^/]+)/branches$",
          "pagePathMatches": "^/tidbs/([^/]+)/branches$"
        },
        "maxRequests": 1,
        "deduplicateBy": ["display_name"],
        "captureResponse": { "variable": "starterBranchId", "paths": ["id"], "reuseAsConfirmed": false }
      }
    ]
  }
}
