Skip to content

feat: support wiki node target in markdown +create#883

Open
wittam-01 wants to merge 1 commit into
mainfrom
feat/markdown-create-wiki-target
Open

feat: support wiki node target in markdown +create#883
wittam-01 wants to merge 1 commit into
mainfrom
feat/markdown-create-wiki-target

Conversation

@wittam-01
Copy link
Copy Markdown
Collaborator

@wittam-01 wittam-01 commented May 14, 2026

Summary

Add --wiki-token support to markdown +create so Markdown files can be created directly under a Wiki node instead of only Drive folders. The implementation stays scoped to shortcuts/markdown and aligns the command behavior with existing Drive wiki-upload semantics.

Changes

  • Add --wiki-token support, target validation, and parent_type=wiki routing to markdown +create
  • Omit the fallback /file/<token> URL for wiki-hosted Markdown files, and update command help / skill reference docs
  • Add unit tests, markdown dry-run E2E coverage, and a wiki-parent live workflow test

Test Plan

  • Unit tests pass (go test ./shortcuts/markdown -count=1, go test ./tests/cli_e2e/markdown -count=1, make unit-test)
  • Manual local verification confirms the lark xxx command works as expected (./lark-cli markdown +create --as bot --wiki-token ... with both --content and --file, followed by ./lark-cli markdown +fetch)

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added support for creating Markdown files directly in Wiki nodes, complementing existing Drive folder support
    • Implemented mutual exclusivity validation between wiki and folder targets to prevent conflicts
    • Wiki-hosted Markdown files now properly omit the URL field in output (Wiki files lack independent URLs)
  • Documentation

    • Updated documentation with examples and detailed guidance for Markdown creation in Wiki nodes

Review Change Stack

Change-Id: Idb89464344599571cda3d27d136727553dcf0e7e
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR extends the markdown +create shortcut to support uploading Markdown files under Wiki nodes in addition to Drive folders. It introduces WikiToken field support, abstracts parent-type selection via a Target() method, enforces wiki/folder mutual exclusivity, updates all request payloads to use computed targets, wires the --wiki-token CLI flag, and provides comprehensive unit and E2E test coverage.

Changes

Wiki-parent markdown creation support

Layer / File(s) Summary
Wiki destination abstraction and target derivation
shortcuts/markdown/helpers.go
WikiToken field added to upload spec; Target() method introduced to derive parent-type (wiki or explorer) and parent-node based on which token is provided.
Wiki token validation and empty-flag detection
shortcuts/markdown/helpers.go
Validation expanded to reject whitespace-only wiki and folder tokens when flags changed, enforce mutual exclusivity between the two, and validate resource names for the provided token.
Dry-run and upload request payload updates
shortcuts/markdown/helpers.go
All markdown upload request bodies—single-part and multipart dry-runs, actual uploads, and overwrite flows—updated to use computed target parent-type and parent-node instead of hardcoded explorer values.
Markdown create shortcut flag and spec wiring
shortcuts/markdown/markdown_create.go
--wiki-token flag added to MarkdownCreate shortcut; WikiToken populated in validation/dry-run/execute specs; URL field in stdout now gated to explorer parent type only.
Unit test coverage for wiki markdown creation
shortcuts/markdown/markdown_test.go
Wiki-token validation constraints tested (non-empty, mutually exclusive, valid resource names); wiki-targeted markdown creation flows tested (dry-run output, single-part upload, multipart upload), each asserting wiki parent fields and absent URL in stdout.
User-facing documentation and examples
skills/lark-markdown/references/lark-markdown-create.md
Command description updated to include wiki-parent support; new example added demonstrating wiki-token usage; --wiki-token flag documented with mutual-exclusivity note and absence-of-URL behavior clarified.
E2E dry-run and workflow tests
tests/cli_e2e/markdown/markdown_dryrun_test.go, tests/cli_e2e/markdown/markdown_workflow_test.go
Dry-run mode verified to include wiki request fields and payload; empty wiki-token validation tested; end-to-end create/fetch/delete workflow tested with wiki cleanup helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#704: Both PRs modify the markdown shortcut implementation to extend the upload spec and payload logic, with this PR adding wiki-token support.
  • larksuite/cli#753: Both PRs modify URL field output in markdown +create stdout—this PR gates it conditionally on parent type, while the related PR adds it when buildable.

Suggested labels

size/M, domain/ccm

Suggested reviewers

  • liujinkun2025
  • fangshuyu-768

Poem

🐰 A wiki dwells where folders stood,
Now markdown finds it where it should,
Two tokens dance—exclusive pair—
Files float upward through the air,
No URL returned, but file_token bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 clearly and concisely summarizes the primary change: adding wiki node target support to markdown +create.
Description check ✅ Passed The description provides a clear summary, detailed changes, comprehensive test plan with checkboxes, and follows the required template structure.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/markdown-create-wiki-target

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/M Single-domain feat or fix with limited business impact label May 14, 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
shortcuts/markdown/helpers.go (1)

82-84: ⚡ Quick win

Clarify 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

📥 Commits

Reviewing files that changed from the base of the PR and between a27c636 and fdda288.

📒 Files selected for processing (6)
  • shortcuts/markdown/helpers.go
  • shortcuts/markdown/markdown_create.go
  • shortcuts/markdown/markdown_test.go
  • skills/lark-markdown/references/lark-markdown-create.md
  • tests/cli_e2e/markdown/markdown_dryrun_test.go
  • tests/cli_e2e/markdown/markdown_workflow_test.go

Comment on lines +143 to +145
result.AssertExitCode(t, 2)
assert.Contains(t, result.Stderr, "--wiki-token cannot be empty")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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.

Comment on lines +169 to +182
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)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.91%. Comparing base (37459b6) to head (fdda288).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/markdown/helpers.go 94.87% 2 Missing ⚠️
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.
📢 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@fdda28843c2ae764e87b09377c542dcc10d650af

🧩 Skill update

npx skills add larksuite/cli#feat/markdown-create-wiki-target -y -g

@evandance evandance added the domain/ccm PR touches the ccm domain label May 15, 2026
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