Skip to content

feat(cli): add experimental rpty command #16700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2025
Merged

feat(cli): add experimental rpty command #16700

merged 4 commits into from
Feb 26, 2025

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Feb 25, 2025

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 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
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

Copy link
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.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

nothing blocking, I suppose

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
Member

Choose a reason for hiding this comment

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

:)

Copy link
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
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!

require.ErrorContains(t, err, "not found")
})

t.Run("Container", func(t *testing.T) {
Copy link
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
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.

Copy link
Member

@mafredri mafredri left a comment

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 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
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
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.

ContainerUser: args.ContainerUser,
Width: termWidth,
Height: termHeight,
})
Copy link
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
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.

}); err != nil {
return
}
}
Copy link
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
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
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
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.

@johnstcn johnstcn merged commit c5a265f into main Feb 26, 2025
30 checks passed
@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