Skip to content

fix(im): unify messages-search pagination int flags#446

Merged
YangJunzhou-01 merged 1 commit intolarksuite:mainfrom
YangJunzhou-01:fix/pagelimit
Apr 23, 2026
Merged

fix(im): unify messages-search pagination int flags#446
YangJunzhou-01 merged 1 commit intolarksuite:mainfrom
YangJunzhou-01:fix/pagelimit

Conversation

@YangJunzhou-01
Copy link
Copy Markdown
Collaborator

@YangJunzhou-01 YangJunzhou-01 commented Apr 13, 2026

Summary

Unify lark-cli im +messages-search pagination flags to use int semantics consistently.

Previously, page-limit was registered as an int flag while page-size was still handled as a string flag and parsed manually. This led to inconsistent runtime behavior inside the same shortcut and allowed test helpers to drift from the real CLI flag registration.

This PR keeps the page-limit fix and further updates +messages-search so that both page-limit and page-size are handled as int flags. The implementation now reads:

  • page-limit via runtime.Int("page-limit")
  • page-size via runtime.Int("page-size")

Related test helpers and coverage tests are also aligned with the real CLI int flag registration for this shortcut.

Scope

  • Only affects lark-cli im +messages-search
  • No shared/common modules changed
  • No user-facing change for valid pagination usage
  • Default pagination behavior remains unchanged
  • --page-all behavior remains unchanged
  • page-size > 50 is still capped at 50
  • Invalid --page-size values now fail earlier at flag parsing instead of business validation

Test Plan

go test ./shortcuts/im -count=1

Also verified locally that valid usages remain consistent, including:

lark-cli im +messages-search --as user --chat-id <chat_id> --query 的 --page-size=1 --page-limit=2

and quoted numeric values such as:

lark-cli im +messages-search --as user --chat-id <chat_id> --query 的 --page-size="1" --page-limit='2'

continue to work as expected in normal shell usage.

Summary by CodeRabbit

  • Refactor

    • Pagination flags for message search are now treated as numeric, with stricter integer validation, clamping of page-size to the maximum, and explicit page-limit bounds (defaults unchanged).
  • Tests

    • Updated test setup and coverage to reflect the numeric pagination behavior and validate pagination-related scenarios.

@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 Apr 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Pagination flags (--page-size, --page-limit) were changed from string-backed to integer-backed in runtime and tests. Code now reads these via runtime.Int(...), validates and clamps integer values, and test helpers register and set the flags as Int types.

Changes

Cohort / File(s) Summary
Test runtime helpers & tests
shortcuts/im/builders_test.go, shortcuts/im/im_messages_search_execute_test.go, shortcuts/im/coverage_additional_test.go
Introduce newMessagesSearchTestRuntimeContext; register --page-size and --page-limit as Int flags (default 20), remove them from string-flag lists, parse flags, and set provided flag values via Flags().Set(...). Tests switched to use the new helper.
Implementation: messages search
shortcuts/im/im_messages_search.go
Replace string trimming/Atoi with runtime.Int("page-size") / runtime.Int("page-limit"); validate lower/upper bounds, clamp to messagesSearchMaxPageSize/messagesSearchMaxPageLimit; remove unused strings import.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I munched on flags beneath the moon,
Turned loose strings into numbers soon.
Twenty hops in tidy rows,
Pages counted as the breeze blows. ✨

🚥 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 and concisely summarizes the main change: unifying pagination int flags in the im messages-search shortcut.
Description check ✅ Passed The description covers all required template sections: Summary explains the motivation, Changes lists the main updates, Test Plan provides verification commands and examples, and Related Issues is addressed.
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.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 13, 2026

Greptile Summary

