Compare commits

...

4 Commits

Author SHA1 Message Date
d277369aca Cover clean_audio_filters.sh (89.25%), completing testsAndMisc-bash/lib
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
A 38-assertion suite for the last lib in the directory without one. Every
one of its five libs now has a suite; at the start of the session it had
none. 118 assertions across the directory, 0 failures.

build_filters is asserted on the EXACT filter string it emits, because that
string is the lib's entire product. An arnndn chain missing its mandatory
48 kHz resample, or a preset silently falling through to no dynamics, yields
worse audio and never an error -- nothing else would catch it.

Every exit code is pinned: 1 for a missing command, 11 for "RNNoise required
but unavailable" (refusing to quietly fall back to afftdn), 8 for an ffmpeg
whose afftdn lacks md=.

Measured 83/93 = 89.25%; it stays on the allowlist. All ten uncovered lines
are the documented under-report, not gaps: an `exit 66` sentinel proves
require_cmd's lines 37-38 execute, 52-58 are a multi-line array literal (the
confirmed continuation-line artifact), and 129 is an empty `*) ;;` arm whose
branch has a passing assertion. The gate uses the measured figure, so the
exemption stands regardless.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016sxxsDHWgdRhmdmzNMA6XM
2026-08-22 13:27:44 +02:00
154b416617 Clear transcribe_venv.sh: 100%, off the allowlist, 104 -> 103
A 29-assertion suite covering all six functions. transcribe_venv.sh measures
53/53 = 100.00% through the directory runner, and check_shell_coverage.sh
passes it with the exemption deleted.

Assertions are on recorded ARGV because which index a pip install points at
IS the behaviour: the OpenNMT cu12 wheel index on the NVIDIA path, the
CPU-only torch index for diarization (forced to avoid mismatched CUDA
builds). "pip was called" cannot see either.

generate_test_audio's four-deep fallback chain is covered by failing each
generator in turn. Every stub materialises the wav, because the chain
advances on `[[ ! -s $tmpwav ]]` -- a record-only stub would silently
exercise the branch after the one under test.

One assertion was wrong and got corrected rather than forced: I claimed a
wholly-failing pip still returns 0, but the final `python "$PY_HELPERS"
deps-installed` carries no `|| log`, so it does not. The suite now asserts
what the subject actually guarantees -- all four warnings emitted, no earlier
failure aborting the run.

SC2016 fixed at the source with a quoted heredoc, not suppressed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016sxxsDHWgdRhmdmzNMA6XM
2026-08-22 13:24:28 +02:00
b91be3099d Clear unity_handler.sh: 100%, off the allowlist, 105 -> 104
The first allowlist removal of the campaign this session. unity_handler.sh
measures 32/32 = 100.00% through its directory's runner, and
check_shell_coverage.sh passes it with the exemption DELETED -- the real
gate, not just the measurement.

HARNESS BUG found getting there: bash caches executable locations in a hash
table, so `command -v foo` keeps succeeding after foo is removed from the
stub dir. Every "tool is missing" test was therefore running as a "tool is
present" test, asserting the opposite of its own name while looking
plausible. Reproduced minimally: after rm, STILL FOUND; after `hash -r`,
gone.

A _t_unstub helper now removes the stub and clears the table. The two suites
committed an hour ago had the same defect and are corrected here --
test_transcribe_pkgmgr.sh goes from 15 to 18 passing assertions, so three of
its checks had been vacuous. This is exactly the failure the campaign exists
to catch, found in its own test code.

`basename` joins the restricted PATH because the SUBJECT calls it; the suite
avoids needing `tail` via a parameter expansion instead, since every binary
in that PATH is one more thing a stub's shebang can trip over.

transcribe_deps.sh (92.31%) and transcribe_pkgmgr.sh (98.00%) re-measured
unchanged and stay on the allowlist.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016sxxsDHWgdRhmdmzNMA6XM
2026-08-22 13:20:54 +02:00
ac1cf57656 Give testsAndMisc-bash/lib a harness; cover transcribe_deps and _pkgmgr
The directory held five allowlisted libs and no tests. It now has a harness,
a runner, and suites for two libs: transcribe_deps.sh (the fourth
hardest-first target, 48/52 = 92.31%) and transcribe_pkgmgr.sh (49/50 =
98.00%). Both stay on the allowlist. 15 + 18 assertions, 0 failures.

No jail is needed here and no jail_args marker is created: every branch turns
on `command -v <manager>` and every install goes through sudo, both
intercepted by a PATH stub dir. Verified the runner exits 0 when invoked
bare, which is how both gates call it.

The harness REPLACES PATH rather than prepending. This host really has
pacman, and a prepended stub dir cannot HIDE a binary, so every "manager not
installed" case would have asserted nothing. `bash` and `env` are in the
private coreutils dir for a non-obvious reason: every stub's
`#!/usr/bin/env bash` shebang resolves through that restricted PATH, and
without them each stub died with "env: 'bash': No such file or directory"
while looking exactly like a coverage gap.

Assertions are on recorded ARGV rather than on the call happening, because
which packages a branch installs is what differs between distros --
pacman gets python-virtualenv where apt gets python3-venv.

Three assertions aimed at the libsndfile branch were REMOVED rather than left
green-but-vacuous: /usr/lib/libsndfile.so exists on this host, so
need_libsndfile is legitimately 0 and lines 19/52/53/55 are unreachable
without a jail that hides the library. The limitation is written into the
suite instead of asserted around.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016sxxsDHWgdRhmdmzNMA6XM
2026-08-22 13:14:02 +02:00
14 changed files with 1199 additions and 2 deletions

View File

@ -0,0 +1,20 @@
{
"title": "Give testsAndMisc-bash/lib a test harness and cover its two package-manager libs",
"objective": "Create the first tests/run_all.sh for linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib -- a directory holding five allowlisted libs and no tests -- and use it to cover transcribe_deps.sh (the fourth hardest-first target) and transcribe_pkgmgr.sh.",
"acceptance_criteria": [
"tests/run_all.sh exists and exits 0 when invoked BARE, because no jail_args marker is created and both ci_mirror.sh and shell-tests.yml therefore run it directly.",
"Every assertion passes: test_transcribe_deps.sh and test_transcribe_pkgmgr.sh both report 0 failed.",
"Each package-manager branch is asserted on its RECORDED ARGV, not merely on the manager being called -- pacman must be shown asking for python-virtualenv where apt asks for python3-venv.",
"The 'not installed' cases genuinely hide the binary: PATH is replaced, not prepended, since this host really has pacman.",
"Coverage of both libs is measured through run_all.sh, the subject is_covered() builds, and reported as the measured figure.",
"Both libs remain on the allowlist unless they measure 100%.",
"No assertion is left in place that cannot fail on this host; an unreachable branch is documented rather than asserted vacuously.",
"shellcheck clean on every new file with no suppressions, and all files within the 250-line cap."
],
"out_of_scope": [
"The other three libs in the directory (clean_audio_filters.sh, transcribe_venv.sh, unity_handler.sh) -- they inherit the harness but are not covered here.",
"Any change to transcribe_deps.sh or transcribe_pkgmgr.sh; no latent bug surfaced in either.",
"Making the directory jail-only in order to hide /usr/lib/libsndfile.so and reach the four libsndfile lines."
],
"verifier": "bash .../testsAndMisc-bash/lib/tests/run_all.sh (expects 15 + 18 assertions, 0 failed, exit 0), plus meta/scripts/shell_coverage_jail.sh --subject that runner --measure each lib --fail-on-case-error, plus shellcheck on the four new files and meta/scripts/check_file_length.sh --all."
}

View File

