From 0bbed459fb60f1b9ebe0e137527aa44b75c4835e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 13:27:39 -0500 Subject: 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. --- tests/test-debug-wttrin-show-raw.el | 17 +++++++++++++++++ wttrin-debug.el | 10 ++++++---- 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 () -- cgit v1.2.3