Skip to content

feat: add drive version shortcut#841

Open
wittam-01 wants to merge 1 commit into
mainfrom
feat/drive-version-shortcuts
Open

feat: add drive version shortcut#841
wittam-01 wants to merge 1 commit into
mainfrom
feat/drive-version-shortcuts

Conversation

@wittam-01
Copy link
Copy Markdown
Collaborator

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

• ## Summary
Add Drive file version shortcuts so agents can list, download, revert, and delete historical file versions through shortcut UX instead of raw API calls. This PR also adds documentation and test coverage for the new workflow.

Changes

  • Add Drive version shortcuts: drive +version-history, drive +version-get, drive +version-revert, and drive +version-delete
  • Add validation, dry-run support, bot/user auth support, structured output, and local file handling for the new Drive version shortcuts
  • Update the lark-drive skill references for the new shortcuts
  • Add unit tests plus dry-run/live E2E coverage for the Drive version shortcut workflow

Test Plan

  • Unit tests pass (go test ./shortcuts/drive -run TestDriveVersion -count=1)
  • Manual local verification confirms the lark xxx command works as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Drive file version management: view paginated version history, download specific versions (stdout or file, with overwrite and directory handling), revert to a prior version, and delete versions.
  • Documentation

    • Added reference guides and workflow notes for the new version-management commands with examples and parameter details.
  • Tests

    • Added unit, integration, and end-to-end dry-run tests covering history, download, revert, delete, and workflow scenarios.

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 12, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ea0b2bcf-00a6-4d3f-9c2e-a37041f2472d

📥 Commits

Reviewing files that changed from the base of the PR and between b36b07c and cdd96f3.

📒 Files selected for processing (12)
  • internal/core/types.go
  • shortcuts/drive/drive_version.go
  • shortcuts/drive/drive_version_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-version-delete.md
  • skills/lark-drive/references/lark-drive-version-get.md
  • skills/lark-drive/references/lark-drive-version-history.md
  • skills/lark-drive/references/lark-drive-version-revert.md
  • tests/cli_e2e/drive/drive_version_dryrun_test.go
  • tests/cli_e2e/drive/drive_version_workflow_test.go
✅ Files skipped from review due to trivial changes (6)
  • skills/lark-drive/references/lark-drive-version-history.md
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-version-revert.md
  • skills/lark-drive/references/lark-drive-version-delete.md
  • internal/core/types.go
  • shortcuts/drive/shortcuts.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • shortcuts/drive/shortcuts_test.go
  • tests/cli_e2e/drive/drive_version_dryrun_test.go
  • tests/cli_e2e/drive/drive_version_workflow_test.go
  • shortcuts/drive/drive_version.go
  • shortcuts/drive/drive_version_test.go

📝 Walkthrough

Walkthrough

Adds four Drive CLI shortcuts: +version-history, +version-get, +version-revert, +version-delete; updates endpoint resolution to pre-production domains; includes implementation, unit tests, E2E tests, and user documentation.

Changes

Drive Version Management Feature

