From 01b75599a500d6276a962b47744166abb25d846c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 28 Apr 2026 19:13:05 -0500 Subject: refactor: switch gloss-fetch result to uniform plist shape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous shape (:ok DEFS) | (:empty :no-defs (...) :failed (...)) was malformed as a plist. The :empty tag at position 0 shifted the plist alignment. plist-get on :no-defs or :failed returned nil. Tests had to use (plist-get (cdr result) ...) as a workaround. The new shape is a uniform plist with all three keys always present: (:defs DEFS :no-defs (SYM ...) :failed (SYM ...)). Consumers branch on whether :defs is non-empty. There is no tag. plist-get works uniformly across success and empty cases. Updated gloss-fetch.el (rollup function and docstrings), 7 test files, and the design doc (docs/design/gloss.org ยง Error Handling). Tested by `make test`. 65 tests pass in 0.36 seconds. --- tests/test-gloss-fetch--multi-source-walks-registry.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/test-gloss-fetch--multi-source-walks-registry.el') diff --git a/tests/test-gloss-fetch--multi-source-walks-registry.el b/tests/test-gloss-fetch--multi-source-walks-registry.el index cb2b730..482cc40 100644 --- a/tests/test-gloss-fetch--multi-source-walks-registry.el +++ b/tests/test-gloss-fetch--multi-source-walks-registry.el @@ -42,12 +42,12 @@ (list :source 'beta :status :server-error :reason "HTTP 503"))))) (gloss-fetch-sources '(alpha beta)) (result (gloss-fetch-definitions "x"))) - (should (eq (car result) :empty)) - (should (member 'alpha (plist-get (cdr result) :no-defs))) - (should (member 'beta (plist-get (cdr result) :failed))))) + (should-not (plist-get result :defs)) + (should (member 'alpha (plist-get result :no-defs))) + (should (member 'beta (plist-get result :failed))))) (ert-deftest test-gloss-fetch-rollup-any-ok-yields-ok () - "Boundary: if any source returns :ok with defs, the rollup is (:ok DEFS)." + "Boundary: if any source returns :ok with defs, the rollup has non-empty :defs." (let* ((gloss-fetch--sources `((alpha . ,(lambda (_term) (list :source 'alpha :status :no-defs :reason "404"))) @@ -56,9 +56,9 @@ (list (list :source 'beta :text "got it"))))))) (gloss-fetch-sources '(alpha beta)) (result (gloss-fetch-definitions "x"))) - (should (eq (car result) :ok)) - (should (= 1 (length (plist-get result :ok)))) - (should (equal "got it" (plist-get (car (plist-get result :ok)) :text))))) + (should (plist-get result :defs)) + (should (= 1 (length (plist-get result :defs)))) + (should (equal "got it" (plist-get (car (plist-get result :defs)) :text))))) (ert-deftest test-gloss-fetch-collect-skips-source-not-in-defcustom () "Error: a source registered in `gloss-fetch--sources' but not in `gloss-fetch-sources' is skipped." -- cgit v1.2.3