Skip to content

fix(im): support file input for message content flags#926

Open
xu91102 wants to merge 1 commit into
larksuite:mainfrom
xu91102:codex/im-messages-send-input
Open

fix(im): support file input for message content flags#926
xu91102 wants to merge 1 commit into
larksuite:mainfrom
xu91102:codex/im-messages-send-input

Conversation

@xu91102
Copy link
Copy Markdown

@xu91102 xu91102 commented May 16, 2026

Summary

Support @file and stdin (-) input for the message body flags in im +messages-send, so agents and scripts can send larger text, Markdown, and interactive card JSON without shell-escaping the whole payload inline.

Changes

  • Add common.File and common.Stdin input metadata to --content, --text, and --markdown.
  • Add mounted shortcut dry-run tests that verify --content @card.json and --markdown @message.md are resolved before request construction.
  • Keep media flags unchanged because they represent media keys, URLs, or local media paths rather than file contents.

Test Plan

  • Unit tests pass: go test ./shortcuts/im -run 'TestImMessagesSend(ContentFlagsSupportFileAndStdin|DryRunResolves(Content|Markdown)FileInput)' -count=1
  • Related IM dry-run tests pass: go test ./shortcuts/im -run 'TestImMessagesSend|TestShortcutDryRunShapes' -count=1
  • Format check: gofmt -l shortcuts/im/im_messages_send.go shortcuts/im/im_messages_send_input_test.go
  • Diff check: git diff --check -- shortcuts/im/im_messages_send.go shortcuts/im/im_messages_send_input_test.go
  • Full package test: go test ./shortcuts/im -count=1 was 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

  • New Features
    • The IM send message shortcut now supports file and stdin inputs for message content options (--content, --text, --markdown), allowing users to provide message content from files or piped input.

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

📝 Walkthrough

Walkthrough

The PR adds file and stdin input source support to the im +messages-send shortcut's message content flags (--content, --text, --markdown). Flag metadata is updated to advertise common.File and common.Stdin, and a comprehensive test suite verifies the metadata presence and file-input resolution behavior in dry-run mode.

Changes

Message content file and stdin input support

Layer / File(s) Summary
Flag input source metadata
shortcuts/im/im_messages_send.go
The --content, --text, and --markdown flags in ImMessagesSend.Flags now include Input: []string{common.File, common.Stdin} to declare file and stdin input support.
Input support validation and dry-run tests
shortcuts/im/im_messages_send_input_test.go
Three test functions verify that content flags declare the correct input sources and that dry-run correctly resolves @card.json into interactive message type and @message.md into post message type. Four helper functions support test setup, shortcut execution, and dry-run output parsing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

domain/im

Suggested reviewers

  • YangJunzhou-01

Poem

🐰 A shortcut learns to read from files,
No more quoting JSON miles,
Cards and markdown find their way,
From disk to chat in one command's play!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding file input support for message content flags in the im messages-send shortcut.
Description check ✅ Passed The description follows the repository template with all required sections: Summary, Changes, Test Plan, and Related Issues are complete and detailed.
Linked Issues check ✅ Passed The PR fully addresses issue #916 by implementing file/stdin support for --content, --text, and --markdown flags with corresponding tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: flag metadata updates and input validation tests for message content flags only.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact labels May 16, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
shortcuts/im/im_messages_send_input_test.go (1)

54-55: ⚡ Quick win

Use os.WriteFile for temp test fixtures instead of vfs.WriteFile.

For t.TempDir() fixtures, prefer stdlib file writes so tests don’t depend on production vfs behavior.

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 under t.TempDir() with standard library os.* APIs; avoid vfs.* 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

📥 Commits

Reviewing files that changed from the base of the PR and between 898e0ee and e85aa5f.

📒 Files selected for processing (2)
  • shortcuts/im/im_messages_send.go
  • shortcuts/im/im_messages_send_input_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support file/stdin content for interactive card sends

2 participants