test: record paired live batch runtime acceptance
This commit is contained in:
1 parent
bdb096fb88
commit
9a3dff2f14
2 files changed
+413
No files matched your search
@@ -0,0 +1,69 @@
|
||||
# 批次私有桌面实机验收,2026-10-21
|
||||
|
||||
本机单组对照通过:两个工程的 BOM 导入及一次顺序替换合计从 170.860 秒降至 151.859 秒,减少 19.001 秒,约 11.12%。业务流程的私有桌面数从 6 个降至 2 个,CAD 启动数从 2 次降至 1 次。该时间不包含独立核验器额外启动 CAD 的开销,属于本次对照的实测值。
|
||||
|
||||
## 输入与隔离范围
|
||||
|
||||
- 基线:原仓库 `e15ee25`;候选:`.worktrees/batch-runtime` 的批次运行时实现。
|
||||
- 原始 fixture:原仓库 `build/cbb-bom-import-live-20261015/projects/Audio_D2128` 与 `Audio_T605A`。
|
||||
- 两版本分别复制到全新目录,使用相同源文件及输入;源工程全文件 SHA-256 在结束后保持一致。
|
||||
- 中心库:`F:/Sync Tool Skyworth/Work Maps/Skyworth_CBB_Lib/Mentor_lib_EE7.9/mentor_lib.lmc`,只读使用,`.lmc` SHA-256 不变。
|
||||
- 两工程均只替换 `RV05`,由 `4100-CA0000-T7` 替换为 `4100-CA0000-T0`。`sync_nc=True`,`copy_part_number_to_value=False`,队列策略为 `preserve`。
|
||||
- 证据根:工作树 `build/batch-runtime-live-20261021-144210`,实际基线结果在 `baseline2`,候选在 `candidate`。`comparison.json` 汇总跨版本对照。
|
||||
|
||||
`preserve` 保持原生目标库器件的 Value,而非恢复旧器件文字。此目标的原生 Value 属性缺失,最终期望为 Part Number=`4100-CA0000-T0`、Part Label=`0R`、Value 属性不存在。该语义来自 `docs/superpowers/specs/2026-10-14-v1.1.0-project-tasks-design.md`,与 `QPRestoreComponent`、`QPVerifyValuePolicy` 的存在性及内容核验一致。两版本的最终实际状态均符合该期望。
|
||||
|
||||
## 测量结果
|
||||
|
||||
| 指标 | 基线 | 候选 |
|
||||
|---|---:|---:|
|
||||
| BOM 导入两工程 | 2.250 s | 3.187 s |
|
||||
| 两工程顺序替换、保存、回读和流程收尾 | 168.610 s | 148.672 s |
|
||||
| 上述业务流程合计 | 170.860 s | 151.859 s |
|
||||
| BOM 阶段私有桌面 | 2 | 1 |
|
||||
| 执行阶段私有桌面 | 4 | 1 |
|
||||
| 执行阶段 CAD 启动 | 2 | 1 |
|
||||
|
||||
基线执行阶段含两个只读 native CLI 桌面和两个 CAD 桌面;候选在该阶段共用一个私有桌面和同一个 CAD PID `9192`,generation 为 `1`。独立核验器使用的额外 CAD 会话单独记录在 `desktop_starts`、`cad_starts` 的 `independent_before`、`independent_after` 阶段,不计入表中的业务资源数量。
|
||||
|
||||
## 保存结果与释放核验
|
||||
|
||||
每份工程均通过独立 Python COM 读取器,从空 CAD 开始重新打开磁盘工程,直接读取图页组件、全部属性和引脚网络。读取器不调用生产恢复/替换代码。
|
||||
|
||||
- 两版本替换前的完整独立读取 JSON 完全相等;替换后的完整 JSON 也完全相等,包含目标器件的所有属性。
|
||||
- 每份工程保持 57 个组件身份、103 个引脚连接;56 个非目标器件的全部属性、位置、变换和引脚状态完全不变。
|
||||
- `RV05` 的 UID、Refdes、位置、方向、比例和网络连接保持一致,目标引脚编号非空;Part Number/Part Label/Value 符合上述策略。
|
||||
- 候选两份写前记录具有相同 batch session/generation、不同 attempt ID,并均为 `mutation_possible`。两个逻辑工程分别记录标记。
|
||||
- 候选 BOM 和任务队列资源记录均为 `released`,无自动重试、恢复或已成功步骤的重放。
|
||||
- 观察器确认所有拥有的 CAD 退出、私有桌面消失,输入桌面未切换,拥有的 CAD 未出现在用户桌面或成为前台窗口。
|
||||
- 候选源代码/VBS 清单的 SHA-256 在实机执行期间保持一致。两个工程源副本及中心库 `.lmc` 的 SHA-256 均不变。
|
||||
|
||||
关键证据:
|
||||
|
||||
- `comparison.json`
|
||||
- `candidate/report.json`
|
||||
- `candidate/desktop-observation.json`
|
||||
- `candidate/source-under-test-manifest.json`
|
||||
- `candidate/data/batch-resources/*/session.json`
|
||||
- `candidate/data/tasks/*/quick-run/batch-attempts/*/*.json`
|
||||
- `baseline2/read-only-verification/saved-verification.json`
|
||||
- `baseline2/{before,after}-Audio_D2128.json`、`baseline2/{before,after}-Audio_T605A.json` 及 candidate 对应文件
|
||||
|
||||
初次探针在 `baseline` 目录因属性 COM 对象未强制转为 `IVdAttr` 而停止,尚未执行替换。修复读取器后使用全新 `baseline2` 副本执行。`baseline2` 两次替换均已完成,随后旧核验断言误把默认关闭复制选项视为 Part Label 复制;保留原错误报告,依据既有 Value 策略修正独立预期,再仅补充缺少的磁盘读取。该补充过程没有调用队列、恢复或替换。原始错误记录和历史输出均保留。
|
||||
|
||||
## 复现
|
||||
|
||||
`tools/probe_batch_runtime_live.py` 使用服务层 BOM 导入和任务队列入口,自动创建全新工程副本,无恢复/重放选项。`--repo` 指向被测版本,工具本身保持相同。
|
||||
|
||||
```powershell
|
||||
$batchProbeRepo = 'F:/Sync Tool Skyworth/Work Maps/dxdesigner-part-replacement'
|
||||
$batchProbeWorktree = "$batchProbeRepo/.worktrees/batch-runtime"
|
||||
$batchProbeSources = "$batchProbeRepo/build/cbb-bom-import-live-20261015/projects"
|
||||
$batchProbeLibrary = 'F:/Sync Tool Skyworth/Work Maps/Skyworth_CBB_Lib/Mentor_lib_EE7.9/mentor_lib.lmc'
|
||||
$batchProbeOutput = "$batchProbeWorktree/build/batch-runtime-live-NEW-TIMESTAMP"
|
||||
|
||||
python "$batchProbeWorktree/tools/probe_batch_runtime_live.py" --repo $batchProbeRepo --source-root $batchProbeSources --library $batchProbeLibrary --output "$batchProbeOutput/baseline" --run-native
|
||||
python "$batchProbeWorktree/tools/probe_batch_runtime_live.py" --repo $batchProbeWorktree --source-root $batchProbeSources --library $batchProbeLibrary --output "$batchProbeOutput/candidate" --run-native
|
||||
```
|
||||
|
||||
仅在两个任务均已完成而独立核验需补读时,可使用 `--verify-existing <已有输出目录>`。该分支只读已保存工程,不执行任务队列;核验结果写入独立的 `read-only-verification` 目录,且拒绝覆盖已有核验目录。
|
||||
@@ -0,0 +1,344 @@
|
||||
"""One-shot, two-project BOM/replace comparison on newly copied projects only.
|
||||
|
||||
The same tool imports either checkout via --repo. A failed run is retained and
|
||||
cannot be resumed: completed writes are never automatically repeated.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from dataclasses import asdict
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from threading import Event
|
||||
import time
|
||||
import traceback
|
||||
|
||||
|
||||
OLD, NEW = '4100-CA0000-T7', '4100-CA0000-T0'
|
||||
NAMES = ('Audio_D2128', 'Audio_T605A')
|
||||
|
||||
|
||||
def save(path, value):
|
||||
path.write_text(json.dumps(value, ensure_ascii=False, indent=2, default=str), encoding='utf-8')
|
||||
|
||||
|
||||
def hashes(root):
|
||||
return {str(path.relative_to(root)): hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
for path in root.rglob('*') if path.is_file()}
|
||||
|
||||
|
||||
def inspect_native(spec_path):
|
||||
"""Read the saved sheet directly, independently of the replacement snapshot."""
|
||||
import pythoncom
|
||||
import win32com.client
|
||||
from dx_productivity.trial_task_center.cad_identity import project_file_path, verify_application
|
||||
from dx_productivity.trial_task_center.native_helper import attach, attribute_value, components_on_sheet
|
||||
spec = json.loads(spec_path.read_text(encoding='utf-8'))
|
||||
assert Path(spec['project']).resolve().is_relative_to(Path(__file__).resolve().parents[1] / 'build')
|
||||
pythoncom.CoInitialize()
|
||||
app = document = None
|
||||
try:
|
||||
app = win32com.client.GetActiveObject('Viewdraw.Application')
|
||||
verify_application(app, require_view=False)
|
||||
assert not project_file_path(app), 'reader must start with empty CAD'
|
||||
assert app.OpenProject(spec['project'])
|
||||
rows = {}
|
||||
for schematic, sheet in spec['sheets']:
|
||||
document = app.SchematicSheetDocuments().Open(schematic, sheet)
|
||||
document.Activate()
|
||||
app, api = attach()
|
||||
assert Path(project_file_path(app)).resolve() == Path(spec['project']).resolve()
|
||||
pins = {}
|
||||
for item in app.ActiveView.Query(4096, 0):
|
||||
pin = api.IVdCmpPin(item._oleobj_)
|
||||
point = pin.GetLocation()
|
||||
connection = pin.Connection
|
||||
net = None if connection is None else connection.Net
|
||||
assert connection is None or net is not None
|
||||
pins.setdefault(str(pin.Component.UID), []).append(dict(number=str(pin.Number),
|
||||
x=float(point.X), y=float(point.Y), net_uid=None if net is None else str(net.UID),
|
||||
net_name=None if net is None else str(net.LogicalNetName)))
|
||||
for component in components_on_sheet(app, api):
|
||||
uid = str(component.UID)
|
||||
point = component.GetLocation()
|
||||
attributes = {}
|
||||
for item in component.Attributes:
|
||||
attr = api.IVdAttr(item._oleobj_)
|
||||
location = attr.GetLocation()
|
||||
attributes[str(attr.Name)] = dict(value=str(attr.Value or ''),
|
||||
instance_value=str(attr.InstanceValue or ''), x=float(location.X), y=float(location.Y),
|
||||
color=int(attr.Color), font=int(attr.Font), size=float(attr.Size),
|
||||
orientation=int(attr.Orientation), visible=bool(attr.Visible))
|
||||
rows[f'{schematic}:{sheet}:{uid}'] = dict(uid=uid, refdes=str(component.Refdes),
|
||||
schematic=schematic, sheet=sheet, x=float(point.X), y=float(point.Y),
|
||||
orientation=int(component.Orientation), scale=float(component.Scale), attributes=attributes,
|
||||
part_number=attribute_value(component, 'Part Number'), value=attribute_value(component, 'Value'),
|
||||
part_label=attribute_value(component, 'Part Label'),
|
||||
pins=sorted(pins.get(uid, []), key=lambda pin: (pin['x'], pin['y'], pin['number'])))
|
||||
document.Close(False, '')
|
||||
document = None
|
||||
app.CloseProject()
|
||||
assert not project_file_path(app)
|
||||
save(Path(spec['destination']), rows)
|
||||
finally:
|
||||
if document is not None:
|
||||
document.Close(False, '')
|
||||
if app is not None and project_file_path(app):
|
||||
assert Path(project_file_path(app)).resolve() == Path(spec['project']).resolve()
|
||||
app.CloseProject()
|
||||
app = None
|
||||
pythoncom.CoUninitialize()
|
||||
|
||||
|
||||
def compare_saved(before, after):
|
||||
assert set(before) == set(after), 'component identity set changed'
|
||||
selected = 0
|
||||
for key, old in before.items():
|
||||
new = after[key]
|
||||
if old['refdes'] != 'RV05':
|
||||
assert old == new, f'non-target changed: {key}'
|
||||
continue
|
||||
selected += 1
|
||||
assert old['part_number'] == OLD and new['part_number'] == NEW
|
||||
assert new['part_label'] == '0R'
|
||||
# This fixture uses the unchecked copy option. Its native target has no
|
||||
# Value attribute; preserve means retaining that absence, not restoring
|
||||
# OLD's Value. See the 2026-10-14 project-tasks design and the production
|
||||
# QPVerifyValuePolicy existence/content check after native replacement.
|
||||
assert new['value'] == '' and 'Value' not in new['attributes']
|
||||
for field in ('uid', 'refdes', 'schematic', 'sheet', 'x', 'y', 'orientation', 'scale'):
|
||||
assert old[field] == new[field], (key, field)
|
||||
graph = lambda row: sorted((pin['x'], pin['y'], pin['net_uid'], pin['net_name']) for pin in row['pins'])
|
||||
assert graph(old) == graph(new) and new['pins'], f'target connectivity changed: {key}'
|
||||
assert all(pin['number'] for pin in new['pins']), f'unpromoted target pin: {key}'
|
||||
assert selected == 1
|
||||
return {'components': len(after), 'targets': selected, 'unchanged_components': len(after) - selected,
|
||||
'pin_connections': sum(len(row['pins']) for row in after.values()),
|
||||
'target_state': [{key: row[key] for key in ('uid', 'refdes', 'part_number', 'part_label', 'value')}
|
||||
| {'value_attribute_exists': 'Value' in row['attributes']}
|
||||
for row in after.values() if row['refdes'] == 'RV05']}
|
||||
|
||||
|
||||
def verify_existing(repo, root):
|
||||
"""Finish readback only; this branch has no task queue or replacement call."""
|
||||
import sqlite3
|
||||
import win32api
|
||||
from dx_productivity.trial_task_center.isolated_cad import IsolatedCadSession
|
||||
from private_desktop_observer import PrivateDesktopObserver
|
||||
root = root.resolve(strict=True)
|
||||
assert root.is_relative_to(Path(__file__).resolve().parents[1] / 'build')
|
||||
original = json.loads((root / 'report.json').read_text(encoding='utf-8'))
|
||||
with sqlite3.connect(root / 'tasks.db') as database:
|
||||
assert database.execute('select count(*) from tasks where status="completed" and copy_part_number_to_value=0').fetchone()[0] == 2
|
||||
verification = root / 'read-only-verification'
|
||||
verification.mkdir(exist_ok=False)
|
||||
report = {'mode': 'read_only_saved_verification', 'copy_part_number_to_value': False,
|
||||
'value_policy': 'preserve native target Value; this target has no Value attribute', 'projects': []}
|
||||
try:
|
||||
with PrivateDesktopObserver(verification) as observer:
|
||||
for raw_project in original['projects']:
|
||||
project = Path(raw_project).resolve(strict=True)
|
||||
assert project.is_relative_to(root / 'projects')
|
||||
before = json.loads((root / f'before-{project.stem}.json').read_text(encoding='utf-8'))
|
||||
destination = root / f'after-{project.stem}.json'
|
||||
if not destination.exists():
|
||||
evidence = verification / project.stem
|
||||
evidence.mkdir()
|
||||
spec = evidence / 'spec.json'
|
||||
save(spec, {'project': str(project), 'sheets': sorted({(row['schematic'], row['sheet']) for row in before.values()}),
|
||||
'destination': str(destination)})
|
||||
with IsolatedCadSession(evidence) as cad:
|
||||
observer.records[cad.desktop.name] = dict(cad.record)
|
||||
observer.handles[cad.cad.pid] = win32api.OpenProcess(0x100000, False, cad.cad.pid)
|
||||
process = cad.start_worker((sys.executable, str(Path(__file__).resolve()), '--repo', str(repo),
|
||||
'--inspect-file', str(spec), '--run-native'), stdout=-1, stderr=-1)
|
||||
try:
|
||||
code = process.wait(timeout=180)
|
||||
(evidence / 'worker-output.txt').write_bytes(process.stdout.read() + b'\n' + process.stderr.read())
|
||||
assert code == 0, (evidence / 'worker-output.txt').read_text(errors='replace')
|
||||
finally:
|
||||
process.close()
|
||||
after = json.loads(destination.read_text(encoding='utf-8'))
|
||||
report['projects'].append({'project': str(project), **compare_saved(before, after)})
|
||||
observation = json.loads((verification / 'desktop-observation.json').read_text(encoding='utf-8'))
|
||||
assert not observation['observer_errors']
|
||||
assert observation['input_desktop_before'] == observation['input_desktop_after']
|
||||
assert not observation['owned_cad_became_foreground'] and not observation['owned_cad_on_input_desktop']
|
||||
assert all(observation['cad_exit_confirmed'].values()) and all(observation['desktop_absent'].values())
|
||||
report['passed'] = True
|
||||
finally:
|
||||
save(verification / 'saved-verification.json', report)
|
||||
print(json.dumps(report, ensure_ascii=False), flush=True)
|
||||
return 0 if report.get('passed') else 1
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--repo', type=Path, required=True)
|
||||
parser.add_argument('--source-root', type=Path)
|
||||
parser.add_argument('--library', type=Path)
|
||||
parser.add_argument('--output', type=Path)
|
||||
parser.add_argument('--run-native', action='store_true', required=True)
|
||||
parser.add_argument('--inspect-file', type=Path)
|
||||
parser.add_argument('--verify-existing', type=Path, help='Read saved completed run only; never execute replacement')
|
||||
args = parser.parse_args()
|
||||
repo = args.repo.resolve(strict=True)
|
||||
sys.path.insert(0, str(repo / 'src'))
|
||||
sys.path.insert(0, str(repo / 'tools'))
|
||||
if args.inspect_file:
|
||||
inspect_native(args.inspect_file)
|
||||
return 0
|
||||
if args.verify_existing:
|
||||
return verify_existing(repo, args.verify_existing)
|
||||
assert args.output and args.source_root and args.library
|
||||
output = args.output.resolve()
|
||||
assert output.is_relative_to(Path(__file__).resolve().parents[1] / 'build')
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
source_manifest = {'git_head': subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo, text=True).strip(),
|
||||
'files': {str(path.relative_to(repo)): hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
for folder, pattern in (('src', '*.py'), ('integration', '*.vbs'))
|
||||
for path in (repo / folder).rglob(pattern)}}
|
||||
save(output / 'source-under-test-manifest.json', source_manifest)
|
||||
library = args.library.resolve(strict=True)
|
||||
library_hash = hashlib.sha256(library.read_bytes()).hexdigest()
|
||||
source_root = args.source_root.resolve(strict=True)
|
||||
source_hashes, projects = {}, []
|
||||
for name in NAMES:
|
||||
source = source_root / name
|
||||
assert (source / (name + '.prj')).is_file()
|
||||
source_hashes[name] = hashes(source)
|
||||
folder = output / 'projects' / name
|
||||
shutil.copytree(source, folder)
|
||||
project = folder / (name + '.prj')
|
||||
text, count = re.subn(r'(?m)^KEY CentralLibrary .*$',
|
||||
lambda _: f'KEY CentralLibrary "{library.as_posix()}"', project.read_text(encoding='utf-8-sig'))
|
||||
assert count == 1
|
||||
project.write_text(text, encoding='utf-8')
|
||||
projects.append(project)
|
||||
from dx_productivity.trial_task_center.bom_plan import write_bom_template
|
||||
from dx_productivity.trial_task_center.isolated_cad import IsolatedCadSession
|
||||
from dx_productivity.trial_task_center.isolated_desktop import PrivateDesktop
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
from dx_productivity.trial_task_center.store import TaskStore
|
||||
from dx_productivity.trial_task_center.task_queue import execute_task_queue
|
||||
from private_desktop_observer import PrivateDesktopObserver
|
||||
report = {'repo': str(repo), 'library': str(library), 'source_root': str(source_root),
|
||||
'projects': list(map(str, projects)), 'input': {'old': OLD, 'new': NEW, 'refdes': 'RV05',
|
||||
'copy_part_number_to_value': False, 'value_mode': 'preserve'},
|
||||
'steps': [], 'desktop_starts': [], 'cad_starts': [], 'source_hashes': source_hashes}
|
||||
save(output / 'report.json', report)
|
||||
phase = 'setup'
|
||||
observer = PrivateDesktopObserver(output)
|
||||
original_desktop_enter, original_cad_enter = PrivateDesktop.__enter__, IsolatedCadSession.__enter__
|
||||
def enter_desktop(desktop):
|
||||
started = time.monotonic()
|
||||
try:
|
||||
return original_desktop_enter(desktop)
|
||||
finally:
|
||||
report['desktop_starts'].append({'phase': phase, 'desktop': desktop.name,
|
||||
'seconds': time.monotonic() - started})
|
||||
def enter_cad(cad):
|
||||
started = time.monotonic()
|
||||
try:
|
||||
return original_cad_enter(cad)
|
||||
finally:
|
||||
entry = {'phase': phase, 'desktop': cad.desktop.name, 'seconds': time.monotonic() - started,
|
||||
'pid': None if cad.cad is None else cad.cad.pid}
|
||||
report['cad_starts'].append(entry)
|
||||
if entry['pid']:
|
||||
import win32api
|
||||
observer.records[entry['desktop']] = dict(cad.record)
|
||||
try:
|
||||
observer.handles[entry['pid']] = win32api.OpenProcess(0x100000, False, entry['pid'])
|
||||
except Exception:
|
||||
pass
|
||||
PrivateDesktop.__enter__, IsolatedCadSession.__enter__ = enter_desktop, enter_cad
|
||||
store = TaskStore(output / 'tasks.db')
|
||||
service = TaskCenterService(store, configure_logging(output / 'data'))
|
||||
def record(stage, started, **details):
|
||||
entry = {'stage': stage, 'seconds': time.monotonic() - started, **details}
|
||||
report['steps'].append(entry)
|
||||
save(output / 'report.json', report)
|
||||
print(json.dumps(entry, ensure_ascii=False, default=str), flush=True)
|
||||
def independent(project, sheets, label):
|
||||
name = project.stem
|
||||
root = output / 'independent-read' / 'quick-run-history' / f'sheet-discovery-{label}-{name}'
|
||||
root.mkdir(parents=True)
|
||||
destination, spec = output / f'{label}-{name}.json', root / 'spec.json'
|
||||
save(spec, {'project': str(project), 'sheets': sorted(sheets), 'destination': str(destination)})
|
||||
with IsolatedCadSession(root) as cad:
|
||||
process = cad.start_worker((sys.executable, str(Path(__file__).resolve()), '--repo', str(repo),
|
||||
'--inspect-file', str(spec), '--run-native'), stdout=-1, stderr=-1)
|
||||
try:
|
||||
code = process.wait(timeout=180)
|
||||
(root / 'worker-output.txt').write_bytes(process.stdout.read() + b'\n' + process.stderr.read())
|
||||
assert code == 0, (root / 'worker-output.txt').read_text(errors='replace')
|
||||
finally:
|
||||
process.close()
|
||||
return json.loads(destination.read_text(encoding='utf-8'))
|
||||
started_all = time.monotonic()
|
||||
try:
|
||||
with observer:
|
||||
tasks = service.create_project_tasks(output / 'projects', selected_paths=tuple(projects))
|
||||
assert len(tasks) == 2
|
||||
bom = write_bom_template(output / 'input.xlsx', ({'project_path': str(project),
|
||||
'old_part_number': OLD, 'new_part_number': NEW, 'refdes': 'RV05', 'enabled': True,
|
||||
'sync_nc': True} for project in projects))
|
||||
phase = 'bom_import'
|
||||
started = time.monotonic()
|
||||
imported = service.inspect_bom_batch(tasks[0].task_id, bom, on_progress=lambda message: print(message, flush=True))
|
||||
assert imported.passed_rows == 2 and imported.preview is not None and not imported.failed_rows
|
||||
service.save_bom_batch(imported.preview, {item.task_id: item.rows for item in imported.preview.projects})
|
||||
record(phase, started, passed_rows=imported.passed_rows)
|
||||
phase = 'independent_before'
|
||||
before = {}
|
||||
for project in projects:
|
||||
rows = next(item.rows for item in imported.preview.projects if item.project_path.resolve() == project.resolve())
|
||||
sheets = {(row.target.schematic_name, row.target.sheet_number) for row in rows}
|
||||
before[project.stem] = independent(project, sheets, 'before')
|
||||
phase = 'queue_execution'
|
||||
started = time.monotonic()
|
||||
result = execute_task_queue(service, tuple(task.task_id for task in tasks), stop_event=Event())
|
||||
assert all(entry.state == 'completed' for entry in result.entries), result
|
||||
record(phase, started, result=asdict(result))
|
||||
phase = 'independent_after'
|
||||
for project in projects:
|
||||
sheets = {(row['schematic'], row['sheet']) for row in before[project.stem].values()}
|
||||
started = time.monotonic()
|
||||
after = independent(project, sheets, 'after')
|
||||
record(f'independent-{project.stem}', started, **compare_saved(before[project.stem], after))
|
||||
observation = json.loads((output / 'desktop-observation.json').read_text(encoding='utf-8'))
|
||||
assert not observation['observer_errors']
|
||||
assert observation['input_desktop_before'] == observation['input_desktop_after']
|
||||
assert not observation['owned_cad_became_foreground'] and not observation['owned_cad_on_input_desktop']
|
||||
assert all(observation['cad_exit_confirmed'].values()) and all(observation['desktop_absent'].values())
|
||||
report['verified'] = True
|
||||
except BaseException as error:
|
||||
report['error'] = f'{type(error).__name__}: {error}'
|
||||
report['traceback'] = traceback.format_exc()
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
report['total_seconds_including_independent_reads'] = time.monotonic() - started_all
|
||||
report['workflow_seconds'] = sum(step['seconds'] for step in report['steps'] if step['stage'] in {'bom_import', 'queue_execution'})
|
||||
report['source_unchanged'] = all(hashes(source_root / name) == source_hashes[name] for name in NAMES)
|
||||
report['library_lmc_unchanged'] = hashlib.sha256(library.read_bytes()).hexdigest() == library_hash
|
||||
PrivateDesktop.__enter__, IsolatedCadSession.__enter__ = original_desktop_enter, original_cad_enter
|
||||
store.close()
|
||||
from dx_productivity.trial_task_center.legacy_paths import cleanup_worker_aliases
|
||||
report['alias_cleanup_errors'] = list(map(str, cleanup_worker_aliases()))
|
||||
save(output / 'report.json', report)
|
||||
print(json.dumps({key: report.get(key) for key in ('verified', 'error', 'workflow_seconds', 'source_unchanged',
|
||||
'library_lmc_unchanged', 'desktop_starts', 'cad_starts')}, ensure_ascii=False), flush=True)
|
||||
return 0 if (report.get('verified') and report['source_unchanged'] and report['library_lmc_unchanged']
|
||||
and not report['alias_cleanup_errors']) else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user