diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-23 20:12:58 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-23 20:12:58 -0400 |
| commit | 10fa6f4e2e7150ad99827721ada1ae4badcc5e90 (patch) | |
| tree | 960065c8e69f1e7a4150ecf522e2f813c239b5ee /archive/gptel/tests/test-gptel-tools-git-log.el | |
| parent | f4cc70c69e7707dd4a686637e14885f5443fcca6 (diff) | |
| download | dotemacs-10fa6f4e2e7150ad99827721ada1ae4badcc5e90.tar.gz dotemacs-10fa6f4e2e7150ad99827721ada1ae4badcc5e90.zip | |
chore(ai): archive gptel and remove it from the live config
I archived gptel to archive/gptel/ since I rarely use it. Moved there: the six gptel modules (ai-config, ai-conversations, ai-conversations-browser, ai-mcp, ai-quick-ask, ai-rewrite), the gptel-tools/ directory, custom/gptel-prompts.el, their test files and utilities, and the four gptel-only specs.
Scrubbed from the live config: the ai-config require in init.el, which also drops the whole C-; a keymap; the gptel-mode emojify hook in font-config.el; the gptel-tools entries in the Makefile clean target and the coverage runner; and the gptel feature notes in README. Cancelled the open gptel tasks in todo.org (the AI Open Work issues, the feature-extension brainstorm, the velox gptel-magit bug).
ai-term stays. It is the ghostel Claude launcher, independent of gptel.
Verified: every module loads, a batch init launch reaches completion clean, and the full test suite shows only pre-existing coverage failures unrelated to this change.
Diffstat (limited to 'archive/gptel/tests/test-gptel-tools-git-log.el')
| -rw-r--r-- | archive/gptel/tests/test-gptel-tools-git-log.el | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/archive/gptel/tests/test-gptel-tools-git-log.el b/archive/gptel/tests/test-gptel-tools-git-log.el new file mode 100644 index 00000000..c0503039 --- /dev/null +++ b/archive/gptel/tests/test-gptel-tools-git-log.el @@ -0,0 +1,183 @@ +;;; test-gptel-tools-git-log.el --- Tests for git_log gptel tool -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests run against real temp git repos under HOME via `process-file'. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(eval-and-compile + (add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) + (add-to-list 'load-path (expand-file-name "gptel-tools" user-emacs-directory)) + (setq load-prefer-newer t) + (unless (featurep 'gptel) + (defvar gptel-tools nil) + (defun gptel-make-tool (&rest _args) nil) + (defun gptel-get-tool (&rest _args) nil) + (provide 'gptel))) + +(require 'git_log) + +;; ---------- helpers + +(defun test-gptel-tools-git-log--with-repo (commit-count fn) + "Create a temp git repo under HOME with COMMIT-COUNT empty commits. +Call FN with the absolute path, clean up after." + (let* ((name (format ".test-gptel-tools-git-log-%s" + (format-time-string "%s%N"))) + (dir (expand-file-name name "~"))) + (unwind-protect + (progn + (make-directory dir) + (let ((default-directory dir)) + (call-process "git" nil nil nil "init" "--quiet") + (call-process "git" nil nil nil "config" "user.email" "test@x") + (call-process "git" nil nil nil "config" "user.name" "Test") + (dotimes (i commit-count) + (let ((process-environment + (append + (list "GIT_AUTHOR_DATE=2000-01-01T00:00:00+0000" + "GIT_COMMITTER_DATE=2000-01-01T00:00:00+0000") + process-environment))) + (call-process "git" nil nil nil "commit" "--allow-empty" + "--quiet" "-m" (format "commit %d" i))))) + (funcall fn dir)) + (when (file-exists-p dir) (delete-directory dir t))))) + +;; ---------- effective-count + +(ert-deftest test-gptel-tools-git-log-effective-count-defaults-on-nil () + "Boundary: nil N → default count." + (should (= (cj/gptel-git-log--effective-count nil) + cj/gptel-git-log--default-count))) + +(ert-deftest test-gptel-tools-git-log-effective-count-defaults-on-non-integer () + "Boundary: non-integer N → default count." + (should (= (cj/gptel-git-log--effective-count "ten") + cj/gptel-git-log--default-count)) + (should (= (cj/gptel-git-log--effective-count 0.5) + cj/gptel-git-log--default-count))) + +(ert-deftest test-gptel-tools-git-log-effective-count-clamps-low () + "Boundary: N below 1 → default count." + (should (= (cj/gptel-git-log--effective-count 0) + cj/gptel-git-log--default-count)) + (should (= (cj/gptel-git-log--effective-count -5) + cj/gptel-git-log--default-count))) + +(ert-deftest test-gptel-tools-git-log-effective-count-caps-high () + "Boundary: N above max → max." + (should (= (cj/gptel-git-log--effective-count 1000) + cj/gptel-git-log--max-count))) + +(ert-deftest test-gptel-tools-git-log-effective-count-normal () + "Normal: a valid N passes through." + (should (= (cj/gptel-git-log--effective-count 5) 5))) + +;; ---------- validate-path + +(ert-deftest test-gptel-tools-git-log-validate-path-normal () + "Normal: validator accepts a git working tree." + (test-gptel-tools-git-log--with-repo + 1 + (lambda (dir) + (should (equal (cj/gptel-git-log--validate-path dir) dir))))) + +(ert-deftest test-gptel-tools-git-log-validate-path-error-outside-home () + "Error: path outside HOME signals." + (should-error (cj/gptel-git-log--validate-path "/etc"))) + +(ert-deftest test-gptel-tools-git-log-validate-path-error-not-a-repo () + "Error: directory outside any git working tree signals." + (let ((dir (make-temp-file + (expand-file-name ".test-gptel-tools-git-log-" "~") t))) + (unwind-protect + (should-error (cj/gptel-git-log--validate-path dir)) + (when (file-exists-p dir) (delete-directory dir t))))) + +(ert-deftest test-gptel-tools-git-log-validate-path-error-not-a-directory () + "Error: file paths are rejected." + (let ((file (make-temp-file + (expand-file-name ".test-gptel-tools-git-log-file-" "~")))) + (unwind-protect + (should-error (cj/gptel-git-log--validate-path file)) + (when (file-exists-p file) (delete-file file))))) + +(ert-deftest test-gptel-tools-git-log-validate-path-error-symlink-outside-home () + "Error: symlinked directories resolving outside HOME are rejected." + (let ((link (expand-file-name + (format ".test-gptel-tools-git-log-link-%s" + (format-time-string "%s%N")) + "~"))) + (unwind-protect + (progn + (make-symbolic-link "/tmp" link t) + (should-error (cj/gptel-git-log--validate-path link))) + (when (file-symlink-p link) (delete-file link))))) + +;; ---------- run + +(ert-deftest test-gptel-tools-git-log-run-default-count () + "Normal: default count limits output to that many commits." + (test-gptel-tools-git-log--with-repo + 30 + (lambda (dir) + (let* ((out (cj/gptel-git-log--run dir)) + (lines (split-string (string-trim out) "\n"))) + (should (= (length lines) cj/gptel-git-log--default-count)))))) + +(ert-deftest test-gptel-tools-git-log-run-honors-n () + "Normal: an explicit N limits output to N commits." + (test-gptel-tools-git-log--with-repo + 10 + (lambda (dir) + (let* ((out (cj/gptel-git-log--run dir 3)) + (lines (split-string (string-trim out) "\n"))) + (should (= (length lines) 3)))))) + +(ert-deftest test-gptel-tools-git-log-run-since-no-match () + "Boundary: --since filter with no matching commits returns marker." + (test-gptel-tools-git-log--with-repo + 1 + (lambda (dir) + (let ((out (cj/gptel-git-log--run dir 10 "2001-01-01"))) + (should (string-match-p "No commits" out)))))) + +(ert-deftest test-gptel-tools-git-log-run-error-on-git-log-failure () + "Error: non-zero git log exits are surfaced." + (test-gptel-tools-git-log--with-repo + 1 + (lambda (dir) + (cl-letf (((symbol-function 'process-file) + (lambda (program infile destination display &rest args) + (if (member "log" args) + (progn + (when (bufferp destination) + (with-current-buffer destination (insert "bad log"))) + 2) + (apply #'call-process program infile destination display args))))) + (should-error (cj/gptel-git-log--run dir)))))) + +(ert-deftest test-gptel-tools-git-log-run-empty-repo () + "Boundary: a repo with no commits returns the empty-result marker." + (let* ((name (format ".test-gptel-tools-git-log-empty-%s" + (format-time-string "%s%N"))) + (dir (expand-file-name name "~"))) + (unwind-protect + (progn + (make-directory dir) + (let ((default-directory dir)) + (call-process "git" nil nil nil "init" "--quiet")) + ;; git log on a no-commits repo errors in some versions, but + ;; our wrapper turns "no commits" into the no-match marker. + (let ((res (ignore-errors (cj/gptel-git-log--run dir)))) + ;; Either path is acceptable: error captured (nil) or the + ;; explicit "No commits matching" marker. + (should (or (null res) + (string-match-p "No commits" res))))) + (when (file-exists-p dir) (delete-directory dir t))))) + +(provide 'test-gptel-tools-git-log) +;;; test-gptel-tools-git-log.el ends here |
