From a26eade80b8ad1586c644f734d204b320564e609 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Tue, 12 Aug 2025 05:15:41 +0200 Subject: [PATCH] [test] add examples-check target with stubbed BIN and no-network validation for example scripts --- Makefile | 23 ++++++++++++++++++++ docs/development.md | 10 +++++++++ examples/download_models_interactive.sh | 0 examples/transcribe_file.sh | 0 examples/update_models.sh | 0 scripts/bin_stub.sh | 26 +++++++++++++++++++++++ scripts/with_flags.sh | 28 +++++++++++++++++++++++++ 7 files changed, 87 insertions(+) create mode 100644 Makefile mode change 100644 => 100755 examples/download_models_interactive.sh mode change 100644 => 100755 examples/transcribe_file.sh mode change 100644 => 100755 examples/update_models.sh create mode 100755 scripts/bin_stub.sh create mode 100755 scripts/with_flags.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c39b7f --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# Lightweight examples-check: runs all examples/*.sh with --no-interaction -q and stubbed BIN +# This target does not perform network calls and never prompts for input. + +.SHELL := /bin/bash + +.PHONY: examples-check +examples-check: + @set -euo pipefail; \ + shopt -s nullglob; \ + BIN_WRAPPER="$(PWD)/scripts/with_flags.sh"; \ + failed=0; \ + for f in examples/*.sh; do \ + echo "[examples-check] Running $$f"; \ + BIN="$$BIN_WRAPPER" bash "$$f" /dev/null 2>&1 || { \ + echo "[examples-check] FAILED: $$f"; failed=1; \ + }; \ + done; \ + if [[ $$failed -ne 0 ]]; then \ + echo "[examples-check] Some examples failed."; \ + exit 1; \ + else \ + echo "[examples-check] All examples passed (no interaction, quiet)."; \ + fi diff --git a/docs/development.md b/docs/development.md index 44e25b2..12d40d8 100644 --- a/docs/development.md +++ b/docs/development.md @@ -47,6 +47,16 @@ Tests - cargo test - The test suite includes CLI-oriented integration tests and unit tests. Some tests simulate GPU detection using env vars (POLYSCRIBE_TEST_FORCE_*). Do not rely on these flags in production code. +Examples check (no network, non-interactive) +- To quickly validate that example scripts are wired correctly (no prompts, quiet, exit 0), run: + - make examples-check +- What it does: + - Iterates over examples/*.sh + - Forces execution with --no-interaction and -q via a wrapper + - Uses a stubbed BIN that performs no network access and exits successfully + - Redirects stdin from /dev/null to ensure no prompts +- This is intended for CI smoke checks and local verification; it does not actually download models or transcribe audio. + Clippy - Run lint checks and treat warnings as errors: - cargo clippy --all-targets -- -D warnings diff --git a/examples/download_models_interactive.sh b/examples/download_models_interactive.sh old mode 100644 new mode 100755 diff --git a/examples/transcribe_file.sh b/examples/transcribe_file.sh old mode 100644 new mode 100755 diff --git a/examples/update_models.sh b/examples/update_models.sh old mode 100644 new mode 100755 diff --git a/scripts/bin_stub.sh b/scripts/bin_stub.sh new file mode 100755 index 0000000..b520269 --- /dev/null +++ b/scripts/bin_stub.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Lightweight stub for examples-check: simulates the PolyScribe CLI without I/O or network +# - Accepts any arguments +# - Exits 0 +# - Produces no output unless VERBOSE_STUB=1 +# - Never performs network operations +# - Never reads from stdin +set -euo pipefail + +if [[ "${VERBOSE_STUB:-0}" == "1" ]]; then + echo "[stub] polyscribe $*" 1>&2 +fi + +# Behave quietly if -q/--quiet is present by default (no output) +# Honor --help/-h: print minimal usage if verbose requested +if [[ "${VERBOSE_STUB:-0}" == "1" ]]; then + for arg in "$@"; do + if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then + echo "PolyScribe stub: no-op (examples-check)" 1>&2 + break + fi + done +fi + +# Always succeed quietly +exit 0 diff --git a/scripts/with_flags.sh b/scripts/with_flags.sh new file mode 100755 index 0000000..d11cc88 --- /dev/null +++ b/scripts/with_flags.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Wrapper that ensures --no-interaction -q are present, then delegates to the real BIN (stub by default) +set -euo pipefail + +REAL_BIN=${REAL_BIN:-"$(dirname "$0")/bin_stub.sh"} + +# Append flags if not already present in args +args=("$@") +need_no_interaction=1 +need_quiet=1 +for a in "${args[@]}"; do + [[ "$a" == "--no-interaction" ]] && need_no_interaction=0 + [[ "$a" == "-q" || "$a" == "--quiet" ]] && need_quiet=0 +done + +if [[ $need_no_interaction -eq 1 ]]; then + args=("--no-interaction" "${args[@]}") +fi +if [[ $need_quiet -eq 1 ]]; then + args=("-q" "${args[@]}") +fi + +# Never read stdin; prevent accidental blocking by redirecting from /dev/null +# Also advertise offline via env variables commonly checked by the app +export CI=1 +export POLYSCRIBE_MODELS_BASE_COPY_DIR="${POLYSCRIBE_MODELS_BASE_COPY_DIR:-}" # leave empty by default + +exec "$REAL_BIN" "${args[@]}"