feat: add RuntimeContext.BotInfo() for lazy bot identity retrieval#409
feat: add RuntimeContext.BotInfo() for lazy bot identity retrieval#409liangshuo-1 merged 1 commit intomainfrom
Conversation
Add BotInfo() method on RuntimeContext that lazily fetches the current app's bot open_id and display name from /bot/v3/info on first call, cached via sync.OnceValues for the lifetime of the process. - BotInfo struct (OpenID, AppName) in Identity section of runner.go - fetchBotInfo() uses DoAPIAsBot for consistent header injection - CanBot() on CliConfig gates the call when bot identity is unavailable - Nil guard prevents panic in test contexts - Full test coverage via httpmock.Registry + mounted shortcuts Change-Id: I40ac710fb52d13939853f71827a5cbdbddd4f80f
|
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 (5)
📝 WalkthroughWalkthroughThis PR adds bot identity capability checking and introduces bot information retrieval functionality. A new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR adds a Confidence Score: 5/5Safe to merge; all findings are style-level P2 suggestions with no correctness or reliability impact. All three comments are P2 (style/documentation): the No files require special attention beyond the P2 style notes on runner.go and config.go. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant RuntimeContext
participant sync.OnceValues
participant fetchBotInfo
participant CliConfig
participant DoAPIAsBot
Caller->>RuntimeContext: BotInfo()
alt botInfoFunc == nil
RuntimeContext-->>Caller: error(not fully initialized)
else botInfoFunc set
RuntimeContext->>sync.OnceValues: invoke botInfoFunc()
alt already cached
sync.OnceValues-->>RuntimeContext: cached (*BotInfo, error)
else first call
sync.OnceValues->>fetchBotInfo: call
fetchBotInfo->>CliConfig: CanBot()
alt SupportedIdentities has bot bit or == 0
CliConfig-->>fetchBotInfo: true
fetchBotInfo->>DoAPIAsBot: GET /open-apis/bot/v3/info
DoAPIAsBot-->>fetchBotInfo: ApiResp
alt HTTP >= 400
fetchBotInfo-->>sync.OnceValues: nil, error(HTTP N)
else code != 0
fetchBotInfo-->>sync.OnceValues: nil, error(code msg)
else open_id empty
fetchBotInfo-->>sync.OnceValues: nil, error(open_id is empty)
else success
fetchBotInfo-->>sync.OnceValues: BotInfo, nil
end
else bot not supported
CliConfig-->>fetchBotInfo: false
fetchBotInfo-->>sync.OnceValues: nil, error(not available)
end
sync.OnceValues-->>RuntimeContext: (*BotInfo, error) cached
end
RuntimeContext-->>Caller: (*BotInfo, error)
end
Reviews (1): Last reviewed commit: "feat: add RuntimeContext.BotInfo() for l..." | Re-trigger Greptile |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@2764540085c63759f365b39a004ff17311d10a06🧩 Skill updatenpx skills add larksuite/cli#feat/runtime-bot-info -y -g |
Summary
BotInfo()method onRuntimeContextthat lazily fetches the current app's botopen_idand display name from/bot/v3/info, cached viasync.OnceValuesCanBot()onCliConfigto gate the call when bot identity is unavailable (e.g. external credential provider only injecting UAT)fetchBotInfo()private method usingDoAPIAsBotfor consistent shortcut header injection (X-Cli-Shortcut,X-Cli-Execution-Id)TestNewRuntimeContextWithBotInfotest helper for shortcut tests that need a pre-set bot identityTest plan
TestFetchBotInfo_Success— full path via httpmockTestFetchBotInfo_ShortcutHeaders— verifies X-Cli-Shortcut/X-Cli-Execution-Id injectionTestFetchBotInfo_OnceSemantics— single stub, two callsTestFetchBotInfo_APICodeNonZero— code != 0 error branchTestFetchBotInfo_EmptyOpenID— empty open_id error branchTestFetchBotInfo_HTTP4xx— HTTP status code >= 400TestFetchBotInfo_InvalidJSON— malformed response bodyTestFetchBotInfo_CanBotFalse— SupportedIdentities=user-only pre-checkTestBotInfo_NilFunc— nil guard for uninitialized contextsTestCliConfig_CanBot— 4 sub-cases for CanBot() bitflag logicSummary by CodeRabbit
Release Notes