Skip to content

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

Merged
wittam-01 merged 1 commit into
mainfrom
feat/markdown-create-wiki-target
May 20, 2026
Merged

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

Conversation

@wittam-01

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

Copy link
Copy Markdown
Collaborator

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

    • Create Markdown files under Wiki nodes; dry-run and upload flows include wiki parent info and omit a file URL for Wiki-hosted files.
  • Bug Fixes

    • Stronger flag validation: rejects empty/whitespace tokens, disallows supplying both wiki and folder targets, and validates resource names for the chosen target.
  • Documentation

    • Updated docs and examples to show --wiki-token and its mutual-exclusivity with --folder-token.
  • Tests

    • Added unit and E2E tests covering wiki-target validation, dry-run payloads, uploads, and workflow.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

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

Adds WikiToken support to markdown +create, derives parent_type/parent_node via Target(), enforces mutual exclusivity with folder-token, updates dry-run/upload payloads to use the computed target, wires the CLI flag, and adds unit, E2E tests, and docs.

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 emitted only for explorer parent type.
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; --folder-token documented as mutually exclusive with --wiki-token; absence-of-URL behavior for wiki-hosted files documented.
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 best-effort wiki cleanup helper.

Sequence Diagram

sequenceDiagram
  participant CLI as CLI (user)
  participant Shortcut as MarkdownCreate shortcut
  participant Spec as markdownUploadSpec.Target()
  participant API as Upload API (upload_all / upload_prepare)
  participant Storage as Storage (Drive or Wiki)

  CLI->>Shortcut: invoke +create with flags (--file, --folder-token, --wiki-token)
  Shortcut->>Spec: construct spec with FolderToken/WikiToken
  Spec->>API: include parent_type/parent_node in request body
  API->>Storage: store file under parent_type/parent_node
  Storage-->>API: return file_token (wiki: no /file/<token> URL)
  API-->>Shortcut: response payload
  Shortcut-->>CLI: print output (omit url for wiki)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#753: Related changes to markdown +create output handling and conditional url emission.
  • larksuite/cli#611: Prior PR adding --wiki-token style support and payload routing to parent_type=wiki.
  • larksuite/cli#704: Earlier work introducing the shortcuts/markdown upload implementation extended by this PR.

Suggested labels

domain/ccm

Suggested reviewers

  • fangshuyu-768
  • liujinkun2025

Poem

🐰 I hopped through flags both kind and new,
A Wiki token in my paw I drew,
Parent_type chosen, careful and sly,
Uploads land where wiki pages lie,
No URL returned — just a quiet file_token, woo-hoo!

🚥 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 describes the main feature addition: wiki node target support in markdown +create.
Description check ✅ Passed The description includes all required sections: Summary, Changes, Test Plan, and Related Issues, with concrete details and verified test execution.
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

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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

@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: 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 thread tests/cli_e2e/markdown/markdown_dryrun_test.go
Comment thread tests/cli_e2e/markdown/markdown_workflow_test.go
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.66%. Comparing base (69c3448) to head (95f569d).
⚠️ Report is 5 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   67.58%   67.66%   +0.07%     
==========================================
  Files         575      576       +1     
  Lines       54269    54510     +241     
==========================================
+ Hits        36679    36885     +206     
- Misses      14548    14566      +18     
- Partials     3042     3059      +17     

☔ 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

github-actions Bot commented May 14, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@95f569df1b772e5c23981455abfb34153ecaa1b8

🧩 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
@wittam-01
wittam-01 force-pushed the feat/markdown-create-wiki-target branch from fdda288 to 3f359ec Compare May 20, 2026 04:01
@github-actions github-actions Bot removed the domain/ccm PR touches the ccm domain label May 20, 2026
@wittam-01
wittam-01 force-pushed the feat/markdown-create-wiki-target branch 2 times, most recently from 8c83f3a to d23181a Compare May 20, 2026 07:14

@fangshuyu-768 fangshuyu-768 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR! Overall the implementation is clean and well-tested. I have a few comments below — two are worth investigating before merge, the rest are minor suggestions.

Comment thread shortcuts/markdown/helpers.go
Comment thread shortcuts/markdown/markdown_create.go
Comment thread shortcuts/markdown/helpers.go
Comment thread tests/cli_e2e/markdown/markdown_workflow_test.go
Change-Id: Idb89464344599571cda3d27d136727553dcf0e7e
@wittam-01
wittam-01 force-pushed the feat/markdown-create-wiki-target branch from d23181a to 95f569d Compare May 20, 2026 08:47

@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 (2)
shortcuts/markdown/markdown_test.go (2)

555-556: ⚡ Quick win

Avoid using production constants as the expected value in these assertions.

Using markdownUploadParentTypeWiki in the expected side couples the test oracle to implementation details; if the constant drifts, tests can still pass while the API contract breaks. Prefer asserting the literal wire value "wiki".

Suggested diff
-	if got := body.Fields["parent_type"]; got != markdownUploadParentTypeWiki {
-		t.Fatalf("parent_type = %q, want %q", got, markdownUploadParentTypeWiki)
+	if got := body.Fields["parent_type"]; got != "wiki" {
+		t.Fatalf("parent_type = %q, want %q", got, "wiki")
 	}
...
-	if got := body["parent_type"]; got != markdownUploadParentTypeWiki {
-		t.Fatalf("parent_type = %#v, want %q", got, markdownUploadParentTypeWiki)
+	if got := body["parent_type"]; got != "wiki" {
+		t.Fatalf("parent_type = %#v, want %q", got, "wiki")
 	}

Also applies to: 746-747

🤖 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/markdown_test.go` around lines 555 - 556, Replace the use
of the production constant markdownUploadParentTypeWiki in the test assertions
with the literal wire value "wiki" so the test oracle verifies the actual API
contract; specifically update the comparisons that check
body.Fields["parent_type"] (and the other occurrence that currently asserts
against markdownUploadParentTypeWiki) to use the string "wiki" as the expected
value.

561-563: ⚡ Quick win

Add a positive stdout assertion in the wiki success tests.

These checks only verify URL absence. Add a positive assertion (e.g., file_token exists) so empty/partial stdout regressions don’t pass.

Suggested diff
 	if strings.Contains(stdout.String(), `"url":`) {
 		t.Fatalf("stdout should omit url for wiki-hosted markdown files: %s", stdout.String())
 	}
+	if !strings.Contains(stdout.String(), `"file_token": "box_md_create_wiki"`) {
+		t.Fatalf("stdout missing file_token: %s", stdout.String())
+	}
...
 	if strings.Contains(stdout.String(), `"url":`) {
 		t.Fatalf("stdout should omit url for wiki-hosted multipart markdown files: %s", stdout.String())
 	}
+	if !strings.Contains(stdout.String(), `"file_token": "box_md_multipart_wiki"`) {
+		t.Fatalf("stdout missing file_token: %s", stdout.String())
+	}

Also applies to: 752-754

🤖 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/markdown_test.go` around lines 561 - 563, The test
currently only asserts that stdout does not contain `"url":` which can miss
empty/partial output regressions; update the wiki success tests (the block that
checks stdout via stdout.String() and uses strings.Contains) to also assert a
positive indicator is present (for example, verify stdout contains
`"file_token"` or another expected token) so the test fails on empty output;
make the same change to the second occurrence of the same pattern (the other
wiki success test around the later check currently at lines 752-754).
🤖 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 `@shortcuts/markdown/markdown_test.go`:
- Around line 555-556: Replace the use of the production constant
markdownUploadParentTypeWiki in the test assertions with the literal wire value
"wiki" so the test oracle verifies the actual API contract; specifically update
the comparisons that check body.Fields["parent_type"] (and the other occurrence
that currently asserts against markdownUploadParentTypeWiki) to use the string
"wiki" as the expected value.
- Around line 561-563: The test currently only asserts that stdout does not
contain `"url":` which can miss empty/partial output regressions; update the
wiki success tests (the block that checks stdout via stdout.String() and uses
strings.Contains) to also assert a positive indicator is present (for example,
verify stdout contains `"file_token"` or another expected token) so the test
fails on empty output; make the same change to the second occurrence of the same
pattern (the other wiki success test around the later check currently at lines
752-754).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 19ef8ae6-2865-45c7-b752-ddba6804aa56

📥 Commits

Reviewing files that changed from the base of the PR and between d23181a and 95f569d.

📒 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
✅ Files skipped from review due to trivial changes (1)
  • skills/lark-markdown/references/lark-markdown-create.md

@wittam-01
wittam-01 merged commit c02a38f into main May 20, 2026
22 checks passed
@wittam-01
wittam-01 deleted the feat/markdown-create-wiki-target branch May 20, 2026 09:03
@liangshuo-1 liangshuo-1 mentioned this pull request May 20, 2026
2 tasks
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
Change-Id: Idb89464344599571cda3d27d136727553dcf0e7e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants