Skip to content

feat(drive): add drive preview and cover shortcuts and document quota details#1256

Closed
zhoujunteng-max wants to merge 2 commits into
mainfrom
feat/drive-add-preview-cover-and-quota
Closed

feat(drive): add drive preview and cover shortcuts and document quota details#1256
zhoujunteng-max wants to merge 2 commits into
mainfrom
feat/drive-add-preview-cover-and-quota

Conversation

@zhoujunteng-max

@zhoujunteng-max zhoujunteng-max commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds drive +preview and drive +cover shortcuts for Drive file preview artifact and cover downloads, and updates the lark-drive skill metadata to expose quota detail capability and the new shortcuts to AI agents.

Changes

  • add drive +preview to list and download available preview artifacts
  • add drive +cover to list and download built-in cover presets
  • normalize preview result wrapping and cover parameter mapping based on backend validation rules
  • add unit tests, dry-run E2E tests, and live workflow E2E tests for preview/cover flows
  • update skills/lark-drive/SKILL.md and add preview/cover references
  • document quota_details.get in skills/lark-drive/SKILL.md

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark-cli drive +preview and lark-cli drive +cover commands work as expected

Additional verification:

  • make unit-test
  • go test ./shortcuts/drive -run 'TestDrivePreview|TestDriveCover|TestShortcutsIncludesExpectedCommands'
  • go test ./tests/cli_e2e/drive -run 'TestDrive(Preview|Cover)DryRun'
  • go test ./tests/cli_e2e/drive -run 'TestDrive_PreviewAndCoverWorkflow'

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added drive +preview to list/download Drive preview artifacts (list-only, type selection, versioning, output conflict policies, automatic extension inference).
    • Added drive +cover to list/download stable cover presets (spec selection, list-only, versioning, conflict policies).
  • Documentation

    • Added detailed reference pages with usage examples, parameters, responses, and constraints for both commands.
  • Tests

    • Added unit, dry-run, and end-to-end tests covering listing, downloads, validation, conflict handling, and retry workflows.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR adds two new Drive shortcut commands—drive +preview and drive +cover—for listing and downloading file preview artifacts and cover presets. Both commands support list-only mode, selective downloads with version/spec parameters, flexible output conflict handling, and dry-run request preview. Shared helpers handle API integration, candidate normalization, path finalization, and extension inference.

Changes

Drive Preview and Cover Commands

Layer / File(s) Summary
Shared preview/cover data model and helpers
shortcuts/drive/drive_preview_common.go
Defines preview candidate, cover spec, and status metadata; initializes built-in preview and cover catalogs; MIME-to-extension mappings; validates flag combinations and overwrite policy; fetches and normalizes preview candidates from Drive API; selects candidates by type with alias matching and downloadable preference; handles artifact download with stream processing, path finalization, extension inference from headers/disposition, and --if-exists collision handling (error, overwrite, rename-to-next-available).
Preview shortcut command
shortcuts/drive/drive_preview.go
Implements drive +preview with Validate (enforces --file-token format and mode constraints), DryRun (constructs POST preview_result request, conditionally includes version in body), and Execute (fetches candidates, handles list-only output, selects by type, verifies readiness, downloads with fallback extension and --if-exists policy).
Cover shortcut command
shortcuts/drive/drive_cover.go
Implements drive +cover with Validate (enforces file-token format, preset/mode combinations, spec matching), DryRun (outputs precomputed cover list or constructs GET preview_download request), and Execute (outputs spec list or downloads requested preset via downloadDrivePreviewArtifactWithParams, augmenting response with mode/file_token/selected_spec).
Shortcut registration
shortcuts/drive/shortcuts.go, shortcuts/drive/shortcuts_test.go
Registers DrivePreview and DriveCover in the shortcuts list; updates test expectations to include +preview and +cover commands.
Unit tests
shortcuts/drive/drive_preview_test.go
Comprehensive test coverage: preview list-only normalization, download with type resolution and rename semantics, unavailable type rejection; cover spec enumeration and parameter mapping; dry-run mode assertions (method, endpoint, query fields, body encoding); validation and error paths (missing flags, conflicting options, API not-ready mapped to FailedPrecondition error with hints); helper tests for extension fallback, content-type/content-disposition resolution, path rename/overwrite, scalar parsing, alias resolution, and validation hint construction.
E2E dry-run and workflow tests
tests/cli_e2e/drive/drive_preview_dryrun_test.go, tests/cli_e2e/drive/drive_preview_workflow_test.go
Dry-run tests verify API request shape (POST preview_result for list-only, GET preview_download for download, correct query/body parameters). Workflow test exercises end-to-end: creates folder, uploads text fixture, runs preview list/download with retry polling until downloadable candidate available (validates JSON fields and .txt extension), runs cover list/download with retry polling (validates JSON fields and image file non-empty); includes helpers for fixture I/O, upload with cleanup, candidate readiness checking, and folder creation with permission-based skip.
User documentation
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-preview.md, skills/lark-drive/references/lark-drive-cover.md
SKILL.md overview mentions preview and cover commands and adds shortcut table entries documenting required flags. Extends API resources/permissions section to include quota_details resource and quota_details.get permission. Preview reference doc includes prerequisites, usage examples (list, download PDF/text, rename-on-conflict, version query), full parameter table, query/download response conventions, candidate field schema, and key constraints. Cover reference doc includes examples (list specs, download spec, default with conflict handling), parameter table, output conventions, built-in spec enumeration (default/icon/grid/small/middle/big/square), constraints, and 404 error guidance.

