Skip to content

fix: honor requiredScopes conjunction in CollectScopesForProjects#1878

Open
dc-bytedance wants to merge 1 commit into
mainfrom
fix/collect-scopes-required-scopes
Open

fix: honor requiredScopes conjunction in CollectScopesForProjects#1878
dc-bytedance wants to merge 1 commit into
mainfrom
fix/collect-scopes-required-scopes

Conversation

@dc-bytedance

@dc-bytedance dc-bytedance commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

CollectScopesForProjects collected only the single highest-priority scope (bestScope) per API method, dropping the rest of a method's requiredScopes conjunction, and diverging from CollectCommandScopes, which already resolves scopes via DeclaredScopesForMethod.

This is a latent defect, not an active user-visible failure. In the current runtime catalog only the mail message get / batch_get methods declare requiredScopes (readonly + subject:read + address:read + body:read). On the single production path that calls CollectScopesForProjectsauth login's domain→scope resolution — the result is unioned with the mail read shortcuts' scopes (mail +message, +messages, +thread, …), which declare the same subject/address/body:read set, so today the requested scope set is identical with or without this fix. But requiredScopes is server-side meta that takes effect without a CLI release: the moment a method with no shortcut coverage gains requiredScopes, the under-collection becomes user-visible. This change makes the correct behavior a property of the code rather than a coincidence of the current shortcut declarations.

Changes

  • CollectScopesForProjects now resolves scopes via DeclaredScopesForMethod (the single policy source): it returns a method's full requiredScopes set when declared, and otherwise falls back to the recommended single scope. For methods that declare no requiredScopes the fallback is the same bestScope / LoadScopePriorities path as before, so the output is byte-identical — the behavior change is strictly limited to methods that declare requiredScopes.
  • Impact is bounded: only two methods in the current production meta declare requiredScopes, so a collected set grows by at most three scopes. LoadScopePriorities is package-cached, so resolving per method inside the loop adds no performance regression.

Test Plan

  • go test ./internal/registry/... passes
  • Added TestCollectScopesForProjects_HonorsRequiredScopes, which asserts the mail message required scopes are collected (runs in CI, not skipped) and pins the requiredScopes-conjunction contract

Related Issues

  • None

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

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CollectScopesForProjects now returns all effective required scopes for each method instead of selecting one best scope. A unit test verifies the complete required scope set for mail message access.

Changes

Required scope collection

Layer / File(s) Summary
Collect and validate required scopes
internal/registry/scopes.go, internal/registry/registry_test.go
CollectScopesForProjects collects all scopes declared for each method, while a new test verifies the subject, address, and body read scopes for the mail domain.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 clearly and concisely summarizes the main change to CollectScopesForProjects.
Description check ✅ Passed The description follows the required template and includes summary, changes, test plan, and related issues.
✨ 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/collect-scopes-required-scopes

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 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.67%. Comparing base (37d490a) to head (0ac3c23).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1878   +/-   ##
=======================================
  Coverage   74.66%   74.67%           
=======================================
  Files         877      877           
  Lines       91731    91730    -1     
=======================================
+ Hits        68494    68500    +6     
+ Misses      17926    17920    -6     
+ Partials     5311     5310    -1     

☔ 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 14, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#fix/collect-scopes-required-scopes -y -g

@dc-bytedance dc-bytedance force-pushed the fix/collect-scopes-required-scopes branch from 1e04d36 to 0ac3c23 Compare July 14, 2026 08:34
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.

1 participant