Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/fm-harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ detect_own() {
local pid=$$ comm args
for _ in 1 2 3 4 5 6 7 8; do
comm=$(ps -o comm= -p "$pid" 2>/dev/null) || break
case "$(basename "$comm")" in
case "$(basename -- "$comm")" in
*claude*) echo claude; return ;;
*codex*) echo codex; return ;;
*opencode*) echo opencode; return ;;
Expand Down
4 changes: 2 additions & 2 deletions bin/fm-session-lock-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fm_harness_ancestry_pid() {
for _ in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
comm=$(ps -o comm= -p "$pid" 2>/dev/null) || break
args=$(ps -o args= -p "$pid" 2>/dev/null)
bc=$(basename "$comm")
bc=$(basename -- "$comm")
hit=0; is_claude=0
if printf '%s' "$bc" | grep -qE "$FM_HARNESS_RE"; then
hit=1
Expand Down Expand Up @@ -69,7 +69,7 @@ fm_harness_pid_alive() {
local pid=$1 comm args
kill -0 "$pid" 2>/dev/null || return 1
comm=$(ps -o comm= -p "$pid" 2>/dev/null) || return 1
if printf '%s' "$(basename "$comm")" | grep -qE "$FM_HARNESS_RE"; then
if printf '%s' "$(basename -- "$comm")" | grep -qE "$FM_HARNESS_RE"; then
return 0
fi
case "$comm" in
Expand Down
52 changes: 52 additions & 0 deletions tests/fm-secondmate-harness.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,57 @@ SH
pass "pi-signed identity: authoritative launch selection distinguishes shared wrapper ancestry"
}

test_dash_leading_process_names_are_basename_operands() {
local dir fakebin got err status
dir="$TMP_ROOT/dash-leading-process-names"
fakebin=$(fm_fakebin "$dir")
cat > "$fakebin/ps" <<'SH'
#!/usr/bin/env bash
set -u
field= pid=
while [ "$#" -gt 0 ]; do
case "$1" in
-o) field=$2; shift 2 ;;
-p) pid=$2; shift 2 ;;
*) shift ;;
esac
done
case "$pid:$field" in
4242:comm=) printf '%s\n' '/opt/test/bin/codex' ;;
4242:args=) printf '%s\n' 'codex' ;;
4242:ppid=) printf '%s\n' 1 ;;
5252:comm=) printf '%s\n' '-codex' ;;
5252:args=) printf '%s\n' '-codex' ;;
5252:ppid=) printf '%s\n' 1 ;;
*:comm=) printf '%s\n' '-zsh' ;;
*:args=) printf '%s\n' '-zsh' ;;
*:ppid=) printf '%s\n' 4242 ;;
esac
SH
chmod +x "$fakebin/ps"

err="$dir/fm-harness.err"
got=$(env -u CLAUDECODE -u PI_CODING_AGENT -u GROK_AGENT \
PATH="$fakebin:$BASE_PATH" "$ROOT/bin/fm-harness.sh" 2>"$err")
[ "$got" = codex ] || fail "dash-leading shell ancestry resolved '$got', expected codex"
[ ! -s "$err" ] || fail "fm-harness wrote basename option noise for literal -zsh: $(cat "$err")"

err="$dir/fm-session-lock-ancestry.err"
got=$(PATH="$fakebin:$BASE_PATH" bash -c \
'. "$0/bin/fm-session-lock-lib.sh"; fm_harness_ancestry_pid' "$ROOT" 2>"$err")
[ "$got" = 4242 ] || fail "session-lock dash-leading ancestry selected '$got', expected pid 4242"
[ ! -s "$err" ] || fail "session-lock ancestry wrote basename option noise for literal -zsh: $(cat "$err")"

err="$dir/fm-session-lock-alive.err"
PATH="$fakebin:$BASE_PATH" bash -c \
'. "$0/bin/fm-session-lock-lib.sh"; kill() { return 0; }; fm_harness_pid_alive 5252' \
"$ROOT" 2>"$err"; status=$?
expect_code 0 "$status" "session-lock liveness should accept literal -codex as a harness process name"
[ ! -s "$err" ] || fail "session-lock liveness wrote basename option noise for literal -codex: $(cat "$err")"

pass "harness identity: dash-leading ps command names are basename operands, not options"
}

# ===========================================================================
# B) propagate_inheritable_config unit behavior
# ===========================================================================
Expand Down Expand Up @@ -2246,6 +2297,7 @@ SH
test_harness_resolution
test_secondmate_model_effort_tokens
test_pi_signed_detection_and_session_lock_identity
test_dash_leading_process_names_are_basename_operands
test_propagate_lib
test_spawn_split_and_inherit
test_spawn_backward_compat_crew_fallback
Expand Down
Loading