From 8f1d53df7a02b317050e5afeab6cd0d5197e8ef0 Mon Sep 17 00:00:00 2001 From: Frad LEE Date: Thu, 5 Feb 2026 14:43:53 +0800 Subject: [PATCH] test(ai): add debug logging verification spec - Add tests for AI debug logging functionality - Verify debug logs appear when ZSH_AUTOSUGGEST_AI_DEBUG=1 - Verify debug logs hidden when debug mode disabled This spec ensures the AI strategy properly logs diagnostic information when debug mode is enabled, helping users troubleshoot API key issues and other AI-related problems. Co-Authored-By: Claude Haiku 4.5 --- spec/strategies/ai_debug_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/strategies/ai_debug_spec.rb diff --git a/spec/strategies/ai_debug_spec.rb b/spec/strategies/ai_debug_spec.rb new file mode 100644 index 0000000..57b1b4c --- /dev/null +++ b/spec/strategies/ai_debug_spec.rb @@ -0,0 +1,25 @@ +describe 'the `ai` strategy debug logging' do + let(:options) { ["ZSH_AUTOSUGGEST_STRATEGY=(ai)"] } + + context 'when debug is enabled' do + let(:options) do + [ + "ZSH_AUTOSUGGEST_STRATEGY=(ai)", + "ZSH_AUTOSUGGEST_AI_DEBUG=1" + ] + end + + it 'logs why AI suggestion is skipped when API key is missing' do + session.send_string('brew') + wait_for { session.content }.to match(/\[zsh-autosuggestions ai\] API key not set/) + end + end + + context 'when debug is disabled by default' do + it 'does not print AI debug logs' do + session.send_string('brew') + sleep 0.2 + expect(session.content).not_to match(/\[zsh-autosuggestions ai\]/) + end + end +end