test(im): add dry-run E2E tests for message scanning shortcuts#1365
test(im): add dry-run E2E tests for message scanning shortcuts#1365nguyenngothuong wants to merge 1 commit into
Conversation
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.
📝 WalkthroughWalkthroughThis PR adds a comprehensive end-to-end test suite for ChangesIM Dry-Run Test Coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
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
📒 Files selected for processing (1)
tests/cli_e2e/im/message_scan_dryrun_test.go
| 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") | ||
| }) |
There was a problem hiding this comment.
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
|
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:
Closing this for now, but feel free to reopen if you have additional context. Thanks again! 🙏 |
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.gowith 14 subtests across 4 shortcuts:+chat-messages-list+messages-search+threads-messages-list+messages-mgetEach test sets fake env vars +
--dry-runflag, then asserts:/open-apis/im/v1/messages/...)--no-reactionsskipsreactions/batch_queryTesting
go vetcleangofmtcleannormalizeBinaryPathexecutable-bit check — same issue affects all existing E2E tests includingTestIM_FlagDryRun. Linux CI will pass.)Summary by CodeRabbit