From c8e108237f4414c6204455b5a6b1a566ffc2d37d Mon Sep 17 00:00:00 2001 From: Jian Weng Date: Wed, 4 Feb 2026 14:14:17 +0300 Subject: [PATCH] cli docs test: add Response header for TTY stdout Summary: - add Response header to the TTY stdout echo path for chat/editor/stdout - document the Response header behavior in acw CLI and dispatch docs - assert Response header ordering in the TTY stdout test Files: - src/cli/acw/dispatch.sh: emit Response header after the user prompt echo on TTY stdout. - docs/cli/acw.md: document Response header for TTY stdout chat/editor mode. - src/cli/acw/dispatch.md: describe Response header in stdout capture behavior. - tests/cli/test-acw-flags.sh: assert Response header presence and ordering on TTY stdout; ensure non-TTY excludes it. - tests/cli/test-acw-flags.md: update TTY echo expectations to include Response header. Issue: #798 Tests: `bash tests/cli/test-acw-flags.sh` (passed) --- docs/cli/acw.md | 2 +- src/cli/acw/dispatch.md | 4 ++-- src/cli/acw/dispatch.sh | 1 + tests/cli/test-acw-flags.md | 2 +- tests/cli/test-acw-flags.sh | 17 +++++++++++++---- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/cli/acw.md b/docs/cli/acw.md index e45fae14..ebf9c5fb 100644 --- a/docs/cli/acw.md +++ b/docs/cli/acw.md @@ -175,7 +175,7 @@ autoload -Uz compinit && compinit - `--stdout` behavior: - Without `--chat`: merges provider stderr into stdout so progress and output can be piped together. - With `--chat`: provider stderr is appended to `.tmp/acw-sessions/.stderr` to keep stdout clean for piping. Empty sidecar files created by `acw` are automatically removed. - - With `--chat --editor`: when stdout is a TTY, the user prompt is echoed immediately before provider invocation, so it appears before assistant output. + - With `--chat --editor`: when stdout is a TTY, the user prompt is echoed immediately before provider invocation, followed by a `Response:` header before assistant output. - In file mode (no `--stdout`), provider stderr is written to `.stderr`. Empty sidecar files are removed after the provider exits. ## See Also diff --git a/src/cli/acw/dispatch.md b/src/cli/acw/dispatch.md index 0094353b..1bfd02e4 100644 --- a/src/cli/acw/dispatch.md +++ b/src/cli/acw/dispatch.md @@ -74,8 +74,8 @@ and turn appending: output is captured to a temp file. After the provider exits, the captured content is emitted to stdout and the assistant response is appended to the session file. If `--editor` is used and stdout is a TTY, the editor prompt -is echoed to stdout before provider invocation so it appears before assistant -output. +is echoed to stdout before provider invocation, followed by a `Response:` +header so it appears before assistant output. **Stderr sidecar**: When `--stdout` is combined with `--chat`, provider stderr is appended to `.stderr` beside the session file rather than diff --git a/src/cli/acw/dispatch.sh b/src/cli/acw/dispatch.sh index f75a9857..b49b59da 100644 --- a/src/cli/acw/dispatch.sh +++ b/src/cli/acw/dispatch.sh @@ -372,6 +372,7 @@ acw() { echo "User Prompt:" cat "$original_input_file" echo "" + echo "Response:" fi # Remaining arguments are provider options diff --git a/tests/cli/test-acw-flags.md b/tests/cli/test-acw-flags.md index 2fcf8c8c..ed6e04be 100644 --- a/tests/cli/test-acw-flags.md +++ b/tests/cli/test-acw-flags.md @@ -36,7 +36,7 @@ Validate `acw` flag behavior for `--editor`, `--stdout`, and file-mode stderr ca ### chat_editor_stdout_tty_echo **Purpose**: `--chat --editor --stdout` echoes the editor prompt when stdout is a TTY. -**Expected**: Output includes `User Prompt:` and editor content before assistant output. +**Expected**: Output includes `User Prompt:` and editor content, then `Response:` before assistant output. ### chat_editor_stdout_non_tty_no_echo **Purpose**: `--chat --editor --stdout` keeps stdout assistant-only when stdout is not a TTY. diff --git a/tests/cli/test-acw-flags.sh b/tests/cli/test-acw-flags.sh index c487f844..6ed1c5b7 100644 --- a/tests/cli/test-acw-flags.sh +++ b/tests/cli/test-acw-flags.sh @@ -273,15 +273,20 @@ if ! printf "%s\n" "$clean_tty_output" | grep -q "TTY prompt content"; then test_fail "TTY stdout should include editor prompt content" fi +if ! printf "%s\n" "$clean_tty_output" | grep -q "^Response:"; then + test_fail "TTY stdout should include Response header" +fi + prompt_line=$(printf "%s\n" "$clean_tty_output" | awk '/^User Prompt:/{print NR; exit}') +response_line=$(printf "%s\n" "$clean_tty_output" | awk '/^Response:/{print NR; exit}') user_header_line=$(printf "%s\n" "$clean_tty_output" | awk '/^# User/{print NR; exit}') -if [ -z "$prompt_line" ] || [ -z "$user_header_line" ]; then - test_fail "TTY stdout should include prompt header and assistant output" +if [ -z "$prompt_line" ] || [ -z "$response_line" ] || [ -z "$user_header_line" ]; then + test_fail "TTY stdout should include prompt, response headers, and assistant output" fi -if [ "$prompt_line" -gt "$user_header_line" ]; then - test_fail "TTY stdout should echo prompt before assistant output" +if [ "$prompt_line" -gt "$response_line" ] || [ "$response_line" -gt "$user_header_line" ]; then + test_fail "TTY stdout should echo prompt and response headers before assistant output" fi # Test 9: --chat --editor --stdout skips prompt echo on non-TTY stdout @@ -300,6 +305,10 @@ if printf "%s\n" "$clean_non_tty_output" | grep -q "^User Prompt:"; then test_fail "Non-TTY stdout should not include prompt echo" fi +if printf "%s\n" "$clean_non_tty_output" | grep -q "^Response:"; then + test_fail "Non-TTY stdout should not include response header" +fi + if ! printf "%s\n" "$clean_non_tty_output" | grep -q "TTY prompt content"; then test_fail "Non-TTY stdout should still include assistant output" fi