view mrjunejune/test/inference_stack_config_test.sh @ 271:13d61401c57d

redirect Copilot cache to service state Set XDG_CACHE_HOME from the configured inference state so the systemd service can extract Copilot outside its protected home directory. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 13:24:05 -0700
parents 056790c4fb0d
children
line wrap: on
line source

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

source_script="$(realpath "$1")"
root="$(mktemp -d)"
trap 'rm -rf "$root"' EXIT
mkdir -p "$root/mrjunejune"
for file in server launcher sidecar copilot litellm config python mock; do
  touch "$root/$file"
done

cat > "$root/mrjunejune/.config" <<EOF
AUTH_COOKIE_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
AUTH_BOOTSTRAP_USERNAME=admin
AUTH_BOOTSTRAP_PASSWORD_HASH=zenbu-scrypt\$v=1\$N=32768\$r=8\$p=1\$salt\$hash
LITELLM_MASTER_KEY=sk-test-only-value
GITHUB_COPILOT_TOKEN_DIR=$root/token-dir
MRJUNEJUNE_INFERENCE_STATE=$root
MRJUNEJUNE_ALLOW_GUEST_INFERENCE=true
SERVER_HOST=127.0.0.1
EOF

output="$(
  MRJUNEJUNE_ALLOW_GUEST_INFERENCE=false \
    BUILD_WORKSPACE_DIRECTORY="$root" \
    "$source_script" \
      "$root/server" \
      "$root/launcher" \
      "$root/sidecar" \
      "$root/copilot" \
      "$root/litellm" \
      "$root/config" \
      "$root/python" \
      "$root/mock" \
      --check-config
)"
grep -q "config=$root/mrjunejune/.config" <<<"$output"
grep -q '^litellm_master_key=set$' <<<"$output"
grep -q "copilot_token_dir=$root/token-dir" <<<"$output"
grep -q "copilot_cache_dir=$root/cache" <<<"$output"
grep -q '^guest_inference=true$' <<<"$output"
if grep -q 'sk-test-only-value' <<<"$output"; then
  echo "Config check leaked the LiteLLM master key" >&2
  exit 1
fi

echo 'UNSUPPORTED_SETTING=value' >> "$root/mrjunejune/.config"
if BUILD_WORKSPACE_DIRECTORY="$root" \
    "$source_script" \
      "$root/server" \
      "$root/launcher" \
      "$root/sidecar" \
      "$root/copilot" \
      "$root/litellm" \
      "$root/config" \
      "$root/python" \
      "$root/mock" \
      --check-config >/dev/null 2>&1; then
  echo "Unsupported config key was accepted" >&2
  exit 1
fi

if grep -Eq '(^|[[:space:]])(source|eval)[[:space:]]' "$source_script"; then
  echo "Inference config parser must not source or eval config files" >&2
  exit 1
fi