From 73e63b6c6850f8e14d8374c7bf6b127971cfbb08 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 16 May 2026 01:39:57 -0500 Subject: 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. --- todo.org | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'todo.org') diff --git a/todo.org b/todo.org index 8313d8bc..c0a9fa0e 100644 --- a/todo.org +++ b/todo.org @@ -2637,18 +2637,39 @@ the install-once guard for the post-response hook, and the save/delete interactive entry points exercised via =cl-letf= stubs. Per-test temp directories; no writes outside them. -*** TODO [#B] Add ERT coverage for gptel-tools .el files :tests: - -The six tool files have zero direct coverage. Focus on the pure helpers (the interactive =gptel-make-tool= entry points get smoke coverage only): - -- =read_text_file.el= — =cj/validate-file-path=, =cj/get-file-metadata=, =cj/check-file-size-limits=, =cj/detect-binary-file=, =cj/handle-special-file-types=. -- =update_text_file.el= — =cj/build-sed-command= (each operation × Normal / Boundary / Error), backup-naming behavior. -- =write_text_file.el= — overwrite-vs-error path, backup naming, parent-directory creation. -- =list_directory_files.el= — =--mode-to-permissions=, =--get-file-info=, =--filter-by-extension=, =--format-file-entry=, recursive vs flat listing on a temp dir. -- =move_to_trash.el= — =gptel--move-to-trash-validate-path= (home/tmp allowed, anywhere else rejected), =gptel--move-to-trash-generate-unique-name= name-conflict suffixing. -- =read_buffer.el= — small smoke test that =read_buffer= returns the body of an existing buffer and errors on a nonexistent name. - -Skip mocking =gptel-make-tool= itself; cover the helpers it wraps. +*** 2026-05-16 Sat @ 01:39:11 -0500 Added ERT coverage for the gptel-tools .el files + +Five new test files cover the five remaining gptel tools beyond +=update_text_file= (which was tested with its rewrite): + +- =tests/test-gptel-tools-read-buffer.el= -- 5 tests for the new + =cj/read-buffer--get-content= helper extracted from the + =gptel-make-tool= lambda. +- =tests/test-gptel-tools-write-text-file.el= -- 10 tests for the + helpers extracted from =write_text_file.el= (validate-path, + backup-name, ensure-parent, run with normal/overwrite/error + paths). +- =tests/test-gptel-tools-read-text-file.el= -- 12 tests for the + pre-existing helpers: =cj/validate-file-path=, + =cj/get-file-metadata=, =cj/check-file-size-limits=, + =cj/detect-binary-file=, =cj/handle-special-file-types=. +- =tests/test-gptel-tools-list-directory-files.el= -- 15 tests for + the =list-directory-files--*= helpers (mode-to-permissions for + files/dirs/executables, get-file-info, extension filter, formatter, + recursive vs flat listing, error path). +- =tests/test-gptel-tools-move-to-trash.el= -- 10 tests for the + =gptel--move-to-trash-*= helpers (unique-name generation with and + without extension, path validation gating HOME and /tmp, critical + directory rejection, perform on files and directories). + +Two small refactors landed first to make the tooling testable: +=read_buffer.el= and =write_text_file.el= had their main bodies +inlined into the =gptel-make-tool= lambdas; I extracted them into +=cj/read-buffer--get-content= and =cj/write-text-file--run= (plus +=--validate-path=, =--backup-name=, =--ensure-parent=) following the +Internal/Wrapper split documented in =elisp-testing.md=. + +52 new tests, all green. *** TODO [#C] Research and shortlist additional gptel tools :feature:research: -- cgit v1.2.3