@ -0,0 +1,19 @@
{
"title": "Take unity_handler.sh off the shell-coverage allowlist at a measured 100%",
"objective": "Cover unity_handler.sh to 100% through its directory's runner and remove it from meta/shell-coverage-allowlist.txt -- the campaign's first removal this session -- while fixing the bash hash-cache defect that had made 'missing tool' assertions in the same directory vacuous.",
"acceptance_criteria": [
"unity_handler.sh measures 100.00% through tests/run_all.sh, the subject is_covered() builds, with --fail-on-case-error passing.",
"check_shell_coverage.sh passes for unity_handler.sh AFTER the allowlist entry is deleted -- the real gate, not just the measurement.",
"meta/shell-coverage-allowlist.txt drops from 105 to 104 entries and no entry is ever added.",
"Every 'tool is missing' assertion genuinely hides the tool: removal must clear bash's command hash table, or the assertion tests the opposite of its name.",
"The two suites committed earlier in the same directory are corrected for the same defect, and their assertion counts are re-verified rather than assumed.",
"The other two libs' measured figures are unchanged by the harness edit.",
"All three suites pass with 0 failures; shellcheck clean with no suppressions; all files within the 250-line cap."
],
"out_of_scope": [
"clean_audio_filters.sh and transcribe_venv.sh, the two libs in this directory still without suites.",
"Auditing every other suite in the repo for the same bare-`rm` unstub defect; it is recorded as a risk for a later sweep.",
"Any change to unity_handler.sh itself."
],
"verifier": "meta/scripts/shell_coverage_jail.sh --subject .../testsAndMisc-bash/lib/tests/run_all.sh --measure unity_handler.sh --min 100 --fail-on-case-error (expects 32/32 = 100.00%, exit 0), then bash meta/scripts/check_shell_coverage.sh on that path with the allowlist entry removed (expects exit 0), plus .../tests/run_all.sh reporting 15 + 18 + 18 assertions and 0 failures."
}

View File

@ -0,0 +1,45 @@
{
"intent": "Cover clean_audio_filters.sh, the last lib in testsAndMisc-bash/lib without a suite. It stays on the allowlist at a measured 89.25%: every uncovered line is a kcov under-report, but the measured figure is what the gate uses and it is below the bar.",
"scope": [
".../testsAndMisc-bash/lib/tests/test_clean_audio_filters.sh: new, 38 assertions across all 7 functions",
".../tests/transcribe_harness.sh: dirname, find and sort added to the restricted PATH",
"Non-goal: no change to the subject; no latent bug surfaced",
"Non-goal: removing it from the allowlist -- 89.25% is below the 100% bar"
],
"changes": [
"build_filters is asserted on the EXACT filter string it emits, because that string is the lib's entire product. An arnndn chain missing its mandatory 48 kHz resample, or a preset silently falling through to no dynamics, produces worse audio and never an error -- there is nothing else to catch it.",
"Every exit code the lib defines is pinned: 1 for a missing command, 11 for 'RNNoise required but unavailable' (refusing to quietly fall back to afftdn), 8 for an ffmpeg whose afftdn lacks md=.",
"All four presets are covered including the unrecognised one, plus arnndn vs afftdn, --no-advanced, the optional lowpass, both output codecs, the skip-unless-forced guard, and run_dir in serial, parallel and no-wait-n modes.",
"This completes the directory: all five of its libs now have suites, where at the start of the session it had none."
],
"verification": [
{
"command": ".../lib/tests/run_all.sh",
"result": "pass",
"evidence": "15 + 38 + 18 + 29 + 18 = 118 assertions, 0 failures across all five suites."
},
{
"command": "shell_coverage_jail.sh --subject .../tests/run_all.sh --measure clean_audio_filters.sh --min 1 --fail-on-case-error",
"result": "pass",
"evidence": "clean_audio_filters.sh: 83/93 lines = 89.25%, uncovered 37, 38, 52-58, 129. The measured figure; the lib stays allowlisted."
},
{
"command": "temporarily append `exit 66` after the require_cmd assertions, run under --fail-on-case-error",
"result": "pass",
"evidence": "'case exited 66' fired, proving lines 37-38 execute despite reporting zero hits. Lines 52-58 are a multi-line array literal -- the CONFIRMED continuation-line artifact -- and 129 is an empty `*) ;;` case arm whose branch is asserted and passing. All 10 are under-reports, not gaps."
},
{
"command": "shellcheck on the new suite",
"result": "pass",
"evidence": "clean on the first run; no suppressions added."
}
],
"risks": [
"89.25% understates the real coverage by an unknown margin, so the lib sits on the allowlist for an instrument reason rather than a testing one. Conservative direction only: the defect can keep a lib exempt, never promote an untested one.",
"The restricted PATH grew again (dirname, find, sort). Each addition is a real subject dependency, but the list is now long enough that a missing entry surfaces as 'command not found' mid-suite rather than as a clear assertion failure."
],
"rollback": [
"git revert the commit; the lib loses its suite and stays allowlisted, and the harness loses three PATH entries the other suites do not need.",
"After rollback, re-run the directory's run_all.sh to confirm the other four suites still pass with the shorter PATH."
]
}

View File

@ -0,0 +1,53 @@
{
"intent": "Give the testsAndMisc-bash/lib directory its first test harness and cover transcribe_deps.sh (score 50, the fourth hardest-first target) plus transcribe_pkgmgr.sh alongside it. Both stay on the allowlist: 92.31% and 98.00%, below the 100% bar.",
"scope": [
"linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/tests/transcribe_harness.sh: new shared fixture",
".../tests/run_all.sh: new runner, deliberately WITHOUT a jail_args marker",
".../tests/test_transcribe_deps.sh: new, 15 assertions",
".../tests/test_transcribe_pkgmgr.sh: new, 18 assertions",
"Non-goal: the other three libs in the directory (clean_audio_filters, transcribe_venv, unity_handler) -- the harness they need now exists",
"Non-goal: no change to either subject; no latent bug surfaced"
],
"changes": [
"These suites need NO jail: every branch turns on `command -v <manager>` and every install goes through sudo, both intercepted by a PATH stub dir. No jail_args file is created, so ci_mirror.sh and shell-tests.yml both run this runner bare -- verified, exit 0.",
"The harness REPLACES PATH rather than prepending to it. This host really has pacman, and a prepended stub dir cannot HIDE a binary, so every 'manager not installed' case would silently assert nothing. A private symlink dir supplies the coreutils the suites themselves need.",
"`bash` and `env` are in that dir for a non-obvious reason: every stub carries a `#!/usr/bin/env bash` shebang resolved through the restricted PATH. Without them each stub died with \"env: 'bash': No such file or directory\" and the branch it stood in for was silently never taken -- a failure that looked like a coverage gap.",
"Assertions are on RECORDED ARGV, not on the call happening: which packages a branch installs is what differs between distros (pacman gets python-virtualenv where apt gets python3-venv) and is exactly what a presence test cannot see.",
"ensure_cuda_runtime calls `exit 6` when cuBLAS is still missing. Called at top level that exits the SUITE, so each branch assertion runs in a subshell."
],
"verification": [
{
"command": ".../lib/tests/run_all.sh",
"result": "pass",
"evidence": "test_transcribe_deps.sh: 15 passed, 0 failed; test_transcribe_pkgmgr.sh: 18 passed, 0 failed; 'All transcribe lib test files passed.' Bare runner exit=0, which is how both gates invoke it."
},
{
"command": "shell_coverage_jail.sh --subject .../tests/run_all.sh --measure transcribe_deps.sh --min 1 --fail-on-case-error",
"result": "pass",
"evidence": "transcribe_deps.sh: 48/52 = 92.31%, uncovered 19, 52, 53, 55. Measured through run_all.sh, the subject is_covered() builds."
},
{
"command": "same, --measure transcribe_pkgmgr.sh",
"result": "pass",
"evidence": "transcribe_pkgmgr.sh: 49/50 = 98.00%, uncovered 42. A second lib covered by the same harness."
},
{
"command": "ls -la /usr/lib/libsndfile.so",
"result": "pass",
"evidence": "The symlink exists on this host, so need_libsndfile is legitimately 0 and lines 19/52/53/55 are unreachable here. Three assertions that appeared to test this branch were REMOVED rather than left green-but-vacuous, and the limitation is written into the suite."
},
{
"command": "shellcheck on all four new files",
"result": "pass",
"evidence": "clean; no suppressions added. A malformed `# shellcheck source=... -- comment` directive was rewritten rather than deleted."
}
],
"risks": [
"The libsndfile branch cannot be reached on a host that has the library. Covering it needs a jail that hides /usr/lib/libsndfile.so, which would mean adding a jail_args marker and making the whole directory jail-only for one branch. Deferred deliberately; the cost is 4 lines of the 52.",
"The restricted PATH must list every binary the suites use. A future assertion invoking an unlisted tool fails with 'command not found' rather than a clear assertion failure -- the bash/env case above cost real time to diagnose."
],
"rollback": [
"git revert the commit; the directory loses its harness and all five of its libs stay allowlisted with no tests.",
"After rollback, confirm no tests/run_all.sh remains under testsAndMisc-bash/lib, so the gate's view of the directory is unchanged."
]
}

View File

