# tests/test_check_strict_adds_commands.py
from __future__ import annotations

from pathlib import Path

import oceansguard.cli as cli
from tests.conftest import read_json, write_aiguard_yml


def test_check_strict_adds_strict_commands(repo_ctx, ux, patch_checks_all_ok, monkeypatch):
    repo = repo_ctx.repo

    write_aiguard_yml(repo)

    # guard/dlp/openapi を素通り
    def fake_run_argv(argv, cwd, check=False, timeout=None):
        if argv[:2] == ["git", "diff"] and "--numstat" in argv:
            return cli.subprocess.CompletedProcess(argv, 0, stdout="", stderr="")
        if argv[:2] == ["git", "ls-files"]:
            return cli.subprocess.CompletedProcess(argv, 0, stdout="", stderr="")
        return cli.subprocess.CompletedProcess(argv, 0, stdout="", stderr="")

    monkeypatch.setattr(cli, "run_argv", fake_run_argv)

    cli.cmd_check(ux, repo, strict=True)

    report = read_json(repo / "ai_check_report.json")
    assert report["status"] == "pass"

    cmds = [c["command"] for c in report["checks"]]
    assert any("npm ci" in c or "npm install" in c for c in cmds)
    assert any("npm run build" in c for c in cmds)
