Skip to content

feat: support wiki node targets in drive +upload#611

Open
wittam-01 wants to merge 1 commit intomainfrom
feat/drive-upload-wiki-target
Open

feat: support wiki node targets in drive +upload#611
wittam-01 wants to merge 1 commit intomainfrom
feat/drive-upload-wiki-target

Conversation

@wittam-01
Copy link
Copy Markdown
Collaborator

@wittam-01 wittam-01 commented Apr 22, 2026

Summary

Add wiki-target upload support to drive +upload by introducing --wiki-token and mapping uploads to parent_type=wiki / parent_node=<wiki_token>. This keeps existing folder/root behavior unchanged while making wiki uploads available through the same shortcut.

Changes

  • Add --wiki-token to drive +upload, make it mutually exclusive with --folder-token, and route both single-part and multipart upload flows through a shared target resolver.
  • Update the lark-drive upload guidance to document folder/root/wiki targets and the parent_type=wiki behavior.
  • Add unit coverage for wiki upload request shapes and a dry-run E2E test for drive +upload --wiki-token.

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark xxx command works as expected
  • go test ./shortcuts/drive
  • go test ./tests/cli_e2e/drive -run 'TestDriveUploadDryRun_WikiTarget'
  • gofmt -l shortcuts/drive/drive_upload.go shortcuts/drive/drive_io_test.go tests/cli_e2e/drive/drive_upload_dryrun_test.go

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added --wiki-token to target uploads to wiki nodes; omitting tokens uploads to Drive root.
  • Improvements

    • Enforces mutual exclusivity of --folder-token/--wiki-token, rejects empty/whitespace tokens, and trims folder/wiki tokens.
    • Dry-run shows resolved destination fields (parent_type/parent_node) and progress displays the resolved destination label.
  • Tests

    • Added dry-run and e2e tests, plus multipart decoding helpers to validate wiki-target behavior.
  • Documentation

    • Updated upload docs and examples to cover folder vs. wiki targeting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

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 --wiki-token support for Drive uploads (mutually exclusive with --folder-token), centralizes filename/token handling into a spec/target, updates DryRun/Execute and upload helpers to populate parent_type/parent_node, and adds tests, multipart-decoding helpers, and documentation updates for wiki-target behavior.

Changes

Cohort / File(s) Summary
Drive Upload Implementation
shortcuts/drive/drive_upload.go
Add --wiki-token flag; introduce driveUploadSpec/driveUploadTarget; trim/validate tokens; enforce mutual exclusivity and reject explicit empty tokens; refactor DryRun/Execute and upload helpers to use parent_type/parent_node and derived file_name.
Drive Upload Tests & Helpers
shortcuts/drive/drive_io_test.go
Add tests for large/small upload flows with wiki targeting; dry-run assertions; trimming/validation and mutual-exclusion rejection tests; add multipart decoding helpers (capturedDriveMultipart, decodeDriveMultipartBody).
E2E Dry-run Tests
tests/cli_e2e/drive/drive_upload_dryrun_test.go
Add dry-run test validating wiki-target request shape and a test rejecting empty --wiki-token; include helper to set dry-run env config.
Documentation & References
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-upload.md
Document --wiki-token usage and mutual-exclusivity rules; update examples and upload_prepare --data mapping describing parent_type/parent_node semantics for Drive vs wiki.
Coverage Report
tests/cli_e2e/drive/coverage.md
Update coverage metrics and note that dry-run test covers wiki-target request shape while live upload remains untested.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(200,200,255,0.5)
    actor CLI
  end
  rect rgba(200,255,200,0.5)
    participant Runtime
  end
  rect rgba(255,200,200,0.5)
    participant DriveAPI
  end

  CLI->>Runtime: parse flags (--file, --folder-token, --wiki-token, --name, --dry-run)
  Runtime->>Runtime: build driveUploadSpec → derive driveUploadTarget {file_name, parent_type, parent_node}
  Runtime->>DriveAPI: upload_prepare (send parent_type, parent_node, file_name)
  DriveAPI-->>Runtime: upload_prepare response (upload_all / part URLs)
  Runtime->>DriveAPI: upload_all / upload_part(s) (multipart or small upload with file bytes and parent fields)
  DriveAPI-->>Runtime: upload_finish
  Runtime->>CLI: display progress and result (includes destination label)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • fangshuyu-768
  • zgz2048

