Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(agent/cursor): send prompt on stdin so CLI-like flags cannot be re-tokenised (MUL-4992) (#5711)

Bohan Jiange5e278a1a26f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e484884af5..d98e815fc3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -194,6 +194,21 @@ jobs:
# outside this PR; the normal backend job still runs the full package.
run: go test ./internal/daemon/execenv -run '^TestPrepareIsolated_WindowsKillsDescendantBeforeRetry$' -count=1 -timeout=5m
+ - name: Test Windows agent launcher argv/stdin handling
+ working-directory: server
+ # Agent prompts must never reach a Windows launcher through argv: the
+ # official cursor-agent.ps1 ends in `& node.exe index.js $args`, and
+ # PowerShell re-serialises $args onto the child command line. Under
+ # Legacy native argument passing (powershell.exe 5.1, pwsh <= 7.2) a
+ # prompt holding embedded quotes is re-tokenised and fragments like
+ # `-X` become flags (#5649). Only a real PowerShell host proves this,
+ # so it cannot live in the ubuntu backend job. Scoped to the launcher
+ # tests, which are windows-tagged and therefore run nowhere else today;
+ # the backend job still runs the full package on Linux.
+ # -v so a silent skip (no PowerShell host resolved, or a -run pattern
+ # that stops matching) is visible in the log instead of passing as "ok".
+ run: go test ./pkg/agent -v -run '^(TestCursorExecutePromptSurvivesPowerShellShim|TestPlatformCursorInvocation|TestPlatformCopilotInvocation|TestPlatformPiInvocation)' -count=1 -timeout=5m
+
- name: Build Windows CLI helper entrypoint
working-directory: server
run: go build ./cmd/multica
diff --git a/server/pkg/agent/cursor.go b/server/pkg/agent/cursor.go
index 0baa7e80df..037e5f1766 100644
--- a/server/pkg/agent/cursor.go
+++ b/server/pkg/agent/cursor.go
@@ -5,10 +5,12 @@ import (
"context"
"encoding/json"
"fmt"
+ "io"
"log/slog"
"os/exec"
"regexp"
"strings"
+ "sync"
"time"
)
@@ -33,7 +35,7 @@ func (b *cursorBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
timeout := opts.Timeout
runCtx, cancel := runContext(ctx, timeout)
- args := buildCursorArgs(prompt, opts, b.cfg.Logger)
+ args := buildCursorArgs(opts, b.cfg.Logger)
argv0, cmdArgs := chooseCursorInvocation(execName, lookedUp, args, b.cfg.Logger)
cmd := exec.CommandContext(runCtx, argv0, cmdArgs...)
@@ -50,10 +52,18 @@ func (b *cursorBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
cancel()
return nil, fmt.Errorf("cursor stdout pipe: %w", err)
}
+ stdin, err := cmd.StdinPipe()
+ if err != nil {
+ cancel()
+ return nil, fmt.Errorf("cursor stdin pipe: %w", err)
+ }
+ var closeStdinOnce sync.Once
+ closeStdin := func() { closeStdinOnce.Do(func() { _ = stdin.Close() }) }
stderrBuf := newStderrTail(newLogWriter(b.cfg.Logger, "[cursor:stderr] "), agentStderrTailBytes)
cmd.Stderr = stderrBuf
if err := cmd.Start(); err != nil {
+ closeStdin()
cancel()
return nil, fmt.Errorf("start cursor-agent: %w", err)
}
@@ -63,14 +73,30 @@ func (b *cursorBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
msgCh := make(chan Message, 256)
resCh := make(chan Result, 1)
+ // The prompt is delivered on stdin (see buildCursorArgs). Write it from its
+ // own goroutine so it cannot deadlock against the stdout reader below: a
+ // prompt larger than the OS pipe buffer (~64 KiB) blocks mid-write until the
+ // child drains it, and the child cannot drain while we are not reading its
+ // stdout. Closing stdin is what signals end-of-prompt — cursor-agent reads
+ // to EOF — so we always close, on both the success and error paths.
+ writeErrCh := make(chan error, 1)
+ go func() {
+ _, err := io.WriteString(stdin, prompt)
+ closeStdin()
+ writeErrCh <- err
+ }()
+
go func() {
defer cancel()
defer close(msgCh)
defer close(resCh)
// Close stdout when the context is cancelled so scanner.Scan() unblocks.
+ // Closing stdin too releases a prompt write still blocked on a full pipe
+ // (e.g. the child died before draining it), so that goroutine cannot leak.
go func() {
<-runCtx.Done()
+ closeStdin()
_ = stdout.Close()
}()
@@ -224,6 +250,10 @@ func (b *cursorBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
exitErr := cmd.Wait()
duration := time.Since(startTime)
+ // Wait has already closed the stdin pipe, so a prompt write still blocked
+ // on a full pipe has returned by now; the writer sends exactly once.
+ writeErr := <-writeErrCh
+
if resultSeen {
// A parsed result is the protocol boundary. Ignore the cancellation and
// exit error caused by stopping a Cursor worker that lingers afterward.
@@ -244,6 +274,14 @@ func (b *cursorBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
case protocolError != "":
finalStatus = "failed"
finalError = protocolError
+ case writeErr != nil:
+ // Ranked below explicit agent errors because a child that exits
+ // early for its own reason (bad auth, bad flag) makes our write
+ // fail with EPIPE as a side effect. The stderr tail is appended
+ // to every !resultSeen failure below, so the real cause still
+ // surfaces either way.
+ finalStatus = "failed"
+ finalError = fmt.Sprintf("cursor-agent prompt write failed: %v", writeErr)
case exitErr != nil:
finalStatus = "failed"
finalError = fmt.Sprintf("cursor-agent exited with error: %v", exitErr)
@@ -587,12 +625,27 @@ var cursorBlockedArgs = map[string]blockedArgMode{
// buildCursorArgs assembles the argv for a one-shot cursor-agent invocation.
//
-// Usage: cursor-agent -p <prompt> --output-format stream-json
+// Usage: cursor-agent -p --output-format stream-json
//
// --workspace <cwd> --yolo [--model <m>] [--resume <id>]
-func buildCursorArgs(prompt string, opts ExecOptions, logger *slog.Logger) []string {
+//
+// The prompt is deliberately NOT part of argv. cursor-agent's -p is a boolean
+// print-mode switch and the prompt is a positional argument; when no positional
+// prompt is present and stdin is not a TTY, the CLI reads stdin to EOF and uses
+// that as the prompt. We rely on that path because putting user-controlled text
+// on the command line is not safe on Windows: the official cursor-agent.cmd/.ps1
+// launcher ends in `& node.exe index.js $args`, and PowerShell re-serialises
+// $args onto node's command line. Under Windows PowerShell 5.1 (and pwsh
+// <= 7.2, which default to Legacy native argument passing) an argument holding
+// embedded double quotes is not re-escaped, so a prompt containing e.g.
+// `go build -ldflags "-X main.version=foo"` gets re-tokenised and `-X` reaches
+// commander.js as a standalone flag: "error: unknown option '-X'" (#5649).
+// Routing the prompt through stdin keeps it off every command line, so no shell
+// or launcher on any platform can re-tokenise it. Only fixed, content-free
+// flags remain in argv.
+func buildCursorArgs(opts ExecOptions, logger *slog.Logger) []string {
args := []string{
- "-p", prompt,
+ "-p",
"--output-format", "stream-json",
"--yolo",
}
diff --git a/server/pkg/agent/cursor_stdin_unix_test.go b/server/pkg/agent/cursor_stdin_unix_test.go
new file mode 100644
index 0000000000..71010e0b27
--- /dev/null
+++ b/server/pkg/agent/cursor_stdin_unix_test.go
@@ -0,0 +1,237 @@
+//go:build unix
+
+package agent
+
+import (
+ "context"
+ "fmt"
+ "log/slog"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// cursorStdinProbe runs the cursor backend against a fake cursor-agent that
+// records the argv it was given and drains its stdin to EOF, then emits a
+// terminal stream-json result. It returns (argv, stdin, result).
+//
+// Draining stdin before answering mirrors the real CLI: with no positional
+// prompt and a non-TTY stdin, cursor-agent reads stdin to EOF and uses it as
+// the prompt.
+func cursorStdinProbe(t *testing.T, prompt string) ([]string, string, Result) {
+ t.Helper()
+
+ dir := t.TempDir()
+ argvPath := filepath.Join(dir, "argv.txt")
+ stdinPath := filepath.Join(dir, "stdin.txt")
+
+ // Record argv one element per line, then drain stdin to EOF before
+ // answering. Quoting "$@" keeps each argv element intact.
+ script := fmt.Sprintf(`#!/bin/sh
+: > %[1]q
+for a in "$@"; do printf '%%s\n' "$a" >> %[1]q; done
+cat > %[2]q
+printf '%%s\n' '{"type":"result","subtype":"success","is_error":false,"result":"ok"}'
+`, argvPath, stdinPath)
+
+ fakePath := filepath.Join(dir, "cursor-agent")
+ writeTestExecutable(t, fakePath, []byte(script))
+
+ backend, err := New("cursor", Config{ExecutablePath: fakePath, Logger: slog.Default()})
+ if err != nil {
+ t.Fatalf("New(cursor): %v", err)
+ }
+ session, err := backend.Execute(t.Context(), prompt, ExecOptions{Timeout: 30 * time.Second})
+ if err != nil {
+ t.Fatalf("Execute: %v", err)
+ }
+ go func() {
+ for range session.Messages {
+ }
+ }()
+ result := <-session.Result
+
+ argvRaw, err := os.ReadFile(argvPath)
+ if err != nil {
+ t.Fatalf("read recorded argv: %v", err)
+ }
+ stdinRaw, err := os.ReadFile(stdinPath)
+ if err != nil {
+ t.Fatalf("read recorded stdin: %v", err)
+ }
+ argv := strings.Split(strings.TrimSuffix(string(argvRaw), "\n"), "\n")
+ return argv, string(stdinRaw), result
+}
+
+// TestCursorExecuteSendsPromptOnStdinNotArgv is the regression test for #5649.
+// A prompt carrying CLI-like flags inside embedded double quotes (the exact
+// shape from the report) must reach the child intact on stdin, and must not
+// appear in argv at all — argv is where Windows launchers re-tokenise it.
+func TestCursorExecuteSendsPromptOnStdinNotArgv(t *testing.T) {
+ t.Parallel()
+
+ prompt := "Please fix the build.\n" +
+ "Log follows:\n" +
+ `go build -ldflags "-X main.version=foo -X main.commit=bar" -o bin/server ./cmd/server` + "\n" +
+ "Thanks."
+
+ argv, stdinGot, result := cursorStdinProbe(t, prompt)
+
+ if stdinGot != prompt {
+ t.Errorf("prompt did not arrive on stdin intact:\n got %q\n want %q", stdinGot, prompt)
+ }
+
+ // The whole point of the fix: no fragment of the prompt is in argv, so no
+ // shell or launcher on any platform can re-tokenise it into flags.
+ for _, a := range argv {
+ for _, needle := range []string{"-X", "ldflags", "main.version", "Please fix"} {
+ if strings.Contains(a, needle) {
+ t.Errorf("prompt fragment %q leaked into argv element %q; argv=%v", needle, a, argv)
+ }
+ }
+ }
+
+ // The fixed, content-free flags must still be present.
+ joined := strings.Join(argv, " ")
+ for _, want := range []string{"-p", "--output-format", "stream-json", "--yolo"} {
+ if !strings.Contains(joined, want) {
+ t.Errorf("expected %q in argv, got %v", want, argv)
+ }
+ }
+
+ if result.Status != "completed" {
+ t.Fatalf("status = %q, want completed; error=%q", result.Status, result.Error)
+ }
+}
+
+// TestCursorExecuteLargePromptDoesNotDeadlock is the interlock test: it forces
+// the exact mutual block the concurrent writer exists to avoid.
+//
+// The child floods stdout PAST the pipe capacity *before* reading a byte of
+// stdin. So the child is blocked writing stdout, and a parent that wrote the
+// prompt before starting its stdout reader would be blocked writing stdin —
+// neither side can advance and the run only ends at the task timeout. It passes
+// only because the writer and the scanner run concurrently.
+//
+// Ordering matters: a fake that drains stdin first would pass even against a
+// synchronous write, which is why this test flooded stdout first.
+func TestCursorExecuteLargePromptDoesNotDeadlock(t *testing.T) {
+ t.Parallel()
+
+ dir := t.TempDir()
+ stdinPath := filepath.Join(dir, "stdin.txt")
+
+ // ~520 KiB of stdout before any read of stdin, several times any plausible
+ // pipe buffer on Linux/macOS.
+ script := fmt.Sprintf(`#!/bin/sh
+yes '{"type":"noise","pad":"0123456789012345678901234567890123456789"}' | head -n 8000
+cat > %[1]q
+printf '%%s\n' '{"type":"result","subtype":"success","is_error":false,"result":"ok"}'
+`, stdinPath)
+
+ fakePath := filepath.Join(dir, "cursor-agent")
+ writeTestExecutable(t, fakePath, []byte(script))
+
+ prompt := strings.Repeat("multica cursor stdin payload 0123456789\n", 13_108)
+ if len(prompt) < 512*1024 {
+ t.Fatalf("test prompt too small: %d bytes", len(prompt))
+ }
+
+ backend, err := New("cursor", Config{ExecutablePath: fakePath, Logger: slog.Default()})
+ if err != nil {
+ t.Fatalf("New(cursor): %v", err)
+ }
+ // A deadlock surfaces as this timeout firing instead of a completed run.
+ session, err := backend.Execute(t.Context(), prompt, ExecOptions{Timeout: 30 * time.Second})
+ if err != nil {
+ t.Fatalf("Execute: %v", err)
+ }
+ go func() {
+ for range session.Messages {
+ }
+ }()
+ result := <-session.Result
+
+ stdinRaw, err := os.ReadFile(stdinPath)
+ if err != nil {
+ t.Fatalf("read recorded stdin: %v", err)
+ }
+ if len(stdinRaw) != len(prompt) {
+ t.Errorf("stdin truncated: got %d bytes, want %d", len(stdinRaw), len(prompt))
+ }
+ if string(stdinRaw) != prompt {
+ t.Error("large prompt arrived corrupted on stdin")
+ }
+ if result.Status != "completed" {
+ t.Fatalf("status = %q, want completed (deadlock would show as timeout); error=%q", result.Status, result.Error)
+ }
+}
+
+// TestCursorExecuteCancelReleasesBlockedPromptWrite pins the other unlock
+// point. The child never reads stdin at all, so a prompt past the pipe buffer
+// leaves the writer blocked indefinitely; cancelling the parent context must
+// close stdin, release that writer, and settle the run rather than hang.
+func TestCursorExecuteCancelReleasesBlockedPromptWrite(t *testing.T) {
+ t.Parallel()
+
+ dir := t.TempDir()
+ // Never reads stdin, never exits on its own.
+ script := "#!/bin/sh\nsleep 120\n"
+ fakePath := filepath.Join(dir, "cursor-agent")
+ writeTestExecutable(t, fakePath, []byte(script))
+
+ prompt := strings.Repeat("blocked write payload 0123456789\n", 16_384) // ~512 KiB
+
+ backend, err := New("cursor", Config{ExecutablePath: fakePath, Logger: slog.Default()})
+ if err != nil {
+ t.Fatalf("New(cursor): %v", err)
+ }
+ ctx, cancel := context.WithCancel(t.Context())
+ session, err := backend.Execute(ctx, prompt, ExecOptions{Timeout: 120 * time.Second})
+ if err != nil {
+ cancel()
+ t.Fatalf("Execute: %v", err)
+ }
+ go func() {
+ for range session.Messages {
+ }
+ }()
+
+ // Give the writer time to fill the pipe and block, then cancel.
+ time.Sleep(200 * time.Millisecond)
+ cancel()
+
+ select {
+ case result := <-session.Result:
+ if result.Status != "aborted" {
+ t.Fatalf("status = %q, want aborted; error=%q", result.Status, result.Error)
+ }
+ case <-time.After(30 * time.Second):
+ t.Fatal("cancel did not release the blocked prompt write; Result never arrived")
+ }
+}
+
+// TestCursorExecuteWritesPromptVerbatim pins our side of the whitespace
+// contract: we write the prompt bytes exactly as given, adding no wrapper,
+// framing or trailing newline (unlike Claude, which sends a JSON frame).
+//
+// Note the CLI itself trims the stdin prompt before use, so leading/trailing
+// whitespace is not preserved end-to-end. That is cursor-agent's behaviour, not
+// ours; task prompts carry no meaning in outer whitespace, so we do not
+// compensate for it here.
+func TestCursorExecuteWritesPromptVerbatim(t *testing.T) {
+ t.Parallel()
+
+ prompt := "\n leading and trailing whitespace \n\n"
+
+ _, stdinGot, result := cursorStdinProbe(t, prompt)
+
+ if stdinGot != prompt {
+ t.Errorf("prompt was mutated before write:\n got %q\n want %q", stdinGot, prompt)
+ }
+ if result.Status != "completed" {
+ t.Fatalf("status = %q, want completed; error=%q", result.Status, result.Error)
+ }
+}
diff --git a/server/pkg/agent/cursor_stdin_windows_test.go b/server/pkg/agent/cursor_stdin_windows_test.go
new file mode 100644
index 0000000000..c233f6453a
--- /dev/null
+++ b/server/pkg/agent/cursor_stdin_windows_test.go
@@ -0,0 +1,187 @@
+//go:build windows
+
+package agent
+
+import (
+ "fmt"
+ "io"
+ "log/slog"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// Env contract between the test and the helper process it re-executes as the
+// native child of the PowerShell shim.
+const (
+ shimHelperEnv = "MULTICA_CURSOR_SHIM_HELPER"
+ shimHelperArgvFile = "MULTICA_CURSOR_SHIM_ARGV_FILE"
+ shimHelperInFile = "MULTICA_CURSOR_SHIM_STDIN_FILE"
+)
+
+// TestCursorShimHelperProcess is not a test. Re-executed by the fake
+// cursor-agent.ps1 below, it stands in for `node.exe index.js` as a real native
+// child: it records the argv it was handed, drains stdin, and emits the
+// terminal stream-json event. Inert unless the shim env var is set.
+func TestCursorShimHelperProcess(t *testing.T) {
+ if os.Getenv(shimHelperEnv) != "1" {
+ t.Skip("helper process; only runs when re-executed by the shim")
+ }
+
+ // Everything after "--" is what the shim forwarded to us.
+ var forwarded []string
+ for i, a := range os.Args {
+ if a == "--" {
+ forwarded = os.Args[i+1:]
+ break
+ }
+ }
+ if err := os.WriteFile(os.Getenv(shimHelperArgvFile), []byte(strings.Join(forwarded, "\n")), 0o644); err != nil {
+ fmt.Fprintf(os.Stderr, "helper: write argv: %v\n", err)
+ os.Exit(1)
+ }
+ stdin, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "helper: read stdin: %v\n", err)
+ os.Exit(1)
+ }
+ if err := os.WriteFile(os.Getenv(shimHelperInFile), stdin, 0o644); err != nil {
+ fmt.Fprintf(os.Stderr, "helper: write stdin: %v\n", err)
+ os.Exit(1)
+ }
+
+ fmt.Println(`{"type":"result","subtype":"success","is_error":false,"result":"ok"}`)
+ // Exit before the test framework can print PASS/ok into the JSON stream.
+ os.Exit(0)
+}
+
+// TestCursorExecutePromptSurvivesPowerShellShim is the Windows half of the
+// #5649 regression, and it exercises the full production launch chain:
+//
+// Go → powershell -File cursor-agent.ps1 → native child
+//
+// The last hop is the one that matters and the one a shim-only test cannot
+// reach. The official cursor-agent.ps1 ends in `& node.exe index.js $args`, so
+// the fake ps1 here likewise invokes a *native* executable with $args and lets
+// that child record argv and read stdin. That proves both properties the fix
+// depends on end to end:
+//
+// - the prompt is absent from the argv PowerShell re-serialises onto the
+// child's command line, so there is nothing left to re-tokenise; and
+// - stdin is still inherited by the native child, byte for byte.
+//
+// It runs against every PowerShell host present, not just the one
+// defaultPowerShellLookup would pick, because the hosts differ on exactly the
+// mechanism behind this bug: powershell.exe (5.1) and pwsh <= 7.2 default to
+// Legacy native argument passing, pwsh >= 7.3 to Standard. A fix that only held
+// on the newer host would be no fix at all for the reporter.
+func TestCursorExecutePromptSurvivesPowerShellShim(t *testing.T) {
+ hosts := availablePowerShellHosts()
+ if len(hosts) == 0 {
+ t.Skip("no PowerShell host available")
+ }
+ for _, host := range hosts {
+ t.Run(filepath.Base(host), func(t *testing.T) {
+ stubPowerShell(t, host, true)
+ assertPromptSurvivesShim(t)
+ })
+ }
+}
+
+// availablePowerShellHosts resolves every PowerShell host on PATH so the
+// regression can be proven on each independently.
+func availablePowerShellHosts() []string {
+ var found []string
+ for _, name := range []string{"powershell.exe", "pwsh.exe"} {
+ if p, err := exec.LookPath(name); err == nil {
+ found = append(found, p)
+ }
+ }
+ return found
+}
+
+func assertPromptSurvivesShim(t *testing.T) {
+ t.Helper()
+
+ self, err := os.Executable()
+ if err != nil {
+ t.Fatalf("locate test binary to use as native child: %v", err)
+ }
+
+ dir := t.TempDir()
+ argvPath := filepath.Join(dir, "argv.txt")
+ stdinPath := filepath.Join(dir, "stdin.txt")
+
+ // The .cmd only has to exist and carry the right extension; the rewrite
+ // routes around it to the sibling .ps1, which is what actually runs.
+ cmdPath := filepath.Join(dir, "cursor-agent.cmd")
+ writeFile(t, cmdPath, "@echo off\r\npowershell -NoProfile -ExecutionPolicy Bypass -File \"%~dp0cursor-agent.ps1\" %*\r\n")
+
+ // Shaped like the official shim: set up, then hand $args to a native child.
+ ps1 := fmt.Sprintf(""+
+ "$env:%s = '1'\r\n"+
+ "$env:%s = '%s'\r\n"+
+ "$env:%s = '%s'\r\n"+
+ "& '%s' '-test.run=^TestCursorShimHelperProcess$' '--' $args\r\n"+
+ "exit $LASTEXITCODE\r\n",
+ shimHelperEnv,
+ shimHelperArgvFile, argvPath,
+ shimHelperInFile, stdinPath,
+ self)
+ writeFile(t, filepath.Join(dir, "cursor-agent.ps1"), ps1)
+
+ prompt := "Please fix the build.\n" +
+ `go build -ldflags "-X main.version=foo -X main.commit=bar" -o bin/server ./cmd/server` + "\n" +
+ "Thanks."
+
+ backend, err := New("cursor", Config{ExecutablePath: cmdPath, Logger: slog.Default()})
+ if err != nil {
+ t.Fatalf("New(cursor): %v", err)
+ }
+ session, err := backend.Execute(t.Context(), prompt, ExecOptions{Timeout: 60 * time.Second})
+ if err != nil {
+ t.Fatalf("Execute: %v", err)
+ }
+ go func() {
+ for range session.Messages {
+ }
+ }()
+ result := <-session.Result
+
+ argvRaw, err := os.ReadFile(argvPath)
+ if err != nil {
+ t.Fatalf("native child never recorded argv (did the shim reach it?): %v; result=%+v", err, result)
+ }
+ stdinRaw, err := os.ReadFile(stdinPath)
+ if err != nil {
+ t.Fatalf("native child never recorded stdin: %v; result=%+v", err, result)
+ }
+
+ // argv as the *native child* received it — past PowerShell's $args
+ // re-serialisation, which is where #5649 was introduced.
+ for _, a := range strings.Split(strings.TrimSuffix(string(argvRaw), "\n"), "\n") {
+ for _, needle := range []string{"-X", "ldflags", "main.version", "Please fix"} {
+ if strings.Contains(a, needle) {
+ t.Errorf("prompt fragment %q leaked into native child argv element %q", needle, a)
+ }
+ }
+ }
+ // The content-free flags must still survive the same hop.
+ gotArgv := string(argvRaw)
+ for _, want := range []string{"-p", "--output-format", "stream-json", "--yolo"} {
+ if !strings.Contains(gotArgv, want) {
+ t.Errorf("expected %q to reach the native child; argv was %q", want, gotArgv)
+ }
+ }
+
+ if string(stdinRaw) != prompt {
+ t.Errorf("prompt did not survive Go → PowerShell → native child:\n got %q\n want %q", string(stdinRaw), prompt)
+ }
+
+ if result.Status != "completed" {
+ t.Fatalf("status = %q, want completed; error=%q", result.Status, result.Error)
+ }
+}
diff --git a/server/pkg/agent/cursor_test.go b/server/pkg/agent/cursor_test.go
index 5546424ca8..93c3114842 100644
--- a/server/pkg/agent/cursor_test.go
+++ b/server/pkg/agent/cursor_test.go
@@ -21,13 +21,13 @@ func TestNewReturnsCursorBackend(t *testing.T) {
func TestBuildCursorArgs(t *testing.T) {
t.Parallel()
- args := buildCursorArgs("do something", ExecOptions{
+ args := buildCursorArgs(ExecOptions{
Cwd: "/tmp/work",
Model: "composer-1.5",
}, slog.Default())
expected := []string{
- "-p", "do something",
+ "-p",
"--output-format", "stream-json",
"--yolo",
"--workspace", "/tmp/work",
@@ -47,7 +47,7 @@ func TestBuildCursorArgs(t *testing.T) {
func TestBuildCursorArgsWithResume(t *testing.T) {
t.Parallel()
- args := buildCursorArgs("continue", ExecOptions{
+ args := buildCursorArgs(ExecOptions{
ResumeSessionID: "sess-123",
}, slog.Default())
@@ -65,8 +65,8 @@ func TestBuildCursorArgsWithResume(t *testing.T) {
func TestBuildCursorArgsMinimal(t *testing.T) {
t.Parallel()
- args := buildCursorArgs("hello", ExecOptions{}, slog.Default())
- expected := []string{"-p", "hello", "--output-format", "stream-json", "--yolo"}
+ args := buildCursorArgs(ExecOptions{}, slog.Default())
+ expected := []string{"-p", "--output-format", "stream-json", "--yolo"}
if len(args) != len(expected) {
t.Fatalf("expected %d args, got %d: %v", len(expected), len(args), args)
@@ -78,7 +78,7 @@ func TestBuildCursorArgsIgnoresSystemPromptAndMaxTurns(t *testing.T) {
// cursor-agent CLI does not support --system-prompt or --max-turns;
// verify they are NOT emitted even when set in ExecOptions.
- args := buildCursorArgs("task", ExecOptions{
+ args := buildCursorArgs(ExecOptions{
SystemPrompt: "You are helpful",
MaxTurns: 5,
}, slog.Default())
@@ -96,7 +96,7 @@ func TestBuildCursorArgsIgnoresSystemPromptAndMaxTurns(t *testing.T) {
func TestBuildCursorArgsCustomArgs(t *testing.T) {
t.Parallel()
- args := buildCursorArgs("task", ExecOptions{
+ args := buildCursorArgs(ExecOptions{
CustomArgs: []string{"--extra", "val", "--yolo", "--output-format", "text"},
}, slog.Default())