#!/usr/bin/env bash # Preflight: what refuses a switch, and why - against fake servers. . "$(dirname "$0")/../lib.sh" start_fake code() { preflight_code "$@" | cut -d' ' -f1; } expect_eq "$(code ollama)" needs-setup 'a shipped preset is set up before use' ready_preset ollama "$OLLAMA_URL" expect_eq "$(code ollama)" ok 'ollama answers' cp "$P/ollama.json" "$P/dead.json" python3 "$J" set-url "$P/dead.json" http://127.0.0.1:1 >/dev/null expect_eq "$(code ollama dead)" server-unreachable 'a dead ollama is refused' ready_preset lmstudio "$LMSTUDIO_URL" expect_eq "$(code lmstudio)" ok 'lm studio answers' # custom: every tier empty first, then no address, then the key, then a proxy ready_preset custom expect_eq "$(preflight_code custom)" 'no-models edit-preset' 'a preset with no models is refused' python3 "$J" set-tier "$P/custom.json" opus gw/model-a expect_eq "$(preflight_code custom)" 'no-url set-url' 'a custom endpoint needs an address' python3 "$J" set-url "$P/custom.json" "$KEYED_URL" >/dev/null python3 "$J" set-auth "$P/custom.json" none >/dev/null expect_eq "$(code custom)" server-auth 'a keyed endpoint refuses the placeholder' cp "$P/custom.json" "$P/proxy.json" python3 "$J" set-url "$P/proxy.json" "$PROXY_URL" >/dev/null expect_eq "$(code custom proxy)" ok 'a proxy with no model list passes the lenient probe' run_cm preset new b1 --provider openrouter --blank expect_eq "$(code openrouter b1)" no-models 'a blank preset cannot be switched to' finish