#!/usr/bin/env python3
"""Erforderlicher Phase-6-Abnahmesatz; keine Downloads oder Golden-Erzeugung."""
import argparse
import os
from pathlib import Path
import subprocess


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--vbdos-repo", type=Path, required=True,
                        help="lokaler cout/vbdos-Git-Bestand in der in foreign.rs fixierten Revision")
    args = parser.parse_args()
    env = dict(os.environ, TB_VBDOS_REPO=str(args.vbdos_repo.resolve()))
    root = Path(__file__).resolve().parents[2]
    commands = [
        ["cargo", "test", "--locked", "-p", "tb-cli", "--test", "foreign", "--",
         "--include-ignored", "--nocapture"],
        ["cargo", "test", "--locked", "--workspace"],
        ["cargo", "test", "--locked", "-p", "tb-cli", "--test", "inventar", "--",
         "--exact", "abdeckungsstand_wird_ausgewiesen", "--nocapture"],
        ["cargo", "fmt", "--all", "--", "--check"],
        ["cargo", "clippy", "--locked", "--workspace", "--all-targets", "--", "-D", "warnings"],
        ["cargo", "bench", "--locked", "-p", "tb-vm", "--bench", "compile", "--bench", "vm"],
    ]
    for command in commands:
        print("+ " + " ".join(command), flush=True)
        result = subprocess.run(command, cwd=root, env=env, check=False)
        if result.returncode:
            return result.returncode if result.returncode > 0 else 1
    print("Phase-6-Grundabnahme bestanden; native Ziel-/Releaseabnahme folgt in Changes 02–07.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
