Files
finish/tests/test_finish.sh
mike 074a2b1f5f
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 24s
Tests / test (bash) (push) Successful in 10s
Tests / test (zsh) (push) Successful in 10s
Tests / lint (push) Successful in 9s
Tests / docker (push) Successful in 19s
update
2025-12-11 08:27:03 +01:00

83 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# ----- tiny test framework -----
pass() { printf "✔ %s\n" "$1"; }
fail() { printf "✘ %s\n" "$1"; exit 1; }
assert_ok() {
if [[ $1 -ne 0 ]]; then fail "$2"; fi
}
assert_nonempty() {
if [[ -z "$1" ]]; then fail "$2"; fi
}
assert_contains() {
if [[ ! "$1" =~ $2 ]]; then fail "$3"; fi
}
# Ensure output does not contain any of the common error phrases.
assert_no_common_errors() {
local output="$1"
local -a patterns=(
"ACSH_ACTIVE_API_KEY not set"
"Bad Request"
"Unauthorized"
"Too Many Requests"
"Internal Server Error"
"Unknown Error"
"Failed to parse completions"
"SyntaxError"
"ERROR:"
)
for pat in "${patterns[@]}"; do
if grep -qE "$pat" <<<"$output"; then
printf "Test failed: output contains error pattern '%s'\nFull output follows:\n%s\n" "$pat" "$output"
exit 1
fi
done
}
# --------------------------------
echo "=== SETUP ==="
bash ./docs/install.sh main
source ~/.bashrc
finish config set provider lmstudio
finish config set endpoint http://plato.lan:1234/v1/chat/completions
finish config set model darkidol-llama-3.1-8b-instruct-1.3-uncensored_gguf:2
# -------------------------------- TESTS --------------------------------
# 1) which finish should return something
out=$(which finish 2>&1) ; code=$?
assert_ok $code "which finish should exit 0"
assert_nonempty "$out" "which finish returned empty output"
pass "which finish returns path"
# 2) finish output should contain 'finish.sh'
out=$(finish 2>&1) ; code=$?
assert_ok $code "finish should exit 0"
assert_contains "$out" "finish\.sh" "finish output does not contain finish.sh"
pass "finish outputs reference to finish.sh"
# 3) config should contain lmstudio
out=$(finish config 2>&1) ; code=$?
assert_ok $code "finish config should exit 0"
assert_contains "$out" "lmstudio" "finish config missing lmstudio provider"
pass "finish config contains lmstudio"
# 4) finish command should run
out=$(finish command "ls # show largest files" 2>&1) ; code=$?
assert_ok $code "finish command did not exit 0"
assert_nonempty "$out" "finish command returned empty output"
assert_no_common_errors "$out"
pass "finish command executed and returned output"
# ------------------------------- CLEANUP --------------------------------
echo "=== CLEANUP ==="
finish remove -y || true
echo "All tests passed."