Skip to content

Commit 7a48538

Browse files
Copilotalexec
andcommitted
Improve comment clarity per code review feedback
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
1 parent 91aa33f commit 7a48538

2 files changed

Lines changed: 49 additions & 48 deletions

File tree

integration_test.go

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,66 +1233,66 @@ This rule is from a remote directory.
12331233

12341234
// TestSingleExpansion verifies that content is expanded only once in the full flow
12351235
func TestSingleExpansion(t *testing.T) {
1236-
dirs := setupTestDirs(t)
1236+
dirs := setupTestDirs(t)
12371237

1238-
// Create a task that uses a parameter with expansion syntax
1239-
taskFile := filepath.Join(dirs.tasksDir, "test-expand.md")
1240-
taskContent := `Task with parameter: ${param1}
1238+
// Create a task that uses a parameter with expansion syntax
1239+
taskFile := filepath.Join(dirs.tasksDir, "test-expand.md")
1240+
taskContent := `Task with parameter: ${param1}
12411241
12421242
And a value that looks like expansion syntax but should not be expanded: ${"nested"}`
1243-
if err := os.WriteFile(taskFile, []byte(taskContent), 0644); err != nil {
1244-
t.Fatalf("failed to create task file: %v", err)
1245-
}
1243+
if err := os.WriteFile(taskFile, []byte(taskContent), 0644); err != nil {
1244+
t.Fatalf("failed to create task file: %v", err)
1245+
}
12461246

1247-
// Run with param1 set to a value that contains expansion syntax
1248-
output := runTool(t, "-C", dirs.tmpDir, "-p", "param1=!`echo hello`", "test-expand")
1247+
// Run with param1 set to a value that contains expansion syntax
1248+
output := runTool(t, "-C", dirs.tmpDir, "-p", "param1=!`echo hello`", "test-expand")
12491249

1250-
// The param1 should be replaced with the literal string "!`echo hello`"
1251-
// It should NOT be expanded again (that would execute the command)
1252-
if !strings.Contains(output, "!`echo hello`") {
1253-
t.Errorf("Expected param1 to be replaced with literal value, got: %s", output)
1254-
}
1250+
// The param1 should be replaced with the literal string "!`echo hello`"
1251+
// It should NOT be expanded again (that would execute the command)
1252+
if !strings.Contains(output, "!`echo hello`") {
1253+
t.Errorf("Expected param1 to be replaced with literal value, got: %s", output)
1254+
}
12551255

1256-
// Verify "hello" is not in output (which would indicate the command was executed)
1257-
// Note: there may be other "hello" strings, so check for the specific context
1258-
if strings.Contains(output, "Task with parameter: hello") {
1259-
t.Errorf("Parameter value was re-expanded (command was executed), got: %s", output)
1260-
}
1256+
// Verify "hello" is not in output (which would indicate the command was executed)
1257+
// Note: there may be other "hello" strings, so check for the specific context
1258+
if strings.Contains(output, "Task with parameter: hello") {
1259+
t.Errorf("Parameter value was re-expanded (command was executed), got: %s", output)
1260+
}
12611261
}
12621262

12631263
// TestCommandExpansionOnce verifies that command files are expanded only once
12641264
func TestCommandExpansionOnce(t *testing.T) {
1265-
dirs := setupTestDirs(t)
1266-
commandsDir := filepath.Join(dirs.tmpDir, ".agents", "commands")
1267-
if err := os.MkdirAll(commandsDir, 0o755); err != nil {
1268-
t.Fatalf("failed to create commands dir: %v", err)
1269-
}
1265+
dirs := setupTestDirs(t)
1266+
commandsDir := filepath.Join(dirs.tmpDir, ".agents", "commands")
1267+
if err := os.MkdirAll(commandsDir, 0o755); err != nil {
1268+
t.Fatalf("failed to create commands dir: %v", err)
1269+
}
12701270

1271-
// Create a command file with a parameter
1272-
commandFile := filepath.Join(commandsDir, "test-cmd.md")
1273-
commandContent := `Command param: ${cmd_param}`
1274-
if err := os.WriteFile(commandFile, []byte(commandContent), 0644); err != nil {
1275-
t.Fatalf("failed to create command file: %v", err)
1276-
}
1271+
// Create a command file with a parameter
1272+
commandFile := filepath.Join(commandsDir, "test-cmd.md")
1273+
commandContent := `Command param: ${cmd_param}`
1274+
if err := os.WriteFile(commandFile, []byte(commandContent), 0644); err != nil {
1275+
t.Fatalf("failed to create command file: %v", err)
1276+
}
12771277

1278-
// Create a task that calls the command with a param containing expansion syntax
1279-
taskFile := filepath.Join(dirs.tasksDir, "test-cmd-task.md")
1280-
taskContent := `/test-cmd cmd_param="!` + "`echo injected`" + `"`
1281-
if err := os.WriteFile(taskFile, []byte(taskContent), 0644); err != nil {
1282-
t.Fatalf("failed to create task file: %v", err)
1283-
}
1278+
// Create a task that calls the command with a param containing expansion syntax
1279+
taskFile := filepath.Join(dirs.tasksDir, "test-cmd-task.md")
1280+
taskContent := `/test-cmd cmd_param="!` + "`echo injected`" + `"`
1281+
if err := os.WriteFile(taskFile, []byte(taskContent), 0644); err != nil {
1282+
t.Fatalf("failed to create task file: %v", err)
1283+
}
12841284

1285-
// Run the task
1286-
output := runTool(t, "-C", dirs.tmpDir, "test-cmd-task")
1285+
// Run the task
1286+
output := runTool(t, "-C", dirs.tmpDir, "test-cmd-task")
12871287

1288-
// The command parameter should be replaced with the literal string "!`echo injected`"
1289-
// It should NOT be expanded again (that would execute the command)
1290-
if !strings.Contains(output, "!`echo injected`") {
1291-
t.Errorf("Expected command param to be replaced with literal value, got: %s", output)
1292-
}
1288+
// The command parameter should be replaced with the literal string "!`echo injected`"
1289+
// It should NOT be expanded again (that would execute the command)
1290+
if !strings.Contains(output, "!`echo injected`") {
1291+
t.Errorf("Expected command param to be replaced with literal value, got: %s", output)
1292+
}
12931293

1294-
// Verify "injected" is not in output (which would indicate the command was executed)
1295-
if strings.Contains(output, "Command param: injected") {
1296-
t.Errorf("Command parameter value was re-expanded (command was executed), got: %s", output)
1297-
}
1294+
// Verify "injected" is not in output (which would indicate the command was executed)
1295+
if strings.Contains(output, "Command param: injected") {
1296+
t.Errorf("Command parameter value was re-expanded (command was executed), got: %s", output)
1297+
}
12981298
}

pkg/codingcontext/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ func (cc *Context) findTask(taskName string) error {
201201

202202
// Build the final content by processing each block
203203
// Text blocks are expanded if expand_params is not false
204-
// Slash command arguments are NOT expanded (they are literal parameter values)
204+
// Slash command arguments are NOT expanded here - they are passed as literals
205+
// to command files where they may be substituted via ${param} templates
205206
finalContent := strings.Builder{}
206207
for _, block := range task {
207208
if block.Text != nil {

0 commit comments

Comments
 (0)