Skip to content

fix(docs): reject legacy create flags in v2#1129

Open
zhouhuan327 wants to merge 1 commit into
larksuite:mainfrom
zhouhuan327:codex/validate-docs-create-v2-flags
Open

fix(docs): reject legacy create flags in v2#1129
zhouhuan327 wants to merge 1 commit into
larksuite:mainfrom
zhouhuan327:codex/validate-docs-create-v2-flags

Conversation

@zhouhuan327
Copy link
Copy Markdown

@zhouhuan327 zhouhuan327 commented May 27, 2026

Summary

docs +create supports both the legacy v1 MCP flag set and the v2 OpenAPI flag set. When the v2 path is selected, passing v1-only flags should fail early instead of being accepted or producing a less actionable validation error.

Reproduction

Before this change, this v2 dry-run accepted the legacy --wiki-node flag but silently omitted the intended parent placement from the request body:

lark-cli docs +create \
  --api-version v2 \
  --content '<title>x</title>' \
  --wiki-node wikcn_legacy_node \
  --dry-run

The emitted dry-run body contained content and format, but no parent_token. Similarly, --api-version v2 --markdown ... failed with --content is required, which did not explain that --markdown belongs to the v1 create path.

Changes

  • Reject v1-only docs +create flags on the v2 create path: --markdown, --title, --folder-token, --wiki-node, and --wiki-space.
  • Add migration hints to the validation errors, pointing users to --content, --doc-format markdown, --parent-token, or --parent-position as appropriate.
  • Add unit coverage for the v2 validation behavior.
  • Add docs dry-run E2E coverage and update the docs E2E coverage inventory.

Test Plan

  • make build
  • make unit-test
  • go vet ./...
  • gofmt -l . produced no output
  • go mod tidy produced no go.mod / go.sum diff
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main (0 issues; emitted the existing gocritic disabled-check warning)
  • go test ./shortcuts/doc -run TestDocsCreateV2RejectsV1OnlyFlags -count=1
  • go test ./tests/cli_e2e/docs -run TestDocs_CreateV2RejectsLegacyFlagsDryRun -count=1
  • go test ./shortcuts/...

Related Issues

  • None

Summary by CodeRabbit

  • Bug Fixes

    • v2 create commands now reject legacy v1-only flags and display clear, per-flag guidance pointing to v2 alternatives.
  • Tests

    • Added unit and end-to-end tests validating v2 flag rejection, dry-run behavior, exit codes, and that no API calls occur when validation fails.
  • Documentation

    • Updated test coverage notes to include the v2 dry-run legacy-flag rejection scenario.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 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: 1e6ee2fc-0958-4670-a200-1e6794ec8762

📥 Commits

Reviewing files that changed from the base of the PR and between 747b6dc and 944bc40.

📒 Files selected for processing (4)
  • shortcuts/doc/docs_create_test.go
  • shortcuts/doc/docs_create_v2.go
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_create_dryrun_test.go
✅ Files skipped from review due to trivial changes (1)
  • tests/cli_e2e/docs/coverage.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • shortcuts/doc/docs_create_test.go
  • tests/cli_e2e/docs/docs_create_dryrun_test.go
  • shortcuts/doc/docs_create_v2.go

📝 Walkthrough

Walkthrough

Adds early validation to the v2 docs create flow rejecting v1-only flags, plus a unit test, an end-to-end dry-run test with helpers that assert no API calls on validation failure, and corresponding coverage documentation updates.

Changes

V2 Create Flag Validation

Layer / File(s) Summary
V1 flag rejection validation for v2 create
shortcuts/doc/docs_create_v2.go
rejectV1CreateFlagsForV2 helper defines v1-exclusive flags and guidance, checks the runtime context, and returns FlagErrorf if any v1-only flag is present; integrated into validateCreateV2 as an early validation step.
V2 validation test for v1-only flag rejection
shortcuts/doc/docs_create_test.go
TestDocsCreateV2RejectsV1OnlyFlags table-driven unit test exercises each v1-only flag (--markdown, --wiki-node, --title, --folder-token, --wiki-space) with --api-version v2 and verifies specific error messages and --api-version v2 guidance.
E2E dry-run tests and helpers
tests/cli_e2e/docs/docs_create_dryrun_test.go
E2E test TestDocs_CreateV2RejectsLegacyFlagsDryRun runs docs +create --api-version v2 --dry-run for legacy flag scenarios, asserts exit code 2, verifies validation error text, and checks that no API calls were made; includes setDocsDryRunEnv and docsValidationErrorMessage helpers.
Docs coverage update
tests/cli_e2e/docs/coverage.md
Adds TestDocs_CreateV2RejectsLegacyFlagsDryRun to coverage summary and updates the docs +create command table to note dry-run validation prevents API calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • fangshuyu-768
  • SunPeiYang996

Poem

🐰 I sniff the flags both old and new,
I tap my paw and say "Not you!"
V2's strict path I guard with glee,
Tests and docs sing validation's decree. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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 'fix(docs): reject legacy create flags in v2' clearly and concisely summarizes the main change: rejecting v1-only flags in the v2 create path.
Description check ✅ Passed The description includes all required template sections: Summary (explaining the motivation), Changes (listing main modifications), and Test Plan (with verified checkmarks). The description is comprehensive and complete.
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 domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels May 27, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 27, 2026

CLA assistant check
All committers have signed the CLA.

@zhouhuan327 zhouhuan327 force-pushed the codex/validate-docs-create-v2-flags branch from 73d0184 to 747b6dc Compare May 27, 2026 08:17
@zhouhuan327 zhouhuan327 changed the title Validate legacy flags for docs create v2 fix(docs): reject legacy create flags in v2 May 27, 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)
tests/cli_e2e/docs/docs_create_dryrun_test.go (1)

20-46: ⚡ Quick win

Consider adding test cases for remaining v1-only flags.

The test table covers --markdown and --wiki-node, but the PR description mentions five v1-only flags: --markdown, --title, --folder-token, --wiki-node, and --wiki-space. Adding cases for --title, --folder-token, and --wiki-space would provide more comprehensive coverage and ensure all migration hints are exercised.

📋 Suggested additional test cases
 		{
 			name: "wiki node",
 			args: []string{
 				"docs", "+create",
 				"--api-version", "v2",
 				"--content", "<title>内容</title><p>正文</p>",
 				"--wiki-node", "wikcn_legacy_node",
 				"--dry-run",
 			},
 			wantErr: "use --parent-token",
 		},
+		{
+			name: "title",
+			args: []string{
+				"docs", "+create",
+				"--api-version", "v2",
+				"--title", "Legacy Title",
+				"--content", "content",
+				"--dry-run",
+			},
+			wantErr: "--title",  // adjust to match actual migration hint
+		},
+		{
+			name: "folder token",
+			args: []string{
+				"docs", "+create",
+				"--api-version", "v2",
+				"--content", "content",
+				"--folder-token", "fldcn_legacy",
+				"--dry-run",
+			},
+			wantErr: "use --parent-token",
+		},
+		{
+			name: "wiki space",
+			args: []string{
+				"docs", "+create",
+				"--api-version", "v2",
+				"--content", "content",
+				"--wiki-space", "12345",
+				"--dry-run",
+			},
+			wantErr: "use --parent-token",
+		},
 	}
🤖 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/docs/docs_create_dryrun_test.go` around lines 20 - 46, Add
table-driven tests to the existing tests slice in docs_create_dryrun_test.go
covering the remaining v1-only flags: create entries named e.g. "title",
"folder-token", and "wiki-space" that pass args including "docs", "+create",
"--api-version", "v2", "--content" or the flag under test (e.g. "--title",
"--folder-token", "--wiki-space"), and "--dry-run"; set each entry's wantErr to
the expected migration hint string (parallel to existing wantErr values like
"use --content with --doc-format markdown" and "use --parent-token") so the test
harness that iterates over tests will validate those migration messages for the
--title, --folder-token, and --wiki-space flags.
🤖 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 `@tests/cli_e2e/docs/docs_create_dryrun_test.go`:
- Around line 20-46: Add table-driven tests to the existing tests slice in
docs_create_dryrun_test.go covering the remaining v1-only flags: create entries
named e.g. "title", "folder-token", and "wiki-space" that pass args including
"docs", "+create", "--api-version", "v2", "--content" or the flag under test
(e.g. "--title", "--folder-token", "--wiki-space"), and "--dry-run"; set each
entry's wantErr to the expected migration hint string (parallel to existing
wantErr values like "use --content with --doc-format markdown" and "use
--parent-token") so the test harness that iterates over tests will validate
those migration messages for the --title, --folder-token, and --wiki-space
flags.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d31d36ea-06e6-4051-89c9-6ee2b7fd48a3

📥 Commits

Reviewing files that changed from the base of the PR and between 73d0184 and 747b6dc.

📒 Files selected for processing (4)
  • shortcuts/doc/docs_create_test.go
  • shortcuts/doc/docs_create_v2.go
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_create_dryrun_test.go
✅ Files skipped from review due to trivial changes (1)
  • tests/cli_e2e/docs/coverage.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/doc/docs_create_test.go
  • shortcuts/doc/docs_create_v2.go

@zhouhuan327 zhouhuan327 force-pushed the codex/validate-docs-create-v2-flags branch from 747b6dc to 944bc40 Compare May 27, 2026 08:22
@zhouhuan327
Copy link
Copy Markdown
Author

Updated the PR to address the review setup issues:

  • Amended the commit author/committer from zh <sean> to the GitHub account email so CLA Assistant can associate the commit with @zhouhuan327.
  • Expanded the docs dry-run E2E table to cover all v1-only flags rejected by the v2 create path.
  • Re-ran the focused checks:
    • go test ./tests/cli_e2e/docs -run TestDocs_CreateV2RejectsLegacyFlagsDryRun -count=1
    • go test ./shortcuts/doc -run TestDocsCreateV2RejectsV1OnlyFlags -count=1
    • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main (0 issues, same existing gocritic warning)

The remaining CLA step may still require signing via CLA Assistant if this account has not signed it before.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.24%. Comparing base (e98471c) to head (944bc40).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1129      +/-   ##
==========================================
+ Coverage   68.22%   68.24%   +0.02%     
==========================================
  Files         617      617              
  Lines       57192    57192              
==========================================
+ Hits        39017    39029      +12     
+ Misses      14945    14933      -12     
  Partials     3230     3230              

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

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add zhouhuan327/cli#codex/validate-docs-create-v2-flags -y -g

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

Labels

domain/ccm PR touches the ccm 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.

2 participants