Files
NODEDC_MISSION_CORE/tests/test_simulation_location_library.py
T
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

90 lines
3.6 KiB
Python

"""One catalog and artifact identity for local driving and route planning."""
import hashlib
import pytest
from test_ai_polygon_realtime import realtime as _realtime
from k1link.simulation.ai_polygon.contracts import RunCreate
from k1link.simulation.ai_polygon.editor_cache import EditorCache
from k1link.simulation.ai_polygon.worlds import WorldStore
from k1link.simulation.projects import _world_manifest
realtime = _realtime
def project_fixture(tmp_path):
worlds = WorldStore(tmp_path)
store = worlds.projects.projects
project = store.create(
name="Synthetic scan",
scene_type="outdoor",
source_kind="archive",
files=[{"logical_path": "scan.zip", "byte_length": 8}],
)
pid = project["project_id"]
assets = []
for role, name, data in [
("stream-manifest", "streamed/lod-meta.json", b'{"version":1}'),
("collision-mesh", "collision/scene.glb", b"synthetic-mesh"),
]:
path = store.artifacts_root(pid) / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(data)
assets.append(
dict(
role=role,
logical_path=name,
media_type="application/octet-stream",
byte_length=len(data),
sha256=hashlib.sha256(data).hexdigest(),
)
)
project = store.complete(
pid, result={}, artifacts=assets, world_manifest=_world_manifest(pid, assets)
)
return worlds, project
def test_project_is_listed_once_and_reuses_full_streamed_sog(tmp_path):
worlds, project = project_fixture(tmp_path)
world = worlds.list()[0]
assert world["world_id"] == project["project_id"].replace("sim-", "aiworld-")
assert worlds.get(world["world_id"]) == world
cache = EditorCache(tmp_path, worlds)
row = cache.request(world["world_id"])
assert row["status"] == "ready"
assert row["local_scene"]["visual_url"].endswith("streamed/lod-meta.json")
assert cache.pending() is None # No Worker lease/converter required for an existing SOG.
assert not (cache.directory(row["key"]) / "scene.sog").exists()
assert cache.get(row["key"])["files"] == row["files"]
assert len(worlds.list()) == 1
def test_calibration_or_artifact_revision_invalidates_plan_identity(tmp_path):
worlds, project = project_fixture(tmp_path)
before = worlds.list()[0]
settings = project["viewer_settings"]
settings["visual"]["rotation_degrees"]["x"] = 90
worlds.projects.projects.update_viewer_settings(project["project_id"], settings)
after = worlds.get(before["world_id"])
assert before["sha256"] != after["sha256"]
assert EditorCache.identity(before) != EditorCache.identity(after)
with pytest.raises(FileNotFoundError):
worlds.get("../outside")
def test_project_requires_capable_worker_and_saved_task_before_gpu_reservation(tmp_path, realtime):
store, hello, active = realtime
store.finish(active["run_id"], hello.instance_id, "stopped", "")
worlds, _ = project_fixture(tmp_path)
# Select the project, independently of original PLY entries in the fixture.
world = next(w for w in worlds.list() if w.get("local_scene"))
request = RunCreate(world_id=world["world_id"], clock="realtime", start_paused=True)
with pytest.raises(RuntimeError, match="поддерживает SOG"):
store.start(request, "project-old-worker")
store.register(hello.model_copy(update={"scene_formats": ["gaussian-ply", "project-sog"]}))
with pytest.raises(ValueError, match="сохраните маршрут"):
store.start(request, "project-no-task")
assert store.active is None