Skip to content

Commit f6fbaec

Browse files
kwonah0claude
andcommitted
Add configuration priority testing scripts
- test-config-priority.sh: Interactive menu-driven testing script with 5 scenarios - quick-config-test.sh: Simple script that runs the two main test cases sequentially Testing scenarios: 1. Environment variables only (no user config file) 2. User config file + environment override 3. Built-in defaults only 4. Custom user config file + environment override 5. Show current configuration analysis Features: - Color-coded output for better readability - Expected behavior descriptions for each test - Automatic cleanup of temporary files - Configuration analysis tool - Easy reproduction of the priority system tests Usage: - ./scripts/test-config-priority.sh (interactive menu) - ./scripts/quick-config-test.sh (run both main tests) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3c9ff1f commit f6fbaec

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed

scripts/quick-config-test.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Quick Configuration Test - The two scenarios you just tested
4+
5+
echo "🚀 Quick DTUI2 Configuration Priority Tests"
6+
echo "==========================================="
7+
8+
# Colors
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
NC='\033[0m'
12+
13+
echo ""
14+
echo "${GREEN}Test 1: Environment Variables Only${NC}"
15+
echo "${YELLOW}DTUI_CFG__ai__shell__args='[\"[ENV_ONLY]:\"]\' npm run electron${NC}"
16+
echo "Expected: Skip user config file, use env vars only"
17+
echo "Look for: 'No DTUI_USER_CONFIGFILE specified, skipping user config file stage'"
18+
echo ""
19+
DTUI_CFG__ai__shell__command=echo \
20+
DTUI_CFG__ai__shell__args='["[ENV_ONLY]:"]' \
21+
DTUI_CFG__ai__shell__template='{command} {args} "{prompt}"' \
22+
npm run electron
23+
24+
echo ""
25+
echo "Press Enter to continue to Test 2..."
26+
read
27+
28+
echo ""
29+
echo "${GREEN}Test 2: User Config File + Environment Override${NC}"
30+
echo "${YELLOW}DTUI_USER_CONFIGFILE=dtui-hpc.json DTUI_CFG__ai__shell__args='[\"[USER+ENV]:\"]\' npm run electron${NC}"
31+
echo "Expected: Load dtui-hpc.json, then override with env vars"
32+
echo "Look for: 'Loaded user config file: dtui-hpc.json'"
33+
echo ""
34+
DTUI_USER_CONFIGFILE=dtui-hpc.json \
35+
DTUI_CFG__ai__shell__command=echo \
36+
DTUI_CFG__ai__shell__args='["[USER+ENV]:"]' \
37+
DTUI_CFG__ai__shell__template='{command} {args} "{prompt}"' \
38+
npm run electron
39+
40+
echo ""
41+
echo "✅ Both tests completed!"