@ -0,0 +1,44 @@
{
"intent": "Cover transcribe_venv.sh to a measured 100% and take it off the allowlist -- the second removal this session, 104 -> 103.",
"scope": [
".../testsAndMisc-bash/lib/tests/test_transcribe_venv.sh: new, 29 assertions across all 6 functions",
"meta/shell-coverage-allowlist.txt: transcribe_venv.sh removed",
"Non-goal: no change to the subject; no latent bug surfaced"
],
"changes": [
"Assertions are on RECORDED ARGV because which index a pip install points at IS the behaviour here: the OpenNMT cu12 wheel index on the NVIDIA path, and the CPU-only torch index for diarization (forced to avoid mismatched CUDA builds). A 'pip was called' check cannot see either.",
"generate_test_audio's four-deep fallback chain (espeak-ng -> espeak -> Python stdlib -> ffmpeg) is covered by failing each generator in turn. Each stub MATERIALISES the wav, because the chain advances on `[[ ! -s $tmpwav ]]` -- a record-only stub would silently exercise the next branch instead of the one under test.",
"The four `|| log \"Warning: ...\"` pip-failure paths are covered with a python stub that always exits 1. An initial assertion that the function still returns 0 was WRONG and was corrected rather than forced: the final `python \"$PY_HELPERS\" deps-installed` has no `|| log`, so a wholly-failing python does make it return non-zero. The suite now asserts what the subject actually guarantees -- all four warnings are emitted and no earlier failure aborts the run.",
"SC2016 was fixed at the source by switching the failing-pip stub to a quoted heredoc, not suppressed."
],
"verification": [
{
"command": "shell_coverage_jail.sh --subject .../tests/run_all.sh --measure transcribe_venv.sh --min 100 --fail-on-case-error",
"result": "pass",
"evidence": "transcribe_venv.sh: 53/53 lines = 100.00%, exit 0 at --min 100."
},
{
"command": "bash meta/scripts/check_shell_coverage.sh .../transcribe_venv.sh (AFTER removing the allowlist entry)",
"result": "pass",
"evidence": "'every checked shell library meets the coverage bar'. The real gate accepts it with no exemption."
},
{
"command": ".../lib/tests/run_all.sh",
"result": "pass",
"evidence": "15 + 18 + 29 + 18 = 80 assertions, 0 failures across all four suites in the directory."
},
{
"command": "shellcheck on the new suite",
"result": "pass",
"evidence": "clean; no suppressions added."
}
],
"risks": [
"The suite stubs python/python3 heavily. If the subject later stops routing work through $PY_HELPERS the stubs would keep passing while testing nothing -- the assertions are on argv, so a changed argv fails loudly, but a REMOVED call would not.",
"generate_test_audio's chain depends on each stub writing a non-empty file. A future stub that forgets to would move the test to a different branch than its name claims, the same failure mode this suite exists to avoid."
],
"rollback": [
"git revert the commit; transcribe_venv.sh returns to the allowlist and loses its suite.",
"After rollback, confirm the allowlist is back to 104 entries."
]
}

View File

@ -0,0 +1,51 @@
{
"intent": "Cover unity_handler.sh to a measured 100% and take it OFF the shell-coverage allowlist -- the first entry removed this session, 105 -> 104. Fix the bash hash-cache bug found doing it, which had silently weakened the two suites committed just before.",
"scope": [
".../testsAndMisc-bash/lib/tests/test_unity_handler.sh: new, 18 assertions across all 4 functions",
".../tests/transcribe_harness.sh: new _t_unstub helper; basename added to the restricted PATH",
".../tests/test_transcribe_deps.sh and test_transcribe_pkgmgr.sh: switched to _t_unstub",
"meta/shell-coverage-allowlist.txt: unity_handler.sh removed",
"Non-goal: no change to any subject; no latent bug surfaced in unity_handler.sh"
],
"changes": [
"HARNESS BUG, found by an assertion that would not go green: bash caches executable locations in a hash table, so `command -v foo` keeps SUCCEEDING after foo is deleted from the stub dir. Every 'tool is missing' test therefore ran as a 'tool is present' test -- asserting the opposite of its own name while looking plausible. Reproduced minimally: after `rm`, STILL FOUND; after `hash -r`, gone.",
"The fix is a _t_unstub helper that removes the stub and clears the table, applied to all three suites in the directory. The two committed an hour earlier were affected and are corrected here; test_transcribe_pkgmgr.sh goes 15 -> 18 passing assertions as a result, so three of its checks had been vacuous.",
"`basename` was added to the restricted PATH because the SUBJECT calls it, unlike bash/env which the stubs' shebangs need. The suite avoids needing `tail` by taking the last line with a parameter expansion instead: every binary in that PATH is another thing a shebang can trip over.",
"The generated .desktop file is asserted on its CONTENT (Exec and MimeType lines), and xdg-mime registration on the BASENAME it is given -- a full path there would silently fail to register."
],
"verification": [
{
"command": "shell_coverage_jail.sh --subject .../tests/run_all.sh --measure unity_handler.sh --min 100 --fail-on-case-error",
"result": "pass",
"evidence": "unity_handler.sh: 32/32 lines = 100.00%, exit 0 at --min 100. Measured through run_all.sh, the subject is_covered() builds."
},
{
"command": "bash meta/scripts/check_shell_coverage.sh .../unity_handler.sh (AFTER removing it from the allowlist)",
"result": "pass",
"evidence": "'every checked shell library meets the coverage bar', exit 0. The lib passes the REAL gate with no exemption -- properly cleared, not merely measured."
},
{
"command": ".../lib/tests/run_all.sh",
"result": "pass",
"evidence": "15 + 18 + 18 = 51 assertions, 0 failures, 'All transcribe lib test files passed.'"
},
{
"command": "minimal repro of the hash cache: stub a command, run it, rm it, then command -v",
"result": "pass",
"evidence": "'STILL FOUND (hash cache)' before `hash -r`, 'gone after hash -r'. This is what makes _t_unstub necessary rather than cosmetic."
},
{
"command": "re-measure the other two libs after the harness change",
"result": "pass",
"evidence": "transcribe_deps.sh 48/52 = 92.31% and transcribe_pkgmgr.sh 49/50 = 98.00%, both unchanged. Both stay on the allowlist."
}
],
"risks": [
"Any other suite in the repo that removes a stub with a bare `rm` has the same latent defect: its 'missing tool' branch is not being tested. The features/lib suites use a jail and mostly add rather than remove stubs, but this is worth a sweep before the gate is armed.",
"The restricted PATH must list every binary the subjects use. A missing one surfaces as 'command not found' mid-suite rather than as a clear assertion failure."
],
"rollback": [
"git revert the commit; unity_handler.sh returns to the allowlist and the three suites return to bare `rm` unstubbing.",
"After rollback, confirm the allowlist is back to 105 entries so the gate's view is unchanged."
]
}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
# lib/tests/run_all.sh — run every transcribe lib test in one process tree.
#
# Also the subject handed to shell_coverage_jail.sh when measuring coverage of
# a lib in this directory: coverage is only complete across the whole suite.
#
# No jail_args file sits beside this runner, and that is deliberate: these
# suites intercept every package manager and sudo call with a PATH stub dir,
# so they touch nothing outside their own mktemp -d. Both ci_mirror.sh and
# the shell-tests workflow therefore run this runner directly.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
failed=0
for test_script in "${SCRIPT_DIR}"/test_*.sh; do
printf '\n### %s\n' "$(basename "$test_script")"
if ! "$test_script"; then
failed=$((failed + 1))
fi
done
if [[ $failed -gt 0 ]]; then
printf '\n%d test file(s) FAILED\n' "$failed"
exit 1
fi
printf '\nAll transcribe lib test files passed.\n'

View File

