Skip to content

feat: support file-token overwrite and version output for drive +upload - #885

Merged
fangshuyu-768 merged 1 commit into
mainfrom
feat/drive-upload-file-token
May 14, 2026
Merged

feat: support file-token overwrite and version output for drive +upload#885
fangshuyu-768 merged 1 commit into
mainfrom
feat/drive-upload-file-token

Conversation

@wittam-01

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

Copy link
Copy Markdown
Collaborator

Summary

This PR adds in-place overwrite support to drive +upload via an optional --file-token flag and surfaces upload version in the shortcut output when the backend returns it. It also adds coverage and updates the lark-drive skill docs so the new behavior is documented for agents and users.

Changes

  • Add optional --file-token to drive +upload and pass file_token through both upload_all and upload_prepare
  • Return data.version from drive +upload when the backend response includes version or data_version
  • Add unit tests and drive E2E coverage for overwrite upload flows, including request-shape validation and live create/overwrite/download verification
  • Update skills/lark-drive/references/lark-drive-upload.md and drive E2E coverage notes

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark-cli drive +upload command works as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added --file-token to support in-place overwrites for Drive uploads; CLI now emits version when available and preserves file_token behavior.
  • Documentation

    • Drive upload docs updated with overwrite examples, parameter guidance, and request examples showing file_token and version behavior.
  • Bug Fixes

    • Validation rejects explicitly empty/whitespace --file-token and enforces non-empty token rules; bot-mode permission grant suppressed for overwrite.
  • Tests

    • Expanded unit and end-to-end tests covering overwrite flows, multipart/single-part uploads, dry-run request shapes, and version handling.

Review Change Stack

@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 May 14, 2026
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3033abb-ec3c-4616-8378-c1f96a212020

📥 Commits

Reviewing files that changed from the base of the PR and between 623edd8 and 64d49e9.

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

📝 Walkthrough

Walkthrough

Adds overwrite support for Drive uploads via --file-token: spec/result types, validation (reject empty), DryRun/request threading, upload helpers returning FileToken+Version, unit and E2E tests, and documentation updates.

Changes

Drive file overwrite with token

Layer / File(s) Summary
Data structures and CLI flag definition
shortcuts/drive/drive_upload.go
driveUploadSpec gains FileToken; new driveUploadResult carries FileToken and Version; DriveUpload registers --file-token and DryRun includes file_token when set.
Upload execution and helper functions with result threading
shortcuts/drive/drive_upload.go
Execute uses driveUploadResult, forwards spec.FileToken into single-part and multipart helpers, conditionally includes file_token in requests, standardizes error returns, and extracts version with data_version fallback.
Validation rules and constraint enforcement
shortcuts/drive/drive_upload.go, shortcuts/drive/drive_io_test.go
Validation rejects explicitly empty --file-token, validates non-empty FileToken as a resource name, and updates tests to initialize the new flag where required; invalid-token table extended with file-token cases.
Unit test coverage for overwrite and flag behavior
shortcuts/drive/drive_io_test.go
Added large-file multipart overwrite tests, small-file overwrite multipart body assertions, dry-run spec trimming and request-body inclusion tests, and version-from-response alias checks; updated validation tables and flag wiring in tests.
Bot-mode permission grant tests
shortcuts/drive/drive_permission_grant_test.go
Added test verifying bot-mode overwrite (with --file-token) skips permission grant and preserves version from the upload response.
End-to-end workflow tests & dry-run
tests/cli_e2e/drive/drive_upload_dryrun_test.go, tests/cli_e2e/drive/drive_upload_workflow_test.go
Added dry-run E2E test asserting file_token in upload_all output and a full workflow test covering initial upload, overwrite via --file-token (token stability), cleanup, and download verification.
User-facing and coverage documentation
skills/lark-drive/references/lark-drive-upload.md, tests/cli_e2e/drive/coverage.md
Documented --file-token and file_token in pre-upload JSON examples, surfaced version output, clarified empty-token constraints, and updated coverage summary/table to include overwrite behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • fangshuyu-768
  • liangshuo-1

Poem

🐰 I nibbled at code, found a token to keep,
Overwrite in place, no old copies to heap,
Multipart dances and versions that sing,
File token held tight — hop! — into spring.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% 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 accurately and concisely describes the main feature: adding file-token overwrite support and version output for drive +upload.
Description check ✅ Passed The description follows the template with all required sections (Summary, Changes, Test Plan, Related Issues) completed with sufficient detail about the feature.
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/drive-upload-file-token

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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/drive/drive_upload.go (1)

