import hashlib import json from pathlib import Path import subprocess import sys import tempfile import zipfile root = Path(__file__).resolve().parents[2] sys.path.insert(0, str(root / "scripts")) import sync_package version = (root / "VERSION").read_text().strip() document = (root / "references" / "doc-snapshot.txt").read_text(encoding="utf-8") fingerprint = hashlib.sha1(sync_package.rule_check.normalize(document).encode("utf-8")).hexdigest()[:12] output = root.parent / "dist" archive = Path(sync_package.make_zip(str(root), str(output), version)) with zipfile.ZipFile(archive) as bundle: count = len(bundle.infolist()) sync_package.update_install_note(str(root), version, count, fingerprint) archive = Path(sync_package.make_zip(str(root), str(output), version)) extracted = Path(tempfile.mkdtemp(prefix="sku-audit-v114-")) with zipfile.ZipFile(archive) as bundle: names = bundle.namelist() assert len(names) == count assert bundle.testzip() is None assert not any(name.endswith("credentials.json") or "__pycache__" in name or "/.git/" in name for name in names) assert bundle.read("sku_audit/VERSION").decode().strip() == version for name in names: parts = Path(name).parts assert not Path(name).is_absolute() and ".." not in parts bundle.extractall(extracted) workspace = extracted / root.name coverage = subprocess.run([sys.executable, "-B", "scripts/audit.py", "--coverage"], cwd=workspace, check=True, capture_output=True, text=True, encoding="utf-8") print("\n".join(coverage.stdout.splitlines()[:3])) check = ( "from pathlib import Path;import sys;sys.path.insert(0,'scripts');import rule_check,audit;" "r=rule_check.cmd_verify(Path('references/doc-snapshot.txt').read_text(encoding='utf-8'),audit.pick_workbook(),quiet=True);" "print({k:r[k] for k in ('ok','warn','bad')});raise SystemExit(bool(r['bad']))" ) verified = subprocess.run([sys.executable, "-B", "-c", check], cwd=workspace, check=True, capture_output=True, text=True, encoding="utf-8") print("extracted rule verification", verified.stdout.strip()) digest = hashlib.sha256(archive.read_bytes()).hexdigest() archive.with_suffix(".zip.sha256").write_text(digest + " " + archive.name + "\n", encoding="utf-8") print(json.dumps({"version": version, "archive": str(archive), "files": count, "size_bytes": archive.stat().st_size, "zip_crc": "pass", "credentials_included": False, "extracted_checks": "pass", "sha256": digest}, ensure_ascii=False))