@ -0,0 +1,213 @@
#!/usr/bin/env bash
# Tests for clean_audio_filters.sh — the ffmpeg filter chain for clean_audio.sh.
#
# No jail: the only writes go under $OUT_DIR, pointed at a throwaway dir, and
# ffmpeg is intercepted by the harness's PATH stub dir.
#
# build_filters is asserted on the EXACT filter string it emits. That string
# is the entire product of this lib -- an arnndn chain missing its 48 kHz
# resample, or a preset silently falling through to no dynamics, is a bug that
# only shows up as worse audio, never as an error.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./transcribe_harness.sh
. "$SCRIPT_DIR/transcribe_harness.sh"
_t_setup_env
trap _t_teardown EXIT
# Globals the entry script sets before calling in.
HIGHPASS=80
AFFTDN_NF=-25
AFFTDN_MD=17
LOWPASS=""
PRESET="asr"
SUFFIX="_clean"
OUT_EXT="wav"
OUT_DIR=""
FORCE=false
JOBS=1
RN_MODEL=""
REQUIRE_ML=false
NO_ADVANCED=false
FFMPEG_BIN="ffmpeg"
FFMPEG_LOG=(-hide_banner)
FFMPEG_OVERWRITE=()
use_arnndn=false
afftdn_supports_md=true
supports_wait_n=true
# shellcheck source=../clean_audio_filters.sh
. "$TRANSCRIBE_LIB_DIR/clean_audio_filters.sh"
# --- print_usage ------------------------------------------------------------
usage_out="$(print_usage)"
_t_has "$usage_out" '--allow-fallback' "the usage text documents --allow-fallback"
_t_has "$usage_out" 'asr (default) | podcast | aggressive' "the usage text lists every preset"
# --- require_cmd ------------------------------------------------------------
_t_stub ffmpeg
require_rc=0
require_cmd ffmpeg || require_rc=$?
_t_eq "0" "$require_rc" "require_cmd accepts a command on PATH"
missing_rc=0
(require_cmd definitely-not-a-real-binary) >/dev/null 2>&1 || missing_rc=$?
_t_eq "1" "$missing_rc" "require_cmd exits 1 for a command that is absent"
# --- find_default_rn_model: the env override wins ---------------------------
: >"$TEST_TMPDIR/override.rnnn"
_t_eq "$TEST_TMPDIR/override.rnnn" "$(RNNOISE_MODEL="$TEST_TMPDIR/override.rnnn" find_default_rn_model)" \
"RNNOISE_MODEL overrides the search when the file exists"
# --- find_default_rn_model: .rnnn is preferred over .nn ---------------------
mkdir -p "$TEST_TMPDIR/models"
: >"$TEST_TMPDIR/models/legacy.nn"
: >"$TEST_TMPDIR/models/modern.rnnn"
_t_eq "$TEST_TMPDIR/models/modern.rnnn" "$(SCRIPT_DIR="$TEST_TMPDIR" find_default_rn_model)" \
"a .rnnn model is preferred over a legacy .nn"
# --- find_default_rn_model: nothing found -----------------------------------
rm -f "$TEST_TMPDIR/models/legacy.nn" "$TEST_TMPDIR/models/modern.rnnn"
none_rc=0
(SCRIPT_DIR="$TEST_TMPDIR/empty" find_default_rn_model) >/dev/null 2>&1 || none_rc=$?
_t_eq "1" "$none_rc" "find_default_rn_model returns 1 when no model exists anywhere"
# --- build_filters: the default afftdn chain --------------------------------
default_af="$(build_filters)"
_t_has "$default_af" 'highpass=f=80' "the chain starts with the configured highpass"
_t_has "$default_af" 'afftdn=nf=-25:md=17' "afftdn carries both nf and md when md is supported"
_t_has "$default_af" 'alimiter=limit=0.94' "the asr preset adds a limiter and no dynamics"
_t_has "$default_af" 'aresample=16000' "the chain resamples to 16 kHz for ASR"
_t_has "$default_af" 'aformat=channel_layouts=mono:sample_fmts=s16' "the chain ends mono s16"
_t_lacks "$default_af" 'loudnorm' "the asr preset does not apply loudness normalisation"
# --- build_filters: arnndn replaces afftdn ----------------------------------
arnndn_af="$(
use_arnndn=true
RN_MODEL="$TEST_TMPDIR/m.rnnn"
build_filters
)"
_t_has "$arnndn_af" 'aresample=48000' "arnndn is preceded by the 48 kHz resample it requires"
_t_has "$arnndn_af" "arnndn=m=$TEST_TMPDIR/m.rnnn:mix=1.0" "the arnndn filter carries the model path"
_t_lacks "$arnndn_af" 'afftdn' "afftdn is not applied when arnndn is in use"
# --- build_filters: --no-advanced drops md ----------------------------------
plain_af="$(
NO_ADVANCED=true
build_filters
)"
_t_has "$plain_af" 'afftdn=nf=-25' "no-advanced still denoises"
_t_lacks "$plain_af" 'md=' "no-advanced omits the md parameter"
# --- build_filters: REQUIRE_ML refuses to fall back -------------------------
require_ml_rc=0
(
REQUIRE_ML=true
build_filters
) >/dev/null 2>&1 || require_ml_rc=$?
_t_eq "11" "$require_ml_rc" "requiring RNNoise exits 11 rather than silently using afftdn"
# --- build_filters: an ffmpeg without md support aborts ---------------------
no_md_rc=0
(
afftdn_supports_md=false
build_filters
) >/dev/null 2>&1 || no_md_rc=$?
_t_eq "8" "$no_md_rc" "an ffmpeg lacking afftdn md= exits 8 with an upgrade hint"
# --- build_filters: the optional lowpass ------------------------------------
_t_has "$(
LOWPASS=8000
build_filters
)" 'lowpass=f=8000' "a configured lowpass is inserted"
# --- build_filters: the podcast and aggressive presets ----------------------
podcast_af="$(
PRESET=podcast
build_filters
)"
_t_has "$podcast_af" 'dynaudnorm=f=500:g=5:p=0.1' "the podcast preset applies gentle dynamics"
_t_has "$podcast_af" 'loudnorm=i=-18:lra=9:tp=-2.0' "the podcast preset normalises loudness"
aggressive_af="$(
PRESET=aggressive
build_filters
)"
_t_has "$aggressive_af" 'agate=threshold=0.012:ratio=2.5:release=200' "the aggressive preset gates"
_t_has "$aggressive_af" 'dynaudnorm=f=400:g=7:p=0.1' "the aggressive preset uses its own dynaudnorm"
# --- build_filters: an unknown preset adds nothing --------------------------
unknown_af="$(
PRESET=nonsense
build_filters
)"
_t_lacks "$unknown_af" 'alimiter' "an unrecognised preset adds no preset filters"
_t_has "$unknown_af" 'aresample=16000' "an unrecognised preset still gets the ASR tail"
# --- make_out_path_for_file -------------------------------------------------
_t_eq "$TEST_TMPDIR/audio_clean.wav" "$(make_out_path_for_file "$TEST_TMPDIR/audio.mp3")" \
"the output lands beside the input when no out-dir is set"
_t_eq "$TEST_TMPDIR/out/audio_clean.wav" "$(
OUT_DIR="$TEST_TMPDIR/out"
make_out_path_for_file "$TEST_TMPDIR/audio.mp3"
)" "an out-dir redirects the output path"
# --- process_one ------------------------------------------------------------
: >"$TEST_TMPDIR/in.wav"
_t_reset_calls
process_one "$TEST_TMPDIR/in.wav" >/dev/null
_t_has "$(_t_calls)" '-c:a pcm_s16le' "a wav output selects the PCM codec"
flac_calls="$(
OUT_EXT=flac
_t_reset_calls
process_one "$TEST_TMPDIR/in.wav" >/dev/null
_t_calls
)"
_t_has "$flac_calls" '-c:a flac' "a flac output selects the flac codec"
# --- process_one: an existing output is skipped unless forced ---------------
: >"$TEST_TMPDIR/in_clean.wav"
skip_out="$(process_one "$TEST_TMPDIR/in.wav")"
_t_has "$skip_out" 'Skip (exists)' "an existing output is skipped when FORCE is false"
forced_out="$(
FORCE=true
process_one "$TEST_TMPDIR/in.wav"
)"
_t_has "$forced_out" 'Cleaning:' "FORCE=true reprocesses an existing output"
# --- run_dir ----------------------------------------------------------------
mkdir -p "$TEST_TMPDIR/empty_dir"
_t_has "$(run_dir "$TEST_TMPDIR/empty_dir")" 'No audio files found' \
"an empty directory is reported rather than silently doing nothing"
mkdir -p "$TEST_TMPDIR/audio_dir"
: >"$TEST_TMPDIR/audio_dir/one.wav"
: >"$TEST_TMPDIR/audio_dir/two.MP3"
dir_out="$(
OUT_DIR="$TEST_TMPDIR/dir_out"
run_dir "$TEST_TMPDIR/audio_dir"
)"
_t_has "$dir_out" 'one.wav' "run_dir processes a .wav"
_t_has "$dir_out" 'two.MP3' "run_dir matches extensions case-insensitively"
# --- run_dir: parallel mode -------------------------------------------------
parallel_out="$(
OUT_DIR="$TEST_TMPDIR/par_out"
JOBS=2
run_dir "$TEST_TMPDIR/audio_dir"
)"
_t_has "$parallel_out" 'Cleaning:' "run_dir still processes files with JOBS=2"
serial_out="$(
OUT_DIR="$TEST_TMPDIR/ser_out"
JOBS=2
supports_wait_n=false
run_dir "$TEST_TMPDIR/audio_dir"
)"
_t_has "$serial_out" 'Cleaning:' "an ffmpeg without wait -n falls back to serial processing"
_t_report "test_clean_audio_filters.sh"

