{
  "name": "compatibility_testing",
  "title": "兼容性测试",
  "description": "兼容性测试",
  "group": "develop",
  "version": "1.0.0",
  "input_schema": {
    "type": "object",
    "properties": {
      "task": {
        "type": "string",
        "description": "需要执行的任务描述"
      },
      "file_path": {
        "type": "string",
        "description": "代码写入的目标文件路径"
      }
    },
    "required": ["task", "file_path"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "msg": {
        "type": "string",
        "description": "测试执行结果描述"
      },
      "stdout": {
        "type": "string",
        "description": "测试标准输出"
      },
      "stderr": {
        "type": "string",
        "description": "测试标准错误"
      },
      "exit_code": {
        "type": "number",
        "description": "测试退出码"
      }
    }
  },
  "steps": [
    {
      "id": "generate_code",
      "description": "按兼容性测试规范生成代码",
      "operator": "executor",
      "handler": "llm",
      "on_error": {
        "retry": 2,
        "retry_delay": 500
      },
      "params": {
        "system_prompt": "{{ $meta.system_prompt }}",
        "user_prompt": "{{ $input.task }}"
      }
    },
    {
      "id": "verify_format",
      "description": "验证代码语法和格式规范",
      "operator": "validator",
      "handler": "code",
      "params": {
        "code": "{{ $steps.generate_code.content }}"
      }
    },
    {
      "id": "check_valid",
      "description": "校验失败则中止，通过则写入文件",
      "operator": "dispatcher",
      "handler": "condition",
      "params": {
        "source": "{{ $steps.verify_format.valid }}",
        "operator": "truthy",
        "then_jump": "write_file",
        "else_jump": "end"
      }
    },
    {
      "id": "write_file",
      "description": "将生成的代码写入文件",
      "operator": "manager",
      "handler": "file",
      "params": {
        "action": "write",
        "file_path": "{{ $input.file_path }}",
        "content": "{{ $steps.generate_code.content }}"
      }
    },
    {
      "id": "test_code",
      "description": "运行代码进行测试",
      "operator": "executor",
      "handler": "command",
      "params": {
        "command": "node {{ $input.file_path }}"
      }
    },
    {
      "id": "log_artifact",
      "description": "记录产出文件信息",
      "operator": "manager",
      "handler": "artifact",
      "params": {
        "work_name": "compatibility_testing",
        "stage": "executed",
        "file_path": "{{ $input.file_path }}",
        "valid": "{{ $steps.verify_format.valid }}",
        "error_count": "{{ $steps.verify_format.error_count }}",
        "exit_code": "{{ $steps.test_code.exit_code }}",
        "line_count": "{{ $steps.verify_format.line_count }}"
      }
    },
    {
      "id": "log_call",
      "description": "记录调用日志",
      "operator": "manager",
      "handler": "call_log",
      "params": {
        "work_name": "compatibility_testing",
        "stage": "executed",
        "status": "{{ $steps.verify_format.valid && $steps.test_code.exit_code === 0 ? 'success' : 'fail' }}",
        "input_preview": { "$expr": "String($input.task).slice(0, 80)" },
        "last_error": "{{ $last_error }}"
      }
    }
  ]
}
