fix: judge declared sizes per entry with size_fits

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:01:46 +01:00
1 parent 2308039452
commit b81e89dbfb
6 files changed
+78 -82

No files matched your search

+29 -5
View File
@@ -1266,7 +1266,7 @@ class TestE2E(unittest.TestCase):
index = build_validation_index(profiles)
self.assertIn("present_req.bin", index)
self.assertIn("size", index["present_req.bin"]["checks"])
self.assertIn(16, index["present_req.bin"]["sizes"])
self.assertIn(16, {s for r in index["present_req.bin"]["rules"] for s in r["sizes"]})
self.assertIn("correct_hash.bin", index)
self.assertIn("crc32", index["correct_hash.bin"]["checks"])
@@ -1347,7 +1347,31 @@ class TestE2E(unittest.TestCase):
},
}
index = build_validation_index(profiles)
self.assertEqual(index["shared.bin"]["sizes"], {512, 1024})
self.assertEqual([r["sizes"] for r in index["shared.bin"]["rules"]], [{512}, {1024}])
def test_71b_validation_sizes_judged_per_entry(self):
"""One core's exact size is never bounded by another core's minimum:
pooled, gsplus's 131072-byte Apple IIGS ROM fell under basiliskii's
min_size and was refused."""
import tempfile
profiles = {
"exact": {"type": "libretro", "files": [
{"name": "ROM", "validation": ["size"], "size": [131072, 262144]}]},
"ranged": {"type": "libretro", "files": [
{"name": "ROM", "validation": ["size"], "min_size": 377670}]},
}
index = build_validation_index(profiles)
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "ROM")
with open(path, "wb") as f:
f.write(b"\0" * 131072)
self.assertIsNone(check_file_validation(path, "ROM", index))
with open(path, "wb") as f:
f.write(b"\0" * 1000)
reason, emus = check_file_validation(path, "ROM", index)
self.assertIn("size", reason)
self.assertEqual(emus, ["exact", "ranged"])
def test_79_validation_md5_pass(self):
"""File with correct MD5 passes validation."""
@@ -1392,9 +1416,9 @@ class TestE2E(unittest.TestCase):
path = self.files["present_req.bin"]["path"]
reason = check_file_validation(path, "present_req.bin", index)
self.assertIsNone(reason)
# Verify the index has min/max
self.assertEqual(index["present_req.bin"]["min_size"], 10)
self.assertEqual(index["present_req.bin"]["max_size"], 100)
# Each entry keeps its own min/max
rules = index["present_req.bin"]["rules"]
self.assertIn((10, 100), {(r["min_size"], r["max_size"]) for r in rules})
def test_84_validation_crypto_tracked(self):
"""Signature/crypto checks are tracked as non-reproducible."""
+11
View File
@@ -726,5 +726,16 @@ class MissingDumpsNameTheirRomsets(unittest.TestCase):
self.assertEqual(len(romsets_holding({"crc32": "00000001", "size": 8}, index)), 1)
class SizeRule(unittest.TestCase):
def test_a_granule_is_read_as_size_fits_reads_it(self):
from scripts.acquire.provenance import _fits
flash = {"min_size": 65536, "size_multiple": 65536}
self.assertTrue(_fits(131072, flash))
self.assertFalse(_fits(70000, flash))
self.assertFalse(_fits(None, flash))
if __name__ == "__main__":
unittest.main()