Skip to content

Commit 18a223f

Browse files
committed
feat/batch-changes: fix codingAgent prompt-quoting test
The previous assertion round-tripped the rendered shell script through shellquote.Split and compared the last token to the expected prompt. That tokenizer does not understand POSIX shell comments, so the apostrophe in the install script's "can't" comment was read as an unterminated single-quoted string and swallowed everything to EOF as one token. Production /bin/sh handles the comment correctly; only the test was broken. Assert on the shell-quoted suffix instead.
1 parent 8a10375 commit 18a223f

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

lib/batches/codingagent/codingagent_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package codingagent_test
22

33
import (
44
"errors"
5+
"strings"
56
"testing"
67

78
"github.com/kballard/go-shellquote"
@@ -36,13 +37,20 @@ func TestRenderRunCommand_promptShellQuoting(t *testing.T) {
3637
t.Fatal(err)
3738
}
3839

39-
tokens, err := shellquote.Split(cmd)
40-
if err != nil {
41-
t.Fatal(err)
42-
}
40+
// The rendered command appends the shell-quoted prompt as its final
41+
// argument. Round-tripping via shellquote.Split is unreliable here
42+
// because the install script contains POSIX shell comments with
43+
// apostrophes (e.g. "can't"), which shellquote does not understand
44+
// and would treat as unterminated quoted strings. Assert on the
45+
// suffix instead.
4346
wantPrompt := "You're working in the " + repoName + " repository.\n" +
4447
"Add a README section describing the project; don't touch existing files."
45-
if got := tokens[len(tokens)-1]; got != wantPrompt {
46-
t.Fatalf("prompt mismatch:\n got: %q\n want: %q", got, wantPrompt)
48+
wantQuoted := shellquote.Join(wantPrompt)
49+
if !strings.HasSuffix(cmd, wantQuoted) {
50+
tail := cmd
51+
if n := len(wantQuoted) + 50; len(cmd) > n {
52+
tail = cmd[len(cmd)-n:]
53+
}
54+
t.Fatalf("rendered cmd does not end with shell-quoted prompt:\n want suffix: %q\n cmd tail: %q", wantQuoted, tail)
4755
}
4856
}

0 commit comments

Comments
 (0)