fix(drive): use title for default download filename - #2089
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthrough
ChangesDrive download output flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant DriveDownload
participant DriveMetadataAPI
participant DriveDownloadAPI
participant FileSystem
User->>DriveDownload: Run download without --output
DriveDownload->>DriveMetadataAPI: Query metadata title
DriveDownload->>DriveDownloadAPI: Request file content
DriveDownloadAPI-->>DriveDownload: Return content and filename header
DriveDownload->>FileSystem: Resolve and save output path
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e31740fa44d2a30b3517ba94a3a12cd66f94be46🧩 Skill updatenpx skills add larksuite/cli#fix/drive-download-default-filename -y -g |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2089 +/- ##
==========================================
+ Coverage 75.16% 75.20% +0.04%
==========================================
Files 912 913 +1
Lines 96475 96707 +232
==========================================
+ Hits 72517 72732 +215
- Misses 18381 18386 +5
- Partials 5577 5589 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
shortcuts/drive/drive_download.go (1)
46-55: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsolidate the Drive metadata scope constant.
driveMetadataReadScopeis this file-only copy of the shared drive metadata scope already used across many Drive shortcuts. Define/export it fromshortcuts/commonor another shared location and reuse it here.🤖 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_download.go` around lines 46 - 55, Consolidate the duplicated driveMetadataReadScope constant by defining or exporting the shared Drive metadata scope from shortcuts/common (or the existing shared Drive scope location), then update DriveDownload and other references to reuse that symbol. Remove the file-local copy while preserving the existing ConditionalScopes behavior.
🤖 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 `@shortcuts/drive/drive_download.go`:
- Around line 21-44: Update driveDownloadFallbackFileName and
driveDownloadDefaultOutputPath to reject "/" in addition to the existing empty,
"." and ".." checks, falling back to fileToken before returning or appending an
extension.
In `@shortcuts/drive/drive_io_test.go`:
- Around line 1714-1744: Strengthen
TestDriveDownloadMetadataErrorBeforeDownloadWhenOutputOmitted by asserting
problem.Subtype alongside problem.Category and problem.Code. Verify it is the
expected authorization subtype, or at minimum non-empty if no specific subtype
constant is available, while preserving the existing typed-error validation.
In `@tests/cli_e2e/drive/drive_download_dryrun_test.go`:
- Line 1: Add live E2E coverage alongside the existing dry-run tests in
drive_download_dryrun_test.go for drive +download filename resolution:
create/upload a fixture with a known title, download without an explicit output
path against the live backend, assert the resolved filename and file contents,
and clean up all created resources using the available bot credentials. Update
the corresponding coverage.md row/notes to reflect the new live workflow and
remove the “no live file fixture workflow yet” caveat only after the test is
implemented.
---
Nitpick comments:
In `@shortcuts/drive/drive_download.go`:
- Around line 46-55: Consolidate the duplicated driveMetadataReadScope constant
by defining or exporting the shared Drive metadata scope from shortcuts/common
(or the existing shared Drive scope location), then update DriveDownload and
other references to reuse that symbol. Remove the file-local copy while
preserving the existing ConditionalScopes behavior.
🪄 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: a289514b-00f9-41e4-94fe-a2636810964e
📒 Files selected for processing (5)
shortcuts/drive/drive_download.goshortcuts/drive/drive_io_test.goskills/lark-drive/references/lark-drive-download.mdtests/cli_e2e/drive/coverage.mdtests/cli_e2e/drive/drive_download_dryrun_test.go
| @@ -0,0 +1,90 @@ | |||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | |||
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Missing live E2E coverage for the drive +download filename-resolution behavior change. As per path instructions for tests/cli_e2e/**/*.go, "New flows or behavior changes require live E2E coverage with a self-contained create/use/cleanup workflow and bot credentials where applicable." The new default-filename-resolution behavior (Content-Disposition → metadata title → token precedence, metadata fetched before download) is only exercised via dry-run mocks; coverage.md itself acknowledges no live fixture workflow exists yet.
tests/cli_e2e/drive/drive_download_dryrun_test.go#L1-91: add a live workflow test (e.g., upload a fixture file with a known title/no explicit output, rundrive +downloadfor real, and assert the saved filename/content against the live backend, with create/use/cleanup) alongside the existing dry-run tests.tests/cli_e2e/drive/coverage.md#L34-34: update the row/notes once the live workflow test lands; until then, the "no live file fixture workflow yet" caveat should stay explicit rather than implying full coverage.
🤖 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_download_dryrun_test.go` at line 1, Add live E2E
coverage alongside the existing dry-run tests in drive_download_dryrun_test.go
for drive +download filename resolution: create/upload a fixture with a known
title, download without an explicit output path against the live backend, assert
the resolved filename and file contents, and clean up all created resources
using the available bot credentials. Update the corresponding coverage.md
row/notes to reflect the new live workflow and remove the “no live file fixture
workflow yet” caveat only after the test is implemented.
Source: Coding guidelines
40fefc3 to
21daea2
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
shortcuts/drive/drive_io_test.go (1)
1808-1812: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAvoid
t.Fatalinside theOnMatchcallback.
OnMatchruns insideRoundTrip, which is not guaranteed to execute on the test goroutine;t.Fatalthere callsruntime.Goexiton the wrong goroutine and can hang or mask the failure. Record the ordering and assert after the command returns (or uset.Errorf).♻️ Suggested adjustment
+ var metaSeenBeforeDownload bool OnMatch: func(req *http.Request) { - if len(metaStub.CapturedBody) == 0 { - t.Fatal("metadata title lookup must happen before download") - } + metaSeenBeforeDownload = len(metaStub.CapturedBody) > 0 },Then assert
metaSeenBeforeDownloadaftermountAndRunDrivereturns.🤖 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_io_test.go` around lines 1808 - 1812, Replace the t.Fatal call inside the OnMatch callback with a goroutine-safe ordering record, such as setting metaSeenBeforeDownload when the metadata body is captured before download. After mountAndRunDrive returns, assert the recorded ordering on the test goroutine, preserving the requirement that metadata lookup precedes download.
🤖 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 `@skills/lark-drive/references/lark-drive-download.md`:
- Around line 14-15: Update the token-only usage documentation for `lark-cli
drive +download` to state that omitting `--output` requires the Drive metadata
read scope, and document the automatic filename precedence as
Content-Disposition filename, then metadata title, then file token.
In `@tests/cli_e2e/drive/coverage.md`:
- Line 34: Update the Metrics block in coverage.md to reflect 15 covered out of
32 leaf commands and the corresponding percentage, then add a Summary bullet for
the newly covered drive +download command describing its dry-run
metadata-planning and explicit-output behavior.
---
Nitpick comments:
In `@shortcuts/drive/drive_io_test.go`:
- Around line 1808-1812: Replace the t.Fatal call inside the OnMatch callback
with a goroutine-safe ordering record, such as setting metaSeenBeforeDownload
when the metadata body is captured before download. After mountAndRunDrive
returns, assert the recorded ordering on the test goroutine, preserving the
requirement that metadata lookup precedes download.
🪄 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: c6e193d4-30f8-452e-bcb9-be7ca01e3f4c
📒 Files selected for processing (5)
shortcuts/drive/drive_download.goshortcuts/drive/drive_io_test.goskills/lark-drive/references/lark-drive-download.mdtests/cli_e2e/drive/coverage.mdtests/cli_e2e/drive/drive_download_dryrun_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/cli_e2e/drive/drive_download_dryrun_test.go
- shortcuts/drive/drive_download.go
21daea2 to
e31740f
Compare
Summary
Fix
drive +downloaddefault naming when--outputis omitted. The command now resolves metadata title before starting the download and saves withContent-Dispositionfilename > metadata title > token.Changes
--output, so missing metadata permission fails before the download stream starts.--outputbehavior unchanged.Test Plan
go test ./shortcuts/drive -run 'TestDriveDownload(UsesContentDispositionWhenOutputOmitted|FallsBackToMetadataTitleWhenOutputOmitted|FallsBackToTokenWhenOutputOmittedAndMetadataEmpty|MetadataErrorBeforeDownloadWhenOutputOmitted|RejectsOverwriteWithoutFlag|AllowsOverwriteFlag)' -count=1\n- [x] Dry-run E2E passes with a locally built binary:LARK_CLI_BIN=/Users/bytedance/go/src/github.com/larksuite/cli/tmp/lark-cli-drive-download-default go test ./tests/cli_e2e/drive -run 'TestDriveDownloadDryRun_(DefaultNamePlansMetadataBeforeDownload|ExplicitOutputSkipsMetadata)' -count=1\n- [x]git diff --cached --check\n\n## Related Issues\n- None\nSummary by CodeRabbit
--outputis omitted, Drive downloads now use a safe default filename/path automatically.Content-Dispositionfilename, then Drive metadata title, then the file token.--outputskips it.--overwrite.drive +downloadnotes for the token-only flow’s default save location.