Skip to content

feat(drive): add +copy shortcut - #2129

Open
zzzchao123 wants to merge 1 commit into
mainfrom
feat/drive-copy-shortcut
Open

feat(drive): add +copy shortcut#2129
zzzchao123 wants to merge 1 commit into
mainfrom
feat/drive-copy-shortcut

Conversation

@zzzchao123

@zzzchao123 zzzchao123 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Wrap the Drive file-copy endpoint as drive +copy. Accept a document URL (recommended) or bare token + --type for the source, a folder token or folder URL for the target, and repeatable --extra key=value pairs forwarded verbatim for special copy semantics (e.g. target_type=docx to convert a legacy doc during copy). Reject wiki URLs/tokens with a typed validation error whose hint carries a ready-to-adapt wiki +node-copy command, because a Drive copy of a wiki-backed document would land in Drive space instead of the wiki tree.

Declare docs:document:copy (the narrowest scope in the endpoint's any-of set). Cover the shortcut with unit tests, dry-run e2e and a self-contained live workflow (upload -> copy -> download-verify -> cleanup), and register it in tests/cli_e2e/drive/coverage.md. Route copy intents in the lark-drive skill to the shortcut instead of the raw files copy service command.

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark-cli <domain> <command> flow works as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added the drive +copy command for copying Drive documents and folders.
    • Supports URLs or tokens, destination folders, custom names, extra parameters, and dry-run previews.
    • Resolves personal-space destinations and provides Wiki-specific guidance when copying isn’t supported.
  • Documentation

    • Added detailed copy workflow documentation, examples, permissions, and usage guidance.
  • Tests

    • Added comprehensive unit and end-to-end coverage for parsing, validation, previews, API execution, and content verification.

@zzzchao123 zzzchao123 self-assigned this Jul 31, 2026
@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 Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

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 the drive +copy shortcut. It resolves URLs and tokens, validates parameters, supports dry runs and extras, redirects Wiki inputs, executes Drive copy requests, updates documentation, and adds unit and end-to-end tests.

Changes

Drive copy workflow

Layer / File(s) Summary
Input resolution and validation
shortcuts/drive/drive_copy.go, shortcuts/drive/drive_copy_test.go, shortcuts/drive/shortcuts.go, shortcuts/drive/shortcuts_test.go
The shortcut parses URLs and tokens, validates names, folders, types, and extras, normalizes base to bitable, and redirects Wiki inputs to wiki +node-copy. The shortcut registry and command-list test include +copy.
Copy request and result handling
shortcuts/drive/drive_copy.go, shortcuts/drive/drive_copy_test.go
The command builds Drive copy requests, supports dry-run previews, resolves my_space, executes the API call, preserves typed API errors, synthesizes missing resource URLs, and formats copied-file metadata.
Documentation and end-to-end coverage
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-copy.md, tests/cli_e2e/drive/*
The Drive documentation describes drive +copy. Tests cover URL and token inputs, extras, Wiki rejection, my_space, live copying, and content equality. Coverage metrics and command records are updated.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant DriveCopy
  participant DriveAPI
  Operator->>DriveCopy: Provide source, name, and folder
  DriveCopy->>DriveCopy: Resolve and validate inputs
  DriveCopy->>DriveAPI: POST files copy request
  DriveAPI-->>DriveCopy: Return copied-file metadata
  DriveCopy-->>Operator: Print copy status and resource URL
Loading

Possibly related PRs

Suggested reviewers: fangshuyu-768

🚥 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 identifies the main change: adding the drive +copy shortcut.
Description check ✅ Passed The description covers the summary, implementation scope, testing, and related issues, but it omits the explicit Changes section.
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.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch feat/drive-copy-shortcut
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/drive-copy-shortcut

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.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

PR Quality Summary

CI did not complete successfully. Use the failed check links below to decide whether this PR needs a code change or a rerun.

Failed checks

@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-copy-shortcut -y -g

@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 (1)
tests/cli_e2e/drive/drive_copy_dryrun_test.go (1)

105-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the exact exit code for the Validate-stage rejection.

The test only checks result.ExitCode == 0 fails. Assert result.ExitCode == 2 directly. Based on learnings, when a shortcut's Validate callback rejects input, the CLI exits with code 2 and prints a structured JSON error envelope to stdout. Asserting the exact code makes this a stronger contract test and matches the established pattern used elsewhere in this test suite (e.g., TestDrive_PullDryRunRejectsAbsoluteLocalDir).

♻️ Proposed tightening of the exit-code assertion
-	if result.ExitCode == 0 {
+	if result.ExitCode != 2 {
 		t.Fatalf("wiki URL should be rejected with a redirect error\nstdout:\n%s\nstderr:\n%s", result.Stdout, result.Stderr)
 	}
🤖 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/drive/drive_copy_dryrun_test.go` around lines 105 - 108, Update
the exit-code assertion in the affected dry-run rejection test to require
result.ExitCode == 2 directly, preserving the existing failure diagnostics and
stdout/stderr checks.

Source: Learnings

🤖 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/drive/drive_copy_dryrun_test.go`:
- Around line 105-108: Update the exit-code assertion in the affected dry-run
rejection test to require result.ExitCode == 2 directly, preserving the existing
failure diagnostics and stdout/stderr checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a0e2c344-7685-4d93-a2ca-c7cd425f8c29

📥 Commits

Reviewing files that changed from the base of the PR and between cfe76ad and f3d0a65.

📒 Files selected for processing (9)
  • shortcuts/drive/drive_copy.go
  • shortcuts/drive/drive_copy_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-copy.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_copy_dryrun_test.go
  • tests/cli_e2e/drive/drive_copy_workflow_test.go

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.72727% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.43%. Comparing base (fa9c30c) to head (f3d0a65).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_copy.go 97.71% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2129      +/-   ##
==========================================
+ Coverage   75.39%   75.43%   +0.04%     
==========================================
  Files         924      925       +1     
  Lines       98005    98181     +176     
==========================================
+ Hits        73895    74067     +172     
- Misses      18478    18480       +2     
- Partials     5632     5634       +2     

☔ View full report in Codecov by Harness.
📢 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.

Comment thread skills/lark-drive/references/lark-drive-copy.md Outdated
Comment thread skills/lark-drive/references/lark-drive-copy.md
Comment thread skills/lark-drive/references/lark-drive-copy.md Outdated
Comment thread skills/lark-drive/references/lark-drive-copy.md Outdated
Comment thread skills/lark-drive/SKILL.md Outdated
@zzzchao123
zzzchao123 force-pushed the feat/drive-copy-shortcut branch 6 times, most recently from 85c093b to 07b9b3a Compare July 31, 2026 07:19

@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 (2)
shortcuts/drive/drive_copy_test.go (1)

30-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a case for a matching --type with a URL input.

The table covers a conflicting --type (lines 80-86) but not a matching one. The flag description states that --type is optional for URLs and must match the URL type. A case such as --url .../docx/docxCopySource with --type docx, and a case with --type base against a /base/ URL, would lock in the normalized-comparison path at line 190.

🤖 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/drive/drive_copy_test.go` around lines 30 - 61, Add table-driven
test cases in the existing drive copy input tests for URL inputs whose --type
matches the URL type, including a /docx/ URL with docx and a /base/ URL with
base; assert the expected token and normalized bitable type to cover the
matching normalized-comparison path.
shortcuts/drive/drive_copy.go (1)

25-25: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Derive the allowed-type text from one source.

The supported-type list is repeated in four places: driveCopyTypes (line 25), the two error messages (lines 204 and 219, 225), and the driveCopyTypeSupported switch (line 294). A future type addition must be applied in each place, and a missed edit produces a misleading error message. Build the message text from the supported set instead.

♻️ Example consolidation
+var driveCopySupportedTypes = []string{"doc", "docx", "sheet", "file", "mindnote", "slides", "bitable"}
+
+// driveCopySupportedTypesText lists the accepted values, including the base alias.
+func driveCopySupportedTypesText() string {
+	return strings.Join(append(driveCopySupportedTypes, "base"), ", ")
+}
+
 func driveCopyTypeSupported(docType string) bool {
-	switch normalizeDriveCopyType(docType) {
-	case "doc", "docx", "sheet", "file", "mindnote", "slides", "bitable":
-		return true
-	default:
-		return false
-	}
+	normalized := normalizeDriveCopyType(docType)
+	for _, allowed := range driveCopySupportedTypes {
+		if normalized == allowed {
+			return true
+		}
+	}
+	return false
 }

Also applies to: 201-226, 292-299

🤖 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/drive/drive_copy.go` at line 25, Consolidate supported drive-copy
types around the single source `driveCopyTypes`: update `driveCopyTypeSupported`
to derive membership from that set and build both error messages in the affected
validation paths from the same list, rather than repeating type names. Preserve
the existing validation behavior and keep the displayed allowed-type text
synchronized automatically when `driveCopyTypes` changes.
🤖 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/drive/drive_copy_dryrun_test.go`:
- Around line 139-152: The wiki URL redirect assertions should validate the
typed error’s exact exit code and inspect combined process output. In the
relevant test, replace the nonzero check with result.AssertExitCode(t, 2) (or an
equivalent exact assertion), define combined output from result.Stdout and
result.Stderr, and use it for all validation and guidance string checks.

In `@tests/cli_e2e/drive/drive_copy_workflow_test.go`:
- Around line 18-24: Add clie2e.SkipWithoutTenantAccessToken(t) at the start of
TestDrive_CopyWorkflow, before the createDriveFolder setup, so the workflow is
skipped when tenant/BOT credentials are unavailable.

---

Nitpick comments:
In `@shortcuts/drive/drive_copy_test.go`:
- Around line 30-61: Add table-driven test cases in the existing drive copy
input tests for URL inputs whose --type matches the URL type, including a /docx/
URL with docx and a /base/ URL with base; assert the expected token and
normalized bitable type to cover the matching normalized-comparison path.

In `@shortcuts/drive/drive_copy.go`:
- Line 25: Consolidate supported drive-copy types around the single source
`driveCopyTypes`: update `driveCopyTypeSupported` to derive membership from that
set and build both error messages in the affected validation paths from the same
list, rather than repeating type names. Preserve the existing validation
behavior and keep the displayed allowed-type text synchronized automatically
when `driveCopyTypes` changes.
🪄 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 Plus

Run ID: 8d1d5be5-4615-445c-ae18-efabb82185f2

📥 Commits

Reviewing files that changed from the base of the PR and between 74de554 and 07b9b3a.

📒 Files selected for processing (9)
  • shortcuts/drive/drive_copy.go
  • shortcuts/drive/drive_copy_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-copy.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_copy_dryrun_test.go
  • tests/cli_e2e/drive/drive_copy_workflow_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • shortcuts/drive/shortcuts_test.go
  • shortcuts/drive/shortcuts.go
  • tests/cli_e2e/drive/coverage.md
  • skills/lark-drive/references/lark-drive-copy.md

Comment thread tests/cli_e2e/drive/drive_copy_dryrun_test.go
Comment thread tests/cli_e2e/drive/drive_copy_workflow_test.go

```json
{
"copied": true,

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.

内容脱敏,包括域名看是否需要处理


> **前置条件:** 先阅读 [`../lark-shared/SKILL.md`](../../lark-shared/SKILL.md) 了解认证、全局参数和安全规则。

复制一个 Drive 文件(在线文档、表格、多维表格、幻灯片、思维笔记或普通文件)到目标文件夹,生成一个内容相同的新副本。推荐直接传文档 URL。

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.

如果是bot身份拷贝文档,需要自动给当前用户身份授予可管理权限,参考 +upload、+import

Wrap the Drive file-copy endpoint as drive +copy. Accept a document URL
(recommended) or bare token + --type for the source; the target takes a
folder token, a folder URL, or the my_space constant, which resolves the
caller's My Space root folder via the root-folder-meta endpoint (absent
from platform metadata, works for both user and bot). Repeatable --extra
key=value pairs are forwarded verbatim for special copy semantics (e.g.
target_type=docx to convert a legacy doc during copy). Reject wiki
URLs/tokens with a typed validation error whose hint carries a
ready-to-adapt wiki +node-copy command, because a Drive copy of a
wiki-backed document would land in Drive space instead of the wiki tree.

Declare docs:document:copy (the narrowest scope in the endpoint's any-of
set) plus a conditional drive:drive.metadata:readonly for my_space
resolution. Cover the shortcut with unit tests, dry-run e2e and a
self-contained live workflow (upload -> copy -> download-verify ->
my_space copy -> cleanup), and register it in
tests/cli_e2e/drive/coverage.md. Route copy intents in the lark-drive
skill to the shortcut instead of the raw files copy service command.
@zzzchao123
zzzchao123 force-pushed the feat/drive-copy-shortcut branch from 07b9b3a to 2c906b9 Compare July 31, 2026 09:39
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