Skip to content

Scoped PAT: Add unit tests - #47999

Merged
djhi merged 13 commits into
scopedpat/root-branchfrom
scopedpat/scoped-token-creation-tests
Jul 29, 2026
Merged

djhi merged 13 commits into
scopedpat/root-branchfrom
scopedpat/scoped-token-creation-tests

Conversation

@djhi

@djhi djhi commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • fix some accessibility issues
  • add unit tests

Summary by CodeRabbit

  • Tests

    • Added coverage for creating scoped access tokens at the project, organization, and account levels.
    • Verified validation for required fields, successful token creation, clipboard copying, and completion flow.
  • Chores

    • Added temporary browser console logging when viewing a scoped access token.

@djhi
djhi requested a review from a team as a code owner July 16, 2026 10:34
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cb7340ac-6cc9-4106-90db-fc8a593e9583

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds comprehensive UI tests for scoped token validation and creation across project, organization, and account scopes, plus render-time logging of fetched token data in ViewTokenSheet.

Changes

Scoped token creation tests

Layer / File(s) Summary
Test harness and API fixtures
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx
Configures clipboard-enabled user events, profile context, MSW API handlers, and shared test setup.
Scope validation coverage
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx
Tests required token names, organizations, projects, and permissions across all supported scopes.
Token creation flows
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx
Tests token creation, clipboard copying, confirmation, and dialog dismissal for project, organization, and account scopes.

Token view logging

Layer / File(s) Summary
Fetched token logging
apps/studio/components/interfaces/Account/AccessTokens/Scoped/ViewTokenSheet.tsx
Logs the fetched token object during component rendering.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the required template sections for behavior, change type, and context. Fill out the required template sections: contributing confirmation, change type, current behavior, new behavior, and additional context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: adding unit tests for scoped PAT.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch scopedpat/scoped-token-creation-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 29, 2026 10:37am
studio-staging Ready Ready Preview, Comment Jul 29, 2026 10:37am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 29, 2026 10:37am
design-system Skipped Skipped Jul 29, 2026 10:37am
docs Skipped Skipped Jul 29, 2026 10:37am
ui-library Skipped Skipped Jul 29, 2026 10:37am
zone-www-dot-com Skipped Skipped Jul 29, 2026 10:37am

Request Review

@supabase

supabase Bot commented Jul 16, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@github-actions

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  238 passed
skipped  5 skipped

Details

stats  243 tests across 28 suites
duration  4 minutes, 11 seconds
commit  12d367e

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  243 passed
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  3 minutes, 48 seconds
commit  21d21f1

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@djhi
djhi changed the base branch from scopedpat/scoped-token-creation-sheet to scopedpat/view-permissions July 16, 2026 13:03
djhi added a commit that referenced this pull request Jul 29, 2026
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 -->
Base automatically changed from scopedpat/view-permissions to scopedpat/root-branch July 29, 2026 09:23
@djhi
djhi requested a review from a team as a code owner July 29, 2026 09:23
@djhi

djhi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Extract 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 because findByText itself throws if the element isn't found, but the bare expect() 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 the vitest/valid-expect rule (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

📥 Commits

Reviewing files that changed from the base of the PR and between eb4aafa and 1e4da81.

📒 Files selected for processing (2)
  • apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx
  • apps/studio/components/interfaces/Account/AccessTokens/Scoped/ViewTokenSheet.tsx

@djhi
djhi merged commit 456ac22 into scopedpat/root-branch Jul 29, 2026
27 checks passed
@djhi
djhi deleted the scopedpat/scoped-token-creation-tests branch July 29, 2026 12:13
djhi added a commit that referenced this pull request Jul 30, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants