fix: check each built variant as verify-packs does

The build skipped conformance on every required-only, platform-only and
truth pack while --verify-packs held the same pack to its own variant,
so an --all-variants run passed packs the verifier could fail.
check_pack_conformance reads the variant from the pack name and both
paths call it; the finalizer is told the variants the run built.
baseline_shortfall moves beside the check, narrows_contents goes.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 21:42:19 +01:00
1 parent e0cbf35adc
commit 3df143cbe1
9 files changed
+181 -124

No files matched your search

+24 -39
View File
@@ -17,24 +17,14 @@ from core.options import reject_unknown
from model.registry import list_registered_platforms
from model.targets import load_target_config
from packs.archive import write_generated_member
from packs.integrity import verify_pack, verify_pack_against_platform
from packs.naming import expected_pack_names, narrows_contents, pack_archives
from packs.integrity import check_pack_conformance, verify_pack
from packs.naming import expected_pack_names, pack_archives
from packs.scope import annotate_pack_systems
if TYPE_CHECKING:
from typing_extensions import Unpack
def baseline_shortfall(excluded: int, absent: int) -> list[str]:
"""Why a verified pack holds fewer baseline files than the platform declares."""
parts = []
if excluded:
parts.append(f"{excluded} unsafe excluded")
if absent:
parts.append(f"{absent} not in the collection")
return parts
# Post-generation pack verification + manifest
@@ -94,6 +84,7 @@ class FinalizeOptions(TypedDict, total=False):
no_game_data: bool
pack_systems_by_name: dict[str, dict] | None
built: Iterable[str] | None
variants: tuple[tuple[str, bool], ...]
@dataclass(frozen=True)
@@ -109,23 +100,14 @@ class _FinalizeSettings:
no_game_data: bool = False
pack_systems_by_name: dict[str, dict] | None = None
built: Iterable[str] | None = None
variants: tuple[tuple[str, bool], ...] = (("full", False),)
def _conforms(zip_path: str, pname: str, db: dict, opts: _FinalizeSettings) -> bool:
"""Stage 2 for one platform of a pack: extract and verify against its
config. Prints the platform's line and its errors."""
(
p_ok,
_total,
_matched,
p_errors,
bl_checked,
bl_present,
core_checked,
core_present,
bl_excluded,
bl_absent,
) = verify_pack_against_platform(
config, under the variant the pack was built as. Prints the platform's
line and its errors."""
result = check_pack_conformance(
zip_path,
pname,
opts.platforms_dir,
@@ -136,19 +118,20 @@ def _conforms(zip_path: str, pname: str, db: dict, opts: _FinalizeSettings) -> b
target_cores=_target_cores_for(pname, opts.target_name, opts.platforms_dir),
no_game_data=opts.no_game_data,
)
status = "OK" if p_ok else "FAILED"
exclusion_note = "".join(
f", {part}" for part in baseline_shortfall(bl_excluded, bl_absent)
)
if result is None:
# One BIOS per slot: the slot choice is not replayed.
return True
status = "OK" if result.ok else "FAILED"
exclusion_note = "".join(f", {part}" for part in result.shortfall)
print(
f" platform {pname}: {bl_present}/{bl_checked} baseline present"
f" platform {pname}: {result.baseline_present}/{result.baseline_checked} baseline present"
f"{exclusion_note}, "
f"{core_present}/{core_checked} cores present, {status}"
f"{result.core_present}/{result.core_checked} cores present, {status}"
)
if not p_ok:
for err in p_errors:
if not result.ok:
for err in result.errors:
print(f" {err}")
return p_ok
return result.ok
def verify_and_finalize_packs(
@@ -166,6 +149,9 @@ def verify_and_finalize_packs(
reopened, recompressed and given a manifest without its pack_systems,
which made the installer refuse to narrow it. None takes every pack.
``variants`` lists the (source, required_only) combinations the run
built, so each narrowed pack is checked as --verify-packs checks it.
Two-stage verification:
1. Hash check against database.json (integrity)
2. Extract + verify against platform config (conformance)
@@ -183,7 +169,7 @@ def verify_and_finalize_packs(
registered = list_registered_platforms(opts.platforms_dir)
expected = expected_pack_names(
registered, opts.platforms_dir, opts.regions, opts.target_name,
no_game_data=opts.no_game_data,
opts.variants, no_game_data=opts.no_game_data,
)
packs = pack_archives(output_dir)
if opts.built is not None:
@@ -214,12 +200,11 @@ def verify_and_finalize_packs(
annotate_pack_systems(manifest, (opts.pack_systems_by_name or {}).get(name))
inject_manifest(zip_path, manifest)
# Stage 2: platform conformance (extract + verify)
# Skipped for filtered/split/custom packs (intentionally partial)
# Stage 2: platform conformance (extract + verify), each variant
# held to its own expectation. Skipped for split and system packs
# (intentionally partial).
if opts.skip_conformance:
continue
if narrows_contents(name):
continue
for pname in pack_to_platform.get(name, []):
if not _conforms(zip_path, pname, db, opts):
all_ok = False
+66 -3
View File
@@ -32,6 +32,7 @@ from model.profiles import load_emulator_profiles
from model.platforms import load_platform_config
import os
from packs.extras import platform_region_groups
from packs.naming import pack_variant
from packs.paths import flat_arcname
from resolve.nativemode import reads_file_contents
from resolve import regions as resolve_regions
@@ -596,16 +597,21 @@ def _same_content(zf: zipfile.ZipFile, member: str, local: str) -> bool:
return is_archive_path(local) and _same_members(zf, member, local)
class PlatformCheckOptions(TypedDict, total=False):
"""The keyword options of verify_pack_against_platform."""
class ConformanceOptions(TypedDict, total=False):
"""The keyword options of check_pack_conformance."""
emulators_dir: str
emu_profiles: dict | None
regions: list[str] | None
data_registry: dict | None
no_game_data: bool
class PlatformCheckOptions(ConformanceOptions, total=False):
"""The keyword options of verify_pack_against_platform."""
source: str
required_only: bool
no_game_data: bool
@dataclass(frozen=True)
@@ -1006,3 +1012,60 @@ def verify_pack_against_platform(
baseline.excluded,
baseline.absent,
)
def baseline_shortfall(excluded: int, absent: int) -> list[str]:
"""Why a verified pack holds fewer baseline files than the platform declares."""
parts = []
if excluded:
parts.append(f"{excluded} unsafe excluded")
if absent:
parts.append(f"{absent} not in the collection")
return parts
@dataclass(frozen=True)
class PackConformance:
"""A pack checked against one platform, as verify_pack_against_platform returns it."""
ok: bool
checked: int
present: int
errors: list[str]
baseline_checked: int
baseline_present: int
core_checked: int
core_present: int
baseline_excluded: int
baseline_absent: int
@property
def shortfall(self) -> list[str]:
"""Why the baseline holds fewer files than the platform declares."""
return baseline_shortfall(self.baseline_excluded, self.baseline_absent)
def check_pack_conformance(
zip_path: str,
platform_name: str,
platforms_dir: str,
db: dict | None = None,
*,
target_cores: set[str] | None = None,
**options: Unpack[ConformanceOptions],
) -> PackConformance | None:
"""A pack checked against its platform under the variant its name says.
The build and --verify-packs both read this, so a pack gets one verdict:
a required-only, platform-only or truth pack is held to its own
expectation, never skipped by one and failed by the other. None for a
one-per-slot pack, whose slot choice the check does not replay.
"""
variant = pack_variant(os.path.basename(zip_path))
if variant is None:
return None
source, required_only = variant
return PackConformance(*verify_pack_against_platform(
zip_path, platform_name, platforms_dir, db,
target_cores=target_cores, source=source, required_only=required_only, **options,
))
+3 -38
View File
@@ -261,48 +261,13 @@ def expected_pack_names(
return names
def _content_narrowing_tags() -> tuple[str, ...]:
"""Tags naming a pack that holds fewer files than the platform declares.
Read from the name builder rather than retyped, so the two cannot drift.
Region and target are absent on purpose: both are handed to the check
itself, which narrows its expectation instead of skipping it.
"""
# (source, one_per_slot, required_only), one dimension at a time.
dimensions = (
("platform", False, False),
("truth", False, False),
("full", True, False),
("full", False, True),
)
tags: list[str] = []
for source, one_per_slot, required_only in dimensions:
tags.extend(
tag
for tag, _label in pack_narrowings(source, None, None, one_per_slot, required_only)
)
return tuple(tags)
_CONTENT_NARROWING_TAGS = _content_narrowing_tags()
def narrows_contents(pack_name: str) -> bool:
"""True when a pack holds fewer files than the platform declares.
A source-restricted or required-only build is narrower by design, so the
full platform expectation does not apply to it and conformance is skipped.
Region is not listed: the region filter is passed to the check itself, and
a hardware target is passed the same way.
"""
return any(f"{tag}_" in pack_name for tag in _CONTENT_NARROWING_TAGS)
def pack_variant(pack_name: str) -> tuple[str, bool] | None:
"""The (source, required_only) a pack was built as, read from its name.
None for a one-per-slot pack, whose slot choice the check does not
replay. The tags come from the name builder, as for narrows_contents.
replay. The tags come from the name builder rather than retyped, so the
two cannot drift. Region and target are not variants: both are handed to
the check itself, which narrows its expectation instead of skipping it.
"""
def tagged(**dimension: object) -> bool:
tags = [
+17 -24
View File
@@ -12,9 +12,8 @@ from model.database import load_database
from model.profiles import load_emulator_profiles
from model.registry import list_release_pack_platforms, load_data_dir_registry
from model.targets import target_scope
from packs.finalize import baseline_shortfall
from packs.integrity import verify_pack_against_platform
from packs.naming import expected_pack_names, pack_variant
from packs.integrity import check_pack_conformance
from packs.naming import expected_pack_names
from packs.variants import ALL_VARIANTS
@@ -56,16 +55,7 @@ def _check_pack(
tc: set[str] | None,
) -> list[str] | None:
"""Check one pack and print its line. Its errors, or None when it passed."""
variant = pack_variant(pack_name)
if variant is None:
# One BIOS per slot: the slot choice is not replayed here.
print(
f" {platform_name} [{pack_name}]: hashes checked during the build; "
"one per slot by design, so not compared to the platform's full list"
)
return None
source, required_only = variant
result = verify_pack_against_platform(
result = check_pack_conformance(
zip_path,
platform_name,
check.platforms_dir,
@@ -75,28 +65,31 @@ def _check_pack(
regions=check.regions,
data_registry=check.data_registry,
target_cores=tc,
source=source,
required_only=required_only,
no_game_data=check.no_game_data,
)
(ok, _checked, _present, errors, bl_checked, bl_present,
core_checked, core_present, bl_excluded, bl_absent) = result
if result is None:
# One BIOS per slot: the slot choice is not replayed here.
print(
f" {platform_name} [{pack_name}]: hashes checked during the build; "
"one per slot by design, so not compared to the platform's full list"
)
return None
# These explain a baseline short of its total: a dump whose hash
# the frontend refuses is left out on purpose, and a file the
# collection does not hold cannot be packed (verify reports it).
shortfall = ", ".join(baseline_shortfall(bl_excluded, bl_absent))
shortfall = ", ".join(result.shortfall)
excluded = f" ({shortfall})" if shortfall else ""
counts = (
f"{bl_present}/{bl_checked} baseline{excluded}, "
f"{core_present}/{core_checked} cores"
f"{result.baseline_present}/{result.baseline_checked} baseline{excluded}, "
f"{result.core_present}/{result.core_checked} cores"
)
if ok:
if result.ok:
print(f" {platform_name} [{pack_name}]: OK ({counts})")
return None
print(f" {platform_name} [{pack_name}]: FAIL ({counts}, {len(errors)} errors)")
for err in errors:
print(f" {platform_name} [{pack_name}]: FAIL ({counts}, {len(result.errors)} errors)")
for err in result.errors:
print(f" {err}")
return errors
return result.errors
def run_verify_packs(args: argparse.Namespace) -> bool:
+1
View File
@@ -234,6 +234,7 @@ def finalize_platform_packs(
regions=getattr(args, "regions", None),
target_name=args.target,
no_game_data=getattr(args, "no_game_data", False),
variants=run_variants(args),
)
if args.split:
for entry in os.listdir(args.output_dir):