Sequence Diagram

sequenceDiagram
  participant User as User/CLI
  participant Validator
  participant DriveAPI as Drive API
  participant FileSystem as File System
  User->>Validator: drive +preview/+cover with flags
  Validator->>Validator: validate file-token, mode, parameters
  alt list-only mode
    Validator-->>User: emit precomputed candidates/specs (no API call)
  else download mode
    Validator->>DriveAPI: fetch preview_result or download artifact
    DriveAPI-->>Validator: candidate list or artifact stream
    Validator->>Validator: select by type/spec, verify readiness
    Validator->>FileSystem: resolve output path, infer extension
    FileSystem->>FileSystem: handle --if-exists (error/overwrite/rename)
    FileSystem-->>Validator: finalized path
    Validator-->>User: return result with mode, selected type/spec, output
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • fangshuyu-768
  • wittam-01
  • liujinkun2025

Poem

🐇 A rabbit taps keys in morning light,

Previews bloom and covers take flight,
Streams and specs and dry-run dreams,
Tests that chase the tiniest beams,
Hooray — artifacts land just right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding drive preview and cover shortcuts, plus documenting quota details.
Description check ✅ Passed The description follows the template structure with all required sections completed: Summary describes motivation, Changes lists main updates, and Test Plan includes checkmarks for verification steps.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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-add-preview-cover-and-quota

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/XL Architecture-level or global-impact change labels Jun 4, 2026
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-add-preview-cover-and-quota -y -g

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.57290% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.75%. Comparing base (b3fcf55) to head (e60c285).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_preview_common.go 83.06% 40 Missing and 24 partials ⚠️
shortcuts/drive/drive_cover.go 84.00% 4 Missing and 4 partials ⚠️
shortcuts/drive/drive_preview.go 85.96% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1256      +/-   ##
==========================================
- Coverage   69.90%   69.75%   -0.16%     
==========================================
  Files         645      669      +24     
  Lines       60233    64900    +4667     
==========================================
+ Hits        42108    45268    +3160     
- Misses      14823    15991    +1168     
- Partials     3302     3641     +339     

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

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

78-125: ⚡ Quick win

Add a dry-run E2E for drive +cover --list-only.

This file only exercises the cover download branch, but shortcuts/drive/drive_cover.go:48-56 has a separate --list-only dry-run path with a different contract (mode=list, precomputed candidates, and no API call). A regression there would currently ship untested.

Based on learnings, "Dry-run E2E tests required for every shortcut change must validate request structure without calling real APIs and be placed in tests/cli_e2e/dryrun/ or domain directory, using --dry-run flag".

