fix(auth): guard isOAuthAuth against undefined/null#476
fix(auth): guard isOAuthAuth against undefined/null#476jroth1111 wants to merge 2 commits intoNoeFabris:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge base: Disabled due to data retention organization setting 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis change makes the Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Greptile SummaryFixed crash in Key changes:
The fix is minimal, correct, and properly tested. The change aligns with existing usage patterns where Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 43a8f0e |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/plugin/auth.test.ts (1)
25-33: LGTM — regression tests correctly cover both null-safety requirements from the issue.Minor nit: each test calls
isOAuthAuthtwice. Since the function is pure, thenot.toThrow()assertion is implicitly covered by thetoBe(false)assertion that follows (a thrown error would itself fail the test). You could consolidate to a single assertion per test, but the explicit form is acceptable given the issue explicitly requested verifying "does not throw."♻️ Optional consolidation (two assertions → one per test)
- it("returns false for undefined auth without throwing", () => { - expect(() => isOAuthAuth(undefined)).not.toThrow(); - expect(isOAuthAuth(undefined)).toBe(false); - }); - - it("returns false for null auth without throwing", () => { - expect(() => isOAuthAuth(null)).not.toThrow(); - expect(isOAuthAuth(null)).toBe(false); - }); + it("returns false for undefined auth without throwing", () => { + expect(isOAuthAuth(undefined)).toBe(false); + }); + + it("returns false for null auth without throwing", () => { + expect(isOAuthAuth(null)).toBe(false); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/plugin/auth.test.ts` around lines 25 - 33, The two tests in auth.test.ts redundantly call isOAuthAuth twice (once inside expect(...).not.toThrow() and once for expect(...).toBe(false)); since isOAuthAuth is pure a thrown error would already fail the test, consolidate each test to a single assertion by removing the not.toThrow() check and only assert expect(isOAuthAuth(undefined)).toBe(false) and expect(isOAuthAuth(null)).toBe(false) respectively, keeping the same test names and the isOAuthAuth references so the intent remains clear.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
src/plugin/auth.test.tssrc/plugin/auth.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/plugin/auth.test.ts (1)
src/plugin/auth.ts (1)
isOAuthAuth(5-7)
src/plugin/auth.ts (1)
src/plugin/types.ts (2)
AuthDetails(21-21)OAuthAuthDetails(4-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Greptile Review
🔇 Additional comments (1)
src/plugin/auth.ts (1)
5-6: LGTM — fix is correct and the type predicate remains sound.The
!!auth &&guard properly short-circuits null/undefined before.typeaccess, andauth is OAuthAuthDetailscontinues to narrow correctly on thetruebranch. The signature widening is fully backward-compatible with all existing callers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/plugin/auth.test.ts`:
- Around line 25-33: The two tests in auth.test.ts redundantly call isOAuthAuth
twice (once inside expect(...).not.toThrow() and once for
expect(...).toBe(false)); since isOAuthAuth is pure a thrown error would already
fail the test, consolidate each test to a single assertion by removing the
not.toThrow() check and only assert expect(isOAuthAuth(undefined)).toBe(false)
and expect(isOAuthAuth(null)).toBe(false) respectively, keeping the same test
names and the isOAuthAuth references so the intent remains clear.
|
Correction to prior comment (formatting issue): Addressed valid review feedback in commit 43a8f0e.
Verified with: |
…ss review issues - PR NoeFabris#476: guard isOAuthAuth against undefined/null (auth.ts) - PR NoeFabris#465: use ensureProjectContext for google_search project‑ID resolution - PR NoeFabris#460: throttle excessive file writes from account state updates - Fix abort‑during‑cooldown error‑escape (wrap all calls) - Remove stale THINKING_RECOVERY_NEEDED sentinel branch - Change abort status from HTTP 499 to standard 408 (Request Timeout) - All tests pass, type‑check clean
…ss review issues - PR NoeFabris#476: guard isOAuthAuth against undefined/null (auth.ts) - PR NoeFabris#465: use ensureProjectContext for google_search project‑ID resolution - PR NoeFabris#460: throttle excessive file writes from account state updates - Fix abort‑during‑cooldown error‑escape (wrap all calls) - Remove stale THINKING_RECOVERY_NEEDED sentinel branch - Change abort status from HTTP 499 to standard 408 (Request Timeout) - All tests pass, type‑check clean
|
Please stop opening AI slop issues and PRs @jroth1111 |
Summary
Fixes a crash in OAuth auth guard when auth state is missing.
Changes
isOAuthAuthnull-safe:auth.type === "oauth"!!auth && auth.type === "oauth"undefinedandnullinputs returnfalseand do not throw.Why
isOAuthAuthwas dereferencingauth.typedirectly. Whenauthis missing/undefined, this can throwTypeError: undefined is not an object (evaluating 'auth.type')before normal fallback handling.Verification
npx vitest run src/plugin/auth.test.tsnpm run typecheck --silentCloses #474