Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc281d2

Browse files
committed
Warn that ReadUntil* must be used with 80x80 PTYs
1 parent 73778b9 commit fc281d2

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

agent/agent_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,12 +1630,12 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16301630
//nolint:dogsled
16311631
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
16321632
id := uuid.New()
1633-
netConn1, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1633+
netConn1, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16341634
require.NoError(t, err)
16351635
defer netConn1.Close()
16361636

16371637
// A second simultaneous connection.
1638-
netConn2, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1638+
netConn2, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16391639
require.NoError(t, err)
16401640
defer netConn2.Close()
16411641

@@ -1674,7 +1674,7 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16741674

16751675
_ = netConn1.Close()
16761676
_ = netConn2.Close()
1677-
netConn3, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1677+
netConn3, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16781678
require.NoError(t, err)
16791679
defer netConn3.Close()
16801680

@@ -1698,7 +1698,7 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16981698
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
16991699

17001700
// Try a non-shell command. It should output then immediately exit.
1701-
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 100, 100, "echo test")
1701+
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo test")
17021702
require.NoError(t, err)
17031703
defer netConn4.Close()
17041704

coderd/workspaceapps/apptest/apptest.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
6464
testReconnectingPTY(ctx, t, client, codersdk.WorkspaceAgentReconnectingPTYOpts{
6565
AgentID: appDetails.Agent.ID,
6666
Reconnect: uuid.New(),
67-
Height: 80,
68-
Width: 80,
67+
Height: 100,
68+
Width: 1000,
6969
Command: "bash",
7070
})
7171
})
@@ -98,8 +98,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
9898
testReconnectingPTY(ctx, t, unauthedAppClient, codersdk.WorkspaceAgentReconnectingPTYOpts{
9999
AgentID: appDetails.Agent.ID,
100100
Reconnect: uuid.New(),
101-
Height: 80,
102-
Width: 80,
101+
Height: 100,
102+
Width: 100,
103103
Command: "bash",
104104
SignedToken: issueRes.SignedToken,
105105
})
@@ -1360,8 +1360,8 @@ func testReconnectingPTY(ctx context.Context, t *testing.T, client *codersdk.Cli
13601360
// First attempt to resize the TTY.
13611361
// The websocket will close if it fails!
13621362
data, err := json.Marshal(codersdk.ReconnectingPTYRequest{
1363-
Height: 250,
1364-
Width: 250,
1363+
Height: 80,
1364+
Width: 80,
13651365
})
13661366
require.NoError(t, err)
13671367
_, err = conn.Write(data)

testutil/pty.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
)
1111

1212
// ReadUntilString emulates a terminal and reads one byte at a time until we
13-
// either see the string we want, or the context expires.
13+
// either see the string we want, or the context expires. The PTY must be sized
14+
// to 80x80 or there could be unexpected results.
1415
func ReadUntilString(ctx context.Context, t *testing.T, want string, r io.Reader) error {
1516
return ReadUntil(ctx, t, r, func(line string) bool {
1617
return strings.TrimSpace(line) == want
@@ -19,6 +20,7 @@ func ReadUntilString(ctx context.Context, t *testing.T, want string, r io.Reader
1920

2021
// ReadUntil emulates a terminal and reads one byte at a time until the matcher
2122
// returns true or the context expires. If the matcher is nil, read until EOF.
23+
// The PTY must be sized to 80x80 or there could be unexpected results.
2224
func ReadUntil(ctx context.Context, t *testing.T, r io.Reader, matcher func(line string) bool) error {
2325
// output can contain virtual terminal sequences, so we need to parse these
2426
// to correctly interpret getting what we want.

0 commit comments

Comments
 (0)