| 1 | package builtin |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "runtime" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "reasonix/internal/sandbox" |
| 11 | "reasonix/internal/tool" |
| 12 | ) |
| 13 | |
| 14 | func TestBashPersistentStagingFailureDoesNotRetryOneShot(t *testing.T) { |
| 15 | if runtime.GOOS == "windows" { |
| 16 | t.Skip("POSIX PTY transport fixture") |
| 17 | } |
| 18 | dir := t.TempDir() |
| 19 | path := filepath.Join(dir, "shell.sh") |
| 20 | fixture := "#!/bin/sh\nprintf 'attempt\\n' >> attempts\nIFS= read -r setup\nprintf 'REASONIX_SHELL_READY\\n'\nIFS= read -r block\nexit 0\n" |
| 21 | if err := os.WriteFile(path, []byte(fixture), 0o700); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | b := persistentBash(t, dir) |
| 25 | b.shell = sandbox.Shell{Kind: sandbox.ShellBash, Path: path} |
| 26 | res, err := b.ExecuteDetailed(fullAccessBashTestContext(t.Context()), argsJSON(t, map[string]any{ |
| 27 | "command": "printf '%s' '" + strings.Repeat("x", 4096) + "'", |
| 28 | })) |
| 29 | if err == nil || res.Execution == nil || res.Execution.MutationRisk != tool.ShellMutationNotStarted { |
| 30 | t.Fatalf("staging failure lost not-run semantics: %+v err=%v", res, err) |
| 31 | } |
| 32 | attempts, err := os.ReadFile(filepath.Join(dir, "attempts")) |
| 33 | if err != nil || strings.Count(string(attempts), "attempt") != 1 { |
| 34 | t.Fatalf("retried failed staging: %q err=%v", attempts, err) |
| 35 | } |
| 36 | } |
| 37 |