From deff663d480afb23e47f0d0fd834d2c0959d0b00 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 3 May 2026 19:59:42 -0500 Subject: fix: make test scratch paths sandbox-friendly `tests/testutil-general.el` hard-coded `~/.temp-emacs-tests/` as the test root. That worked locally but blew up under sandboxed `make` runs and CI environments that can't write outside the repo or `/tmp`. A clean sandbox `make test` run reported 32 failing test files purely from the home-directory write attempt, even though the same suite passed when run with normal write permission. I rewrote `cj/test-base-dir` to honor `CJ_EMACS_TEST_DIR` if set, otherwise create a unique directory under `temporary-file-directory` via `make-temp-file`. So sandbox and CI paths just work, and a stable local debug root is still one env-var away. I also tightened the path-containment checks. The old `(string-prefix-p base fullpath)` was a textual hack. Relative paths and weird trailing slashes could fool it. I extracted `cj/test--assert-inside-base` using `file-in-directory-p`, which is the proper API. While I was there, I added `cj/test--safe-base-dir-p` so `cj/delete-test-base-dir` refuses to recursively wipe `/`, `~/`, `temporary-file-directory`, `user-emacs-directory`, `default-directory`, or any path of length under six characters. That guards against an env-var typo or a misaligned `let` binding accidentally deleting something important. I updated the Makefile's `clean-tests` target to nuke the new `$TMPDIR/cj-emacs-tests-*` pattern plus an explicit `CJ_EMACS_TEST_DIR` (if set) and the legacy `~/.temp-emacs-tests` directory. I added `tests/test-testutil-general.el` with five tests: default base lives under `temporary-file-directory`, env override resolves correctly, parent-escape paths are rejected, broad roots are refused for deletion, and a specific selected root is cleaned cleanly. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a7183d85..2006f5f4 100644 --- a/Makefile +++ b/Makefile @@ -379,7 +379,8 @@ clean-compiled: clean-tests: @echo "Removing test artifacts..." - @rm -rf $(HOME)/.temp-emacs-tests + @test_dir="$${CJ_EMACS_TEST_DIR:-$${TMPDIR:-/tmp}/cj-emacs-tests}"; \ + rm -rf "$$test_dir" "$${TMPDIR:-/tmp}"/cj-emacs-tests-* "$(HOME)/.temp-emacs-tests" @echo "✓ Test artifacts removed" reset: -- cgit v1.2.3