from __future__ import annotations

import sys
from pathlib import Path


def test_driver_entrypoint_missing_cmd_returns_2(monkeypatch, tmp_path: Path):
    from argus.ray.driver_entrypoint import main

    monkeypatch.setattr(sys, "argv", ["x", "--job-dir", str(tmp_path)])
    assert main() == 2


def test_driver_entrypoint_strips_double_dash_and_returns_code(monkeypatch, tmp_path: Path):
    from argus.ray import driver_entrypoint as mod

    class _Proc:
        returncode = 7

    monkeypatch.setattr(mod.subprocess, "run", lambda cmd, check: _Proc())
    got = {}
    monkeypatch.setattr(mod.os, "chdir", lambda p: got.update({"cwd": str(p)}))
    monkeypatch.setattr(sys, "argv", ["x", "--job-dir", str(tmp_path), "--", "echo", "hi"])

    assert mod.main() == 7
    assert (tmp_path).exists()
    assert got["cwd"] == str(tmp_path)
