From 4d64437433ed221a08a5258243c01e3a05980db9 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 29 Jun 2026 08:42:10 -0400 Subject: feat(completion): annotate the file-basename pickers with size and date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eight completing-read pickers listed bare file basenames, so marginalia had no directory to resolve and couldn't annotate them. Add cj/completion-file-annotator to system-lib — an annotation-function factory that takes a candidate->path resolver and yields a size + modification-date suffix (or "dir" for directories, nil for missing files). Wire each picker through cj/completion-table-annotated with a per-site category and resolver: timer sounds, drill flashcards, Info files, the test-runner focus add/remove, vc clone dirs, hugo drafts, and agenda projects (the project's todo.org mtime). music-config's existing completion table gains the category and annotator inline, keeping its sort metadata. The candidate strings and every return value are unchanged — this only adds completion metadata — so all downstream logic is untouched. The six modules that didn't already pull in system-lib now require it. Tests: cj/completion-file-annotator gets Normal/Boundary/Error coverage (file, directory, nil path, missing file). Full suite green at 5394. Claude-Session: https://claude.ai/code/session_014fyKMTTqLrZpL3rDF3dYc3 --- .../test-system-lib--completion-file-annotator.el | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test-system-lib--completion-file-annotator.el (limited to 'tests') diff --git a/tests/test-system-lib--completion-file-annotator.el b/tests/test-system-lib--completion-file-annotator.el new file mode 100644 index 000000000..9e1f4aa4a --- /dev/null +++ b/tests/test-system-lib--completion-file-annotator.el @@ -0,0 +1,54 @@ +;;; test-system-lib--completion-file-annotator.el --- Tests for cj/completion-file-annotator -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for `cj/completion-file-annotator', the annotation-function +;; factory used to annotate file-basename completion pickers with size and +;; modification date. + +;;; Code: + +(require 'ert) +(require 'system-lib) + +(ert-deftest test-system-lib-completion-file-annotator-normal-file-shows-size-and-date () + "Normal: a regular file is annotated with a size and an ISO date." + (let ((file (make-temp-file "cfa-test-" nil ".txt" "hello world"))) + (unwind-protect + (let* ((annotate (cj/completion-file-annotator + (lambda (_cand) file))) + (result (funcall annotate "anything"))) + (should (stringp result)) + ;; file-size-human-readable of 11 bytes is "11" + (should (string-match-p "11" result)) + ;; ISO date for the file's mtime + (should (string-match-p + (format-time-string "%Y-%m-%d" + (file-attribute-modification-time + (file-attributes file))) + result))) + (delete-file file)))) + +(ert-deftest test-system-lib-completion-file-annotator-boundary-directory-marked-dir () + "Boundary: a directory candidate is annotated with the `dir' marker." + (let ((dir (make-temp-file "cfa-dir-" t))) + (unwind-protect + (let* ((annotate (cj/completion-file-annotator (lambda (_c) dir))) + (result (funcall annotate "d"))) + (should (stringp result)) + (should (string-match-p "dir" result))) + (delete-directory dir t)))) + +(ert-deftest test-system-lib-completion-file-annotator-error-nil-path-returns-nil () + "Error: a candidate whose path-resolver returns nil yields no annotation." + (let ((annotate (cj/completion-file-annotator (lambda (_c) nil)))) + (should (null (funcall annotate "missing"))))) + +(ert-deftest test-system-lib-completion-file-annotator-error-missing-file-returns-nil () + "Error: a path that does not exist yields no annotation." + (let* ((path (expand-file-name "definitely-not-here-12345.txt" + temporary-file-directory)) + (annotate (cj/completion-file-annotator (lambda (_c) path)))) + (should (null (funcall annotate "gone"))))) + +(provide 'test-system-lib--completion-file-annotator) +;;; test-system-lib--completion-file-annotator.el ends here -- cgit v1.2.3