Skip to content

feat: support wiki sources in drive export#1802

Merged
wittam-01 merged 1 commit into
mainfrom
feat/drive-export-wiki-source
Jul 13, 2026
Merged

feat: support wiki sources in drive export#1802
wittam-01 merged 1 commit into
mainfrom
feat/drive-export-wiki-source

Conversation

@wittam-01

@wittam-01 wittam-01 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Support Wiki and URL inputs in drive +export so agents can pass document URLs or bare Wiki node tokens without guessing the underlying doc_type. This resolves Wiki nodes to obj_token / obj_type before export and adds actionable validation hints for unsupported export format combinations.

Changes

  • Add --url and --doc-type wiki support to drive +export, including Wiki URL pre-resolution and bare Wiki token fallback after file token invalid.
  • Add client-side export format compatibility validation with typed error hints for agent retry guidance.
  • Update lark-drive skill docs and dry-run coverage for Wiki URL and Wiki token export flows.

Test Plan

  • Unit tests pass
    • go test ./shortcuts/drive -run 'TestValidateDriveExportSpec|TestDriveExport' -count=1\n - go test ./shortcuts/sheets -run 'WorkbookExport|SheetExport' -count=1\n- [x] Manual local verification confirms the lark-cli <domain> <command> flow works as expected\n - go build -o /tmp/lark-cli-export-wiki-test .\n - LARK_CLI_BIN=/tmp/lark-cli-export-wiki-test go test ./tests/cli_e2e/drive -run 'TestDriveExportDryRun' -count=1\n - LARK_CLI_BIN=/tmp/lark-cli-export-wiki-test go test ./tests/cli_e2e/sheets -run 'WorkbookExportDryRun' -count=1\n - git diff --check\n - gofmt -l shortcuts/drive/drive_export.go shortcuts/drive/drive_export_common.go shortcuts/drive/drive_export_test.go tests/cli_e2e/drive/drive_export_dryrun_test.go\n\n## Related Issues\n- None

Summary by CodeRabbit

  • New Features

    • drive +export can export directly from --url, automatically inferring the document type and token.
    • Wiki exports now perform required Wiki node resolution before creating export tasks, with wiki context included in outputs.
  • Bug Fixes

    • Improved validation and compatibility checks, including better errors and hints for unsupported formats.
    • Enhanced fallback/retry behavior (e.g., when an incorrect token/type triggers “file token invalid”).
  • Documentation

    • Updated Drive export docs and usage rules to recommend --url and explain Wiki handling and retry guidance.

@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 Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4782cf33-c596-4cc6-ab4b-77452a7358fb

📥 Commits

Reviewing files that changed from the base of the PR and between 268ae1b and c7345a6.

📒 Files selected for processing (7)
  • shortcuts/drive/drive_export.go
  • shortcuts/drive/drive_export_common.go
  • shortcuts/drive/drive_export_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-export.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_export_dryrun_test.go
 _________________________________________
< Tensor cores warmed; bug cores chilled. >
 -----------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
📝 Walkthrough

Walkthrough

Adds URL-driven token/doc-type inference and wiki node resolution to drive +export. The command now normalizes input, validates wiki-aware export specs, retries task creation through wiki resolution when needed, annotates outputs with wiki metadata, and updates tests and docs.

Changes

Drive export URL and wiki resolution

Layer / File(s) Summary
Export spec, params, and command config
shortcuts/drive/drive_export.go, shortcuts/drive/drive_export_common.go
Adds URL to ExportParams/driveExportSpec, updates DriveExport flags and conditional scopes, and introduces input-source/wiki-resolution structs plus export-type constants.
Normalization and validation pipeline
shortcuts/drive/drive_export_common.go
Adds normalization-first validation, URL parsing and token/type inference, source-aware wiki validation, and extension/format compatibility checks.
Task creation and wiki resolution/fallback
shortcuts/drive/drive_export_common.go
Moves export-task body construction into a helper, resolves wiki nodes through get_node, and adds wiki fallback retry gating for export-task creation.
Dry-run planning and execution wiring
shortcuts/drive/drive_export.go
Reworks dry-run and runtime export flows to resolve wiki sources, drive markdown/export paths, and annotate results with wiki token/node metadata.
Unit and integration tests
shortcuts/drive/drive_export_test.go, tests/cli_e2e/drive/drive_export_dryrun_test.go
Expands validation coverage and adds URL, wiki resolution, fallback, mismatch, and dry-run sequencing tests.
Skill and coverage documentation
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-export.md, tests/cli_e2e/drive/coverage.md
Updates usage guidance, compatibility rules, and dry-run coverage notes for --url and wiki handling.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Validator
  participant WikiAPI as Wiki get_node API
  participant DriveAPI as Drive export_tasks API

  CLI->>Validator: normalizeDriveExportSpecInput / validateDriveExportSpec
  Validator-->>CLI: normalized spec and input source
  alt wiki source
    CLI->>WikiAPI: GET get_node(wiki token)
    WikiAPI-->>CLI: obj_token, obj_type
    CLI->>DriveAPI: POST export_tasks(resolved token/type)
  else non-wiki source
    CLI->>DriveAPI: POST export_tasks(token/type)
    DriveAPI-->>CLI: file token invalid
    CLI->>WikiAPI: GET get_node(fallback token)
    WikiAPI-->>CLI: obj_token, obj_type
    CLI->>DriveAPI: POST export_tasks(resolved token/type)
  end
  DriveAPI-->>CLI: task result
  CLI->>CLI: annotateDriveExportWikiOutput(output, wikiResolution)
Loading