View File

@ -0,0 +1,121 @@
#!/usr/bin/env bash
# Tests for transcribe_deps.sh — the system-dependency install phase.
#
# No jail: every branch turns on `command -v` and every install goes through
# sudo, both intercepted by the harness's PATH stub dir. The assertions are on
# RECORDED ARGV, because WHICH packages each distro branch would install is
# the part that actually differs between them and the part a presence test
# cannot see -- pacman gets python-virtualenv where apt gets python3-venv.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./transcribe_harness.sh
. "$SCRIPT_DIR/transcribe_harness.sh"
_t_setup_env
trap _t_teardown EXIT
# Globals the entry script defines above its source line.
OFFLINE=0
FW_DIARIZE=0
# detect_pkg_mgr lives next door and is what selects the branch below.
# shellcheck source=../transcribe_pkgmgr.sh
. "$TRANSCRIBE_LIB_DIR/transcribe_pkgmgr.sh"
# shellcheck source=../transcribe_deps.sh
. "$TRANSCRIBE_LIB_DIR/transcribe_deps.sh"
# A pass-through sudo, so the package-manager stub records the real argv.
printf '#!/usr/bin/env bash\nexec "$@"\n' >"$TEST_TMPDIR/bin/sudo"
chmod +x "$TEST_TMPDIR/bin/sudo"
# --- everything already present is a no-op ----------------------------------
_t_stub ffmpeg
_t_stub espeak-ng
_t_reset_calls
present_out="$(install_system_deps 2>&1)"
_t_has "$present_out" 'System deps present' "install_system_deps reports a satisfied system"
_t_lacks "$(_t_calls)" 'pacman' "nothing is installed when ffmpeg and espeak-ng are both present"
# --- offline with a missing dep exits 5 -------------------------------------
_t_unstub ffmpeg
offline_rc=0
(
OFFLINE=1
install_system_deps
) >/dev/null 2>&1 || offline_rc=$?
_t_eq "5" "$offline_rc" "a missing dep in offline mode exits 5"
# --- no sudo means the install is skipped, not failed -----------------------
_t_unstub sudo
_t_stub pacman
no_sudo_out="$(install_system_deps 2>&1)"
_t_has "$no_sudo_out" 'sudo not found' "a missing sudo skips the install instead of failing"
printf '#!/usr/bin/env bash\nexec "$@"\n' >"$TEST_TMPDIR/bin/sudo"
chmod +x "$TEST_TMPDIR/bin/sudo"
# --- the pacman branch uses Arch package names ------------------------------
_t_reset_calls
install_system_deps >/dev/null 2>&1
pac_calls="$(_t_calls)"
_t_has "$pac_calls" 'python-virtualenv' "the pacman branch asks for python-virtualenv, not python3-venv"
_t_has "$pac_calls" 'ffmpeg' "the pacman branch installs the missing ffmpeg"
_t_lacks "$pac_calls" 'espeak-ng' "the pacman branch omits espeak-ng, which is already present"
# --- the apt branch uses Debian package names and refreshes first -----------
_t_unstub pacman
_t_stub apt-get
_t_reset_calls
install_system_deps >/dev/null 2>&1
apt_calls="$(_t_calls)"
_t_has "$apt_calls" 'apt-get update -y' "the apt branch refreshes the package list first"
_t_has "$apt_calls" 'python3-venv' "the apt branch asks for python3-venv, not python-virtualenv"
# --- the dnf branch ---------------------------------------------------------
_t_unstub apt-get
_t_stub dnf
_t_reset_calls
install_system_deps >/dev/null 2>&1
_t_has "$(_t_calls)" 'dnf install -y python3-venv' "the dnf branch installs python3-venv"
# --- the yum branch ---------------------------------------------------------
_t_unstub dnf
_t_stub yum
_t_reset_calls
install_system_deps >/dev/null 2>&1
_t_has "$(_t_calls)" 'yum install -y python3-venv' "the yum branch installs python3-venv"
# --- the zypper branch uses its own versioned python names ------------------
_t_unstub yum
_t_stub zypper
_t_reset_calls
install_system_deps >/dev/null 2>&1
_t_has "$(_t_calls)" 'python311-virtualenv' "the zypper branch asks for python311-virtualenv"
# --- an unknown package manager warns rather than guessing ------------------
_t_unstub zypper
unknown_out="$(install_system_deps 2>&1)"
_t_has "$unknown_out" 'Unknown package manager' "an unrecognised manager warns instead of installing"
# --- a failing install is best-effort, never fatal --------------------------
_t_stub_failing pacman
failing_out="$(install_system_deps 2>&1)"
_t_has "$failing_out" 'pacman install failed; continuing' "a failing install is reported and survived"
# --- diarization: the libsndfile probe is host-dependent --------------------
# FW_DIARIZE=1 adds a check for libsndfile at three absolute paths. This host
# HAS /usr/lib/libsndfile.so, so need_libsndfile is legitimately 0 here and
# the "add libsndfile to the package list" branch cannot be reached without a
# jail that hides the library. Asserting it would mean asserting nothing.
#
# What IS testable without a jail: with diarization on and the library
# present, the satisfied-system message names libsndfile.
_t_stub ffmpeg
diarize_out="$(
FW_DIARIZE=1
install_system_deps 2>&1
)"
_t_has "$diarize_out" 'libsndfile' \
"FW_DIARIZE=1 names libsndfile in the satisfied-deps message when the library is present"
_t_report "test_transcribe_deps.sh"

View File

