Skip to content

fix(im): handle messages-search page-limit int flag#446

Open
YangJunzhou-01 wants to merge 1 commit intolarksuite:mainfrom
YangJunzhou-01:fix/pagelimit
Open

fix(im): handle messages-search page-limit int flag#446
YangJunzhou-01 wants to merge 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

Fix lark-cli im +messages-search --page-limit incorrectly rejecting valid integer values such as --page-limit=2.

page-limit is registered as an int flag, but the implementation was reading it via runtime.Str("page-limit"). In real CLI execution this returned an empty value, causing validation to fail with:

--page-limit must be an integer between 1 and 40

This PR updates +messages-search to read page-limit via runtime.Int("page-limit") and aligns the related test helpers with the real int flag registration.

Scope

  • Only affects lark-cli im +messages-search
  • No shared/common modules changed
  • No behavior change for default pagination or --page-all without explicit --page-limit

Test Plan

go test ./shortcuts/im -count=1

Also verified locally that:

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

now succeeds and returns 2 results instead of failing validation.

Summary by CodeRabbit

  • Bug Fixes
    • Improved page limit handling for message searches by ensuring the --page-limit flag is properly processed as an integer with appropriate range validation, instead of relying on string parsing.

Change-Id: Ic4876f4ca7f410a8fe3234e08e41b54ce26990d9
@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0e900e7-0125-48ef-9106-d15ff439f5f5

📥 Commits

Reviewing files that changed from the base of the PR and between bb79572 and de80169.

📒 Files selected for processing (3)
  • shortcuts/im/builders_test.go
  • shortcuts/im/im_messages_search.go
  • shortcuts/im/im_messages_search_execute_test.go

📝 Walkthrough

Walkthrough

The pull request refactors the page-limit CLI flag from a string-based flag to an integer flag across test helpers and implementation code. Flag registration and parsing logic in three files now consistently treat page-limit as an int type with a default value of 20, eliminating manual string-to-integer conversion.

Changes

Cohort / File(s) Summary
Test Flag Registration
shortcuts/im/builders_test.go, shortcuts/im/im_messages_search_execute_test.go
Updated page-limit flag registration from String() to Int() with default value 20 in test runtime context helpers.
Implementation Logic
shortcuts/im/im_messages_search.go
Removed unused strings import. Changed page-limit parsing to call runtime.Int("page-limit") directly instead of string trimming and strconv.Atoi(). Updated pagination config to use min(runtime.Int("page-limit"), messagesSearchMaxPageLimit) for clamping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop, a skip, a type so fine,
From string to int in perfect line,
The page-limit flag now truly gleams,
With default twenty in our streams! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing handling of the page-limit flag as an integer in the messages-search command.
Description check ✅ Passed The description includes all required template sections: Summary (explaining the fix and root cause), Changes (implied through scope), Test Plan (with go test command and manual verification), and Related Issues.

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

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

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 on lines 31 to 36
for name := range stringFlags {
if name == "page-limit" {
cmd.Flags().Int(name, 20, "")
continue
}
cmd.Flags().String(name, "", "")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Int-flag semantics leaking into stringFlags parameter

newTestRuntimeContext accepts stringFlags map[string]string, but now special-cases "page-limit" to register it as an int flag. This works, but any future int flag would need another hardcoded branch here. im_messages_search_execute_test.go took the cleaner approach of registering int flags outside the helper — consider adding an intFlags map[string]int parameter to newTestRuntimeContext for consistency and extensibility.

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

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

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.

1 participant