From b33b29876610eb9c5fe48297d7c2ab84a7a57582 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 28 Aug 2026 02:31:45 +0800 Subject: [PATCH] test(workflow): cover execution port registry --- docs/architecture-optimization-checklist.md | 2 +- .../architecture/coverage-baseline.json | 6 ++-- tests/test_workflow_mutation_command.py | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/architecture-optimization-checklist.md b/docs/architecture-optimization-checklist.md index f87161c3a..d0fac3032 100644 --- a/docs/architecture-optimization-checklist.md +++ b/docs/architecture-optimization-checklist.md @@ -79,7 +79,7 @@ MoviePilot V3 已经形成较清晰的模块化单体:`foundation`、`domain` | 长方法 | 281 个超过 80 行 | 67 个超过 150 行,23 个超过 250 行;大量是私有方法 | | 全量 mypy 历史债务 | 11,809 / 596 文件 | strict frontier 当前覆盖 41 个文件,本批迁移路径的类型债务已清零 | | Ruff 历史诊断 | 879 | 低水位门禁通过,但规则集只覆盖 `E4/E7/E9/F/I` | -| 覆盖率低水位 | Application 78.78%,Domain 79.29% | Chain、Runtime、Agent、Adapter、Startup 未进入包级覆盖率门禁 | +| 覆盖率低水位 | Application 78.79%,Domain 79.29% | Chain、Runtime、Agent、Adapter、Startup 未进入包级覆盖率门禁 | ### 3.3 热点文件 diff --git a/tests/fixtures/architecture/coverage-baseline.json b/tests/fixtures/architecture/coverage-baseline.json index f1773ce4a..23b52112d 100644 --- a/tests/fixtures/architecture/coverage-baseline.json +++ b/tests/fixtures/architecture/coverage-baseline.json @@ -1,8 +1,8 @@ { "application": { - "covered_lines": 9988, - "percent": 78.78, - "statements": 12678 + "covered_lines": 10001, + "percent": 78.79, + "statements": 12694 }, "domain": { "covered_lines": 3392, diff --git a/tests/test_workflow_mutation_command.py b/tests/test_workflow_mutation_command.py index aa09d2dac..2d97cfa41 100644 --- a/tests/test_workflow_mutation_command.py +++ b/tests/test_workflow_mutation_command.py @@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, Mock import pytest +import app.application.workflow as workflow_application from app.application.workflow import ( WorkflowDefinitionCommand, WorkflowExecutionCommand, @@ -87,6 +88,23 @@ def _execution_command(commit_error=None): ), repository, unit_of_work +def test_workflow_execution_port_requires_explicit_configuration(monkeypatch): + """执行状态端口必须显式装配,并原样返回组合根登记的服务。""" + monkeypatch.setattr( + workflow_application, + "_configured_workflow_execution", + None, + ) + + with pytest.raises(RuntimeError, match="工作流执行状态事务服务尚未配置"): + workflow_application.get_configured_workflow_execution() + + service = Mock() + workflow_application.configure_workflow_execution(service) + + assert workflow_application.get_configured_workflow_execution() is service + + def test_execution_step_is_staged_before_unit_of_work_commit(): """工作流进度写入必须由应用命令暂存后统一提交。""" command, repository, unit_of_work = _execution_command() @@ -151,6 +169,18 @@ def test_start_timer_workflow_commits_before_registering_job(): dependencies["repository"].stage_state.assert_called_once_with(7, "W") +def test_start_rejects_missing_workflow_without_transaction(): + """工作流不存在时不得暂存状态或触发事务。""" + command, dependencies = _command() + + result = command.start(7) + + assert result.success is False + assert result.message == "工作流不存在" + dependencies["repository"].stage_state.assert_not_called() + dependencies["unit_of_work"].commit.assert_not_called() + + def test_start_rejects_invalid_trigger_without_transaction(): """未知触发类型不得更新数据库或注册运行时触发器。""" command, dependencies = _command(_workflow(trigger_type="unknown"))