#!/usr/bin/env python3 """Offline tests for check_zip_alignment.py. Standard library only, no network, no nix, no external binary -- this is the one piece of this repo that needs none of the pinned toolchain, so it is tested at plain `python3` speed rather than through with-nixpkgs.sh. Builds both a genuinely aligned fixture and a deliberately misaligned one with nothing but `zipfile`/`struct`, and runs the checker as a *subprocess* (not an import) against both, because that is how sign-apk.sh actually calls it -- a test that only imports the function would miss an argv or exit-code regression. python3 test_check_zip_alignment.py """ import os import struct import subprocess import sys import tempfile import unittest import zipfile HERE = os.path.dirname(os.path.abspath(__file__)) CHECKER = os.path.join(HERE, "check_zip_alignment.py") def add_stored(zf, name, data, align=None): """Write a STORED entry, padded to `align` bytes if given. Mirrors what a real zip-aligning tool does: pad the "extra field" of the local header so the entry's *data* (not its header) starts on the boundary. `align=None` writes the entry with no padding at all, which is what a plain zipfile.writestr call already does by default -- the negative-control case that must fail the check. """ info = zipfile.ZipInfo(name) info.compress_type = zipfile.ZIP_STORED if align: header_len = 30 + len(name.encode()) data_start_if_no_extra = zf.fp.tell() + header_len pad = (-data_start_if_no_extra) % align if pad: if pad < 4: pad += align extra_len = pad - 4 info.extra = struct.pack("