From 960c66b196812e9de1d2251f15b32babed55a6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Fri, 6 Nov 2026 15:16:11 +0800 Subject: [PATCH] fix: keep portable execution identities and core imports consistent --- .gitea/workflows/ci.yml | 1 + .../2026-11-06-pr-software-validation.md | 11 ++++++ .../trial_task_center/quick_run.py | 3 +- .../trial_task_center/ui/__init__.py | 10 ++++-- tests/v1_1/test_headless_core.py | 34 +++++++++++++++++++ tests/v1_1/test_nonblocking_bom_values.py | 3 ++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/v1_1/test_headless_core.py diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 2693cc7..777367f 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -47,6 +47,7 @@ jobs: tests/v1_1/test_component_scope.py tests/v1_1/test_deferred_problem_pass.py tests/v1_1/test_problem_workflow.py + tests/v1_1/test_headless_core.py tests/v1_1/test_nonblocking_acceptance.py tests/v1_1/test_nonblocking_resume.py tests/v1_1/test_project_session_health.py diff --git a/docs/testing/2026-11-06-pr-software-validation.md b/docs/testing/2026-11-06-pr-software-validation.md index 91e3104..f906d16 100644 --- a/docs/testing/2026-11-06-pr-software-validation.md +++ b/docs/testing/2026-11-06-pr-software-validation.md @@ -33,3 +33,14 @@ python -m pytest tests/v1_1/test_problem_workflow.py tests/v1_1/test_problem_ite 将新的定向重试和旧问题预留恢复用例 `test_problem_workflow.py` 加入现有便携 CI。远端结果以 PR 上的 commit status 为准。 本轮验证的是源码应用与真实 Windows 监督进程,未构建新发布 EXE,未模拟实际系统重启,也未执行真实 CAD 替换或线上 AI/工单请求。工程结果待核验时仍禁止直接重放;启动身份不足的残留记录继续受保护。 + +## 远端 CI 发现项修复 + +首次远端 Python 回归暴露项目键在 Linux 保留大小写、与库存及命令身份的 casefold 规则不一致,以及纯核心读取模块经 UI 包提前导入 Qt 的问题。另有一个 Qt 对话框用例混在无 Qt 的便携测试组中。 + +- `_path_key` 统一采用已有的大小写不敏感项目身份规则,未修改实际工程路径。 +- UI 包延迟导出主窗口,纯 execution_state/messages 导入不再要求 Qt;窗口的既有导出保持兼容。 +- 对话框用例在有 PySide6/pytest-qt 的 Windows 环境仍执行,无依赖的便携环境明确跳过。 +- 新增 `test_headless_core.py`,先复现项目键不一致和无 Qt 导入失败,再验证修复。 +- 修复后的 Windows 定向回归:`test_headless_core.py`、`test_problem_workflow.py`、`tests/dsh/test_run_journal.py`、BOM 部分导入对话框用例和 `test_application.py` 共 **37 passed**,包含真实源码入口启动验证。 +- 独立审查未发现新的必要修复或保护放宽;远端最终结果见 PR 的最新提交状态。 diff --git a/src/dx_productivity/trial_task_center/quick_run.py b/src/dx_productivity/trial_task_center/quick_run.py index 85ed2be..e6681cb 100644 --- a/src/dx_productivity/trial_task_center/quick_run.py +++ b/src/dx_productivity/trial_task_center/quick_run.py @@ -1935,7 +1935,8 @@ def _write_atomic_queue_text(path: Path, text: str, code: str, message: str) -> def _path_key(path: str | Path) -> str: - return os.path.normcase(os.path.abspath(str(path))) + # CAD project identities remain case-insensitive on portable test hosts too. + return os.path.normcase(os.path.abspath(str(path))).casefold() def _selected_projects(projects: tuple[ProjectRecord, ...]) -> tuple[ProjectRecord, ...]: diff --git a/src/dx_productivity/trial_task_center/ui/__init__.py b/src/dx_productivity/trial_task_center/ui/__init__.py index 0ceeddd..7260720 100644 --- a/src/dx_productivity/trial_task_center/ui/__init__.py +++ b/src/dx_productivity/trial_task_center/ui/__init__.py @@ -1,5 +1,11 @@ """PySide6 task-center presentation layer.""" -from .main_window import TrialTaskCenterWindow - __all__ = ["TrialTaskCenterWindow"] + + +def __getattr__(name): + # Core projections live in this package too; importing them needs no Qt. + if name == 'TrialTaskCenterWindow': + from .main_window import TrialTaskCenterWindow + return TrialTaskCenterWindow + raise AttributeError(name) diff --git a/tests/v1_1/test_headless_core.py b/tests/v1_1/test_headless_core.py new file mode 100644 index 0000000..99af975 --- /dev/null +++ b/tests/v1_1/test_headless_core.py @@ -0,0 +1,34 @@ +"""Portable core reads must not depend on a Qt installation or host casing.""" +import os +from pathlib import Path +import subprocess +import sys +from types import SimpleNamespace + + +def test_windows_project_keys_remain_case_insensitive_on_portable_host(tmp_path, monkeypatch): + from dx_productivity.trial_task_center import quick_run + monkeypatch.setattr(quick_run.os.path, 'normcase', lambda path: path) + project = tmp_path / 'Board-A' / 'BOARD.prj' + target = SimpleNamespace(project_path=Path(str(project).casefold()), schematic_name='MAIN', sheet_number='1') + rule = SimpleNamespace(scope='targets', targets=(target,)) + quick_run._validate_target_scope((SimpleNamespace(path=project),), (rule,), + {quick_run._path_key(project): (('MAIN', '1'),)}) + + +def test_core_ui_projections_can_import_without_qt(): + source = Path(__file__).resolve().parents[2] / 'src' + script = '''import importlib.abc,sys +class NoQt(importlib.abc.MetaPathFinder): + def find_spec(self, fullname, path=None, target=None): + if fullname.split('.')[0] in {'PySide6', 'shiboken6'}: + raise ImportError('Qt must not be loaded by a pure core projection') +sys.meta_path.insert(0, NoQt()) +from dx_productivity.trial_task_center.ui.execution_state import execution_state +from dx_productivity.trial_task_center.ui.messages import replacement_result_rows +assert execution_state(None).editable is False +assert not any(name.startswith(('PySide6', 'shiboken6')) for name in sys.modules) +''' + result = subprocess.run([sys.executable, '-c', script], capture_output=True, text=True, + env=os.environ | {'PYTHONPATH': str(source)}, timeout=15) + assert result.returncode == 0, result.stderr diff --git a/tests/v1_1/test_nonblocking_bom_values.py b/tests/v1_1/test_nonblocking_bom_values.py index 0bd6d76..6ba481c 100644 --- a/tests/v1_1/test_nonblocking_bom_values.py +++ b/tests/v1_1/test_nonblocking_bom_values.py @@ -1,4 +1,5 @@ from dataclasses import replace +from importlib.util import find_spec from types import SimpleNamespace import pytest @@ -81,6 +82,8 @@ def test_partial_selection_rejects_changed_source_and_edited_rows(batch, tmp_pat assert all(not store.list_target_plan(task.task_id) for task in tasks) +@pytest.mark.skipif(find_spec('PySide6') is None or find_spec('pytestqt') is None, + reason='Qt dialog acceptance runs on the Windows UI host') def test_partial_ui_stages_only_user_selected_passed_projects(batch, tmp_path, qtbot): from dx_productivity.trial_task_center.bom_import_report import inspect_batch from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow