feat: add embedder public APIs (meta, error dispatch, OpenID)#1865
feat: add embedder public APIs (meta, error dispatch, OpenID)#1865zhaojunlin0405 wants to merge 12 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughThe change centralizes CLI error classification and envelope rendering, exposes embedded API metadata injection, and adds verified OpenID propagation from environment credentials through account resolution. ChangesError dispatch and envelope parity
Embedded metadata injection
Verified OpenID account resolution
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant DispatchError
participant EnvelopeRenderer
participant Stderr
CLI->>DispatchError: pass error and identity
DispatchError->>EnvelopeRenderer: classify and render error
EnvelopeRenderer-->>DispatchError: envelope bytes and exit code
DispatchError-->>CLI: envelope, code, presence
CLI->>Stderr: write envelope when present
sequenceDiagram
participant Integrator
participant ApiMeta
participant Registry
participant SchemaCatalog
Integrator->>ApiMeta: SetEmbedded(metadata)
ApiMeta->>Registry: SetEmbeddedMeta(metadata)
Registry->>Registry: validate and store before parse
Registry->>SchemaCatalog: expose embedded services
SchemaCatalog-->>Integrator: injected catalog data
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@7f23badfea46d2049073d1314327e9afb043a95d🧩 Skill updatenpx skills add larksuite/cli#feat/embedder-public-apis -y -g |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1865 +/- ##
==========================================
+ Coverage 74.66% 74.70% +0.03%
==========================================
Files 877 880 +3
Lines 91731 91767 +36
==========================================
+ Hits 68494 68556 +62
+ Misses 17926 17894 -32
- Partials 5311 5317 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@extension/envelope/envelope.go`:
- Around line 4-26: Clarify the DispatchError documentation to exclude
command-context-dependent hint enrichment from its parity guarantee. Explicitly
state that the official root dispatcher may apply the need_user_authorization
scope hint through its Factory, while direct envelope.DispatchError calls on raw
errors do not, and revise the byte-identical/classification guarantee
accordingly.
In `@internal/output/dispatch.go`:
- Around line 49-54: Update the cobra-usage branch in the fallback construction
within dispatch error handling to chain .WithCause(err) onto the validation
error, matching the existing internal-error branch. Preserve the current subtype
and message while ensuring the original error remains available through
errors.Is and errors.Unwrap.
🪄 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: 49e025a8-335b-4722-ae68-e238fbc177cb
📒 Files selected for processing (18)
cmd/dispatch_golden_test.gocmd/root.goextension/apimeta/apimeta.goextension/apimeta/apimeta_test.goextension/credential/env/env.goextension/credential/env/env_test.goextension/credential/types.goextension/envelope/envelope.gointernal/credential/credential_provider.gointernal/credential/credential_provider_test.gointernal/envvars/envvars.gointernal/output/dispatch.gointernal/output/dispatch_test.gointernal/output/errors.gointernal/qualitygate/cmd/semantic-review/main_test.gointernal/registry/loader.gointernal/registry/loader_inject_test.gointernal/registry/remote_test.go
…cobra-usage cause Address CodeRabbit review on PR #1865: - envelope.DispatchError godoc no longer claims blanket byte-identical parity; it discloses that the official dispatcher folds the need_user_authorization scope hint via a Factory embedders lack, so a direct call omits only that hint. - dispatch.go cobra-usage fallback now chains .WithCause(err), matching the internal-error branch and the repo guideline (keeps errors.Is/Unwrap working); envelope bytes and exit code are unchanged (Cause is not serialized).
…ed-literal break Inserting an exported field mid-struct breaks downstream unkeyed struct literals (a Go API compatibility break for module embedders): a positional value intended for SupportedIdentities would land on the new bool field. Append OpenIDVerified after SupportedIdentities so existing field positions are preserved; keyed literals were already unaffected.
…ve lint The bare mention of go:embed at the start of a doc comment line tripped gocheckcompilerdirectives (it parsed as a malformed //go:embed directive). Reword so the token appears mid-sentence.
…cobra-usage cause Address CodeRabbit review on PR #1865: - envelope.DispatchError godoc no longer claims blanket byte-identical parity; it discloses that the official dispatcher folds the need_user_authorization scope hint via a Factory embedders lack, so a direct call omits only that hint. - dispatch.go cobra-usage fallback now chains .WithCause(err), matching the internal-error branch and the repo guideline (keeps errors.Is/Unwrap working); envelope bytes and exit code are unchanged (Cause is not serialized).
cbdb39b to
7f23bad
Compare
Summary
Add three public APIs so integrators that consume lark-cli as a Go module
(restricted, embedded, or agent-oriented distributions) can build and run a
customized binary without depending on internal packages or unstable symbols:
extension/apimeta.SetEmbedded— inject embedded API metadata at processstart, so binaries built from the bare module resolve schema and generated
service commands offline.
extension/envelope.DispatchError— classify an error exactly like the rootcommand dispatcher and return the stderr envelope bytes plus the exit code,
so custom entrypoints render errors identically to the official binary.
extension/credential: an optional pre-verified OpenID channel(
Account.OpenIDVerified+LARKSUITE_CLI_USER_OPEN_ID) that lets a providerassert an already-verified user identity and skip the startup
user_infocall. Off by default.
Changes
SetEmbeddedMetawith a parse-order guard and a defensive copy.DispatchErrorpure classifier;renderTypedEnvelopeextracted fromWriteTypedErrorEnvelope;handleRootErrorroutes throughDispatchError.Account.OpenIDVerified(appended at struct end forABI-friendly evolution) plus env-driven injection; a call-site short-circuit
of the startup verification in the credential resolver.
pre-existing date-dependent test failure.
Test Plan
DispatchErrorbranch classification,and the credential behavior matrix.
DispatchErrortriple isbyte-identical to the real root dispatcher's stderr output and exit code.
container sandbox.
go build ./...,go vet, andgolangci-lint run --new-from-rev=origin/mainall clean.
Related Issues
N/A
Summary by CodeRabbit
New Features
Bug Fixes