{
  "id": "starter-chat2query",
  "name": "Run a Starter SQL query",
  "skip": {
    "reason": "SQL Editor cannot create a session through Data App Gateway and returns [59900500] Internal Error; keep the migrated case disabled until the environment is healthy."
  },
  "risk": "mutating",
  "goal": [
    "Open Chat2Query and wait until Run is enabled and the Schemas panel has finished loading without an Internal Error.",
    "Using only the visible editor, run select 333; and stop as soon as 333 appears in the result."
  ],
  "success": {
    "evidence": [
      { "kind": "url", "matches": "/tidbs/[^/]+/(?:chat2query|sql-editor)(?:[/?]|$)" },
      { "kind": "testIdVisible", "testId": "chat2query-run-btn" },
      { "kind": "visibleText", "text": "333" },
      { "kind": "visibleText", "text": "1 rows" },
      { "kind": "absentText", "matches": "Query Running|The execution result is loading|\\[59900500\\] Internal Error" }
    ]
  },
  "terminalFailure": {
    "message": "The SQL Editor still shows [59900500] Internal Error after the single allowed reload.",
    "evidence": [{ "kind": "visibleText", "text": "[59900500] Internal Error" }]
  },
  "recovery": [
    "Do not click Run while the Schemas panel shows Error or [59900500] Internal Error. Reload once, then wait for the schema error to clear; if it persists, stop and report the environment failure.",
    "Wait for Run to become enabled before the one statement. Do not run it twice.",
    "If the editor reference becomes stale, observe fresh page state; do not repeat an accepted statement.",
    "Once 333 is visible in the result, stop immediately."
  ],
  "limits": { "maxDurationMs": 180000, "maxActions": 15 },
  "safety": {
    "deny": [
      "Do not run SQL other than select 333;.",
      "Do not intentionally create or modify SQL files beyond the editor's automatic Getting Started autosave; do not modify tables or any other remote resource."
    ],
    "networkGuards": [
      {
        "id": "starter-sql-session",
        "method": "POST",
        "pathMatches": "^/api/v1/dataapps/sqleditor/orgs/[^/]+/projects/[^/]+/clusters/[^/]+/session$",
        "bodyEquals": { "database": "" },
        "maxRequests": 4
      },
      {
        "id": "starter-safe-statements",
        "method": "POST",
        "pathMatches": "^/api/v1/dataapps/sqleditor/orgs/[^/]+/projects/[^/]+/clusters/[^/]+/statements$",
        "bodyMatches": {
          "sql": "^select 333;$"
        },
        "maxRequests": 1
      },
      {
        "id": "starter-create-default-sql-file",
        "method": "POST",
        "pathMatches": "^/api/v1/dataapps/sqleditor/orgs/[^/]+/projects/[^/]+/clusters/[^/]+/sqlfiles$",
        "bodyMatches": {
          "name": "^Getting Started$",
          "content": "^(?:use databaseNameHere;\\n\\n)?/\\* Enter \\\"USE \\{database\\};\\\" to start exploring your data\\.\\n   Press Ctrl \\+ I to try out AI-generated SQL queries or SQL rewrite using Chat2Query\\. \\*/\\nUSE $"
        },
        "maxRequests": 1
      },
      {
        "id": "starter-update-default-sql-file",
        "method": "PUT",
        "pathMatches": "^/api/v1/dataapps/sqleditor/orgs/[^/]+/projects/[^/]+/clusters/[^/]+/sqlfiles/[^/]+$",
        "bodyMatches": {
          "name": "^Getting Started$",
          "content": "^(?:use databaseNameHere;\\n\\n/\\* Enter \\\"USE \\{database\\};\\\" to start exploring your data\\.\\n   Press Ctrl \\+ I to try out AI-generated SQL queries or SQL rewrite using Chat2Query\\. \\*/\\nUSE |select 333;)$"
        },
        "maxRequests": 3
      }
    ]
  }
}
