aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-04 13:27:39 -0500
committerCraig Jennings <c@cjennings.net>2026-04-04 13:27:39 -0500
commit0bbed459fb60f1b9ebe0e137527aa44b75c4835e (patch)
treef6117366fd616127997a2510ba984954e8b4a090
parentde99a2930bbe65d7c2ea04656caa18823068c182 (diff)
downloademacs-wttrin-0bbed459fb60f1b9ebe0e137527aa44b75c4835e.tar.gz
emacs-wttrin-0bbed459fb60f1b9ebe0e137527aa44b75c4835e.zip
fix: debug-wttrin-show-raw serves cached data instead of fetching
A debug command should show what the API currently returns, not a cached copy. Bind wttrin--force-refresh to t so the fetch always bypasses the cache.
-rw-r--r--tests/test-debug-wttrin-show-raw.el17
-rw-r--r--wttrin-debug.el10
2 files changed, 23 insertions, 4 deletions
diff --git a/tests/test-debug-wttrin-show-raw.el b/tests/test-debug-wttrin-show-raw.el
index b447292..67e50ca 100644
--- a/tests/test-debug-wttrin-show-raw.el
+++ b/tests/test-debug-wttrin-show-raw.el
@@ -100,5 +100,22 @@
(should (get-buffer "*wttrin-debug*")))
(test-debug-wttrin-show-raw-teardown)))
+(ert-deftest test-debug-wttrin-show-raw-normal-always-fetches-fresh ()
+ "A debug command should always fetch from the API, not serve cached data.
+When debugging, the user needs to see what the API currently returns."
+ (test-debug-wttrin-show-raw-setup)
+ (unwind-protect
+ (let ((force-refresh-was-set nil))
+ ;; Seed cache so there IS data to serve
+ (testutil-wttrin-add-to-cache "Paris" "old cached data" 300)
+ (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch)
+ (lambda (_location callback)
+ (setq force-refresh-was-set wttrin--force-refresh)
+ (funcall callback "fresh from API"))))
+ (debug-wttrin-show-raw "Paris")
+ ;; Force-refresh should have been active during the fetch
+ (should force-refresh-was-set)))
+ (test-debug-wttrin-show-raw-teardown)))
+
(provide 'test-debug-wttrin-show-raw)
;;; test-debug-wttrin-show-raw.el ends here
diff --git a/wttrin-debug.el b/wttrin-debug.el
index 57de3a4..6bb281f 100644
--- a/wttrin-debug.el
+++ b/wttrin-debug.el
@@ -39,10 +39,12 @@
;;;###autoload
(defun debug-wttrin-show-raw (location)
"Fetch and display raw wttr.in data for LOCATION with line numbers.
-This is useful for debugging header parsing issues."
+This is useful for debugging header parsing issues.
+Always fetches fresh data from the API, bypassing cache."
(interactive "sLocation: ")
- (wttrin--get-cached-or-fetch
- location
+ (let ((wttrin--force-refresh t))
+ (wttrin--get-cached-or-fetch
+ location
(lambda (raw-string)
(with-current-buffer (get-buffer-create "*wttrin-debug*")
(erase-buffer)
@@ -56,7 +58,7 @@ This is useful for debugging header parsing issues."
(setq line-num (1+ line-num))
(forward-line 1)))
(goto-char (point-min))
- (switch-to-buffer (current-buffer))))))
+ (switch-to-buffer (current-buffer)))))))
;;;###autoload
(defun debug-wttrin-enable ()