diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-16 01:39:57 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-16 01:39:57 -0500 |
| commit | 73e63b6c6850f8e14d8374c7bf6b127971cfbb08 (patch) | |
| tree | b446f4ac63901d75376664abfd7b8cb5f8ac436a /gptel-tools/read_buffer.el | |
| parent | 2a98feaf1285b495e7d6d1eed2abf02620188e29 (diff) | |
| download | dotemacs-73e63b6c6850f8e14d8374c7bf6b127971cfbb08.tar.gz dotemacs-73e63b6c6850f8e14d8374c7bf6b127971cfbb08.zip | |
test(gptel-tools): cover the helpers across the five remaining tools
The gptel-tools files had zero direct coverage outside of
`update_text_file`, which landed with its rewrite earlier this
session. This commit adds 52 tests across the five other tools.
For three of the tools the helpers were already top-level defuns
(`read_text_file`, `list_directory_files`, `move_to_trash`). The
other two had their main bodies inlined into the `gptel-make-tool`
lambda -- I extracted them so the work is testable without mocking
gptel itself:
read_buffer.el -> `cj/read-buffer--get-content`
write_text_file.el -> `cj/write-text-file--run` plus
`--validate-path`, `--backup-name`,
`--ensure-parent`
Test files, by tool:
- read_buffer.el (5 tests): normal, empty, buffer-object,
text-property-stripping, missing buffer.
- write_text_file.el (10 tests): validate-path, backup-name
shape, ensure-parent (creates missing / rejects unwritable), run
with normal / overwrite / existing-no-overwrite / empty content /
outside-home.
- read_text_file.el (12 tests): validate-file-path (normal +
three error shapes), metadata plist shape, size limits (no-op /
hard cap / warning bypass with no-confirm), binary detection
(text vs null-byte), special-type EPUB and generic-binary paths.
- list_directory_files.el (15 tests): mode-to-permissions (file /
dir / executable), get-file-info (file / directory), extension
filter (keep / drop / always-dir / nil-extension), format-file-
entry, list-directory flat / recursive / error, format-output
with and without files.
- move_to_trash.el (10 tests): unique-name (no conflict /
conflict with timestamp / no-extension), validate-path (HOME / /tmp
/ outside / critical-dir / missing), perform on file and
directory.
Each test file uses the same load-path / gptel-stub idiom
(`eval-and-compile` block, gptel stub when the real package isn't
available) so the byte-compile hook is happy.
Diffstat (limited to 'gptel-tools/read_buffer.el')
| -rw-r--r-- | gptel-tools/read_buffer.el | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/gptel-tools/read_buffer.el b/gptel-tools/read_buffer.el index d01cee71..1b4fc904 100644 --- a/gptel-tools/read_buffer.el +++ b/gptel-tools/read_buffer.el @@ -1,27 +1,31 @@ ;;; read_buffer.el --- Read buffer tool for GPTel -*- coding: utf-8; lexical-binding: t; -*- ;;; Commentary: -;; +;; Gptel tool that returns the contents of an Emacs buffer by name. ;;; Code: (require 'gptel) +(defun cj/read-buffer--get-content (buffer) + "Return the substring of BUFFER from `point-min' to `point-max'. +BUFFER may be a buffer object or a buffer name string. Signal an +error when no live buffer matches." + (unless (buffer-live-p (get-buffer buffer)) + (error "Buffer %s is not live" buffer)) + (with-current-buffer buffer + (buffer-substring-no-properties (point-min) (point-max)))) + (gptel-make-tool :name "read_buffer" - :function (lambda (buffer) - (unless (buffer-live-p (get-buffer buffer)) - (error "Error: buffer %s is not live" buffer)) - (with-current-buffer buffer - (buffer-substring-no-properties (point-min) (point-max)))) + :function (lambda (buffer) (cj/read-buffer--get-content buffer)) :description "return the contents of an emacs buffer" :args (list '(:name "buffer" - :type string ; :type value must be a symbol - :description "the name of the buffer whose contents are to be retrieved")) + :type string + :description "the name of the buffer whose contents are to be retrieved")) :category "emacs") -;; Automatically add to gptel-tools on load (add-to-list 'gptel-tools (gptel-get-tool '("emacs" "read_buffer"))) (provide 'read_buffer) -;;; read_buffer.el ends here. +;;; read_buffer.el ends here |
