From 540d805bd917a37d0fafa5393f3bfc7e3603570e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 01:03:13 -0500 Subject: test: add gloss orchestration core test suite (red phase) Two test files for the orchestration core. All 13 tests fail at this commit because the implementation is still stubbed. `gloss--orchestrate-fetch-result' gets full N/B/E coverage on the decision matrix: single def, multi def, the >1 boundary, empty defs with each combination of :no-defs and :failed populated, and the all-empty degenerate case. `gloss--lookup-flow' covers cache hit (no fetch), cache miss with one def (auto-save), cache miss with multiple (picker), cancelled picker (no save), no-defs error, and the force-fetch override that bypasses the cache. Mocks live at network and UI boundaries; persistence runs against a real temp glossary so the save side effect is validated. --- tests/test-gloss--orchestrate-fetch-result.el | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/test-gloss--orchestrate-fetch-result.el (limited to 'tests/test-gloss--orchestrate-fetch-result.el') diff --git a/tests/test-gloss--orchestrate-fetch-result.el b/tests/test-gloss--orchestrate-fetch-result.el new file mode 100644 index 0000000..b4a4cf8 --- /dev/null +++ b/tests/test-gloss--orchestrate-fetch-result.el @@ -0,0 +1,67 @@ +;;; test-gloss--orchestrate-fetch-result.el --- Tests for gloss--orchestrate-fetch-result -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; Tests for the pure pattern-matcher `gloss--orchestrate-fetch-result'. +;; It maps a `gloss-fetch-definitions' result plist to a decision +;; symbol that the lookup flow then dispatches on. Full N/B/E +;; coverage on the full decision matrix. + +;;; Code: + +(require 'ert) +(require 'gloss) + +(ert-deftest test-gloss-orchestrate-fetch-result-single-def-returns-auto-save () + "Normal: exactly one definition returns :auto-save." + (let ((result '(:defs ((:source wiktionary :text "Only sense.")) + :no-defs nil + :failed nil))) + (should (eq (gloss--orchestrate-fetch-result result) :auto-save)))) + +(ert-deftest test-gloss-orchestrate-fetch-result-multi-def-returns-pick () + "Normal: more than one definition returns :pick." + (let ((result '(:defs ((:source wiktionary :text "First.") + (:source wiktionary :text "Second.") + (:source wiktionary :text "Third.")) + :no-defs nil + :failed nil))) + (should (eq (gloss--orchestrate-fetch-result result) :pick)))) + +(ert-deftest test-gloss-orchestrate-fetch-result-two-defs-returns-pick () + "Boundary: exactly two definitions returns :pick (above the >1 threshold)." + (let ((result '(:defs ((:source wiktionary :text "A.") + (:source wiktionary :text "B.")) + :no-defs nil + :failed nil))) + (should (eq (gloss--orchestrate-fetch-result result) :pick)))) + +(ert-deftest test-gloss-orchestrate-fetch-result-only-no-defs-returns-error-no-defs () + "Boundary: no defs and only :no-defs sources returns :error-no-defs." + (let ((result '(:defs nil + :no-defs (wiktionary) + :failed nil))) + (should (eq (gloss--orchestrate-fetch-result result) :error-no-defs)))) + +(ert-deftest test-gloss-orchestrate-fetch-result-only-failed-returns-error-failed () + "Boundary: no defs and only :failed sources returns :error-failed." + (let ((result '(:defs nil + :no-defs nil + :failed (wiktionary)))) + (should (eq (gloss--orchestrate-fetch-result result) :error-failed)))) + +(ert-deftest test-gloss-orchestrate-fetch-result-mixed-no-defs-and-failed-returns-error-mixed () + "Boundary: no defs but BOTH :no-defs and :failed populated returns :error-mixed." + (let ((result '(:defs nil + :no-defs (wiktionary) + :failed (dictionary-api)))) + (should (eq (gloss--orchestrate-fetch-result result) :error-mixed)))) + +(ert-deftest test-gloss-orchestrate-fetch-result-all-empty-returns-error-no-defs () + "Error: degenerate result with all three keys empty returns :error-no-defs." + (let ((result '(:defs nil :no-defs nil :failed nil))) + (should (eq (gloss--orchestrate-fetch-result result) :error-no-defs)))) + +(provide 'test-gloss--orchestrate-fetch-result) +;;; test-gloss--orchestrate-fetch-result.el ends here -- cgit v1.2.3