From e4c5ebdca210f66c7f41a7f06a092c85dca31bb5 Mon Sep 17 00:00:00 2001 From: apstndb <803393+apstndb@users.noreply.github.com> Date: Tue, 18 Aug 2026 05:00:44 +0900 Subject: [PATCH 1/3] fix(watch): fold sentinel '-' into the empty session-id path (#855) Callers still pass "${GROK_SESSION_ID:--}" from #477, but watch.sh stopped folding the literal dash, so monitor re-eval wrote watch.-.pid. Restore the one-line fold and the bats case that locked it. Co-authored-by: Cursor --- scripts/watch.sh | 1 + tests/test_watch.bats | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/scripts/watch.sh b/scripts/watch.sh index 722a95b5b..55b917659 100755 --- a/scripts/watch.sh +++ b/scripts/watch.sh @@ -36,6 +36,7 @@ source "$(cd "$(dirname "$0")" && pwd)/lib/compat.sh" # in — notably Grok Build's `monitor` tool, where "$GROK_SESSION_ID" expands to # empty — still starts the watcher. project_path and agent_type are required. SESSION_ID="${1:-}" +[ "$SESSION_ID" = "-" ] && SESSION_ID="" # #477: caller sentinel for empty session id PROJECT_PATH="${2:?Missing project_path}" AGENT_TYPE="${3:?Missing agent_type}" ACTIVE_NAME="${4:-}" diff --git a/tests/test_watch.bats b/tests/test_watch.bats index 6e6d50929..c09b19796 100644 --- a/tests/test_watch.bats +++ b/tests/test_watch.bats @@ -845,3 +845,24 @@ _record_handover_events() { [ "$started" -eq 1 ] ! grep -q "Usage: watch.sh" "$out" } + +# Callers pass "${GROK_SESSION_ID:--}" (and the same pattern for other hosts) +# so a launcher that drops a quoted-empty first arg cannot shift project/type. +# watch.sh must fold "-" into the same generated-fallback path as "" (#236). +@test "watch: sentinel '-' session_id resolves like an empty one (#855)" { + local out="$BATS_TEST_TMPDIR/dash-sid.out" + AGMSG_WATCH_INTERVAL=1 bash "$SCRIPTS/watch.sh" - "$PROJ" claude-code alice >"$out" 2>&1 3>&- & + local pid=$! + # Folded to empty => a generated fallback id, so a watch.agmsg-*.pid appears. + local i started=0 + for i in $(seq 1 25); do + if ls "$TEST_SKILL_DIR/run"/watch.agmsg-*.pid >/dev/null 2>&1; then started=1; break; fi + sleep 0.2 + done + kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true + [ "$started" -eq 1 ] + # No literal "-" session id leaked into the run dir key space. + ! ls "$TEST_SKILL_DIR/run"/watch.-*.pid >/dev/null 2>&1 + ! grep -q "Usage: watch.sh" "$out" + ! grep -q "ERROR: unknown agent type" "$out" +} From bb1e6e3d5e0750538bba4e017015b4f9ec8d93ef Mon Sep 17 00:00:00 2001 From: apstndb <803393+apstndb@users.noreply.github.com> Date: Tue, 18 Aug 2026 05:12:13 +0900 Subject: [PATCH 2/3] test(watch): cite the original #477 contract on the sentinel fold case The restored bats locks the #477 fold, not the later regression ticket. Co-authored-by: Cursor --- tests/test_watch.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_watch.bats b/tests/test_watch.bats index c09b19796..8a2ad582a 100644 --- a/tests/test_watch.bats +++ b/tests/test_watch.bats @@ -849,7 +849,7 @@ _record_handover_events() { # Callers pass "${GROK_SESSION_ID:--}" (and the same pattern for other hosts) # so a launcher that drops a quoted-empty first arg cannot shift project/type. # watch.sh must fold "-" into the same generated-fallback path as "" (#236). -@test "watch: sentinel '-' session_id resolves like an empty one (#855)" { +@test "watch: sentinel '-' session_id resolves like an empty one (#477)" { local out="$BATS_TEST_TMPDIR/dash-sid.out" AGMSG_WATCH_INTERVAL=1 bash "$SCRIPTS/watch.sh" - "$PROJ" claude-code alice >"$out" 2>&1 3>&- & local pid=$! From 8a3474a4f1296ac61656530359cef1f194fd7267 Mon Sep 17 00:00:00 2001 From: apstndb <803393+apstndb@users.noreply.github.com> Date: Tue, 18 Aug 2026 05:35:14 +0900 Subject: [PATCH 3/3] test(watch): use refute for sentinel absence checks (#855) Non-last `! cmd` is silent on bash 3.2, so the new fold case raised the enforced-assertions baseline. refute fails the test on every platform. Co-authored-by: Cursor --- tests/test_watch.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_watch.bats b/tests/test_watch.bats index 8a2ad582a..db6c29e14 100644 --- a/tests/test_watch.bats +++ b/tests/test_watch.bats @@ -862,7 +862,7 @@ _record_handover_events() { kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true [ "$started" -eq 1 ] # No literal "-" session id leaked into the run dir key space. - ! ls "$TEST_SKILL_DIR/run"/watch.-*.pid >/dev/null 2>&1 - ! grep -q "Usage: watch.sh" "$out" - ! grep -q "ERROR: unknown agent type" "$out" + refute ls "$TEST_SKILL_DIR/run"/watch.-*.pid >/dev/null 2>&1 + refute grep -q "Usage: watch.sh" "$out" + refute grep -q "ERROR: unknown agent type" "$out" }