#!/usr/bin/env bash
set -euo pipefail

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT

mkdir -p "$tmp/bin"
cat >"$tmp/bin/systemctl" <<'EOF'
#!/usr/bin/env bash
case "${1:-}" in
  --user) exit 0 ;;
esac
exit 1
EOF
cat >"$tmp/bin/systemd-run" <<'EOF'
#!/usr/bin/env bash
printf '%s\n' "$*" >>"$PRIORITY_RUN_TEST_LOG"
exit 0
EOF
chmod +x "$tmp/bin/systemctl" "$tmp/bin/systemd-run"

export PRIORITY_RUN_TEST_LOG="$tmp/systemd-run.log"
PATH="$tmp/bin:$PATH" /home/user/.claude/lib/priority-run.sh low /bin/true

calls="$(wc -l <"$PRIORITY_RUN_TEST_LOG")"
if [[ "$calls" != 1 ]]; then
  printf 'expected one systemd-run call, got %s\n' "$calls" >&2
  exit 1
fi

grep -q -- '--slice=build.slice' "$PRIORITY_RUN_TEST_LOG"
