Files
darthrubik 1d799cc05d Implement build_edit_prompt for history editing (issue #99)
- Add HistoryEditor::build_edit_prompt() to format edit prompts
  with previous message context and >8 separator
- Message 0 shows '(no previous message)' instead of context
- Add -T debug flag to test build_edit_prompt
- Extend mock_editor.sh to support sequential invocations via
  counter file and staged input files
- Add unit tests for build_edit_prompt functionality
- Register new test in CMakeLists.txt
2026-05-29 15:43:47 -05:00

59 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# $1 is the file path passed to the editor
FILE=$1
# Support sequential invocations using a counter file
# Track invocations in $TEST_TEMP_DIR/.editor_invocation_count
# Copy from $TEST_TEMP_DIR/.editor_input_$INVOCATION to the editor file
if [ -n "$TEST_TEMP_DIR" ] && [ -f "$TEST_TEMP_DIR/.editor_input_0" ]; then
# Initialize counter file if it doesn't exist
if [ ! -f "$TEST_TEMP_DIR/.editor_invocation_count" ]; then
echo "0" > "$TEST_TEMP_DIR/.editor_invocation_count"
fi
# Read current invocation count
INVOCATION=$(cat "$TEST_TEMP_DIR/.editor_invocation_count")
# Check if there's a staged input file for this invocation
STAGED_INPUT="$TEST_TEMP_DIR/.editor_input_$INVOCATION"
if [ -f "$STAGED_INPUT" ]; then
# Copy staged content to the editor file
cp "$STAGED_INPUT" "$FILE"
fi
# Increment the counter for next invocation
echo $((INVOCATION + 1)) > "$TEST_TEMP_DIR/.editor_invocation_count"
# For inspecting by tests
cat $FILE > hist.md
exit 0
fi
# For inspecting by tests
cat $FILE > hist.md
MODE="${DRHARNESS_EDITOR_MODE:-default}"
if [[ "$MODE" == "empty" ]]; then
echo "" > $FILE
echo "-- >8 --" >> $FILE
echo "" >> $FILE
elif [[ "$MODE" == "full_history" ]]; then
echo "" >> $FILE
echo "My Full History Reply" >> $FILE
elif [[ "$MODE" == "partial_line" ]]; then
echo "" >> $FILE
echo "This is a -- >8 -- partial line" >> $FILE
elif [[ "$MODE" == "separator" ]]; then
echo "Context" > $FILE
echo "-- >8 --" >> $FILE
echo "-- >8 --" >> $FILE
echo "Parsed Prompt" >> $FILE
elif [[ "$MODE" == "placeholder" ]]; then
echo "Placeholder text" > $FILE
echo "-- >8 --" >> $FILE
echo "New Chat Reply" >> $FILE
else
echo "" >> $FILE
echo "Default Prompt" >> $FILE
fi