gamemode-session: reference-counted state machine core

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
funman300
2026-07-15 21:31:52 -07:00
parent e0c12ff0c9
commit 05707afc04
2 changed files with 129 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
#!/bin/bash
# Drives gamemode-session in dryrun against a temp state dir and asserts the
# reference-counting state machine. No live effects run.
set -u
HERE=$(cd "$(dirname "$0")/.." && pwd)
SCRIPT="$HERE/gamemode-session.sh"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
export GAMEMODE_STATE_DIR="$TMP/state"
export GAMEMODE_DRYRUN=1
fail=0
check() { # desc, actual, expected
if [ "$2" = "$3" ]; then printf 'ok - %s\n' "$1"
else printf 'FAIL - %s (got [%s] want [%s])\n' "$1" "$2" "$3"; fail=1; fi
}
active() { "$SCRIPT" status >/dev/null 2>&1 && echo active || echo inactive; }
check "starts inactive" "$(active)" "inactive"
"$SCRIPT" add feral >/dev/null 2>&1
check "feral activates" "$(active)" "active"
check "src.feral marker set" "$([ -e "$GAMEMODE_STATE_DIR/src.feral" ] && echo y)" "y"
check "baseline captured" "$([ -e "$GAMEMODE_STATE_DIR/baseline.profile" ] && echo y)" "y"
"$SCRIPT" add manual >/dev/null 2>&1
check "manual keeps active" "$(active)" "active"
"$SCRIPT" del feral >/dev/null 2>&1
check "still active on 1 left" "$(active)" "active"
"$SCRIPT" del manual >/dev/null 2>&1
check "last del deactivates" "$(active)" "inactive"
check "baseline cleared" "$([ -e "$GAMEMODE_STATE_DIR/baseline.profile" ] && echo y || echo n)" "n"
"$SCRIPT" toggle >/dev/null 2>&1
check "toggle on activates" "$(active)" "active"
"$SCRIPT" toggle >/dev/null 2>&1
check "toggle off deactivates" "$(active)" "inactive"
"$SCRIPT" reset >/dev/null 2>&1
check "reset leaves inactive" "$(active)" "inactive"
exit $fail