Skip to content

Commit d85af28

Browse files
committed
Clean up sandbox command execution flags
1 parent 0d1f851 commit d85af28

4 files changed

Lines changed: 2 additions & 73 deletions

File tree

pkg/cmd/sandbox/common.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@ func sandboxRef(id string) *sandboxv1.SandboxRef {
3838
}
3939
}
4040

41-
// commandRef wraps a command id in the depot.sandbox.v1 selector oneof.
42-
// Used by AttachCommand / KillCommand callers.
43-
func commandRef(id string) *sandboxv1.SandboxCommandExecutionRef {
44-
return &sandboxv1.SandboxCommandExecutionRef{
45-
Selector: &sandboxv1.SandboxCommandExecutionRef_Id{Id: id},
46-
}
47-
}
48-
49-
// snapshotRef wraps a snapshot id in the depot.sandbox.v1 selector oneof.
50-
// Used by GetSnapshot / DeleteSnapshot.
51-
func snapshotRef(id string) *sandboxv1.SnapshotRef {
52-
return &sandboxv1.SnapshotRef{
53-
Selector: &sandboxv1.SnapshotRef_Id{Id: id},
54-
}
55-
}
56-
5741
// consumeCommandEventStream drains a depot.sandbox.v1 CommandEvent stream
5842
// into stdout/stderr and returns the final exit code from Finished. The
5943
// stream shape mirrors RunCommand / RunCommandPipe / AttachCommand /
@@ -63,19 +47,9 @@ func snapshotRef(id string) *sandboxv1.SnapshotRef {
6347
// see the gap; the stream continues afterward. Error frames are surfaced the
6448
// same way and do not abort the loop (the server is signalling partial
6549
// degradation, not a fatal end — Connect transport errors are the fatal path).
66-
// detachedMode flags a RunCommand stream that the server will close after
67-
// Started — no Finished event will arrive, and that's not an error.
68-
type detachedMode bool
69-
70-
const (
71-
streamUntilFinished detachedMode = false
72-
streamUntilStarted detachedMode = true
73-
)
74-
7550
func consumeCommandEventStream(
7651
stream *connect.ServerStreamForClient[sandboxv1.SandboxCommandExecutionEvent],
7752
stdout, stderr io.Writer,
78-
mode detachedMode,
7953
) (exitCode int32, err error) {
8054
defer func() { _ = stream.Close() }()
8155
for stream.Receive() {
@@ -109,13 +83,5 @@ func consumeCommandEventStream(
10983
if err := stream.Err(); err != nil && !errors.Is(err, io.EOF) {
11084
return 0, fmt.Errorf("command stream: %w", err)
11185
}
112-
// In detached mode the server hangs up after Started — no Finished is
113-
// expected and "exit 0, no error" is the right success signal. For
114-
// non-detached commands, end-of-stream without Finished means the server
115-
// disconnected mid-run; surface that as an error so callers don't conflate
116-
// a clean disconnect with a real exit-0 completion.
117-
if mode == streamUntilStarted {
118-
return 0, nil
119-
}
12086
return 0, fmt.Errorf("command stream closed without Finished event")
12187
}

pkg/cmd/sandbox/common_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,3 @@ func TestSandboxRef_PinnedShape(t *testing.T) {
2222
t.Errorf("id = %q, want cs-abc123", sel.Id)
2323
}
2424
}
25-
26-
func TestCommandRef_PinnedShape(t *testing.T) {
27-
r := commandRef("cmd-xyz789")
28-
if r == nil {
29-
t.Fatal("commandRef returned nil")
30-
}
31-
sel, ok := r.Selector.(*sandboxv1.SandboxCommandExecutionRef_Id)
32-
if !ok {
33-
t.Fatalf("expected CommandRef_Id selector, got %T", r.Selector)
34-
}
35-
if sel.Id != "cmd-xyz789" {
36-
t.Errorf("id = %q, want cmd-xyz789", sel.Id)
37-
}
38-
}
39-
40-
func TestSnapshotRef_PinnedShape(t *testing.T) {
41-
r := snapshotRef("snap-456")
42-
if r == nil {
43-
t.Fatal("snapshotRef returned nil")
44-
}
45-
sel, ok := r.Selector.(*sandboxv1.SnapshotRef_Id)
46-
if !ok {
47-
t.Fatalf("expected SnapshotRef_Id selector, got %T", r.Selector)
48-
}
49-
if sel.Id != "snap-456" {
50-
t.Errorf("id = %q, want snap-456", sel.Id)
51-
}
52-
}

pkg/cmd/sandbox/exec.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ parsing stops there.`,
5454
cwd, _ := cmd.Flags().GetString("cwd")
5555
envSlice, _ := cmd.Flags().GetStringArray("env")
5656
sudo, _ := cmd.Flags().GetBool("sudo")
57-
detached, _ := cmd.Flags().GetBool("detached")
5857

5958
envMap, err := parseEnvSlice(envSlice)
6059
if err != nil {
@@ -73,9 +72,6 @@ parsing stops there.`,
7372
if sudo {
7473
req.Sudo = &sudo
7574
}
76-
if detached {
77-
req.Detached = &detached
78-
}
7975

8076
// The --timeout flag is deprecated. Warn if it is still set, but
8177
// do not fail, since the wire protocol no longer carries a timeout.
@@ -88,11 +84,7 @@ parsing stops there.`,
8884
return fmt.Errorf("run command: %w", err)
8985
}
9086

91-
mode := streamUntilFinished
92-
if detached {
93-
mode = streamUntilStarted
94-
}
95-
exit, err := consumeCommandEventStream(stream, os.Stdout, os.Stderr, mode)
87+
exit, err := consumeCommandEventStream(stream, os.Stdout, os.Stderr)
9688
if err != nil {
9789
return err
9890
}
@@ -106,7 +98,6 @@ parsing stops there.`,
10698
cmd.Flags().String("cwd", "", "Working directory inside the sandbox")
10799
cmd.Flags().StringArray("env", nil, "Environment variables to set (KEY=VALUE), repeatable")
108100
cmd.Flags().Bool("sudo", false, "Run as root")
109-
cmd.Flags().Bool("detached", false, "Return after Started; reattach later via AttachCommand")
110101
// Deprecated: hidden and ignored.
111102
cmd.Flags().Int("timeout", 0, "Deprecated: timeouts are not part of the v0 wire (will be removed)")
112103
_ = cmd.Flags().MarkHidden("timeout")

pkg/cmd/sandbox/hooks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func runHook(ctx context.Context, client sandboxv1connect.SandboxServiceClient,
147147
// command with setsid and exits 0, so the stream reaches Finished right
148148
// away. Waiting until finished is correct for both detached and
149149
// foreground hooks.
150-
exit, err := consumeCommandEventStream(stream, stdout, stderr, streamUntilFinished)
150+
exit, err := consumeCommandEventStream(stream, stdout, stderr)
151151
if err != nil {
152152
return err
153153
}

0 commit comments

Comments
 (0)