@ -0,0 +1,120 @@
#!/usr/bin/env bash
# Tests for transcribe_pkgmgr.sh — package-manager detection and the CUDA check.
#
# No jail: every branch turns on `command -v <manager>` and every install goes
# through sudo, both of which the harness's PATH stub dir intercepts. The
# suite asserts on RECORDED ARGV, because which packages a branch would
# install is the part a presence test cannot see.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./transcribe_harness.sh
. "$SCRIPT_DIR/transcribe_harness.sh"
_t_setup_env
trap _t_teardown EXIT
# Globals the entry script defines above its source line.
OFFLINE=0
VENV_DIR="$TEST_TMPDIR/venv"
PY_HELPERS="$TEST_TMPDIR/helpers.py"
# shellcheck source=../transcribe_pkgmgr.sh
. "$TRANSCRIBE_LIB_DIR/transcribe_pkgmgr.sh"
# --- detect_pkg_mgr: none of them present -----------------------------------
_t_eq "none" "$(detect_pkg_mgr)" "detect_pkg_mgr reports 'none' with no manager on PATH"
# --- detect_pkg_mgr: each manager, in the documented priority order ---------
# Later entries are added on top of earlier ones to prove the ORDER, not just
# that each name is recognised: apt must win over dnf, dnf over yum, and so on.
_t_stub zypper
_t_eq "zypper" "$(detect_pkg_mgr)" "detect_pkg_mgr finds zypper"
_t_stub pacman
_t_eq "pacman" "$(detect_pkg_mgr)" "pacman takes priority over zypper"
_t_stub yum
_t_eq "yum" "$(detect_pkg_mgr)" "yum takes priority over pacman"
_t_stub dnf
_t_eq "dnf" "$(detect_pkg_mgr)" "dnf takes priority over yum"
_t_stub apt-get
_t_eq "apt" "$(detect_pkg_mgr)" "apt-get takes highest priority and reports 'apt'"
# --- has_libcublas12: absent everywhere -------------------------------------
cublas_rc=0
has_libcublas12 || cublas_rc=$?
_t_eq "1" "$cublas_rc" "has_libcublas12 fails when no CUDA library exists"
# --- has_libcublas12: found in a venv's nvidia site-packages ----------------
mkdir -p "$VENV_DIR/bin"
printf '#!/usr/bin/env bash\nprintf "3.11\\n"\n' >"$VENV_DIR/bin/python"
chmod +x "$VENV_DIR/bin/python"
mkdir -p "$VENV_DIR/lib/python3.11/site-packages/nvidia/cublas/lib"
: >"$VENV_DIR/lib/python3.11/site-packages/nvidia/cublas/lib/libcublas.so.12"
cublas_rc=0
has_libcublas12 || cublas_rc=$?
_t_eq "0" "$cublas_rc" "has_libcublas12 finds the library inside the venv's nvidia packages"
# --- ensure_cuda_runtime: already present is a no-op ------------------------
_t_reset_calls
ensure_cuda_runtime
_t_lacks "$(_t_calls)" 'sudo' "ensure_cuda_runtime installs nothing when cuBLAS is already present"
# --- ensure_cuda_runtime: offline and missing exits 6 -----------------------
rm -f "$VENV_DIR/lib/python3.11/site-packages/nvidia/cublas/lib/libcublas.so.12"
offline_rc=0
(
OFFLINE=1
ensure_cuda_runtime
) >/dev/null 2>&1 || offline_rc=$?
_t_eq "6" "$offline_rc" "ensure_cuda_runtime exits 6 when offline and CUDA is missing"
# --- ensure_cuda_runtime: no sudo means the install is skipped -------------
no_sudo_out="$( (ensure_cuda_runtime) 2>&1)" || true
_t_has "$no_sudo_out" 'sudo not found' "ensure_cuda_runtime reports a missing sudo instead of failing on it"
# --- ensure_cuda_runtime: the pacman branch ---------------------------------
# sudo is a pass-through so the manager stub below records the real argv.
printf '#!/usr/bin/env bash\nexec "$@"\n' >"$TEST_TMPDIR/bin/sudo"
chmod +x "$TEST_TMPDIR/bin/sudo"
_t_unstub apt-get
_t_unstub dnf
_t_unstub yum
_t_reset_calls
pac_rc=0
(ensure_cuda_runtime) >/dev/null 2>&1 || pac_rc=$?
_t_has "$(_t_calls)" 'pacman -Sy --noconfirm cuda cudnn' "the pacman branch installs cuda and cudnn"
_t_eq "6" "$pac_rc" "a still-missing cuBLAS after the install attempt exits 6"
# --- ensure_cuda_runtime: the apt branch ------------------------------------
_t_stub apt-get
_t_reset_calls
(ensure_cuda_runtime) >/dev/null 2>&1 || true
_t_has "$(_t_calls)" 'apt-get install -y nvidia-cuda-toolkit' "the apt branch installs the CUDA toolkit"
# --- ensure_cuda_runtime: dnf and yum share one branch ----------------------
_t_unstub apt-get
_t_stub dnf
_t_reset_calls
(ensure_cuda_runtime) >/dev/null 2>&1 || true
_t_has "$(_t_calls)" 'dnf install -y cuda cudnn' "the dnf branch installs cuda and cudnn"
_t_unstub dnf
_t_stub yum
_t_reset_calls
(ensure_cuda_runtime) >/dev/null 2>&1 || true
_t_has "$(_t_calls)" 'yum install -y cuda cudnn' "the shared dnf|yum branch also drives yum"
# --- ensure_cuda_runtime: the zypper branch ---------------------------------
_t_unstub yum
_t_unstub pacman
_t_stub zypper
_t_reset_calls
(ensure_cuda_runtime) >/dev/null 2>&1 || true
_t_has "$(_t_calls)" 'zypper install -y cuda cudnn' "the zypper branch installs cuda and cudnn"
# --- ensure_cuda_runtime: an unknown manager warns --------------------------
_t_unstub zypper
unknown_out="$( (ensure_cuda_runtime) 2>&1)" || true
_t_has "$unknown_out" 'cannot install CUDA automatically' "an unknown package manager warns rather than guessing"
_t_report "test_transcribe_pkgmgr.sh"

View File

