Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test: keep the acceptance script and hook tests out of the operator's install

AkitaOnRails14d78680f26f
diff --git a/scripts/managed-workstream-acceptance.sh b/scripts/managed-workstream-acceptance.sh
index c17f6fab..f2a39dae 100755
--- a/scripts/managed-workstream-acceptance.sh
+++ b/scripts/managed-workstream-acceptance.sh
@@ -16,8 +16,39 @@ CONFIG="$TMP/config"
LOGS="$TMP/logs"
SERVER_PID=""
+# `ai-memory run` wires the harness it launches into that harness's user
+# config. Every leg below must do that inside a fixture home; a leak points
+# the operator's real Codex or Claude config at this throwaway server. These
+# are the files ai-memory writes, so any change to one fails the run.
+OPERATOR_HOME=$HOME
+OPERATOR_CONFIGS=(
+ "$OPERATOR_HOME/.codex/hooks.json"
+ "$OPERATOR_HOME/.codex/config.toml"
+ "$OPERATOR_HOME/.claude/settings.json"
+ "$OPERATOR_HOME/.gemini/config/hooks.json"
+ "$OPERATOR_HOME/.gemini/config/mcp_config.json"
+ "$OPERATOR_HOME/.kimi-code/config.toml"
+)
+operator_config_digest() {
+ local file
+ for file in "${OPERATOR_CONFIGS[@]}"; do
+ if [ -f "$file" ]; then
+ sha256sum "$file"
+ else
+ printf 'absent %s\n' "$file"
+ fi
+ done
+}
+OPERATOR_CONFIG_DIGEST=$(operator_config_digest)
+
cleanup() {
local code=$?
+ if [ "$(operator_config_digest)" != "$OPERATOR_CONFIG_DIGEST" ]; then
+ printf 'the acceptance run changed the operator'"'"'s agent config:\n' >&2
+ diff <(printf '%s\n' "$OPERATOR_CONFIG_DIGEST") \
+ <(operator_config_digest) >&2 || true
+ code=1
+ fi
if [ -n "$SERVER_PID" ]; then
kill "$SERVER_PID" 2>/dev/null || true
wait "$SERVER_PID" 2>/dev/null || true
@@ -27,6 +58,7 @@ cleanup() {
else
rm -rf "$TMP"
fi
+ exit "$code"
}
trap cleanup EXIT INT TERM
@@ -424,6 +456,14 @@ chmod +x "$FAKE"
printf 'running deterministic wrapper edge checks\n'
+# The fake harnesses below need nothing from the operator's home, and each
+# `run` would otherwise autowire the operator's real agent config.
+OPERATOR_XDG_CONFIG_HOME=${XDG_CONFIG_HOME-}
+OPERATOR_XDG_DATA_HOME=${XDG_DATA_HOME-}
+export HOME="$CONFIG/edge-home"
+mkdir -p "$HOME"
+unset CODEX_HOME CLAUDE_CONFIG_DIR XDG_CONFIG_HOME XDG_DATA_HOME
+
# Utility invocations must not discover and import another process's recent
# session merely because it is active in the same checkout.
UTILITY_CODEX_HOME="$CONFIG/utility-codex"
@@ -1332,6 +1372,12 @@ if [ "$DETERMINISTIC_ONLY" = 1 ]; then
exit 0
fi
+# The real-harness phase reads credentials from the operator's home and
+# isolates each leg itself.
+export HOME="$OPERATOR_HOME"
+[ -z "$OPERATOR_XDG_CONFIG_HOME" ] || export XDG_CONFIG_HOME="$OPERATOR_XDG_CONFIG_HOME"
+[ -z "$OPERATOR_XDG_DATA_HOME" ] || export XDG_DATA_HOME="$OPERATOR_XDG_DATA_HOME"
+
read -r -a requested_harnesses <<<"$HARNESS_WORDS"
harnesses=()
for requested_harness in "${requested_harnesses[@]}"; do
diff --git a/tests/hooks/test_lib.sh b/tests/hooks/test_lib.sh
index 0aeee979..f75057fe 100755
--- a/tests/hooks/test_lib.sh
+++ b/tests/hooks/test_lib.sh
@@ -17,6 +17,11 @@ TMP=$(mktemp -d)
ORIG_HOME=${HOME:-}
HOME="$TMP"
export HOME
+# The data dir comes from XDG_DATA_HOME before HOME, so an exported one would
+# send this suite's spooled events, and its auth-header lookups, to the
+# caller's real install.
+CALLER_SPOOL="${AI_MEMORY_DATA_DIR:-${XDG_DATA_HOME:-$ORIG_HOME/.local/share}/ai-memory}/hook-spool"
+unset AI_MEMORY_DATA_DIR XDG_DATA_HOME XDG_CONFIG_HOME XDG_STATE_HOME XDG_CACHE_HOME
unset AI_MEMORY_RUN_ID AI_MEMORY_MANAGED_WORKSTREAM_ID AI_MEMORY_MANAGED_WORKSTREAM_NAME
trap 'rm -rf "$TMP"; HOME=$ORIG_HOME' EXIT
@@ -1070,6 +1075,9 @@ PS_BRIEF_STATIC=$(grep -Fq 'if ($Event -eq "session-start" -and -not $BriefingOn
&& printf 'ok' || printf 'missing')
assert_eq "powershell session-start handoff GET carries the briefing keys" "ok" "$PS_BRIEF_STATIC"
+assert_eq "no fixture event was spooled into the caller's data dir" "" \
+ "$(grep -rlF -e "$TMP" -e 'memory.test' "$CALLER_SPOOL" 2>/dev/null | head -n 1)"
+
# --- summary ----------------------------------------------------------
printf '\n%d passed, %d failed\n' "$PASS" "$FAIL"
[ "$FAIL" -eq 0 ]