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