Skip to content

Commit 5b0b083

Browse files
committed
fix(tests): use isolated test configs for bash version tests
Tests 6-9 in test_bash_versions.bats were failing on systems with custom user configs because they expected an "openai" provider with api.openai.com. Fixed by creating isolated test configs in BATS_TMPDIR with a known openai provider, similar to other tests in the file.
1 parent 4304a83 commit 5b0b083

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

tests/unit/test_bash_versions.bats

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,63 +75,133 @@ teardown() {
7575
}
7676

7777
@test "associative array compatibility: works in bash 4.0+ mode" {
78+
# Create test config with known openai provider
79+
local test_config_dir="$BATS_TMPDIR/llm-env-assoc-test-4"
80+
mkdir -p "$test_config_dir/.config/llm-env"
81+
cat > "$test_config_dir/.config/llm-env/config.conf" << 'EOF'
82+
[openai]
83+
base_url=https://api.openai.com/v1
84+
api_key_var=LLM_OPENAI_API_KEY
85+
default_model=gpt-5
86+
description=Test OpenAI provider
87+
enabled=true
88+
EOF
89+
7890
# Test through the main script interface
7991
run bash -c "
8092
export BASH_ASSOC_ARRAY_SUPPORT='true'
93+
export XDG_CONFIG_HOME='$test_config_dir/.config'
8194
source $BATS_TEST_DIRNAME/../../llm-env
8295
get_provider_value 'PROVIDER_BASE_URLS' 'openai'
8396
"
97+
98+
# Clean up
99+
rm -rf "$test_config_dir"
100+
84101
[ "$status" -eq 0 ]
85102
[[ "$output" =~ "api.openai.com" ]]
86103
}
87104

88105
@test "associative array compatibility: works in bash 3.2 mode" {
106+
# Create test config with known openai provider
107+
local test_config_dir="$BATS_TMPDIR/llm-env-assoc-test-3"
108+
mkdir -p "$test_config_dir/.config/llm-env"
109+
cat > "$test_config_dir/.config/llm-env/config.conf" << 'EOF'
110+
[openai]
111+
base_url=https://api.openai.com/v1
112+
api_key_var=LLM_OPENAI_API_KEY
113+
default_model=gpt-5
114+
description=Test OpenAI provider
115+
enabled=true
116+
EOF
117+
89118
# Test through the main script interface
90119
run bash -c "
91120
export BASH_ASSOC_ARRAY_SUPPORT='false'
121+
export XDG_CONFIG_HOME='$test_config_dir/.config'
92122
source $BATS_TEST_DIRNAME/../../llm-env
93123
get_provider_value 'PROVIDER_BASE_URLS' 'openai'
94124
"
125+
126+
# Clean up
127+
rm -rf "$test_config_dir"
128+
95129
[ "$status" -eq 0 ]
96130
[[ "$output" =~ "api.openai.com" ]]
97131
}
98132

99133
@test "provider operations: list providers works in both modes" {
134+
# Create test config with known openai provider
135+
local test_config_dir="$BATS_TMPDIR/llm-env-list-test"
136+
mkdir -p "$test_config_dir/.config/llm-env"
137+
cat > "$test_config_dir/.config/llm-env/config.conf" << 'EOF'
138+
[openai]
139+
base_url=https://api.openai.com/v1
140+
api_key_var=LLM_OPENAI_API_KEY
141+
default_model=gpt-5
142+
description=Test OpenAI provider
143+
enabled=true
144+
EOF
145+
100146
# Test with native arrays (bash 4.0+)
101147
run bash -c "
102148
export BASH_ASSOC_ARRAY_SUPPORT='true'
149+
export XDG_CONFIG_HOME='$test_config_dir/.config'
103150
source $BATS_TEST_DIRNAME/../../llm-env list
104151
"
105152
[ "$status" -eq 0 ]
106153
[[ "$output" =~ "Available providers:" ]]
107154
[[ "$output" =~ "openai" ]]
108-
155+
109156
# Test with compatibility arrays (bash 3.2)
110157
run bash -c "
111158
export BASH_ASSOC_ARRAY_SUPPORT='false'
159+
export XDG_CONFIG_HOME='$test_config_dir/.config'
112160
source $BATS_TEST_DIRNAME/../../llm-env list
113161
"
162+
163+
# Clean up
164+
rm -rf "$test_config_dir"
165+
114166
[ "$status" -eq 0 ]
115167
[[ "$output" =~ "Available providers:" ]]
116168
[[ "$output" =~ "openai" ]]
117169
}
118170

119171
@test "provider operations: set provider works in both modes" {
172+
# Create test config with known openai provider
173+
local test_config_dir="$BATS_TMPDIR/llm-env-set-test"
174+
mkdir -p "$test_config_dir/.config/llm-env"
175+
cat > "$test_config_dir/.config/llm-env/config.conf" << 'EOF'
176+
[openai]
177+
base_url=https://api.openai.com/v1
178+
api_key_var=LLM_OPENAI_API_KEY
179+
default_model=gpt-5
180+
description=Test OpenAI provider
181+
enabled=true
182+
EOF
183+
120184
# Test with native arrays (bash 4.0+)
121185
run bash -c "
122186
export LLM_OPENAI_API_KEY='test-key-12345'
123187
export BASH_ASSOC_ARRAY_SUPPORT='true'
188+
export XDG_CONFIG_HOME='$test_config_dir/.config'
124189
source $BATS_TEST_DIRNAME/../../llm-env set openai
125190
"
126191
[ "$status" -eq 0 ]
127192
[[ "$output" =~ "openai" ]]
128-
193+
129194
# Test with compatibility arrays (bash 3.2)
130195
run bash -c "
131196
export LLM_OPENAI_API_KEY='test-key-12345'
132197
export BASH_ASSOC_ARRAY_SUPPORT='false'
198+
export XDG_CONFIG_HOME='$test_config_dir/.config'
133199
source $BATS_TEST_DIRNAME/../../llm-env set openai
134200
"
201+
202+
# Clean up
203+
rm -rf "$test_config_dir"
204+
135205
[ "$status" -eq 0 ]
136206
[[ "$output" =~ "openai" ]]
137207
}

0 commit comments

Comments
 (0)