Layer / File(s) Summary
Pre-production Endpoint Configuration
internal/core/types.go
Endpoint resolution now returns pre-production *.feishu-pre.cn domains for Open and Accounts services.
Drive Version Shortcuts Implementation & Registration
shortcuts/drive/drive_version.go, shortcuts/drive/shortcuts.go
Implements +version-history (paginated history with only_tag=true), +version-get (streamed download; stdout or saved file with overwrite rules), +version-revert (POST {version}), and +version-delete (POST {version}); registers shortcuts.
Unit Tests & Registry Updates
shortcuts/drive/drive_version_test.go, shortcuts/drive/shortcuts_test.go
Adds unit tests for validation, response transformation, download/save behavior (directory fallback, overwrite), mutation request capture, flag handling, and dry-run support; updates registry expectations.
Documentation & Reference Guides
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-version-*.md
Adds SKILL guidance and four reference pages documenting command syntax, flags, pagination, response schemas, and bot/user examples.
End-to-End Tests
tests/cli_e2e/drive/drive_version_dryrun_test.go, tests/cli_e2e/drive/drive_version_workflow_test.go
Dry-run tests validate serialized endpoints and JSON payloads; gated workflow E2E creates and overwrites a file, then verifies version-history retrieval.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI User
  participant Shortcut as Drive Shortcut
  participant DriveAPI as Drive API
  participant FileIO as File I/O

  CLI->>Shortcut: invoke +version-history / +version-get / +version-revert / +version-delete
  Shortcut->>DriveAPI: HTTP GET/POST to /open-apis/drive/v1/files/:file_token/...
  DriveAPI-->>Shortcut: JSON response or stream (headers + body)
  alt +version-get with --output
    Shortcut->>FileIO: resolve path, enforce overwrite, save stream
    FileIO-->>Shortcut: saved_path, size
  else stdout mode
    Shortcut-->>CLI: pretty JSON with content/file_name
  end
  Shortcut-->>CLI: JSON result (versions, has_more/next_cursor, or empty data)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#704: Also modifies internal/core/types.go to use pre-production *.feishu-pre.cn endpoints.
  • larksuite/cli#588: Adds/changes Drive shortcuts and touches shortcuts/drive/shortcuts.go.
  • larksuite/cli#432: Modifies drive shortcuts registry and adds Drive shortcut commands.

Suggested reviewers

  • fangshuyu-768
  • liujinkun2025

Poem

🐰 I hop through versioned file lands,
Fetching histories with tiny hands.
Download, revert, or wipe a trace,
Tests and docs keep every case.
Four shortcuts bloom—hope they run with grace.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% 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 summarizes the main change: adding Drive version shortcuts. It is concise, specific, and directly related to the primary objective of the PR.
Description check ✅ Passed The description follows the required template with all key sections completed: Summary explains the motivation, Changes lists the main additions, Test Plan confirms testing was performed with checkbox verification, and Related Issues is addressed.
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-version-shortcuts

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/cli_e2e/drive/drive_version_workflow_test.go (1)

75-86: ⚡ Quick win

Strengthen workflow assertion by validating returned history payload, not only success status.

Right now Line 84–85 only proves the command ran. Add assertions on data.versions (e.g., non-empty, and ideally at least one expected version marker) so this test verifies actual version-history behavior.

Example assertion enhancement
 	require.NoError(t, err)
 	historyResult.AssertExitCode(t, 0)
 	historyResult.AssertStdoutStatus(t, true)
+	require.GreaterOrEqual(t, len(gjson.Get(historyResult.Stdout, "data.versions").Array()), 1, "stdout:\n%s", historyResult.Stdout)

As per coding guidelines, “Live E2E tests required for new flows or behavior changes must validate real API round-trips.”

🤖 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_version_workflow_test.go` around lines 75 - 86, The
test currently only checks exit code and success status for the
"+version-history" CLI call (historyResult from clie2e.RunCmd); enhance it to
parse and validate the returned payload: unmarshal historyResult.Stdout (or the
captured output) into a struct/map and assert that the "data.versions" field
exists, is non-empty, and contains at least one expected version marker (e.g., a
known version ID or timestamp). Update the test around
historyResult.AssertStdoutStatus to decode the JSON response and add assertions
on data.versions (referencing historyResult and clie2e.RunCmd) to ensure the
workflow actually returns version history rather than just succeeding.
🤖 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 `@internal/core/types.go`:
- Around line 45-46: The default BrandFeishu Open and Accounts URLs were changed
to pre-prod hosts causing risky global behavior; revert the BrandFeishu default
Open and Accounts values back to the production endpoints and instead add an
explicit option for pre-prod (e.g., a new BrandFeishuPre constant or an
environment/flag check) so callers can opt into pre-prod. Locate the BrandFeishu
definition (symbols: BrandFeishu, Open, Accounts) in internal/core/types.go,
restore the prod URLs for Open and Accounts, and add a clear opt-in path (new
constant, factory function, or env-driven branch) that sets the pre-prod URLs
only when explicitly requested. Ensure unknown/unspecified brands continue to
use the safe prod defaults.

---

Nitpick comments:
In `@tests/cli_e2e/drive/drive_version_workflow_test.go`:
- Around line 75-86: The test currently only checks exit code and success status
for the "+version-history" CLI call (historyResult from clie2e.RunCmd); enhance
it to parse and validate the returned payload: unmarshal historyResult.Stdout
(or the captured output) into a struct/map and assert that the "data.versions"
field exists, is non-empty, and contains at least one expected version marker
(e.g., a known version ID or timestamp). Update the test around
historyResult.AssertStdoutStatus to decode the JSON response and add assertions
on data.versions (referencing historyResult and clie2e.RunCmd) to ensure the
workflow actually returns version history rather than just succeeding.
🪄 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: e0388c04-6384-48cd-af91-283dfc5f9373

📥 Commits

Reviewing files that changed from the base of the PR and between db1a3fc and 0983192.

📒 Files selected for processing (12)
  • internal/core/types.go
  • shortcuts/drive/drive_version.go
  • shortcuts/drive/drive_version_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-version-delete.md
  • skills/lark-drive/references/lark-drive-version-get.md
  • skills/lark-drive/references/lark-drive-version-history.md
  • skills/lark-drive/references/lark-drive-version-revert.md
  • tests/cli_e2e/drive/drive_version_dryrun_test.go
  • tests/cli_e2e/drive/drive_version_workflow_test.go

Comment thread internal/core/types.go
Comment on lines +45 to +46
Open: "https://open.feishu-pre.cn",
Accounts: "https://accounts.feishu-pre.cn",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Default Feishu endpoint now points to pre-prod hosts, which is high-risk global behavior change.

Line 45 and Line 46 switch the default BrandFeishu Open/Accounts base URLs to *.feishu-pre.cn, while other services still use prod. Since unknown brands also fall back here, this can break normal auth/API flows outside test environments.

Suggested safer change
 default:
 	return Endpoints{
-		Open:     "https://open.feishu-pre.cn",
-		Accounts: "https://accounts.feishu-pre.cn",
+		Open:     "https://open.feishu.cn",
+		Accounts: "https://accounts.feishu.cn",
 		MCP:      "https://mcp.feishu.cn",
 		AppLink:  "https://applink.feishu.cn",
 	}

If pre endpoints are required, consider introducing an explicit brand/env switch instead of changing the default branch.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Open: "https://open.feishu-pre.cn",
Accounts: "https://accounts.feishu-pre.cn",
Open: "https://open.feishu.cn",
Accounts: "https://accounts.feishu.cn",
🤖 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 `@internal/core/types.go` around lines 45 - 46, The default BrandFeishu Open
and Accounts URLs were changed to pre-prod hosts causing risky global behavior;
revert the BrandFeishu default Open and Accounts values back to the production
endpoints and instead add an explicit option for pre-prod (e.g., a new
BrandFeishuPre constant or an environment/flag check) so callers can opt into
pre-prod. Locate the BrandFeishu definition (symbols: BrandFeishu, Open,
Accounts) in internal/core/types.go, restore the prod URLs for Open and
Accounts, and add a clear opt-in path (new constant, factory function, or
env-driven branch) that sets the pre-prod URLs only when explicitly requested.
Ensure unknown/unspecified brands continue to use the safe prod defaults.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-version-shortcuts -y -g

@wittam-01 wittam-01 force-pushed the feat/drive-version-shortcuts branch from 0983192 to b36b07c Compare May 12, 2026 08:55
Change-Id: I87bb32c86e3c3362f541ccc6320c656eb795ec9b
@wittam-01 wittam-01 force-pushed the feat/drive-version-shortcuts branch from b36b07c to cdd96f3 Compare May 12, 2026 09:03
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.

1 participant