From b90a9bbfab15c7ef3ee3375ea8bb80366f58110e 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: Mon, 2 Nov 2026 18:52:04 +0800 Subject: [PATCH] fix: allow explicit native repair owner process queries --- .../2026-11-02-issue-2-startup-recovery.md | 9 ++++ src/cbb_refresh_verify/mentor_adapter.py | 2 + tests/test_native_repair.py | 43 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/docs/releases/2026-11-02-issue-2-startup-recovery.md b/docs/releases/2026-11-02-issue-2-startup-recovery.md index 67b5ffd..65f13f6 100644 --- a/docs/releases/2026-11-02-issue-2-startup-recovery.md +++ b/docs/releases/2026-11-02-issue-2-startup-recovery.md @@ -155,3 +155,12 @@ Task 1 review fix round: 259 related tests passed (17.86s); compileall and `git diff --check` passed. These checks include busy retention, real readback failure branches, 30 malformed-success variants at both release and reopen/ counting boundaries, and a complete actual worker-result replay control. + +Runtime fix round 2 adds `iCDBProjectBackup.exe` and `ReuseBlockImporter.exe` to +the process helper's fixed query whitelist. Without these entries, the real +parent release probe rejected its own required queries and always denied safe +release. New tests keep the release validator and process helper real and stub +only WMI: no owners permits release, either native owner prevents it, and +arbitrary query names remain rejected. Focused validation: 172 passed. Candidate +`c823a4b` must be rebuilt with this correction before frozen/native validation; +field recovery remains unverified. diff --git a/src/cbb_refresh_verify/mentor_adapter.py b/src/cbb_refresh_verify/mentor_adapter.py index b877b7e..21fe87a 100644 --- a/src/cbb_refresh_verify/mentor_adapter.py +++ b/src/cbb_refresh_verify/mentor_adapter.py @@ -220,6 +220,8 @@ def _process_details(name): queries = { 'ExpeditionPCB.exe': "SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine FROM Win32_Process WHERE Name='ExpeditionPCB.exe'", 'LibraryManager.exe': "SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine FROM Win32_Process WHERE Name='LibraryManager.exe'", + 'iCDBProjectBackup.exe': "SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine FROM Win32_Process WHERE Name='iCDBProjectBackup.exe'", + 'ReuseBlockImporter.exe': "SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine FROM Win32_Process WHERE Name='ReuseBlockImporter.exe'", 'cscript.exe': "SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine FROM Win32_Process WHERE Name='cscript.exe'", 'viewdraw.exe': "SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine FROM Win32_Process WHERE Name='viewdraw.exe'", } diff --git a/tests/test_native_repair.py b/tests/test_native_repair.py index 5485477..af34a42 100644 --- a/tests/test_native_repair.py +++ b/tests/test_native_repair.py @@ -811,3 +811,46 @@ def test_malformed_native_success_never_reopens_or_counts_repaired(tmp_path, mon assert result.recovery_attempts[0]['status'] == 'UNCONFIRMED' assert result.recovery_attempts[0]['release']['safe_to_continue'] is False assert maintenance_counts([result])['repaired'] == 0 + + +@pytest.mark.parametrize('owner', [None, 'iCDBProjectBackup.exe', 'ReuseBlockImporter.exe']) +def test_repair_release_uses_real_process_query_contract(tmp_path, monkeypatch, owner): + from types import SimpleNamespace + import win32com.client + from cbb_refresh_verify.native_repair import repair_release_state + request, diagnosis, target = target_fixture(tmp_path) + queried = [] + names = ('ExpeditionPCB.exe', 'LibraryManager.exe', 'iCDBProjectBackup.exe', + 'ReuseBlockImporter.exe', 'cscript.exe') + queries = {"SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine " + f"FROM Win32_Process WHERE Name='{name}'": name for name in names} + def query(wql): + name = queries[wql] + queried.append(name) + return ([SimpleNamespace(ProcessId='456', ParentProcessId='1', + ExecutablePath=f'C:\\Mentor\\{name}', CommandLine=f'{name} target')] + if name == owner else []) + def service(moniker): + assert moniker == 'winmgmts:' + return SimpleNamespace(ExecQuery=query) + monkeypatch.setattr(win32com.client, 'GetObject', service) + # Keep pcb_processes, _processes, _process_details and release validation real. + state = repair_release_state(request, target, complete_native_success(target)) + assert 'error' not in state + assert queried == list(names) + assert state['safe_to_continue'] is (owner is None) + assert state['remaining_pids'] == ([] if owner is None else [456]) + assert state['database_exclusive'] is (owner is None) + + +@pytest.mark.parametrize('name', [ + 'other.exe', 'icdbprojectbackup.exe', + "iCDBProjectBackup.exe' OR Name='other.exe", + "ReuseBlockImporter.exe' OR Name='other.exe", +]) +def test_repair_process_queries_still_reject_arbitrary_input(monkeypatch, name): + import win32com.client + from cbb_refresh_verify.mentor_adapter import _process_details + monkeypatch.setattr(win32com.client, 'GetObject', lambda *a: pytest.fail('Unsupported name reached WMI')) + with pytest.raises(ValueError, match='Unsupported process query'): + _process_details(name)