@@ -143,3 +143,71 @@ func TestToolsetInstructions(t *testing.T) {
143143 expected := "Dummy fetch tool instruction"
144144 require .Equal (t , expected , instructions )
145145}
146+
147+ // TestExpandCommandPlaceholders tests that $placeholders in commands are expanded with env var values
148+ func TestExpandCommandPlaceholders (t * testing.T ) {
149+ tests := []struct {
150+ name string
151+ commands map [string ]string
152+ envVars map [string ]string
153+ expected map [string ]string
154+ }{
155+ {
156+ name : "single placeholder" ,
157+ commands : map [string ]string {"greet" : "Say hello to $USER" },
158+ envVars : map [string ]string {"USER" : "alice" },
159+ expected : map [string ]string {"greet" : "Say hello to alice" },
160+ },
161+ {
162+ name : "multiple placeholders" ,
163+ commands : map [string ]string {"analyze" : "Analyze $PROJECT_NAME in $ENVIRONMENT" },
164+ envVars : map [string ]string {"PROJECT_NAME" : "myproject" , "ENVIRONMENT" : "production" },
165+ expected : map [string ]string {"analyze" : "Analyze myproject in production" },
166+ },
167+ {
168+ name : "no placeholders" ,
169+ commands : map [string ]string {"simple" : "List all files" },
170+ envVars : map [string ]string {},
171+ expected : map [string ]string {"simple" : "List all files" },
172+ },
173+ {
174+ name : "placeholder with curly braces" ,
175+ commands : map [string ]string {"check" : "Check ${SERVICE_NAME} status" },
176+ envVars : map [string ]string {"SERVICE_NAME" : "api-server" },
177+ expected : map [string ]string {"check" : "Check api-server status" },
178+ },
179+ {
180+ name : "missing env var expands to empty string" ,
181+ commands : map [string ]string {"test" : "Check $MISSING_VAR status" },
182+ envVars : map [string ]string {},
183+ expected : map [string ]string {"test" : "Check status" },
184+ },
185+ {
186+ name : "empty commands" ,
187+ commands : map [string ]string {},
188+ envVars : map [string ]string {},
189+ expected : map [string ]string {},
190+ },
191+ }
192+
193+ for _ , tt := range tests {
194+ t .Run (tt .name , func (t * testing.T ) {
195+ // Create a test environment provider
196+ env := & testEnvProvider {vars : tt .envVars }
197+
198+ // Expand the commands
199+ result := expandCommandPlaceholders (t .Context (), tt .commands , env )
200+
201+ require .Equal (t , tt .expected , result )
202+ })
203+ }
204+ }
205+
206+ // testEnvProvider is a simple environment provider for testing
207+ type testEnvProvider struct {
208+ vars map [string ]string
209+ }
210+
211+ func (p * testEnvProvider ) Get (_ context.Context , name string ) string {
212+ return p .vars [name ]
213+ }
0 commit comments