Files
drharness/tests/test_edit_history_then_continue.sh
darthrubik 41b49aeeae Fix issue 129: Use TEST_TEMP_DIR instead of /tmp for test output files
Replace hardcoded /tmp/drharness_output.txt with $TEST_TEMP_DIR/drharness_output.txt
in all test files. Tests should only write to subfiles/directories of the working
directory (which is already a temp directory created by run_test.sh).
2026-06-02 17:09:32 -05:00

115 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# test_edit_history_then_continue.sh - Edit then continue conversation normally
# Helper function to run drharness and capture output to a temp file
run_drharness() {
"$DRHARNESS" "$@" > "$TEST_TEMP_DIR/drharness_output.txt" 2>&1
return $?
}
# Helper to get the output
get_output() {
cat "$TEST_TEMP_DIR/drharness_output.txt"
}
# Helper to reset editor state for each test
reset_editor_state() {
rm -f .editor_input_* .editor_invocation_count hist.md
}
reset_editor_state
# Create a chat file with two messages
create_chat_file chat.json user "hello" assistant "hi there"
# Stage the rebase editor output (edit message 0)
cat > .editor_input_0 << 'EDITEOF'
# History Rebase Editor
#
# Commands:
# pick - keep the message unchanged
# edit - modify the message content and/or role
# drop - remove the message from history
#
# Each line format: <command> <index> [<role>] <display_content>
# - index: 0-based message index
# - role: [user], [assistant], or [tool] (editable)
# - display_content: first line of message (display only, not editable here)
#
# Lines starting with # are comments and will be ignored.
# Empty lines are treated as drops.
#
-- >8 --
edit 0 [user] hello
pick 1 [assistant] hi there
EDITEOF
# Stage the edit prompt response
cat > .editor_input_1 << 'EDITEOF'
# (no previous message)
Edit message 0 (role: user) below:
-- >8 --
hello world
EDITEOF
# Run drharness with -b flag to edit history
set +e
VISUAL="$MOCK_EDITOR" run_drharness -b -F chat.json
EXIT_CODE=$?
OUTPUT=$(get_output)
set -e
if [ ${EXIT_CODE} -ne 0 ]; then
echo "FAIL: edit_then_continue - edit phase: expected exit code 0, got $EXIT_CODE"
echo "Output: $OUTPUT"
exit 1
fi
# Verify the edit was saved
msg0_content=$(dr_result chat.json 0)
if [ "$msg0_content" != "hello world" ]; then
echo "FAIL: edit_then_continue - edit not saved correctly"
exit 1
fi
# Now run drharness normally (without -b) to continue the conversation
# We need a new editor input for the normal flow
# Reset staged inputs for the second run
cat > .editor_input_0 << 'EDITEOF'
[assistant] hi there
-- >8 --
how are you?
EDITEOF
# Reset the invocation counter for the new run
echo "0" > .editor_invocation_count
# Create mock LLM response for the debug client
be_done "I'm doing well, thanks for asking!" > mock_responses.txt
# Run drharness normally (uses DebugClient to read from stdin)
set +e
VISUAL="$MOCK_EDITOR" run_drharness -d -F chat.json < mock_responses.txt
EXIT_CODE=$?
OUTPUT=$(get_output)
set -e
if [ ${EXIT_CODE} -ne 0 ]; then
echo "FAIL: edit_then_continue - continue phase: expected exit code 0, got $EXIT_CODE"
echo "Output: $OUTPUT"
exit 1
fi
# Verify the history now has 4 messages (original 2 + new user message + new assistant response)
len=$(history_length chat.json)
if [ "$len" != "4" ]; then
echo "FAIL: edit_then_continue - expected 4 messages after continue, got $len"
exit 1
fi
echo "PASS: edit_then_continue"