From ec677a2864891800ad6f815b53bf0d156fb9f92d 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 16:03:02 +0800 Subject: [PATCH] feat: export verification evidence and preserve result history --- docs/user/independent-verification.md | 13 ++ .../trial_task_center/ui/operation_history.py | 1 + .../ui/verification_inspector.py | 3 + .../trial_task_center/verification/queries.py | 18 ++- .../trial_task_center/verification/report.py | 114 ++++++++++++++++++ .../trial_task_center/verification/service.py | 25 ++++ .../trial_task_center/verification/store.py | 9 ++ tests/ui/test_verification_report_actions.py | 5 + tests/v1_1/test_verification_reports.py | 49 ++++++++ 9 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 docs/user/independent-verification.md create mode 100644 src/dx_productivity/trial_task_center/verification/report.py create mode 100644 tests/ui/test_verification_report_actions.py create mode 100644 tests/v1_1/test_verification_reports.py diff --git a/docs/user/independent-verification.md b/docs/user/independent-verification.md new file mode 100644 index 0000000..bba4657 --- /dev/null +++ b/docs/user/independent-verification.md @@ -0,0 +1,13 @@ +# 工程校验 + +在第四个“工程校验”页面随时新建任务。选择修改前、修改后两份已保存的 `.prj` 工程添加比较项,不能选择同一文件或共用数据库的两个工程。已有替换任务不影响新建;替换已保存的成功项会自动交接,缺少前后副本的项显示无法校验,不能用当前工程补造历史版本。 + +“开始全部”处理当前任务中当时待校验/中断的工程;筛选不会缩小这个范围。“校验所选”和“重校验”明确处理所选工程当前版本。运行期间后到的新项或新版本留待下次开始。校验只读副本,不会重新换料或自动换脚。 + +一致表示已覆盖的必查项未发现差异;需关注表示有文字或属性变化需要人工判断;异常表示已证明位号、物理脚号、连接或声明目标等不符合;无法校验表示证据不足。没有固定换料清单时始终显示“未核对换料规则”。执行结束不等于工程一致。 + +选择工程,在右侧选择位号查看固定脚号的前后接线图和逐脚事实。红线对应连接变化;纯名称变化以关注提示。图由网表生成,不是原理图截图。原始证据入口会核对摘要;历史版本仅供查看,不改变当前结论。导出报告包含同一份图表、检查范围、输入和尝试摘要,不复制整个工程。 + +停止采用安全收尾。未派发项保留待校验,已开始项保留停止记录。重启不会自动重跑;缺少进程退出证明的项保留现场并暂停新的原生导出,不按 PID 猜测或终止其他进程。 + +首版未证明引脚级 Value 读取和确切库内部引脚→焊盘映射,页面明确未覆盖。电气类型按原生码展示,不臆造语义。本网表比较不宣称完成 ERC、PCB 或封装库内部正确性验证。普通操作历史清空和运行日志保留不会删除校验快照与证据。 diff --git a/src/dx_productivity/trial_task_center/ui/operation_history.py b/src/dx_productivity/trial_task_center/ui/operation_history.py index 21a2e99..4034cc5 100644 --- a/src/dx_productivity/trial_task_center/ui/operation_history.py +++ b/src/dx_productivity/trial_task_center/ui/operation_history.py @@ -18,6 +18,7 @@ STATES={'verified':'已核验完成','no_match':'未命中','failed':'失败','f 'uncertain':'待核验','saved_unverified':'保存待核验','skipped':'已跳过','recorded':'已记录', 'running':'执行中','paused':'已暂停','pending':'待执行','restored':'已恢复'} OPERATIONS={'quick_run_executed':'替换执行','quick_run_prepared':'准备执行', + 'verification_completed':'工程校验', 'quick_run_recovered':'核验恢复','quick_run_queue_paused':'暂停执行', 'quick_run_retry_prepared':'准备失败项重试','create_project_tasks':'创建工程任务', 'create_task':'新建任务','update_task':'编辑任务','delete_task':'归档任务', diff --git a/src/dx_productivity/trial_task_center/ui/verification_inspector.py b/src/dx_productivity/trial_task_center/ui/verification_inspector.py index 0583856..59053b3 100644 --- a/src/dx_productivity/trial_task_center/ui/verification_inspector.py +++ b/src/dx_productivity/trial_task_center/ui/verification_inspector.py @@ -72,6 +72,9 @@ class VerificationInspector(QWidget): self.versions.addItem(f'输入 v{version}',version) self.versions.setCurrentIndex(self.versions.findData(record['input_version']));self.versions.blockSignals(False) result=((record.get('attempt') or {}).get('result') or {}) + if record.get('evidence_error'): + self.set_evidence(None);self.heading.setText(record['display_name']+' · 证据不可用') + self.facts.setPlainText(record['evidence_error']);return self.set_evidence(result.get('evidence')) self.heading.setText(record['display_name']+' · '+{'CONSISTENT':'一致','WARNING':'需关注','DIFFERENT':'异常','INCOMPLETE':'无法完整校验'}.get(result.get('verdict'),'待校验')) self.facts.setPlainText(json.dumps({'范围':result.get('scope',record['scope']),'检查':result.get('checks',[]), diff --git a/src/dx_productivity/trial_task_center/verification/queries.py b/src/dx_productivity/trial_task_center/verification/queries.py index b6929c3..442ad68 100644 --- a/src/dx_productivity/trial_task_center/verification/queries.py +++ b/src/dx_productivity/trial_task_center/verification/queries.py @@ -43,7 +43,14 @@ def paginate(rows,cursor,limit,binding,maximum): class VerificationQueries: - def __init__(self,repo):self.repo=repo + def __init__(self,repo):self.repo=repo;self.validator=None + + def _validate(self,row,attempt): + if self.validator and attempt and attempt['state']=='succeeded': + try:self.validator(attempt) + except (ValueError,OSError,KeyError,TypeError) as error: + row.update(status='unavailable',verdict='INCOMPLETE',evidence_error=str(error)) + return row def _rows(self,task_id,control=None): checkpoint(control) @@ -58,7 +65,12 @@ class VerificationQueries: LEFT JOIN verification_attempts a ON a.attempt_id=(SELECT attempt_id FROM verification_attempts WHERE item_id=i.item_id AND input_version=i.current_version ORDER BY generation DESC LIMIT 1) WHERE i.task_id=? ORDER BY i.rowid''',(task_id,)).fetchall() - return [project(row) for row in rows] + result=[] + for row in rows: + checkpoint(control);row=project(row) + if self.validator and row['attempt_state']=='succeeded':self._validate(row,self.repo.attempt(row['attempt_id'])) + result.append(row) + return result def list_tasks(self,*,query='',cursor=None,limit=50,read_control=None): with self.repo.store.transaction(): @@ -97,7 +109,7 @@ class VerificationQueries: attempt_state=attempt['state'] if attempt else None,reason=attempt['reason'] if attempt else '', verdict=(attempt['result'] or {}).get('verdict') if attempt else None) history=[dict(r) for r in self.repo.connection.execute('SELECT input_version,generation,attempt_id,state FROM verification_attempts WHERE item_id=? ORDER BY input_version DESC,generation DESC',(item_id,))] - return dict(project(row),payload=revision['payload'],attempt=attempt,history=history) + return dict(self._validate(project(row),attempt),payload=revision['payload'],attempt=attempt,history=history) def read_issues(self,attempt_id,*,kind='',cursor=None,limit=100,read_control=None): checkpoint(read_control) diff --git a/src/dx_productivity/trial_task_center/verification/report.py b/src/dx_productivity/trial_task_center/verification/report.py new file mode 100644 index 0000000..7b974fb --- /dev/null +++ b/src/dx_productivity/trial_task_center/verification/report.py @@ -0,0 +1,114 @@ +"""HTML and JSON views of the exact immutable evidence shown in the workspace.""" +from html import escape +import json +import os +from pathlib import Path +from uuid import uuid4 +from ..native_netlist import _hash +from ..batch_resources import write_record +from .contracts import fail,digest +from .evidence import verify_evidence + + +def validate_result(result,root=None): + evidence=result.get('evidence') + if evidence: + verify_evidence(evidence) + for raw in evidence['binding'].get('raw',()): + path=Path(raw['path']).resolve() + if root is not None and not path.is_relative_to(Path(root).resolve()):fail('证据文件不属于本任务库。') + try: + if _hash(path)!=raw['sha256']:fail('原始证据已损坏。','verification_evidence') + except OSError:fail('原始证据已丢失。','verification_evidence') + + +def text(value): + if isinstance(value,(dict,list,tuple)):value=json.dumps(value,ensure_ascii=False,sort_keys=True) + return escape(str(value if value is not None else '未知')) + + +STYLE='body{font:14px "Segoe UI","Microsoft YaHei",sans-serif;color:#34445b;background:#f5f7fa;margin:24px}main{background:white;padding:24px;border-radius:12px}table{border-collapse:collapse;width:100%;margin:16px 0}td,th{border:1px solid #dae2eb;padding:9px;text-align:left;vertical-align:top}pre{white-space:pre-wrap;overflow-wrap:anywhere}.error{color:#b83d4a}.warning{color:#9c6b1e}svg{max-width:100%;height:auto}' + + +def diagram(pins): + height=max(100,70+len(pins)*90);out=[f'' + + +def item_html(result): + validate_result(result) + evidence=result.get('evidence') or {};pins=evidence.get('pins',[]) + out=[f'
{text(result.get("scope","未核对换料规则"))} · 由网表生成 · 未覆盖:封装库内部映射、引脚级 Value
'] + keys=sorted({tuple(p['endpoint'][:2]) for p in pins}) + for key in keys: + subset=[p for p in pins if tuple(p['endpoint'][:2])==key] + out.append(f'| 物理脚 | 修改前 | 修改后 | 事实 |
|---|---|---|---|
| {text(pin["endpoint"][2])} | {text(pin["before"])} | {text(pin["after"])} | {"连接变化" if pin["connection_changed"] else "文字变化" if pin["text_changed"] else "未发现变化"} |
'+text({key:result.get(key) for key in ('checks','issues','uncovered','attempt_id','input_version','input_digest','policy')})+'')
+ out.append(''+text(evidence.get('binding',{}))+'')
+ return ''.join(out)
+
+
+def render_item_report(result_ref,destination):
+ destination=Path(destination)
+ if destination.exists():fail('报告文件已存在,请换一个名称。')
+ html='视图版本 {task["view_revision"]} · 生成时冻结,待校验/运行中项尚未完成。