Skip to content

feat: propagate credential metadata - #2305

Merged
kiraWangRuilong merged 2 commits into
mainfrom
feat/credential-source-header
Aug 13, 2026
Merged

feat: propagate credential metadata#2305
kiraWangRuilong merged 2 commits into
mainfrom
feat/credential-source-header

Conversation

@kiraWangRuilong

@kiraWangRuilong kiraWangRuilong commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Propagate request-scoped credential metadata through shared request paths.

Changes

  • Preserve credential metadata alongside resolved access tokens.
  • Propagate it through supported request paths.

Test Plan

  • [ x ] Unit tests pass

Related Issues

  • None

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

coderabbitai Bot commented Aug 11, 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 Plus

Run ID: 159a57c3-24b6-4e15-bb14-7d639966e2d8

📥 Commits

Reviewing files that changed from the base of the PR and between f0dafec and 9a4875c.

📒 Files selected for processing (2)
  • internal/credential/credential_provider.go
  • internal/credential/credential_provider_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/credential/credential_provider_test.go
  • internal/credential/credential_provider.go

📝 Walkthrough

Walkthrough

Credential providers now classify resolved tokens by source. Client, identity, and MCP request paths propagate this metadata through contexts. Risk-control transport injects the source header for authorized origins and removes it when restricted headers are disabled.

Changes

Credential source propagation

Layer / File(s) Summary
Credential source classification and resolution
internal/core/types.go, internal/credential/...
Adds validated credential-source types, records sources in TokenResult, classifies providers, and preserves source metadata during resolution.
Token metadata propagation
internal/client/client.go, internal/identitydiag/diagnostics.go, shortcuts/common/...
Preserves resolved token results and attaches their sources to SDK, streaming, identity, and MCP request contexts.
Risk-control credential signaling
internal/riskcontrol/...
Injects credential-source headers for authorized official origins, supports Feishu and Lark MCP endpoints, and tests stripping and request scoping.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested labels: enhancement

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% 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 clearly summarizes the primary change: propagating credential metadata.
Description check ✅ Passed The description covers the summary, changes, tests, and related issues, but omits the required manual local verification item.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/credential-source-header

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.

@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)
internal/cmdutil/transport_test.go (1)

111-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a resolved CredentialProvider transport regression test.

All cited tests pass nil. The existing risk-control test uses a static stub and does not exercise the SDK transport. Resolve a token on a non-nil CredentialProvider, pass it to buildSDKTransportWithBase, and assert X-Agent-Credential-Source at the final network boundary.

🤖 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/cmdutil/transport_test.go` at line 111, Update the transport
regression test around buildSDKTransport(nil, nil) to use a non-nil
CredentialProvider, resolve a token, and construct the transport through
buildSDKTransportWithBase. Assert at the final network boundary that the request
contains the expected X-Agent-Credential-Source value, while preserving the
existing test setup and assertions.

Source: Coding guidelines

🤖 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/riskcontrol/transport.go`:
- Around line 42-49: Restore NewTransport to its existing two-parameter
signature so current callers remain compatible, and provide CredentialSource
through a separate constructor or option without changing the default behavior.
Update the Transport initialization flow to use the new credential configuration
path while preserving existing NewTransport callers.

---

Nitpick comments:
In `@internal/cmdutil/transport_test.go`:
- Line 111: Update the transport regression test around buildSDKTransport(nil,
nil) to use a non-nil CredentialProvider, resolve a token, and construct the
transport through buildSDKTransportWithBase. Assert at the final network
boundary that the request contains the expected X-Agent-Credential-Source value,
while preserving the existing test setup and assertions.
🪄 Autofix

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 Plus

Run ID: fc82dd60-f3ab-4378-83a4-5145fa056782

📥 Commits

Reviewing files that changed from the base of the PR and between e1f9872 and 839b04f.

📒 Files selected for processing (6)
  • internal/cmdutil/factory_default.go
  • internal/cmdutil/transport_test.go
  • internal/credential/credential_provider.go
  • internal/credential/credential_provider_test.go
  • internal/riskcontrol/transport.go
  • internal/riskcontrol/transport_test.go

Comment thread internal/riskcontrol/transport.go Outdated
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/credential-source-header -y -g

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.14286% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.44%. Comparing base (52ab2ea) to head (ba21604).

Files with missing lines Patch % Lines
shortcuts/common/runner.go 0.00% 9 Missing ⚠️
internal/core/types.go 76.47% 2 Missing and 2 partials ⚠️
internal/identitydiag/diagnostics.go 66.66% 3 Missing ⚠️
shortcuts/common/mcp_client.go 0.00% 3 Missing ⚠️
internal/client/client.go 84.61% 2 Missing ⚠️
internal/credential/credential_provider.go 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2305      +/-   ##
==========================================
- Coverage   76.44%   76.44%   -0.01%     
==========================================
  Files        1025     1025              
  Lines      113710   113748      +38     
==========================================
+ Hits        86931    86958      +27     
- Misses      20108    20117       +9     
- Partials     6671     6673       +2     

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

@kiraWangRuilong
kiraWangRuilong force-pushed the feat/credential-source-header branch from 839b04f to f2b7168 Compare August 11, 2026 13:43
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@kiraWangRuilong
kiraWangRuilong force-pushed the feat/credential-source-header branch from f2b7168 to f0dafec Compare August 12, 2026 06:51

@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 `@internal/client/client.go`:
- Around line 50-67: Update APIClient.resolveAccessToken to check whether result
is nil before reading result.Token, returning newTokenMissingError(as, nil) for
a nil result or empty token. Add a regression test covering a credential
resolver that returns nil, nil and verify it produces the typed token-missing
error without panicking.
🪄 Autofix

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 Plus

Run ID: 4e2391ab-ec31-4c5c-ae04-47c7ba92cf6a

📥 Commits

Reviewing files that changed from the base of the PR and between f2b7168 and f0dafec.

📒 Files selected for processing (12)
  • internal/client/client.go
  • internal/core/types.go
  • internal/core/types_test.go
  • internal/credential/credential_provider.go
  • internal/credential/credential_provider_test.go
  • internal/credential/integration_test.go
  • internal/credential/types.go
  • internal/identitydiag/diagnostics.go
  • internal/riskcontrol/transport.go
  • internal/riskcontrol/transport_test.go
  • shortcuts/common/mcp_client.go
  • shortcuts/common/runner.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/credential/credential_provider_test.go

Comment thread internal/client/client.go
@kiraWangRuilong
kiraWangRuilong force-pushed the feat/credential-source-header branch from f0dafec to 9a4875c Compare August 12, 2026 07:50
@kiraWangRuilong kiraWangRuilong changed the title feat: report credential source in request headers feat: propagate credential metadata Aug 12, 2026
@kiraWangRuilong
kiraWangRuilong force-pushed the feat/credential-source-header branch from 9a4875c to 4504ac5 Compare August 12, 2026 10:04
@kiraWangRuilong
kiraWangRuilong force-pushed the feat/credential-source-header branch from 4504ac5 to ba21604 Compare August 12, 2026 10:06
@kiraWangRuilong
kiraWangRuilong merged commit ac6d7ce into main Aug 13, 2026
26 checks passed
@kiraWangRuilong
kiraWangRuilong deleted the feat/credential-source-header branch August 13, 2026 06:42
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