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("display_name","工程校验"))}
',f'
{text(result.get("verdict","未完成"))}
',
+ 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(key[1])} · {text(key[0])}
');out.append(diagram(subset))
+ out.append('
物理脚
修改前
修改后
事实
')
+ for pin in subset:
+ out.append(f'
{text(pin["endpoint"][2])}
{text(pin["before"])}
{text(pin["after"])}
{"连接变化" if pin["connection_changed"] else "文字变化" if pin["text_changed"] else "未发现变化"}
')
+ out.append('
')
+ out.append('
判断依据与范围
'+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='工程校验报告'+item_html(result_ref)+''
+ destination.parent.mkdir(parents=True,exist_ok=True)
+ temporary=destination.with_name(destination.name+'.'+uuid4().hex+'.tmp')
+ try:
+ temporary.write_text(html,encoding='utf-8')
+ # On Windows rename does not overwrite an existing destination.
+ if destination.exists():fail('报告文件已存在。')
+ temporary.rename(destination)
+ finally:temporary.unlink(missing_ok=True)
+ return destination
+
+
+def export_task(service,task_id,destination,*,request_id):
+ body=[task_id,str(Path(destination).resolve())]
+ with service._intake_lock:
+ with service.repo.store._lock:
+ old=service.repo._request('export',request_id,body)
+ if old is not None:
+ path=Path(old['path'])
+ if not path.is_file() and not path.is_dir():fail('先前导出的报告已丢失,请重新导出。')
+ return path
+ with service.repo.store.transaction():
+ task=service.repo.task(task_id);rows=service.queries._rows(task_id)
+ records=[service.read_item(row['item_id']) for row in rows]
+ for row in records:
+ if row.get('evidence_error'):fail('证据不可用,不能导出为有效报告:'+row['evidence_error'])
+ snapshot=dict(task,items=records)
+ root=Path(destination).resolve();root.mkdir(parents=True,exist_ok=True)
+ output=root/f'verification-{task_id[:12]}-v{task["view_revision"]}-{digest(request_id)[:8]}'
+ if output.exists():fail('报告目录已存在。')
+ staging=root/('.verification-'+uuid4().hex);staging.mkdir()
+ write_record(staging/'task.json',snapshot)
+ content=[f'
']
+ for row in records:
+ filename=row['item_id']+f'-v{row["input_version"]}.html'
+ result=((row.get('attempt') or {}).get('result') or {})
+ if result:
+ render_item_report(dict(result,display_name=row['display_name']),staging/filename)
+ content.append(f'