"""Hermetic, no-hardware checks for the independent six-profile USB set.""" import contextlib import io from pathlib import Path import struct import subprocess import sys import tempfile import unittest from unittest import mock import zipfile ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts")) import build_esp32_partition_migration as recipe import package_usb_partition_bridges as package from package_esp32_partition_migration import ( USB_BRIDGE_MARKER, USB_NVS_GUARD_MARKER, USB_BRIDGE_PROFILES, ) class UsbPartitionBridgeSetTest(unittest.TestCase): def setUp(self): self.temporary = tempfile.TemporaryDirectory(prefix="usb-bridge-set-") self.addCleanup(self.temporary.cleanup) self.root = Path(self.temporary.name) self.build = self.root / "custom build tree" self.output = self.root / "release" / "meshcore-usb-partition-bridges.zip" self.provenance = {"source_commit": "0123456789abcdef" * 2 + "01234567", "working_tree_dirty": True, "source_tree_sha256": "a" * 64} self.images = {} for (chip, mib), environment in USB_BRIDGE_PROFILES.items(): header = bytearray(24) header[0:3] = b"\xe9\x01\x02" header[3] = {4: 2, 8: 3, 16: 4}[mib] << 4 struct.pack_into("