"""Run local worker benchmarks from the packaged macOS app."""

from __future__ import annotations

import subprocess
from pathlib import Path

from hive_compute.app.runtime_bootstrap import ensure_worker_runtime, sanitized_runtime_env

CONFIG_PATH = Path("~/.ambient/config.yaml").expanduser()


def run_app_benchmark(*, report_to_coordinator: bool = True) -> subprocess.CompletedProcess[str]:
    """Run the standard benchmark suite in the app-managed worker runtime."""
    runtime = ensure_worker_runtime()
    command = runtime.cli_command("benchmark", "--config", str(CONFIG_PATH))
    if report_to_coordinator:
        command.append("--report-to-coordinator")
    return subprocess.run(
        command,
        check=True,
        capture_output=True,
        text=True,
        encoding="utf-8",
        errors="replace",
        env=sanitized_runtime_env(),
    )
