Skip to content

Commit ca36f4a

Browse files
committed
fix(e2e): await idle before launch exit
Signed-off-by: Senthil Ravichandran <senthilr@nvidia.com>
1 parent 0d3a532 commit ca36f4a

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

test/e2e/live/launch-agent-turn.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ response_start="$(wc -c <"$capture")"
8989
printf '%s\r' "$NEMOCLAW_LAUNCH_PROMPT" >&3
9090
9191
reply_seen=0
92-
has_exact_reply() {
92+
normalized_response() {
9393
tail -c "+$((response_start + 1))" "$capture" \
9494
| sed -E $'s/\x1B][^\x07\x1B]*(\x07|\x1B\\\\)//g' \
9595
| sed -E $'s/\x1B\\[[0-?]*[ -\\/]*[@-~]//g' \
9696
| tr '\r' '\n' \
97-
| LC_ALL=C tr -d '\000-\010\013\014\016-\037\177' \
98-
| awk -v expected="$NEMOCLAW_LAUNCH_EXPECTED_REPLY" '
97+
| LC_ALL=C tr -d '\000-\010\013\014\016-\037\177'
98+
}
99+
has_exact_reply() {
100+
normalized_response | awk -v expected="$NEMOCLAW_LAUNCH_EXPECTED_REPLY" '
99101
{
100102
line = $0
101103
sub(/^[[:space:]]+/, "", line)
@@ -105,6 +107,20 @@ has_exact_reply() {
105107
END { exit found ? 0 : 1 }
106108
'
107109
}
110+
has_post_reply_ready() {
111+
normalized_response | awk \
112+
-v expected="$NEMOCLAW_LAUNCH_EXPECTED_REPLY" \
113+
-v ready="$NEMOCLAW_LAUNCH_READY_TEXT" '
114+
{
115+
line = $0
116+
sub(/^[[:space:]]+/, "", line)
117+
sub(/[[:space:]]+$/, "", line)
118+
if (line == expected) reply = 1
119+
if (reply && index(line, ready) != 0) found = 1
120+
}
121+
END { exit found ? 0 : 1 }
122+
'
123+
}
108124
for _ in {1..180}; do
109125
if has_exact_reply; then
110126
reply_seen=1
@@ -116,6 +132,24 @@ for _ in {1..180}; do
116132
sleep 1
117133
done
118134
135+
if [[ "$reply_seen" = 1 && -n "$NEMOCLAW_LAUNCH_READY_TEXT" ]]; then
136+
post_reply_ready_seen=0
137+
for _ in {1..60}; do
138+
if has_post_reply_ready; then
139+
post_reply_ready_seen=1
140+
break
141+
fi
142+
if ! kill -0 "$session_pid" 2>/dev/null; then
143+
break
144+
fi
145+
sleep 1
146+
done
147+
if [[ "$post_reply_ready_seen" != 1 ]]; then
148+
echo "launch did not return to the expected TUI state after the reply" >&2
149+
exit 1
150+
fi
151+
fi
152+
119153
if [[ -n "$NEMOCLAW_LAUNCH_EXIT_COMMAND" ]]; then
120154
printf '%s\r' "$NEMOCLAW_LAUNCH_EXIT_COMMAND" >&3
121155
else

test/e2e/support/launch-agent-turn.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ it.runIf(process.platform === "linux")(
112112
);
113113

114114
it.runIf(process.platform !== "win32")(
115-
"waits for OpenClaw gateway readiness before sending the launch prompt (#7230)",
115+
"waits for OpenClaw idle before the prompt and again before the exit command (#9023)",
116116
() => {
117117
const fixtureRoot = mkdtempSync(join(tmpdir(), "nemoclaw-launch-turn-ready-"));
118118
const scriptStub = join(fixtureRoot, "script");
@@ -136,6 +136,11 @@ fi
136136
printf 'gateway connected | idle\n' | tee -a "$capture"
137137
IFS= read -r -d $'\r' _
138138
printf 'PONG\n' | tee -a "$capture"
139+
if IFS= read -r -t 1 -d $'\r' _; then
140+
echo "exit arrived before post-reply readiness" >&2
141+
exit 1
142+
fi
143+
printf 'gateway connected | idle\n' | tee -a "$capture"
139144
IFS= read -r -d $'\r' exit_command
140145
[[ "$exit_command" == "/exit" ]]
141146
exit 0

0 commit comments

Comments
 (0)