diff --git a/Makefile b/Makefile index 3b62a22..ee2ba24 100644 --- a/Makefile +++ b/Makefile @@ -288,6 +288,9 @@ tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN) check: $(LIB) $(BIN) $(CLIENT) $(PLUGIN) $(TESTS) tests/test_junction @set -e; python3 tools/check_i18n.py; \ export LD_LIBRARY_PATH=.; \ + SPLINTER_SESSION_DIR=$$(mktemp -d "$${TMPDIR:-/tmp}/splinter-check-XXXXXX"); \ + export SPLINTER_SESSION_DIR; \ + trap 'rm -rf "$$SPLINTER_SESSION_DIR"' EXIT; \ for t in $(TESTS); do echo "== $$t"; ./$$t; done; \ echo "== tests/test_delegate_cli.sh"; sh tests/test_delegate_cli.sh; \ echo "== tests/test_interview.sh"; sh tests/test_interview.sh; \ diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 66ad139..a2f8e76 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -245,7 +245,7 @@ lies about what it does. | `max_bytes` | conversation budget in bytes, `0` = no limit | | `compact_threshold` | context tokens past which the next request is compacted (`0` = off) | | `compact_target` | the size compaction aims for, in tokens; `/compact [tokens]` forces it now | -| `session_dir` | where session logs go (default `~/.splinter`) | +| `session_dir` | where session logs go (default `~/.splinter`); `SPLINTER_SESSION_DIR` overrides it, which is how `make check` keeps its test sessions out of yours | | `system_prompt` | sent once at the start of a conversation | | `telegram_allow` | user ids the gateway answers, comma-separated; empty means nobody | | `skills_dir` | a directory of skills, one line each | diff --git a/src/backend/engine.c b/src/backend/engine.c index ce2cd16..ca607b0 100644 --- a/src/backend/engine.c +++ b/src/backend/engine.c @@ -2521,7 +2521,15 @@ open_session(struct sp_engine *e, const struct sp_engine_opts *o, static char sessbuf[512], idbuf[64]; const char *dir = o->session_dir; const char *id = o->session_id; + const char *envdir = getenv("SPLINTER_SESSION_DIR"); + /* + * Tests and throwaway runs get their own directory without a config: + * the suite used to create hundreds of "hallo" sessions in the user's + * ~/.splinter because --no-config does not change where sessions go. + */ + if (dir == NULL && envdir != NULL && *envdir != '\0') + dir = envdir; if (dir == NULL) { const char *home = getenv("HOME"); diff --git a/tests/test_a2a.sh b/tests/test_a2a.sh index fba3e4b..ebb0a69 100755 --- a/tests/test_a2a.sh +++ b/tests/test_a2a.sh @@ -8,6 +8,7 @@ set -u cd "$(dirname "$0")/.." || exit 1 D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR P=$((20000 + ($$ % 20000))) F= cleanup() { [ -n "$F" ] && kill "$F" 2>/dev/null; rm -rf "$D"; } diff --git a/tests/test_a2a_server.sh b/tests/test_a2a_server.sh index 30f6d2c..26f3064 100755 --- a/tests/test_a2a_server.sh +++ b/tests/test_a2a_server.sh @@ -7,6 +7,7 @@ set -u cd "$(dirname "$0")/.." || exit 1 D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-srv-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR P=$((20000 + ($$ % 20000))) P2=$((P + 1)) P3=$((P + 2)) diff --git a/tests/test_agents_ui.sh b/tests/test_agents_ui.sh index 0eece8f..d03ef7e 100644 --- a/tests/test_agents_ui.sh +++ b/tests/test_agents_ui.sh @@ -5,6 +5,7 @@ set -u cd "$(dirname "$0")/.." || exit 1 command -v tmux >/dev/null 2>&1 || { echo "test_agents_ui: skipped (no tmux)"; exit 0; } D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-ag-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR # Our own socket, never the user's. $TMUX (set when this runs inside somebody's # tmux) wins over TMUX_TMPDIR, so drop it and point the server at $D: a key # this test sends can then not land in a real session, and the kill-session diff --git a/tests/test_gateway.sh b/tests/test_gateway.sh index 22c351c..cc794e0 100755 --- a/tests/test_gateway.sh +++ b/tests/test_gateway.sh @@ -9,6 +9,7 @@ set -u cd "$(dirname "$0")/.." || exit 1 D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-gw-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR trap 'rm -rf "$D"' EXIT fails=0 diff --git a/tests/test_interview.sh b/tests/test_interview.sh index 8b4ab03..1fa8518 100755 --- a/tests/test_interview.sh +++ b/tests/test_interview.sh @@ -7,6 +7,7 @@ set -u cd "$(dirname "$0")/.." || exit 1 D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-iv-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR port=18992 srv= cleanup() { [ -n "$srv" ] && kill "$srv" 2>/dev/null; rm -rf "$D"; } diff --git a/tests/test_reconnect.sh b/tests/test_reconnect.sh index 2173617..64eda6b 100755 --- a/tests/test_reconnect.sh +++ b/tests/test_reconnect.sh @@ -12,6 +12,8 @@ if ! command -v tmux >/dev/null 2>&1; then exit 0 fi D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-reconnect-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/server/.splinter" +export SPLINTER_SESSION_DIR unset TMUX TMUX_PANE export TMUX_TMPDIR="$D" own_server() { diff --git a/tests/test_ui.sh b/tests/test_ui.sh index 50ab905..def26bd 100755 --- a/tests/test_ui.sh +++ b/tests/test_ui.sh @@ -15,6 +15,8 @@ if ! command -v tmux >/dev/null 2>&1; then exit 0 fi D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-ui-XXXXXX") || exit 1 +SPLINTER_SESSION_DIR="$D/home/.splinter" +export SPLINTER_SESSION_DIR # Our own socket, never the user's. $TMUX wins over both -L and TMUX_TMPDIR # (tmux.c: when $TMUX is set the client takes the socket path out of it), so a # run started from inside the user's tmux would drive the user's server -- and