359-375: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Multipart finish path drops version from output.

uploadFileMultipart only extracts file_token from the finish response and returns driveUploadResult{FileToken: fileToken} without populating Version. The small-file path (uploadFileToDrive) uses driveUploadVersionFromData(data) to surface either version or data_version, so the same overwrite call produces a version field for files ≤ 20MB but never for files > 20MB. Per the PR description, returning data.version should be uniform across both upload paths.

🛠️ Proposed fix
 	fileToken := common.GetString(finishResult, "file_token")
 	if fileToken == "" {
 		return driveUploadResult{}, output.Errorf(output.ExitAPI, "api_error", "upload_finish succeeded but no file_token returned")
 	}

-	return driveUploadResult{FileToken: fileToken}, nil
+	return driveUploadResult{
+		FileToken: fileToken,
+		Version:   driveUploadVersionFromData(finishResult),
+	}, nil
 }

runtime.CallAPI already returns the unwrapped data map (the same shape used to read file_token/upload_id), so driveUploadVersionFromData can be reused as-is. Consider extending TestDriveUploadLargeFileOverwriteUsesMultipart (or adding a sibling test) to assert data["version"] for the multipart path.

🤖 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_upload.go` around lines 359 - 375, The multipart finish
path in uploadFileMultipart only returns FileToken and omits Version; call
driveUploadVersionFromData(finishResult) after runtime.CallAPI returns and
populate the Version field on the returned driveUploadResult (i.e., return
driveUploadResult{FileToken: fileToken, Version:
<value_from_driveUploadVersionFromData>}), reusing the existing
driveUploadVersionFromData helper so multipart uploads surface the same
data.version/data_version as small-file uploads; also add/extend
TestDriveUploadLargeFileOverwriteUsesMultipart to assert data["version"] is
present for the multipart path.
🤖 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.

Outside diff comments:
In `@shortcuts/drive/drive_upload.go`:
- Around line 359-375: The multipart finish path in uploadFileMultipart only
returns FileToken and omits Version; call
driveUploadVersionFromData(finishResult) after runtime.CallAPI returns and
populate the Version field on the returned driveUploadResult (i.e., return
driveUploadResult{FileToken: fileToken, Version:
<value_from_driveUploadVersionFromData>}), reusing the existing
driveUploadVersionFromData helper so multipart uploads surface the same
data.version/data_version as small-file uploads; also add/extend
TestDriveUploadLargeFileOverwriteUsesMultipart to assert data["version"] is
present for the multipart path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 200c6cb5-d8f4-48ab-ad73-1db1bee7c388

📥 Commits

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

📒 Files selected for processing (6)
  • shortcuts/drive/drive_io_test.go
  • shortcuts/drive/drive_upload.go
  • skills/lark-drive/references/lark-drive-upload.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_upload_dryrun_test.go
  • tests/cli_e2e/drive/drive_upload_workflow_test.go

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.48387% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.89%. Comparing base (37459b6) to head (64d49e9).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_upload.go 85.48% 8 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #885      +/-   ##
==========================================
- Coverage   65.89%   65.89%   -0.01%     
==========================================
  Files         518      520       +2     
  Lines       48945    49220     +275     
==========================================
+ Hits        32254    32435     +181     
- Misses      13921    14015      +94     
  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

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@64d49e95fe70f63e8ebef5b79f2bc1cfe2ece243

🧩 Skill update

npx skills add larksuite/cli#feat/drive-upload-file-token -y -g

@wittam-01
wittam-01 force-pushed the feat/drive-upload-file-token branch 2 times, most recently from 6c80d43 to 623edd8 Compare May 14, 2026 09:59
Change-Id: I76c334578fc2fa5cfd2eedb4525b0d9d735f610e
@wittam-01
wittam-01 force-pushed the feat/drive-upload-file-token branch from 623edd8 to 64d49e9 Compare May 14, 2026 10:16
Comment thread shortcuts/drive/drive_upload.go
@fangshuyu-768
fangshuyu-768 merged commit 0d20f88 into main May 14, 2026
22 checks passed
@fangshuyu-768
fangshuyu-768 deleted the feat/drive-upload-file-token branch May 14, 2026 11:50
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
…ad (larksuite#885)

Change-Id: I76c334578fc2fa5cfd2eedb4525b0d9d735f610e
@coderabbitai coderabbitai Bot mentioned this pull request Jul 9, 2026
4 tasks
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