"""Synthetic protocol checks; these do not qualify rendering or AI model quality.""" import base64 import hashlib import io import json import numpy as np import pytest from fastapi import FastAPI from fastapi.testclient import TestClient from PIL import Image from pydantic import ValidationError from test_observatory_recorded_jobs import _definitions from k1link.observatory.recorded_jobs import ObservatoryRecordedJobQueue from k1link.simulation.ai_polygon.contracts import ( Decision, RunApplied, RunCreate, RunSample, WorkerHello, WorkerWorldCreate, WorldCreate, WorldSettings, ) from k1link.simulation.ai_polygon.policy import RoadPolicy from k1link.simulation.ai_polygon.runs import RunStore from k1link.simulation.ai_polygon.worlds import WorldStore, inspect_gaussian_ply from k1link.web.ai_polygon_api import build_ai_polygon_router def ply(value=0.0): names = [ "x", "y", "z", "opacity", "f_dc_0", "f_dc_1", "f_dc_2", "scale_0", "scale_1", "scale_2", "rot_0", "rot_1", "rot_2", "rot_3", ] header = "ply\nformat binary_little_endian 1.0\nelement vertex 1\n" header += "".join(f"property float {name}\n" for name in names) + "end_header\n" return header.encode() + np.full(14, value, dtype=" 0 and 0 < decision.speed_mps < 0.3 def test_progress_does_not_claim_camera_ready(runs): store, hello, world = runs run = store.start(RunCreate(world_id=world["world_id"]), "progress-case-001") store.progress(run["run_id"], hello.instance_id, "scene") assert store.get(run["run_id"])["phase"] == "scene" assert store.get(run["run_id"])["state"] == "starting" store.control(run["run_id"], "stop") assert store.progress(run["run_id"], hello.instance_id, "models")["control"] == "stop" assert store.get(run["run_id"])["state"] == "stopping" def test_worker_stop_race_accepts_already_exited_process(monkeypatch): import importlib.util from pathlib import Path runtime = Path(__file__).resolve().parents[1] / "simulation/ai-polygon" monkeypatch.syspath_prepend(str(runtime)) spec = importlib.util.spec_from_file_location("polygon_worker_stop_test", runtime / "worker.py") module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) calls = [] class Child: pid = 123 def poll(self): return None def wait(self, timeout): calls.append(("wait", timeout)) return 0 def taskkill(*args, **kwargs): # Windows reports a non-zero taskkill when the process exits in the race. assert kwargs["check"] is False calls.append(("taskkill", 255)) monkeypatch.setattr(module.subprocess, "run", taskkill) module.terminate_episode(Child()) assert calls == [("taskkill", 255), ("wait", 30)]