testsAndMisc/docs/superpowers/evidence/transcribe-helpers-tests-2026-08-17.json
Krzysztof kuhy Rudnicki 7587cd9604 transcribe_helpers: cover 0% -> 100% before splitting
transcribe_helpers.py is 289 lines against the 250-line cap and was
completely untested. Tests land first, in their own commit, so the split
that follows is verified against tests that predate the seam.

Left at its current path rather than moved under python_pkg/: transcribe.sh
invokes it by path inside a dedicated ML venv, and transcribe_fw.py imports
two siblings by bare name, so the closure is five files (1236 lines), not
three. Tests go in linux_configuration/tests/ instead, whose conftest
already puts standalone script directories on sys.path - the same
arrangement the usage_report work used, and still collected by CI.

The ML dependencies are never installed in CI and the module reaches them
only through _try_import, so patching that one seam covers every probe in
both directions. An AST scan at every nesting level confirmed there is no
other path to them: the only direct numpy imports sit under TYPE_CHECKING.

41 tests, 100% line and branch. The last gap was the dispatch guard at
line 284, unreachable through the CLI because argparse's choices list and
the dispatch dict carry the same eight commands; covering it by admitting a
ninth choice also documents why the guard is there.

Split across four test files because a single module hit 291 lines - over
the cap this work exists to clear.

Verified: python-version prints 3.14, check-faster-whisper exits 7 with no
ML deps present, generate-wav writes a 96044-byte WAV; 243 tests pass in the
directory, up from 202 by exactly the 41 added.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
2026-08-17 13:29:07 +02:00

67 lines
4.8 KiB
JSON

{
"intent": "Cover transcribe_helpers.py from 0% to 100% line and branch, so the following split of the 289-line file is verified against tests written before the seam existed.",
"scope": [
"New: linux_configuration/tests/test_transcribe_{probes,model_ops,wav,helpers_cli}.py",
"linux_configuration/tests/conftest.py - added the tools/ dir to sys.path and two shared doubles as fixtures",
"Non-goal: any change to transcribe_helpers.py, which is byte-identical to HEAD",
"Non-goal: moving these files under python_pkg/"
],
"changes": [
"Added the tools/ directory to the existing _SCRIPT_DIRS list in conftest.py, the same mechanism already used for the usage_report bin/ modules.",
"Added 41 tests covering the dependency probes, the sine-WAV generator, model preparation, the CUDA probe, and all eight CLI subcommands with their exit codes.",
"Patched only at the _try_import seam, so no ML package is needed: the module reaches faster_whisper, torch, speechbrain, soundfile, ctranslate2 and huggingface_hub exclusively through it. Verified by an AST scan at every nesting level - the only direct numpy imports in the package sit under TYPE_CHECKING and never execute.",
"Shared doubles live in conftest.py as fixtures rather than an importable helper module: name-tests-test requires every .py under tests/ to be named test_*.py, and conftest is not importable by name.",
"Split the tests across four files rather than one, because a single module reached 291 lines - over the cap this work exists to clear."
],
"verification": [
{
"command": "git diff --stat -- .../tools/transcribe_helpers.py",
"result": "pass",
"evidence": "No change: this commit adds tests only."
},
{
"command": "pytest linux_configuration/tests/test_transcribe_*.py --cov=transcribe_helpers --cov-branch --cov-report=term-missing",
"result": "pass",
"evidence": "41 passed. transcribe_helpers.py: 118 statements, 0 missing, 26 branches, 0 partial, 100%. The last gap was the dispatch guard at line 284, unreachable through the CLI because argparse's choices list and the dispatch dict carry the same eight commands; it is covered by admitting a ninth choice, which also documents why the guard exists."
},
{
"command": "pytest linux_configuration/tests/test_transcribe_*.py (count across the test-file split)",
"result": "pass",
"evidence": "41 passed both before and after splitting the 291-line module into four, which is the discriminating check for a test-file split: a file outside the runner's glob would be silently uncollected."
},
{
"command": "python3 transcribe_helpers.py python-version && python3 transcribe_helpers.py check-faster-whisper",
"result": "pass",
"evidence": "Prints 3.14, then exits 7 with the offline-mode message - 7 being the code transcribe.sh branches on. Confirms the real entry point still works on a machine with no ML dependencies."
},
{
"command": "python3 transcribe_helpers.py generate-wav --file <scratch>/tone.wav",
"result": "pass",
"evidence": "Wrote a 96044-byte WAV, matching 16000 Hz x 3 s x 16-bit mono plus header."
},
{
"command": "pytest linux_configuration/tests/ -q",
"result": "pass",
"evidence": "243 passed, up from 202 by exactly the 41 tests added; no existing test was altered."
},
{
"command": "pre-commit run --files <changed files>",
"result": "pass",
"evidence": "All hooks pass. Fixed rather than suppressed: three FBT001 boolean-positional warnings became keyword-only parameters, an S108 hardcoded /tmp path became tmp_path, a mypy func-returns-value error from an append-inside-or expression became a named function, and three noqa: N802 comments were removed by exposing the third-party CamelCase name through __getattr__ instead of defining it."
},
{
"command": "bash ~/utils/scripts/check_file_length.sh --all",
"result": "pass",
"evidence": "35 files over cap, unchanged by this commit. New test files are 223/122/108/58 lines, all under 250."
}
],
"risks": [
"The tests stub every ML dependency, so they prove the control flow and the exit-code contract, not that faster_whisper itself behaves as expected. That is deliberate: the packages are absent in CI, and a real model download is not a unit test.",
"conftest.py now grows shared doubles alongside its sys.path bootstrap. Acceptable because name-tests-test forbids a helper module under tests/, and the alternative is duplicating the double in two files."
],
"rollback": [
"git revert the commit; the four test files and the conftest additions disappear together.",
"After rollback, confirm pytest linux_configuration/tests/ reports 202 passed and that transcribe_helpers.py is unchanged."
]
}