mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Part 5 of 6: #52989 → #52990 → #52991 → #52992 → #52993 → #53138 Switches Studio navigation between Advisors and Issues with `issuesInbox`. With the flag off, the existing Advisors sidebar, pages, command menu entries, shortcuts, header panel, and contextual finding links remain available. With it on, these entry points show Issues and legacy Advisor URLs forward to the matching Issues category while preserving finding context. Direct Issues routes remain accessible in either state. The homepage section remains hidden when the flag is off. Telemetry event names are unchanged. ## How to test 1. Turn `issuesInbox` off: desktop and mobile navigation show Advisors, the header opens Advisor Center, and Security, Performance, and enabled Health Advisor pages remain usable. 2. Turn it on: navigation and the header show Issues. Legacy Advisor category URLs forward to matching Issues lists. 3. `G` then `V` opens the active variant. `V` then `S`, `P`, or `H` follows the active category links; shortcut reference labels match. 4. Table Editor finding links open the legacy finding when off and its issue when on. 5. Direct Issues routes remain usable with the flag off; the homepage section stays hidden. ## Validation - Broad navigation/layout/redirect/shortcut regression suite: 456 tests passed, retries disabled. - Focused suite: 181 tests passed with shuffle seed 52993, retries disabled. - Full Studio TypeScript, scoped ESLint, and changed-file Prettier pass. - Behavioral mutation probes detect broken flag guards, finding links, and redirect destinations; source restored afterward. [DEBUG-255](https://linear.app/supabase/issue/DEBUG-255/replace-advisor-terminology-with-issues-throughout-studio) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jordi Enric <jordi.err@gmail.com>
422 lines
13 KiB
TypeScript
422 lines
13 KiB
TypeScript
import { readdirSync } from 'node:fs'
|
|
import { createRequire } from 'node:module'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
getMaintenanceRedirects,
|
|
MAINTENANCE_PASSTHROUGH_SEGMENTS,
|
|
matchRedirect,
|
|
preserveQueryAndHash,
|
|
} from './redirects.shared'
|
|
|
|
// Next's own redirect matcher, so the declarative rule is tested as Next runs it.
|
|
const require = createRequire(import.meta.url)
|
|
const { getPathMatch } = require('next/dist/shared/lib/router/utils/path-match') as {
|
|
getPathMatch: (
|
|
path: string,
|
|
options: { strict: boolean; removeUnnamedParams: boolean }
|
|
) => (pathname: string) => false | Record<string, string>
|
|
}
|
|
|
|
describe('preserveQueryAndHash', () => {
|
|
it('carries incoming query params onto the destination', () => {
|
|
expect(preserveQueryAndHash('/org', { foo: '1', bar: 'x' })).toBe('/org?foo=1&bar=x')
|
|
})
|
|
|
|
it('returns the destination untouched when there is nothing to carry', () => {
|
|
expect(preserveQueryAndHash('/org', {})).toBe('/org')
|
|
expect(preserveQueryAndHash('/org', new URLSearchParams())).toBe('/org')
|
|
})
|
|
|
|
it('drops params consumed by the matched rule', () => {
|
|
expect(
|
|
preserveQueryAndHash(
|
|
'/new/new-project',
|
|
{ next: 'new-project', a: '1' },
|
|
{
|
|
consumedKeys: ['next'],
|
|
}
|
|
)
|
|
).toBe('/new/new-project?a=1')
|
|
})
|
|
|
|
it("lets the destination's own params win on conflict", () => {
|
|
expect(
|
|
preserveQueryAndHash('/org/_/billing?panel=subscriptionPlan', { panel: 'other', x: '1' })
|
|
).toBe('/org/_/billing?panel=subscriptionPlan&x=1')
|
|
})
|
|
|
|
it('preserves repeated keys and array values', () => {
|
|
expect(preserveQueryAndHash('/dest', new URLSearchParams('f=a&f=b'))).toBe('/dest?f=a&f=b')
|
|
expect(preserveQueryAndHash('/dest', { f: ['a', 'b'] })).toBe('/dest?f=a&f=b')
|
|
})
|
|
|
|
it('carries the incoming hash', () => {
|
|
expect(preserveQueryAndHash('/dest', { a: '1' }, { hash: 'section' })).toBe('/dest?a=1#section')
|
|
expect(preserveQueryAndHash('/dest', {}, { hash: 'section' })).toBe('/dest#section')
|
|
})
|
|
|
|
it("lets the destination's own hash win over the incoming one", () => {
|
|
expect(preserveQueryAndHash('/org/slug/billing#invoices', { a: '1' }, { hash: 'other' })).toBe(
|
|
'/org/slug/billing?a=1#invoices'
|
|
)
|
|
})
|
|
|
|
it('skips undefined values in a record search', () => {
|
|
expect(preserveQueryAndHash('/dest', { a: undefined, b: '1' })).toBe('/dest?b=1')
|
|
})
|
|
})
|
|
|
|
describe('matchRedirect moved Studio routes', () => {
|
|
const ref = 'abcdefghijklmnopqrst'
|
|
|
|
it.each([
|
|
[`/project/${ref}/database/backups`, `/project/${ref}/database/backups/scheduled`],
|
|
[`/project/${ref}/auth/emails`, `/project/${ref}/auth/templates`],
|
|
[`/project/${ref}/logs/edge-functions`, `/project/${ref}/logs/edge-functions-logs`],
|
|
[`/project/${ref}/settings/vault`, `/project/${ref}/integrations/vault/secrets`],
|
|
[`/project/${ref}/settings/billing`, '/org/_/billing'],
|
|
[`/project/${ref}/database/hooks`, `/project/${ref}/integrations/webhooks/overview`],
|
|
['/account', '/account/me'],
|
|
['/org/my-org/projects', '/org/my-org'],
|
|
['/project', '/organizations'],
|
|
])('redirects %s to %s', (pathname, destination) => {
|
|
expect(matchRedirect({ pathname, search: {}, isPlatform: true })).toEqual({
|
|
destination,
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it.each(['security', 'performance', 'health'])(
|
|
'leaves %s advisors to the flag-aware page',
|
|
(category) => {
|
|
for (const isPlatform of [true, false]) {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: `/project/${ref}/advisors/${category}`,
|
|
search: { severity: 'critical' },
|
|
isPlatform,
|
|
})
|
|
).toBeNull()
|
|
}
|
|
}
|
|
)
|
|
|
|
it.each([
|
|
['database/security-advisor', 'security'],
|
|
['database/performance-advisor', 'performance'],
|
|
['database/linter', 'security'],
|
|
])('preserves legacy finding links from %s', (path, category) => {
|
|
for (const isPlatform of [true, false]) {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: `/project/${ref}/${path}`,
|
|
search: { id: 'opaque-key', preset: 'WARN' },
|
|
hash: 'finding',
|
|
isPlatform,
|
|
})
|
|
).toEqual({
|
|
destination: `/project/${ref}/advisors/${category}?id=opaque-key&preset=WARN#finding`,
|
|
permanent: true,
|
|
})
|
|
}
|
|
})
|
|
|
|
it('redirects the advisor root while leaving check settings and Issues alone', () => {
|
|
expect(
|
|
matchRedirect({ pathname: `/project/${ref}/advisors`, search: {}, isPlatform: true })
|
|
).toEqual({ destination: `/project/${ref}/advisors/security`, permanent: true })
|
|
expect(
|
|
matchRedirect({
|
|
pathname: `/project/${ref}/advisors/rules/security`,
|
|
search: {},
|
|
isPlatform: true,
|
|
})
|
|
).toBeNull()
|
|
expect(
|
|
matchRedirect({
|
|
pathname: `/project/${ref}/issues`,
|
|
search: { category: 'security' },
|
|
isPlatform: true,
|
|
})
|
|
).toBeNull()
|
|
})
|
|
|
|
it('preserves the incoming query and hash', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: `/project/${ref}/database/backups`,
|
|
search: { source: 'bookmark' },
|
|
hash: 'scheduled',
|
|
isPlatform: true,
|
|
})
|
|
).toEqual({
|
|
destination: `/project/${ref}/database/backups/scheduled?source=bookmark#scheduled`,
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('does not intercept the project selector', () => {
|
|
expect(matchRedirect({ pathname: '/project/_', search: {}, isPlatform: true })).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('matchRedirect query/hash preservation', () => {
|
|
it('redirects the legacy compute and disk route while preserving query and hash', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/settings/compute-and-disk',
|
|
search: { upgrade: 'micro' },
|
|
isPlatform: true,
|
|
hash: 'disk',
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/settings/infrastructure?upgrade=micro#disk',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('redirects legacy replication replica detail to infrastructure', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/database/replication/replica/replica-1',
|
|
search: {},
|
|
isPlatform: true,
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/settings/infrastructure/replica/replica-1',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('redirects the legacy replication list route to Pipelines while preserving query and hash', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/database/replication',
|
|
search: { source: 'bookmark' },
|
|
isPlatform: true,
|
|
hash: 'destinations',
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/database/pipelines?source=bookmark#destinations',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('redirects legacy pipeline detail URLs to Pipelines', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/database/replication/pipeline-1',
|
|
search: {},
|
|
isPlatform: true,
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/database/pipelines/pipeline-1',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('redirects the legacy compute billing panel to the CPU section', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/settings/billing/subscription',
|
|
search: { panel: 'computeInstance', source: 'banner' },
|
|
isPlatform: true,
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/settings/infrastructure?source=banner#cpu',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('carries the incoming query and hash through a plain rule', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/sql/quickstarts',
|
|
search: { template: 'countries', flag: 'true' },
|
|
isPlatform: true,
|
|
hash: 'top',
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/sql/examples?template=countries&flag=true#top',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('consumes `has` query keys but keeps the rest', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/',
|
|
search: { next: 'new-project', projectName: 'foo' },
|
|
isPlatform: true,
|
|
})
|
|
).toEqual({ destination: '/new/new-project?projectName=foo', permanent: false })
|
|
})
|
|
|
|
it("keeps the destination's own params when the incoming query repeats them", () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/settings/billing/subscription',
|
|
search: { panel: 'pitr', source: 'email' },
|
|
isPlatform: true,
|
|
})
|
|
).toEqual({
|
|
destination: '/project/abc/settings/addons?panel=pitr&source=email',
|
|
permanent: true,
|
|
})
|
|
})
|
|
|
|
it('keeps a destination hash (e.g. billing#invoices) over the incoming hash', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/org/my-org/invoices',
|
|
search: {},
|
|
isPlatform: true,
|
|
hash: 'ignored',
|
|
})
|
|
).toEqual({ destination: '/org/my-org/billing#invoices', permanent: true })
|
|
})
|
|
|
|
it('leaves plain redirects without query or hash untouched', () => {
|
|
expect(matchRedirect({ pathname: '/', search: {}, isPlatform: true })).toEqual({
|
|
destination: '/org',
|
|
permanent: false,
|
|
})
|
|
expect(matchRedirect({ pathname: '/', search: {}, isPlatform: false })).toEqual({
|
|
destination: '/project/default',
|
|
permanent: false,
|
|
})
|
|
})
|
|
|
|
it('still returns null for non-matching paths', () => {
|
|
expect(
|
|
matchRedirect({ pathname: '/project/abc/editor', search: { a: '1' }, isPlatform: true })
|
|
).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('matchRedirect maintenance mode', () => {
|
|
it('sends every other path to /maintenance when enabled', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/editor',
|
|
search: {},
|
|
isPlatform: true,
|
|
maintenanceMode: true,
|
|
})
|
|
).toEqual({ destination: '/maintenance', permanent: false })
|
|
})
|
|
|
|
it('carries query and hash onto /maintenance', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/project/abc/editor',
|
|
search: { a: '1' },
|
|
isPlatform: true,
|
|
maintenanceMode: true,
|
|
hash: 'section',
|
|
})
|
|
).toEqual({ destination: '/maintenance?a=1#section', permanent: false })
|
|
})
|
|
|
|
it('leaves /maintenance and /img reachable when enabled', () => {
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/maintenance',
|
|
search: {},
|
|
isPlatform: true,
|
|
maintenanceMode: true,
|
|
})
|
|
).toBeNull()
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/img/supabase-logo.svg',
|
|
search: {},
|
|
isPlatform: true,
|
|
maintenanceMode: true,
|
|
})
|
|
).toBeNull()
|
|
})
|
|
|
|
// Static files the maintenance page (or the SPA shell rendering it) loads.
|
|
const assetPaths = [
|
|
'/maintenance',
|
|
'/maintenance/',
|
|
'/img/supabase-dark.svg',
|
|
'/favicon/favicon.ico',
|
|
'/favicon/manifest.json',
|
|
'/fonts/CustomFont-Book.woff2',
|
|
'/assets/main-abc123.js',
|
|
'/_vercel/immutable/salt/nitro/main-abc123.js',
|
|
'/_vercel/immutable/salt/nitro/styles-abc123.css',
|
|
'/_next/static/chunks/main-abc123.js',
|
|
'/monaco-editor/vs/loader.js',
|
|
'/supabase-logo.svg',
|
|
]
|
|
const pagePaths = [
|
|
'/',
|
|
'/project/abc/editor',
|
|
'/org/acme/billing',
|
|
'/sign-in',
|
|
'/maintenance-other',
|
|
'/images/logo.svg',
|
|
'/project/img',
|
|
'/api/platform/profile',
|
|
'/_serverFn/function-id',
|
|
]
|
|
|
|
it.each(assetPaths)('leaves %s reachable when enabled', (pathname) => {
|
|
expect(
|
|
matchRedirect({ pathname, search: {}, isPlatform: true, maintenanceMode: true })
|
|
).toBeNull()
|
|
})
|
|
|
|
it.each(pagePaths)('redirects %s when enabled', (pathname) => {
|
|
expect(
|
|
matchRedirect({ pathname, search: {}, isPlatform: true, maintenanceMode: true })
|
|
).toEqual({ destination: '/maintenance', permanent: false })
|
|
})
|
|
|
|
it.each(['', '/dashboard'])(
|
|
'declarative rule agrees with the runtime matcher under Next with base path "%s"',
|
|
(basePath) => {
|
|
const [rule] = getMaintenanceRedirects(true)
|
|
// Next prepends basePath to redirect sources.
|
|
const match = getPathMatch(`${basePath}${rule.source}`, {
|
|
strict: true,
|
|
removeUnnamedParams: true,
|
|
})
|
|
for (const pathname of assetPaths) {
|
|
expect(match(`${basePath}${pathname}`), pathname).toBe(false)
|
|
}
|
|
for (const pathname of pagePaths) {
|
|
expect(match(`${basePath}${pathname}`), pathname).not.toBe(false)
|
|
}
|
|
}
|
|
)
|
|
|
|
it('keeps every top-level public/ entry reachable', () => {
|
|
const publicDir = fileURLToPath(new URL('./public', import.meta.url))
|
|
for (const entry of readdirSync(publicDir)) {
|
|
if (entry.startsWith('.')) continue
|
|
expect(MAINTENANCE_PASSTHROUGH_SEGMENTS, entry).toContain(entry)
|
|
}
|
|
})
|
|
|
|
it('bounces /maintenance back to / when disabled', () => {
|
|
expect(matchRedirect({ pathname: '/maintenance', search: {}, isPlatform: true })).toEqual({
|
|
destination: '/',
|
|
permanent: false,
|
|
})
|
|
expect(
|
|
matchRedirect({
|
|
pathname: '/maintenance',
|
|
search: {},
|
|
isPlatform: true,
|
|
maintenanceMode: false,
|
|
})
|
|
).toEqual({ destination: '/', permanent: false })
|
|
})
|
|
})
|