Skip to content

fix(drive): improve token recognition for download and preview - #2680

Open
wittam-01 wants to merge 1 commit into
mainfrom
fix/drive-token-recognition
Open

fix(drive): improve token recognition for download and preview#2680
wittam-01 wants to merge 1 commit into
mainfrom
fix/drive-token-recognition

Conversation

@wittam-01

@wittam-01 wittam-01 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Improve token recognition for drive +download and drive +preview: a Wiki token supplied through --file-token now resolves to its underlying file instead of being sent to file APIs as a file token. Both commands share the same best-effort entity lookup and legacy fallback behavior.

Changes

  • Add queryDriveTokenInfo for typed token identification and reuse resolveDriveFileSource plus the source dry-run planner across download and preview.
  • Use the resolved file token throughout download and all preview modes: candidate listing, source-file access, and converted preview artifacts. Preserve Wiki source annotations and reject non-file objects with the existing export guidance.
  • On API, transport, or malformed-response failures, warn on stderr and use the original file-token or Wiki resolution path. Wiki permission is required only for the legacy Wiki fallback; default download naming keeps its existing metadata scope requirement.
  • Keep source flag descriptions focused on accepted inputs, with no internal lookup explanation. Skills are unchanged.

Test Plan

  • Focused shortcut unit tests pass for token resolution, malformed/API/transport fallback, type and permission guards, conditional Wiki scopes, download requests, all three preview modes, and updated dry-run contracts.
  • CLI dry-run E2E: go test ./tests/cli_e2e/drive -run '^(TestDriveDownloadDryRun_EntityLookup|TestDrivePreviewDryRun_EntityLookup)$' -count=1 -v — 17 input/mode variants pass.
  • Canonical make build, both shortcuts' help, changed-file formatting, and git diff --check pass.
  • Manual bot validation: 26 checks using PNG and text files uploaded to a test Drive folder and Wiki parent. Covers ordinary file tokens, Wiki tokens passed through --file-token, explicit Wiki tokens, URLs, underlying file tokens, default naming, preview candidates, and converted text previews. PNG downloads match the source SHA-256; text previews contain the expected content. All four fixtures created for this run were deleted successfully.

Full repository-wide unit tests, vet/lint/quality/license gates, and the complete live suite were not run locally; local validation was limited to the affected behavior.

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Drive download and preview now resolve file and Wiki tokens, including URL inputs, before retrieving content.
    • Preview supports consistent token handling across list, source-file, and PDF modes.
    • Dry-run plans now show token lookup and any conditional Wiki resolution steps.
  • Bug Fixes

    • Added fallback behavior when token lookup is unavailable, with warnings when applicable.
    • Invalid or unsupported Drive entity types are rejected before output is produced.
    • Improved handling of deleted, recycled, or malformed file references.

Change-Id: I70ea563448b445f3e11fb72f7ce8492f2ab8191d
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7c56d784-a2ec-4662-ad81-0813998d1454

📥 Commits

Reviewing files that changed from the base of the PR and between 4fddd6b and 86dd0f0.

📒 Files selected for processing (11)
  • shortcuts/drive/drive_download.go
  • shortcuts/drive/drive_download_source_test.go
  • shortcuts/drive/drive_file_source.go
  • shortcuts/drive/drive_io_test.go
  • shortcuts/drive/drive_preview.go
  • shortcuts/drive/drive_preview_source_test.go
  • shortcuts/drive/drive_preview_test.go
  • shortcuts/drive/drive_token.go
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_download_dryrun_test.go
  • tests/cli_e2e/drive/drive_preview_dryrun_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Drive download and preview now perform best-effort entity-token lookup before execution. Wiki inputs use legacy node resolution only when lookup fails. Dry-run plans, scope handling, fallback behavior, entity validation, and end-to-end coverage were updated.

Changes

Drive token resolution

Layer / File(s) Summary
Token lookup and fallback resolution
shortcuts/drive/drive_token.go, shortcuts/drive/drive_file_source.go
Adds Drive token metadata lookup. Valid file entities use the returned token. Failed lookups use file-token or Wiki-node fallback paths.
Download and preview integration
shortcuts/drive/drive_download.go, shortcuts/drive/drive_preview.go
Routes execution and dry-run planning through shared resolution helpers. Wiki and metadata scopes are checked only when their fallback paths require them.
Resolution and dry-run validation
shortcuts/drive/drive_download_source_test.go, shortcuts/drive/drive_preview_source_test.go, shortcuts/drive/drive_io_test.go, shortcuts/drive/drive_preview_test.go
Tests successful lookup, fallback warnings, invalid entity types, permission failures, output handling, and updated request ordering.
End-to-end dry-run coverage
tests/cli_e2e/drive/*, tests/cli_e2e/drive/coverage.md
Consolidates download and preview dry-run cases around entity lookup, conditional Wiki resolution, resolved tokens, and output modes.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 86dd0

The updated token-resolution paths preserve the intended fallback and scope behavior.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant resolveDriveFileSource
  participant DriveAPI
  participant WikiAPI
  participant ContentAPI
  CLI->>resolveDriveFileSource: resolve input token
  resolveDriveFileSource->>DriveAPI: query_by_token
  DriveAPI-->>resolveDriveFileSource: entity metadata
  alt lookup succeeds
    resolveDriveFileSource-->>CLI: resolved file token
  else Wiki fallback required
    resolveDriveFileSource->>WikiAPI: get_node
    WikiAPI-->>resolveDriveFileSource: Wiki node token
    resolveDriveFileSource-->>CLI: resolved Wiki file token
  end
  CLI->>ContentAPI: authorize and request content
Loading

Suggested reviewers: zzzchao123, caojie0621

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 59.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 10 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description includes all required sections. It clearly explains the token-resolution changes, fallback behavior, testing performed, and validation limits.
Title check ✅ Passed The title is concise and directly summarizes the main change: improved token recognition for Drive download and preview commands.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 59.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 10 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/drive-token-recognition

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 added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 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

  • deterministic-gate — failure — details
  • results — failure — details

deterministic-gate

  • public_content_change_id_trailercommit:86dd0f0e110c:3 — public contribution contains a Change-Id trailer — Action: remove the value from the public contribution and replace it with a non-sensitive placeholder

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#fix/drive-token-recognition -y -g

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.32394% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.27%. Comparing base (4fddd6b) to head (86dd0f0).

Files with missing lines Patch % Lines
shortcuts/drive/drive_file_source.go 78.57% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
+ Coverage   76.23%   76.27%   +0.03%     
==========================================
  Files        1120     1121       +1     
  Lines      127233   127253      +20     
==========================================
+ Hits        96997    97063      +66     
+ Misses      22429    22384      -45     
+ Partials     7807     7806       -1     

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

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/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant