Files
VoiceStudio/tests/test_build_script_stubs.py
debpalash 2e30b1bdf3 test: isolate ASR selection and GGUF build stubs from the host (#3549)
ASR selection tests pinned only some hardware predicates, so on an Apple
Silicon or Windows ROCm host `_auto_detect` answered from the real MPS or
HIP state. A shared `neutral_asr_host` fixture now starts every predicate
False (including the lazily imported Windows HIP checks, patched on the
canonical module) and releases the warm transcription engine around the
test; the whisper.cpp fixture and the auto-detect suites use it.

The GGUF build tests wrote CRLF stubs and a Windows-form PATH under Git
Bash, so the real git/cmake could run. A shared harness writes LF files,
sets PATH inside Bash and refuses to start the script unless each
declared tool resolves to its stub.

Inspired by #3549 by @Pates2004.
2026-11-09 17:31:57 +05:30

28 lines
1.4 KiB
Python

"""The stub-tool harness for the GGUF build tests proves which tools ran (#3549)."""
from build_script_stubs import WRONG_TOOL, run_bash, stage_build_script, write_lf
def test_a_missing_stub_is_refused_before_the_script_runs(tmp_path):
write_lf(tmp_path / "probe.sh", 'touch "$PWD/ran"\ngit --version\n')
result = run_bash(tmp_path, ["probe.sh"], tools={"cmake": "exit 0"}, expect=("git", "cmake"))
assert result.returncode == WRONG_TOOL, result.stdout + result.stderr
assert "mock git resolves to" in result.stderr
assert not (tmp_path / "ran").exists()
def test_declared_stubs_are_the_tools_the_script_invokes(tmp_path):
write_lf(tmp_path / "probe.sh", 'git clone x\ncmake --version\n')
log = tmp_path / "calls.log"
tools = {name: f'printf "{name} %s\\n" "$*" >> "$CALL_LOG"' for name in ("git", "cmake")}
result = run_bash(tmp_path, ["probe.sh"], tools=tools, env={"CALL_LOG": log.as_posix()})
assert result.returncode == 0, result.stdout + result.stderr
assert log.read_text(encoding="utf-8").splitlines() == ["git clone x", "cmake --version"]
def test_stubs_and_staged_scripts_use_lf_endings(tmp_path):
write_lf(tmp_path / "stub", "a\r\nb\r\n")
assert (tmp_path / "stub").read_bytes() == b"a\nb\n"
stage_build_script(tmp_path)
staged = list((tmp_path / "scripts").rglob("*.sh"))
assert staged and all(b"\r" not in path.read_bytes() for path in staged)