Skip to content

fix(slides): build create URL locally instead of drive metas call#1329

Merged
fangshuyu-768 merged 1 commit into
mainfrom
fix/slides-create-drive-meta-scope
Jun 9, 2026
Merged

fix(slides): build create URL locally instead of drive metas call#1329
fangshuyu-768 merged 1 commit into
mainfrom
fix/slides-create-drive-meta-scope

Conversation

@ViperCai

@ViperCai ViperCai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Background

While analyzing slides:+create failure telemetry (2026-06-07), the single largest fixable cluster was the post-creation URL lookup, not the creation itself.

slides +create ended its flow with a call to /open-apis/drive/v1/metas/batch_query purely to fetch the presentation URL (slides_create.go, Execute). That call needs a drive scope that the shortcut never declares, so it failed for two populations:

  • UserAccessToken99991679 (user hasn't authorized drive:drive / drive:drive.metadata:readonly)
  • TenantAccessToken99991672 (app hasn't opened the drive scope)

Together these accounted for ~64 failure events (~34% of the shortcut's failures) in the sample — even though in almost all cases the presentation was already created successfully and only this best-effort enrichment call failed. It inflated failure counts and dropped the url from the result.

Why not just declare the drive scope?

markdown +create / drive +upload do declare drive:drive.metadata:readonly — but their core operation is a drive upload (drive:file:upload is mandatory anyway), so the read scope is a free add-on. slides creation goes through slides_ai and never otherwise touches drive, so requiring a drive scope would gate an otherwise drive-free operation and block creation at preflight for users who only authorized slides scopes. That's a worse trade than the bug.

Fix

Drop the drive call entirely and build the URL locally from the token via common.BuildResourceURL(runtime.Config.Brand, "slides", presentationID) — the same brand-standard-host fallback already used by drive +upload, wiki +node-create, and sheets. The host transparently redirects to the tenant domain.

Result:

  • No drive API call → the ~64 failures disappear for both identities.
  • No extra scope required; preflight scope set is unchanged.
  • Creation never blocks on the URL.
  • url is always returned.

Scope / out of scope

  • This addresses problem B (missing-scope drive call) only.
  • The remaining TenantAccessToken slides:presentation:create failures stem from silent bot-identity fallback (problem A) and are not in this PR.

Diff

shortcuts/slides/slides_create.go: +11 / −23 (remove inline metas/batch_query block → BuildResourceURL; comment note on why no drive scope).

Testing

  • lark-cli slides +create returns a working url without any drive scope granted.
  • No /drive/v1/metas/batch_query call is made (verify via --dry-run / network trace).

Summary by CodeRabbit

  • Bug Fixes

    • Clarified pre-flight authorization so slide creation no longer requires drive scope.
  • Refactor

    • Presentation URLs are now deterministically constructed locally, removing best-effort drive lookups and improving reliability.
  • Tests

    • Updated and added tests to assert locally-built slide URLs and remove reliance on drive metadata stubs.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24483aa2-df22-49b3-a09b-c220bfc5669c

📥 Commits

Reviewing files that changed from the base of the PR and between 050643a and 7156a2b.

📒 Files selected for processing (2)
  • shortcuts/slides/slides_create.go
  • shortcuts/slides/slides_create_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/slides/slides_create.go
  • shortcuts/slides/slides_create_test.go

📝 Walkthrough

Walkthrough

SlidesCreate now constructs presentation URLs locally (via common.BuildResourceURL) and documents that no drive scope is required; tests were updated to expect locally built URLs and removed drive metas/batch_query stubbing.

Changes

Slides URL Resolution

Layer / File(s) Summary
URL resolution refactor and docs
shortcuts/slides/slides_create.go
Inline docs updated to state SlidesCreate avoids drive scope. Execute now calls common.BuildResourceURL(runtime.Config.Brand, "slides", presentationID) and assigns the returned URL to result["url"] when non-empty, removing the prior drive metas/batch_query success-path.
Tests updated to expect local URLs
shortcuts/slides/slides_create_test.go
Multiple +create tests removed registerBatchQueryStub usage. TestSlidesCreateBasic asserts the locally constructed Feishu slides host; a new TestSlidesCreateURLBuiltLocally verifies URL construction without any batch_query stubs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#425: Adds the drive metadata lookup for result["url"] that this PR removes in favor of local URL construction.
  • larksuite/cli#680: Introduces and uses common.BuildResourceURL for creating brand-standard resource URLs, similar to this change.

Suggested labels

size/M

Suggested reviewers

  • fangshuyu-768

Poem

🐰 I built a link with brand and pride,
No drive to ping, no stub to hide.
A tidy URL hops into view,
Tests adjusted — steady and true.
Hooray, the slides now link anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing a drive metas call for URL lookup and replacing it with local URL construction.
Description check ✅ Passed The description includes all required sections: Summary (background and fix motivation), Changes (specific modifications to code), Testing (verification steps), and Related Issues. The content is detailed and complete.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% 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 fix/slides-create-drive-meta-scope

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 commented Jun 8, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#fix/slides-create-drive-meta-scope -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

🤖 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/slides/slides_create.go`:
- Around line 211-219: Update the tests to match the new local URL construction
behavior: remove or stop using registerBatchQueryStub calls in
slides_create_test.go (tests should no longer assume
/open-apis/drive/v1/metas/batch_query is called), update TestSlidesCreateBasic's
expected presentation URL to use the brand host returned by
common.BuildResourceURL (e.g. change expected https://example.feishu.cn/... to
https://www.feishu.cn/...), and modify TestSlidesCreateURLFetchBestEffort to
assert that result["url"] is present (since common.BuildResourceURL now always
sets the url) instead of expecting no url.
🪄 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: 4b6324c9-e27f-47d3-b4c1-821e41079b2f

📥 Commits

Reviewing files that changed from the base of the PR and between 8f5504c and 70dca2c.

📒 Files selected for processing (1)
  • shortcuts/slides/slides_create.go

Comment thread shortcuts/slides/slides_create.go
fangshuyu-768
fangshuyu-768 previously approved these changes Jun 8, 2026
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.47%. Comparing base (99ceb22) to head (7156a2b).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1329      +/-   ##
==========================================
- Coverage   71.47%   71.47%   -0.01%     
==========================================
  Files         688      688              
  Lines       65482    65467      -15     
==========================================
- Hits        46806    46791      -15     
  Misses      15031    15031              
  Partials     3645     3645              

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

slides +create finished by calling /drive/v1/metas/batch_query just to
fetch the presentation URL. That call needs a drive scope the shortcut
never declares, so it 403'd for users who only authorized slides scopes
(both UserAccessToken re-auth and TenantAccessToken scope-not-opened),
producing a large share of the shortcut's failure telemetry — even though
the presentation itself was already created successfully.

slides creation never otherwise touches drive, so rather than gating a
drive-free operation behind a drive scope, build the URL locally from the
token via common.BuildResourceURL (the same brand-standard-host fallback
already used by drive +upload / wiki +node-create). The URL is now always
returned, no extra scope is required, and creation never blocks.

Tests are updated to match: drop the registerBatchQueryStub helper and its
call sites (the httpmock Verify cleanup was failing on the now-unconsumed
batch_query stubs), point url assertions at the brand-standard host, and
replace TestSlidesCreateURLFetchBestEffort with TestSlidesCreateURLBuiltLocally,
which asserts the url is produced with no drive call registered.
@ViperCai ViperCai force-pushed the fix/slides-create-drive-meta-scope branch from 050643a to 7156a2b Compare June 9, 2026 03:17
@fangshuyu-768 fangshuyu-768 merged commit ed3fe93 into main Jun 9, 2026
21 checks passed
@fangshuyu-768 fangshuyu-768 deleted the fix/slides-create-drive-meta-scope branch June 9, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants