|
| 1 | +//go:build e2e |
| 2 | + |
| 3 | +package e2e |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +// SandboxExecResult mirrors the exec result shape for test assertions. |
| 12 | +// The CLI emits raw stdout/stderr (not JSON), so this struct is used |
| 13 | +// for internal test logic only — we parse the raw output directly. |
| 14 | +type SandboxExecResult struct { |
| 15 | + Stdout string `json:"stdout"` |
| 16 | + Stderr string `json:"stderr"` |
| 17 | + ExitCode int `json:"exit_code"` |
| 18 | +} |
| 19 | + |
| 20 | +func TestExecSuccess(t *testing.T) { |
| 21 | + sb := newSandbox(t) |
| 22 | + |
| 23 | + ctx, cancel := context.WithTimeout(context.Background(), execTimeout) |
| 24 | + defer cancel() |
| 25 | + |
| 26 | + // sandbox exec emits the command's raw stdout directly (non-JSON). |
| 27 | + stdout, stderr, code := runCLICtx(ctx, "sandbox", "exec", sb.ID, "--", "echo", "hello") |
| 28 | + if code != 0 { |
| 29 | + t.Fatalf("exec exited %d\nstdout: %s\nstderr: %s", code, stdout, stderr) |
| 30 | + } |
| 31 | + if !strings.Contains(stdout, "hello") { |
| 32 | + t.Fatalf("expected stdout to contain %q, got: %s", "hello", stdout) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func TestExecNonZeroExit(t *testing.T) { |
| 37 | + sb := newSandbox(t) |
| 38 | + |
| 39 | + ctx, cancel := context.WithTimeout(context.Background(), execTimeout) |
| 40 | + defer cancel() |
| 41 | + |
| 42 | + // The CLI calls os.Exit with the inner command's exit code, so the |
| 43 | + // process exit code reflects the sandbox command's exit code. |
| 44 | + // We don't assert code == 0 here — just that the CLI preserved exit 42. |
| 45 | + _, _, code := runCLICtx(ctx, "sandbox", "exec", sb.ID, "--", "sh", "-c", "exit 42") |
| 46 | + if code != 42 { |
| 47 | + t.Fatalf("expected CLI exit code 42 (preserved from inner command), got %d", code) |
| 48 | + } |
| 49 | +} |
0 commit comments