Skip to content

Commit c4b0ca4

Browse files
committed
Cover associative-array fallback
1 parent 505e95d commit c4b0ca4

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

clai.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ HAS_ASSOC_ARRAY=false
315315
# Bash ≥4 or any zsh support associative arrays. We only care whether declare
316316
# succeeds; the probe variable is intentionally throwaway.
317317
# shellcheck disable=SC2034
318-
if (unset TEST 2>/dev/null; declare -A TEST 2>/dev/null); then
318+
if [ "$CLAI_FORCE_NO_ASSOC_ARRAY" != true ] && (unset TEST 2>/dev/null; declare -A TEST 2>/dev/null); then
319319
HAS_ASSOC_ARRAY=true
320320
fi
321321

test/smoke.bats

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,72 @@ EOF
722722
"$TEST_HOME/curl-request-2.json" >/dev/null
723723
}
724724

725+
@test "tool calls work with associative-array fallback enabled" {
726+
write_config <<'EOF'
727+
key=test-key
728+
hi_contrast=false
729+
expose_current_dir=true
730+
max_history_turns=10
731+
api=https://example.invalid/v1/chat/completions
732+
model=gpt-4o-mini
733+
json_mode=false
734+
temp=0.1
735+
tokens=500
736+
exec_query=
737+
question_query=
738+
error_query=
739+
EOF
740+
741+
mkdir -p "$TEST_HOME/.clai_tools"
742+
cat > "$TEST_HOME/.clai_tools/record-note.sh" <<'EOF'
743+
#!/bin/bash
744+
init() {
745+
echo '{
746+
"type": "function",
747+
"function": {
748+
"name": "record-note",
749+
"description": "Record a note for testing.",
750+
"parameters": {
751+
"type": "object",
752+
"properties": {
753+
"value": {
754+
"type": "string"
755+
}
756+
},
757+
"required": [
758+
"value"
759+
]
760+
}
761+
}
762+
}'
763+
}
764+
765+
execute() {
766+
echo "tool said: $(echo "$1" | jq -r '.value')"
767+
}
768+
EOF
769+
chmod +x "$TEST_HOME/.clai_tools/record-note.sh"
770+
771+
make_tool_call_curl
772+
773+
run env \
774+
HOME="$TEST_HOME" \
775+
TMPDIR="$TEST_HOME/tmp" \
776+
PATH="$TEST_HOME/fakebin:$PATH" \
777+
USER="bats" \
778+
LANG="C" \
779+
LC_TIME="C" \
780+
CLAI_FORCE_NO_ASSOC_ARRAY=true \
781+
TEST_HOME="$TEST_HOME" \
782+
bash ./clai.sh "use a tool"
783+
784+
[ "$status" -eq 0 ]
785+
[[ "$output" == *"tool flow complete"* ]]
786+
[ -f "$TEST_HOME/curl-request-2.json" ]
787+
jq -e '.messages | map(select(.role == "tool" and .content == "tool said: hello from tool")) | length >= 1' \
788+
"$TEST_HOME/curl-request-2.json" >/dev/null
789+
}
790+
725791
@test "command responses can be accepted and executed" {
726792
write_config <<'EOF'
727793
key=test-key

0 commit comments

Comments
 (0)