#!/usr/bin/env bash # A real switch - into the sandbox's own settings.json - and editing the preset # in use. --yes because the machine running the tests may well have Claude Code # sessions open; with --yes the CLI proceeds and leaves them alone. . "$(dirname "$0")/../lib.sh" start_fake S="$CLAUDE_CONFIG_DIR/settings.json" ready_preset ollama "$OLLAMA_URL" run_cm ollama --yes expect_rc 0 'switch to ollama' expect_eq "$(jget "$S" env.ANTHROPIC_BASE_URL)" "$OLLAMA_URL" 'base url written' expect_eq "$(jget "$S" env.ANTHROPIC_AUTH_TOKEN)" ollama 'placeholder token written' expect_eq "$(jget "$S" env.ANTHROPIC_DEFAULT_OPUS_MODEL)" qwen3-coder 'tier mapped' expect_eq "$(jget "$S" env.CLAUDE_CODE_MAX_CONTEXT_TOKENS)" 65536 'context declared' expect_eq "$(jget "$S" env.CLAUDE_CODE_ATTRIBUTION_HEADER)" 0 'extra env written' expect_eq "$(jget "$CM_ROOT/state.json" mode)" ollama 'state records the mode' expect_eq "$(jget "$CM_ROOT/health.json" preset)" ollama 'health.json follows' run_cm anthropic --yes expect_rc 0 'switch back to anthropic' expect_eq "$(jget "$S" env.ANTHROPIC_BASE_URL)" '' 'gateway env removed' expect_eq "$(jget "$S" env.CLAUDE_CODE_ATTRIBUTION_HEADER)" '' 'including the extra env' # The preset in use: a tier edit re-applies without asking about sessions. set_state openrouter default run_cm preset set default sonnet test/model-c --force expect_rc 0 'a tier edit on the active preset re-applies' expect_no_out 'refusing to switch while sessions are running' 'without the sessions prompt' expect_eq "$(jget "$S" env.ANTHROPIC_DEFAULT_SONNET_MODEL)" test/model-c 'and reaches settings.json' run_cm preset set default opus anthropic/claude-opus-5 --force expect_rc 1 'the cost guard still refuses an Anthropic model' expect_out 'saved, but re-applying the active preset failed' 'and says the edit was saved' finish