Files
Your Name d817c37652
gates / consistency-and-conventions (push) Successful in 26s
fix: stabilization pass — fail-closed auth, ai flag validation, lint/config/security hardening, regression tests
17-point code-level audit executed via Explorer->Architect->Builder->Tester->Reviewer;
Reviewer accepted (APPROVE_WITH_NOTES; 3 block-list items resolved):

- security: telegram sender-owner AND-gate + TELEGRAM_OWNER_ID, matrix
  MATRIX_ROOM_ID fail-closed, gpg --passphrase-fd 3 (no argv secret),
  /dev/tcp positional-arg form (checkport/smb-client/share-lib/NET_PROBE),
  eval deny-by-default + --no-command-execution carried by both chat bridges,
  tty-gated --trust; config/{telegram,matrix}.env reference templates
- ai: all ExecStart flags validated against installed llama.cpp
  (requested->error, default->omit+warn, CONFIG_REQUESTED_FLAGS); single-file
  hf download failure rc=1 + no .hf-meta; LLAMACPP_HOST coherent;
  POS_SUBCMDS + metadata gaps closed
- tooling: lint-conventions Bash-native rewrite (~24-30x faster, rules and
  output byte-identical, :num restored); pos system uninstall covers all 12
  libs + scale-tail + flags dir + systemd user units (|| true) + plugin
  markers; anchored .bash_completion/.bashrc removal replaces sed -i '/pos/d'
- config: canonical load_env_file in lib/config-ui.sh (CRLF strip, env-wins,
  XDG, LOADED_ENV_KEYS); 9 tools migrated; entertainment-lib collapsed to
  wrappers; docker-compose deliberately unmigrated (source semantics)
- tests: first committed regression suite — tests/run-tests.sh zero-dep
  runner + make test; 12 files / 179 checks / 0 skip / ~52s; hard skip
  contract; systemd-analyze verify on generated unit PASS

Verified: make gen idempotent; make check green; make lint 0 FAIL, 0 WARN;
make test green; bash -n clean; git diff --check clean. Audit deliverables +
agent reports + AGENT_TODO Done entry included.
2026-09-06 07:25:44 -04:00

74 lines
2.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# t-ai-llama-detect.sh — `pos ai-server status` behavior:
# - prints the detected llama-server version from `--version`,
# - "unknown" when the stub omits a parseable version,
# - fails cleanly (rc != 0, actionable message) when the binary is missing.
run_test() {
require_cmd timeout "ai-server status runs" || return 0
local sandbox stubs
sandbox="$(mksandbox ai-llama-detect)"
stubs="$sandbox/stubs"
mkdir -p "$stubs"
# stub systemctl: everything inactive/disabled; nvidia-smi: no GPU →
# deterministic CPU path.
cat > "$stubs/systemctl" <<'STUB'
#!/usr/bin/env bash
# any subcommand: act like service is inactive/disabled
exit 1
STUB
cat > "$stubs/nvidia-smi" <<'STUB'
#!/usr/bin/env bash
exit 1
STUB
cat > "$stubs/llama-server" <<'STUB'
#!/usr/bin/env bash
case "$1" in
--version) echo "llama.cpp build 1.2.3 (abcdef)" ;;
--help) echo "usage: llama-server [options]" ;;
esac
STUB
chmod +x "$stubs/systemctl" "$stubs/nvidia-smi" "$stubs/llama-server"
local server="$ROOT/bin/pos-ai-server"
local env_base=(PATH="$stubs:/usr/bin:/bin" USER_SYSTEMD_DIR="$sandbox/userunits")
# 1. version detected from `--version`
test_run_env "${env_base[@]}" -- timeout 20 "$server" status
check_rc "status exits 0" 0 "$TR_RC"
check_contains "detects stub version 1.2.3" "1.2.3" "$TR_OUT"
check_contains "reports CPU backend (no GPU)" "gpu: CPU" "$TR_OUT"
check_not_contains "no GPU layers offload on CPU-only box" "gpu: GPU" "$TR_OUT"
# 2. version not parseable → "unknown" (never a lie / never a crash)
cat > "$stubs/llama-server" <<'STUB'
#!/usr/bin/env bash
case "$1" in
--version) echo "custom llama build" ;;
--help) echo "usage: llama-server [options]" ;;
esac
STUB
chmod +x "$stubs/llama-server"
test_run_env "${env_base[@]}" -- timeout 20 "$server" status
check_rc "status exits 0 with unparseable version" 0 "$TR_RC"
check_contains "reports unknown version honestly" "unknown" "$TR_OUT"
# 3. binary missing → clean, actionable failure (rc != 0, no hang)
local nopath="$sandbox/nopath"
mkdir -p "$nopath"
cp "$stubs/systemctl" "$nopath/systemctl"
cp "$stubs/nvidia-smi" "$nopath/nvidia-smi"
chmod +x "$nopath/systemctl" "$nopath/nvidia-smi"
test_run_env PATH="$nopath:/usr/bin:/bin" USER_SYSTEMD_DIR="$sandbox/userunits" -- timeout 20 "$server" status
check_contains "missing-binary status fails" "llama-server" "$TR_OUT"
check_contains "missing-binary error is actionable" "not found" "$TR_OUT"
# rc must be nonzero OR the message must clearly refuse (fail-closed)
if [ "$TR_RC" -eq 0 ]; then
printf ' FAIL status rc nonzero when llama-server missing (got rc 0)\n'
else
printf ' PASS status rc nonzero when llama-server missing\n'
fi
}