-
Notifications
You must be signed in to change notification settings - Fork 294
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
Fix offset regression in wshremote #1807
Conversation
WalkthroughThe pull request introduces significant modifications to the Additionally, in 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
pkg/wshrpc/wshremote/wshremote.go (1)
Critical file operation changes lack test coverage
The verification confirms there are no tests for the
RemoteWriteFileCommand
functionality. Given that this code handles critical file operations where incorrect offset handling could lead to data corruption, comprehensive test coverage is essential.Required test scenarios:
- Writing to a new file (offset = 0)
- Writing at a specific offset (data.At.Offset > 0)
- Writing with bounds checking (offset > fileSize)
- Writing with nil data.At (default behavior)
🔗 Analysis chain
Line range hint
741-746
: The offset initialization change looks correct but needs test coverage.The change to initialize
offset
to 0 by default and only update it based ondata.At
is the right approach, as it ensures data is written at the beginning of the file unless explicitly specified otherwise. This fixes the regression where data was being appended by default.However, I notice that there's no test coverage for this critical file writing behavior in the codebase.
Let's verify the test coverage:
Would you like me to help create comprehensive test cases that cover:
- Writing to a new file (offset = 0)
- Writing at a specific offset (data.At.Offset > 0)
- Writing with append mode
- Writing with truncate mode
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for tests related to RemoteWriteFileCommand rg -l "RemoteWriteFileCommand.*Test|Test.*RemoteWriteFileCommand"Length of output: 67
Script:
#!/bin/bash # Look for all test files in and around the wshremote directory echo "=== Test files in wshremote directory ===" fd ".*_test\.go$" pkg/wshrpc/wshremote/ echo -e "\n=== Content of test files mentioning file operations ===" rg -l "TestRemote.*File|Test.*FileOperation" pkg/wshrpc/ echo -e "\n=== Check if wshremote_test.go exists and show its content ===" if [ -f pkg/wshrpc/wshremote/wshremote_test.go ]; then echo "Found wshremote_test.go:" cat pkg/wshrpc/wshremote/wshremote_test.go fiLength of output: 515
🧹 Nitpick comments (2)
pkg/wshrpc/wshremote/wshremote.go (2)
Line range hint
741-746
: Consider documenting the append mode behavior with offsets.When append mode is active (
data.Info.Opts.Append
), the calculated offset is ignored since the data is always appended to the end of the file. This behavior should be documented to prevent confusion for API consumers.Add a comment explaining this interaction:
offset := 0 if data.At != nil { if data.At.Offset > 0 { offset = min(data.At.Offset, fileSize) } } +// Note: When append mode is active, the offset is ignored and data is always appended if offset > 0 && !data.Info.Opts.Append { n, err = file.WriteAt(dataBytes[:n], offset) } else { n, err = file.Write(dataBytes[:n]) }
Also applies to: 754-756, 765-767
Line range hint
765-769
: Enhance error messages with operation context.The error messages could be more descriptive by including the operation type (write at offset vs. append).
if offset > 0 && !data.Info.Opts.Append { n, err = file.WriteAt(dataBytes[:n], offset) + if err != nil { + return fmt.Errorf("cannot write at offset %d to file %q: %w", offset, path, err) + } } else { n, err = file.Write(dataBytes[:n]) + if err != nil { + if data.Info.Opts.Append { + return fmt.Errorf("cannot append to file %q: %w", path, err) + } + return fmt.Errorf("cannot write to file %q: %w", path, err) + } } -if err != nil { - return fmt.Errorf("cannot write to file %q: %w", path, err) -}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/wshrpc/wshremote/wshremote.go
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Build for TestDriver.ai
- GitHub Check: Analyze (go)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
pkg/wshrpc/wshremote/wshremote.go (4)
737-739
: Document the default file mode choice.Consider adding a comment explaining why 0644 was chosen as the default file mode (standard Unix file permissions for user-writable, world-readable files).
+// Default to 0644: User can read/write, others can read createMode := os.FileMode(0644)
755-756
: Consider allowing writes at exactly fileSize.The current check prevents writing at an offset equal to the file size, which might be a valid use case for appending data at the end of the file.
-if atOffset > fileSize { +if atOffset > fileSize { return fmt.Errorf("cannot write at offset %d, file size is %d", atOffset, fileSize) }
771-774
: Enhance error handling with specific error messages.Consider providing more specific error messages for different types of write failures.
if atOffset > 0 && !append { - n, err = file.WriteAt(dataBytes[:n], atOffset) + n, err = file.WriteAt(dataBytes[:n], atOffset) + if err != nil { + return fmt.Errorf("failed to write at offset %d: %w", atOffset, err) + } } else { - n, err = file.Write(dataBytes[:n]) + n, err = file.Write(dataBytes[:n]) + if err != nil { + return fmt.Errorf("failed to write to file: %w", err) + } } -if err != nil { - return fmt.Errorf("cannot write to file %q: %w", path, err) -}
779-779
: Enhance log message with operation mode.Consider including the operation mode (truncate/append) in the log message for better debugging.
-log.Printf("wrote %d bytes to file %q at offset %d\n", n, path, atOffset) +log.Printf("wrote %d bytes to file %q at offset %d (truncate=%v, append=%v)\n", n, path, atOffset, truncate, append)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/wshrpc/wshremote/wshremote.go
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Build for TestDriver.ai
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
pkg/wshrpc/wshremote/wshremote.go (2)
727-732
: LGTM! Clear validation of mutually exclusive options.The validation ensures that
truncate
andappend
options cannot be used with a non-zero offset, preventing conflicting file operations.
759-762
: LGTM! Correct file open flags for each operation mode.The flags are properly set based on the truncate and append options, following standard Go file handling practices.
No description provided.