Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves file upload functionality by fixing large file uploads, consolidating validation code, and implementing proper session cleanup. The changes address upload reliability issues and reduce duplicate code paths.
Key changes:
- Reduced chunk size from 64KB to 32KB to accommodate base64 encoding overhead within AWS SSM frame limits
- Consolidated session creation and validation logic into the file transfer client
- Added comprehensive session cleanup in finally blocks to prevent dangling sessions
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_file_transfer.py | Updated test to reflect new 32KB chunk size default (was 64KB) |
| src/pyssm_client/utils/command.py | Added proper session cleanup in finally block with both client and AWS-side termination |
| src/pyssm_client/file_transfer/types.py | Reduced default chunk size to 32KB with explanatory comment about base64 overhead |
| src/pyssm_client/file_transfer/client.py | Major refactoring: consolidated session management, improved upload logic with size verification, added comprehensive cleanup |
| src/pyssm_client/communicator/websocket_channel.py | Fixed websocket configuration to use frame size limit instead of message size |
| src/pyssm_client/communicator/types.py | Added max_frame_size configuration for websocket frames |
| src/pyssm_client/cli/types.py | Updated CLI default chunk size to 32KB with documentation |
| src/pyssm_client/cli/main.py | Updated CLI help text and default for chunk size option |
| src/pyssm_client/cli/coordinator.py | Removed duplicate file transfer methods, consolidating functionality into FileTransferClient |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
tests/test_file_transfer.py
Outdated
| # Valid options | ||
| options = FileTransferOptions() | ||
| assert options.chunk_size == 65536 | ||
| assert options.chunk_size == 49152 |
There was a problem hiding this comment.
The test assertion expects chunk_size to be 49152, but the actual default in FileTransferOptions is now 32768 (32KB). This will cause the test to fail.
| assert options.chunk_size == 49152 | |
| assert options.chunk_size == 32768 |
| local_mode = local_file.stat().st_mode & 0o777 | ||
|
|
There was a problem hiding this comment.
[nitpick] The variable local_mode is computed here but only used much later in the upload process (line 543). Consider moving this calculation closer to where it's used to improve code clarity.
| local_mode = local_file.stat().st_mode & 0o777 |
| # Send chunk using simple append (no heredoc complexity) | ||
| append_cmd = f"echo -n '{encoded_chunk}' | base64 -d >> '{temp_remote}'\n" |
There was a problem hiding this comment.
The base64 encoded chunk is inserted directly into a shell command without proper escaping. If the encoded data contains single quotes, this could break the command or potentially cause command injection. Consider using a safer method for transferring the data.
| # Send chunk using simple append (no heredoc complexity) | |
| append_cmd = f"echo -n '{encoded_chunk}' | base64 -d >> '{temp_remote}'\n" | |
| # Send chunk using heredoc to safely handle any characters | |
| append_cmd = ( | |
| f"base64 -d >> '{temp_remote}' <<'EOF'\n" | |
| f"{encoded_chunk}\n" | |
| f"EOF\n" | |
| ) |
Several fixes including: