fix(docs): reject legacy create flags in v2#1129
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds 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. ChangesV2 Create Flag Validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
73d0184 to
747b6dc
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/cli_e2e/docs/docs_create_dryrun_test.go (1)
20-46: ⚡ Quick winConsider adding test cases for remaining v1-only flags.
The test table covers
--markdownand--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-spacewould 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
📒 Files selected for processing (4)
shortcuts/doc/docs_create_test.goshortcuts/doc/docs_create_v2.gotests/cli_e2e/docs/coverage.mdtests/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
747b6dc to
944bc40
Compare
|
Updated the PR to address the review setup issues:
The remaining CLA step may still require signing via CLA Assistant if this account has not signed it before. |
Summary
docs +createsupports 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-nodeflag 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-runThe emitted dry-run body contained
contentandformat, but noparent_token. Similarly,--api-version v2 --markdown ...failed with--content is required, which did not explain that--markdownbelongs to the v1 create path.Changes
docs +createflags on the v2 create path:--markdown,--title,--folder-token,--wiki-node, and--wiki-space.--content,--doc-format markdown,--parent-token, or--parent-positionas appropriate.Test Plan
make buildmake unit-testgo vet ./...gofmt -l .produced no outputgo mod tidyproduced nogo.mod/go.sumdiffgo 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=1go test ./tests/cli_e2e/docs -run TestDocs_CreateV2RejectsLegacyFlagsDryRun -count=1go test ./shortcuts/...Related Issues
Summary by CodeRabbit
Bug Fixes
Tests
Documentation