🤖 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_preview_dryrun_test.go` around lines 78 - 125, Add
a new dry-run E2E that covers the `--list-only` branch in the drive cover
shortcut: create a test (e.g. TestDriveCoverDryRun_ListOnly) alongside
TestDriveCoverDryRun_Download under tests/cli_e2e/dryrun or the drive domain
tests that calls clie2e.RunCmd with the same args but include "--list-only" (and
"--dry-run"), then assert there are no API calls (ensure api.0 does not exist),
assert the dry-run payload contains "mode" == "list" and that precomputed
"candidates" (and "selected_spec" if applicable) are present and correct; mirror
existing use of gjson.Get checks from TestDriveCoverDryRun_Download to validate
these fields rather than expecting a preview_download URL. Reference
TestDriveCoverDryRun_Download, clie2e.RunCmd, and the drive_cover.go dry-run
`--list-only` path (mode=list, candidates) when adding assertions.
🤖 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_preview_common.go`:
- Around line 620-634: The fallback mapping in drivePreviewFallbackExt
incorrectly returns ".png" for "jpg" and "jpg_lin"; update the switch in
drivePreviewFallbackExt to return ".jpg" for cases "jpg" and "jpg_lin" (while
keeping "png" and related cases returning ".png") so that
normalizeDrivePreviewRequest-driven preview types produce the correct fallback
extension used by DrivePreview.Execute and download paths.

In `@tests/cli_e2e/drive/drive_preview_workflow_test.go`:
- Around line 230-236: The test currently only inspects result.Stderr to detect
a missing bot scope and skip the test, but commands surface errors in the JSON
envelope on stdout; update the skip logic in the failing-path block that checks
result.ExitCode and result.Stderr to also inspect result.Stdout (lowercased) for
the same markers ("app scope not enabled", "space:folder:create",
"99991672")—e.g., build a combined lowercase string from result.Stdout and
result.Stderr or check both separately, and use that to decide t.Skipf so
missing-scope failures returned on stdout are correctly skipped; locate this
logic around the result variable in drive_preview_workflow_test.go.

---

Nitpick comments:
In `@tests/cli_e2e/drive/drive_preview_dryrun_test.go`:
- Around line 78-125: Add a new dry-run E2E that covers the `--list-only` branch
in the drive cover shortcut: create a test (e.g. TestDriveCoverDryRun_ListOnly)
alongside TestDriveCoverDryRun_Download under tests/cli_e2e/dryrun or the drive
domain tests that calls clie2e.RunCmd with the same args but include
"--list-only" (and "--dry-run"), then assert there are no API calls (ensure
api.0 does not exist), assert the dry-run payload contains "mode" == "list" and
that precomputed "candidates" (and "selected_spec" if applicable) are present
and correct; mirror existing use of gjson.Get checks from
TestDriveCoverDryRun_Download to validate these fields rather than expecting a
preview_download URL. Reference TestDriveCoverDryRun_Download, clie2e.RunCmd,
and the drive_cover.go dry-run `--list-only` path (mode=list, candidates) when
adding assertions.
🪄 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: 5933b3d6-ab48-4120-b96c-0abb0d9eabc6

📥 Commits

Reviewing files that changed from the base of the PR and between 8ce3879 and e60c285.

📒 Files selected for processing (11)
  • shortcuts/drive/drive_cover.go
  • shortcuts/drive/drive_preview.go
  • shortcuts/drive/drive_preview_common.go
  • shortcuts/drive/drive_preview_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-cover.md
  • skills/lark-drive/references/lark-drive-preview.md
  • tests/cli_e2e/drive/drive_preview_dryrun_test.go
  • tests/cli_e2e/drive/drive_preview_workflow_test.go

Comment thread shortcuts/drive/drive_preview_common.go
Comment thread tests/cli_e2e/drive/drive_preview_workflow_test.go
- add `drive +preview` and `drive +cover` shortcuts
- wrap `preview_result` output with stable preview item fields
- support cover download via `preview_download` with validated preset mappings
- update lark-drive skill references for preview and cover usage
@zhoujunteng-max
zhoujunteng-max force-pushed the feat/drive-add-preview-cover-and-quota branch from e60c285 to a4af3a3 Compare June 4, 2026 04:57
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/XL Architecture-level or global-impact change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant