describe 'the `ai` suggestion strategy' do let(:options) { ["ZSH_AUTOSUGGEST_STRATEGY=(ai history)"] } let(:before_sourcing) do -> { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { return 1 }') } end it 'falls through to next strategy' do with_history('git status') do session.send_string('git st') wait_for { session.content }.to eq('git status') end end end context 'when API returns HTTP error' do let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_STRATEGY=(ai history)"] } let(:before_sourcing) do -> { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { return 1 }') } end it 'uses history when AI fails' do with_history('git status --long') do session.send_string('git st') wait_for { session.content }.to eq('git status --long') end end end end context 'prompt artifact stripping' do let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_STRATEGY=(ai)"] } let(:before_sourcing) do -> { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { if [[ "$*" == *"max-time"* ]]; then cat < { session.run_command('curl() { local url="" for arg in "$@"; do if [[ "$arg" == http* ]]; then url="$arg" break fi done if [[ "$url" == */chat/completions ]]; then cat < { session.run_command('curl() { local data="" for arg in "$@"; do if [[ "$arg" == -d ]]; then shift data="$1" break fi shift done if [[ "$data" == *"Directory contents"* ]]; then cat < { session.run_command('curl() { local data="" for arg in "$@"; do if [[ "$arg" == -d ]]; then shift data="$1" break fi shift done if [[ "$data" == *"prediction engine"* ]]; then cat < { session.run_command('curl() { local data="" for arg in "$@"; do if [[ "$arg" == -d ]]; then shift data="$1" break fi shift done if [[ "$data" == *"\"temperature\": 0.5"* ]]; then cat <