{
  "format": "flow-studio-project-export/v1",
  "metadata": {
    "title": "行为用例 · 设备连接",
    "description": "独立会话核对连接成功、失败提示与取消；不调用真实设备服务。"
  },
  "manifest": {
    "format": "flow-studio-project/v1",
    "adapter": "generic",
    "source": "flow.json",
    "defaultGroup": "main",
    "defaultScenario": "default"
  },
  "flow": {
    "schemaVersion": 2,
    "version": "DRAFT-01",
    "entry": "start",
    "status": "新建项目草稿，等待 AI 补充真实需求",
    "defaults": {
      "state": {
        "name": "",
        "status": "idle"
      }
    },
    "conditions": {},
    "effects": {
      "startWork": "开始连接",
      "done": "连接完成",
      "reset": "取消连接"
    },
    "conditionValues": {},
    "effectValues": {
      "startWork": {
        "status": "running"
      },
      "done": {
        "status": "done"
      },
      "reset": {
        "status": "idle"
      }
    },
    "actions": {
      "connect": {
        "task": "connect",
        "effect": "startWork",
        "validate": true
      },
      "cancel": {
        "stay": true,
        "cancelTasks": [
          "connect"
        ],
        "effect": "reset"
      },
      "close": {
        "dismiss": true
      }
    },
    "fixed": {},
    "groups": [
      {
        "id": "main",
        "title": "主要流程",
        "description": "",
        "screens": [
          "start",
          "finish",
          "error"
        ],
        "main": [
          "start",
          "finish"
        ]
      }
    ],
    "scenarios": [
      {
        "id": "default",
        "title": "初始样例",
        "entry": "start",
        "state": {}
      }
    ],
    "uncovered": [
      "真实需求、条件分支与异常恢复待补充"
    ],
    "deferred": [],
    "screens": {
      "start": {
        "title": "连接设备",
        "blocks": [
          {
            "id": "name",
            "type": "field",
            "field": "name",
            "label": "设备名称",
            "required": true
          },
          {
            "id": "connect",
            "type": "action",
            "text": "开始连接",
            "action": "connect"
          },
          {
            "id": "cancel",
            "type": "action",
            "text": "取消连接",
            "action": "cancel"
          }
        ]
      },
      "finish": {
        "title": "连接完成",
        "back": {
          "to": "start"
        },
        "blocks": [
          {
            "id": "done",
            "type": "heading",
            "text": "{name} 已连接"
          },
          {
            "id": "again",
            "type": "action",
            "text": "返回",
            "action": "start"
          }
        ]
      },
      "error": {
        "title": "连接失败",
        "presentation": "dialog",
        "blocks": [
          {
            "id": "error-text",
            "type": "text",
            "text": "连接未完成，可关闭后重试。"
          },
          {
            "id": "close",
            "type": "action",
            "text": "关闭",
            "action": "close"
          }
        ]
      }
    },
    "tasks": {
      "connect": {
        "title": "连接设备",
        "outcomes": {
          "success": {
            "to": "finish",
            "effect": "done"
          },
          "failure": {
            "present": "error"
          }
        }
      }
    },
    "events": {
      "disconnect": {
        "title": "设备断开",
        "routes": [
          {
            "cancelTasks": [
              "connect"
            ],
            "stay": true,
            "effect": "reset"
          }
        ]
      }
    },
    "testCases": [
      {
        "id": "success",
        "title": "填写后连接成功",
        "scenario": "default",
        "steps": [
          {
            "type": "input",
            "blockId": "name",
            "value": "耳机"
          },
          {
            "type": "click",
            "blockId": "connect"
          },
          {
            "type": "taskResult",
            "taskId": "connect",
            "outcome": "success"
          },
          {
            "type": "assert",
            "page": "finish",
            "state": {
              "name": "耳机",
              "status": "done"
            }
          }
        ]
      },
      {
        "id": "failure",
        "title": "失败提示保留原页面与输入",
        "scenario": "default",
        "steps": [
          {
            "type": "input",
            "blockId": "name",
            "value": "音箱"
          },
          {
            "type": "click",
            "blockId": "connect"
          },
          {
            "type": "taskResult",
            "taskId": "connect",
            "outcome": "failure"
          },
          {
            "type": "assert",
            "page": "error",
            "base": "start",
            "layers": [
              "error"
            ]
          },
          {
            "type": "dismiss"
          },
          {
            "type": "assert",
            "page": "start",
            "layers": [],
            "state": {
              "name": "音箱"
            }
          }
        ]
      },
      {
        "id": "cancel",
        "title": "外部断开取消任务",
        "scenario": "default",
        "steps": [
          {
            "type": "input",
            "blockId": "name",
            "value": "手柄"
          },
          {
            "type": "click",
            "blockId": "connect"
          },
          {
            "type": "event",
            "eventId": "disconnect"
          },
          {
            "type": "taskResult",
            "taskId": "connect",
            "outcome": "success",
            "accepted": false
          },
          {
            "type": "assert",
            "page": "start",
            "state": {
              "status": "idle"
            }
          }
        ]
      },
      {
        "id": "required",
        "title": "必填缺失阻止连接",
        "scenario": "default",
        "steps": [
          {
            "type": "click",
            "blockId": "connect",
            "accepted": false
          },
          {
            "type": "assert",
            "page": "start",
            "errors": [
              "name"
            ]
          }
        ]
      }
    ]
  }
}
