Skip to content

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

Closed
xukuncx wants to merge 1 commit into
larksuite:mainfrom
xukuncx:feat/1694214
Closed

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

Conversation

@xukuncx

@xukuncx xukuncx commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

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

  • Bug Fixes

    • Query parameters for service commands now validate integer values against configured min/max bounds and reject out-of-range or non-integer inputs with clear messages. Pagination-exception and existing parameter behaviors remain unchanged; validation applies only to targeted service parameters.
  • Tests

    • Added extensive tests covering range checks, parsing of numeric formats, allowlist behavior, and command-level dry-run scenarios (both failing and succeeding cases).

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

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

The PR adds selective query parameter range validation for service requests. A static allowlist maps service schema paths to specific parameter names eligible for validation. When building service requests, validateQueryParamRange is invoked for declared query parameters, dispatching to type-specific validators. Integer validation parses values, enforces optional min/max metadata constraints, and returns structured errors. Comprehensive tests cover allowlist behavior, boundary conditions, type safety, and end-to-end command execution with and without --dry-run.

Changes

Query Parameter Range Validation

Layer / File(s) Summary
Validation implementation and service integration
cmd/service/param_validation.go, cmd/service/service.go
Allowlist maps (schemaPath, paramName) pairs to enable validation. validateQueryParamRange dispatches based on metadata type; integer validation parses and checks optional min/max bounds, returning errs.NewValidationError when constraints are violated. Service request construction calls the validator during query-parameter assembly.
Unit and integration tests
cmd/service/param_validation_test.go
Unit tests verify allowlist-based skipping, nil specs, exact boundary inclusion, out-of-range rejection with message substrings, and type safety (float/non-numeric rejection). Integration tests confirm --dry-run command success/failure based on page_size bounds and --page-all skipping required parameter checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/M

Suggested reviewers

  • chanthuang

Poem

A rabbit hops through parameters with care,
Counting min and max with a thoughtful stare,
Allowlists keep the checks delightfully light,
Integers parsed and bounded just right,
Dry runs applaud the validator’s tiny bite. 🐰

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks the required template structure (Summary, Changes, Test Plan, Related Issues sections) and contains procedural recovery/resume-run traces instead of focused behavior documentation. Replace the description with the standard template: provide a concise Summary, itemized Changes list, documented Test Plan, and Related Issues section. Remove recovery-run execution traces.
Docstring Coverage ⚠️ Warning Docstring coverage is 4.44% 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 clearly and concisely describes the main change: adding client-side page_size validation for service commands, which matches the core functionality added in the changeset.
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

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

🧹 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

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

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

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.67%. Comparing base (03a5899) to head (734f73d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cmd/service/param_validation.go 96.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1222      +/-   ##
==========================================
- Coverage   69.90%   69.67%   -0.24%     
==========================================
  Files         645      667      +22     
  Lines       60235    64465    +4230     
==========================================
+ Hits        42110    44914    +2804     
- Misses      14823    15943    +1120     
- Partials     3302     3608     +306     

☔ View full report in Codecov by Harness.
📢 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

xukuncx commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

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

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

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

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

@xukuncx

xukuncx commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

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

@xukuncx

xukuncx commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 AI Review | CR 汇总 | 可合入(无新增代码问题)

增量审查:基于之前的 CodeRabbit 评论和 2 条 AI Review 评论,本次针对当前 head a7fa3e2 复查 cmd/service/service.gocmd/service/service_test.go,新增 0 条代码评论。

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 1(PR 描述过程痕迹仍存在,已由既有 AI 评论覆盖,本次不重复发表)

验证:go test ./cmd/service -run 'TestValidateQueryParamRange|TestServiceMethod_PageSize|TestServiceMethod_PageAll' -count=1 通过。

附注:GitHub 当前显示 mergeable_state=dirty,合入前仍需处理分支冲突。

@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 `@cmd/service/param_validation.go`:
- Around line 57-72: The min/max parsing currently swallows parse errors and
silently skips the bound check; update the blocks that call strconv.ParseInt on
minStr and maxStr (the code surrounding registry.GetStrFromMap, minStr/maxStr,
and strconv.ParseInt) to detect a non-nil err and return a validation error
instead of ignoring it—use errs.NewValidationError (same pattern as the existing
errors) to report a malformed bound for the parameter name and include a helpful
hint (use WithHint and WithParam) referencing schemaPath so callers know to fix
the paramSpec.
🪄 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: 30589444-7cda-4c5d-9c18-80f72bd2df4f

📥 Commits

Reviewing files that changed from the base of the PR and between a7fa3e2 and 33fe2a8.

📒 Files selected for processing (3)
  • cmd/service/param_validation.go
  • cmd/service/param_validation_test.go
  • cmd/service/service.go
💤 Files with no reviewable changes (1)
  • cmd/service/service.go

Comment thread cmd/service/param_validation.go
@xukuncx
xukuncx force-pushed the feat/1694214 branch 2 times, most recently from 209b88e to 335083c Compare June 3, 2026 12:44
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