Files
darthrubik 718bd5dca7 Refactor run_test.sh to generate history json blobs in only one spot (issue 137)
The create_state function now accepts role/content pairs as arguments
and generates the JSON internally using jq for proper escaping. This
centralizes all JSON blob generation in run_test.sh, eliminating the
need for test files to manually construct JSON arrays.
2026-06-03 17:00:10 -05:00

82 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
set -e
export EDITOR="$MOCK_EDITOR"
create_state test_drharness.json assistant "This is the AI last response."
export DRHARNESS_EDITOR_MODE="default"
be_done 'Mock response' | $DRHARNESS -F test_drharness.json -d
# Make sure we got correct prompt out of it
if [[ "$(dr_result test_drharness.json 1)" != "Default Prompt" ]]; then
exit 1
fi
rm -f test_drharness_empty.json
create_state test_drharness_empty.json assistant "Mock response"
export DRHARNESS_EDITOR_MODE="empty"
if $DRHARNESS -F test_drharness_empty.json -d < /dev/null 2>&1 | grep -q "Prompt is empty"; then
echo "PASS: Empty input handled"
else
echo "FAIL: Empty input not handled correctly"
exit 1
fi
rm -f test_drharness_sep.json
create_state test_drharness_sep.json assistant "Mock response"
export DRHARNESS_EDITOR_MODE="separator"
be_done 'Mock response' | $DRHARNESS -F test_drharness_sep.json -d
# Make sure we got correct prompt out of it
if [[ "$(dr_result test_drharness_sep.json 1)" != "Parsed Prompt" ]]; then
exit 1
fi
cat > expected_history <<EOF
[assistant] Mock response
-- >8 --
EOF
# Check expected history
diff -u expected_history hist.md
rm -f test_drharness_full.json
create_state test_drharness_full.json user "Hello" assistant "Hi there!"
export DRHARNESS_EDITOR_MODE="full_history"
be_done 'Mock response' | $DRHARNESS -F test_drharness_full.json -f -d
cat > expected_history <<EOF
[User] Hello
[Ai Response] Hi there!
-- >8 --
EOF
# Check expected history
diff -u expected_history hist.md
export DRHARNESS_EDITOR_MODE="default"
be_done 'Mock response' | $DRHARNESS -F test_drharness_first.json -d -n
cat > expected_history <<EOF
New Conversation.
This is the start of a new chat. Type your prompt below the separator.
The AI will respond after you save and close the editor.
-- >8 --
EOF
diff -u expected_history hist.md
create_state test_drharness_partial_line.json assistant "Hi there!"
export DRHARNESS_EDITOR_MODE="partial_line"
be_done 'Mock response' | $DRHARNESS -F test_drharness_partial_line.json -f -d
if [[ "$(dr_result test_drharness_partial_line.json 1)" != "This is a -- >8 -- partial line" ]]; then
exit 1
fi