Include selected source LOD in Worker scene package

This commit is contained in:
DCCONSTRUCTIONS
2026-10-09 22:28:06 +03:00
parent 37d6f90456
commit be5cc98d5c
3 changed files with 30 additions and 6 deletions
+10 -2
View File
@@ -23,6 +23,13 @@ def digest(path):
return hashlib.file_digest(stream, "sha256").hexdigest()
def project_members(package, lod):
required = {package["visual_path"], package["collision_path"]}
return [item for item in package["artifacts"] if (
item["logical_path"] in required or
item["logical_path"].startswith((f"streamed/{lod}_", "streamed/env/")))]
def prepare_project(client, run, state, episode, job, pulse, isaac, *, lod=0):
if type(lod) is not int or not 0 <= lod <= 6:
raise ValueError("Invalid source LOD")
@@ -31,6 +38,7 @@ def prepare_project(client, run, state, episode, job, pulse, isaac, *, lod=0):
if package["world_sha256"] != world["sha256"]:
raise ValueError("Project changed after mission admission")
pid, provider_job = package["project_id"], package["provider_job_id"]
members = project_members(package, lod)
if not re.fullmatch(r"sim-[a-f0-9]{32}", pid) or not re.fullmatch(
r"gsp-[0-9]{14}-[a-f0-9]{8}", provider_job
):
@@ -40,14 +48,14 @@ def prepare_project(client, run, state, episode, job, pulse, isaac, *, lod=0):
root.mkdir(parents=True, exist_ok=True)
required = sum(
item["byte_length"]
for item in package["artifacts"]
for item in members
if not (root / item["logical_path"]).is_file()
)
if shutil.disk_usage(root).free < required + 4 * 1024**3:
raise RuntimeError("Недостаточно места на Worker для подготовки локации.")
# A filesystem package is needed by the stock streamed-SOG reader. Reuse
# local verified bytes without re-encoding. Keep an owned immutable copy for the run.
for item in package["artifacts"]:
for item in members:
name = item["logical_path"]
if (
not re.fullmatch(r"[A-Za-z0-9_. /-]+", name)
@@ -83,10 +83,7 @@ class ProjectWorlds:
artifacts = [
a
for a in project["artifacts"]
if (
a["logical_path"].startswith("streamed/0_")
or a["logical_path"].startswith("streamed/env/")
)
if a["logical_path"].startswith("streamed/")
or a["logical_path"] in paths.values()
]
return {
+19
View File
@@ -72,3 +72,22 @@ def test_paired_import_checks_actual_files_and_never_fetches_from_operator(tmp_p
preparer.prepare_terrain(root, tmp_path, {**world, "collider_sha256": "f" * 64})
with pytest.raises(ValueError, match="identity"):
importer.stage(root, source, collider, {**descriptor, "collider_sha256": "f" * 64})
def test_project_package_supports_each_published_lod_without_cropping(monkeypatch):
from types import SimpleNamespace
from k1link.simulation.ai_polygon.project_worlds import ProjectWorlds
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
module = importlib.import_module("project_assets")
paths = ["streamed/lod-meta.json", "collision.glb", "streamed/env/meta.json",
"streamed/0_0/meta.json", "streamed/1_0/meta.json", "streamed/1_0/means_l.webp",
"streamed/2_0/meta.json", "private/source.zip"]
project = dict(project_id="sim-test", provider={"job_id":"gsp-test"},
artifacts=[dict(logical_path=name) for name in paths])
worlds = object.__new__(ProjectWorlds)
worlds.projects = SimpleNamespace(get=lambda _: project)
prefix = "/api/v1/simulation-worlds/projects/sim-test/artifacts/"
package = worlds.package(dict(storage={"project_id":"sim-test"}, sha256="test",
local_scene=dict(visual_url=prefix+paths[0], collision_url=prefix+paths[1])))
assert [item["logical_path"] for item in package["artifacts"]] == paths[:-1]
assert [item["logical_path"] for item in module.project_members(package, 1)] == paths[:3]+paths[4:6]