Preflight asset pack media files
这个提交存在于:
父节点
6752df16bc
当前提交
a6063759b8
共有 2 个文件被更改,包括 55 次插入 和 3 次删除
|
|
@ -190,7 +190,7 @@ def _manifest_summary(package_path: Path, candidates: list[dict[str, Any]]) -> d
|
|||
"errors": [{"code": "MANIFEST_NOT_OBJECT", "message": "asset pack manifest must be a JSON object"}],
|
||||
}
|
||||
|
||||
errors = _manifest_entry_errors(payload)
|
||||
errors = _manifest_entry_errors(payload, package_path=package_path, manifest_path=selected["path"])
|
||||
return {
|
||||
"present": True,
|
||||
"valid": not errors,
|
||||
|
|
@ -210,7 +210,7 @@ def _load_manifest_payload(path: Path) -> dict[str, Any]:
|
|||
return payload
|
||||
|
||||
|
||||
def _manifest_entry_errors(payload: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
def _manifest_entry_errors(payload: dict[str, Any], *, package_path: Path, manifest_path: Path) -> list[dict[str, Any]]:
|
||||
errors: list[dict[str, Any]] = []
|
||||
materials = payload.get("materials")
|
||||
if materials is not None and not isinstance(materials, list):
|
||||
|
|
@ -233,7 +233,8 @@ def _manifest_entry_errors(payload: dict[str, Any]) -> list[dict[str, Any]]:
|
|||
}
|
||||
)
|
||||
continue
|
||||
if not _optional_text(item.get("image_uri") or item.get("uri") or item.get("image") or item.get("file")):
|
||||
image_value = _optional_text(item.get("image_uri") or item.get("uri") or item.get("image") or item.get("file"))
|
||||
if not image_value:
|
||||
errors.append(
|
||||
{
|
||||
"code": "MATERIAL_IMAGE_MISSING",
|
||||
|
|
@ -241,9 +242,38 @@ def _manifest_entry_errors(payload: dict[str, Any]) -> list[dict[str, Any]]:
|
|||
"field": f"{field}.image_uri",
|
||||
}
|
||||
)
|
||||
elif _is_missing_relative_asset(image_value, package_path, manifest_path):
|
||||
errors.append(
|
||||
{
|
||||
"code": "MATERIAL_FILE_MISSING",
|
||||
"message": "asset pack material image file was not found",
|
||||
"field": f"{field}.image_uri",
|
||||
}
|
||||
)
|
||||
thumbnail_value = _optional_text(item.get("thumbnail_uri") or item.get("thumbnail"))
|
||||
if thumbnail_value and _is_missing_relative_asset(thumbnail_value, package_path, manifest_path):
|
||||
errors.append(
|
||||
{
|
||||
"code": "MATERIAL_THUMBNAIL_MISSING",
|
||||
"message": "asset pack material thumbnail file was not found",
|
||||
"field": f"{field}.thumbnail_uri",
|
||||
}
|
||||
)
|
||||
return errors
|
||||
|
||||
|
||||
def _is_missing_relative_asset(value: str, package_path: Path, manifest_path: Path) -> bool:
|
||||
if value.startswith("storage://"):
|
||||
return False
|
||||
base_path = package_path if package_path.is_dir() else manifest_path.parent
|
||||
candidate = (base_path / value).resolve()
|
||||
try:
|
||||
candidate.relative_to(base_path.resolve())
|
||||
except ValueError:
|
||||
return True
|
||||
return not candidate.is_file()
|
||||
|
||||
|
||||
def _material_payload_from_manifest_item(
|
||||
item: dict[str, Any],
|
||||
*,
|
||||
|
|
|
|||
|
|
@ -812,6 +812,28 @@ database:
|
|||
self.assertFalse(missing_image_execution["ok"])
|
||||
self.assertEqual(missing_image_execution["error_code"], "VALIDATION_FAILED")
|
||||
|
||||
missing_file_pack = self.root / "materials" / "missing-file-pack"
|
||||
missing_file_pack.mkdir(parents=True, exist_ok=True)
|
||||
(missing_file_pack / "manifest.json").write_text(
|
||||
'{"name":"missing file","materials":[{"name":"hat","image":"missing.png"}]}',
|
||||
encoding="utf-8",
|
||||
)
|
||||
missing_file = import_asset_pack(
|
||||
self.ctx,
|
||||
{"package_uri": "storage://materials/missing-file-pack", "dry_run": True},
|
||||
self.asset_import_service,
|
||||
)
|
||||
self.assertTrue(missing_file["ok"])
|
||||
self.assertFalse(missing_file["data"]["manifest"]["valid"])
|
||||
self.assertEqual(missing_file["data"]["manifest"]["errors"][0]["code"], "MATERIAL_FILE_MISSING")
|
||||
missing_file_execution = import_asset_pack(
|
||||
self.ctx,
|
||||
{"package_uri": "storage://materials/missing-file-pack", "dry_run": False},
|
||||
self.asset_import_service,
|
||||
)
|
||||
self.assertFalse(missing_file_execution["ok"])
|
||||
self.assertEqual(missing_file_execution["error_code"], "VALIDATION_FAILED")
|
||||
|
||||
def test_media_signing_rejects_unsafe_or_missing_uri(self):
|
||||
unsafe = sign_media(
|
||||
self.ctx,
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用