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

85 lines
3.0 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# t-ai-hf-download.sh — `pos ai hf download` single-file path (D-C layout):
# - success: target file + .hf-meta written, rc 0, honest summary line;
# - failure: "Failed to download", NO .hf-meta (incomplete model is never
# advertised as complete), rc != 0, honest (0 of N files) summary.
# curl is stubbed (no network): /tree/ + /models/ APIs return canned JSON,
# /resolve/ writes content or fails via HF_FAIL_DOWNLOAD.
run_test() {
require_cmd jq "ai hf download" || return 0
require_cmd timeout "ai hf download" || return 0
local sandbox stubs dl tree_resp
sandbox="$(mksandbox ai-hf-download)"
stubs="$sandbox/stubs"
dl="$sandbox/models"
mkdir -p "$stubs" "$dl"
local tree_resp="$sandbox/tree.json"
printf '%s' '[{"type":"file","path":"model.gguf","size":12345}]' > "$tree_resp"
cat > "$stubs/curl" <<STUB
#!/usr/bin/env bash
out=""
has_w=0
i=1
for (( ; i<=\$#; i++ )); do
arg="\${!i}"
case "\$arg" in
-w) has_w=1 ;;
-o|-D)
n=\$((i+1))
val="\${!n}"
if [ "\$arg" = "-o" ]; then out="\$val"; else : > "\$val"; fi
;;
esac
done
url="\${@: -1}"
case "\$url" in
*"/tree/"*)
[ "\$has_w" -eq 1 ] && printf '200'
cat "\$TREE_RESP" > "\$out"
;;
*"/models/"*)
[ "\$has_w" -eq 1 ] && printf '200'
printf '%s' '{"defaultBranch":null}' > "\$out"
;;
*"/resolve/"*)
if [ "\${HF_FAIL_DOWNLOAD:-0}" = "1" ]; then
exit 1
fi
printf 'stub model binary content\n' > "\$out"
;;
*)
[ "\$has_w" -eq 1 ] && printf '200'
;;
esac
STUB
chmod +x "$stubs/curl"
local tool="$ROOT/bin/pos-ai-hf"
local env_base=(PATH="$stubs:/usr/bin:/bin" HF_DOWNLOAD_DIR="$dl" TREE_RESP="$tree_resp")
# ── 1. success ──
test_run_env "${env_base[@]}" -- timeout 60 "$tool" download ns/test-model model.gguf
check_rc "download succeeds" 0 "$TR_RC"
check_contains "success summary names file" "Downloaded: ns/test-model/model.gguf" "$TR_OUT"
check_file_exists "target model downloaded" "$dl/ns-test-model/model.gguf"
check_file_exists "metadata written on full success" "$dl/ns-test-model/.hf-meta"
check_contains "metadata records repo" "ns/test-model" "$(cat "$dl/ns-test-model/.hf-meta")"
# ── 2. download failure → no metadata, rc != 0 ──
rm -rf "$dl/ns-test-model"
test_run_env "${env_base[@]}" HF_FAIL_DOWNLOAD=1 -- timeout 60 "$tool" download ns/test-model model.gguf
check_contains "failure warns per file" "Failed to download model.gguf" "$TR_OUT"
check_contains "failure refuses to write metadata" "Not writing .hf-meta" "$TR_OUT"
check_contains "failure summary is honest (0 of 1)" "0 of 1 files, 1 failed" "$TR_OUT"
check_file_absent "no .hf-meta on partial failure" "$dl/ns-test-model/.hf-meta"
if [ "$TR_RC" -ne 0 ]; then
printf ' PASS download failure exits nonzero\n'
else
printf ' FAIL download failure exited 0\n'
fi
}