File size: 2,264 Bytes
573b479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
import hashlib
import json
import pathlib
import unittest


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


class StaticSpaceTests(unittest.TestCase):
    def setUp(self):
        self.manifest = json.loads(
            (ROOT / "static" / "results.json").read_text(encoding="utf-8")
        )

    def test_manifest_is_static_synthetic_and_complete(self):
        self.assertEqual(self.manifest["mode"], "static_precomputed_demonstration")
        self.assertFalse(self.manifest["live_inference"])
        self.assertTrue(self.manifest["synthetic_only"])
        self.assertEqual(self.manifest["stored_client_data"], "none")
        self.assertEqual(len(self.manifest["scenes"]), 3)

    def test_static_assets_match_recorded_hashes(self):
        for scene in self.manifest["scenes"]:
            for field in ("source", "depth"):
                path = ROOT / scene[field]
                self.assertTrue(path.is_file(), path)
                digest = hashlib.sha256(path.read_bytes()).hexdigest()
                self.assertEqual(digest, scene[f"{field}_sha256"])

    def test_page_exposes_no_submission_controls_or_remote_runtime(self):
        html = (ROOT / "index.html").read_text(encoding="utf-8").lower()
        script = (ROOT / "app-static.js").read_text(encoding="utf-8").lower()
        self.assertNotIn("<form", html)
        self.assertNotIn("<input", html)
        self.assertNotIn("<textarea", html)
        self.assertNotIn("type=\"file\"", html)
        self.assertIn('fetch("static/results.json"', script)
        self.assertNotIn("api-inference", script)
        self.assertNotIn("gradio_client", script)

    def test_preserved_gradio_sources_match_reviewed_hashes(self):
        expected = {
            "app.py": "5a17d5039fb1e77117ac80c104e8042a9154e1154d4dd49a02fb1b30f9199327",
            "lab_core.py": "77e61aadae335b45526befb50d6766dc22a8ba8add91a2183b34beebcaeca21d",
            "requirements.txt": "f289ae35c0e40ef77a94f2ed0cb2830fba563c02ce3594195b4c8b1d5880c561",
        }
        for relative_path, expected_hash in expected.items():
            digest = hashlib.sha256((ROOT / relative_path).read_bytes()).hexdigest()
            self.assertEqual(digest, expected_hash)


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