Spaces:
Paused
Paused
Harden Docker manifest parsing
Browse files- validate_manifest.py +12 -3
validate_manifest.py
CHANGED
|
@@ -16,6 +16,13 @@ def _version_at_least(version: object, required: tuple[int, int, int]) -> bool:
|
|
| 16 |
return parts >= required
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def file_sha256(path: Path) -> str:
|
| 20 |
digest = hashlib.sha256()
|
| 21 |
with path.open("rb") as handle:
|
|
@@ -33,7 +40,8 @@ def validate_manifest(manifest_path: str | Path) -> tuple[bool, list[str]]:
|
|
| 33 |
return False, [f"manifest unreadable: {exc}"]
|
| 34 |
if manifest.get("project") != "Simam3D":
|
| 35 |
errors.append("project is not Simam3D")
|
| 36 |
-
|
|
|
|
| 37 |
errors.append("manifest schema is older than provenance-contract schema 3")
|
| 38 |
if manifest.get("status") == "failed":
|
| 39 |
required = {"run_id", "backend", "runtime", "stage", "error", "input_sha256"}
|
|
@@ -67,7 +75,7 @@ def validate_manifest(manifest_path: str | Path) -> tuple[bool, list[str]]:
|
|
| 67 |
if not isinstance(diversity, dict):
|
| 68 |
errors.append("metrics.input_diversity is missing")
|
| 69 |
else:
|
| 70 |
-
expected_views =
|
| 71 |
if diversity.get("input_view_count") != expected_views:
|
| 72 |
errors.append("input diversity view count does not match manifest view_count")
|
| 73 |
unique = diversity.get("unique_input_view_count")
|
|
@@ -116,7 +124,8 @@ def validate_manifest(manifest_path: str | Path) -> tuple[bool, list[str]]:
|
|
| 116 |
if claims.get("direct_gaussian_prediction") is True:
|
| 117 |
if gaussian_source != "da3_direct":
|
| 118 |
errors.append("direct Gaussian claim does not match gaussian_source")
|
| 119 |
-
|
|
|
|
| 120 |
errors.append("direct Gaussian claim has no exported Gaussian count")
|
| 121 |
if direct_gaussian_error:
|
| 122 |
errors.append("direct Gaussian claim cannot include an export error")
|
|
|
|
| 16 |
return parts >= required
|
| 17 |
|
| 18 |
|
| 19 |
+
def _safe_int(value: object, default: int | None = None) -> int | None:
|
| 20 |
+
try:
|
| 21 |
+
return int(value)
|
| 22 |
+
except (TypeError, ValueError, OverflowError):
|
| 23 |
+
return default
|
| 24 |
+
|
| 25 |
+
|
| 26 |
def file_sha256(path: Path) -> str:
|
| 27 |
digest = hashlib.sha256()
|
| 28 |
with path.open("rb") as handle:
|
|
|
|
| 40 |
return False, [f"manifest unreadable: {exc}"]
|
| 41 |
if manifest.get("project") != "Simam3D":
|
| 42 |
errors.append("project is not Simam3D")
|
| 43 |
+
schema_version = _safe_int(manifest.get("manifest_schema_version", 0), 0)
|
| 44 |
+
if schema_version < 3:
|
| 45 |
errors.append("manifest schema is older than provenance-contract schema 3")
|
| 46 |
if manifest.get("status") == "failed":
|
| 47 |
required = {"run_id", "backend", "runtime", "stage", "error", "input_sha256"}
|
|
|
|
| 75 |
if not isinstance(diversity, dict):
|
| 76 |
errors.append("metrics.input_diversity is missing")
|
| 77 |
else:
|
| 78 |
+
expected_views = _safe_int(manifest.get("view_count", -1), -1)
|
| 79 |
if diversity.get("input_view_count") != expected_views:
|
| 80 |
errors.append("input diversity view count does not match manifest view_count")
|
| 81 |
unique = diversity.get("unique_input_view_count")
|
|
|
|
| 124 |
if claims.get("direct_gaussian_prediction") is True:
|
| 125 |
if gaussian_source != "da3_direct":
|
| 126 |
errors.append("direct Gaussian claim does not match gaussian_source")
|
| 127 |
+
exported_count = _safe_int(metrics.get("direct_gaussian_exported_count", 0), 0)
|
| 128 |
+
if exported_count <= 0:
|
| 129 |
errors.append("direct Gaussian claim has no exported Gaussian count")
|
| 130 |
if direct_gaussian_error:
|
| 131 |
errors.append("direct Gaussian claim cannot include an export error")
|