fix(mail): avoid real keychain access in mail scope tests#212
fix(mail): avoid real keychain access in mail scope tests#212haidaodashushu merged 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughA test setup modification that initializes an in-memory keyring mock in the mail shortcut test factory, replacing reliance on system keyring during test execution. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 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 fixes macOS keychain popup dialogs that appeared when running
Confidence Score: 5/5Safe to merge — change is confined to test infrastructure with no production code affected The change is two lines in a test helper: one import and one No files require special attention Important Files Changed
Sequence DiagramsequenceDiagram
participant T as Test
participant MF as mailShortcutTestFactory
participant KR as go-keyring (MockInit)
participant AU as auth.SetStoredToken
participant KC as macOS Keychain
Note over T,KC: Before this PR
T->>MF: mailShortcutTestFactory(t)
MF->>AU: SetStoredToken(token)
AU->>KC: write to real keychain (⚠️ popup)
Note over T,KC: After this PR
T->>MF: mailShortcutTestFactory(t)
MF->>KR: keyring.MockInit()
KR-->>MF: backend = in-memory store
MF->>AU: SetStoredToken(token)
AU->>KR: write to in-memory store (✅ no popup)
Reviews (2): Last reviewed commit: "fix(mail): use in-memory keyring in mail..." | Re-trigger Greptile |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@5e18e5a400474b4c4c793b6562218e21fb6d2e88🧩 Skill updatenpx skills add larksuite/cli#fix/mail-test-avoid-real-keychain -y -g |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
shortcuts/mail/mail_shortcut_test.go (1)
32-40:⚠️ Potential issue | 🟡 MinorClear
LARKSUITE_CLI_DEFAULT_ASin this helper.
ResolveAschecks that env var beforecfg.DefaultAs, so a developer shell withLARKSUITE_CLI_DEFAULT_AS=botwill bypass this new user default and stop exercising the scope-cache path. Please neutralize it here to keep the tests hermetic.Suggested tweak
func mailShortcutTestFactory(t *testing.T) (*cmdutil.Factory, *bytes.Buffer, *bytes.Buffer, *httpmock.Registry) { t.Helper() t.Setenv("HOME", t.TempDir()) + t.Setenv("LARKSUITE_CLI_DEFAULT_AS", "") cfg := mailTestConfig() scope := "mail:user_mailbox.messages:write mail:user_mailbox.messages:read mail:user_mailbox.message:modify mail:user_mailbox.message:readonly mail:user_mailbox.message.address:read mail:user_mailbox.message.subject:read mail:user_mailbox.message.body:read mail:user_mailbox:readonly" f, stdout, stderr, reg := cmdutil.TestFactory(t, cfg)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/mail/mail_shortcut_test.go` around lines 32 - 40, The helper mailShortcutTestFactory must clear the LARKSUITE_CLI_DEFAULT_AS environment variable so ResolveAs doesn't pick up a developer's shell value and bypass cfg.DefaultAs; update mailShortcutTestFactory to call t.Setenv("LARKSUITE_CLI_DEFAULT_AS", "") (or unset) before calling cmdutil.TestFactory so tests exercise the scope-cache path that ResolveAs and cfg.DefaultAs are intended to cover.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@shortcuts/common/runner.go`:
- Around line 456-472: getStoredScope currently conflates “no stored token” and
“token present with empty Scope” by returning "" which breaks scope-validation
paths (checkShortcutScopes and mail validators); modify getStoredScope (or add a
companion like getStoredTokenPresence) to return both the stored scope and a
presence flag (e.g., (*string, bool) or (string, bool)) so callers
(checkShortcutScopes, RuntimeContext, mail-specific validators) can distinguish
a missing token from a token that has an empty Scope, keep honoring
Factory.StoredScopeOverride, and update all callers noted (including the mail
validators and the RuntimeContext usage) to bypass checks only when
presence==false rather than when scope=="".
---
Outside diff comments:
In `@shortcuts/mail/mail_shortcut_test.go`:
- Around line 32-40: The helper mailShortcutTestFactory must clear the
LARKSUITE_CLI_DEFAULT_AS environment variable so ResolveAs doesn't pick up a
developer's shell value and bypass cfg.DefaultAs; update mailShortcutTestFactory
to call t.Setenv("LARKSUITE_CLI_DEFAULT_AS", "") (or unset) before calling
cmdutil.TestFactory so tests exercise the scope-cache path that ResolveAs and
cfg.DefaultAs are intended to cover.
🪄 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: 54dc3f35-ec17-4d60-9e41-6fcce13dc74c
📒 Files selected for processing (4)
internal/cmdutil/factory.goshortcuts/common/runner.goshortcuts/mail/helpers.goshortcuts/mail/mail_shortcut_test.go
…eychain popups Mail scope tests (TestConfirmSendMissingScope*) were calling auth.SetStoredToken/RemoveStoredToken which accessed the real macOS keychain via go-keyring, causing persistent popup dialogs when the master key was missing. Add keyring.MockInit() to swap in an in-memory backend during tests.
7ebd091 to
5e18e5a
Compare
Summary
TestConfirmSendMissingScopeReply/ReplyAll/Forward) were callingauth.SetStoredToken/RemoveStoredTokenwhich accessed the real macOS keychain viago-keyring, causing persistent popup dialogs when the master key was missingkeyring.MockInit()inmailShortcutTestFactoryto swap the keyring backend to an in-memory implementation during tests, completely avoiding real keychain accessshortcuts/mail/mail_shortcut_test.go(added 1 import + 1 line)Test plan
TestConfirmSendMissingScopeReply,TestConfirmSendMissingScopeReplyAll,TestConfirmSendMissingScopeForwardpass without keychain popupsfactory.go,runner.go,helpers.goare untouched)🤖 Generated with Claude Code