Skip to content

feat(drive): add modified-time smart sync mode#859

Open
fangshuyu-768 wants to merge 1 commit into
mainfrom
feat/drive-push-smart-if-exists
Open

feat(drive): add modified-time smart sync mode#859
fangshuyu-768 wants to merge 1 commit into
mainfrom
feat/drive-push-smart-if-exists

Conversation

@fangshuyu-768
Copy link
Copy Markdown
Collaborator

@fangshuyu-768 fangshuyu-768 commented May 13, 2026

Summary

This PR implements the first roadmap feature point for Drive sync efficiency by adding a new smart mode for the existing --if-exists policy.

--if-exists=smart is a best-effort incremental optimization based on modified_time, not a content-hash equality check. It skips redundant transfers when timestamps already show the target side is up to date, and falls back to the safe transfer path when the metadata cannot be trusted.

Changes

  • Add smart as a new --if-exists mode for drive +push and skip uploads when Drive modified_time already matches or is newer than the local file mtime.
  • Add smart as a new --if-exists mode for drive +pull and skip downloads when the local file mtime already matches or is newer than Drive modified_time.
  • Preserve the remote modified_time on downloaded local files so repeated drive +pull --if-exists=smart runs stay stable.
  • Add shared Drive epoch parsing and comparison helpers so second-, millisecond-, and microsecond-based timestamps behave consistently.
  • Remove size-based smart-mode checks after verifying that the Drive listing metadata used by this flow does not provide a trustworthy size field for this purpose.
  • Extend unit tests for push and pull smart-mode skip and transfer behavior, plus timestamp parsing edge cases and metadata fallback coverage.
  • Add dry-run end-to-end coverage to ensure smart is accepted by both drive +push and drive +pull.
  • Update shortcut docs and skill references to describe the final modified-time-based smart sync semantics.

Design Notes

  • smart is intentionally a best-effort optimization, not a strict content-equality guarantee.
  • On pull, the CLI preserves the remote modified_time on downloaded local files to keep repeated smart syncs stable.
  • On push, the remote modified_time remains server-controlled, so the CLI can only compare against it, not rewrite it.

Test Plan

  • Unit tests pass
  • Manual local verification confirms the CLI commands work as expected
  • go test ./shortcuts/drive
  • go test ./tests/cli_e2e/drive
  • go vet ./...
  • make unit-test
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main

Related Issues

  • None

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a smart mode for Drive --if-exists in push and pull that uses remote epoch parsing and resolution-aware modified-time comparison (plus optional size checks) to decide skip vs transfer; includes helpers, unit and e2e tests, and documentation updates.

Changes

Smart --if-exists implementation for Drive push/pull

Layer / File(s) Summary
Timestamp parsing and comparison helpers
shortcuts/drive/list_remote.go, shortcuts/drive/drive_duplicate_remote_test.go
Added parseDriveEpoch to parse Drive epoch strings (inferring seconds/milliseconds/microseconds) and compareDriveRemoteModifiedToLocal to compare remote vs local times with resolution truncation. Unit tests validate epoch handling and invalid inputs.
Drive pull smart mode
shortcuts/drive/drive_pull.go, shortcuts/drive/drive_pull_test.go
Added smart to --if-exists, extended drivePullTarget to carry ModifiedTime, populated remote metadata in remote-view paths, and implemented drivePullShouldSkipSmart which resolves local path, stats local ModTime, requires remote ModifiedTime, and skips only when local is at least as new under remote resolution. Added tests for skip, download, and fallback cases.
Drive push smart mode
shortcuts/drive/drive_push.go, shortcuts/drive/drive_push_test.go
Added smart to --if-exists, recorded local ModTime during file walk, and routed skip decisions through drivePushShouldSkipExisting/drivePushShouldSkipSmart which call compareDriveRemoteModifiedToLocal; smart falls back to upload on parse/stat failures. Added tests for skip, overwrite, and fallback behavior.
End-to-end dry-run tests
tests/cli_e2e/drive/drive_pull_dryrun_test.go, tests/cli_e2e/drive/drive_push_dryrun_test.go
Added dry-run tests verifying --if-exists smart is accepted and generates expected dry-run envelopes (HTTP method GET and the expected folder token).
Documentation updates
skills/lark-drive/*, skills/lark-drive/references/*
Rewrote SKILL and reference docs to document --if-exists=smart semantics, summary.skipped behavior, examples, and performance guidance for push/pull.

Sequence Diagram(s)

The diagrams embedded in the hidden review stack artifact visualize the timestamp parsing flow and the smart skip decision sequences for pull and push.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#709: Related work on drive +push and --if-exists behavior that also touches skip/overwrite decisions.
  • larksuite/cli#803: Related changes around Drive epoch timestamp handling and duplicate-remote tests.
  • larksuite/cli#696: Previous drive +pull work extended by this PR to add smart mtime-based comparisons.

Suggested reviewers

  • wittam-01
  • zhouyue-bytedance

🐰 I nibbled timestamps, tiny and grand,
Smart mode now checks time with careful hand.
If local time is equal or a tad more new,
Skip the transfer — no needless chew.
Hop — syncs are clever, light, and true.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% 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
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.
Title check ✅ Passed The title 'feat(drive): add modified-time smart sync mode' directly and clearly describes the main change: introducing a smart sync mode based on modified-time comparison for Drive operations.
Description check ✅ Passed The description is comprehensive and well-structured. It includes a clear summary, detailed changes covering both push and pull implementations, design notes explaining the best-effort approach, and a completed test plan with all checkboxes marked.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/drive-push-smart-if-exists

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/M Single-domain feat or fix with limited business impact labels May 13, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 90.27778% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.93%. Comparing base (62ff3d6) to head (74b6c94).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_pull.go 81.81% 3 Missing and 3 partials ⚠️
shortcuts/drive/drive_push.go 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #859      +/-   ##
==========================================
+ Coverage   65.87%   65.93%   +0.06%     
==========================================
  Files         518      518              
  Lines       48814    48895      +81     
==========================================
+ Hits        32157    32240      +83     
+ Misses      13890    13885       -5     
- Partials     2767     2770       +3     

☔ 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
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-push-smart-if-exists -y -g

@fangshuyu-768 fangshuyu-768 force-pushed the feat/drive-push-smart-if-exists branch from f12883b to a1c22f0 Compare May 13, 2026 07:08
@github-actions github-actions Bot added size/L Large or sensitive change across domains or core paths and removed size/M Single-domain feat or fix with limited business impact labels May 13, 2026
@fangshuyu-768 fangshuyu-768 force-pushed the feat/drive-push-smart-if-exists branch 3 times, most recently from 9770cfd to 9b93fbf Compare May 13, 2026 09:08
@fangshuyu-768 fangshuyu-768 changed the title feat(drive): add smart if-exists incremental sync mode feat(drive): add modified-time smart sync mode May 13, 2026
Add --if-exists=smart to Drive push and pull so repeated folder syncs can skip transfers when modified_time shows the target copy is already up to date. The mode is intentionally best-effort, and the pull path preserves the remote modified_time on downloaded local files to keep repeated smart syncs stable while aligning the implementation, tests, and skill docs with the real Drive metadata contract.
@fangshuyu-768 fangshuyu-768 force-pushed the feat/drive-push-smart-if-exists branch from 9b93fbf to 74b6c94 Compare May 13, 2026 09:24
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