File size: 2,431 Bytes
28dbedc
8aeaae5
 
28dbedc
 
 
 
 
 
8aeaae5
28dbedc
 
 
 
 
 
 
 
 
 
 
 
8e0d79f
 
28dbedc
 
 
 
 
8aeaae5
28dbedc
8aeaae5
 
 
 
 
 
 
 
 
28dbedc
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
import hashlib
from io import BytesIO
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from zipfile import ZipFile
from PIL import Image

ROOT = Path(__file__).resolve().parents[1]


class BundleTests(unittest.TestCase):
    def test_public_allowlist_and_ui_lock(self):
        with tempfile.TemporaryDirectory() as temp:
            target = Path(temp) / "space.zip"
            subprocess.run([sys.executable, str(ROOT / "scripts/build_bundle.py"), str(target)], check=True, capture_output=True)
            with ZipFile(target) as archive:
                names = archive.namelist()
                self.assertIn("space_app.py", names)
                self.assertIn("assets/NotoSansCJKsc-Regular.otf", names)
                self.assertIn("assets/NotoSansCJK-OFL.txt", names)
                self.assertIn("docs/HF_SPACE_DEPLOYMENT.md", names)
                self.assertFalse(any(n.startswith(("verification/", "logs/", ".runtime/", "deploy/")) for n in names))
                self.assertNotIn("docs/FUYAO_REPRODUCTION.md", names)
                self.assertNotIn("scripts/service.py", names)
                rows = json.loads(archive.read("data/cases.json"))
                self.assertEqual(len(rows), 22)
                self.assertTrue(all("artifact_image_sha256" in row for row in rows))
                self.assertEqual(len({row["route"] for row in rows}), 9)
                for row in rows:
                    image_bytes = archive.read(row["image"])
                    self.assertEqual(hashlib.sha256(image_bytes).hexdigest(), row["image_sha256"])
                    self.assertEqual(row["artifact_image_sha256"], row["image_sha256"])
                    with Image.open(BytesIO(image_bytes)) as image:
                        self.assertEqual(list(image.size), row["image_size"])
                    if not row["expected_available"]:
                        self.assertEqual(row["expected"], "")
                payload = archive.read("data/cases.json").decode()
                for marker in ["/dataset-", "/workspace/", "xiaopeng.com", "source_jsonl", "source_line"]:
                    self.assertNotIn(marker, payload)
                archive.extractall(Path(temp) / "unpacked")
            subprocess.run([sys.executable, "scripts/verify_ui.py"], cwd=Path(temp) / "unpacked", check=True, capture_output=True)


if __name__ == "__main__":
    unittest.main()