Harden YOLO compatibility preflight
This commit is contained in:
@@ -30,6 +30,13 @@ def test_readiness_gate_compiles_demo_cleanup_script() -> None:
|
||||
assert "-m py_compile backend/scripts/cleanup_demo_artifacts.py" in content
|
||||
|
||||
|
||||
def test_readiness_gate_compiles_yolo_preflight_script() -> None:
|
||||
script = Path(__file__).resolve().parents[2] / "scripts" / "run_readiness_check.sh"
|
||||
content = script.read_text(encoding="utf-8")
|
||||
|
||||
assert "-m py_compile scripts/yolo_preflight.py" in content
|
||||
|
||||
|
||||
def test_demo_export_workflow_script_verifies_export_endpoints() -> None:
|
||||
script = Path(__file__).resolve().parents[2] / "scripts" / "verify_demo_export_workflow.sh"
|
||||
content = script.read_text(encoding="utf-8")
|
||||
|
||||
@@ -17,6 +17,12 @@ class AvailableAdapter:
|
||||
def dependencies_available() -> bool:
|
||||
return True
|
||||
|
||||
def __init__(self, settings: Settings) -> None:
|
||||
self.settings = settings
|
||||
|
||||
def load_model(self, model_path: Path) -> object:
|
||||
return {"model_path": str(model_path)}
|
||||
|
||||
|
||||
class MissingDependencyAdapter:
|
||||
@staticmethod
|
||||
@@ -24,6 +30,11 @@ class MissingDependencyAdapter:
|
||||
return False
|
||||
|
||||
|
||||
class FailingLoadAdapter(AvailableAdapter):
|
||||
def load_model(self, model_path: Path) -> object:
|
||||
raise RuntimeError(f"cannot load {model_path}")
|
||||
|
||||
|
||||
def _manifest(tmp_path: Path, tile_count: int = 1) -> Path:
|
||||
tiles = []
|
||||
for index in range(tile_count):
|
||||
@@ -93,6 +104,41 @@ def test_yolo_preflight_validates_model_and_manifest_without_importing_yolo(tmp_
|
||||
assert result["will_run_inference"] is False
|
||||
|
||||
|
||||
def test_yolo_preflight_can_explicitly_smoke_load_local_model(tmp_path: Path) -> None:
|
||||
model_path = tmp_path / "model.pt"
|
||||
model_path.write_bytes(b"weights")
|
||||
manifest_path = _manifest(tmp_path)
|
||||
|
||||
result = YoloPreflightService.run(
|
||||
settings=Settings(yolo_enabled=True, yolo_model_path=str(model_path), yolo_max_tiles=4),
|
||||
tile_manifest_path=str(manifest_path),
|
||||
yolo_adapter_class=AvailableAdapter,
|
||||
check_model_load=True,
|
||||
)
|
||||
|
||||
assert result["status"] == "ready"
|
||||
assert result["checks"]["model_load_requested"] is True
|
||||
assert result["checks"]["model_load_ok"] is True
|
||||
assert result["will_download_models"] is False
|
||||
assert result["will_run_inference"] is False
|
||||
|
||||
|
||||
def test_yolo_preflight_reports_explicit_model_load_failure(tmp_path: Path) -> None:
|
||||
model_path = tmp_path / "model.pt"
|
||||
model_path.write_bytes(b"weights")
|
||||
|
||||
result = YoloPreflightService.run(
|
||||
settings=Settings(yolo_enabled=True, yolo_model_path=str(model_path), yolo_max_tiles=4),
|
||||
tile_manifest_path=str(_manifest(tmp_path)),
|
||||
yolo_adapter_class=FailingLoadAdapter,
|
||||
check_model_load=True,
|
||||
)
|
||||
|
||||
assert result["status"] == "model_load_failed"
|
||||
assert result["error_code"] == "DETECTION_MODEL_LOAD_FAILED"
|
||||
assert result["checks"]["model_load_ok"] is False
|
||||
|
||||
|
||||
def test_yolo_preflight_script_outputs_json(tmp_path: Path) -> None:
|
||||
model_path = tmp_path / "model.pt"
|
||||
model_path.write_bytes(b"weights")
|
||||
@@ -119,3 +165,24 @@ def test_yolo_preflight_script_outputs_json(tmp_path: Path) -> None:
|
||||
assert payload["status"] == "ready"
|
||||
assert payload["model_path"] == str(model_path)
|
||||
assert payload["tile_manifest_path"] == str(manifest_path)
|
||||
|
||||
|
||||
def test_yolo_preflight_script_rejects_assumed_dependencies_for_model_load(tmp_path: Path) -> None:
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(ROOT / "scripts" / "yolo_preflight.py"),
|
||||
"--model-path",
|
||||
str(tmp_path / "model.pt"),
|
||||
"--assume-dependencies",
|
||||
"--check-model-load",
|
||||
"--json",
|
||||
],
|
||||
cwd=ROOT,
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
assert result.returncode != 0
|
||||
assert "--check-model-load cannot be combined with --assume-dependencies" in result.stderr
|
||||
|
||||
Reference in New Issue
Block a user