Skip to content

feat: add client-side page_size validation for service commands#1222

Open
xukuncx wants to merge 2 commits into
larksuite:mainfrom
xukuncx:feat/1694214
Open

feat: add client-side page_size validation for service commands#1222
xukuncx wants to merge 2 commits into
larksuite:mainfrom
xukuncx:feat/1694214

Conversation

@xukuncx
Copy link
Copy Markdown
Collaborator

@xukuncx xukuncx commented Jun 2, 2026

Generated by the harness-coding skill (recovery run — original attempt crashed before MR open).

  • Branch: feat/1694214
  • Target: main

The commits below were produced by a prior coding run on this branch. The current resume run regenerated the sprint plan from tech-specs and confirmed those commits already implement the work (sprint status skipped:already_implemented). Any sprint with status passed in the table below represents work this resume run added on top.

Commits on branch (ahead of main)

Commit Subject
7160473 feat: add client-side page_size validation for service commands

This resume run

ID Title Status Commit
S1 Synthesize transport contract for larksuite/cli passed bc8e9bd
S2 Add page_size client-side validation for mail user_mailbox.messages list command passed 7160473

This MR was created autonomously. Quality gates were enforced by the repo's own pre-commit hooks.

Summary by CodeRabbit

  • New Features

    • Query parameters are validated against configured minimum and maximum constraints.
    • Numeric values supplied as strings or numbers are interpreted and validated; out-of-range values produce clear validation errors.
    • Pagination page_size is enforced against configured maximums (dry-run rejects too-large values; boundary values allowed).
  • Tests

    • Added comprehensive tests for numeric range validation and pagination enforcement.

Validate query parameter values against min/max constraints declared
in the API schema metadata before sending requests to the server.
This provides clear error messages instead of the generic "field
validation failed" response from the backend.

The validation applies to all numeric query parameters that have min
or max constraints in their schema definition, catching out-of-range
values early with actionable hints (including the schema command path
for reference).

sprint: S2
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94e1dba3-b2ca-47ef-9abe-9793a5fd1cab

📥 Commits

Reviewing files that changed from the base of the PR and between 7160473 and 0ebb9de.

📒 Files selected for processing (1)
  • cmd/service/service.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/service/service.go

📝 Walkthrough

Walkthrough

Adds numeric min/max enforcement for query parameters during service request construction via a new validateQueryParamRange helper; integrates checks into buildServiceRequest and adds unit and integration tests exercising boundary and type cases, including page_size enforcement in dry-run mode.

Changes

Query Parameter Range Validation

Layer / File(s) Summary
Range validation helper and integration
cmd/service/service.go
Added imports for encoding/json and strconv. Implemented validateQueryParamRange and parseFloat64 to convert numeric inputs and enforce min/max constraints; integrated validation into buildServiceRequest for declared query params and leftover --params.
Unit and integration tests
cmd/service/service_test.go
Added unit tests covering nil/missing specs, boundary matches, out-of-range errors, and multiple input types (string, non-numeric, int). Added integration tests ensuring --dry-run rejects page_size above configured max and accepts values at the max boundary while producing dry-run output.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit checks each numeric gate,
Min and max now guard the slate,
Page sizes bounded, strings converted true,
Dry-run whispers when limits are untrue,
Hopping safe through params — hop, review!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it lacks a structured Summary and Changes section, and provides no Test Plan, making it difficult to understand the PR's scope and verification approach. Add a Summary section explaining the motivation, list main Changes (buildServiceRequest, validateQueryParamRange, test additions), and document how changes were tested.
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add client-side page_size validation for service commands' clearly summarizes the main change—adding validation for page_size on the client side.
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/L Large or sensitive change across domains or core paths label Jun 2, 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)
cmd/service/service.go (1)

437-444: 💤 Low value

validateQueryParamRange(name, value, nil, …) is always a no-op here.

This second loop only handles params not already mapped to a declared query param, so paramSpec is always nil and the helper returns immediately at Line 549-551. The call neither validates nor documents a future constraint source. Consider dropping it to avoid implying validation that can never run.

♻️ Optional simplification
 	for name, value := range params {
 		if _, ok := queryParams[name]; !ok {
-			if err := validateQueryParamRange(name, value, nil, schemaPath); err != nil {
-				return client.RawApiRequest{}, nil, err
-			}
 			queryParams[name] = value
 		}
 	}
🤖 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 `@cmd/service/service.go` around lines 437 - 444, The second loop over params
is calling validateQueryParamRange(name, value, nil, schemaPath) but since this
loop only handles names not in queryParams the helper always receives paramSpec
== nil and returns immediately; remove the no-op call to validateQueryParamRange
from that loop and just set queryParams[name] = value (or, if you intended to
validate against a fallback/global constraint, replace the nil paramSpec with
the appropriate spec lookup before calling validateQueryParamRange). Ensure
references to queryParams, params, validateQueryParamRange, and schemaPath are
updated accordingly.
🤖 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 `@cmd/service/service.go`:
- Around line 437-444: The second loop over params is calling
validateQueryParamRange(name, value, nil, schemaPath) but since this loop only
handles names not in queryParams the helper always receives paramSpec == nil and
returns immediately; remove the no-op call to validateQueryParamRange from that
loop and just set queryParams[name] = value (or, if you intended to validate
against a fallback/global constraint, replace the nil paramSpec with the
appropriate spec lookup before calling validateQueryParamRange). Ensure
references to queryParams, params, validateQueryParamRange, and schemaPath are
updated accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6783135-69c7-4b7f-a92b-1bd694beb5fd

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa9e96 and 7160473.

📒 Files selected for processing (2)
  • cmd/service/service.go
  • cmd/service/service_test.go

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add xukuncx/cli#feat/1694214 -y -g

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 73.46939% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.20%. Comparing base (0aa9e96) to head (0ebb9de).

Files with missing lines Patch % Lines
cmd/service/service.go 73.46% 13 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1222   +/-   ##
=======================================
  Coverage   69.19%   69.20%           
=======================================
  Files         634      634           
  Lines       59482    59531   +49     
=======================================
+ Hits        41161    41200   +39     
- Misses      15007    15018   +11     
+ Partials     3314     3313    -1     

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

@xukuncx
Copy link
Copy Markdown
Collaborator Author

xukuncx commented Jun 2, 2026

🤖 AI Review | [P3 可维护性] PR 描述残留恢复运行过程信息

PR 描述包含 recovery runoriginal attempt crashedprior coding runresume run 等执行过程痕迹,并把验证信息留在流水线叙述中。后续维护者无法仅根据描述快速确认变更范围和实际验证项;这也不符合仓库要求完整填写 PR 模板的约定。

修复建议: 将描述改为自包含的 SummaryChangesTest PlanRelated Issues 四节,只保留最终行为、改动文件和已执行测试,不保留恢复过程或 sprint 状态。

如有疑问或认为判断不准确,欢迎直接回复讨论。

@xukuncx
Copy link
Copy Markdown
Collaborator Author

xukuncx commented Jun 2, 2026

🤖 AI Review | CR 汇总 | 可合入(2 个建议项)

增量审查:基于之前 1 条 CodeRabbit 审查意见,本次新增 1 条评论。

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 2

其中 cmd/service/service.go:439validateQueryParamRange(name, value, nil, schemaPath) 恒为 no-op,已有 CodeRabbit 评论覆盖,本次按去重规则不重复发表。新增评论要求清理 PR 描述中的恢复运行过程痕迹,并补齐自包含 Test Plan。

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

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant