test: verify native cleanup and fail packaged acceptance on queue errors

This commit is contained in:
阿白叔 committed 2026-10-19 17:02:54 +08:00
1 parent e2f76c3387
commit bbf9bffe32
8 files changed
+416 -37

No files matched your search

+61 -28
View File
@@ -15,9 +15,21 @@ from accept_packaged_ui import wait
from packaged_window_driver import WindowDriver
def read_tasks(path):
with sqlite3.connect(path) as db:
return db.execute('select task_id,name from tasks order by task_id').fetchall()
def read_rules(path):
with sqlite3.connect(path) as db:
db.row_factory = sqlite3.Row
return [dict(row) for row in db.execute('select * from rules order by rule_id')]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--root', type=Path, required=True)
parser.add_argument('--resume-created', action='store_true', help='Reuse already-created disposable legacy task/rule fixtures after a driver assertion failed')
args = parser.parse_args()
root = args.root.resolve(strict=True)
repository = Path(__file__).resolve().parents[1]
@@ -25,36 +37,53 @@ def main():
release = json.loads((repository / 'docs/releases/v1.1.1-build.json').read_text(encoding='utf-8'))
assert hashlib.sha256(legacy.read_bytes()).hexdigest() == release['artifacts']['exe_sha256']
old_data, new_data = root / 'v111-created-data', root / 'v111-upgraded-copy'
old_data.mkdir(exist_ok=False)
projects = root / 'upgrade-fixture-projects'
for name in ('Legacy-A', 'Legacy-B'):
path = projects / name / 'board.prj'
path.parent.mkdir(parents=True)
path.write_text('KEY FrontEndSnapshot "DxD"\nKEY iCDBDir "database"\n', encoding='utf-8')
env = dict(os.environ, TEMP=str(repository / 'build/test-temp-remediation'),
TMP=str(repository / 'build/test-temp-remediation'), LOCALAPPDATA=str(root / 'profile'))
for key in ('PYTHONPATH', 'PYTHONHOME', 'DX_TASK_CENTER_HOME', 'QT_QPA_PLATFORM'):
env.pop(key, None)
process = subprocess.Popen([str(legacy), '--data-root', str(old_data)], env=env,
creationflags=subprocess.CREATE_NO_WINDOW)
driver = WindowDriver(process.pid, root / 'upgrade-recording')
window = driver.main()
try:
driver.click(driver.find(automation_id='newTaskButton'))
dialog = wait(lambda: next((w for w in driver.windows() if w.window_text() == '从目录创建工程任务'), None), timeout=15)
driver.type_text(driver.find(automation_id='taskDirectory', window=dialog), str(projects))
driver.click(driver.find(automation_id='readTaskProjects', window=dialog))
create = driver.find('创建任务', kind='Button', window=dialog)
wait(create.is_enabled, timeout=20)
driver.click(create)
def read_tasks(path):
with sqlite3.connect(path) as db:
return db.execute('select task_id,name from tasks order by task_id').fetchall()
original = wait(lambda: (rows if len(rows := read_tasks(old_data / 'task-center.db')) == 2 else None), timeout=20)
time.sleep(.5)
finally:
win32gui.PostMessage(window.handle, win32con.WM_CLOSE, 0, 0)
process.wait(timeout=30)
if args.resume_created:
assert old_data.is_dir() and not new_data.exists()
original = read_tasks(old_data / 'task-center.db')
old_rules = read_rules(old_data / 'task-center.db')
assert len(original) == 2 and old_rules
assert all(row['old_part_number'] == 'LEGACY_OLD' and row['new_part_number'] == 'LEGACY_NEW' for row in old_rules)
else:
old_data.mkdir(exist_ok=False)
projects = root / 'upgrade-fixture-projects'
for name in ('Legacy-A', 'Legacy-B'):
path = projects / name / 'board.prj'
path.parent.mkdir(parents=True)
path.write_text('KEY FrontEndSnapshot "DxD"\nKEY iCDBDir "database"\n', encoding='utf-8')
env = dict(os.environ, TEMP=str(repository / 'build/test-temp-remediation'),
TMP=str(repository / 'build/test-temp-remediation'), LOCALAPPDATA=str(root / 'profile'))
for key in ('PYTHONPATH', 'PYTHONHOME', 'DX_TASK_CENTER_HOME', 'QT_QPA_PLATFORM'):
env.pop(key, None)
process = subprocess.Popen([str(legacy), '--data-root', str(old_data)], env=env,
creationflags=subprocess.CREATE_NO_WINDOW)
driver = WindowDriver(process.pid, root / 'upgrade-recording')
window = driver.main()
try:
driver.click(driver.find(automation_id='newTaskButton'))
dialog = wait(lambda: next((w for w in driver.windows() if w.window_text() == '从目录创建工程任务'), None), timeout=15)
driver.type_text(driver.find(automation_id='taskDirectory', window=dialog), str(projects))
driver.click(driver.find(automation_id='readTaskProjects', window=dialog))
create = driver.find('创建任务', kind='Button', window=dialog)
wait(create.is_enabled, timeout=20)
driver.click(create)
original = wait(lambda: (rows if len(rows := read_tasks(old_data / 'task-center.db')) == 2 else None), timeout=20)
add_rule = wait(lambda: (button if (button := driver.find(automation_id='addMappingButton')).is_enabled() else None), timeout=20)
driver.click(add_rule)
rule_dialog = wait(lambda: next((w for w in driver.windows() if w.window_text() == '替换规则'), None), timeout=15)
fields = sorted(rule_dialog.descendants(control_type='Edit'), key=lambda field: field.rectangle().top)
assert len(fields) >= 2
driver.type_text(fields[0], 'LEGACY_OLD')
driver.type_text(fields[1], 'LEGACY_NEW')
driver.click(driver.find('确定', kind='Button', window=rule_dialog))
old_rules = wait(lambda: (rows if len(rows := read_rules(old_data / 'task-center.db')) >= 1 else None), timeout=20)
assert all(row['old_part_number'] == 'LEGACY_OLD' and row['new_part_number'] == 'LEGACY_NEW' for row in old_rules)
finally:
win32gui.PostMessage(window.handle, win32con.WM_CLOSE, 0, 0)
process.wait(timeout=30)
before = hashlib.sha256((old_data / 'task-center.db').read_bytes()).hexdigest()
new_data.mkdir()
with sqlite3.connect((old_data / 'task-center.db').as_uri() + '?mode=ro', uri=True) as src, sqlite3.connect(new_data / 'task-center.db') as dst:
@@ -66,8 +95,12 @@ def main():
report = dict(legacy_version='1.1.1', task_count=len(original), candidate_exit_code=result.returncode,
task_identities_preserved=read_tasks(new_data / 'task-center.db') == original,
legacy_source_unchanged=hashlib.sha256((old_data / 'task-center.db').read_bytes()).hexdigest() == before,
fixture_is_metadata_only=True, cad_launched=False)
assert result.returncode == 0 and report['task_identities_preserved'] and report['legacy_source_unchanged'], report
fixture_is_metadata_only=True, cad_launched=False,
rules_preserved=all(all(row[key] == before_value for key, before_value in old.items())
for old, row in zip(old_rules, read_rules(new_data / 'task-center.db'), strict=True)),
unselected_cells_migrated=all(row['target_cell'] == '' for row in read_rules(new_data / 'task-center.db')),
rule_count=len(old_rules))
assert result.returncode == 0 and report['task_identities_preserved'] and report['legacy_source_unchanged'] and report['rules_preserved'] and report['unselected_cells_migrated'], report
(root / 'v111-upgrade-report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
print(json.dumps(report, ensure_ascii=False, indent=2))