Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ func runLogStreams(ctx context.Context, streams []logStream, out, errOut io.Writ
for _, stream := range streams {
one := &running{logStream: stream, lines: make(chan string, 256), stderr: &limitedBuffer{limit: 4 << 10}}

// The ssh commands come wired to this process's terminal (vssh's
// command()), and a stream that already has somewhere to write
// cannot also be read: exec refuses with "Stdout already set". The
// lines are read here, so the output is taken back first.
stream.cmd.Stdin = nil
stream.cmd.Stdout = nil
stream.cmd.Stderr = one.stderr
pipe, err := stream.cmd.StdoutPipe()
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions internal/cli/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"context"
"encoding/json"
"os"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -189,6 +190,22 @@ func TestSeveralMachinesAreReadInOrderOfTime(t *testing.T) {
}
}

// The ssh commands the target builds write to this process's terminal; the
// reader takes their output back rather than failing on "Stdout already
// set", which is what `vallic logs` answered on its first real run.
func TestStreamWiredToTheTerminalIsRead(t *testing.T) {
cmd := exec.Command("printf", "%s\n", "2026-11-13T10:00:00.000Z [cron] ran")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

var out, errOut strings.Builder
lines, err := runLogStreams(context.Background(), []logStream{{cmd: cmd}}, &out, &errOut, logsRequest{})
if err != nil || lines != 1 || out.String() != "2026-11-13T10:00:00.000Z [cron] ran\n" {
t.Errorf("a stream wired to the terminal read %q, %d lines, %v", out.String(), lines, err)
}
}

// As objects, a line says which machine it is from inside the object, and
// is ordered by the time it holds.
func TestLinesAsObjectsNameTheirMachine(t *testing.T) {
Expand Down
Loading