fix(im): support file input for message content flags#926
Conversation
|
|
📝 WalkthroughWalkthroughThe PR adds file and stdin input source support to the ChangesMessage content file and stdin input support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/im/im_messages_send_input_test.go (1)
54-55: ⚡ Quick winUse
os.WriteFilefor temp test fixtures instead ofvfs.WriteFile.For
t.TempDir()fixtures, prefer stdlib file writes so tests don’t depend on productionvfsbehavior.Suggested patch
import ( "bytes" "context" "encoding/json" + "os" "strings" "testing" @@ - "github.com/larksuite/cli/internal/vfs" _ "github.com/larksuite/cli/internal/vfs/localfileio" @@ - if err := vfs.WriteFile("card.json", []byte(card), 0644); err != nil { + if err := os.WriteFile("card.json", []byte(card), 0o644); err != nil { t.Fatal(err) } @@ - if err := vfs.WriteFile("message.md", []byte(markdown), 0644); err != nil { + if err := os.WriteFile("message.md", []byte(markdown), 0o644); err != nil { t.Fatal(err) }Based on learnings: “In larksuite/cli Go tests (
*_test.go), create/populate fixtures undert.TempDir()with standard libraryos.*APIs; avoidvfs.*in tests.”Also applies to: 85-86
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/im/im_messages_send_input_test.go` around lines 54 - 55, Tests are writing fixture files with vfs.WriteFile which couples tests to production virtual FS; switch to the standard library by using t.TempDir() and os.WriteFile to create the "card.json" fixture (and the other occurrence around the code that writes fixtures at the 85-86 region), e.g. build the fixture path with filepath.Join(t.TempDir(), "card.json") and call os.WriteFile(path, []byte(card), 0644) so the test uses the OS temp dir instead of vfs.WriteFile.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/im/im_messages_send_input_test.go`:
- Around line 54-55: Tests are writing fixture files with vfs.WriteFile which
couples tests to production virtual FS; switch to the standard library by using
t.TempDir() and os.WriteFile to create the "card.json" fixture (and the other
occurrence around the code that writes fixtures at the 85-86 region), e.g. build
the fixture path with filepath.Join(t.TempDir(), "card.json") and call
os.WriteFile(path, []byte(card), 0644) so the test uses the OS temp dir instead
of vfs.WriteFile.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d818b208-5ae7-4bec-bffd-9de45ef74e33
📒 Files selected for processing (2)
shortcuts/im/im_messages_send.goshortcuts/im/im_messages_send_input_test.go
Summary
Support
@fileand stdin (-) input for the message body flags inim +messages-send, so agents and scripts can send larger text, Markdown, and interactive card JSON without shell-escaping the whole payload inline.Changes
common.Fileandcommon.Stdininput metadata to--content,--text, and--markdown.--content @card.jsonand--markdown @message.mdare resolved before request construction.Test Plan
go test ./shortcuts/im -run 'TestImMessagesSend(ContentFlagsSupportFileAndStdin|DryRunResolves(Content|Markdown)FileInput)' -count=1go test ./shortcuts/im -run 'TestImMessagesSend|TestShortcutDryRunShapes' -count=1gofmt -l shortcuts/im/im_messages_send.go shortcuts/im/im_messages_send_input_test.gogit diff --check -- shortcuts/im/im_messages_send.go shortcuts/im/im_messages_send_input_test.gogo test ./shortcuts/im -count=1was run locally on Windows but is blocked by existing media/path tests unrelated to this change (TestParseMediaDurationSuccess,TestNormalizeDownloadOutputPath,TestResolveIMResourceDownloadPath,TestValidateMediaFlagPath).Related Issues
Summary by CodeRabbit
--content,--text,--markdown), allowing users to provide message content from files or piped input.