This PR fixes --page-limit being silently ignored in +messages-search because the flag was registered as int but read via runtime.Str(\"page-limit\"), which always returned an empty string and caused the validation to always fail. The fix is straightforward: switch to runtime.Int(\"page-limit\") in both buildMessagesSearchRequest and messagesSearchPaginationConfig, and align the two test helpers to register the flag as int instead of string.

Confidence Score: 5/5

Safe to merge — the fix is minimal, targeted, and directly resolves a real validation regression with no side effects.

All findings are P2 style suggestions. The core bug fix is correct: switching from Str to Int for an int-registered flag, with test helpers aligned accordingly. No P0/P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
shortcuts/im/im_messages_search.go Core bug fix: replaces runtime.Str("page-limit") with runtime.Int("page-limit") in validation and pagination config; removes now-unnecessary strconv/strings imports.
shortcuts/im/builders_test.go Adds special-case handling for "page-limit" inside the stringFlags loop to register it as an int flag; works correctly but leaks int-flag semantics into the string-flag parameter.
shortcuts/im/im_messages_search_execute_test.go Correctly removes "page-limit" from the string flag list and registers it explicitly as an int flag with cmd.Flags().Int.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI (cobra)
    participant RT as RuntimeContext
    participant BSR as buildMessagesSearchRequest
    participant MPC as messagesSearchPaginationConfig
    participant SM as searchMessages

    CLI->>RT: --page-limit=2 (int flag)
    RT->>BSR: runtime.Int("page-limit") → 2
    BSR->>BSR: validate: 1 ≤ 2 ≤ 40 ✓
    BSR-->>CLI: *messagesSearchRequest (no error)
    CLI->>SM: Execute(req)
    SM->>MPC: runtime.Int("page-limit") → 2
    MPC-->>SM: autoPaginate=true, pageLimit=min(2,40)=2
    SM-->>CLI: results (up to 2 pages)
Loading

Reviews (1): Last reviewed commit: "fix(im): handle messages-search page-lim..." | Re-trigger Greptile

Comment thread shortcuts/im/builders_test.go
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@06c66d90c65ba217ed908e385af51cb571899465

🧩 Skill update

npx skills add YangJunzhou-01/cli#fix/pagelimit -y -g

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.04%. Comparing base (9057299) to head (06c66d9).
⚠️ Report is 29 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #446      +/-   ##
==========================================
- Coverage   60.64%   60.04%   -0.60%     
==========================================
  Files         393      406      +13     
  Lines       33789    43082    +9293     
==========================================
+ Hits        20490    25870    +5380     
- Misses      11391    15194    +3803     
- Partials     1908     2018     +110     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/im/builders_test.go`:
- Around line 576-580: Add a positive regression assertion that an explicit page
limit is accepted by the validation/request-building path: using the existing
test runtime created by newMessagesSearchTestRuntimeContext (with
"page-limit":"3"), call the relevant validation/build path (either Validate on
the command or buildMessagesSearchRequest) and assert it returns no error and
that the produced request contains the expected pageLimit (or that validation
passes). This should be added alongside the existing
messagesSearchPaginationConfig check so the test covers both config parsing and
the Validate/buildMessagesSearchRequest flow (refer to
messagesSearchPaginationConfig, newMessagesSearchTestRuntimeContext, Validate,
and buildMessagesSearchRequest).
🪄 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: e6d00c1e-67cf-481c-9baf-c2d74f882c6f

📥 Commits

Reviewing files that changed from the base of the PR and between 548f377 and eba1fae.

📒 Files selected for processing (4)
  • shortcuts/im/builders_test.go
  • shortcuts/im/coverage_additional_test.go
  • shortcuts/im/im_messages_search.go
  • shortcuts/im/im_messages_search_execute_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/im/im_messages_search_execute_test.go

Comment thread shortcuts/im/builders_test.go
@YangJunzhou-01 YangJunzhou-01 changed the title fix(im): handle messages-search page-limit int flag fix(im): unify messages-search pagination int flags Apr 18, 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_search.go (1)

254-255: Nit: derive error messages from constants to avoid drift.

The error strings hardcode 1 and 40 and 1 and 50, duplicating messagesSearchMaxPageLimit and messagesSearchMaxPageSize. If either bound ever changes, the messages will silently go stale. Since these errors are also parsed by AI agents, keeping them in sync with the actual limit is worthwhile.

♻️ Suggested change
-			return nil, output.ErrValidation("--page-limit must be an integer between 1 and 40")
+			return nil, output.ErrValidation("--page-limit must be an integer between 1 and %d", messagesSearchMaxPageLimit)
@@
-		return nil, output.ErrValidation("--page-size must be an integer between 1 and 50")
+		return nil, output.ErrValidation("--page-size must be an integer between 1 and %d", messagesSearchMaxPageSize)

(Adjust to fmt.Sprintf(...) if output.ErrValidation isn't format-aware.)

Also applies to: 334-336

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/im/im_messages_search.go` around lines 254 - 255, Replace hardcoded
numeric bounds in validation error messages with formatted strings that use the
constants messagesSearchMaxPageLimit and messagesSearchMaxPageSize so the
message always reflects the actual limits; update the calls to
output.ErrValidation to pass a formatted string (e.g. via fmt.Sprintf) using
those constants where the checks occur (the pageLimit and pageSize validation
branches in im_messages_search.go, including the other occurrence around the
block referenced at lines 334-336) so the error text derives from the constants
rather than hardcoded values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shortcuts/im/im_messages_search.go`:
- Around line 254-255: Replace hardcoded numeric bounds in validation error
messages with formatted strings that use the constants
messagesSearchMaxPageLimit and messagesSearchMaxPageSize so the message always
reflects the actual limits; update the calls to output.ErrValidation to pass a
formatted string (e.g. via fmt.Sprintf) using those constants where the checks
occur (the pageLimit and pageSize validation branches in im_messages_search.go,
including the other occurrence around the block referenced at lines 334-336) so
the error text derives from the constants rather than hardcoded values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7565214f-e87b-4ced-93c5-615e1269707d

📥 Commits

Reviewing files that changed from the base of the PR and between eba1fae and 5879f2d.

📒 Files selected for processing (4)
  • shortcuts/im/builders_test.go
  • shortcuts/im/coverage_additional_test.go
  • shortcuts/im/im_messages_search.go
  • shortcuts/im/im_messages_search_execute_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • shortcuts/im/coverage_additional_test.go
  • shortcuts/im/im_messages_search_execute_test.go
  • shortcuts/im/builders_test.go

Change-Id: Ic4876f4ca7f410a8fe3234e08e41b54ce26990d9
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/builders_test.go (1)

28-87: Optional: deduplicate the two runtime-context helpers.

newMessagesSearchTestRuntimeContext is ~95% a copy of newTestRuntimeContext (only difference: it also registers page-size as Int). Consider collapsing to a single helper that accepts an optional list of extra Int flag names, or factor the shared body (parse + set loops) into an unexported helper to avoid drift if the flag-setting protocol changes later.

♻️ Sketch
-func newTestRuntimeContext(t *testing.T, stringFlags map[string]string, boolFlags map[string]bool) *common.RuntimeContext {
-    ...
-}
-
-func newMessagesSearchTestRuntimeContext(t *testing.T, stringFlags map[string]string, boolFlags map[string]bool) *common.RuntimeContext {
-    ...
-}
+func newTestRuntimeContext(t *testing.T, stringFlags map[string]string, boolFlags map[string]bool, intFlags ...string) *common.RuntimeContext {
+    t.Helper()
+    cmd := &cobra.Command{Use: "test"}
+    intSet := map[string]struct{}{"page-limit": {}}
+    for _, n := range intFlags {
+        intSet[n] = struct{}{}
+    }
+    for n := range intSet {
+        cmd.Flags().Int(n, 20, "")
+    }
+    for name := range stringFlags {
+        if _, ok := intSet[name]; ok {
+            continue
+        }
+        cmd.Flags().String(name, "", "")
+    }
+    // ... rest unchanged
+}
+
+func newMessagesSearchTestRuntimeContext(t *testing.T, s map[string]string, b map[string]bool) *common.RuntimeContext {
+    return newTestRuntimeContext(t, s, b, "page-size")
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/im/builders_test.go` around lines 28 - 87, Both
newTestRuntimeContext and newMessagesSearchTestRuntimeContext duplicate almost
all logic; refactor by creating a single helper (e.g., newTestRuntimeContext)
that accepts an optional slice of additional int flag names (extraIntFlags
[]string) or by extracting the shared parsing/setting logic into an unexported
helper (e.g., prepareCmdFlags) used by both functions; update
newMessagesSearchTestRuntimeContext to call the unified helper (or call
prepareCmdFlags) and ensure you still register "page-limit" (and "page-size"
when passed via extraIntFlags) and keep the same flag parsing and Flags().Set
loops (preserve behavior of stringFlags and boolFlags handling and error
t.Fatalf calls).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shortcuts/im/builders_test.go`:
- Around line 28-87: Both newTestRuntimeContext and
newMessagesSearchTestRuntimeContext duplicate almost all logic; refactor by
creating a single helper (e.g., newTestRuntimeContext) that accepts an optional
slice of additional int flag names (extraIntFlags []string) or by extracting the
shared parsing/setting logic into an unexported helper (e.g., prepareCmdFlags)
used by both functions; update newMessagesSearchTestRuntimeContext to call the
unified helper (or call prepareCmdFlags) and ensure you still register
"page-limit" (and "page-size" when passed via extraIntFlags) and keep the same
flag parsing and Flags().Set loops (preserve behavior of stringFlags and
boolFlags handling and error t.Fatalf calls).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 213e381d-653e-4155-bf6c-a55ffb9e9a3a

📥 Commits

Reviewing files that changed from the base of the PR and between 5879f2d and 06c66d9.

📒 Files selected for processing (4)
  • shortcuts/im/builders_test.go
  • shortcuts/im/coverage_additional_test.go
  • shortcuts/im/im_messages_search.go
  • shortcuts/im/im_messages_search_execute_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/im/coverage_additional_test.go
  • shortcuts/im/im_messages_search_execute_test.go

Copy link
Copy Markdown
Contributor

@haozhenghua-code haozhenghua-code left a comment

Choose a reason for hiding this comment

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

get

@YangJunzhou-01 YangJunzhou-01 merged commit fc6d722 into larksuite:main Apr 23, 2026
18 checks passed
@liangshuo-1 liangshuo-1 mentioned this pull request Apr 23, 2026
3 tasks
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.

3 participants