Skip to content

feat(cli): add experimental rpty command#16700

Merged
johnstcn merged 4 commits into
mainfrom
cj/cli-exp-pty-cmd
Feb 26, 2025
Merged

feat(cli): add experimental rpty command#16700
johnstcn merged 4 commits into
mainfrom
cj/cli-exp-pty-cmd

Conversation

@johnstcn

@johnstcn johnstcn commented Feb 25, 2025

Copy link
Copy Markdown
Member

Relates to #16419

Builds upon #16638 and adds a command exp rpty that allows you to open a ReconnectingPTY session to an agent.

This ultimately allows us to add an integration-style CLI test to verify the functionality added in #16638 .

@johnstcn johnstcn self-assigned this Feb 25, 2025
@johnstcn johnstcn changed the title Cj/cli exp pty cmd feat(cli): add experimental rpty command Feb 25, 2025
Base automatically changed from cj/agent-pty-container to main February 26, 2025 09:03
@johnstcn johnstcn marked this pull request as ready for review February 26, 2025 09:06
Comment thread cli/dotfiles_test.go
Comment on lines +20 to +23
// This test will time out if the user has commit signing enabled.
if _, gpgTTYFound := os.LookupEnv("GPG_TTY"); gpgTTYFound {
t.Skip("GPG_TTY is set, skipping test to avoid hanging")
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: decided to add this drive-by since running the tests locally was hanging for me

Comment thread cli/exp_errors.go

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: Decided to move these to have a common exp_ prefix. Also considered moving them to their own package but that would have been more involved.

@mtojek mtojek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing blocking, I suppose

Comment thread cli/exp_rpty.go
cmd := &serpent.Command{
Handler: func(inv *serpent.Invocation) error {
if r.disableDirect {
return xerrors.New("direct connections are disabled, but you can try websocat ;-)")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to actually try it out and it does work! Except you have to enter raw JSON objects to write to the terminal...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very convenient for debugging purposes. Leave the websocat hint please!

Comment thread cli/exp_rpty.go
Comment thread cli/exp_rpty.go Outdated
Comment thread cli/exp_rpty_test.go
require.ErrorContains(t, err, "not found")
})

t.Run("Container", func(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider a test case when container/agent dies?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea! I tested it out on dogfood and it works as expected, but good to codify.

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really cool command to have, thanks for adding it! A few nits inline.

Comment thread cli/exp_rpty.go
Comment on lines +110 to +115
for _, ct := range cts.Containers {
if ct.FriendlyName == args.Container || ct.ID == args.Container {
ctID = ct.ID
break
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the agent API support searching based on name/id? If not, might be nice to have the logic there (not a blocker for this PR though).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just search by labels currently.

Comment thread cli/exp_rpty.go Outdated
Comment thread cli/exp_rpty.go
ContainerUser: args.ContainerUser,
Width: termWidth,
Height: termHeight,
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this goes via coderd; do we need the "direct connection" check at all?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this with Ben and we agreed to keep it even though there's a trivial workaround. We can adjust based on customer feedback.

Comment thread cli/exp_rpty.go
Comment thread cli/exp_rpty.go
Comment thread cli/exp_rpty.go Outdated
Comment thread cli/exp_rpty.go
}); err != nil {
return
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debounce would be "nice", but since this is an experimental command, I'm not pushing for it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you specifically mean by 'debounce' here? Multiple keypresses?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm..isn't it overengineering in this case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the web terminal does any debouncing, so this is potentially a later improvement in both cases.

Comment thread cli/exp_rpty.go Outdated
@johnstcn johnstcn merged commit c5a265f into main Feb 26, 2025
@johnstcn johnstcn deleted the cj/cli-exp-pty-cmd branch February 26, 2025 12:33
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants