Skip to content

fix: Decode JSON directly from stream in waitForCommandOutput#28040

Merged
codingllama merged 1 commit intomasterfrom
codingllama/command-test
Jun 20, 2023
Merged

fix: Decode JSON directly from stream in waitForCommandOutput#28040
codingllama merged 1 commit intomasterfrom
codingllama/command-test

Conversation

@codingllama
Copy link
Copy Markdown
Contributor

@codingllama codingllama commented Jun 19, 2023

Fixes local breakage of TestExecuteCommandHistory.

Without the fix I consistently get this failure:

$ go test ./lib/web -run=TestExecuteCommandHistory
> ...
> === FAIL: lib/web TestExecuteCommandHistory (2.66s)
>     command_test.go:92:
>         	Error Trace:	/Users/alan/workspace/teleport/lib/web/command_test.go:92
>         	Error:      	Received unexpected error:
>         	            	unexpected end of JSON input
>         	Test:       	TestExecuteCommandHistory

While debugging I noticed that the 100 bytes buffer in waitForCommandOutput is too small, so instead of increasing the buffer I removed it altogether.

@codingllama codingllama requested a review from jakule June 19, 2023 18:24
@github-actions github-actions Bot requested review from gzdunek and timothyb89 June 19, 2023 18:25
@codingllama codingllama added this pull request to the merge queue Jun 20, 2023
Merged via the queue into master with commit 86e57aa Jun 20, 2023
@codingllama codingllama deleted the codingllama/command-test branch June 20, 2023 14:21
github-merge-queue Bot pushed a commit that referenced this pull request Jul 14, 2023
* [Assist] Clear the refresh websocket timeout when closing Assist (#28610)

* Clear the refresh websocket timeout when closing Assist

* Missing semicolon to please prettier

* Add comment to remove once the new session implementation is done

* fix: Decode JSON directly from stream in `waitForCommandOutput` (#28040)

* Assist: mark individual nodes as finished (#28477)

* Mark nodes as done when command finishes in Assist

* Split Close/CloseWithPayload

* Expect a close message before the summary in test

* Remediate confusing type usage in test

`Envelope` is the outer layer used (in protobuf format)
for execution / terminal sessions.

Meanwhile `outEnvelope` is the inner layer
used (in JSON) spefically with assist (execution),
when outer envelope is of "raw" type

Using `Envelope` where decoding `outEnvelope` in tests
previously worked "by accident" due to matching field names

* Assert that server ID is set in the close message

* Refactor command execution logic and adjust WebSocket handling

This commit changes how command execution and WebSocket handling are performed in the code. Instead of manually managing session close signals and command execution notifications via WebSocket, we have wrapped it into more easily manageable form.

Changed parts: assist and websocket libraries, test and several components of 'teleport'.

Why:
This allows cleaner command management and error handling, leading to more reliable and maintainable application. Also made code more readable and easy to understand. Made WebSocket more precise with its handling to prevent cases where stale or incorrect data might interrupt the session.

Details:
Instead of sending a close signal after all commands have been executed, we now send individual session end updates for each command. Sessions no longer remain active unnecessarily.

Message handling in command execution has been refactored for better error propagation.

All these changes were also adjusted and reflected in the associated test cases.
Also, names and types of various data structures are edited to reflect their actual usage.

* Change ServerID to NodeID to improve code consistency

This commit replaces occurrences of `ServerID` with `NodeID` across several files.
`ServerID` was misleading and causing confusion as it was serving as an identifier for nodes, so to improve comprehension and consistency in the codebase, all instances of `ServerID` have been replaced with `NodeID`. Tests have also been updated to reflect this change.

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>

---------

Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
Co-authored-by: Justinas Stankevičius <justinas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants