feat: support wiki node target in markdown +create#883
Conversation
Change-Id: Idb89464344599571cda3d27d136727553dcf0e7e
📝 WalkthroughWalkthroughThis PR extends the ChangesWiki-parent markdown creation support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
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 docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
shortcuts/markdown/helpers.go (1)
82-84: ⚡ Quick winClarify the error message for empty wiki-token.
The error message suggests "omit it to upload into Drive root folder," which is confusing when the user explicitly provided
--wiki-token. If they set--wiki-token, they intended wiki upload, not Drive folder upload.Consider revising to focus solely on wiki-token usage, e.g.,
"--wiki-token cannot be empty; provide a valid wiki node token or omit the flag entirely".📝 Proposed message refinement
if markdownFlagExplicitlyEmpty(runtime, "wiki-token") { - return common.FlagErrorf("--wiki-token cannot be empty; omit it to upload into Drive root folder or pass a wiki node token") + return common.FlagErrorf("--wiki-token cannot be empty; provide a valid wiki node token or omit the flag entirely") }🤖 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 `@shortcuts/markdown/helpers.go` around lines 82 - 84, Update the error text emitted when markdownFlagExplicitlyEmpty(runtime, "wiki-token") is true: replace the confusing Drive-root suggestion with a focused message such as "--wiki-token cannot be empty; provide a valid wiki node token or omit the flag entirely" so users who passed --wiki-token understand they must supply a non-empty token or remove the flag; change the string passed to common.FlagErrorf in that conditional 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.
Inline comments:
In `@tests/cli_e2e/markdown/markdown_dryrun_test.go`:
- Around line 143-145: The test currently asserts the exit code via
result.AssertExitCode(t, 2) but only checks result.Stderr for the validation
message; update the assertion to verify the combined output (result.Stdout +
result.Stderr) contains the expected text "--wiki-token cannot be empty" so
validate-stage dry-run errors emitted to stdout JSON are caught; keep the
exit-code assertion (result.AssertExitCode) and replace assert.Contains(t,
result.Stderr, ...) with assert.Contains(t, result.Stdout+result.Stderr,
"--wiki-token cannot be empty") referencing the same result variable in
markdown_dryrun_test.go.
In `@tests/cli_e2e/markdown/markdown_workflow_test.go`:
- Around line 169-182: The test currently only logs when both cleanup attempts
fail, leaving artifacts; replace the final parentT.Logf call with a test failure
so the E2E test fails if neither identity could delete the file. Specifically,
in the cleanup loop around clie2e.RunCmd (using variables identity, cleanupCtx,
cleanupCancel and function clie2e.RunCmd) ensure cleanupCancel is still called
and then call parentT.Fatalf (or equivalent fail method on parentT) with a
message that includes fileToken to fail the test when both delete attempts
return non-zero/err.
---
Nitpick comments:
In `@shortcuts/markdown/helpers.go`:
- Around line 82-84: Update the error text emitted when
markdownFlagExplicitlyEmpty(runtime, "wiki-token") is true: replace the
confusing Drive-root suggestion with a focused message such as "--wiki-token
cannot be empty; provide a valid wiki node token or omit the flag entirely" so
users who passed --wiki-token understand they must supply a non-empty token or
remove the flag; change the string passed to common.FlagErrorf in that
conditional accordingly.
🪄 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: b3579146-97af-48cc-80e7-103cd8ff22a2
📒 Files selected for processing (6)
shortcuts/markdown/helpers.goshortcuts/markdown/markdown_create.goshortcuts/markdown/markdown_test.goskills/lark-markdown/references/lark-markdown-create.mdtests/cli_e2e/markdown/markdown_dryrun_test.gotests/cli_e2e/markdown/markdown_workflow_test.go
| result.AssertExitCode(t, 2) | ||
| assert.Contains(t, result.Stderr, "--wiki-token cannot be empty") | ||
| } |
There was a problem hiding this comment.
Assert validation errors from combined stdout/stderr.
For validate-stage dry-run rejects, error details can be emitted in stdout JSON; asserting only result.Stderr can make this test flaky.
Suggested fix
require.NoError(t, err)
result.AssertExitCode(t, 2)
- assert.Contains(t, result.Stderr, "--wiki-token cannot be empty")
+ assert.Contains(t, result.Stdout+result.Stderr, "--wiki-token cannot be empty")Based on learnings: validate-stage rejects in tests/cli_e2e should assert non-zero exit and verify the message from result.Stdout + result.Stderr.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| result.AssertExitCode(t, 2) | |
| assert.Contains(t, result.Stderr, "--wiki-token cannot be empty") | |
| } | |
| result.AssertExitCode(t, 2) | |
| assert.Contains(t, result.Stdout+result.Stderr, "--wiki-token cannot be empty") | |
| } |
🤖 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/markdown/markdown_dryrun_test.go` around lines 143 - 145, The
test currently asserts the exit code via result.AssertExitCode(t, 2) but only
checks result.Stderr for the validation message; update the assertion to verify
the combined output (result.Stdout + result.Stderr) contains the expected text
"--wiki-token cannot be empty" so validate-stage dry-run errors emitted to
stdout JSON are caught; keep the exit-code assertion (result.AssertExitCode) and
replace assert.Contains(t, result.Stderr, ...) with assert.Contains(t,
result.Stdout+result.Stderr, "--wiki-token cannot be empty") referencing the
same result variable in markdown_dryrun_test.go.
| for _, identity := range []string{"bot", "user"} { | ||
| cleanupCtx, cleanupCancel := clie2e.CleanupContext() | ||
| result, err := clie2e.RunCmd(cleanupCtx, clie2e.Request{ | ||
| Args: request.Args, | ||
| DefaultAs: identity, | ||
| }) | ||
| cleanupCancel() | ||
| if err == nil && result != nil && result.ExitCode == 0 { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| parentT.Logf("cleanup skipped: could not delete wiki-hosted markdown file %s with either bot or user identity", fileToken) | ||
| } |
There was a problem hiding this comment.
Fail when both cleanup identities cannot delete the created file.
If both delete attempts fail, the test still passes and leaves artifacts behind. This breaks the self-contained live E2E contract.
Suggested fix
- parentT.Logf("cleanup skipped: could not delete wiki-hosted markdown file %s with either bot or user identity", fileToken)
+ parentT.Fatalf("cleanup failed: could not delete wiki-hosted markdown file %s with either bot or user identity", fileToken)As per coding guidelines: live E2E tests must be self-contained (create->use->cleanup) for new behavior flows.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for _, identity := range []string{"bot", "user"} { | |
| cleanupCtx, cleanupCancel := clie2e.CleanupContext() | |
| result, err := clie2e.RunCmd(cleanupCtx, clie2e.Request{ | |
| Args: request.Args, | |
| DefaultAs: identity, | |
| }) | |
| cleanupCancel() | |
| if err == nil && result != nil && result.ExitCode == 0 { | |
| return | |
| } | |
| } | |
| parentT.Logf("cleanup skipped: could not delete wiki-hosted markdown file %s with either bot or user identity", fileToken) | |
| } | |
| for _, identity := range []string{"bot", "user"} { | |
| cleanupCtx, cleanupCancel := clie2e.CleanupContext() | |
| result, err := clie2e.RunCmd(cleanupCtx, clie2e.Request{ | |
| Args: request.Args, | |
| DefaultAs: identity, | |
| }) | |
| cleanupCancel() | |
| if err == nil && result != nil && result.ExitCode == 0 { | |
| return | |
| } | |
| } | |
| parentT.Fatalf("cleanup failed: could not delete wiki-hosted markdown file %s with either bot or user identity", fileToken) | |
| } |
🤖 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/markdown/markdown_workflow_test.go` around lines 169 - 182, The
test currently only logs when both cleanup attempts fail, leaving artifacts;
replace the final parentT.Logf call with a test failure so the E2E test fails if
neither identity could delete the file. Specifically, in the cleanup loop around
clie2e.RunCmd (using variables identity, cleanupCtx, cleanupCancel and function
clie2e.RunCmd) ensure cleanupCancel is still called and then call parentT.Fatalf
(or equivalent fail method on parentT) with a message that includes fileToken to
fail the test when both delete attempts return non-zero/err.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #883 +/- ##
==========================================
+ Coverage 65.89% 65.91% +0.02%
==========================================
Files 518 518
Lines 48945 48975 +30
==========================================
+ Hits 32254 32284 +30
Misses 13921 13921
Partials 2770 2770 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@fdda28843c2ae764e87b09377c542dcc10d650af🧩 Skill updatenpx skills add larksuite/cli#feat/markdown-create-wiki-target -y -g |
Summary
Add
--wiki-tokensupport tomarkdown +createso Markdown files can be created directly under a Wiki node instead of only Drive folders. The implementation stays scoped toshortcuts/markdownand aligns the command behavior with existing Drive wiki-upload semantics.Changes
--wiki-tokensupport, target validation, andparent_type=wikirouting tomarkdown +create/file/<token>URL for wiki-hosted Markdown files, and update command help / skill reference docsTest Plan
go test ./shortcuts/markdown -count=1,go test ./tests/cli_e2e/markdown -count=1,make unit-test)lark xxxcommand works as expected (./lark-cli markdown +create --as bot --wiki-token ...with both--contentand--file, followed by./lark-cli markdown +fetch)Related Issues
Summary by CodeRabbit
New Features
Documentation