Possibly related PRs

  • larksuite/cli#194: Extends the same drive +export validation and planning flow in shortcuts/drive/drive_export*.go.
  • larksuite/cli#947: Adds URL/resource parsing and metadata helpers that align with the wiki-aware export flow here.
  • larksuite/cli#948: Touches the Markdown export path that this PR now routes through wiki resolution.

Suggested reviewers: fangshuyu-768

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% 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 is concise and clearly matches the main change: adding Wiki source support to drive export.
Description check ✅ Passed The description follows the template with Summary, Changes, Test Plan, and Related Issues, and it is sufficiently detailed.
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.
✨ 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-export-wiki-source

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.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.79863% with 109 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.40%. Comparing base (f0b6f35) to head (c7345a6).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_export_common.go 65.53% 64 Missing and 17 partials ⚠️
shortcuts/drive/drive_export.go 51.72% 20 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1802      +/-   ##
==========================================
- Coverage   74.46%   74.40%   -0.06%     
==========================================
  Files         855      860       +5     
  Lines       88568    90105    +1537     
==========================================
+ Hits        65954    67045    +1091     
- Misses      17543    17855     +312     
- Partials     5071     5205     +134     

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

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-export-wiki-source -y -g

@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: 1

🧹 Nitpick comments (1)
shortcuts/drive/drive_export_common.go (1)

493-528: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the retriable error code into a named constant.

1069914 (file-token-invalid) is a magic number; a named constant near the other export constants would document intent and make the retry gate self-explanatory.

🤖 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_export_common.go` around lines 493 - 528, The retry
gate in shouldRetryDriveExportAsWiki currently compares against the magic error
code 1069914 directly; extract that value into a named constant near the other
drive export constants and use it in shouldRetryDriveExportAsWiki so the intent
is self-explanatory. Keep the existing behavior in
createDriveExportTaskWithWikiFallback and the retry check unchanged aside from
referencing the new constant.
🤖 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_export.go`:
- Around line 186-188: The dry-run hint logic in drive_export.go is too broad:
it currently sets wiki_token_fallback for every non-URL source, which
incorrectly includes bare wiki sources handled by source.Type and
createDriveExportTaskWithWikiFallback. Update the condition around dry.Set so
the hint is only emitted for the actual fallback path, excluding the direct wiki
branch used when --doc-type wiki is resolved up front.

---

Nitpick comments:
In `@shortcuts/drive/drive_export_common.go`:
- Around line 493-528: The retry gate in shouldRetryDriveExportAsWiki currently
compares against the magic error code 1069914 directly; extract that value into
a named constant near the other drive export constants and use it in
shouldRetryDriveExportAsWiki so the intent is self-explanatory. Keep the
existing behavior in createDriveExportTaskWithWikiFallback and the retry check
unchanged aside from referencing the new constant.
🪄 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: c5fe9272-52fc-4556-b19a-ab49d67efc92

📥 Commits

Reviewing files that changed from the base of the PR and between 9413e7c and faa7a92.

📒 Files selected for processing (7)
  • shortcuts/drive/drive_export.go
  • shortcuts/drive/drive_export_common.go
  • shortcuts/drive/drive_export_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-export.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_export_dryrun_test.go

Comment thread shortcuts/drive/drive_export.go Outdated
@wittam-01
wittam-01 force-pushed the feat/drive-export-wiki-source branch from faa7a92 to 268ae1b Compare July 9, 2026 13:14
@wittam-01
wittam-01 force-pushed the feat/drive-export-wiki-source branch from 268ae1b to c7345a6 Compare July 9, 2026 13:59
@wittam-01
wittam-01 merged commit 35049e8 into main Jul 13, 2026
26 checks passed
@wittam-01
wittam-01 deleted the feat/drive-export-wiki-source branch July 13, 2026 11:50
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 13, 2026
3 tasks
liangshuo-1 added a commit that referenced this pull request Jul 14, 2026
* fix: unify dry-run output contract

* fix: address dry-run review feedback

* fix(dryrun): tighten preview contract and unify data shape

- transcribe HTTP method verbatim in previews (HEAD/OPTIONS were
  reported as GET); reject an empty method in api with a typed error
- unify the dry-run data payload across api/service/shortcut paths:
  {api, context?: {app_id, user_open_id}}; drop data.as — the envelope
  top-level identity is the single identity source
- mark pretty dry-run stdout with '# dry-run: request not sent' so logs
  that drop stderr still show it was a preview
- extract the shared preview builder, collapse PrintDryRunWithFile's
  loose params into FileUploadMeta, and fail loudly on nil previews
- revert description-marker identity parsing: stale prose must not
  override corrected accessTokens (blocks legal user calls on
  images.create); identity gating keys off accessTokens only
- pin the new contracts with tests: verbatim method, three-way context
  parity, nil-preview error, empty-context omission, marker line

* docs(agents): add typed-data, faithful-transcription, and contract-test conventions

- typed struct at the boundary over map[string]interface{} threading;
  distinct types where values could swap silently (internal/meta.Token)
- transcribe input verbatim in previews/transformations; reject
  unhonorable flag combinations with typed errors instead of silently
  substituting behavior
- contract tests must fail when the implementation is reverted

* test: migrate dry-run tests grown on main to the envelope format

main gained raw-format dry-run readers while the PR was in flight
(wiki drive export #1802, drive list comments #1845, slash commands,
sheets history, docs fetch, mail draft-send/triage, vc meeting events).
Migrate them to the envelope accessors (clie2e.DryRunGet / data-wrapped
decoders) and drop the now-redundant DryRunData extractions in files
unified on DryRunGet.

---------

Co-authored-by: guokexin.02 <264159873+Tantanz20020918@users.noreply.github.com>
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.

2 participants