Files
claude-mode/tests/cli/test_preflight.sh
T
smoidoandClaude Opus 5 51e42823d1 Tests, licence, and the tooling to keep the repo consistent
A test suite with no dependencies beyond bash and the Python standard
library, run by one command:

  scripts/test.sh                    (or: make test)
  scripts/test.sh --windows [host]   adds the PowerShell suite over SSH

- tests/static.sh: script syntax, JSON validity, VERSION against the widget
  manifest and CHANGELOG, providers.json against the kinds, probes and checks
  the code implements (and ids that would shadow a command), qmllint and
  shellcheck when installed.
- tests/python: unit tests for cm-json.py - providers and the column contract
  bash depends on, the original three scaffolds byte for byte, every
  catalogue parser and the cache, session scan/dismiss/repair, rename,
  defaults, health, the cost guard.
- tests/cli: the CLI in a sandbox with its own HOME, CM_ROOT,
  CLAUDE_CONFIG_DIR and a file-only vault, against fake Ollama, LM Studio,
  keyed-gateway and proxy servers - preflight, presets, models, doctor, a real
  switch, sessions, and the key helper under a rename race.
- tests/windows: the same idea on a Windows host, with USERPROFILE pointed at
  a temp folder so the real install is never touched.

Also: MIT licence, CHANGELOG.md reconstructed from history, .editorconfig and
.gitattributes pinning LF everywhere (what the tree already is), and
scripts/bump-version.sh, since the version lives in two files and drifted
once before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 01:42:38 +03:00

35 lines
1.4 KiB
Bash
Executable File

#!/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