142 lines
8.9 KiB
Python
142 lines
8.9 KiB
Python
"""
|
||
pipeline-sdlc adapter — registers all SDLC step types and handlers with pipeline-service engine.
|
||
"""
|
||
import logging
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
|
||
def load_sdlc_adapter():
|
||
"""Register all SDLC step types and handlers with pipeline-service engine."""
|
||
from pipeline_service.step_registry import register_step_type, register_handler
|
||
|
||
# --- Import handlers ---
|
||
from .handlers.design import handle_table_design, handle_crud_design, handle_api_design
|
||
from .handlers.develop import handle_code_generate, handle_code_compliance_check, handle_code_auto_fix
|
||
from .handlers.test import (
|
||
handle_test_case_generate, handle_functional_test,
|
||
handle_performance_test, handle_bug_report, handle_bug_verify,
|
||
)
|
||
from .handlers.deploy import (
|
||
handle_deploy_test, handle_deploy_test_verify,
|
||
handle_deploy_production, handle_deploy_production_verify,
|
||
)
|
||
from .handlers.ops import handle_monitor
|
||
|
||
# --- Register step types ---
|
||
step_types = [
|
||
# Phase 1: Requirements
|
||
{"name": "requirement_gathering", "title": "需求采集", "category": "requirements",
|
||
"description": "人工填写需求文档表单", "is_interactive": True, "interaction_type": "human_task",
|
||
"default_role": "product_manager", "timeout_seconds": 604800},
|
||
{"name": "requirement_review", "title": "需求评审", "category": "requirements",
|
||
"description": "利益相关方审批需求文档", "is_interactive": True, "interaction_type": "approval_gate",
|
||
"default_role": "stakeholder", "timeout_seconds": 259200},
|
||
|
||
# Phase 2: Design (parallel-safe)
|
||
{"name": "table_design", "title": "数据表设计", "category": "design",
|
||
"description": "LLM辅助生成models/*.json,人工确认", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "architect", "timeout_seconds": 172800},
|
||
{"name": "crud_design", "title": "CRUD设计", "category": "design",
|
||
"description": "LLM辅助生成json/*.json,人工确认", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "architect", "timeout_seconds": 172800},
|
||
{"name": "api_design", "title": "API设计", "category": "design",
|
||
"description": "LLM辅助生成API清单和.dspy规范", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "architect", "timeout_seconds": 172800},
|
||
{"name": "design_review", "title": "设计评审", "category": "design",
|
||
"description": "架构负责人审批设计方案", "is_interactive": True,
|
||
"interaction_type": "approval_gate", "default_role": "architect_lead", "timeout_seconds": 172800},
|
||
|
||
# Phase 3: Development
|
||
{"name": "code_generate", "title": "代码生成", "category": "development",
|
||
"description": "LLM自动生成完整模块骨架", "is_interactive": False, "timeout_seconds": 600},
|
||
{"name": "code_compliance_check", "title": "规范检查", "category": "development",
|
||
"description": "逐项检查代码是否符合模块开发规范", "is_interactive": False, "timeout_seconds": 300},
|
||
{"name": "code_auto_fix", "title": "自动修复", "category": "development",
|
||
"description": "自动修复可修复的规范违规项", "is_interactive": False, "timeout_seconds": 300},
|
||
{"name": "code_review", "title": "代码审查", "category": "development",
|
||
"description": "高级开发审查代码和检查报告", "is_interactive": True,
|
||
"interaction_type": "approval_gate", "default_role": "senior_developer", "timeout_seconds": 259200},
|
||
{"name": "code_fix", "title": "代码修复", "category": "development",
|
||
"description": "开发者根据审查意见修改代码", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "developer", "timeout_seconds": 172800},
|
||
|
||
# Phase 4: Testing
|
||
{"name": "test_plan_create", "title": "测试方案", "category": "testing",
|
||
"description": "人工编写测试方案(功能/性能/安全)", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "tester", "timeout_seconds": 172800},
|
||
{"name": "test_case_generate", "title": "用例生成", "category": "testing",
|
||
"description": "LLM根据需求和设计自动生成测试用例", "is_interactive": False, "timeout_seconds": 600},
|
||
{"name": "functional_test", "title": "功能测试", "category": "testing",
|
||
"description": "自动执行功能和API测试用例", "is_interactive": False, "timeout_seconds": 1800},
|
||
{"name": "performance_test", "title": "性能测试", "category": "testing",
|
||
"description": "自动执行性能测试(并发/响应/吞吐)", "is_interactive": False, "timeout_seconds": 3600},
|
||
{"name": "bug_report", "title": "Bug报告", "category": "testing",
|
||
"description": "自动收集测试结果生成Bug报告", "is_interactive": False, "timeout_seconds": 300},
|
||
{"name": "bug_fix", "title": "Bug修复", "category": "testing",
|
||
"description": "人工修复Bug", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "developer", "timeout_seconds": 172800},
|
||
{"name": "bug_verify", "title": "Bug验证", "category": "testing",
|
||
"description": "自动回归测试验证Bug修复", "is_interactive": False, "timeout_seconds": 1800},
|
||
{"name": "acceptance_test", "title": "验收测试", "category": "testing",
|
||
"description": "产品经理人工验收", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "product_manager", "timeout_seconds": 259200},
|
||
|
||
# Phase 5: Deployment
|
||
{"name": "deploy_env_collect", "title": "环境配置", "category": "deployment",
|
||
"description": "人工提供部署环境信息(SSH免密/sudo/数据库)", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "devops", "timeout_seconds": 604800},
|
||
{"name": "deploy_test", "title": "测试部署", "category": "deployment",
|
||
"description": "自动部署到测试环境", "is_interactive": False, "timeout_seconds": 600},
|
||
{"name": "deploy_test_verify", "title": "测试验证", "category": "deployment",
|
||
"description": "自动验证测试环境部署", "is_interactive": False, "timeout_seconds": 300},
|
||
{"name": "deploy_test_approve", "title": "部署审批", "category": "deployment",
|
||
"description": "确认测试环境OK,批准生产部署", "is_interactive": True,
|
||
"interaction_type": "approval_gate", "default_role": "release_manager", "timeout_seconds": 259200},
|
||
{"name": "deploy_production", "title": "生产部署", "category": "deployment",
|
||
"description": "自动部署到生产环境", "is_interactive": False, "timeout_seconds": 600},
|
||
{"name": "deploy_production_verify", "title": "生产验证", "category": "deployment",
|
||
"description": "自动验证生产环境部署", "is_interactive": False, "timeout_seconds": 300},
|
||
|
||
# Phase 6: Operations
|
||
{"name": "monitor", "title": "运行监控", "category": "operations",
|
||
"description": "定期健康检查+异常告警", "is_interactive": False, "timeout_seconds": 120},
|
||
{"name": "incident_response", "title": "故障处理", "category": "operations",
|
||
"description": "人工处理故障", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "devops", "timeout_seconds": 86400},
|
||
|
||
# Phase 7: Upgrade
|
||
{"name": "upgrade_plan", "title": "升级规划", "category": "upgrade",
|
||
"description": "规划新版本迭代", "is_interactive": True,
|
||
"interaction_type": "human_task", "default_role": "product_manager", "timeout_seconds": 604800},
|
||
]
|
||
|
||
for st in step_types:
|
||
register_step_type(st)
|
||
|
||
# --- Register handlers (only auto steps have handlers) ---
|
||
handlers = {
|
||
"table_design": handle_table_design,
|
||
"crud_design": handle_crud_design,
|
||
"api_design": handle_api_design,
|
||
"code_generate": handle_code_generate,
|
||
"code_compliance_check": handle_code_compliance_check,
|
||
"code_auto_fix": handle_code_auto_fix,
|
||
"test_case_generate": handle_test_case_generate,
|
||
"functional_test": handle_functional_test,
|
||
"performance_test": handle_performance_test,
|
||
"bug_report": handle_bug_report,
|
||
"bug_verify": handle_bug_verify,
|
||
"deploy_test": handle_deploy_test,
|
||
"deploy_test_verify": handle_deploy_test_verify,
|
||
"deploy_production": handle_deploy_production,
|
||
"deploy_production_verify": handle_deploy_production_verify,
|
||
"monitor": handle_monitor,
|
||
}
|
||
|
||
for step_name, handler_func in handlers.items():
|
||
register_handler(step_name, handler_func)
|
||
|
||
logger.info(f"SDLC adapter loaded: {len(step_types)} step types, {len(handlers)} handlers registered")
|
||
return True
|