From 6175bdb2548eaca8e7494e4afc3dbe4e71bd2e56 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: Tue, 17 Nov 2026 17:33:18 +0800 Subject: [PATCH] fix: keep verification run controls and close cancellation consistent --- .../trial_task_center/ui/main_window.py | 12 +++++------ .../ui/verification_workspace.py | 6 ++++-- .../trial_task_center/verification/queries.py | 3 ++- .../trial_task_center/verification/report.py | 19 ++++++++++++++---- tests/ui/test_verification_control.py | 20 +++++++++++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/dx_productivity/trial_task_center/ui/main_window.py b/src/dx_productivity/trial_task_center/ui/main_window.py index aeaf736..e8bc5ae 100644 --- a/src/dx_productivity/trial_task_center/ui/main_window.py +++ b/src/dx_productivity/trial_task_center/ui/main_window.py @@ -358,12 +358,6 @@ class TrialTaskCenterWindow(MaterialMainWindow): if self._close_saving: event.ignore() return - if self.verification_panel.busy: - self._close_pending = True - self.verification_panel.begin_shutdown() - event.ignore() - QTimer.singleShot(100, self.close) - return if self._workers or self.history_panel._worker: self._close_pending = True if self._dsh_automation and getattr(self._dsh_automation, '_owns_execution_lane', False): @@ -415,6 +409,12 @@ class TrialTaskCenterWindow(MaterialMainWindow): self._dsh_view.stopped.connect(lambda: QTimer.singleShot(0, self, self.close)) self._dsh_view.shutdown() return + if self.verification_panel.busy: + self._close_pending = True + self.verification_panel.begin_shutdown() + event.ignore() + QTimer.singleShot(100, self.close) + return self._cancel_dsh_diagnosis() for name, widget in self._layout_widgets().items(): self._layout_settings.setValue(f'single_project/{name}', widget.saveState()) diff --git a/src/dx_productivity/trial_task_center/ui/verification_workspace.py b/src/dx_productivity/trial_task_center/ui/verification_workspace.py index bc213e3..4686811 100644 --- a/src/dx_productivity/trial_task_center/ui/verification_workspace.py +++ b/src/dx_productivity/trial_task_center/ui/verification_workspace.py @@ -67,7 +67,7 @@ class VerificationWorkspace(QWidget): has=bool(self.controller.task_id);item=bool(self.controller.item_id) self.import_button.setEnabled(has);self.start_button.setEnabled(has);self.selected_button.setEnabled(has and item) self.rerun_button.setEnabled(item);self.export_button.setEnabled(has) - self.stop_button.setEnabled(bool(self._run_id) or getattr(self.service,'busy',False)) + self.stop_button.setEnabled(bool(self._run_id)) self.busy_changed.emit() def set_active(self,active): @@ -111,6 +111,7 @@ class VerificationWorkspace(QWidget): query=self.search.text(),cursor=cursor,read_control=control),lambda result:self._task_received(result,append),self._error,cancellable=True) def _task_received(self,result,append): + self._run_id=(result.get('run') or {}).get('run_id') if not append and result['view_revision']==self._last_revision and len(self._rows)>100: self._gates();return self._last_revision=result['view_revision'] @@ -171,7 +172,8 @@ class VerificationWorkspace(QWidget): def _started(self,result):self._run_id=result['run_id'];self.refresh() def _stop(self): - if self._run_id:self.controller.command(lambda:self.service.stop(self._run_id,request_id=uuid4().hex),lambda _:self.refresh()) + run_id=self._run_id + if run_id:self.controller.command(lambda:self.service.stop(run_id,request_id=uuid4().hex),lambda _:self.refresh()) def _rerun(self): item=self.controller.item_id diff --git a/src/dx_productivity/trial_task_center/verification/queries.py b/src/dx_productivity/trial_task_center/verification/queries.py index cce32ed..57d6fbe 100644 --- a/src/dx_productivity/trial_task_center/verification/queries.py +++ b/src/dx_productivity/trial_task_center/verification/queries.py @@ -93,6 +93,7 @@ class VerificationQueries: def read_task(self,task_id,*,state='',query='',cursor=None,limit=100,read_control=None): with self.repo.store.transaction(): task=self.repo.task(task_id);rows=self._rows(task_id,read_control) + run=self.repo.connection.execute("SELECT run_id,state,stop_requested FROM verification_runs WHERE task_id=? AND state IN ('queued','running','stopping') ORDER BY created LIMIT 1",(task_id,)).fetchone() self.validate_rows(rows,read_control) filtered=[] for row in rows: @@ -103,7 +104,7 @@ class VerificationQueries: if query.casefold() in text.casefold():filtered.append(row) binding=digest([task_id,task['view_revision'],state,query]) page,next_cursor=paginate(filtered,cursor,limit,binding,100) - return dict(task,items=page,cursor=next_cursor,summary=summarize_items(rows)) + return dict(task,items=page,cursor=next_cursor,summary=summarize_items(rows),run=dict(run) if run else None) def read_item(self,item_id,*,version=None,attempt_id=None,read_control=None): row=self.snapshot_item(item_id,version=version,attempt_id=attempt_id,read_control=read_control) diff --git a/src/dx_productivity/trial_task_center/verification/report.py b/src/dx_productivity/trial_task_center/verification/report.py index 0c23aac..3a530a0 100644 --- a/src/dx_productivity/trial_task_center/verification/report.py +++ b/src/dx_productivity/trial_task_center/verification/report.py @@ -47,7 +47,9 @@ def diagram(pins): def item_html(result): validate_result(result) evidence=result.get('evidence') or {};pins=evidence.get('pins',[]) - out=[f'

{text(result.get("display_name","工程校验"))}

',f'

{text(result.get("verdict","未完成"))}

', + verdict=result.get('verdict','未完成') + label={'CONSISTENT':'一致','WARNING':'需关注','DIFFERENT':'异常','INCOMPLETE':'无法完整校验'}.get(verdict,'未完成') + out=[f'

{text(result.get("display_name","工程校验"))}

',f'

{label} · {text(verdict)}

', f'

{text(result.get("scope","未核对换料规则"))} · 由网表生成 · 未覆盖:封装库内部映射、引脚级 Value

'] keys=sorted({tuple(p['endpoint'][:2]) for p in pins}) for key in keys: @@ -55,10 +57,19 @@ def item_html(result): out.append(f'

{text(key[1])} · {text(key[0])}

');out.append(diagram(subset)) out.append('') for pin in subset: - out.append(f'') + def description(row): + if row is None:return '不存在/未覆盖' + nets=';'.join(n['name']+' → '+', '.join(e[1]+'.'+e[2] for e in n['endpoints'] if e!=pin['endpoint']) for n in row['nets']) + return '名称:'+row['logical_name']+'\n'+(nets or '明确未连接') + out.append(f'') out.append('
物理脚修改前修改后事实
{text(pin["endpoint"][2])}
{text(pin["before"])}
{text(pin["after"])}
{"连接变化" if pin["connection_changed"] else "文字变化" if pin["text_changed"] else "未发现变化"}
{text(pin["endpoint"][2])}
{text(description(pin["before"]))}
{text(description(pin["after"]))}
{"连接变化" if pin["connection_changed"] else "文字变化" if pin["text_changed"] else "未发现变化"}
') - out.append('

判断依据与范围

'+text({key:result.get(key) for key in ('attempt_state','reason','resource_state','checks','issues','uncovered','attempt_id','input_version','input_digest','policy')})+'
') - out.append('

原始证据定位与摘要

'+text(evidence.get('binding',{}))+'
') + out.append('

判断依据

') + if result.get('reason'):out.append('

执行说明:'+text(result['reason'])+'

') + out.append('
检查范围、版本与完整事实
'+text({key:result.get(key) for key in ('attempt_state','resource_state','checks','issues','uncovered','attempt_id','input_version','input_digest','policy')})+'
') + out.append('
原始证据定位与摘要
'+text(evidence.get('binding',{}))+'
') return ''.join(out) diff --git a/tests/ui/test_verification_control.py b/tests/ui/test_verification_control.py index 1d1f8b4..43df32f 100644 --- a/tests/ui/test_verification_control.py +++ b/tests/ui/test_verification_control.py @@ -16,3 +16,23 @@ def test_shutdown_is_idempotent_after_store_is_released(ui,qtbot): page.service.begin_shutdown=forbidden try:page.shutdown() finally:page.service.begin_shutdown=original + + +def test_finished_run_does_not_leave_stop_enabled(ui,qtbot): + page=ui.window.verification_panel + task=page.service.create_task('空任务',request_id='finished')['task_id'] + page.open_task(task) + page._started({'run_id':'already-finished'}) + qtbot.waitUntil(lambda:not page.controller.task_query.busy) + assert not page.stop_button.isEnabled() + + +def test_cancelling_window_close_does_not_close_verification_admission(ui,monkeypatch): + from dx_productivity.trial_task_center.ui.verification_workspace import VerificationWorkspace + ui.settle();window=ui.window + with monkeypatch.context() as patch: + patch.setattr(VerificationWorkspace,'busy',property(lambda self:True)) + patch.setattr(window.plan_panel,'has_unsaved_plans',lambda:True) + window._close_plan_confirmer=lambda:'cancel' + assert not window.close() + assert not window.verification_panel.service.control.closing