Fix: Use helper functions in test_harness_config.sh

- Added dr_config_base_url and dr_config_model helper functions to run_test.sh
- Updated test_harness_config.sh to use be_done() and helper functions instead of inline JSON
This commit is contained in:
2026-08-04 20:20:10 +00:00
parent 3e99b37683
commit 02975ddfd4
2 changed files with 23 additions and 9 deletions
+14
View File
@@ -455,6 +455,20 @@ function dr_content_text() {
}
export -f dr_content_text
# Get base_url from config in chat file
function dr_config_base_url() {
local chat_file="$1"
jq -r '.config.base_url' "$chat_file"
}
export -f dr_config_base_url
# Get model from config in chat file
function dr_config_model() {
local chat_file="$1"
jq -r '.config.model' "$chat_file"
}
export -f dr_config_model
# Resolve paths relative to this script
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
PROJECT_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd)
+9 -9
View File
@@ -2,15 +2,15 @@
# test_harness_config.sh - Tests for HarnessConfig with base_url and model fields
# Test 1: Verify config is saved with base_url and model in new conversations
echo '{"choices":[{"delta":{"content":"Response","role":"assistant"},"finish_reason":"stop"}],"usage":{"completion_tokens":10,"prompt_tokens":5,"total_tokens":15}}' | "${DRHARNESS}" \
echo "$(be_done "Response")" | "${DRHARNESS}" \
-F "${TEST_TEMP_DIR}/chat.json" \
-n \
-d \
-m "test" 2>/dev/null
# Verify config contains base_url and model
BASE_URL=$(cat "${TEST_TEMP_DIR}/chat.json" | jq -r '.config.base_url')
MODEL=$(cat "${TEST_TEMP_DIR}/chat.json" | jq -r '.config.model')
BASE_URL=$(dr_config_base_url "${TEST_TEMP_DIR}/chat.json")
MODEL=$(dr_config_model "${TEST_TEMP_DIR}/chat.json")
if [ -z "$BASE_URL" ] || [ "$BASE_URL" = "null" ]; then
echo "FAIL: Expected config.base_url to be set"
@@ -23,30 +23,30 @@ if [ -z "$MODEL" ] || [ "$MODEL" = "null" ]; then
fi
# Test 2: Verify -M flag sets model in config
echo '{"choices":[{"delta":{"content":"Response","role":"assistant"},"finish_reason":"stop"}],"usage":{"completion_tokens":10,"prompt_tokens":5,"total_tokens":15}}' | "${DRHARNESS}" \
echo "$(be_done "Response")" | "${DRHARNESS}" \
-F "${TEST_TEMP_DIR}/chat2.json" \
-n \
-d \
-M "custom-model" \
-m "test" 2>/dev/null
MODEL2=$(cat "${TEST_TEMP_DIR}/chat2.json" | jq -r '.config.model')
MODEL2=$(dr_config_model "${TEST_TEMP_DIR}/chat2.json")
if [ "$MODEL2" != "custom-model" ]; then
echo "FAIL: Expected config.model to be 'custom-model', got '${MODEL2}'"
exit 1
fi
# Test 3: Verify backward compatibility - loading file without base_url and model
echo '{"history":[{"role":"user","content":"hello"}],"tools":[],"config":{"max_tool_iterations":16,"verbose":false,"depth":0}}' > "${TEST_TEMP_DIR}/old_format.json"
create_state "${TEST_TEMP_DIR}/old_format.json" user "hello"
echo '{"choices":[{"delta":{"content":"Response","role":"assistant"},"finish_reason":"stop"}],"usage":{"completion_tokens":10,"prompt_tokens":5,"total_tokens":15}}' | "${DRHARNESS}" \
echo "$(be_done "Response")" | "${DRHARNESS}" \
-F "${TEST_TEMP_DIR}/old_format.json" \
-d \
-m "test" 2>/dev/null
# Verify the saved file now has base_url and model with defaults
SAVED_BASE_URL=$(cat "${TEST_TEMP_DIR}/old_format.json" | jq -r '.config.base_url')
SAVED_MODEL=$(cat "${TEST_TEMP_DIR}/old_format.json" | jq -r '.config.model')
SAVED_BASE_URL=$(dr_config_base_url "${TEST_TEMP_DIR}/old_format.json")
SAVED_MODEL=$(dr_config_model "${TEST_TEMP_DIR}/old_format.json")
if [ -z "$SAVED_BASE_URL" ] || [ "$SAVED_BASE_URL" = "null" ]; then
echo "FAIL: Expected saved config.base_url to be set"