Skip to content

Commit baf499c

Browse files
Copilotalexec
andauthored
Add test for combined task and user prompt parsing (#177)
* Initial plan * Add test for task prompt and user prompt parsing Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Fix test to validate string indices before comparison Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
1 parent 95cb263 commit baf499c

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

pkg/codingcontext/context_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,58 @@ func TestUserPrompt(t *testing.T) {
16601660
wantErr: true,
16611661
errContains: "command not found",
16621662
},
1663+
{
1664+
name: "both task prompt and user prompt parse correctly",
1665+
setup: func(t *testing.T, dir string) {
1666+
// Task has text and slash command
1667+
createTask(t, dir, "parse-test", "", "Task prompt with text\n/task-command arg1\nMore task text\n")
1668+
createCommand(t, dir, "task-command", "", "Task command output ${param1}")
1669+
createCommand(t, dir, "user-command", "", "User command output ${param2}")
1670+
},
1671+
opts: []Option{
1672+
WithUserPrompt("User prompt with text\n/user-command arg2\nMore user text"),
1673+
WithParams(taskparser.Params{
1674+
"param1": []string{"value1"},
1675+
"param2": []string{"value2"},
1676+
}),
1677+
},
1678+
taskName: "parse-test",
1679+
wantErr: false,
1680+
check: func(t *testing.T, result *Result) {
1681+
// Verify task content contains both task and user prompt elements
1682+
if !strings.Contains(result.Task.Content, "Task prompt with text") {
1683+
t.Error("expected task content to contain 'Task prompt with text'")
1684+
}
1685+
if !strings.Contains(result.Task.Content, "More task text") {
1686+
t.Error("expected task content to contain 'More task text'")
1687+
}
1688+
if !strings.Contains(result.Task.Content, "User prompt with text") {
1689+
t.Error("expected task content to contain 'User prompt with text'")
1690+
}
1691+
if !strings.Contains(result.Task.Content, "More user text") {
1692+
t.Error("expected task content to contain 'More user text'")
1693+
}
1694+
// Verify both commands were expanded with correct parameters
1695+
if !strings.Contains(result.Task.Content, "Task command output value1") {
1696+
t.Error("expected task command to be expanded with param1=value1")
1697+
}
1698+
if !strings.Contains(result.Task.Content, "User command output value2") {
1699+
t.Error("expected user command to be expanded with param2=value2")
1700+
}
1701+
// Verify delimiter is present (separating task from user prompt)
1702+
if !strings.Contains(result.Task.Content, "---") {
1703+
t.Error("expected delimiter '---' between task and user prompt")
1704+
}
1705+
// Verify order: task content comes before user content
1706+
taskIdx := strings.Index(result.Task.Content, "Task prompt with text")
1707+
userIdx := strings.Index(result.Task.Content, "User prompt with text")
1708+
if taskIdx == -1 || userIdx == -1 {
1709+
t.Error("expected both task and user prompt text to be found in result")
1710+
} else if taskIdx >= userIdx {
1711+
t.Error("expected task content to come before user prompt content")
1712+
}
1713+
},
1714+
},
16631715
}
16641716

16651717
for _, tt := range tests {

0 commit comments

Comments
 (0)