Repository navigation
Scoped PAT: Add unit tests - #47999
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds comprehensive UI tests for scoped token validation and creation across project, organization, and account scopes, plus render-time logging of fetched token data in ChangesScoped token creation tests
Token view logging
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
🎭 Playwright Test Results (next)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Third stacked PR for scoped PAT extracted from the prototype #47783 to ease reviewing. Previous stacked PR is #47979 Next stacked PR is #47999 This PR add a way to view the tokens permissions <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a “View permissions” option for scoped access tokens. * Scoped token permissions now open in a dedicated viewing panel. * Scoped token support is enabled by default. * **Bug Fixes** * Improved token deletion confirmation to clearly identify the selected token. * Deletion dialogs now close correctly after successful removal. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx (2)
97-249: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract shared setup/completion helpers to reduce duplication.
Every test repeats the same "click Generate new token → wait for dialog → type Name" boilerplate (e.g. Lines 98-100, 106-109, 114-117, 124-127, 136-139...), and the three "creates the token" tests (135-159, 182-205, 222-248) duplicate an identical 10-line copy/confirm/done/close-dialog sequence verbatim. Extracting these into small helpers (e.g.
openNewTokenSheetAndSetName(name),completeTokenCreationFlow(expectedToken)) would cut this file's size substantially and keep future scope-test additions consistent.♻️ Sketch of extracted helper
async function completeTokenCreationFlow(expectedToken: string) { fireEvent.click(await screen.findByRole('button', { name: 'Create token' })) fireEvent.click(await screen.findByRole('button', { name: 'Copy' })) await waitFor(async () => expect(await window.navigator.clipboard.readText()).toEqual(expectedToken) ) fireEvent.click(await screen.findByLabelText('I have copied the key and stored it securely')) fireEvent.click(await screen.findByRole('button', { name: 'Done' })) await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) }🤖 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 `@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx` around lines 97 - 249, Extract the repeated setup and completion flows in the NewScopedTokenSheet tests into shared helpers, such as openNewTokenSheetAndSetName and completeTokenCreationFlow. Replace each test’s Generate new token/dialog/name boilerplate and the three identical token-copy/confirmation/close sequences with these helpers, preserving each test’s existing scope-specific interactions and expected token assertion.
102-102: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
expect(...)calls with no matcher are no-ops.
expect(await screen.findByText(...))on Lines 102, 111, 121, 133, 169, 180, 220 never chains a matcher (e.g..toBeInTheDocument()). These currently "work" only becausefindByTextitself throws if the element isn't found, but the bareexpect()call performs no assertion. If any of these queries were later swapped for a non-throwing variant (e.g.queryByText), the test would silently pass with no verification. This pattern also trips thevitest/valid-expectrule (matcherNotFound) if it's enabled in this repo's ESLint config.✅ Proposed fix (apply to all 7 occurrences)
- expect(await screen.findByText('Please enter a name for the token')) + expect(await screen.findByText('Please enter a name for the token')).toBeInTheDocument()Also applies to: 111-111, 121-121, 133-133, 169-169, 180-180, 220-220
🤖 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 `@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx` at line 102, Update all seven bare expect calls in NewScopedTokenSheet tests to chain an explicit DOM assertion such as toBeInTheDocument(), including the occurrences around lines 102, 111, 121, 133, 169, 180, and 220; preserve the existing findByText queries and messages.
🤖 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
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/ViewTokenSheet.tsx`:
- Line 48: Remove the console.log({ token }) debug statement from ViewTokenSheet
and leave the token rendering and handling behavior unchanged.
---
Nitpick comments:
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx`:
- Around line 97-249: Extract the repeated setup and completion flows in the
NewScopedTokenSheet tests into shared helpers, such as
openNewTokenSheetAndSetName and completeTokenCreationFlow. Replace each test’s
Generate new token/dialog/name boilerplate and the three identical
token-copy/confirmation/close sequences with these helpers, preserving each
test’s existing scope-specific interactions and expected token assertion.
- Line 102: Update all seven bare expect calls in NewScopedTokenSheet tests to
chain an explicit DOM assertion such as toBeInTheDocument(), including the
occurrences around lines 102, 111, 121, 133, 169, 180, and 220; preserve the
existing findByText queries and messages.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4309acfe-3567-4658-b967-6049c3b009b0
📒 Files selected for processing (2)
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsxapps/studio/components/interfaces/Account/AccessTokens/Scoped/ViewTokenSheet.tsx
…n API specs (#48182) Fifth stacked PR for scoped PAT extracted from the prototype #47783 to ease reviewing. Previous stacked PR is #47999 Next stacked PR is #48359 This PR refactor how we get the map of which scopes enable which endpoint or mcp tool. Previously it was an hardcoded file. We now compute it from the OpenAPI specs of our API. This ensure the map stays up to date when the API changes. However, we don't have an always up-to-date equivalent for mcp tools so we duplicated code from platform that map the OAuth scopes they check with the FGA permissions. ## Notes The react-hook-form usage is not great. A follow up PR will fix it ## How to test - On https://studio-staging-git-scopedpat-scope-permissions-api-supabase.vercel.app/dashboard/account/tokens - Create a new token with a few permissions (their risk marker should be displayed: (_High risk_, _Medium risk_ or _Low risk_) - You should see the available endpoints and mcp tools in the review step <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added dynamic permission mapping for scoped access tokens, covering Management API endpoints and MCP tools. * Added a permissions endpoint with hosted-platform support and caching. * Updated scoped token creation and review screens to show capabilities based on granted permissions. * Added permission-aware risk indicators and tool visibility. * **Bug Fixes** * Improved authorization checks so endpoints and tools require all necessary scopes. * **Tests** * Added coverage for endpoint, scope, and MCP tool mapping behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fourth stacked PR for scoped PAT extracted from the prototype #47783 to ease reviewing.
Previous stacked PR is #48003
Next stacked PR is #48002
This PR:
Summary by CodeRabbit
Tests
Chores