From 57e1bb89c3ff37a9de04c1565d508de6ef0dba91 Mon Sep 17 00:00:00 2001 From: whning Date: Sat, 31 Oct 2026 20:15:15 +0800 Subject: [PATCH] Require integer manifest schema versions --- artifactManifest/artifact_manifest.py | 2 +- artifactManifest/tests/test_artifact_manifest.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/artifactManifest/artifact_manifest.py b/artifactManifest/artifact_manifest.py index d9c5946..c529c33 100644 --- a/artifactManifest/artifact_manifest.py +++ b/artifactManifest/artifact_manifest.py @@ -217,7 +217,7 @@ def _load_expected(manifest_path: Path) -> dict[str, ManifestFile]: raise ManifestError(f"cannot read manifest {manifest_path}: {exc}") from exc if not isinstance(payload, dict): raise ManifestError("manifest must contain a JSON object") - if payload.get("schema_version") != SCHEMA_VERSION: + if type(payload.get("schema_version")) is not int or payload["schema_version"] != SCHEMA_VERSION: raise ManifestError( f"unsupported schema_version: {payload.get('schema_version')!r}" ) diff --git a/artifactManifest/tests/test_artifact_manifest.py b/artifactManifest/tests/test_artifact_manifest.py index ba28a53..f9cfc91 100644 --- a/artifactManifest/tests/test_artifact_manifest.py +++ b/artifactManifest/tests/test_artifact_manifest.py @@ -211,3 +211,13 @@ def test_invalid_utf8_manifest_reports_error_without_traceback(tmp_path: Path, c captured = capsys.readouterr() assert "cannot read manifest" in captured.err assert "Traceback" not in captured.err + + +@pytest.mark.parametrize("version", [True, 1.0, "1", None]) +def test_schema_version_requires_integer(tmp_path: Path, version: object) -> None: + root = tmp_path / "artifact" + root.mkdir() + manifest = tmp_path / "manifest.json" + manifest.write_text(json.dumps({"schema_version": version, "root": ".", "files": []}), encoding="utf-8") + with pytest.raises(artifact_manifest.ManifestError, match="unsupported schema_version"): + artifact_manifest.verify_manifest(root, manifest)