Poem

🐰 I trimmed the tokens with a careful hop,
parent_type set, parent_node on top.
Multipart crumbs and tiny-file treats,
Wiki or folder — the upload completes.
Hop, mask, and log — the job's done neat. 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% 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 main change: adding wiki node target support to the drive +upload command.
Description check ✅ Passed The description covers all required sections (Summary, Changes, Test Plan, Related Issues) with sufficient detail about motivation, implementation approach, and verification strategy.
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
  • Commit unit tests in branch feat/drive-upload-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 domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths labels Apr 22, 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: 1

🧹 Nitpick comments (1)
tests/cli_e2e/drive/drive_upload_dryrun_test.go (1)

39-40: Tighten the "wiki" assertion.

assert.Contains(t, output, "wiki") is already satisfied by the wiki token itself (wikcnDryRunUploadTarget) and by the command surface strings, so it does not actually prove parent_type="wiki" was emitted. Consider asserting on a more specific substring, e.g. the pair "parent_type": "wiki" (or whatever shape the dry-run JSON uses), so the test catches regressions where parent_type silently becomes explorer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/cli_e2e/drive/drive_upload_dryrun_test.go` around lines 39 - 40, The
test currently checks output for the generic substring "wiki" which can be
satisfied by tokens like "wikcnDryRunUploadTarget"; update the assertion to
assert the exact dry-run JSON key/value so it proves parent_type was emitted as
wiki—for example replace or add an assertion that output contains the more
specific substring `"parent_type": "wiki"` (matching the dry-run JSON format
emitted by the upload command) and keep the existing check for
"wikcnDryRunUploadTarget" if needed for other coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/cli_e2e/drive/drive_upload_dryrun_test.go`:
- Around line 43-48: Update setDriveDryRunConfigEnv to also isolate config state
by setting LARKSUITE_CLI_CONFIG_DIR (use t.Setenv inside
setDriveDryRunConfigEnv) so the dry-run test does not read real disk configs,
and strengthen the assertion in the drive dry-run test (where assert.Contains(t,
output, "wiki") is used) to check the explicit parent_type value (e.g., assert
that the output contains the JSON key/value for parent_type:"wiki" or equivalent
exact substring) to avoid false positives from tokens like
wikcnDryRunUploadTarget.

---

Nitpick comments:
In `@tests/cli_e2e/drive/drive_upload_dryrun_test.go`:
- Around line 39-40: The test currently checks output for the generic substring
"wiki" which can be satisfied by tokens like "wikcnDryRunUploadTarget"; update
the assertion to assert the exact dry-run JSON key/value so it proves
parent_type was emitted as wiki—for example replace or add an assertion that
output contains the more specific substring `"parent_type": "wiki"` (matching
the dry-run JSON format emitted by the upload command) and keep the existing
check for "wikcnDryRunUploadTarget" if needed for other coverage.
🪄 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: e6d67fd5-345f-41d5-afbf-2ae2cc3243fc

📥 Commits

Reviewing files that changed from the base of the PR and between 543a836 and 66bc689.

📒 Files selected for processing (7)
  • shortcuts/drive/drive_io_test.go
  • shortcuts/drive/drive_upload.go
  • skill-template/domains/drive.md
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go

Comment thread tests/cli_e2e/drive/drive_upload_dryrun_test.go
@wittam-01 wittam-01 force-pushed the feat/drive-upload-wiki-target branch from 66bc689 to 44caba2 Compare April 22, 2026 10:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.17%. Comparing base (543a836) to head (07052fa).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #611      +/-   ##
==========================================
+ Coverage   59.94%   61.17%   +1.23%     
==========================================
  Files         405      428      +23     
  Lines       42673    45248    +2575     
