From 9e44650fa240d4688ea12edad1d805c49e6ae0cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:46:56 +0000 Subject: [PATCH 1/3] Initial plan From 15d9ad452c3217fcde29dec8b34d56f6e6749a86 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:57:57 +0000 Subject: [PATCH 2/3] Replace grep-based weather tests with runtime behavior tests Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com> --- spec/lib/display_spec.sh | 125 ++++++++++++++++++++++++++++++++------- 1 file changed, 103 insertions(+), 22 deletions(-) diff --git a/spec/lib/display_spec.sh b/spec/lib/display_spec.sh index 13e11f1..e02bc02 100644 --- a/spec/lib/display_spec.sh +++ b/spec/lib/display_spec.sh @@ -51,28 +51,109 @@ Describe 'lib/app/display.sh - Display Functions' The output should not be blank End - It 'requires GOODMORNING_WEATHER_LOCATION to be set' - When call grep 'GOODMORNING_WEATHER_LOCATION' "$PROJECT_ROOT/lib/app/display.sh" - The status should be success - The output should not be blank - End - - It 'uses location in wttr.in URL' - When call grep 'wttr.in/\${location}' "$PROJECT_ROOT/lib/app/display.sh" - The status should be success - The output should not be blank - End - - It 'shows setup message when location not configured' - When call grep 'show_setup_message.*GOODMORNING_WEATHER_LOCATION' "$PROJECT_ROOT/lib/app/display.sh" - The status should be success - The output should not be blank - End - - It 'handles not found response from API' - When call grep 'not found:' "$PROJECT_ROOT/lib/app/display.sh" - The status should be success - The output should not be blank + # Integration tests with mocked fetch_with_spinner + It 'returns early when GOODMORNING_WEATHER_LOCATION is not set' + GOODMORNING_WEATHER_LOCATION="" + SHOW_SETUP_MESSAGES="true" + When call show_weather + The status should be success + The output should include "Set GOODMORNING_WEATHER_LOCATION" + End + + Context 'with mocked fetch_with_spinner' + setup_basic_mock() { + fetch_with_spinner() { + shift # Skip the message parameter + echo "$MOCK_WEATHER_RESPONSE" + } + } + + Before 'setup_basic_mock' + + It 'successfully fetches weather when location is set' + GOODMORNING_WEATHER_LOCATION="San_Francisco" + MOCK_WEATHER_RESPONSE="San Francisco ☀️ +72°F" + When call show_weather + The status should be success + The output should include "☀️" + The output should include "+72°F" + End + + It 'handles not found response from API' + GOODMORNING_WEATHER_LOCATION="InvalidCity123" + MOCK_WEATHER_RESPONSE="not found: InvalidCity123" + When call show_weather + The status should be success + The output should include "Weather unavailable for" + The output should include "InvalidCity123" + End + + It 'handles empty response from API' + GOODMORNING_WEATHER_LOCATION="TestCity" + MOCK_WEATHER_RESPONSE="" + When call show_weather + The status should be success + The output should include "Weather unavailable for" + The output should include "TestCity" + End + End + + Context 'URL and parameter validation' + It 'uses location in wttr.in URL construction' + setup_url_check() { + fetch_with_spinner() { + shift # Skip message parameter + # Verify URL contains location + for arg in "$@"; do + if [[ "$arg" == *"wttr.in/New_York"* ]]; then + echo "New York 🌧️ +65°F" + return 0 + fi + done + echo "URL validation failed" >&2 + return 1 + } + } + + setup_url_check + GOODMORNING_WEATHER_LOCATION="New_York" + When call show_weather + The status should be success + The output should include "🌧️" + End + + It 'passes correct parameters to curl command' + setup_param_check() { + fetch_with_spinner() { + shift # Skip message parameter + # Check for expected curl command and flags + local has_curl=false + local has_silent=false + local has_timeout=false + local has_url=false + + for arg in "$@"; do + [[ "$arg" == "curl" ]] && has_curl=true + [[ "$arg" == "-s" ]] && has_silent=true + [[ "$arg" == "--max-time" ]] && has_timeout=true + [[ "$arg" == *"wttr.in/Boston"* ]] && has_url=true + done + + if $has_curl && $has_silent && $has_timeout && $has_url; then + echo "Boston ⛅ +68°F" + return 0 + fi + echo "Missing expected curl parameters" >&2 + return 1 + } + } + + setup_param_check + GOODMORNING_WEATHER_LOCATION="Boston" + When call show_weather + The status should be success + The output should include "⛅" + End End End From 0643f383ec72b7b2e9f78c4698369dee19f9cbb5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:59:13 +0000 Subject: [PATCH 3/3] Add validation to basic mock to verify curl command is passed Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com> --- spec/lib/display_spec.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/lib/display_spec.sh b/spec/lib/display_spec.sh index e02bc02..1b72c67 100644 --- a/spec/lib/display_spec.sh +++ b/spec/lib/display_spec.sh @@ -64,6 +64,11 @@ Describe 'lib/app/display.sh - Display Functions' setup_basic_mock() { fetch_with_spinner() { shift # Skip the message parameter + # Verify we're being called with curl command + if [ "$1" != "curl" ]; then + echo "Expected curl command, got: $1" >&2 + return 1 + fi echo "$MOCK_WEATHER_RESPONSE" } }