Skip to content

Commit 795191c

Browse files
committed
修复小程序蓝本执行器StepResult/TestReport字段名匹配Pydantic模型
1 parent 8bb16b0 commit 795191c

1 file changed

Lines changed: 35 additions & 20 deletions

File tree

src/api/routes.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,15 @@ async def run_miniprogram_blueprint_test(req: dict) -> TestReportResponse:
553553
controller = MiniProgramController(config)
554554

555555
# 简化执行:记录步骤结果
556-
from src.testing.models import StepResult, TestReport, BugReport
556+
from src.testing.models import StepResult, TestReport, BugReport, ActionType, StepStatus, BugSeverity
557557
import time
558558

559+
def _to_action_type(action_str: str) -> ActionType:
560+
try:
561+
return ActionType(action_str)
562+
except ValueError:
563+
return ActionType.SCREENSHOT
564+
559565
start = time.time()
560566
steps_results = []
561567
bugs = []
@@ -582,50 +588,59 @@ async def run_miniprogram_blueprint_test(req: dict) -> TestReportResponse:
582588
raise AssertionError(f"预期文本未找到: {step.expected}")
583589

584590
steps_results.append(StepResult(
585-
step_number=len(steps_results) + 1,
586-
action=action,
587-
status="passed",
588-
duration=time.time() - step_start,
591+
step=len(steps_results) + 1,
592+
action=_to_action_type(action),
593+
status=StepStatus.PASSED,
594+
description=step.description or action,
595+
duration_seconds=time.time() - step_start,
589596
))
590597
except Exception as e:
591598
steps_results.append(StepResult(
592-
step_number=len(steps_results) + 1,
593-
action=step.action,
594-
status="failed",
595-
error=str(e),
596-
duration=time.time() - step_start,
599+
step=len(steps_results) + 1,
600+
action=_to_action_type(step.action),
601+
status=StepStatus.FAILED,
602+
description=step.description or step.action,
603+
error_message=str(e),
604+
duration_seconds=time.time() - step_start,
597605
))
598606
bugs.append(BugReport(
599-
severity="medium",
607+
severity=BugSeverity.MEDIUM,
600608
title=f"步骤{len(steps_results)}失败: {step.action}",
601609
description=str(e),
602610
))
603611

604612
await controller.close()
605613

606614
total = len(steps_results)
607-
passed = sum(1 for s in steps_results if s.status == "passed")
615+
passed = sum(1 for s in steps_results if s.status == StepStatus.PASSED)
616+
failed = total - passed
608617
duration = time.time() - start
609618

619+
from datetime import datetime, timezone, timedelta
620+
end_time = datetime.now(timezone.utc)
621+
start_time = end_time - timedelta(seconds=duration)
622+
610623
report = TestReport(
611624
test_name=f"小程序蓝本测试-{blueprint.app_name}",
612625
url=base_url,
626+
start_time=start_time,
627+
end_time=end_time,
613628
total_steps=total,
614629
passed_steps=passed,
615-
failed_steps=total - passed,
630+
failed_steps=failed,
631+
step_results=steps_results,
616632
bugs=bugs,
617-
duration_seconds=duration,
618-
steps=steps_results,
619633
)
620634

635+
pass_rate = passed / total * 100 if total > 0 else 0
621636
return TestReportResponse(
622637
test_name=report.test_name,
623638
url=report.url,
624-
total_steps=report.total_steps,
625-
passed_steps=report.passed_steps,
626-
failed_steps=report.failed_steps,
627-
bug_count=len(report.bugs),
628-
pass_rate=report.passed_steps / report.total_steps * 100 if report.total_steps > 0 else 0,
639+
total_steps=total,
640+
passed_steps=passed,
641+
failed_steps=failed,
642+
bug_count=len(bugs),
643+
pass_rate=pass_rate,
629644
duration_seconds=report.duration_seconds,
630645
report_markdown=report.report_markdown,
631646
)

0 commit comments

Comments
 (0)