==========================================
+ Hits        25580    27681    +2101     
- Misses      15084    15455     +371     
- Partials     2009     2112     +103     

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

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/drive/drive_upload.go`:
- Around line 40-46: The newDriveUploadSpec currently trims all inputs; remove
strings.TrimSpace for FilePath and Name so that newDriveUploadSpec returns
FilePath: runtime.Str("file") and Name: runtime.Str("name") verbatim, while
keeping TrimSpace for FolderToken and WikiToken (i.e., FolderToken:
strings.TrimSpace(runtime.Str("folder-token")) and WikiToken:
strings.TrimSpace(runtime.Str("wiki-token"))) so tokens stay normalized but
user-supplied file paths and explicit upload names are preserved; update the
function body in newDriveUploadSpec and ensure driveUploadSpec consumers expect
raw values.
🪄 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: 1aab9b83-769c-42db-93cc-f7d121a88184

📥 Commits

Reviewing files that changed from the base of the PR and between 66bc689 and 44caba2.

📒 Files selected for processing (6)
  • shortcuts/drive/drive_io_test.go
  • shortcuts/drive/drive_upload.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go
✅ Files skipped from review due to trivial changes (1)
  • shortcuts/drive/drive_io_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • skills/lark-drive/references/lark-drive-upload.md
  • tests/cli_e2e/drive/coverage.md
  • skills/lark-drive/SKILL.md
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go

Comment thread shortcuts/drive/drive_upload.go
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@07052faeda8fd4231d0225bd909113d7c459598f

🧩 Skill update

npx skills add larksuite/cli#feat/drive-upload-wiki-target -y -g

@wittam-01 wittam-01 force-pushed the feat/drive-upload-wiki-target branch 2 times, most recently from 50e8cf2 to 84becfc Compare April 23, 2026 12:37
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/drive/drive_io_test.go`:
- Around line 956-983: The helper decodeDriveMultipartBody currently treats any
error from reader.NextPart() or buf.ReadFrom(part) as EOF and silently ignores
failures; update decodeDriveMultipartBody to treat non-EOF errors as test
failures by calling t.Fatalf (or t.Fatalf-like) with the error context, i.e.
check if err from reader.NextPart() is io.EOF then break else fail the test, and
check the error returned by buf.ReadFrom(part) and fail the test with details if
non-nil; reference the decodeDriveMultipartBody function and the calls to
reader.NextPart() and buf.ReadFrom(part) when making this change.

In `@tests/cli_e2e/drive/coverage.md`:
- Around line 4-6: The coverage metrics are inconsistent with the command table:
the table lists 29 leaf commands but the metrics show "Denominator: 28", and
dry-run coverage is marked for "drive +apply-permission" while "drive +upload"
has dry-run coverage but remains marked ✕; choose one semantics and make the
counts consistent. Either (A) treat dry-run as covered: update "Denominator" to
29, increment "Covered" to include "drive +upload" so both "drive
+apply-permission" and "drive +upload" are counted, and recalc "Coverage"
percentage; or (B) treat dry-run as not covered: remove dry-run coverage marks
from the table entries (or from "drive +apply-permission"), keep "Denominator:
28", adjust "Covered" and "Coverage" accordingly; apply the same rule
consistently across the file.
🪄 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: b74c4d45-21e2-4476-b883-1801dee27ec3

📥 Commits

Reviewing files that changed from the base of the PR and between 50e8cf2 and 84becfc.

📒 Files selected for processing (6)
  • shortcuts/drive/drive_io_test.go
  • shortcuts/drive/drive_upload.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go
✅ Files skipped from review due to trivial changes (1)
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md

Comment thread shortcuts/drive/drive_io_test.go
Comment thread tests/cli_e2e/drive/coverage.md
@wittam-01 wittam-01 changed the title Feat/drive upload wiki target feat: support wiki node targets in drive +upload Apr 23, 2026
fangshuyu-768
fangshuyu-768 previously approved these changes Apr 23, 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.

♻️ Duplicate comments (2)
shortcuts/drive/drive_io_test.go (1)

1018-1030: ⚠️ Potential issue | 🟡 Minor

Helper still swallows non-EOF multipart errors.

decodeDriveMultipartBody treats any NextPart() error as end-of-stream and discards ReadFrom's error via _, _. A malformed boundary or a truncated part will produce a partially decoded body that silently passes the new wiki-target assertions (e.g., parent_type/parent_node missing could look like an assertion failure even though the real problem is a decode error). This is the same issue raised on the previous commit and still applies.

🧪 Proposed helper hardening
+	"io"
@@
 	for {
 		part, err := reader.NextPart()
+		if errors.Is(err, io.EOF) {
+			break
+		}
 		if err != nil {
-			break
+			t.Fatalf("read multipart part: %v", err)
 		}
 		buf := new(bytes.Buffer)
-		_, _ = buf.ReadFrom(part)
+		if _, err := buf.ReadFrom(part); err != nil {
+			t.Fatalf("read multipart field %q: %v", part.FormName(), err)
+		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/drive/drive_io_test.go` around lines 1018 - 1030, The loop in
decodeDriveMultipartBody incorrectly treats any reader.NextPart() error as EOF
and swallows ReadFrom errors, producing silently partial decodes; change the
NextPart() handling to check for io.EOF and break only on EOF, otherwise return
the error from NextPart(), and propagate any error returned by
buf.ReadFrom(part) instead of discarding it; ensure you still populate
body.Files and body.Fields only after successful ReadFrom and reference the
reader.NextPart(), buf.ReadFrom, and body.Files/body.Fields symbols when making
the change.
tests/cli_e2e/drive/coverage.md (1)

4-28: ⚠️ Potential issue | 🟡 Minor

Metrics and command table still inconsistent.

The table has 29 rows and 2 ✓ entries (drive +apply-permission on line 20 and drive files create_folder on line 39), but the metrics say Denominator: 28 / Covered: 1. Additionally, drive +upload now has dry-run coverage via TestDriveUploadDryRun_WikiTarget but remains marked ✕ on line 28 while drive +apply-permission (also dry-run only) is marked ✓ — pick one semantic for "dry-run counts" and apply it consistently across table + metrics.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/cli_e2e/drive/coverage.md` around lines 4 - 28, Update the coverage
metrics and command table in coverage.md so the "dry-run counts" policy is
applied consistently: decide whether dry-run tests (e.g.,
TestDrive_ApplyPermissionDryRun, TestDriveUploadDryRun_WikiTarget) should be
considered covered or not, then adjust the Denominator, Covered, Coverage
percentage and the ✓/✕ marks in the Command Table accordingly; ensure the
entries referencing TestDrive_FilesCreateFolderWorkflow,
TestDrive_ApplyPermissionDryRun /
TestDrive_ApplyPermissionDryRunRejectsFullAccess, and
TestDriveUploadDryRun_WikiTarget are updated to reflect that chosen semantic so
the table and summary metrics match.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@shortcuts/drive/drive_io_test.go`:
- Around line 1018-1030: The loop in decodeDriveMultipartBody incorrectly treats
any reader.NextPart() error as EOF and swallows ReadFrom errors, producing
silently partial decodes; change the NextPart() handling to check for io.EOF and
break only on EOF, otherwise return the error from NextPart(), and propagate any
error returned by buf.ReadFrom(part) instead of discarding it; ensure you still
populate body.Files and body.Fields only after successful ReadFrom and reference
the reader.NextPart(), buf.ReadFrom, and body.Files/body.Fields symbols when
making the change.

In `@tests/cli_e2e/drive/coverage.md`:
- Around line 4-28: Update the coverage metrics and command table in coverage.md
so the "dry-run counts" policy is applied consistently: decide whether dry-run
tests (e.g., TestDrive_ApplyPermissionDryRun, TestDriveUploadDryRun_WikiTarget)
should be considered covered or not, then adjust the Denominator, Covered,
Coverage percentage and the ✓/✕ marks in the Command Table accordingly; ensure
the entries referencing TestDrive_FilesCreateFolderWorkflow,
TestDrive_ApplyPermissionDryRun /
TestDrive_ApplyPermissionDryRunRejectsFullAccess, and
TestDriveUploadDryRun_WikiTarget are updated to reflect that chosen semantic so
the table and summary metrics match.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7173356d-377a-4aa5-b44a-85171d9c4ab4

📥 Commits

Reviewing files that changed from the base of the PR and between 84becfc and 07052fa.

📒 Files selected for processing (6)
  • shortcuts/drive/drive_io_test.go
  • shortcuts/drive/drive_upload.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go
✅ Files skipped from review due to trivial changes (1)
  • skills/lark-drive/SKILL.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go
  • skills/lark-drive/references/lark-drive-upload.md

Change-Id: Iaf94270c0a2a2ac02af81c234553ac5850c0668b
@wittam-01 wittam-01 force-pushed the feat/drive-upload-wiki-target branch from 07052fa to 22e22fb Compare April 23, 2026 14:32
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/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants