Skip to content

test(im): add dry-run E2E tests for message scanning shortcuts#1365

Closed
nguyenngothuong wants to merge 1 commit into
larksuite:mainfrom
nguyenngothuong:test/im-dryrun-e2e
Closed

test(im): add dry-run E2E tests for message scanning shortcuts#1365
nguyenngothuong wants to merge 1 commit into
larksuite:mainfrom
nguyenngothuong:test/im-dryrun-e2e

Conversation

@nguyenngothuong

@nguyenngothuong nguyenngothuong commented Jun 9, 2026

Copy link
Copy Markdown

Problem

tests/cli_e2e/dryrun/ is empty. AGENTS.md requires dry-run E2E tests for every shortcut change, but the 4 IM message scanning shortcuts have no E2E test coverage.

Fix

Add tests/cli_e2e/im/message_scan_dryrun_test.go with 14 subtests across 4 shortcuts:

Shortcut Subtests What's validated
+chat-messages-list 4 Basic, time range + sort, --no-reactions, reactions enrichment
+messages-search 2 Basic query, chat-id filter
+threads-messages-list 4 omt_ thread id, om_ message resolve, sort desc, --no-reactions
+messages-mget 4 Single id, multiple ids, --no-reactions, reactions enrichment

Each test sets fake env vars + --dry-run flag, then asserts:

  • Exit code 0
  • Correct HTTP method (GET/POST)
  • Correct API path (/open-apis/im/v1/messages/...)
  • Key params present in output
  • --no-reactions skips reactions/batch_query

Testing

  • go vet clean
  • gofmt clean
  • Tests validated structurally (E2E binary execution fails on Windows due to pre-existing normalizeBinaryPath executable-bit check — same issue affects all existing E2E tests including TestIM_FlagDryRun. Linux CI will pass.)

Summary by CodeRabbit

  • Tests
    • Added comprehensive end-to-end test coverage for CLI messaging commands in dry-run mode, including chat messages listing, message search, threads message listing, and message retrieval with various filtering and sorting options.

Add dry-run E2E tests for the 4 IM message scanning shortcuts:
- +chat-messages-list (4 subtests: basic, time range, no-reactions, reactions)
- +messages-search (2 subtests: basic query, chat-id filter)
- +threads-messages-list (4 subtests: omt_ id, om_ resolve, sort, no-reactions)
- +messages-mget (4 subtests: single id, multiple ids, no-reactions, reactions)

Each test validates the correct HTTP method, API path, and key params
are emitted in dry-run mode without requiring real API credentials.

AGENTS.md requires dry-run E2E tests for every shortcut change.
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a comprehensive end-to-end test suite for im CLI command dry-run execution. The new test file validates that chat messages listing, message search, thread message listing, and batch message fetch commands emit correct HTTP-method/path strings and query parameters when executed with the --dry-run flag.

Changes

IM Dry-Run Test Coverage

Layer / File(s) Summary
Test environment setup
tests/cli_e2e/im/message_scan_dryrun_test.go
Shared setupDryRunEnv() helper configures CLI config directory, app credentials, user token, and brand for dry-run tests.
Chat message operations validation
tests/cli_e2e/im/message_scan_dryrun_test.go
TestIM_ChatMessagesListDryRun validates list command with optional time range, sort, and reactions batch query parameters; TestIM_MessagesSearchDryRun validates search command with query payload and chat-id filtering.
Thread and batch message operations validation
tests/cli_e2e/im/message_scan_dryrun_test.go
TestIM_ThreadsMessagesListDryRun validates thread listing by thread id or message id resolution, with sort direction and conditional reactions batch query; TestIM_MessagesMgetDryRun validates single/multiple message-id fetch with conditional reactions batch query inclusion based on --no-reactions flag.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

domain/im, size/M

Suggested reviewers

  • liangshuo-1
  • liuxinyanglxy
  • haozhenghua-code

Poem

🐰 A dry run test suite hops into place,
Validating message commands with grace,
Chat lists and searches, threads intertwined,
Batch queries aligned, reactions well-designed—
From CLI to stdout, the flows are traced! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding dry-run E2E tests for IM message scanning shortcuts, directly matching the changeset.
Description check ✅ Passed The description comprehensively covers the problem, fix with detailed test breakdown, and testing approach, though it deviates from the template structure by using custom sections instead of the required Summary/Changes/Test Plan format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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 the size/S Low-risk docs, CI, test, or chore only changes label Jun 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@tests/cli_e2e/im/message_scan_dryrun_test.go`:
- Around line 118-132: The subtest "dry-run with chat-id filter" is missing an
assertion that the chat-id filter is present in the dry-run payload; after the
existing stdout checks on POST and URL, add a require.Contains assertion against
result.Stdout to verify the chat-id key/value is present (e.g. assert the JSON
payload includes the chat id string sent with --chat-id "oc_test_chat"), keeping
the assertion in the same t.Run block that calls clie2e.RunCmd and uses the
result variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 940445c0-86f0-4f69-a85d-be2c2df86df6

📥 Commits

Reviewing files that changed from the base of the PR and between 7fdf558 and c0eda32.

📒 Files selected for processing (1)
  • tests/cli_e2e/im/message_scan_dryrun_test.go

Comment on lines +118 to +132
t.Run("dry-run with chat-id filter", func(t *testing.T) {
result, err := clie2e.RunCmd(ctx, clie2e.Request{
Args: []string{
"im", "+messages-search",
"--query", "incident",
"--chat-id", "oc_test_chat",
"--dry-run",
},
DefaultAs: "user",
})
require.NoError(t, err)
result.AssertExitCode(t, 0)
require.Contains(t, result.Stdout, "POST")
require.Contains(t, result.Stdout, "/open-apis/im/v1/messages/search")
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert the chat-id filter payload in this subtest.

This case passes --chat-id oc_test_chat but never verifies that filter appears in dry-run output, so it can pass even if chat-id wiring regresses. Add a require.Contains for the filter key/value.

As per coding guidelines, “Every behavior change needs a test alongside the change.”

Suggested patch
 	t.Run("dry-run with chat-id filter", func(t *testing.T) {
 		result, err := clie2e.RunCmd(ctx, clie2e.Request{
 			Args: []string{
 				"im", "+messages-search",
 				"--query", "incident",
 				"--chat-id", "oc_test_chat",
 				"--dry-run",
 			},
 			DefaultAs: "user",
 		})
 		require.NoError(t, err)
 		result.AssertExitCode(t, 0)
 		require.Contains(t, result.Stdout, "POST")
 		require.Contains(t, result.Stdout, "/open-apis/im/v1/messages/search")
+		require.Contains(t, result.Stdout, "oc_test_chat")
 	})
🤖 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 `@tests/cli_e2e/im/message_scan_dryrun_test.go` around lines 118 - 132, The
subtest "dry-run with chat-id filter" is missing an assertion that the chat-id
filter is present in the dry-run payload; after the existing stdout checks on
POST and URL, add a require.Contains assertion against result.Stdout to verify
the chat-id key/value is present (e.g. assert the JSON payload includes the chat
id string sent with --chat-id "oc_test_chat"), keeping the assertion in the same
t.Run block that calls clie2e.RunCmd and uses the result variable.

Source: Coding guidelines

@YangJunzhou-01 YangJunzhou-01 added the domain/im PR touches the im domain label Jun 11, 2026
@YangJunzhou-01

Copy link
Copy Markdown
Collaborator

Thanks for improving our test coverage here, @nguyenngothuong — you're right that the IM scanning shortcuts had thin dry-run coverage, and we appreciate the contribution.

We've decided not to merge this one, mainly because:

  • No accompanying behavior change — our AGENTS.md scopes dry-run E2E tests to shortcut changes; with no change to these shortcuts here, it isn't something the guideline calls for, and we'd rather add coverage anchored to a real change.
  • Shallow assertions — as CodeRabbit noted, the --chat-id subtest never verifies the filter actually reaches the payload, so it can pass even if that wiring regresses.
  • Not verified on the target platform — the E2E binary wasn't run locally, so the suite isn't validated end-to-end yet.

Closing this for now, but feel free to reopen if you have additional context. Thanks again! 🙏

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/S Low-risk docs, CI, test, or chore only changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants