41b49aeeae
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).
108 lines
3.0 KiB
Bash
Executable File
108 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# test_edit_history_no_edits_unchanged.sh - No edits, history remains the same
|
|
|
|
# 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 three messages
|
|
create_chat_file chat.json user "first message" assistant "second message" user "third message"
|
|
|
|
# Stage the rebase editor output exactly as generated by build_rebase_content
|
|
# This simulates the user doing nothing and just saving the editor
|
|
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 --
|
|
pick 0 [user] first message
|
|
pick 1 [assistant] second message
|
|
pick 2 [user] third message
|
|
EDITEOF
|
|
|
|
# Run drharness with -b flag
|
|
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: no_edits_history_unchanged - expected exit code 0, got $EXIT_CODE"
|
|
echo "Output: $OUTPUT"
|
|
exit 1
|
|
fi
|
|
|
|
# Verify history is unchanged - same number of messages
|
|
len=$(history_length chat.json)
|
|
if [ "$len" != "3" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - expected 3 messages, got $len"
|
|
exit 1
|
|
fi
|
|
|
|
# Verify all messages have their original content
|
|
msg0_content=$(dr_result chat.json 0)
|
|
if [ "$msg0_content" != "first message" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - message 0 content changed"
|
|
exit 1
|
|
fi
|
|
|
|
msg1_content=$(dr_result chat.json 1)
|
|
if [ "$msg1_content" != "second message" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - message 1 content changed"
|
|
exit 1
|
|
fi
|
|
|
|
msg2_content=$(dr_result chat.json 2)
|
|
if [ "$msg2_content" != "third message" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - message 2 content changed"
|
|
exit 1
|
|
fi
|
|
|
|
# Verify all roles are unchanged
|
|
msg0_role=$(dr_role chat.json 0)
|
|
if [ "$msg0_role" != "user" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - message 0 role changed"
|
|
exit 1
|
|
fi
|
|
|
|
msg1_role=$(dr_role chat.json 1)
|
|
if [ "$msg1_role" != "assistant" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - message 1 role changed"
|
|
exit 1
|
|
fi
|
|
|
|
msg2_role=$(dr_role chat.json 2)
|
|
if [ "$msg2_role" != "user" ]; then
|
|
echo "FAIL: no_edits_history_unchanged - message 2 role changed"
|
|
exit 1
|
|
fi
|
|
|
|
echo "PASS: no_edits_history_unchanged"
|