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

Skip to content

fix: Run expect tests on Windows with conpty pseudo-terminal #276

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 44 commits into from
Feb 15, 2022

Conversation

bryphe-coder
Copy link
Contributor

@bryphe-coder bryphe-coder commented Feb 11, 2022

This brings together a bunch of random, partially implemented packages for support of the new(ish) Windows conpty API - such that we can leverage the expect style of CLI tests, but in a way that works in Linux/OSX ptys and Windows conpty.

These include:

  • Vendoring the go-expect library from Netflix w/ some tweaks to work cross-platform
  • Vendoring the pty cross-platform implementation from waypoint-plugin-sdk
  • Vendoring the conpty Windows-specific implementation from waypoint-plugin-sdk
  • Adjusting the pty interface to work with go-expect + the cross-plat version

There were several limitations with the current packages:

  • go-expect requires the same os.File (TTY) for input / output, but conhost requires separate file handles
  • conpty does not handle input, only output
  • The cross-platform pty didn't expose the full set of primitives needed for console

Therefore, the following changes were made:

  • Handling of stdin was added to the conpty interface
  • We weren't using the full extent of the go-expect interface, so some portions were removed (ie, exec'ing a process) to simplify our implementation and make it easier to extend cross-platform
  • Instead of console exposing just a Tty, it exposes an InTty and OutTty, to help encapsulate the difference on Windows (on Linux, these point to the same pipe)

Future improvements:

  • The isatty implementation doesn't support accurate detection of conhost pty's without an associated process. In lieu of a more robust check, I've added a --force-tty flag intended for test case use - that forces the CLI to run in tty mode.
  • It seems the windows implementation doesn't support setting a deadline. This is needed for the expect.Timeout API, but isn't used by us yet.

After the all-hands + meetings this afternoon - I'll get my Win environment set up to iterate to get the tests working there.

Fixes #241

@bryphe-coder bryphe-coder self-assigned this Feb 11, 2022
@bryphe-coder bryphe-coder changed the title experiment: Cross-platform (windows supported) expect tests experiment: Cross-platform (windows supported) CLI expect tests Feb 11, 2022
@codecov
Copy link

codecov bot commented Feb 11, 2022

Codecov Report

Merging #276 (1de0f1b) into main (64c14de) will decrease coverage by 0.26%.
The diff coverage is 60.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #276      +/-   ##
==========================================
- Coverage   68.22%   67.96%   -0.27%     
==========================================
  Files         126      130       +4     
  Lines        6898     7079     +181     
  Branches       69       69              
==========================================
+ Hits         4706     4811     +105     
- Misses       1714     1779      +65     
- Partials      478      489      +11     
Flag Coverage Δ
unittest-go-macos-latest 66.24% <60.39%> (-0.26%) ⬇️
unittest-go-ubuntu-latest 67.50% <60.39%> (-0.04%) ⬇️
unittest-go-windows-latest 65.96% <60.39%> (?)
unittest-js 65.24% <ø> (ø)
Impacted Files Coverage Δ
cli/clitest/clitest.go 93.33% <ø> (-1.91%) ⬇️
expect/test_console.go 0.00% <0.00%> (ø)
expect/expect.go 60.37% <60.37%> (ø)
expect/console.go 66.12% <66.12%> (ø)
expect/expect_opt.go 72.00% <72.00%> (ø)
cli/root.go 79.28% <78.57%> (-0.41%) ⬇️
cli/login.go 55.33% <100.00%> (+0.43%) ⬆️
peerbroker/dial.go 76.19% <0.00%> (-4.77%) ⬇️
coderd/provisionerdaemons.go 57.23% <0.00%> (-0.62%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64c14de...1de0f1b. Read the comment docs.

@bryphe-coder bryphe-coder force-pushed the bryphe/experiment/241/cross-plat-expect branch from 0ef4f42 to 03ea70c Compare February 11, 2022 21:53
@bryphe-coder bryphe-coder force-pushed the bryphe/experiment/241/cross-plat-expect branch from 95c891f to a73476d Compare February 12, 2022 02:29
@bryphe-coder bryphe-coder changed the title experiment: Cross-platform (windows supported) CLI expect tests fix: #241 - Cross-platform (windows supported) CLI expect tests Feb 12, 2022
@bryphe-coder
Copy link
Contributor Author

Thanks for reviewing @kylecarbs !

@bryphe-coder bryphe-coder merged commit c9c0312 into main Feb 15, 2022
@bryphe-coder bryphe-coder deleted the bryphe/experiment/241/cross-plat-expect branch February 15, 2022 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test the coder CLI on Windows
2 participants