#!/usr/bin/env python3
"""Run only the Rust tests owned by the world-services milestone."""

from __future__ import annotations

import os
from pathlib import Path
import subprocess


ROOT = Path(__file__).resolve().parents[1]
COMPAT_TARGETS = (
    "appearance_live_semantics",
    "appearance_semantics",
    "appearance_visual_semantics",
    "archive_model_semantics",
    "asset_capability_semantics",
    "asset_document_semantics",
    "avatar_manager_shims",
    "current_outfit_folder_semantics",
    "current_outfit_policy_semantics",
    "inventory_ais_semantics",
    "inventory_live_semantics",
    "inventory_manager_semantics",
    "inventory_store_semantics",
    "marketplace_classifier_semantics",
    "marketplace_manager_semantics",
    "misclassified_link_semantics",
    "slurl_semantics",
    "social_constructor_semantics",
    "social_message_semantics",
    "task_inventory_semantics",
    "user_report_semantics",
    "wire_shims",
    "world_capability_semantics",
    "world_constructor_semantics",
    "world_live_semantics",
    "world_manager_shims",
    "world_message_semantics",
    "world_object_semantics",
    "world_packet_semantics",
)


def run(command: list[str]) -> None:
    print("+", " ".join(command), flush=True)
    subprocess.run(command, cwd=ROOT, env=ENV, check=True)


ENV = os.environ.copy()
ENV.setdefault("CARGO_BUILD_JOBS", "1")
ENV.setdefault("RUST_TEST_THREADS", "1")
ENV.pop("RUN_LIVE_TESTS", None)

run(["cargo", "test", "-p", "libremetaverse", "--lib", "--locked"])
run(
    [
        "cargo",
        "test",
        "-p",
        "libremetaverse",
        "--test",
        "network_manager",
        "offline_fake_grid_drives_the_complete_networking_lifecycle_without_task_leaks",
        "--locked",
    ]
)
compat = ["cargo", "test", "-p", "libremetaverse-compat-tests"]
for target in COMPAT_TARGETS:
    compat.extend(("--test", target))
compat.append("--locked")
run(compat)
