fix: report pack manifests skipped, not valid

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 02:19:13 +01:00
1 parent 02c33be3b5
commit 2f804a26ce
4 files changed
+61 -24

No files matched your search

+6 -12
View File
@@ -3,12 +3,11 @@
from __future__ import annotations
import json
import sys
import zipfile
from pathlib import Path, PurePosixPath
import core.paths
from core.artifacts import ArtifactLockBusy, artifact_lock
from core.artifacts import artifact_lock
from schemas.validators import schema_errors, schema_validator
@@ -22,20 +21,15 @@ def validate_pack_manifests(dist: Path) -> list[str]:
Reading a pack while a build is writing it reports "File is not a zip
file" about an archive that is merely half-written, so this takes the same
shared lock --verify-packs does. A build holding the exclusive lock means
the packs on disk are mid-flight and there is nothing stable to validate.
the packs on disk are mid-flight and there is nothing stable to validate:
ArtifactLockBusy reaches the caller, which reports the skip. An empty
list would read as packs that validated.
"""
if not dist.is_dir():
return []
try:
with artifact_lock(str(dist), exclusive=False):
return _scan_pack_manifests(dist)
except ArtifactLockBusy:
print(
f"note: {dist.name} is being written, skipping pack manifests",
file=sys.stderr,
)
return []
with artifact_lock(str(dist), exclusive=False):
return _scan_pack_manifests(dist)
def _scan_pack_manifests(dist: Path) -> list[str]:
+23 -7
View File
@@ -2,7 +2,10 @@
from __future__ import annotations
from dataclasses import dataclass, field
import core.paths
from core.artifacts import ArtifactLockBusy
from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
from schemas.documents import (
semantic_database_checks,
@@ -48,7 +51,16 @@ def source_errors() -> list[str]:
return errors
def generated_errors() -> list[str]:
@dataclass
class Validation:
"""The errors of a run and the checks it could not make."""
errors: list[str] = field(default_factory=list)
# Each check skipped, by the reason the command reports.
skipped: list[str] = field(default_factory=list)
def generated_errors(run: Validation) -> None:
"""The generated artifacts: database, install lists, site data and packs."""
root = core.paths.REPO_ROOT
errors = validate_json_files(
@@ -87,8 +99,12 @@ def generated_errors() -> list[str]:
errors.extend(_site_api_errors())
errors.extend(games_index_errors())
errors.extend(validate_pack_manifests(root / "dist"))
return errors
dist = root / "dist"
try:
errors.extend(validate_pack_manifests(dist))
except ArtifactLockBusy:
run.skipped.append(f"pack manifests skipped, {dist.name} in use")
run.errors.extend(errors)
def _site_api_errors() -> list[str]:
@@ -120,10 +136,10 @@ def _site_api_errors() -> list[str]:
return errors
def validation_errors(source_only: bool) -> list[str]:
def validate(source_only: bool) -> Validation:
"""Every error of a run: the sources, then the generated artifacts unless
``source_only``."""
errors = source_errors()
run = Validation(source_errors())
if not source_only:
errors.extend(generated_errors())
return errors
generated_errors(run)
return run
+11 -5
View File
@@ -16,7 +16,7 @@ except ImportError:
raise
sys.exit('Error: jsonschema required (pip install "jsonschema[format-nongpl]")')
from schemas.run import validation_errors
from schemas.run import validate
def main() -> int:
@@ -28,12 +28,18 @@ def main() -> int:
)
args = parser.parse_args()
errors = validation_errors(args.source_only)
if errors:
for error in errors:
run = validate(args.source_only)
for skipped in run.skipped:
print(f"note: {skipped}", file=sys.stderr)
if run.errors:
for error in run.errors:
print(f"ERROR {error}")
print(f"{len(errors)} schema or semantic error(s)")
print(f"{len(run.errors)} schema or semantic error(s)")
return 1
if run.skipped:
print("Every schema and semantic invariant checked is valid: "
+ ", ".join(run.skipped) + ".")
return 0
print("All RetroBIOS schemas and semantic invariants are valid.")
return 0
+21
View File
@@ -2193,6 +2193,27 @@ class InstallerBoundaryRegressions(unittest.TestCase):
self.assertTrue(errors, "an invalid in-archive manifest must be reported")
self.assertTrue(any("sha1" in message for message in errors), errors)
@unittest.skipUnless(HAS_JSONSCHEMA, "validating a schema needs jsonschema")
def test_packs_being_written_are_a_skip_not_a_pass(self):
"""Under a build's lock the reader returned [], the value of packs
that validated, and validate_schemas announced everything valid
without reading one."""
from core.artifacts import ArtifactLockBusy, artifact_lock
from schemas import packmanifests, run
with tempfile.TemporaryDirectory() as directory:
dist = Path(directory) / "dist"
dist.mkdir()
(dist / "Bad_BIOS_Pack.zip").write_bytes(b"not a zip")
self.assertTrue(packmanifests.validate_pack_manifests(dist))
with artifact_lock(str(dist), exclusive=True):
with self.assertRaises(ArtifactLockBusy):
packmanifests.validate_pack_manifests(dist)
outcome = run.Validation()
with mock.patch.object(run.core.paths, "REPO_ROOT", Path(directory)):
run.generated_errors(outcome)
self.assertEqual(outcome.skipped, ["pack manifests skipped, dist in use"])
@unittest.skipUnless(HAS_JSONSCHEMA, "validating a schema needs jsonschema")
def test_a_pack_carries_its_install_list_and_board_lists(self):
"""pack_systems puts the install list and the per-board core lists