fix: complete legacy CBB import recovery and guard late native submission

This commit is contained in:
阿白叔 committed 2026-11-03 16:03:14 +08:00
1 parent d36b6bcad0
commit 7527800128
12 files changed
+326 -25

No files matched your search

+29
View File
@@ -72,6 +72,24 @@ def test_assets_require_correct_library_references_and_unknown_bytes(project):
asset_identity(source, library)
def test_linked_legacy_identity_preserves_template_bytes_and_aligns_only_active_project(project, tmp_path):
from cbb_refresh_verify.native_engineering_identity import asset_identity, project_library
from cbb_refresh_verify.backup_recovery import _align_library
source, library = project
template = source.parent/'PCB/template.prj'
(source.parent/'PCB/pcb.prj').rename(template)
original = template.read_bytes()
before = asset_identity(source, library)
assert 'PCB/template.prj' in before['assets']
other = tmp_path/'other.lmc'; other.write_bytes(b'other library')
_align_library(source, next((source.parent/'PCB').glob('*.pcb')), other)
assert template.read_bytes() == original
assert project_library(source) == other
assert asset_identity(source, other) == before
template.write_bytes(original+b'unknown engineering change')
assert asset_identity(source, other) != before
@pytest.mark.parametrize('relative', ['database/cdbsvr/persistent.dat',
'database/cdbsvr/new-engineering/config.bin', 'database/cdbsvr/events/custom.dat',
'database/cdbsvr/plog/unknown-engineering.bin'])
@@ -199,3 +217,14 @@ def test_edif_only_normalizes_root_written_timestamp_preserving_geometry_and_pro
for bad in [first[:-1], first.replace(b'(edifVersion 2 0 0)', b'(edifVersion 1 0 0)'),
first.replace(b'(cellRef Top', b'(cellRef Other'), first.replace(b'(pt 1 2)', b'')]:
with pytest.raises(ValueError): normalize_edif(bad, 'Top')
def test_edif_binds_native_escaped_digit_initial_root_without_changing_design_bytes():
from cbb_refresh_verify.native_engineering_identity import normalize_edif
report = edif_report().replace(b'cell Top', b'cell &1GPHY_8212').replace(b'cellRef Top', b'cellRef &1GPHY_8212')
normalized = normalize_edif(report, '1GPHY_8212')
assert b'(cell &1GPHY_8212' in normalized and b'(cellRef &1GPHY_8212' in normalized
for wrong in ('1GPHY_8211', '&1GPHY_8212'):
with pytest.raises(ValueError): normalize_edif(report, wrong)
with pytest.raises(ValueError):
normalize_edif(report.replace(b'&1GPHY_8212', b'1GPHY_8212'), '1GPHY_8212')