scripts/test-config-priority.sh

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#!/bin/bash
2+
3+
# DTUI2 Configuration Priority Testing Script
4+
# Tests the 3-stage priority system: Environment > User Config File > Built-in Defaults
5+
6+
echo "🧪 DTUI2 Configuration Priority Test Script"
7+
echo "=========================================="
8+
echo ""
9+
10+
# Colors for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
BLUE='\033[0;34m'
15+
NC='\033[0m' # No Color
16+
17+
function show_menu() {
18+
echo "Select test scenario:"
19+
echo ""
20+
echo "${BLUE}1.${NC} Environment variables only (skip user config file)"
21+
echo " ${YELLOW}DTUI_CFG__ai__shell__args='[\"[ENV_ONLY]:\"]\' npm run electron${NC}"
22+
echo ""
23+
echo "${BLUE}2.${NC} User config file + Environment override"
24+
echo " ${YELLOW}DTUI_USER_CONFIGFILE=dtui-hpc.json DTUI_CFG__ai__shell__command=echo npm run electron${NC}"
25+
echo ""
26+
echo "${BLUE}3.${NC} Built-in defaults only (no env vars, no user config)"
27+
echo " ${YELLOW}npm run electron${NC}"
28+
echo ""
29+
echo "${BLUE}4.${NC} Custom user config file + Environment override"
30+
echo " Creates temporary config file with custom settings"
31+
echo ""
32+
echo "${BLUE}5.${NC} Show current configuration (without launching app)"
33+
echo ""
34+
echo "${BLUE}q.${NC} Quit"
35+
echo ""
36+
}
37+
38+
function test_env_only() {
39+
echo "${GREEN}🚀 Testing: Environment variables only${NC}"
40+
echo "Expected: Should skip user config file stage and use env vars"
41+
echo "Look for: 'No DTUI_USER_CONFIGFILE specified, skipping user config file stage'"
42+
echo "Expected output: [ENV_ONLY]: <your_message>"
43+
echo ""
44+
echo "Press Ctrl+C to stop the app when done testing..."
45+
echo ""
46+
47+
DTUI_CFG__ai__shell__command=echo \
48+
DTUI_CFG__ai__shell__args='["[ENV_ONLY]:"]' \
49+
DTUI_CFG__ai__shell__template='{command} {args} "{prompt}"' \
50+
npm run electron
51+
}
52+
53+
function test_user_config_with_env() {
54+
echo "${GREEN}🚀 Testing: User config file + Environment override${NC}"
55+
echo "Expected: Should load dtui-hpc.json, then override with env vars"
56+
echo "Look for: 'Loaded user config file: dtui-hpc.json'"
57+
echo "Expected output: [HPC+ENV]: <your_message>"
58+
echo ""
59+
echo "Press Ctrl+C to stop the app when done testing..."
60+
echo ""
61+
62+
DTUI_USER_CONFIGFILE=dtui-hpc.json \
63+
DTUI_CFG__ai__shell__command=echo \
64+
DTUI_CFG__ai__shell__args='["[HPC+ENV]:"]' \
65+
DTUI_CFG__ai__shell__template='{command} {args} "{prompt}"' \
66+
npm run electron
67+
}
68+
69+
function test_defaults_only() {
70+
echo "${GREEN}🚀 Testing: Built-in defaults only${NC}"
71+
echo "Expected: Should use only built-in defaults"
72+
echo "Look for: 'No DTUI_USER_CONFIGFILE specified, skipping user config file stage'"
73+
echo "Expected output: [DTUI-SHELL]: <your_message>"
74+
echo ""
75+
echo "Press Ctrl+C to stop the app when done testing..."
76+
echo ""
77+
78+
npm run electron
79+
}
80+
81+
function test_custom_user_config() {
82+
echo "${GREEN}🚀 Testing: Custom user config file + Environment override${NC}"
83+
84+
# Create temporary user config file
85+
TEMP_CONFIG="/tmp/dtui-test-$(date +%s).json"
86+
cat > "$TEMP_CONFIG" << 'EOF'
87+
{
88+
"ai": {
89+
"provider": "shell",
90+
"shell": {
91+
"command": "printf",
92+
"args": ["[CUSTOM_USER_FILE]: %s\\n"],
93+
"template": "{command} {args}",
94+
"timeout": 8000,
95+
"outputFormat": {
96+
"useCodeBlock": true,
97+
"codeBlockSyntax": "bash"
98+
}
99+
}
100+
}
101+
}
102+
EOF
103+
104+
echo "Created temporary config file: $TEMP_CONFIG"
105+
echo "Config contents:"
106+
echo "${YELLOW}$(cat $TEMP_CONFIG)${NC}"
107+
echo ""
108+
echo "Expected: Should load custom config, then override args with env var"
109+
echo "Look for: 'Loaded user config file: $TEMP_CONFIG'"
110+
echo "Expected output: [CUSTOM_OVERRIDE]: <your_message>"
111+
echo ""
112+
echo "Press Ctrl+C to stop the app when done testing..."
113+
echo ""
114+
115+
DTUI_USER_CONFIGFILE="$TEMP_CONFIG" \
116+
DTUI_CFG__ai__shell__args='["[CUSTOM_OVERRIDE]:"]' \
117+
npm run electron
118+
119+
# Clean up
120+
rm -f "$TEMP_CONFIG"
121+
echo ""
122+
echo "Cleaned up temporary config file: $TEMP_CONFIG"
123+
}
124+
125+
function show_current_config() {
126+
echo "${GREEN}📋 Current Configuration Analysis${NC}"
127+
echo ""
128+
129+
echo "${BLUE}Environment Variables (DTUI_CFG__*):${NC}"
130+
env | grep "^DTUI_CFG__" || echo " None set"
131+
echo ""
132+
133+
echo "${BLUE}User Config File Environment Variable:${NC}"
134+
if [ -n "$DTUI_USER_CONFIGFILE" ]; then
135+
echo " DTUI_USER_CONFIGFILE=$DTUI_USER_CONFIGFILE"
136+
if [ -f "$DTUI_USER_CONFIGFILE" ]; then
137+
echo " ${GREEN}✅ File exists${NC}"
138+
else
139+
echo " ${RED}❌ File does not exist${NC}"
140+
fi
141+
else
142+
echo " Not set (user config file stage will be skipped)"
143+
fi
144+
echo ""
145+
146+
echo "${BLUE}Built-in Config Files:${NC}"
147+
if [ -f "dtui.json" ]; then
148+
echo " dtui.json: ${GREEN}✅ exists${NC}"
149+
else
150+
echo " dtui.json: ${RED}❌ missing${NC}"
151+
fi
152+
153+
if [ -f "dtui-hpc.json" ]; then
154+
echo " dtui-hpc.json: ${GREEN}✅ exists${NC}"
155+
else
156+
echo " dtui-hpc.json: ${RED}❌ missing${NC}"
157+
fi
158+
echo ""
159+
160+
echo "${BLUE}Priority Order:${NC}"
161+
echo " 1. Environment variables (DTUI_CFG__*) - ${YELLOW}Highest Priority${NC}"
162+
echo " 2. User config file (DTUI_USER_CONFIGFILE) - ${YELLOW}Medium Priority${NC}"
163+
echo " 3. Built-in defaults - ${YELLOW}Lowest Priority${NC}"
164+
}
165+
166+
# Main loop
167+
while true; do
168+
echo ""
169+
show_menu
170+
echo -n "Enter your choice (1-5, q): "
171+
read choice
172+
echo ""
173+
174+
case $choice in
175+
1)
176+
test_env_only
177+
;;
178+
2)
179+
test_user_config_with_env
180+
;;
181+
3)
182+
test_defaults_only
183+
;;
184+
4)
185+
test_custom_user_config
186+
;;
187+
5)
188+
show_current_config
189+
;;
190+
q|Q)
191+
echo "👋 Goodbye!"
192+
exit 0
193+
;;
194+
*)
195+
echo "${RED}❌ Invalid choice. Please select 1-5 or q.${NC}"
196+
;;
197+
esac
198+
199+
echo ""
200+
echo "Press Enter to return to menu..."
201+
read
202+
done

0 commit comments

Comments
 (0)