{
  "id": "starter-branch-delete",
  "name": "Delete the disposable Starter branch",
  "start": { "path": "/tidbs/{{starterClusterId}}/branches" },
  "risk": "mutating",
  "completionMutation": {
    "guardId": "starter-branch-delete",
    "recoveryPath": "/tidbs/{{starterClusterId}}/branches"
  },
  "variables": {
    "branchName": {
      "env": ["E2E_STARTER_BRANCH_NAME"],
      "default": "{{clusterName}}-branch",
      "required": true
    }
  },
  "goal": [
    "Open Branches and delete only {{branchName}}, confirming the destructive dialog.",
    "If it is already absent, do nothing. Finish when the loaded list no longer contains it."
  ],
  "success": {
    "evidence": [
      { "kind": "url", "matches": "/tidbs/[^/]+/branches(?:[/?]|$)" },
      {
        "kind": "responseArrayAbsent",
        "pathMatches": "^/api/v1/serverless/orgs/[^/]+/projects/[^/]+/clusters/{{starterClusterId}}/branches$",
        "arrayPath": "branches",
        "where": { "display_name": "{{branchName}}" },
        "pagination": { "pageParameter": "page_token", "sizeParameter": "page_size", "totalPath": "total" }
      },
      { "kind": "absentText", "matches": "^{{branchName}}$" }
    ]
  },
  "recovery": [
    "Operate only on the row whose visible name exactly equals {{branchName}}.",
    "After one accepted delete request, only observe; if already absent, do not open another row menu."
  ],
  "safety": {
    "backgroundReadStubs": [
      {
        "pathMatches": "^/external/metrics/",
        "json": { "status": "success", "data": { "resultType": "matrix", "result": [] } }
      }
    ],
    "deny": ["Do not delete main, another branch, or the cluster."],
    "networkGuards": [
      {
        "id": "starter-branch-delete",
        "method": "DELETE",
        "pathMatches": "^/api/v1/serverless/orgs/[^/]+/projects/[^/]+/clusters/{{starterClusterId}}/branches/[^/]+$",
        "pageMustContain": ["{{branchName}}"],
        "resourceIdentity": {
          "requestPathMatches": "^/api/v1/serverless/orgs/[^/]+/projects/[^/]+/clusters/{{starterClusterId}}/branches/([^/]+)$",
          "capturedVariable": "starterBranchId"
        },
        "maxRequests": 1
      }
    ]
  }
}
