From 44a9a02a944f2cc05bb888792f6d243a65fb736b Mon Sep 17 00:00:00 2001 From: dschlueter Date: Sun, 28 Jun 2026 04:03:53 +0200 Subject: [PATCH] test: add profile-logic and installer test suite bash tests/test_profiles.sh (or: make test) Covers the bug classes that surfaced during recent work, without any external dependencies or network: Profile logic (stub `claude` captures exported ANTHROPIC_* env): - pro profile clears stale ANTHROPIC env and launches claude - glm/free profiles export BASE_URL/AUTH_TOKEN/MODEL correctly - error paths: missing OPENROUTER_API_KEY, unknown profile, bad mode each exit 1 Installer symlink logic (isolated temp HOME, throwaway clone): - S1 broken/dangling symlink -> repointed via ln -sfn (was fatal before) - S2 real directory at target -> warning, preserved (was silent) - S3 free path -> new symlink created - S4 existing symlink -> repointed All tests use temp dirs for HOME and a throwaway repo clone, so the real working tree is never touched. Co-Authored-By: Claude --- Makefile | 3 + tests/test_profiles.sh | 222 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 Makefile create mode 100755 tests/test_profiles.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bad6abd --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: test +test: + @bash tests/test_profiles.sh diff --git a/tests/test_profiles.sh b/tests/test_profiles.sh new file mode 100755 index 0000000..f824f6a --- /dev/null +++ b/tests/test_profiles.sh @@ -0,0 +1,222 @@ +#!/usr/bin/env bash +# +# Tests for claude-launcher-profiles (profile logic + installer). +# +# Design: +# - A stub `claude` captures the ANTHROPIC_* env vars the launcher exports, +# so we can assert on them without a real Claude Code or network. +# - launch_profile calls `exec claude`, so every invocation runs inside a +# subshell — the exec then only ends the subshell, not the test runner. +# - Installer tests run with HOME pointed at a temp dir and a throwaway repo +# clone, so they never touch the real repo working tree. +# +# Run: bash tests/test_profiles.sh +# or: make test + +set -u + +REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +TESTS_RUN=0 +TESTS_FAIL=0 +FAILED_CASES=() + +# ---- assert helpers -------------------------------------------------------- + +assert_eq() { + # assert_eq