fix: read the content checks from model.profiles

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent 5cce11e7d0
commit bb46a0282a
2 files changed
+15 -4

No files matched your search

+6 -4
View File
@@ -34,8 +34,6 @@ show. Anything else settles nothing. A check the entry declares with
agrees with it. Of validation, the table writes only a
missing `size`. A contradicted content check goes to review: which hash a
core computes is read in its code.
Standard library only.
"""
from __future__ import annotations
@@ -43,6 +41,8 @@ from __future__ import annotations
from collections.abc import Callable, Iterable, Sequence
from dataclasses import dataclass, field
from model import profiles
BOOTS = "boots"
BIOS_ERROR = "bios_error"
CRASH = "crash"
@@ -51,7 +51,9 @@ UNKNOWN = "unknown"
FAILS = (BIOS_ERROR, CRASH, HANG)
REFUSED = "refused"
USED = "used"
CONTENT_CHECKS = ("md5", "sha1", "sha256", "crc32", "adler32", "signature")
HASH_CHECKS = ("md5", "sha1", "sha256", "crc32", "adler32", "signature")
# A check that judges a file by its content: a hash, or a test model.profiles runs.
CONTENT_CHECKS = frozenset(HASH_CHECKS) | profiles.CONTENT_CHECKS
# A field an entry leaves out reads as this value.
FIELD_DEFAULTS: dict[str, object] = {"hle_fallback": False, "path": None, "aliases": [],
@@ -230,7 +232,7 @@ def rule_validation(zeros: Run | None, half: Run | None, none: Run, present: Run
problems = []
if content is not None:
shown.append("checks the content" if content else "does not check the content")
if content != bool(enforced & set(CONTENT_CHECKS)):
if content != bool(enforced & CONTENT_CHECKS):
problems.append("a same-size file of zeros is " + ("refused" if content else "run")
+ f", the profile declares validation {said}")
missing_size = size is True and "size" not in declared
+9
View File
@@ -229,6 +229,15 @@ class RuleTable(unittest.TestCase):
self.assertEqual(rules.rule_validation(used, used, NONE_BOOTS, PRESENT, {"name": "b"}).rule,
"validation_agrees")
def test_a_content_test_agrees_with_refused_zeros(self) -> None:
"""LRPS2 reads the ROMDIR table of a PS2 BIOS (validation: [size, romdir]):
zeros of its size are refused, as the profile says."""
refused = run(rules.BIOS_ERROR)
for check in ("romdir", "masked_sha1"):
entry = {"name": "ps2-0230a-20080220.bin", "validation": ["size", check]}
verdict = rules.rule_validation(refused, refused, refused, PRESENT, entry)
self.assertEqual(verdict.rule, "validation_agrees", check)
def test_validation_contradicted_is_queued(self) -> None:
refused = run(rules.BIOS_ERROR)
used = run(rules.HANG)