@ -0,0 +1,236 @@
#!/usr/bin/env bash
# Tests for transcribe_venv.sh — venv setup, pip installs and model prep.
#
# No jail: every write goes under $VENV_DIR / $PROJECT_DIR / $MODEL_DIR, all
# pointed at a throwaway dir, and python3/python/pip/espeak/ffmpeg are all
# intercepted by the harness's PATH stub dir.
#
# The assertions are on RECORDED ARGV. Which index a pip install points at is
# the whole behaviour here -- the cu12 wheel index for CUDA, the CPU-only
# torch index for diarization -- and it is invisible to a "pip was called"
# check.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./transcribe_harness.sh
. "$SCRIPT_DIR/transcribe_harness.sh"
_t_setup_env
trap _t_teardown EXIT
# Globals the entry script defines above its source line.
VENV_DIR="$TEST_TMPDIR/venv"
PROJECT_DIR="$TEST_TMPDIR/project"
MODEL_DIR="$TEST_TMPDIR/models"
PY_HELPERS="$TEST_TMPDIR/helpers.py"
PY_RUNNER="$TEST_TMPDIR/runner.py"
OFFLINE=0
FW_DIARIZE=0
mkdir -p "$PROJECT_DIR"
# shellcheck source=../transcribe_venv.sh
. "$TRANSCRIBE_LIB_DIR/transcribe_venv.sh"
# A venv whose activate is a no-op, so `source` succeeds without a real venv.
_t_make_venv() {
mkdir -p "$VENV_DIR/bin"
printf '#!/usr/bin/env bash\n:\n' >"$VENV_DIR/bin/activate"
printf '#!/usr/bin/env bash\nprintf "%%s %%s\\n" "venv-python" "$*" >>"%s/calls.log"\nexit 0\n' \
"$TEST_TMPDIR" >"$VENV_DIR/bin/python"
chmod +x "$VENV_DIR/bin/python"
}
# --- setup_venv: creates the venv when absent -------------------------------
_t_stub python3
_t_stub python
_t_reset_calls
_t_make_venv
setup_venv >/dev/null 2>&1
_t_has "$(_t_calls)" 'pip install --upgrade pip wheel setuptools' \
"setup_venv upgrades pip tooling when online"
# --- setup_venv: creates the venv when the directory does not exist ---------
# python3 -m venv is stubbed, so the fixture recreates what it would have
# produced -- the subject sources $VENV_DIR/bin/activate immediately after.
rm -rf "$VENV_DIR"
cat >"$TEST_TMPDIR/bin/python3" <<'MKVENV'
#!/usr/bin/env bash
printf 'python3 %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
for arg in "$@"; do :; done
mkdir -p "$arg/bin"
printf '#!/usr/bin/env bash\n:\n' >"$arg/bin/activate"
MKVENV
chmod +x "$TEST_TMPDIR/bin/python3"
_t_reset_calls
create_out="$(setup_venv 2>&1)"
_t_has "$create_out" 'Creating venv at' "setup_venv announces creating a missing venv"
_t_has "$(_t_calls)" '-m venv' "setup_venv builds the venv with python3 -m venv"
_t_stub python3
_t_make_venv
# --- setup_venv: offline skips the pip upgrade ------------------------------
_t_reset_calls
(
OFFLINE=1
setup_venv
) >/dev/null 2>&1
_t_lacks "$(_t_calls)" 'pip install --upgrade pip' \
"setup_venv performs no network pip work when offline"
# --- ensure_runner ----------------------------------------------------------
: >"$PY_RUNNER"
runner_rc=0
ensure_runner || runner_rc=$?
_t_eq "0" "$runner_rc" "ensure_runner accepts an existing runner"
rm -f "$PY_RUNNER"
missing_rc=0
(ensure_runner) >/dev/null 2>&1 || missing_rc=$?
_t_eq "3" "$missing_rc" "a missing runner exits 3"
: >"$PY_RUNNER"
# --- install_python_deps: the plain online path -----------------------------
_t_reset_calls
install_python_deps 0 >/dev/null 2>&1
plain_calls="$(_t_calls)"
_t_has "$plain_calls" 'faster-whisper ffmpeg-python' "the base install pulls faster-whisper"
_t_lacks "$plain_calls" 'cu12' "no CUDA wheels are fetched without the nvidia flag"
# --- install_python_deps: the NVIDIA path -----------------------------------
# check-ctranslate2 must FAIL for the cu12 wheel branch to be taken.
printf '#!/usr/bin/env bash\nprintf "%%s %%s\\n" "venv-python" "$*" >>"%s/calls.log"\nexit 1\n' \
"$TEST_TMPDIR" >"$VENV_DIR/bin/python"
chmod +x "$VENV_DIR/bin/python"
_t_reset_calls
install_python_deps 1 >/dev/null 2>&1
nv_calls="$(_t_calls)"
_t_has "$nv_calls" 'download.opennmt.net/ctranslate2/cu12' \
"a missing ctranslate2 fetches the cu12 wheel from the OpenNMT index"
_t_has "$nv_calls" 'nvidia-cublas-cu12' "the NVIDIA path installs the cu12 runtime libs"
# --- install_python_deps: offline verifies instead of installing ------------
_t_reset_calls
off_rc=0
(
OFFLINE=1
install_python_deps 0
) >/dev/null 2>&1 || off_rc=$?
off_calls="$(_t_calls)"
_t_eq "0" "$off_rc" "offline install_python_deps succeeds when the module check passes"
_t_has "$off_calls" 'check-faster-whisper' "offline mode verifies the module instead of installing"
_t_lacks "$off_calls" 'pip install' "offline mode runs no pip install at all"
# --- install_python_deps: offline with the module missing exits 7 -----------
printf '#!/usr/bin/env bash\nexit 1\n' >"$TEST_TMPDIR/bin/python"
chmod +x "$TEST_TMPDIR/bin/python"
missing_mod_rc=0
(
OFFLINE=1
install_python_deps 0
) >/dev/null 2>&1 || missing_mod_rc=$?
_t_eq "7" "$missing_mod_rc" "a missing faster-whisper in offline mode exits 7"
_t_stub python
# --- install_python_deps: diarization adds its own wheels -------------------
_t_reset_calls
(
FW_DIARIZE=1
install_python_deps 0
) >/dev/null 2>&1
dia_calls="$(_t_calls)"
_t_has "$dia_calls" 'soundfile speechbrain' "diarization installs soundfile and speechbrain"
_t_has "$dia_calls" 'download.pytorch.org/whl/cpu' \
"diarization forces the CPU-only torch index to avoid mismatched CUDA builds"
# --- install_python_deps: offline diarization checks its own deps -----------
_t_reset_calls
(
OFFLINE=1
FW_DIARIZE=1
install_python_deps 0
) >/dev/null 2>&1
_t_has "$(_t_calls)" 'check-diarization' \
"offline diarization verifies its own deps as well as faster-whisper"
# --- install_python_deps: every pip failure is a warning, never fatal -------
# pip failing must not abort the run: the subject deliberately trades a
# degraded install for a hard stop, and each `|| log` is that decision.
cat >"$TEST_TMPDIR/bin/python" <<'FAILPIP'
#!/usr/bin/env bash
printf 'python %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
exit 1
FAILPIP
chmod +x "$TEST_TMPDIR/bin/python"
warn_out="$(
FW_DIARIZE=1
install_python_deps 1 2>&1
)" || true
_t_has "$warn_out" 'could not reach cu12 wheel index' "the cu12 wheel failure is warned about"
_t_has "$warn_out" 'failed to install NVIDIA cu12 runtime libs' "the cu12 runtime failure is warned about"
_t_has "$warn_out" 'failed to install soundfile/speechbrain' "the diarization dep failure is warned about"
_t_has "$warn_out" 'failed to install torch/torchaudio' "the torch wheel failure is warned about"
_t_stub python
# --- generate_test_audio: espeak-ng is preferred ----------------------------
# The stub must MATERIALISE the wav, or the -s test fails and the next
# fallback runs -- a record-only stub would silently test the wrong branch.
cat >"$TEST_TMPDIR/bin/espeak-ng" <<'ESPEAK'
#!/usr/bin/env bash
printf 'espeak-ng %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
printf 'RIFFfake' >"$2"
ESPEAK
chmod +x "$TEST_TMPDIR/bin/espeak-ng"
_t_reset_calls
audio_out="$(generate_test_audio 2>/dev/null)"
_t_eq "$PROJECT_DIR/test_fw.wav" "${audio_out##*$'\n'}" "generate_test_audio returns the wav path"
_t_has "$(_t_calls)" 'espeak-ng' "espeak-ng is tried first"
# --- generate_test_audio: falls through to espeak ---------------------------
rm -f "$PROJECT_DIR/test_fw.wav"
printf '#!/usr/bin/env bash\nexit 1\n' >"$TEST_TMPDIR/bin/espeak-ng"
chmod +x "$TEST_TMPDIR/bin/espeak-ng"
cat >"$TEST_TMPDIR/bin/espeak" <<'ESPEAK2'
#!/usr/bin/env bash
printf 'espeak %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
printf 'RIFFfake' >"$2"
ESPEAK2
chmod +x "$TEST_TMPDIR/bin/espeak"
_t_reset_calls
generate_test_audio >/dev/null 2>&1
_t_has "$(_t_calls)" 'espeak ' "a failing espeak-ng falls through to espeak"
# --- generate_test_audio: falls through to the Python stdlib generator ------
rm -f "$PROJECT_DIR/test_fw.wav"
_t_unstub espeak-ng
_t_unstub espeak
cat >"$TEST_TMPDIR/bin/python3" <<'PY3'
#!/usr/bin/env bash
printf 'python3 %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
for arg in "$@"; do
case "$prev" in --file) printf 'RIFFfake' >"$arg" ;; esac
prev="$arg"
done
PY3
chmod +x "$TEST_TMPDIR/bin/python3"
_t_reset_calls
generate_test_audio >/dev/null 2>&1
_t_has "$(_t_calls)" 'generate-wav' "with no espeak at all the Python stdlib generator is used"
# --- generate_test_audio: the ffmpeg fallback of last resort ----------------
rm -f "$PROJECT_DIR/test_fw.wav"
_t_stub python3
_t_stub ffmpeg
_t_reset_calls
generate_test_audio >/dev/null 2>&1
_t_has "$(_t_calls)" 'sine=frequency=1000:duration=3' \
"when every generator fails, ffmpeg synthesises a 1kHz tone"
# --- prepare_model ----------------------------------------------------------
_t_reset_calls
prepare_model "small.en" >/dev/null 2>&1
model_calls="$(_t_calls)"
_t_has "$model_calls" 'prepare-model --model small.en' "prepare_model passes the model name through"
_t_has "$model_calls" "--model-dir $MODEL_DIR" "prepare_model targets the configured model dir"
_t_eq "0" "$([[ -d $MODEL_DIR ]] && echo 0 || echo 1)" "prepare_model creates the model dir"
_t_report "test_transcribe_venv.sh"

View File

