feat: integrate shared native Add worker behind identity gate
This commit is contained in:
1 parent
f8f2dd53aa
commit
07a9c1eaaf
4 files changed
+193
-13
No files matched your search
@@ -51,6 +51,8 @@ class NativeOutcome:
|
||||
success: bool
|
||||
safe_to_continue: bool
|
||||
detail: str
|
||||
identity_matches: bool | None = None
|
||||
evidence_path: Path | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
@@ -39,7 +39,7 @@ def removal_input(name, partition):
|
||||
|
||||
def removal_output_ok(code, output, name, partition):
|
||||
return (code == 0 and '# Warning:' not in output and '# Error:' not in output
|
||||
and re.search(r"# Note: Removed [^\r\n]+ '" + re.escape(name)
|
||||
and re.search(r"# Note: Removed [^\n]+ '" + re.escape(name)
|
||||
+ r"' from partition '" + re.escape(partition) + r"'\.", output) is not None)
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class NativeManagementAdapter:
|
||||
self.mapped_drive = drive or ''
|
||||
self.mapped_remote_root = remote_root or ''
|
||||
|
||||
def capabilities(self):
|
||||
def _binary_capability(self):
|
||||
reason = ''
|
||||
for relative, expected in _BINARY_PROOF.items():
|
||||
path = self.home/relative if self.home else Path(relative)
|
||||
@@ -74,9 +74,22 @@ class NativeManagementAdapter:
|
||||
except OSError as error:
|
||||
reason = f'无法核对原生程序 {path}: {error}'
|
||||
break
|
||||
return reason
|
||||
|
||||
def route_capabilities(self):
|
||||
"""Report the proven native transport separately from production gates."""
|
||||
reason = self._binary_capability()
|
||||
return {
|
||||
'remove': Capability(not reason, reason or 'CleanWGLib/F4 route ready.'),
|
||||
'add': Capability(not reason, reason or 'Library Manager Logical-Physical Add route ready.'),
|
||||
'update': Capability(False, 'Update remains remove plus Add while identity readback is gated.'),
|
||||
}
|
||||
|
||||
def capabilities(self):
|
||||
reason = self._binary_capability()
|
||||
return {
|
||||
'remove': Capability(not reason, reason or '已验证 CleanWGLib/F4;仅 ASCII 名称、Logical-Physical 和 DxDesigner 库。'),
|
||||
'add': Capability(False, '原生新增尚未完成隔离注册及工程内容复读验证;请先运行独立诊断。'),
|
||||
'add': Capability(False, '原生新增已调用并注册,但工程身份复读尚未通过;生产新增保持禁用。'),
|
||||
'update': Capability(False, '同名更新需要原生移除、重新导入及完整端到端隔离验证,目前不可用。'),
|
||||
}
|
||||
|
||||
@@ -161,7 +174,41 @@ class NativeManagementAdapter:
|
||||
raise ValueError('仅验证了 DxDesigner / Logical-Physical 管理操作。')
|
||||
|
||||
def add(self, request, evidence):
|
||||
return NativeOutcome(False, True, self.capabilities()['add'].reason)
|
||||
evidence = Path(evidence)
|
||||
validate_name(request.name)
|
||||
if request.partition != 'Logical-Physical':
|
||||
return NativeOutcome(False, True, 'Only the verified Logical-Physical native Add route is supported.',
|
||||
evidence_path=evidence)
|
||||
source = Path(request.source) if request.source is not None else None
|
||||
if source is None or not source.is_file():
|
||||
return NativeOutcome(False, True, 'Native Add requires an existing staged PRJ source project.',
|
||||
evidence_path=evidence)
|
||||
try:
|
||||
source_identity = engineering_identity(source)
|
||||
except (ValueError, OSError) as error:
|
||||
return NativeOutcome(False, True, f'Unable to read source engineering identity: {error}',
|
||||
evidence_path=evidence)
|
||||
route = self.route_capabilities()['add']
|
||||
if not route.supported:
|
||||
return NativeOutcome(False, True, route.reason, evidence_path=evidence)
|
||||
result = self._worker({
|
||||
'operation': 'add',
|
||||
'library': str(absolute_preserving_drive(request.library)),
|
||||
'source': str(source),
|
||||
'name': request.name,
|
||||
'partition': request.partition,
|
||||
'top_level_block': request.top_level_block,
|
||||
'mapped_drive': request.mapped_drive or self.mapped_drive,
|
||||
'mapped_remote_root': request.mapped_remote_root or self.mapped_remote_root,
|
||||
'timeout_seconds': request.timeout_seconds,
|
||||
'source_identity': source_identity,
|
||||
}, evidence)
|
||||
identity_matches = result.get('identity_matches')
|
||||
detail = result.get('detail', '')
|
||||
if result.get('success') and identity_matches is False and not detail:
|
||||
detail = 'Native Add registered the block, but engineering identity readback differs from the staged source.'
|
||||
return NativeOutcome(bool(result.get('success')), bool(result.get('safe_to_continue')),
|
||||
detail, identity_matches=identity_matches, evidence_path=evidence)
|
||||
|
||||
|
||||
def prepare_probe_library(job, root):
|
||||
@@ -292,11 +339,7 @@ def _probe_add_dialog(app, job, desktop, owned_pids, root, *, library=None):
|
||||
|
||||
|
||||
def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None):
|
||||
"""Diagnostic only: proven editor/UIA tab and resource1103 controls.
|
||||
|
||||
This function has no production capability override. It is called only
|
||||
after this worker itself creates a new disposable library.
|
||||
"""
|
||||
"""Submit the proven Logical-Physical Add dialog on an owned library."""
|
||||
import pythoncom, win32con, win32gui, win32process
|
||||
_dispatch_diagnostics(root, 'before-pywinauto-import', app, library)
|
||||
from pywinauto import Desktop
|
||||
@@ -345,7 +388,8 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
|
||||
raise RuntimeError('原生 New 按钮不可用。')
|
||||
win32gui.PostMessage(new_button, win32con.BM_CLICK, 0, 0)
|
||||
dialog = await_window('New Reusable Block')
|
||||
fields = {1217: str(source), 1215: job['name'], 1218: top, 1216: 'Isolated CBB management validation'}
|
||||
fields = {1217: str(source), 1215: job['name'], 1218: top,
|
||||
1216: job.get('description', 'CBB native management validation')}
|
||||
for control, value in fields.items():
|
||||
hwnd = win32gui.GetDlgItem(dialog, control)
|
||||
if not hwnd or win32gui.GetClassName(hwnd) != 'Edit':
|
||||
@@ -538,7 +582,7 @@ def _wait_native_exit(pids, timeout=10):
|
||||
def _catalog_native(job, root):
|
||||
import gc, pythoncom
|
||||
from .com_runtime import initialize_com, uninitialize_com
|
||||
if job.get('operation') in ('probe_create_add', 'probe_readd'):
|
||||
if job.get('operation') in ('add', 'probe_create_add', 'probe_readd'):
|
||||
# The installed UIA import disconnects existing Mentor proxies
|
||||
# (CO_E_OBJNOTCONNECTED). Finish its initialization before creating any.
|
||||
from pywinauto import Desktop
|
||||
@@ -614,8 +658,16 @@ def _catalog_com(job, root):
|
||||
raise RuntimeError('目录读取需要升级中心库或选择流程;已拒绝,目标未获准自动升级。')
|
||||
if library is None or Path(str(library.FullName)).resolve() != Path(job['library']).resolve():
|
||||
raise RuntimeError('原生返回中心库身份不一致。')
|
||||
if job['operation'] in ('probe_create_add', 'probe_readd'):
|
||||
if int(library.FlowType) != 1:
|
||||
raise RuntimeError('Native Add requires the DxDesigner Logical-Physical library flow.')
|
||||
if job['operation'] in ('add', 'probe_create_add', 'probe_readd'):
|
||||
_probe_add_dialog(app, job, desktop, owned_pids, root, library=library)
|
||||
library.Close()
|
||||
library = None
|
||||
library = app.OpenLibrary(str(absolute_preserving_drive(job['library'])))
|
||||
if (library is None or Path(str(library.FullName)).resolve() != Path(job['library']).resolve()
|
||||
or int(library.FlowType) != 1):
|
||||
raise RuntimeError('Native Add reopen did not confirm the exact library and flow.')
|
||||
entries = []
|
||||
parts = library.Partitions(7)
|
||||
for i in range(1, int(parts.Count) + 1):
|
||||
@@ -637,6 +689,17 @@ def _catalog_com(job, root):
|
||||
partition = None
|
||||
parts = None
|
||||
result.update(success=True, library=str(library.FullName), flow=int(library.FlowType), entries=entries)
|
||||
if job['operation'] == 'add':
|
||||
matches = [entry for entry in entries
|
||||
if entry['name'] == job['name'] and entry['partition'] == job['partition']]
|
||||
identity_matches = (len(matches) == 1
|
||||
and matches[0]['engineering_identity'] == job.get('source_identity'))
|
||||
result['identity_matches'] = identity_matches
|
||||
if len(matches) != 1:
|
||||
result.update(success=False, detail='Native Add reopen did not confirm the exact name and partition.')
|
||||
elif not identity_matches:
|
||||
result['detail'] = ('Native Add registered the block, but engineering identity readback '
|
||||
'differs from the staged source.')
|
||||
except Exception as error:
|
||||
result['detail'] = str(error)
|
||||
result['exception'] = _exception_details(error)
|
||||
@@ -675,7 +738,16 @@ def management_worker_main(request_path):
|
||||
if job.get('mapped_drive') and job.get('mapped_remote_root'):
|
||||
from .network_path import ensure_mapped_drive_visible
|
||||
ensure_mapped_drive_visible(job['mapped_drive'], job['mapped_remote_root'])
|
||||
if job['operation'] in ('catalog', 'probe_create_add', 'probe_readd'):
|
||||
if job['operation'] in ('catalog', 'add', 'probe_create_add', 'probe_readd'):
|
||||
if job['operation'] == 'add':
|
||||
route = NativeManagementAdapter(mentor_home=job['mentor_home']).route_capabilities()['add']
|
||||
if not route.supported:
|
||||
raise RuntimeError(route.reason)
|
||||
validate_name(job['name'])
|
||||
if job.get('partition') != 'Logical-Physical':
|
||||
raise ValueError('Native Add requires Logical-Physical.')
|
||||
if engineering_identity(job['source']) != job.get('source_identity'):
|
||||
raise ValueError('Staged source engineering identity changed before native Add.')
|
||||
result = _catalog_native(job, root)
|
||||
elif job['operation'] == 'remove':
|
||||
adapter = NativeManagementAdapter(mentor_home=job['mentor_home'])
|
||||
|
||||
Reference in new issue
Block a user