@ -0,0 +1,123 @@
#!/usr/bin/env bash
# Tests for unity_handler.sh — the unityhub:// URL handler registration.
#
# No jail: the only write goes to $DESKTOP_DIR, pointed at a throwaway dir,
# and every external (update-desktop-database, xdg-mime, xdg-open) is
# intercepted by the harness's PATH stub dir.
#
# The generated .desktop file is asserted on its CONTENT: the MimeType and
# Exec lines are what make the handler work, and a file that exists with the
# wrong Exec is exactly the bug a presence check would pass.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./transcribe_harness.sh
. "$SCRIPT_DIR/transcribe_harness.sh"
_t_setup_env
trap _t_teardown EXIT
# Globals the entry script defines above its source line.
DESKTOP_DIR="$TEST_TMPDIR/applications"
RUN_TEST=false
mkdir -p "$DESKTOP_DIR"
log_info() { printf '[INFO] %s\n' "$*"; }
log_ok() { printf '[OK] %s\n' "$*"; }
log_warn() { printf '[WARN] %s\n' "$*"; }
log_error() { printf '[ERR] %s\n' "$*"; }
# shellcheck source=../unity_handler.sh
. "$TRANSCRIBE_LIB_DIR/unity_handler.sh"
# --- create_handler_desktop -------------------------------------------------
create_out="$(create_handler_desktop '/opt/unityhub/unityhub %u')"
desktop_file="${create_out##*$'\n'}"
_t_eq "$DESKTOP_DIR/unityhub-url-handler.desktop" "$desktop_file" \
"create_handler_desktop returns the path it wrote"
desktop_body="$(cat "$desktop_file")"
_t_has "$desktop_body" 'Exec=/opt/unityhub/unityhub %u' \
"the Exec line carries the command it was given"
_t_has "$desktop_body" 'x-scheme-handler/unityhub;x-scheme-handler/unity;' \
"both URL schemes are declared in MimeType"
_t_has "$desktop_body" 'NoDisplay=true' "the entry is hidden from menus"
# --- register_mime_handler: both tools present ------------------------------
_t_stub update-desktop-database
_t_stub xdg-mime
_t_reset_calls
register_mime_handler "$desktop_file" >/dev/null
mime_calls="$(_t_calls)"
_t_has "$mime_calls" 'update-desktop-database' "the desktop database is refreshed"
_t_has "$mime_calls" 'default unityhub-url-handler.desktop x-scheme-handler/unityhub' \
"xdg-mime registers the unityhub scheme by BASENAME, not full path"
_t_has "$mime_calls" 'unityhub-url-handler.desktop x-scheme-handler/unity' \
"xdg-mime also registers the bare unity scheme"
# --- register_mime_handler: no update-desktop-database is survivable --------
_t_unstub update-desktop-database
no_db_out="$(register_mime_handler "$desktop_file" 2>&1)"
_t_has "$no_db_out" 'update-desktop-database not found' \
"a missing update-desktop-database is reported"
_t_has "$no_db_out" 'MIME handler registered' "registration still completes without it"
# --- register_mime_handler: no xdg-mime is FATAL ----------------------------
# Without xdg-mime nothing is registered, so this must fail rather than
# report success -- the distinction the else branch exists to make.
_t_unstub xdg-mime
no_mime_rc=0
register_mime_handler "$desktop_file" >/dev/null 2>&1 || no_mime_rc=$?
_t_eq "1" "$no_mime_rc" "a missing xdg-mime returns non-zero rather than claiming success"
# --- verify_registration: the handler matches -------------------------------
cat >"$TEST_TMPDIR/bin/xdg-mime" <<'XDGMIME'
#!/usr/bin/env bash
printf 'unityhub-url-handler.desktop\n'
XDGMIME
chmod +x "$TEST_TMPDIR/bin/xdg-mime"
match_out="$(verify_registration "$desktop_file" 2>&1)"
_t_has "$match_out" 'correctly set to unityhub-url-handler.desktop' \
"verify_registration confirms a correctly registered handler"
# --- verify_registration: a foreign handler warns ---------------------------
cat >"$TEST_TMPDIR/bin/xdg-mime" <<'XDGMIME'
#!/usr/bin/env bash
printf 'some-other-app.desktop\n'
XDGMIME
chmod +x "$TEST_TMPDIR/bin/xdg-mime"
wrong_out="$(verify_registration "$desktop_file" 2>&1)"
_t_has "$wrong_out" 'not set to' "verify_registration warns when another app owns the scheme"
_t_has "$wrong_out" 'some-other-app.desktop' "the warning names the handler actually registered"
# --- verify_registration: nothing registered at all -------------------------
cat >"$TEST_TMPDIR/bin/xdg-mime" <<'XDGMIME'
#!/usr/bin/env bash
exit 1
XDGMIME
chmod +x "$TEST_TMPDIR/bin/xdg-mime"
none_out="$(verify_registration "$desktop_file" 2>&1)"
_t_has "$none_out" '<none>' "an unset scheme is reported as <none> rather than blank"
# --- maybe_test_open: disabled prints the manual command --------------------
manual_out="$(maybe_test_open 2>&1)"
_t_has "$manual_out" 'test manually with' "RUN_TEST=false explains how to test by hand"
# --- maybe_test_open: enabled invokes xdg-open ------------------------------
_t_stub xdg-open
_t_reset_calls
opened_out="$(
RUN_TEST=true
maybe_test_open 2>&1
)"
_t_has "$(_t_calls)" 'unityhub://v1/editor-signin' "RUN_TEST=true opens the test link"
_t_has "$opened_out" 'Test link invoked' "the run reports that the link was invoked"
# --- maybe_test_open: enabled but xdg-open missing --------------------------
_t_unstub xdg-open
no_open_out="$(
RUN_TEST=true
maybe_test_open 2>&1
)"
_t_has "$no_open_out" 'xdg-open not found' "a missing xdg-open warns instead of failing"
_t_report "test_unity_handler.sh"

View File

@ -0,0 +1,126 @@
#!/usr/bin/env bash
# lib/tests/transcribe_harness.sh — shared fixture for the transcribe libs.
#
# Sourced, not executed. One harness per DIRECTORY, not per file: jscpd fails
# the commit above 2% duplication, and near-identical per-file harnesses are
# exactly how that trips.
#
# Unlike the features/lib harness, these subjects need NO jail. They branch on
# `command -v <pkg manager>` and shell out through sudo; both are intercepted
# by a PATH stub dir, so nothing here can reach a real package manager. The
# suites assert on the RECORDED ARGV -- which packages a branch would install
# is the thing worth checking, and it is invisible to a presence test.
set -euo pipefail
PASS=0
FAIL=0
_t_pass() {
PASS=$((PASS + 1))
printf ' OK: %s\n' "$1"
}
_t_fail() {
FAIL=$((FAIL + 1))
printf ' FAIL: %s\n' "$1"
}
_t_eq() {
if [[ $2 == "$1" ]]; then
_t_pass "$3"
else
_t_fail "$3 (want '${1}', got '${2}')"
fi
}
_t_has() {
if [[ $1 == *"$2"* ]]; then
_t_pass "$3"
else
_t_fail "$3 (want a substring '${2}')"
fi
}
_t_lacks() {
if [[ $1 != *"$2"* ]]; then
_t_pass "$3"
else
_t_fail "$3 (did not want a substring '${2}')"
fi
}
TRANSCRIBE_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
export TRANSCRIBE_LIB_DIR
log() { printf '[log] %s\n' "$*"; }
_t_setup_env() {
TEST_TMPDIR="$(mktemp -d)"
export TEST_TMPDIR
mkdir -p "$TEST_TMPDIR/bin"
# PATH is REPLACED rather than prepended, but coreutils is kept: these
# subjects branch on which package managers exist and this host really
# has pacman, so a prepended dir could not HIDE it and every "not
# installed" case would silently assert nothing. The stub dir plus a
# private coreutils dir is the whole PATH; package managers and sudo
# appear only when a test puts them there.
mkdir -p "$TEST_TMPDIR/coreutils"
local tool
# `bash` is in this list because every stub carries a `#!/usr/bin/env bash`
# shebang, and env resolves it through the RESTRICTED PATH. Without it each
# stub dies with "env: 'bash': No such file or directory" and the branch it
# was standing in for is silently never taken.
for tool in basename bash cat chmod cp dirname env find grep ln mkdir mktemp printf rm sed sort; do
if command -v "$tool" >/dev/null 2>&1; then
ln -sf "$(command -v "$tool")" "$TEST_TMPDIR/coreutils/$tool"
fi
done
PATH="$TEST_TMPDIR/bin:$TEST_TMPDIR/coreutils"
export PATH
}
# Record-and-succeed stub. The argv is the assertion target, so it is written
# verbatim to one line of the call log.
_t_stub() {
printf '#!/usr/bin/env bash\nprintf "%%s %%s\\n" "%s" "$*" >>"%s/calls.log"\nexit 0\n' \
"$1" "$TEST_TMPDIR" >"$TEST_TMPDIR/bin/$1"
chmod +x "$TEST_TMPDIR/bin/$1"
}
# A stub that FAILS, for the "install failed; continuing" best-effort paths.
_t_stub_failing() {
printf '#!/usr/bin/env bash\nprintf "%%s %%s\\n" "%s" "$*" >>"%s/calls.log"\nexit 1\n' \
"$1" "$TEST_TMPDIR" >"$TEST_TMPDIR/bin/$1"
chmod +x "$TEST_TMPDIR/bin/$1"
}
# Remove a stub AND forget it. bash caches executable locations in a hash
# table, so `command -v foo` keeps succeeding after foo is deleted until the
# table is cleared -- which silently turns every "tool is missing" test into a
# "tool is present" test that asserts the opposite of its own name. Verified:
# without the `hash -r` the removed stub is STILL FOUND.
_t_unstub() {
rm -f "$TEST_TMPDIR/bin/$1"
hash -r
}
_t_calls() {
if [[ -f "$TEST_TMPDIR/calls.log" ]]; then
cat "$TEST_TMPDIR/calls.log"
fi
}
_t_reset_calls() {
: >"$TEST_TMPDIR/calls.log"
}
_t_teardown() {
if [[ -n ${TEST_TMPDIR:-} && -d ${TEST_TMPDIR} ]]; then
rm -rf "$TEST_TMPDIR"
fi
}
_t_report() {
printf '\n%s: %d passed, %d failed\n' "${1:-tests}" "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]]
}

View File

@ -100,8 +100,6 @@ linux_configuration/scripts/single_use/lib/joplin_server.sh
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/clean_audio_filters.sh
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/transcribe_deps.sh
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/transcribe_pkgmgr.sh
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/transcribe_venv.sh
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/unity_handler.sh
meta/lib/lint_full_tools.sh
meta/lib/lint_output.sh
meta/scripts/lib/disk_cleanup_common.sh